Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


#Actualmichaelmk86

Posted 24 March 2013 - 03:40 PM


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));
 }

 


#5michaelmk86

Posted 23 March 2013 - 08:42 AM


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).

 

the code with soft shadows, that i am having problem with

 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;
 }

 

without soft shadows, that is working perfectly

float ShadowedArea(int subFrustum, float diffuseLightingFactor, float distanceFromCamera, SSceneVertexToPixel PSIn)
 {
	float2 ProjectedTexCoords;
	
	ProjectedTexCoords[0] = PSIn.Pos2DAsSeenByLight[subFrustum].x/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
	ProjectedTexCoords[1] = -PSIn.Pos2DAsSeenByLight[subFrustum].y/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;


		float depthStoredInShadowMap = tex2D(xShadowMapSubFrustum0_Sampler, ProjectedTexCoords).r;
		
		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;
 }

#4michaelmk86

Posted 23 March 2013 - 07:54 AM


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 (no need for screenshot, just weird shapes).

 

the code with soft shadows, that i am having problem with

 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;
 }

 

without soft shadows, that is working perfectly

float ShadowedArea(int subFrustum, float diffuseLightingFactor, float distanceFromCamera, SSceneVertexToPixel PSIn)
 {
	float2 ProjectedTexCoords;
	
	ProjectedTexCoords[0] = PSIn.Pos2DAsSeenByLight[subFrustum].x/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
	ProjectedTexCoords[1] = -PSIn.Pos2DAsSeenByLight[subFrustum].y/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;


		float depthStoredInShadowMap = tex2D(xShadowMapSubFrustum0_Sampler, ProjectedTexCoords).r;
		
		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;
 }

#3michaelmk86

Posted 23 March 2013 - 05:26 AM


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 (no need for screenshot, just weird shapes).

 

the code with soft shadows, that i am having problem with

 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)
 {
    float2 ProjectedTexCoords;
    
    ProjectedTexCoords[0] = PSIn.Pos2DAsSeenByLight[subFrustum].x/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
    ProjectedTexCoords[1] = -PSIn.Pos2DAsSeenByLight[subFrustum].y/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
     
    if((saturate(ProjectedTexCoords).x == ProjectedTexCoords.x) && (saturate(ProjectedTexCoords).y == ProjectedTexCoords.y)){

        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;
 }

 

without soft shadows, that is working perfectly

float ShadowedArea(int subFrustum, float diffuseLightingFactor, float distanceFromCamera, SSceneVertexToPixel PSIn)
 {
	float2 ProjectedTexCoords;
	
	ProjectedTexCoords[0] = PSIn.Pos2DAsSeenByLight[subFrustum].x/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
	ProjectedTexCoords[1] = -PSIn.Pos2DAsSeenByLight[subFrustum].y/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
     
	if((saturate(ProjectedTexCoords).x == ProjectedTexCoords.x) && (saturate(ProjectedTexCoords).y == ProjectedTexCoords.y)){

		float depthStoredInShadowMap = tex2D(xShadowMapSubFrustum0_Sampler, ProjectedTexCoords).r;
		
		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;
 }

#2michaelmk86

Posted 21 March 2013 - 04:28 AM


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 (no need for screenshot, just weird shapes).

 

the code with soft shadows, that i am having problem with

 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)
 {
    float2 ProjectedTexCoords;
    
    ProjectedTexCoords[0] = PSIn.Pos2DAsSeenByLight[subFrustum].x/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
    ProjectedTexCoords[1] = -PSIn.Pos2DAsSeenByLight[subFrustum].y/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
     
    if((saturate(ProjectedTexCoords).x == ProjectedTexCoords.x) && (saturate(ProjectedTexCoords).y == ProjectedTexCoords.y)){

        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;
 }

 

without soft shadows, that is working perfectly

float ShadowedArea(int subFrustum, float diffuseLightingFactor, float distanceFromCamera, SSceneVertexToPixel PSIn)
 {
	float2 ProjectedTexCoords;
	
	ProjectedTexCoords[0] = PSIn.Pos2DAsSeenByLight[subFrustum].x/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
	ProjectedTexCoords[1] = -PSIn.Pos2DAsSeenByLight[subFrustum].y/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
     
	if((saturate(ProjectedTexCoords).x == ProjectedTexCoords.x) && (saturate(ProjectedTexCoords).y == ProjectedTexCoords.y)){

		float depthStoredInShadowMap;
		
		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;
 }

#1michaelmk86

Posted 21 March 2013 - 04:25 AM


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 (no need for screenshot, just weird shapes).

 

the code with soft shadows, that i am having problem with

 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)
 {
    float2 ProjectedTexCoords;
    
    ProjectedTexCoords[0] = PSIn.Pos2DAsSeenByLight[subFrustum].x/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
    ProjectedTexCoords[1] = -PSIn.Pos2DAsSeenByLight[subFrustum].y/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
     
    if((saturate(ProjectedTexCoords).x == ProjectedTexCoords.x) && (saturate(ProjectedTexCoords).y == ProjectedTexCoords.y)){

        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;
 }

 

without soft shadows, that working perfectly

float ShadowedArea(int subFrustum, float diffuseLightingFactor, float distanceFromCamera, SSceneVertexToPixel PSIn)
 {
	float2 ProjectedTexCoords;
	
	ProjectedTexCoords[0] = PSIn.Pos2DAsSeenByLight[subFrustum].x/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
	ProjectedTexCoords[1] = -PSIn.Pos2DAsSeenByLight[subFrustum].y/PSIn.Pos2DAsSeenByLight[subFrustum].w/2.0f +0.5f;
     
	if((saturate(ProjectedTexCoords).x == ProjectedTexCoords.x) && (saturate(ProjectedTexCoords).y == ProjectedTexCoords.y)){

		float depthStoredInShadowMap;
		
		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;
 }

 


PARTNERS