Shader graph really needs a Position node for the fragment stage, where the value is read after the vertex displacement of the vertex stage.
This is one of the most glaring issues of 5.13 that I’m seeing. If I were to set the Position parameter in the vertex stage, and then access the position again during the fragment stage, the value I would receive would not be modified at all by the vertex stage. Rather, I would get the same fragment position value if I hadn’t updated the vertex position at all.
This also seems to be reflected in the Screen Position node, which means it’s very difficult to construct any shader that both displaces vertices and uses screen space effects.
I’m currently using a really gross workaround that only works on planes, and any other uniformly spaced geometry with integer vertex positions.
- Get the 4 surrounding vertex positions on each quad { (floor,floor) (floor,ceil) (ceil, floor) (ceil, ceil) }
- Offset the positions by the displacement function
- Determine which triangle the fragment is on (In my case, I compare (x - floor(x) > z - floor(z))
- Using a custom node, get the barycentric (triangle) coordinates of the fragment’s position What's the most efficient way to find barycentric coordinates? - Game Development Stack Exchange. This will be a Vector3 whos values add up to 1
- Multiply each vertex by its corresponding coordinate value (Vertex A * x, Vertex B * y, Vertex C * z).
- Add the scaled vertices together. This will finally return the actual displaced position on the mesh.
This is a lot of assumptions about the mesh, inefficient samples, and a ton of trial and error, just to adequately sample the Scene Depth on a vertex displaced shader.
Additionally, the current behaviour of the Position node goes against its documentation because of this issue. Position Node | Package Manager UI website
“Provides access to the mesh vertex or fragment’s Position, depending on the effective Shader Stage of the graph section the Node is part of.”
Perhaps this is unintended functionality, and it’ll be resolved in a future fix anyway. But if not, this would be extremely valuable.