0
$\begingroup$

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?

$\endgroup$
0
$\begingroup$

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.

enter image description here

$\endgroup$
3
  • $\begingroup$ 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? $\endgroup$
    – jjcasmar
    Dec 21 '19 at 16:08
  • $\begingroup$ Just trying to recreate your GSL code from my limited understanding. Isn't that what modelView * vertexNormal does? $\endgroup$ Dec 22 '19 at 2:19
  • $\begingroup$ ModelView * vertexNormal is the cameea space normal. I'm not sure how that is achieved with that graph. $\endgroup$
    – jjcasmar
    Dec 22 '19 at 11:22
0
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.