Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Point Light with Shadow Casting
Alex Ros Offline
Senior Member

Posts: 447
Threads: 46
Joined: Aug 2012
Reputation: 20
#1
Point Light with Shadow Casting

A question just for a check. Is there a possibility to rescript (or whatever is the right term) Point Light in a way it could cast dynamic shadows similar to Spot Light? I am not sure if it's possible. If this feature (dynamic shadows) is hard-coded in some of engine .dll's surely it would be nearly impossible to make anything or extremely hard because it would require reassembling.

But at the same time there a shader file ...core\shaders\deferred_light_frag.glsl and maybe it's possible to make new strings for some kinda new type of light Point Shadow Light.

Here's a copypast of some strings from deferred_light_frag.glsl shader file:
@ifdef LightType_Spot
    @ifdef UseGobo || UseShadowMap
        uniform mat4 a_mtxSpotViewProj;
    @endif
        
    @ifdef UseGobo
    @else
        uniform float afOneMinusCosHalfSpotFOV;
        uniform vec3 avLightForward;
    @endif
    
    @ifdef UseShadowMap
        @ifdef ShadowMapQuality_Low
        @else
            uniform vec2 avShadowMapOffsetMul;
        @endif
    @endif
//Point specfics
@else
    @ifdef UseGobo
        uniform mat4 a_mtxInvViewRotation;
    @endif
@endif

and here's another part which I presume is code of shadows themselves:
    /////////////////////////////////
    // Caclulate shadow (if any)
    
    @ifdef UseShadowMap && LightType_Spot
        
        @ifdef UseGobo
        @else
            vec4 vProjectedUv = a_mtxSpotViewProj * vec4(vPos,1.0);
        @endif
            
        ////////////////////////
        // No Smoothing
        @ifdef ShadowMapQuality_Low
        
            fAttenuatuion *= shadow2DProj(aShadowMap, vProjectedUv).x;
                    
        ///////////////////////
        // Smoothing
        @else    
            //Set up variables
            float fShadowSum = 0;
            float fJitterZ =0;
            vec2 vScreenJitterCoord = gl_FragCoord.xy * $ShadowJitterLookupMul;
            
            vScreenJitterCoord.y = fract(vScreenJitterCoord.y);     //Make sure the coord is in 0 - 1 range
            vScreenJitterCoord.y *= 1.0 / $ShadowJitterSamplesDiv2;     //Access only first texture piece
                        
                
            ////////////////
            // Shader Model 3, Dynamic Branching available
            @ifdef ShaderModel_4
                ////////////////
                // Cheap pre-test
                //  Note1: division must occur when getting samples else gfx card gets angry.)
                //  Note2: It _must_ be division! doing sample * 1/8 will fail!!
                for(int i=0; i<2.0; i++)
                {
                    vec2 vJitterLookupCoord = vec2(vScreenJitterCoord.x, vScreenJitterCoord.y + fJitterZ);
                    
                    vec4 vOffset = texture2D(aShadowOffsetMap, vJitterLookupCoord) *2.0-1.0;
                                    
                    fShadowSum += ShadowOffsetLookup(aShadowMap, vProjectedUv, vec2(vOffset.xy) * avShadowMapOffsetMul ) / 4.0;
                    fShadowSum += ShadowOffsetLookup(aShadowMap, vProjectedUv, vec2(vOffset.zw) * avShadowMapOffsetMul ) / 4.0;
                                
                    fJitterZ += 1.0 / $ShadowJitterSamplesDiv2;
                }
                
                ////////////////
                // Check if in penumbra
                if( (fShadowSum-1.0) * fShadowSum * fLDotN != 0)
                {     
                    //Multiply, so the X presamples only affect their part (X/all_samples) of samples taken.
                    fShadowSum *= 4.0 / $ShadowJitterSamples;
                                
                    ////////////////
                    // Fullscale filtering
                    for(int i=0; i<$ShadowJitterSamplesDiv2-2.0; i++)
                    {
                        vec2 vJitterLookupCoord = vec2(vScreenJitterCoord.x, vScreenJitterCoord.y + fJitterZ); //Not that coords are 0-1!
                    
                        vec4 vOffset = texture2D(aShadowOffsetMap, vJitterLookupCoord) *2.0 - 1.0;
                                                            
                        fShadowSum += ShadowOffsetLookup(aShadowMap, vProjectedUv, vec2(vOffset.xy) * avShadowMapOffsetMul ) / $ShadowJitterSamples;
                        fShadowSum += ShadowOffsetLookup(aShadowMap, vProjectedUv, vec2(vOffset.zw) * avShadowMapOffsetMul ) / $ShadowJitterSamples;
                        
                        fJitterZ += 1.0 / $ShadowJitterSamplesDiv2;
                    }
                    
                    //vDiffuse.xyz = vec3(0,0,1);
                }
                /*else
                {
                    if(fShadowSum>0.5)     vDiffuse.xyz = vec3(1,0,0);    
                    else             vDiffuse.xyz = vec3(0,1,0);
                    
                    //fAttenuatuion *= fShadowSum;    
                }*/
            /////////////////////
            // No Dynamic Branching
            @else
                for(int i=0; i<$ShadowJitterSamplesDiv2; i++)
                {
                    vec2 vJitterLookupCoord = vec2(vScreenJitterCoord.x, vScreenJitterCoord.y + fJitterZ);
                    
                    vec4 vOffset = texture2D(aShadowOffsetMap, vJitterLookupCoord) *2.0 - 1.0;
                    
                    fShadowSum += ShadowOffsetLookup(aShadowMap, vProjectedUv, vec2(vOffset.xy) * avShadowMapOffsetMul );
                    fShadowSum += ShadowOffsetLookup(aShadowMap, vProjectedUv, vec2(vOffset.zw) * avShadowMapOffsetMul );
                                
                    fJitterZ += 1.0 / $ShadowJitterSamplesDiv2;
                }
                
                fShadowSum /= $ShadowJitterSamples;
            @endif
            
            
            /////////////////////
            // Add shadow sum to attenuation
            fAttenuatuion *= fShadowSum;
        @endif
        
    
    @endif

I am not a scripter and that's why I am asking for help or just an advice. I do have some knowledge of scripts, at least I can understand what is what and what for. But... anyway if anybody can help or advice something, thanks in advance! At the same time I am sure if such an "upgrade" of HPL2 Lights is possible and could be done by someone, than it would be very useful for everybody. I mean everybody could be thankful, not just me.
(This post was last modified: 11-15-2012, 02:17 AM by Alex Ros.)
11-15-2012, 01:55 AM
Website Find
MyRedNeptune Offline
Senior Member

Posts: 553
Threads: 3
Joined: May 2012
Reputation: 33
#2
RE: Point Light with Shadow Casting

Well, technically, you can create a similar effect by combining 6 spotlights 90 degrees each into a cube shape. Big Grin You will need to create a new gobo for it, though.

^(;,;)^
11-15-2012, 11:27 AM
Find
Alex Ros Offline
Senior Member

Posts: 447
Threads: 46
Joined: Aug 2012
Reputation: 20
#3
RE: Point Light with Shadow Casting

(11-15-2012, 11:27 AM)MyRedNeptune Wrote: Well, technically, you can create a similar effect by combining 6 spotlights 90 degrees each into a cube shape. Big Grin You will need to create a new gobo for it, though.
I tried that in the first place. And it doesn't work out well. There were glitches and flickering.
And by the way for that Point Light with Shadows I don't need gobo.
11-15-2012, 01:15 PM
Website Find
MyRedNeptune Offline
Senior Member

Posts: 553
Threads: 3
Joined: May 2012
Reputation: 33
#4
RE: Point Light with Shadow Casting

(11-15-2012, 01:15 PM)Alex Ros Wrote:
(11-15-2012, 11:27 AM)MyRedNeptune Wrote: Well, technically, you can create a similar effect by combining 6 spotlights 90 degrees each into a cube shape. Big Grin You will need to create a new gobo for it, though.
I tried that in the first place. And it doesn't work out well. There were glitches and flickering.
And by the way for that Point Light with Shadows I don't need gobo.
Hm, you're right. I just tested it more thoroughly and it does create strange glitches.

I'm quite interested in this topic as well so count me in. Smile

^(;,;)^
11-15-2012, 01:39 PM
Find
The chaser Offline
Posting Freak

Posts: 2,486
Threads: 76
Joined: Jun 2012
Reputation: 113
#5
RE: Point Light with Shadow Casting

If you wanted to make a Point Light that casts shadows you should modify the lighting code core. It's a good idea, but if FG did this this way, they will have a reason.

THE OTHERWORLD (WIP)
[Image: k6vbdhu]

Aculy iz dolan.
11-15-2012, 02:07 PM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#6
RE: Point Light with Shadow Casting

I was playing Penumbra: Requiem and some areas seemed to have pointlights that gave off shadows. I'm not sure if they removed it or they just did an amazing job placing spotlights...
11-15-2012, 05:21 PM
Find
Hardarm Offline
Posting Freak

Posts: 891
Threads: 39
Joined: Apr 2011
Reputation: 43
#7
RE: Point Light with Shadow Casting

(11-15-2012, 05:21 PM)Statyk Wrote: I was playing Penumbra: Requiem and some areas seemed to have pointlights that gave off shadows. I'm not sure if they removed it or they just did an amazing job placing spotlights...
It's quite easy to make such spotlights. make 4, all with 90-120 as FOV facing 4 different directions. It worked out well for me. Fov mustn't be too large or the shadows will become scretched

listen to boards of canada
11-15-2012, 05:51 PM
Website Find
Alex Ros Offline
Senior Member

Posts: 447
Threads: 46
Joined: Aug 2012
Reputation: 20
#8
RE: Point Light with Shadow Casting

(11-15-2012, 05:21 PM)Statyk Wrote: I was playing Penumbra: Requiem and some areas seemed to have pointlights that gave off shadows. I'm not sure if they removed it or they just did an amazing job placing spotlights...
Seems like you are absolutely right. HPL1 Point Lights did have an ability to cast shadows...

http://wiki.frictionalgames.com/hpl1/doc...ment.chap3

Look for 3.3 Lights chapter and then for 3.3.2 Point Lights...

Thanks for aiming!
(This post was last modified: 11-15-2012, 08:10 PM by Alex Ros.)
11-15-2012, 08:09 PM
Website Find




Users browsing this thread: 1 Guest(s)