Glsl view/world/others matrix, names?

Hi, I’ve been getting a bit confused working with shaders in jme when it comes to names. In tutorials I keep seeing different names.

So for example, from the lighting shader

uniform mat4 g_WorldViewProjectionMatrix; I think this is called the ModelViewProjectionMatrix in opengl?

and so

uniform mat4 g_WorldViewMatrix; this would be the ModelViewMatrix?

What I want to do is find the position of the vertex being processed in the vertex shader. By position I ‘think’ I mean the world space position.

I’m assuming that

attribute vec3 inPosition;

is in object space, so I believe I need to multiply it by the ModelViewMatrix (so world in this case?), and then by the inverse ViewMatrix.

        vec4 posWorld = g_WorldViewMatrix * vec4(inPosition, 0.0);
	mat4 inv = inverse(g_ViewMatrix);
	posWorld = posWorld * inv;

This has not gone well for me, getting confused. Can anyone tell me where I am going wrong?

As the name implies, it transforms it into View space after transforming it into World space.

You want g_WorldMatrix if you only want “world” space.

You can see all of the different types available here:

…they just need to be enabled in the technique in your j3md file.

1 Like

Once upon a time I wrote a doc on this
See the arrows between the boxes, combine the matrix names to get whet you want.

1 Like

Wow, thats awesome, wish I had found that before posting. That’s solved it, and I totally understand it now. Thanks both of you.