Files
2025-07-20 19:03:25 +08:00

213 lines
6.0 KiB
Plaintext

Shader "Hidden/FullScreen/CustomCopy"
{
HLSLINCLUDE
ENDHLSL
SubShader
{
Pass
{
Name "Normal"
ZWrite Off
ZTest Always
Blend Off
Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma target 4.5
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl"
float4 _Scale;
float4 SampleBuffer(PositionInputs posInput);
float4 FullScreenPass(Varyings varyings) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(varyings);
float depth = LoadCameraDepth(varyings.positionCS.xy);
PositionInputs posInput = GetPositionInput(varyings.positionCS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
return SampleBuffer(posInput);
}
#pragma fragment FullScreenPass
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl"
float4 SampleBuffer(PositionInputs posInput)
{
NormalData normalData;
DecodeFromNormalBuffer(posInput.positionSS.xy*_Scale, normalData);//v1.0k
return float4(normalData.normalWS, 1);
}
ENDHLSL
}
Pass
{
Name "Roughness"
ZWrite Off
ZTest Always
Blend Off
Cull Off
HLSLPROGRAM
#pragma vertex Vert
#pragma target 4.5
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl"
float4 _Scale;
float4 SampleBuffer(PositionInputs posInput);
float4 FullScreenPass(Varyings varyings) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(varyings);
float depth = LoadCameraDepth(varyings.positionCS.xy);
PositionInputs posInput = GetPositionInput(varyings.positionCS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
return SampleBuffer(posInput);
}
#pragma fragment FullScreenPass
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl"
float4 SampleBuffer(PositionInputs posInput)
{
NormalData normalData;
DecodeFromNormalBuffer(posInput.positionSS.xy*_Scale, normalData);//v1.0k
return float4(normalData.perceptualRoughness, 0, 0, 1);
}
ENDHLSL
}
Pass
{
Name "Depth"
ZWrite Off
ZTest Always
Blend Off
Cull Off
HLSLPROGRAM
/*
//#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/API/D3D11.hlsl"
#include "UnityCG.cginc"
#pragma vertex vert
#pragma fragment frag
struct v2f
{
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
#if UNITY_UV_STARTS_AT_TOP
half4 uv2 : TEXCOORD1;
#endif
};
v2f vert(appdata_img v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = float4(v.texcoord.xy, 1, 1);
//o.uv = ComputeScreenPos(o.pos);
#if UNITY_UV_STARTS_AT_TOP
o.uv2 = float4(v.texcoord.xy, 1, 1);
//if (_MainTex_TexelSize.y < 0.0)
// o.uv.y = 1.0 - o.uv.y;
#endif
return o;
}
//sampler2D _CameraDepthTexture;
sampler2D sampler_CameraDepthTexture;
TEXTURE2D_ARRAY(_CameraDepthTexture);
//TEXTURE2D_SAMPLER2D(_CameraDepthTexture, sampler_CameraDepthTexture);
// float GetDepthTexture(float2 coord)
//{
//#if defined(UNITY_REVERSED_Z)
// return 1.0 - tex2Dlod(_CameraDepthTexture, float4(coord.x, coord.y, 0.0, 0.0)).x;
//#else
// return tex2Dlod(_CameraDepthTexture, float4(coord.x, coord.y, 0.0, 0.0)).x;
//#endif
// }
//#define LOAD_TEXTURE2D_ARRAY(textureName, unCoord2, index) textureName.Load(int4(unCoord2, index, 0))
//#define SAMPLE_DEPTH_TEXTURE(textureName, samplerName, coord2) SAMPLE_TEXTURE2D(textureName, samplerName, coord2).r
float4 frag(v2f input) : SV_Target
{
//float depth = GetDepthTexture(input.uv);
float2 uv = input.uv.xy / input.uv.w;
float depth = LOAD_TEXTURE2D_ARRAY(_CameraDepthTexture, uv* float2(1073,632),0 );// SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, uv);
//float depth = UNITY_SAMPLE_TEX2DARRAY_LOD(_CameraDepthTexture, float4(uv* float2(1073, 632),0,0),0);
//float depth = SAMPLE_DEPTH_TEXTURE_LOD(_CameraDepthTexture, sampler_CameraDepthTexture, uv* float2(1073, 632),0);
float linearDepth = 1-pow(Linear01Depth(depth),0.02);
return float4(1, 1, 1, 1)*linearDepth;
}
*/
#pragma vertex Vert
#pragma target 4.5
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl"
float4 _Scale;
float4 SampleBuffer(PositionInputs posInput);
float4 FullScreenPass(Varyings varyings) : SV_Target
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(varyings);
float depth = LoadCameraDepth(varyings.positionCS.xy);
PositionInputs posInput = GetPositionInput(varyings.positionCS.xy, _ScreenSize.zw, depth, UNITY_MATRIX_I_VP, UNITY_MATRIX_V);
float linearDepth = Linear01Depth(depth, _ZBufferParams);
return depth * float4(1, 1, 1, 1);
return SampleBuffer(posInput);
}
#pragma fragment FullScreenPass
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl"
// sampler2D _CameraDepthTexture;
float4 SampleBuffer(PositionInputs posInput)
{
return float4(posInput.linearDepth, 0, 0, 1);
}
ENDHLSL
}
}
Fallback Off
}