您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
96 行
3.4 KiB
96 行
3.4 KiB
Shader "Hidden/HDRenderPipeline/GGXConvolve"
|
|
{
|
|
SubShader
|
|
{
|
|
Pass
|
|
{
|
|
Cull Off
|
|
ZTest Always
|
|
ZWrite Off
|
|
Blend Off
|
|
|
|
HLSLPROGRAM
|
|
#pragma target 4.5
|
|
#pragma only_renderers d3d11 ps4 xboxone vulkan metal
|
|
|
|
#pragma multi_compile _ USE_MIS
|
|
|
|
#pragma vertex Vert
|
|
#pragma fragment Frag
|
|
|
|
#include "CoreRP/ShaderLibrary/Common.hlsl"
|
|
#include "CoreRP/ShaderLibrary/ImageBasedLighting.hlsl"
|
|
#include "GGXConvolution.cs.hlsl"
|
|
#include "../../ShaderVariables.hlsl"
|
|
|
|
TEXTURECUBE(_MainTex);
|
|
|
|
TEXTURE2D(_GgxIblSamples);
|
|
|
|
#ifdef USE_MIS
|
|
TEXTURE2D(_MarginalRowDensities);
|
|
TEXTURE2D(_ConditionalDensities);
|
|
#endif
|
|
|
|
float _Level;
|
|
float _InvOmegaP;
|
|
float4x4 _PixelCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
|
|
|
|
struct Attributes
|
|
{
|
|
uint vertexID : SV_VertexID;
|
|
};
|
|
|
|
struct Varyings
|
|
{
|
|
float4 positionCS : SV_POSITION;
|
|
};
|
|
|
|
Varyings Vert(Attributes input)
|
|
{
|
|
Varyings output;
|
|
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID);
|
|
return output;
|
|
}
|
|
|
|
float4 Frag(Varyings input) : SV_Target
|
|
{
|
|
// Points towards the camera
|
|
float3 viewDirWS = normalize(mul(float3(input.positionCS.xy, 1.0), (float3x3)_PixelCoordToViewDirWS));
|
|
// Reverse it to point into the scene
|
|
float3 N = -viewDirWS;
|
|
// Remove view-dependency from GGX, effectively making the BSDF isotropic.
|
|
float3 V = N;
|
|
|
|
float perceptualRoughness = MipmapLevelToPerceptualRoughness(_Level);
|
|
float roughness = PerceptualRoughnessToRoughness(perceptualRoughness);
|
|
uint sampleCount = GetIBLRuntimeFilterSampleCount(_Level);
|
|
|
|
#ifdef USE_MIS
|
|
float4 val = IntegrateLD_MIS(TEXTURECUBE_PARAM(_MainTex, s_trilinear_clamp_sampler),
|
|
_MarginalRowDensities, _ConditionalDensities,
|
|
V, N,
|
|
roughness,
|
|
_InvOmegaP,
|
|
LIGHTSAMPLINGPARAMETERS_TEXTURE_WIDTH,
|
|
LIGHTSAMPLINGPARAMETERS_TEXTURE_HEIGHT,
|
|
1024,
|
|
false);
|
|
#else
|
|
float4 val = IntegrateLD(TEXTURECUBE_PARAM(_MainTex, s_trilinear_clamp_sampler),
|
|
_GgxIblSamples,
|
|
V, N,
|
|
roughness,
|
|
_Level - 1,
|
|
_InvOmegaP,
|
|
sampleCount, // Must be a Fibonacci number
|
|
true,
|
|
true);
|
|
#endif
|
|
|
|
return val;
|
|
}
|
|
ENDHLSL
|
|
}
|
|
}
|
|
}
|