Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

need help with shadow mapping

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 Yours3!f   Members   

1532
Like
0Likes
Like

Posted 05 January 2013 - 05:19 PM

Hi,

 

I'm trying to do shadow mapping. Unfortunately, I can't get the shadow to be displayed. I checked with gDEbugger, the shadow map is correct, but I'm not sure if I calculate the shadows properly.

 

here's the project:

https://docs.google.com/open?id=0BzHTUfIQ-XD8WjNldzEyZXhjTU0

 

I also attached an image of the shadow map depth texture.

 

any idea what is wrong?

 

best regards,

Yours3lf

Attached Thumbnails

  • depth.png


#2 Yours3!f   Members   

1532
Like
1Likes
Like

Posted 06 January 2013 - 10:17 AM

ok, I think I got it.

I just needed to transform the clip space shadow coords to ndc, then to tex coords.

 

#version 330 core

layout(binding=0) uniform sampler2D texture0;
uniform vec3 light_pos, spot_dir;
uniform float radius, spot_exponent, spot_cos_cutoff;

in vec3 normal;
in vec3 vs_pos;
in vec4 ls_pos;

out vec4 color;

void main()
{
	vec3 n = normal;
	vec3 l = light_pos - vs_pos;
	float d = length(l);
	l = normalize(l);
	float att = (1 + d / radius);
	att = 1.0 / ( att * att );
	float n_dot_l = dot(n, l);
	
	if(n_dot_l > 0)
	{		
		vec3 h = 0.5 * (l + normalize(-vs_pos));
		float n_dot_h = max(dot(n, h), 0);
		
		float spot_effect = dot(-l, spot_dir);
		if(spot_effect > spot_cos_cutoff)
		{
			spot_effect = pow( spot_effect, spot_exponent );
			att = spot_effect / att + 1;
		}
		att -= 1;
		
		vec4 shadow_coord = ls_pos / ls_pos.w; //convert to ndc
		shadow_coord = shadow_coord * 0.5 + 0.5; //scale, bias to [0...1]
		
		float depth = texture( texture0, shadow_coord.xy ).x;
		
		att *= depth < shadow_coord.z - 0.005 ? 0 : 1; //add bias to get rid of shadow acne
		
		color += vec4(vec3((0.1 + n_dot_l + pow(n_dot_h, 20)) * att), 1);
	}
	
	color.xyz = pow(color.xyz, vec3(1/2.2));
    //color = vec4(1);
}





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.