Sign in to follow this  
xynapse

[GLSL] Passing mat4x4 as light position

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:


[code]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)

[/code]




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




What i would like to do is to [u]pass a light position as a mat4x4 [/u]- 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 ?




Thanks!

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this