64 lines
2.4 KiB
Plaintext
64 lines
2.4 KiB
Plaintext
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Builtin/BuiltinData.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DynamicScalingClamping.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl"
|
|
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl"
|
|
|
|
#include "Packages/com.misaki.ao-volume/Runtime/Shader/Includes/VolumeData.cs.hlsl"
|
|
#include "Packages/com.misaki.ao-volume/Runtime/Shader/Includes/VolumeSDF.hlsl"
|
|
|
|
// Each #kernel tells which function to compile; you can have many kernels
|
|
#pragma kernel CSMain
|
|
|
|
StructuredBuffer<VolumeData> _VolumeDatas;
|
|
int _VolumeCount;
|
|
|
|
RW_TEXTURE2D_X(float, _AOVolumeBuffer);
|
|
|
|
float3 GetPositionWS(float2 positionSS, float depth)
|
|
{
|
|
float4 positionCS = float4(positionSS * 2.0f - 1.0f, depth * 2.0f - 1.0f, 1.0f);
|
|
float4 positionWS = mul(UNITY_MATRIX_I_VP, positionCS);
|
|
positionWS /= positionWS.w;
|
|
|
|
return positionWS.xyz;
|
|
}
|
|
|
|
float3 GetNormalWS(float2 positionSS)
|
|
{
|
|
float4 normalBufferData = LOAD_TEXTURE2D_X(_NormalBufferTexture, positionSS);
|
|
|
|
NormalData normalData;
|
|
DecodeFromNormalBuffer(normalBufferData, normalData);
|
|
|
|
return normalData.normalWS.xyz;
|
|
}
|
|
|
|
[numthreads(8,8,1)]
|
|
void CSMain(uint3 dispatchThreadId : SV_DispatchThreadID)
|
|
{
|
|
UNITY_XR_ASSIGN_VIEW_INDEX(dispatchThreadId.z);
|
|
|
|
float depth = LoadCameraDepth(dispatchThreadId.xy);
|
|
float3 positionWS = ComputeWorldSpacePosition(dispatchThreadId.xy / _ScreenSize.xy, depth, UNITY_MATRIX_I_VP); // This cloud be camera-relative position
|
|
float3 normalWS = GetNormalWS(dispatchThreadId.xy);
|
|
|
|
float aoVolumeMask = 0.0;
|
|
float gtao = LOAD_TEXTURE2D_X(_AmbientOcclusionTexture, dispatchThreadId.xy).x;
|
|
|
|
// TODO: Tile/H-z optmization
|
|
int i = 0;
|
|
while (i < _VolumeCount)
|
|
{
|
|
VolumeData volumeData = _VolumeDatas[i];
|
|
|
|
aoVolumeMask += EvaluateAOVolumeMask(volumeData, positionWS, normalWS);
|
|
|
|
i++;
|
|
}
|
|
|
|
// GTAO is output in the format that 1 is full occusion, 0 is no occlusion
|
|
_AOVolumeBuffer[COORD_TEXTURE2D_X(dispatchThreadId.xy)] = lerp(gtao, 1.0, saturate(aoVolumeMask));
|
|
//_AOVolumeBuffer[COORD_TEXTURE2D_X(dispatchThreadId.xy)] = positionWS.y;
|
|
} |