- Home /
Plugging in screenPosition node`s A channel gives different result then plugging in an identical float value in shader graph.
Hello, I have a shader from shader graph that should make an object transparent then it is close to camera. It almost works, but the problem is, the shadow of the object seems to have an "offset" from the actual transparency of an object. The problem lies in the screen position node. If I set the camera in such a way, that "screen position" node's splitted A(1) channel returns a certain number (in example below it returns 2) and compare it to plugging in the exact same number, but strait from the float parameter, the shadow will behave differently. Hopefully the examples below will clear the picture. Let's compare two shaders, the only difference between those is one connection to "divide" node. Here is the first shader: Now let's see how it looks in the project: In the screenshot above the "distance" parameter is set to 2. The camera position doesn't matter, but I've put it in the position directly in front of the cube, with 2.5m offset from it. Meaning that the distance to cube's closest plane is 2m. (2.5m - half of the cube's size - 0.5) Now I change the "distance" node to "screen position" that gives the same number as described above (I've also tested a value with debug node, and It gave the same number).
The shader (only two images are allowed, so I`ve put remaining screenshots in dropbox): https://www.dropbox.com/s/f0ln6g3653mnd37/screenPositionNode.png?dl=0
And this is how it looks in the project: https://www.dropbox.com/s/c133fulazchf1h1/distance2automatic.png?dl=0
As you can see, the cubes look identical, but the shadows do not. And if I move the camera, the shadow will not correspond to the level of transparency of the cube, unlike if I change the distance variable from the script. In case of using screen position the shadow will not update at all. It only updates if I change the variable manually on the material itself.
Any ideas? I can provide more information if needed.
Edit: If I change screen position to Vector4 variable and change it`s W from the inspector the effect will be correct. It seems that there are some differences when changing the variable from the editor to changing it in the shader itself.
Answer by DenGrvubra · Apr 20 at 12:35 PM
I changed the screen position node to distance between camera and object, and now it works correctly. Still don't know why screen position node gives strange result in my case. Hopefully calculating distance my way is not more performance heavy.
Your answer
Follow this Question
Related Questions
No shadows when looking through a cutout shader 2 Answers
Transparent/diffuse using fullforwardshadows 0 Answers
Toon shader light culling shadow issue 0 Answers