浏览代码

Updated HDRI sky integration

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

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


TEXTURE2D(_SkyIntensity);
SAMPLER(sampler_SkyIntensity);
float4 _SkyParam; // x exposure, y multiplier, z rotation
float4 _SkyParam; // x exposure, y multiplier, z rotation, w lux
float4x4 _PixelCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
struct Attributes

float3 rotDirY = float3(sinPhi, 0, cosPhi);
dir = float3(dot(rotDirX, dir), dir.y, dot(rotDirY, dir));
float intensity = _SkyParam.w / SAMPLE_TEXTURE2D_LOD(_SkyIntensity, sampler_SkyIntensity, float2(.5, .5), 0).x;
float intensity = _SkyParam.w / SAMPLE_TEXTURE2D_LOD(_SkyIntensity, sampler_SkyIntensity, float2(0.5, 0.5), 0).x;
float3 skyColor = ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb * exp2(_SkyParam.x) * _SkyParam.y * intensity);
return float4(skyColor, 1.0);
}

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


}
real IntegrateHDRISky(TEXTURECUBE_ARGS(skybox, sampler_skybox), real3 N, uint sampleCount = 8192)
{
real acc = 0.0;
real IntegrateHDRISky(TEXTURECUBE_ARGS(skybox, sampler_skybox), real3 N, uint sampleCount = 8192)
{
real acc = 0.0;
// Add some jittering on Hammersley2d
real2 randNum = InitRandom(0.5);
// Add some jittering on Hammersley2d
real2 randNum = InitRandom(0.5);
real3x3 localToWorld = GetLocalFrame(N);
real3x3 localToWorld = GetLocalFrame(N);
for (uint i = 0; i < sampleCount; ++i)
{
real2 u = frac(randNum + Hammersley2d(i, sampleCount));
for (uint i = 0; i < sampleCount; ++i)
{
real2 u = frac(randNum + Hammersley2d(i, sampleCount));
real NdotL;
real weightOverPdf;
real3 L;
ImportanceSampleLambert(u, localToWorld, L, NdotL, weightOverPdf);
real val = Luminance(SAMPLE_TEXTURECUBE_LOD(skybox, sampler_skybox, L, 0).rgb);
acc += NdotL * val;
}
real NdotL;
real weightOverPdf;
real3 L;
ImportanceSampleLambert(u, localToWorld, L, NdotL, weightOverPdf);
real val = Luminance(SAMPLE_TEXTURECUBE_LOD(skybox, sampler_skybox, L, 0).rgb);
acc += PI * val;
}
return acc / sampleCount;
}
return acc / sampleCount;
}
float3 N = float3(0.0, 0.0, 1.0);
float3 N = float3(0.0, -1.0, 0.0);
float intensity = IntegrateHDRISky(TEXTURECUBE_PARAM(_Cubemap, s_trilinear_clamp_sampler), N);

正在加载...
取消
保存