z3y / ShaderGraph

Shader Graph target for the Unity built-in pipeline
MIT License
70 stars 2 forks source link

Scene Depth node with Sampling Eye throws shader error #8

Closed Krysiek closed 3 months ago

Krysiek commented 4 months ago

When I use Scene Depth node and set Sampling to Eye I've got shader errors. The shader does not work and turns into pink color.

Errors do not occur when Sampling is set to Raw or Linear01.

obraz

Example shader:

obraz

Fresh World project created with VRChat Creator Companion. Unity version: 2022.3.22f Shader Graph package: 14.0.10 Shader Graph Target (z3y): 1.0.3

z3y commented 4 months ago

Its probably related to Grab Pass / Screen Color node is broken in VR as well because of the way shader graph calculates screen position. I don't really understand all the sampling modes, or if it can even work properly in built-in in VR this way.

MidwayMarshall commented 3 months ago

Certainly not an expert in C#/Shaders but it seems to stem from the Orthographic branch ("unity_OrthoParams.w is 1.0 when camera is orthographic, 0.0 when perspective.") of this if/else statement. image

VR should always be in perspective mode anyways so I just deleted it from SceneDepthNode.cs in the ShaderGraph package and it worked for me. (alternatively maybe you could patch UNITY_MATRIX_I_VP to be UNITY_MATRIX_I_V * UNITY_MATRIX_P to stop the orthographic section without throwing an error)

image

Previews with no error and seems to work correctly in scene view

image

image

z3y commented 3 months ago

Im glad that you figured it out! I was afraid it would be something in the main package, I'll see if I can fix it still, thanks. Just keep in mind the error might have went away, but it doesnt guarantee that the node output is accurate.

z3y commented 3 months ago

Thats fixed the error, but it still wasnt working properly. I've fixed this issue entirely it should be working now.