Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 11

Thread: Angle between two vectors issue

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Dec 2017

    Angle between two vectors issue

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

    Code :
    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(normalVector)),-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.
    Last edited by Kealor1458; 12-09-2017 at 09:59 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts