Kealor1458

12-09-2017, 08:35 AM

I'm basically trying to get the angle between two vectors and factor that into a smoothstep which i then use elsewhere:

void main()

{

float sampleDepth = texture2D(spec, v_vTexcoord ).r;

vec3 normalPos = vec3(v_vTexcoord.xy,sampleDepth);

vec3 normalVector = texture2D(norm, v_vTexcoord ).rgb;

float brightnessMod = 0.0;

for (float i = 0.0; i < lightNum; i++)

{

vec3 lightPos = texture2D(light,vec2(i,0.0)).rgb;

vec3 lightVector = vec3(normalPos-lightPos);

float angle = acos(clamp(dot(normalize(lightVector),normalize(no rmalVector)),-1.0,1.0); // <<< This is the problem line as far as i can tell

brightnessMod += 1.0-smoothstep(0.0,PI/2.0,angle);

}

gl_FragColor = vec4((v_vColour * texture2D( gm_BaseTexture, v_vTexcoord ) * min(brightnessMod,1.0)).rgb,1.0);

}

From context it seems to me that the "smoothstep()" is allways returning 1, even though the angle should be in [0, pi] but even when i change the "smoothstep()" to "smoothstep(0.0,100000.0,angle)" it still returns 1.

Now am i an idiot and there is a problem with ang = v1 dot v2 (since normalized)? or is there something else going on.

lightVector and NormalVector are both vec3s and i can provide additional context if needed. I'm somewhat fresh on the opengl scene but i cannot for the life of me figure out what is going on.

void main()

{

float sampleDepth = texture2D(spec, v_vTexcoord ).r;

vec3 normalPos = vec3(v_vTexcoord.xy,sampleDepth);

vec3 normalVector = texture2D(norm, v_vTexcoord ).rgb;

float brightnessMod = 0.0;

for (float i = 0.0; i < lightNum; i++)

{

vec3 lightPos = texture2D(light,vec2(i,0.0)).rgb;

vec3 lightVector = vec3(normalPos-lightPos);

float angle = acos(clamp(dot(normalize(lightVector),normalize(no rmalVector)),-1.0,1.0); // <<< This is the problem line as far as i can tell

brightnessMod += 1.0-smoothstep(0.0,PI/2.0,angle);

}

gl_FragColor = vec4((v_vColour * texture2D( gm_BaseTexture, v_vTexcoord ) * min(brightnessMod,1.0)).rgb,1.0);

}

From context it seems to me that the "smoothstep()" is allways returning 1, even though the angle should be in [0, pi] but even when i change the "smoothstep()" to "smoothstep(0.0,100000.0,angle)" it still returns 1.

Now am i an idiot and there is a problem with ang = v1 dot v2 (since normalized)? or is there something else going on.

lightVector and NormalVector are both vec3s and i can provide additional context if needed. I'm somewhat fresh on the opengl scene but i cannot for the life of me figure out what is going on.