GLSL Equivalent to HLSL ViewInverse

Started by
2 comments, last by swiftcoder 14 years, 10 months ago
In the following HLSL vertex shader snippet, there's a variable being set called 'WorldView' OUT.WorldNormal = mul(NormO, tWIT).xyz; half4 Po = half4(PosO.xyz,1); half3 Pw = mul(Po, tW).xyz; OUT.LightVec = normalize(lPos - Pw); OUT.TexCoord = TexCd.xyxx; OUT.WorldView = normalize(tVI[3].xyz - Pw); OUT.HPosition = mul(Po, tWVP); I'm trying to work out how to to do the same thing in GLSL. tVI is defined as: float4x4 tVI : ViewInverse; and is clearly a transformation matrix, but doesn't have a direct equivalent in GLSL/OpenGL, as far as I can tell. Can anyone tell me to how recreate this in a GLSL shader? Cheers, a|x http://machinesdontcare.wordpress.com
Advertisement
Calculate and upload it as a uniform - OpenGL (and thus GLSL) doesn't differentiate between view and model matrices, so you have to maintain them yourself.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Quote:Original post by swiftcoder
Calculate and upload it as a uniform - OpenGL (and thus GLSL) doesn't differentiate between view and model matrices, so you have to maintain them yourself.


i swiftcoder,

thanks for getting back to me!
Would I be right in assuming that 'WorldView' in the the above code is basically the position of the virtual camera in the scene minus the vertex position after multiplication by the gl_ModelViewMatrix? If this is the case, could I extract this value from the ModelView Matrix itself, perhaps?

a|x
Quote:Original post by toneburst
Would I be right in assuming that 'WorldView' in the the above code is basically the position of the virtual camera in the scene minus the vertex position after multiplication by the gl_ModelViewMatrix? If this is the case, could I extract this value from the ModelView Matrix itself, perhaps?
The ModelView matrix is typically the concatenation of two matrices: the Model and the View. The Model matrix is the transform matrix of the currently rendered object, and the View matrix is the transform matrix of the camera.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement