Files
Ipseity-Demo/Assets/_Content/Shaders/Postprocess/EnkiBillalFullscreen.hlsl
T

74 lines
2.4 KiB
HLSL

#ifndef ENKI_BILLAL_FULLSCREEN_INCLUDED
#define ENKI_BILLAL_FULLSCREEN_INCLUDED
#include "Assets/_Content/Shaders/Include/Noises.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
// Gaussian blur on scene color
// blurRadius controls the spread in pixels — adjust to taste
float3 SampleSceneColorBlurred(float2 uv, float blurRadius)
{
float3 result = 0;
float totalWeight = 0;
// Gaussian weights for 5 samples (sigma ~ 1.0)
float weights[5] = { 0.0625, 0.25, 0.375, 0.25, 0.0625 };
float offsets[5] = { -2, -1, 0, 1, 2 };
float2 texelSize = blurRadius / _ScreenParams.xy;
// Horizontal pass
for (int i = 0; i < 5; i++)
{
float2 offsetUV = uv + float2(offsets[i] * texelSize.x, 0);
result += SAMPLE_TEXTURE2D_X(_CameraOpaqueTexture, sampler_LinearClamp, offsetUV).rgb * weights[i];
}
return result;
}
void EnkiBillalFullscreen_float
(
float2 UV,
out float3 Output
)
{
float2 screenUV = UV;
// DEPTH
float rawDepth = SampleSceneDepth(screenUV);
float depthMeters = LinearEyeDepth(rawDepth, _ZBufferParams); // linear eye-space depth in metres
float depth01 = Linear01Depth(rawDepth, _ZBufferParams); // normalised linear depth [0..1]
// POSITION WORLD SPACE
// Remap depth for non-reversed-Z platforms before reconstruction
float depthForReconstruct = rawDepth;
#if !UNITY_REVERSED_Z
depthForReconstruct = lerp(UNITY_NEAR_CLIP_VALUE, 1.0, rawDepth);
#endif
// ComputeWorldSpacePosition handles perspective divide and platform differences
float3 positionWS = ComputeWorldSpacePosition(screenUV, depthForReconstruct, UNITY_MATRIX_I_VP);
// NORMAL WORLD SPACE
// Requires DepthNormals PrePass to be enabled in the URP Renderer
float3 normalWS = SampleSceneNormals(screenUV);
// SCENE COLOR
float3 originColor = SampleSceneColor(screenUV);
float greyscale = (originColor.x + originColor.y + originColor.z) / 3.0;
float3 offsetUV = PerlinColor3D(positionWS * float3(1, 5, 1), 1) * smoothstep(smoothstep(20, 3, depthMeters), 1, greyscale) * .1 / depthMeters;
float3 sceneColor = SampleSceneColor(screenUV + offsetUV);
//float3 sceneColor = SAMPLE_TEXTURE2D_X(_CameraOpaqueTexture, sampler_PointClamp, screenUV).rgb;
// OUTPUT
Output = SampleSceneColorBlurred(screenUV, 10);
}
#endif