Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualnewObjekt

Posted 02 April 2013 - 05:10 PM

Okay so I'm on the right track. I set the game to render from the same position as the light and I put in an if statement that compares the depth of the pixel in the ShadowMap with the depth of the pixel that's being rendered. If the Shadow depth is < the fragDepth then it doesn't apply the Shadow.

 

Heres the code and result:

http://inferno.codebrainshideout.net/Images/shadows%20d.png

		vec4 shadowCoordinateWdivide = ShadowCoord / ShadowCoord.w ;
	
		// Used to lower moiré pattern and self-shadowing
		shadowCoordinateWdivide.z += 0.0005;
	
		float shadowDepth = texture2D(ShadowMap,shadowCoordinateWdivide.st).z / texture2D(ShadowMap,shadowCoordinateWdivide.st).w;
		float fragDepth = (gl_FragCoord.z / gl_FragCoord.w)/2048;
		
		float distanceFromLight = texture2D(ShadowMap,shadowCoordinateWdivide.st).z * 2;
	
	
 		float shadow = 1.0;
 		 if (ShadowCoord.w > 0.0)
 			if (shadowDepth+0.0005 < fragDepth) //THIS IS THE NEW CHECK TO STOP SELF SHADOWING
 					shadow = distanceFromLight < shadowCoordinateWdivide.z ? 0.5 : 1.0;
	
  		gl_FragColor = shadow * texture2D(diffuseTexture, gl_TexCoord[0].st);

 

You can see the self shadowing is gone and from what I can tell the shadows are still being cast on the things they should.  The big problem is that I can't move the camera otherwise the gl_FragCoord is not going to be the same as the ShadowMap coord.

 

So I need to know how to transform the gl_FragCoord to face the light source in GLSL so I can compare the depths before applying a shadow.


#1newObjekt

Posted 02 April 2013 - 05:08 PM

Okay so I'm on the right track. I set the game to render from the same position as the light and I put in an if statement that compares the depth of the pixel in the ShadowMap with the depth of the pixel that's being rendered. If the Shadow depth is < the fragDepth then it doesn't apply the Shadow.

 

Heres the code and result:

Picture

		vec4 shadowCoordinateWdivide = ShadowCoord / ShadowCoord.w ;
	
		// Used to lower moiré pattern and self-shadowing
		shadowCoordinateWdivide.z += 0.0005;
	
		float shadowDepth = texture2D(ShadowMap,shadowCoordinateWdivide.st).z / texture2D(ShadowMap,shadowCoordinateWdivide.st).w;
		float fragDepth = (gl_FragCoord.z / gl_FragCoord.w)/2048;
		
		float distanceFromLight = texture2D(ShadowMap,shadowCoordinateWdivide.st).z * 2;
	
	
 		float shadow = 1.0;
 		 if (ShadowCoord.w > 0.0)
 			if (shadowDepth+0.0005 < fragDepth) //THIS IS THE NEW CHECK TO STOP SELF SHADOWING
 					shadow = distanceFromLight < shadowCoordinateWdivide.z ? 0.5 : 1.0;
	
  		gl_FragColor = shadow * texture2D(diffuseTexture, gl_TexCoord[0].st);

 

You can see the self shadowing is gone and from what I can tell the shadows are still being cast on the things they should.  The big problem is that I can't move the camera otherwise the gl_FragCoord is not going to be the same as the ShadowMap coord.

 

So I need to know how to transform the gl_FragCoord to face the light source in GLSL so I can compare the depths before applying a shadow.


PARTNERS