You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.3 KiB
30 lines
1.3 KiB
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/EntityLighting.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinGIUtilities.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl"
|
|
|
|
#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch switch2
|
|
|
|
// Compute worldspace position and normal at given screenspace position and write it in the ResultBuffer
|
|
#pragma kernel ComputePositionNormal
|
|
|
|
RWStructuredBuffer<float4> _ResultBuffer;
|
|
uniform float4 _positionSS; // screenspace position
|
|
|
|
[numthreads(1,1,1)]
|
|
void ComputePositionNormal (uint3 id : SV_DispatchThreadID)
|
|
{
|
|
float deviceDepth = LOAD_TEXTURE2D_X(_CameraDepthTexture, _positionSS.xy).r;
|
|
|
|
float2 positionNDC = _positionSS.xy *_ScreenSize.zw + (0.5 * _ScreenSize.zw);
|
|
float3 positionWS = ComputeWorldSpacePosition(positionNDC, deviceDepth, UNITY_MATRIX_I_VP);
|
|
positionWS += _WorldSpaceCameraPos;
|
|
|
|
NormalData normalData;
|
|
DecodeFromNormalBuffer(_positionSS.xy, normalData);
|
|
float3 normalWS = normalData.normalWS;
|
|
|
|
_ResultBuffer[0] = float4(positionWS, 1.0f);
|
|
_ResultBuffer[1] = float4(normalWS, 0.0f);
|
|
}
|