• Advertisement
Sign in to follow this  

soft shadows problem

This topic is 1757 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


Hi,
I am trying to implement the Brute-Force Implementation ( as described here http://http.developer.nvidia.com/GPUGems/gpugems_ch11.html) but the shadows do not display correctly (wrong place, orientation), although the shadows appear to look with antialiasing.

 

the code

 float3 offset_lookup(sampler map, float4 loc, float2 offset){
        float2 texmapscale = float2(1/xResolution.x, 1/xResolution.y);
        return tex2Dproj(map, float4(loc.xy + offset * texmapscale * loc.w, loc.z, loc.w));
 }

 float ShadowedArea(int subFrustum, float diffuseLightingFactor, float distanceFromCamera, SSceneVertexToPixel PSIn)
 {
        float depthStoredInShadowMap;
        float sum = 0;
        float x, y;

        for (y = -1.5; y <= 1.5; y += 1.0)
            for (x = -1.5; x <= 1.5; x += 1.0)
                sum += offset_lookup(xShadowMapSubFrustum0_Sampler, PSIn.Pos2DAsSeenByLight[subFrustum], float2(x, y));
        depthStoredInShadowMap = sum / 16.0;
        
        float realDistance = PSIn.Pos2DAsSeenByLight[subFrustum].z/xMaxDepth[subFrustum];

        if((realDistance - 1.0f/100.0f) <= depthStoredInShadowMap){
            //light can see
        }else{
            if(dot(PSIn.Normal, xLightDirection) >= 0){
                //covered by object, and light can't see
                float shadowFade = ShadowFade(diffuseLightingFactor, distanceFromCamera);
                if(shadowFade < diffuseLightingFactor)
                    diffuseLightingFactor = shadowFade;
            }else{
                //not facing the light, and light can't see
                diffuseLightingFactor = 0;
            }
        }
    return diffuseLightingFactor;
 }

 

when I reverse the sign to the loc.y, and divide the (loc.xy + offset * texmapscale * loc.w) with /2.0 + 0.5 the shadows display correctly, but with not antialiasing for some reason(they look pixelated, the same way they were before the soft shadows implementation)

 float3 offset_lookup(sampler map, float4 loc, float2 offset){
        float2 texmapscale = float2(1/xResolution.x, 1/xResolution.y);
        loc.y = -loc.y; 
        return tex2Dproj(map, float4((loc.xy + offset * texmapscale * loc.w)/2.0 + 0.5, loc.z, loc.w));
 }

 

Edited by michaelmk86

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement