Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Matrix4x4 v = renderingData.cameraData.GetViewMatrix();
- Matrix4x4 p = renderingData.cameraData.GetProjectionMatrix();
- v.SetColumn(3, new Vector4(0, 0, 0, 1));
- Matrix4x4 vpInv = (p * v).inverse;
- float near = renderingData.cameraData.camera.nearClipPlane;
- Vector3 topLeftCorner = vpInv.MultiplyPoint(new Vector3(-1, 1, -1));
- Vector3 topRightCorner = vpInv.MultiplyPoint(new Vector3(1, 1, -1));
- Vector3 bottomLeftCorner = vpInv.MultiplyPoint(new Vector3(-1, -1, -1));
- Shader.SetGlobalVector(CamPosToNearLeftUpperVec, topLeftCorner);
- Shader.SetGlobalVector(NearTopLeftToTopRightVec, topRightCorner - topLeftCorner);
- Shader.SetGlobalVector(NearTopLeftToBottomLeftVec, bottomLeftCorner - topLeftCorner);
- Pass
- {
- HLSLPROGRAM
- #pragma vertex Vert
- #pragma fragment frag
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
- #include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
- float3 _CamPosToNearLeftUpperVec;
- float3 _NearTopLeftToTopRightVec;
- float3 _NearTopLeftToBottomLeftVec;
- float3 ReconstructPositionWS(float2 uv)
- {
- float depth = LinearEyeDepth(SampleSceneDepth(uv), _ZBufferParams);
- float3 positionWSIntersectWithNear =
- _CamPosToNearLeftUpperVec
- + uv.x * _NearTopLeftToTopRightVec
- + uv.y * _NearTopLeftToBottomLeftVec;
- // scalene triangle
- return depth / _ProjectionParams.y * positionWSIntersectWithNear + _WorldSpaceCameraPos;
- }
- float3 frag(Varyings IN) : SV_Target
- {
- return abs(ReconstructPositionWS(IN.texcoord));
- }
- ENDHLSL
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement