void SetPreconvolvedAmbientLightProbe(CommandBuffer cmd, float anisotropy) { SphericalHarmonicsL2 probeSH = SphericalHarmonicMath.UndoCosineRescaling(RenderSettings.ambientProbe); ZonalHarmonicsL2 phaseZH = ZonalHarmonicsL2.GetCornetteShanksPhaseFunction(anisotropy); SphericalHarmonicsL2 finalSH = SphericalHarmonicMath.PremultiplyCoefficients(SphericalHarmonicMath.Convolve(probeSH, phaseZH)); cmd.SetGlobalVectorArray(HDShaderIDs._AmbientProbeCoeffs, SphericalHarmonicMath.PackCoefficients(finalSH)); }
public static void GetCornetteShanksPhaseFunction(ZonalHarmonicsL2 zh, float anisotropy) { float g = anisotropy; zh.coeffs[0] = 0.282095f; zh.coeffs[1] = 0.293162f * g * (4.0f + (g * g)) / (2.0f + (g * g)); zh.coeffs[2] = (0.126157f + 1.44179f * (g * g) + 0.324403f * (g * g) * (g * g)) / (2.0f + (g * g)); }
public float[] coeffs; // Must have the size of 3 public static ZonalHarmonicsL2 GetHenyeyGreensteinPhaseFunction(float anisotropy) { float g = anisotropy; var zh = new ZonalHarmonicsL2(); zh.coeffs = new float[3]; zh.coeffs[0] = 0.5f * Mathf.Sqrt(1.0f / Mathf.PI); zh.coeffs[1] = 0.5f * Mathf.Sqrt(3.0f / Mathf.PI) * g; zh.coeffs[2] = 0.5f * Mathf.Sqrt(5.0f / Mathf.PI) * g * g; return(zh); }
public static ZonalHarmonicsL2 GetCornetteShanksPhaseFunction(float anisotropy) { float g = anisotropy; var zh = new ZonalHarmonicsL2(); zh.coeffs = new float[3]; zh.coeffs[0] = 0.282095f; zh.coeffs[1] = 0.293162f * g * (4.0f + (g * g)) / (2.0f + (g * g)); zh.coeffs[2] = (0.126157f + 1.44179f * (g * g) + 0.324403f * (g * g) * (g * g)) / (2.0f + (g * g)); return(zh); }
// Ref: "Stupid Spherical Harmonics Tricks", p. 6. public static SphericalHarmonicsL2 Convolve(SphericalHarmonicsL2 sh, ZonalHarmonicsL2 zh) { for (int l = 0; l <= 2; l++) { float n = Mathf.Sqrt((4.0f * Mathf.PI) / (2 * l + 1)); float k = zh.coeffs[l]; float p = n * k; for (int m = -l; m <= l; m++) { int i = l * (l + 1) + m; for (int c = 0; c < 3; c++) { sh[c, i] *= p; } } } return(sh); }
public void Build(HDRenderPipelineAsset asset) { m_SupportVolumetrics = asset.renderPipelineSettings.supportVolumetrics; if (!m_SupportVolumetrics) { return; } preset = asset.renderPipelineSettings.increaseResolutionOfVolumetrics ? VolumetricLightingPreset.High : VolumetricLightingPreset.Medium; m_VolumeVoxelizationCS = asset.renderPipelineResources.shaders.volumeVoxelizationCS; m_VolumetricLightingCS = asset.renderPipelineResources.shaders.volumetricLightingCS; m_PackedCoeffs = new Vector4[7]; m_PhaseZH = new ZonalHarmonicsL2(); m_PhaseZH.coeffs = new float[3]; m_xySeq = new Vector2[7]; m_xySeqOffset = new Vector4(); CreateBuffers(); }