Jump to content
  • Advertisement
Sign in to follow this  

[GLSL] Passing mat4x4 as light position

This topic is 2591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This might sound strange, but i believe you guys know how to achieve what i need.

Right now i pass my light position to shader via vec3, then i calculate the:

vec3 vertexPos = vec3( m_View * m_Model * gl_Vertex );

vec3 n = normalize(vec3( m_View * m_Model * vec4(gl_Normal, 0.0)));
vec3 t = normalize(gl_NormalMatrix * gl_MultiTexCoord7.xyz);
vec3 b = cross(n, t) * gl_MultiTexCoord7.w;

mat3x3 tbnMatrix = mat3x3(t.x, b.x, n.x,
t.y, b.y, n.y,
t.z, b.z, n.z);

viewDir = tbnMatrix * -vertexPos;

lightDir=tbnMatrix*((gl_LightSource[0].position.xyz - vertexPos.xyz)/radius)

and pass what is required to fragment to lit the surface properly. Works great.

What i would like to do is to pass a light position as a mat4x4 - to have all my transformations in engine stored as matrices.

Of course i would need to forget about gl_LightSource[xxx] and put my own structure into shader, what i already have prepared.
I also have my lights positions stored in matrices, so all is really required is to rewrite the above to run calcs on mat4x4 instead of vec3.

The calculations are the thing here, is it possible to pass mat4x4 instead of vec3 for light position and have the calcs done?

If not, how can i achieve a vec3 out of a mat4x4 ?


Share this post

Link to post
Share on other sites
well as far as I know what you want to do is completely unwanted. The CPU can do far less work than the GPU. To add you'd need to calculate the light direction for every vertex that you render, and for a very large mesh (1 million polygons) the CPU wouldn't process it that fast so that it'd be real-time. On the other side the GPU has like ~1000 shader processors (or more) and each can process 4 operations / cycle (or something like that), and each is going with 1300-1400MHz, so the GPU would process it in no time due to it processes data massively parallelly. So you definitely don't want to compute things for each vertex (or each fragment) on the CPU.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!