Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ internal enum ProbeVolumeAtlasSliceMode
IrradianceSH1_1,
IrradianceSH10,
IrradianceSH11,
IrradianceSH2_2,
IrradianceSH2_1,
IrradianceSH20,
IrradianceSH21,
IrradianceSH22,
Validity,
OctahedralDepth
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@
#define PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH1_1 (1)
#define PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH10 (2)
#define PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH11 (3)
#define PROBEVOLUMEATLASSLICEMODE_VALIDITY (4)
#define PROBEVOLUMEATLASSLICEMODE_OCTAHEDRAL_DEPTH (5)
#define PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH2_2 (4)
#define PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH2_1 (5)
#define PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH20 (6)
#define PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH21 (7)
#define PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH22 (8)
#define PROBEVOLUMEATLASSLICEMODE_VALIDITY (9)
#define PROBEVOLUMEATLASSLICEMODE_OCTAHEDRAL_DEPTH (10)


#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Shader "Hidden/ScriptableRenderPipeline/DebugDisplayProbeVolume"

#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/Lighting/ProbeVolume/ProbeVolumeShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeAtlas.hlsl"

#define DEBUG_DISPLAY
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.hlsl"
Expand All @@ -18,12 +20,6 @@ Shader "Hidden/ScriptableRenderPipeline/DebugDisplayProbeVolume"
int _ProbeVolumeAtlasSliceMode;
// float _RcpGlobalScaleFactor;
SamplerState ltc_linear_clamp_sampler;
TEXTURE3D(_AtlasTextureSH);

#if SHADEROPTIONS_PROBE_VOLUMES_BILATERAL_FILTERING == PROBEVOLUMESBILATERALFILTERINGMODES_OCTAHEDRAL_DEPTH
TEXTURE2D(_AtlasTextureOctahedralDepth);
float4 _AtlasTextureOctahedralDepthScaleBias;
#endif

struct Attributes
{
Expand Down Expand Up @@ -76,10 +72,37 @@ Shader "Hidden/ScriptableRenderPipeline/DebugDisplayProbeVolume"
// Convert to specific view section of atlas.
uvw = uvw * _TextureViewScale + _TextureViewBias;

float4 valueShAr = saturate((SAMPLE_TEXTURE3D_LOD(_AtlasTextureSH, ltc_linear_clamp_sampler, float3(uvw.x, uvw.y, uvw.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 0), 0) - _ValidRange.x) * _ValidRange.y);
float4 valueShAg = saturate((SAMPLE_TEXTURE3D_LOD(_AtlasTextureSH, ltc_linear_clamp_sampler, float3(uvw.x, uvw.y, uvw.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 1), 0) - _ValidRange.x) * _ValidRange.y);
float4 valueShAb = saturate((SAMPLE_TEXTURE3D_LOD(_AtlasTextureSH, ltc_linear_clamp_sampler, float3(uvw.x, uvw.y, uvw.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 2), 0) - _ValidRange.x) * _ValidRange.y);
float valueValidity = saturate((SAMPLE_TEXTURE3D_LOD(_AtlasTextureSH, ltc_linear_clamp_sampler, float3(uvw.x, uvw.y, uvw.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 3), 0).x - _ValidRange.x) * _ValidRange.y);
#if SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L1
ProbeVolumeSphericalHarmonicsL1 coefficients;
ZERO_INITIALIZE(ProbeVolumeSphericalHarmonicsL1, coefficients);
ProbeVolumeSampleAccumulateSphericalHarmonicsL1(uvw, 1.0f, coefficients);
ProbeVolumeSwizzleAndNormalizeSphericalHarmonicsL1(coefficients);
float4 valueShAr = saturate((coefficients.data[0] - _ValidRange.x) * _ValidRange.y);
float4 valueShAg = saturate((coefficients.data[1] - _ValidRange.x) * _ValidRange.y);
float4 valueShAb = saturate((coefficients.data[2] - _ValidRange.x) * _ValidRange.y);

float4 valueShBr = 0.0f;
float4 valueShBg = 0.0f;
float4 valueShBb = 0.0f;
float4 valueShC = 0.0f;

#elif SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L2
ProbeVolumeSphericalHarmonicsL2 coefficients;
ZERO_INITIALIZE(ProbeVolumeSphericalHarmonicsL2, coefficients);
ProbeVolumeSampleAccumulateSphericalHarmonicsL2(uvw, 1.0f, coefficients);
ProbeVolumeSwizzleAndNormalizeSphericalHarmonicsL2(coefficients);
float4 valueShAr = saturate((coefficients.data[0] - _ValidRange.x) * _ValidRange.y);
float4 valueShAg = saturate((coefficients.data[1] - _ValidRange.x) * _ValidRange.y);
float4 valueShAb = saturate((coefficients.data[2] - _ValidRange.x) * _ValidRange.y);

float4 valueShBr = saturate((coefficients.data[3] - _ValidRange.x) * _ValidRange.y);
float4 valueShBg = saturate((coefficients.data[4] - _ValidRange.x) * _ValidRange.y);
float4 valueShBb = saturate((coefficients.data[5] - _ValidRange.x) * _ValidRange.y);
float4 valueShC = saturate((coefficients.data[6] - _ValidRange.x) * _ValidRange.y);

#endif

float valueValidity = saturate((ProbeVolumeSampleValidity(uvw) - _ValidRange.x) * _ValidRange.y);

#if SHADEROPTIONS_PROBE_VOLUMES_BILATERAL_FILTERING == PROBEVOLUMESBILATERALFILTERINGMODES_OCTAHEDRAL_DEPTH
float2 valueOctahedralDepthMeanAndVariance = saturate((SAMPLE_TEXTURE2D_LOD(_AtlasTextureOctahedralDepth, ltc_linear_clamp_sampler, input.texcoord * _AtlasTextureOctahedralDepthScaleBias.xy + _AtlasTextureOctahedralDepthScaleBias.zw, 0).xy - _ValidRange.x) * _ValidRange.y);
Expand All @@ -90,22 +113,47 @@ Shader "Hidden/ScriptableRenderPipeline/DebugDisplayProbeVolume"
case PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH00:
{

return float4(valueShAr.x, valueShAg.x, valueShAb.x, 1);
return float4(valueShAr.w, valueShAg.w, valueShAb.w, 1);
}

case PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH1_1:
{
return float4(valueShAr.y, valueShAg.y, valueShAb.y, 1);
return float4(valueShAr.x, valueShAg.x, valueShAb.x, 1);
}

case PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH10:
{
return float4(valueShAr.z, valueShAg.z, valueShAb.z, 1);
return float4(valueShAr.y, valueShAg.y, valueShAb.y, 1);
}

case PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH11:
{
return float4(valueShAr.w, valueShAg.w, valueShAb.w, 1);
return float4(valueShAr.z, valueShAg.z, valueShAb.z, 1);
}

case PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH2_2:
{
return float4(valueShBr.x, valueShBg.x, valueShBb.x, 1);
}

case PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH2_1:
{
return float4(valueShBr.y, valueShBg.y, valueShBb.y, 1);
}

case PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH20:
{
return float4(valueShBr.z, valueShBg.z, valueShBb.z, 1);
}

case PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH21:
{
return float4(valueShBr.w, valueShBg.w, valueShBb.w, 1);
}

case PROBEVOLUMEATLASSLICEMODE_IRRADIANCE_SH22:
{
return float4(valueShC.x, valueShC.y, valueShC.z, 1);
}

case PROBEVOLUMEATLASSLICEMODE_VALIDITY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Packing.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolume.cs.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeLightLoopDef.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/ProbeVolume/ProbeVolumeAtlas.hlsl"

// Copied from VolumeVoxelization.compute
float ProbeVolumeComputeFadeFactor(
Expand All @@ -23,28 +24,6 @@ float ProbeVolumeComputeFadeFactor(
return dstF * fade;
}

float ProbeVolumeSampleValidity(float3 probeVolumeAtlasUVW)
{
#if SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L1
return SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 3), 0).x;
#elif SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L2
return SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 6), 0).w;
#else
return 0.0;
#endif
}

float ProbeVolumeLoadValidity(int3 probeVolumeAtlasTexelCoord)
{
#if SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L1
return LOAD_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, int3(probeVolumeAtlasTexelCoord.x, probeVolumeAtlasTexelCoord.y, probeVolumeAtlasTexelCoord.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 3), 0).x;
#elif SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L2
return LOAD_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, int3(probeVolumeAtlasTexelCoord.x, probeVolumeAtlasTexelCoord.y, probeVolumeAtlasTexelCoord.z + _ProbeVolumeAtlasResolutionAndSliceCount.z * 6), 0).w;
#else
return 0.0;
#endif
}

#if SHADEROPTIONS_PROBE_VOLUMES_BILATERAL_FILTERING == PROBEVOLUMESBILATERALFILTERINGMODES_OCTAHEDRAL_DEPTH
void ProbeVolumeEvaluateOctahedralDepthOcclusionFilterWeights(
out float weights[8],
Expand Down Expand Up @@ -368,120 +347,6 @@ float3 ProbeVolumeComputeTexel3DFromBilateralFilter(
#endif
}

struct ProbeVolumeSphericalHarmonicsL0
{
float4 data[1];
};

struct ProbeVolumeSphericalHarmonicsL1
{
float4 data[3];
};

struct ProbeVolumeSphericalHarmonicsL2
{
float4 data[7];
};

// See ProbeVolumeAtlasBlit.compute for atlas coefficient layout information.
void ProbeVolumeSampleAccumulateSphericalHarmonicsL0(float3 probeVolumeAtlasUVW, float weight, inout ProbeVolumeSphericalHarmonicsL0 coefficients)
{
coefficients.data[0].xyz += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 0), 0).xyz * weight;
}

void ProbeVolumeSampleAccumulateSphericalHarmonicsL1(float3 probeVolumeAtlasUVW, float weight, inout ProbeVolumeSphericalHarmonicsL1 coefficients)
{
#if SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L1 || SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L2
coefficients.data[0] += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 0), 0) * weight;
coefficients.data[1] += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 1), 0) * weight;
coefficients.data[2] += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 2), 0) * weight;
#endif
}

void ProbeVolumeSampleAccumulateSphericalHarmonicsL2(float3 probeVolumeAtlasUVW, float weight, inout ProbeVolumeSphericalHarmonicsL2 coefficients)
{
#if SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L1
// Requesting SH2, but atlas only contains SH1.
// Only accumulate SH1 coefficients.
coefficients.data[0] += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 0), 0) * weight;
coefficients.data[1] += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 1), 0) * weight;
coefficients.data[2] += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 2), 0) * weight;

#elif SHADEROPTIONS_PROBE_VOLUMES_ENCODING_MODE == PROBEVOLUMESENCODINGMODES_SPHERICAL_HARMONICS_L2
coefficients.data[0] += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 0), 0) * weight;
coefficients.data[1] += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 1), 0) * weight;
coefficients.data[2] += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 2), 0) * weight;

coefficients.data[3] += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 3), 0) * weight;
coefficients.data[4] += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 4), 0) * weight;
coefficients.data[5] += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 5), 0) * weight;

coefficients.data[6].xyz += SAMPLE_TEXTURE3D_LOD(_ProbeVolumeAtlasSH, s_linear_clamp_sampler, float3(probeVolumeAtlasUVW.x, probeVolumeAtlasUVW.y, probeVolumeAtlasUVW.z + _ProbeVolumeAtlasResolutionAndSliceCountInverse.w * 6), 0).xyz * weight;
#endif
}


// Utility functions for converting from atlas coefficients layout, into the layout that our EntityLighting.hlsl evaluation functions expect.
void ProbeVolumeSwizzleAndNormalizeSphericalHarmonicsL0(inout ProbeVolumeSphericalHarmonicsL0 coefficients)
{
// Nothing to do here. DC terms are already normalized and stored in RGB order.
}

void ProbeVolumeSwizzleAndNormalizeSphericalHarmonicsL1(inout ProbeVolumeSphericalHarmonicsL1 coefficients)
{
#ifdef DEBUG_DISPLAY
if (_DebugProbeVolumeMode == PROBEVOLUMEDEBUGMODE_VISUALIZE_DEBUG_COLORS || _DebugProbeVolumeMode == PROBEVOLUMEDEBUGMODE_VISUALIZE_VALIDITY)
{
// coefficients are storing debug info. Do not swizzle or normalize.
return;
}
#endif

// SHEvalLinearL0L1() expects coefficients in real4 shAr, real4 shAg, real4 shAb vectors whos channels are laid out {x, y, z, DC}
float4 shAr = float4(coefficients.data[0].w, coefficients.data[1].x, coefficients.data[1].y, coefficients.data[0].x);
float4 shAg = float4(coefficients.data[1].z, coefficients.data[1].w, coefficients.data[2].x, coefficients.data[0].y);
float4 shAb = float4(coefficients.data[2].y, coefficients.data[2].z, coefficients.data[2].w, coefficients.data[0].z);

coefficients.data[0] = shAr;
coefficients.data[1] = shAg;
coefficients.data[2] = shAb;
}

void ProbeVolumeSwizzleAndNormalizeSphericalHarmonicsL2(inout ProbeVolumeSphericalHarmonicsL2 coefficients)
{
#ifdef DEBUG_DISPLAY
if (_DebugProbeVolumeMode == PROBEVOLUMEDEBUGMODE_VISUALIZE_DEBUG_COLORS || _DebugProbeVolumeMode == PROBEVOLUMEDEBUGMODE_VISUALIZE_VALIDITY)
{
// coefficients are storing debug info. Do not swizzle or normalize.
return;
}
#endif

// SampleSH9() expects coefficients in shAr, shAg, shAb, shBr, shBg, shBb, shCr vectors.
float4 shAr = float4(coefficients.data[0].w, coefficients.data[1].x, coefficients.data[1].y, coefficients.data[0].x);
float4 shAg = float4(coefficients.data[1].z, coefficients.data[1].w, coefficients.data[2].x, coefficients.data[0].y);
float4 shAb = float4(coefficients.data[2].y, coefficients.data[2].z, coefficients.data[2].w, coefficients.data[0].z);

coefficients.data[0] = shAr;
coefficients.data[1] = shAg;
coefficients.data[2] = shAb;

// coefficients[3] through coefficients[6] are already laid out in shBr, shBg, shBb, shCr order.
// Now just need to perform final SH2 normalization:
// Again, normalization from: https://www.ppsloan.org/publications/StupidSH36.pdf
// Appendix A10 Shader/CPU code for Irradiance Environment Maps

// Normalize DC term:
coefficients.data[0].w -= coefficients.data[3].z;
coefficients.data[1].w -= coefficients.data[4].z;
coefficients.data[2].w -= coefficients.data[5].z;

// Normalize Quadratic term:
coefficients.data[3].z *= 3.0;
coefficients.data[4].z *= 3.0;
coefficients.data[5].z *= 3.0;
}

float3 ProbeVolumeEvaluateSphericalHarmonicsL0(float3 normalWS, ProbeVolumeSphericalHarmonicsL0 coefficients)
{

Expand Down
Loading