Firstborn/Library/PackageCache/com.unity.render-pipelines..../ShaderLibrary/AmbientOcclusion.hlsl

69 lines
2.2 KiB
HLSL
Raw Normal View History

2023-03-28 13:24:16 -04:00
#ifndef AMBIENT_OCCLUSION_INCLUDED
#define AMBIENT_OCCLUSION_INCLUDED
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceData.hlsl"
// Ambient occlusion
TEXTURE2D_X(_ScreenSpaceOcclusionTexture);
SAMPLER(sampler_ScreenSpaceOcclusionTexture);
struct AmbientOcclusionFactor
{
half indirectAmbientOcclusion;
half directAmbientOcclusion;
};
half SampleAmbientOcclusion(float2 normalizedScreenSpaceUV)
{
float2 uv = UnityStereoTransformScreenSpaceTex(normalizedScreenSpaceUV);
return half(SAMPLE_TEXTURE2D_X(_ScreenSpaceOcclusionTexture, sampler_ScreenSpaceOcclusionTexture, uv).x);
}
AmbientOcclusionFactor GetScreenSpaceAmbientOcclusion(float2 normalizedScreenSpaceUV)
{
AmbientOcclusionFactor aoFactor;
#if defined(_SCREEN_SPACE_OCCLUSION) && !defined(_SURFACE_TYPE_TRANSPARENT)
float ssao = SampleAmbientOcclusion(normalizedScreenSpaceUV);
aoFactor.indirectAmbientOcclusion = ssao;
aoFactor.directAmbientOcclusion = lerp(half(1.0), ssao, _AmbientOcclusionParam.w);
#else
aoFactor.directAmbientOcclusion = 1;
aoFactor.indirectAmbientOcclusion = 1;
#endif
#if defined(DEBUG_DISPLAY)
switch(_DebugLightingMode)
{
case DEBUGLIGHTINGMODE_LIGHTING_WITHOUT_NORMAL_MAPS:
aoFactor.directAmbientOcclusion = 0.5;
aoFactor.indirectAmbientOcclusion = 0.5;
break;
case DEBUGLIGHTINGMODE_LIGHTING_WITH_NORMAL_MAPS:
aoFactor.directAmbientOcclusion *= 0.5;
aoFactor.indirectAmbientOcclusion *= 0.5;
break;
}
#endif
return aoFactor;
}
AmbientOcclusionFactor CreateAmbientOcclusionFactor(float2 normalizedScreenSpaceUV, half occlusion)
{
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(normalizedScreenSpaceUV);
aoFactor.indirectAmbientOcclusion = min(aoFactor.indirectAmbientOcclusion, occlusion);
return aoFactor;
}
AmbientOcclusionFactor CreateAmbientOcclusionFactor(InputData inputData, SurfaceData surfaceData)
{
return CreateAmbientOcclusionFactor(inputData.normalizedScreenSpaceUV, surfaceData.occlusion);
}
#endif