赞
踩
看了好久的体积光教程,始终卡在重建世界坐标这一步,今天照着官方代码误打误撞弄出来了。
单纯记录一下实现代码及结果,具体实现逻辑还有点懵。
- Shader "shaderName"
- {
- Properties{}
- SubShader
- {
- Tags { "RenderType"="Opaque" "RenderPipeline" = "UniversalPipeline"}
- Cull Off ZWrite Off ZTest Always
-
- Pass
- {
- HLSLPROGRAM
- #pragma vertex vert
- #pragma fragment frag
-
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
-
- struct appdata
- {
- float4 vertex : POSITION;
- };
-
- struct v2f
- {
- float4 vertex : SV_POSITION;
- };
-
- v2f vert (appdata v)
- {
- v2f o;
- o.vertex = TransformObjectToHClip(v.vertex);
- return o;
- }
-
- half4 frag (v2f i) : SV_Target
- {
- float2 UV = i.vertex.xy / _ScaledScreenParams.xy;
- #if UNITY_REVERSED_Z
- real depth = SampleSceneDepth(UV);
- #else
- real depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, SampleSceneDepth(UV));
- #endif
- float3 worldPos = ComputeWorldSpacePosition(UV, depth, UNITY_MATRIX_I_VP);
-
- return half4(worldPos,1);
- }
-
- ENDHLSL
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。