Jump to content
  • Advertisement
Sign in to follow this  
toneburst

OpenGL GLSL Equivalent to HLSL ViewInverse

This topic is 3314 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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!