GLSL halfvector?

Started by
9 comments, last by JohnnyCode 8 years, 11 months ago
In the GLSL docs, it says halfVector is derived for gl_LightSource, however it doesn't really say how it's derived. Question is, does it take into account whether the light source is directional or not, or must I calculate the halfVector myself in this case? I'm somewhat hesistant to use gl_LightSource[0].halfVector.xyz without knowing how it's derived.
Advertisement

vec3 halfVector = normalize(directionTowardsLight + directionTowardsEye);

Used by standart directional, point and spotlight sources. Directions are calculated from transformed position (excluding projection transform) in fragment shader. (In case of directional light it can be calculated outside the shader at all)

Thanks, but does GLSL take into account whether the light is directional or not, before (L+V) is computed?


 vec3 L = normalize(gl_LightSource[0].position.xyz);		// directional

 OR

 vec3 worldPos = vec3(gl_ModelViewMatrix * gl_Vertex);		// point
 vec3 L = normalize(gl_LightSource[0].position.xyz - worldPos);

 vec3 H = (L + V);

What version of OpenGL are you using? You shouldn't be using old OpenGL. Even "new" opengl will be old in a couple of years when Vulkan is in use.

I really wish OpenGL would just remove all the old documentation. It happens too many times that I'm reading documentation or the wiki only to see the "This is legacy code. Do no use!" warning in the middle of the document.

It is difficult when you are first learning this stuff, and you don't even realize you are learning old tech.

I have been compiling a list of modern OpenGL tutorials here: http://www.gamedev.net/topic/667482-modern-opengl-tutorials/

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

I'm learning old GLSL so I can support old OpenGL code. I have no plans to update anytime soon.
I just would like to know if gl_LightSource[0].halfVector.xyz is the same value as my calculated one.
I'm using directional lights.

OpenGL takes into account light type (I am not 100% sure, but it is easy to spot if its not)

If the light source has a position, it's probably not directional.
Directional should have a light direction vector

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

I guess I have to debug it to know for sure. Perhaps this will help write out a vector.


gl_FragColor = vec4( gl_LightSource[0].halfVector.xyz, 1.0 );

It does not matter wheather the light is directional or not.

If it is directional light, only eye direction is a per pixel varying vector, if it is a position light, also light direction is per pixel varying vector. You should use explicit computations , even in old opengl, nothing should restrict you from that.

>>It does not matter wheather the light is directional or not.

Half vector is L+V. Are you saying Lpoint+V = Ldir+V? That doesn't make sense. They're two different light vectors.

This topic is closed to new replies.

Advertisement