• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

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.

#1Yours3!f  Members   -  Reputation: 1023

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:

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

any idea what is wrong?

best regards,

Yours3lf

#2Yours3!f  Members   -  Reputation: 1023

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;

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

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.

PARTNERS