Optimize ProbesFilter shader
This commit is contained in:
@@ -9,21 +9,9 @@ META_CB_BEGIN(0, Data)
|
||||
float2 Dummy0;
|
||||
int CubeFace;
|
||||
int SourceMipIndex;
|
||||
float4 Sample01;
|
||||
float4 Sample23;
|
||||
float4 CoefficientMask0;
|
||||
float4 CoefficientMask1;
|
||||
float3 Dummy1;
|
||||
float CoefficientMask2;
|
||||
META_CB_END
|
||||
|
||||
TextureCube Cube : register(t0);
|
||||
Texture2D Image : register(t1);
|
||||
|
||||
float4 SampleCubemap(float3 uv)
|
||||
{
|
||||
return Cube.SampleLevel(SamplerLinearClamp, uv, SourceMipIndex);
|
||||
}
|
||||
|
||||
float3 UvToCubeMapUv(float2 uv)
|
||||
{
|
||||
@@ -81,82 +69,10 @@ float4 PS_FilterFace(Quad_VS2PS input) : SV_Target
|
||||
BRANCH
|
||||
if (NoL > 0)
|
||||
{
|
||||
filteredColor += SampleCubemap(L) * NoL;
|
||||
filteredColor += Cube.SampleLevel(SamplerLinearClamp, L, SourceMipIndex) * NoL;
|
||||
weight += NoL;
|
||||
}
|
||||
}
|
||||
|
||||
return filteredColor / max(weight, 0.001);
|
||||
}
|
||||
|
||||
// Pixel Shader for coping probe face
|
||||
META_PS(true, FEATURE_LEVEL_ES2)
|
||||
float4 PS_CopyFace(Quad_VS2PS input) : SV_Target
|
||||
{
|
||||
return Image.SampleLevel(SamplerLinearClamp, input.TexCoord, 0);
|
||||
}
|
||||
|
||||
// Pixel Shader for calculating Diffuse Irradiance
|
||||
META_PS(true, FEATURE_LEVEL_ES2)
|
||||
float4 PS_CalcDiffuseIrradiance(Quad_VS2PS input) : SV_Target
|
||||
{
|
||||
float2 uv = input.TexCoord * 2 - 1;
|
||||
float3 cubeCoordinates = normalize(UvToCubeMapUv(uv));
|
||||
float squaredUVs = 1 + dot(uv, uv);
|
||||
float weight = 4 / (sqrt(squaredUVs) * squaredUVs);
|
||||
|
||||
ThreeBandSHVector shCoefficients = SHBasisFunction3(cubeCoordinates);
|
||||
float currentSHCoefficient = dot(shCoefficients.V0, CoefficientMask0) + dot(shCoefficients.V1, CoefficientMask1) + shCoefficients.V2 * CoefficientMask2;
|
||||
|
||||
float3 radiance = SampleCubemap(cubeCoordinates).rgb;
|
||||
return float4(radiance * currentSHCoefficient * weight, weight);
|
||||
}
|
||||
|
||||
// Pixel Shader for accumulating Diffuse Irradiance
|
||||
META_PS(true, FEATURE_LEVEL_ES2)
|
||||
float4 PS_AccDiffuseIrradiance(Quad_VS2PS input) : SV_Target
|
||||
{
|
||||
float4 result = 0;
|
||||
{
|
||||
float2 uv = saturate(input.TexCoord + Sample01.xy) * 2 - 1;
|
||||
float3 cubeCoordinates = UvToCubeMapUv(uv);
|
||||
result += SampleCubemap(cubeCoordinates);
|
||||
}
|
||||
{
|
||||
float2 uv = saturate(input.TexCoord + Sample01.zw) * 2 - 1;
|
||||
float3 cubeCoordinates = UvToCubeMapUv(uv);
|
||||
result += SampleCubemap(cubeCoordinates);
|
||||
}
|
||||
{
|
||||
float2 uv = saturate(input.TexCoord + Sample23.xy) * 2 - 1;
|
||||
float3 cubeCoordinates = UvToCubeMapUv(uv);
|
||||
result += SampleCubemap(cubeCoordinates);
|
||||
}
|
||||
{
|
||||
float2 uv = saturate(input.TexCoord + Sample23.zw) * 2 - 1;
|
||||
float3 cubeCoordinates = UvToCubeMapUv(uv);
|
||||
result += SampleCubemap(cubeCoordinates);
|
||||
}
|
||||
return result / 4.0f;
|
||||
}
|
||||
|
||||
// Pixel Shader for accumulating cube faces into one pixel
|
||||
META_PS(true, FEATURE_LEVEL_ES2)
|
||||
float4 PS_AccumulateCubeFaces(Quad_VS2PS input) : SV_Target
|
||||
{
|
||||
float4 result = SampleCubemap(float3(1, 0, 0));
|
||||
result += SampleCubemap(float3(-1, 0, 0));
|
||||
result += SampleCubemap(float3(0, 1, 0));
|
||||
result += SampleCubemap(float3(0, -1, 0));
|
||||
result += SampleCubemap(float3(0, 0, 1));
|
||||
result += SampleCubemap(float3(0, 0, -1));
|
||||
return float4((4 * PI) * result.rgb / max(result.a, 0.00001f), 0);
|
||||
}
|
||||
|
||||
// Pixel Shader for copying frame to cube face with setting lower hemisphere to black
|
||||
META_PS(true, FEATURE_LEVEL_ES2)
|
||||
float4 PS_CopyFrameLHB(Quad_VS2PS input) : SV_Target
|
||||
{
|
||||
float mask = input.TexCoord.y < 0.5;// TODO: make is smooth (and branchless using function)
|
||||
return float4(Image.SampleLevel(SamplerLinearClamp, input.TexCoord, 0).xyz * mask * CoefficientMask2, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user