# screen space position in material graph

I have a GLSL vertex shader which computes cameraspace normal and screen space position and then it uses them to compute other values.

vec3 n = (modelView * vec4(vertexNormal, 0.0)).xyz;
vec3 p = (mvp * vec4(vertexPosition, 0.0f)).xyz;
vec3 w = n+p; (for example)


I am trying to replicate this shader in an eevee material graph but I'm not sure how can I get screen space and camera space data. Is this posible?

You can get camera space coordinates from the Input > Texture Coordinates node using the Camera or Window socket, depending on what you are looking for.

The same node provides local position for vertex using the Object socket, you can convert to world coordinates using a Vector Transform node.

Using the Vector Math node you can do the required matrix calculations.

If I interpreted your code right you should need something along the lines of the node tree below.

• I get that screen space vertex position (mvp* vertexPosition) is the window output from Texture Coordinate node, but Im not sure how you are getting the camera space normal (modelView * vertexNormal). You are doing a cross product between the world normal and the screen space position, but I completely miss what that means. Can you explain a bit more please? Dec 21 '19 at 16:08
• Just trying to recreate your GSL code from my limited understanding. Isn't that what modelView * vertexNormal does? Dec 22 '19 at 2:19
• ModelView * vertexNormal is the cameea space normal. I'm not sure how that is achieved with that graph. Dec 22 '19 at 11:22

The world normal and the world position (and some other geometry data) can be retrieved from the Geometry input node.

There is also a VectorTransform node which can convert a point, a vector or a normal from object (local), world or camera spaces to object, world or camera space. With that, it's very easy to compute camera space normal.

Finally, to get screen space data, the TextureCoordinate node can be used. It has several outputs: Normal is the object space normals, Camera is the camera space positions and Window is the screen space position (after projection) from 0 to 1.