浏览代码

Better HDRI sky integration formula

/main
Antoine Lelievre 6 年前
当前提交
da2ab148
共有 3 个文件被更改,包括 21 次插入6 次删除
  1. 1
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs
  2. 4
      com.unity.render-pipelines.high-definition/HDRP/Sky/HDRISky/HDRISkyRenderer.cs
  3. 22
      com.unity.render-pipelines.high-definition/HDRP/Sky/HDRISky/IntegrateHDRISky.shader

1
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs


public static readonly int _ThicknessRemap = Shader.PropertyToID("_ThicknessRemap");
public static readonly int _Cubemap = Shader.PropertyToID("_Cubemap");
public static readonly int _InvOmegaP = Shader.PropertyToID("_InvOmegaP");
public static readonly int _SkyParam = Shader.PropertyToID("_SkyParam");
public static readonly int _SkyIntensity = Shader.PropertyToID("_SkyIntensity");
public static readonly int _PixelCoordToViewDirWS = Shader.PropertyToID("_PixelCoordToViewDirWS");

4
com.unity.render-pipelines.high-definition/HDRP/Sky/HDRISky/HDRISkyRenderer.cs


{
using (new ProfilingSample(builtinParams.commandBuffer, "Get hdri skybox intensity"))
{
if (m_HdriSkyParams.updateHDRISkyIntensity)
// if (m_HdriSkyParams.updateHDRISkyIntensity)
float omegaP = (Mathf.PI * 4) / (6.0f * m_HdriSkyParams.hdriSky.value.width * m_HdriSkyParams.hdriSky.value.width);
m_IntegrateHDRISkyMaterial.SetFloat(HDShaderIDs._InvOmegaP, 1.0f / omegaP);
CoreUtils.SetRenderTarget(builtinParams.commandBuffer, m_IntensityTexture, ClearFlag.None);
CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_IntegrateHDRISkyMaterial);

22
com.unity.render-pipelines.high-definition/HDRP/Sky/HDRISky/IntegrateHDRISky.shader


{
[HideInInspector]
_Cubemap ("", CUBE) = "white" {}
_InvOmegaP ("", Float) = 0
}
SubShader

#pragma fragment Frag
#pragma target 4.5
#pragma only_renderers d3d11 ps4 xboxone vulkan metal switch
#pragma enable_d3d11_debug_symbols
#include "CoreRP/ShaderLibrary/Common.hlsl"
#include "CoreRP/ShaderLibrary/Color.hlsl"

};
TextureCube<float4> _Cubemap;
float _InvOmegaP;
Varyings Vert(Attributes input)
{

}
real IntegrateHDRISky(TEXTURECUBE_ARGS(skybox, sampler_skybox), real3 N, uint sampleCount = 8192)
real IntegrateHDRISky(TEXTURECUBE_ARGS(skybox, sampler_skybox), real3 N, uint sampleCount = 4096)
real2 randNum = InitRandom(0.5);
real2 randNum = InitRandom(0.0);
real3x3 localToWorld = GetLocalFrame(N);

real3 L;
ImportanceSampleLambert(u, localToWorld, L, NdotL, weightOverPdf);
real val = Luminance(SAMPLE_TEXTURECUBE_LOD(skybox, sampler_skybox, L, 0).rgb);
acc += PI * val;
real pdf = NdotL / PI;
real omegaS = rcp(sampleCount) * rcp(pdf);
// _InvOmegaP = rcp(FOUR_PI / (6.0 * cubemapWidth * cubemapWidth));
real mipLevel = 0.5 * log2(omegaS * _InvOmegaP);
if (NdotL > 0.0)
{
real val = Luminance(SAMPLE_TEXTURECUBE_LOD(skybox, sampler_skybox, L, mipLevel).rgb);
acc += PI * val;
}
}
return acc / sampleCount;

{
float3 N = float3(0.0, -1.0, 0.0);
float3 N = float3(0.0, 1.0, 0.0);
float intensity = IntegrateHDRISky(TEXTURECUBE_PARAM(_Cubemap, s_trilinear_clamp_sampler), N);

正在加载...
取消
保存