浏览代码

HDRenderLoop: Add concept of lightLoopContext to handle various sampling scheme

/main
sebastienlagarde 8 年前
当前提交
8cf763ef
共有 4 个文件被更改,包括 45 次插入16 次删除
  1. 18
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.hlsl
  2. 21
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePassLoop.hlsl
  3. 20
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl
  4. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl

18
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePass.hlsl


// Use texture array for reflection
UNITY_DECLARE_TEXCUBEARRAY(_EnvTextures);
UNITY_DECLARE_TEXCUBE(_SkyTexture);
#define SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES 0
#define SINGLE_PASS_CONTEXT_SAMPLE_SKY 1
float4 SampleEnv(int envIndex, float3 dirWS, float lod)
float4 SampleEnv(int lightLoopContext, int envIndex, float3 dirWS, float lod)
return UNITY_SAMPLE_TEXCUBEARRAY_LOD(_EnvTextures, float4(dirWS, envIndex), lod);
// This code will be inlined as lightLoopContext is hardcoded in the light loop
if (lightLoopContext == SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES)
{
return UNITY_SAMPLE_TEXCUBEARRAY_LOD(_EnvTextures, float4(dirWS, envIndex), lod);
}
else // SINGLE_PASS_SAMPLE_SKY
{
return UNITY_SAMPLE_TEXCUBE_LOD(_SkyTexture, dirWS, lod);
}
}
/*

shadowData
return UNITY_SAMPLE_SHADOW(_ShadowMapAtlas, ...);
}
*/
*/

21
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/SinglePass/SinglePassLoop.hlsl


StructuredBuffer<EnvLightData> _EnvLightList;
int _EnvLightCount;
EnvLightData _EnvLightSky;
/*
// Use texture atlas for shadow map
StructuredBuffer<PunctualShadowData> _PunctualShadowList;

{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Env(V, positionWS, prelightData, _EnvLightList[j], bsdfData, localDiffuseLighting, localSpecularLighting);
EvaluateBSDF_Env(SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES, V, positionWS, prelightData, _EnvLightList[j], bsdfData, localDiffuseLighting, localSpecularLighting);
iblDiffuseLighting.rgb = lerp(iblDiffuseLighting.rgb, localDiffuseLighting.rgb, localDiffuseLighting.a); // Should be remove by the compiler if it is smart as all is constant 0
iblSpecularLighting.rgb = lerp(iblSpecularLighting.rgb, localSpecularLighting.rgb, localSpecularLighting.a);
}
/*
// Sky Ibl
{
float4 localDiffuseLighting;
float4 localSpecularLighting;
EvaluateBSDF_Env(SINGLE_PASS_CONTEXT_SAMPLE_SKY, V, positionWS, prelightData, _EnvLightSky, bsdfData, localDiffuseLighting, localSpecularLighting);
*/
specularLighting += iblSpecularLighting;
specularLighting += iblSpecularLighting;
}
}

20
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit/Lit.hlsl


// ----------------------------------------------------------------------------
// Ref: Moving Frostbite to PBR (Appendix A)
float3 IntegrateLambertIBLRef( EnvLightData lightData, BSDFData bsdfData,
float3 IntegrateLambertIBLRef( int lightLoopContext,
EnvLightData lightData, BSDFData bsdfData,
uint sampleCount = 2048)
{
float3 N = bsdfData.normalWS;

if (NdotL > 0.0)
{
float4 val = SampleEnv(lightData.envIndex, L, 0);
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0);
// diffuse Albedo is apply here as describe in ImportanceSampleLambert function
acc += bsdfData.diffuseColor * Lambert() * weightOverPdf * val.rgb;

return acc / sampleCount;
}
float3 IntegrateDisneyDiffuseIBLRef(float3 V, EnvLightData lightData, BSDFData bsdfData,
float3 IntegrateDisneyDiffuseIBLRef(int lightLoopContext,
float3 V, EnvLightData lightData, BSDFData bsdfData,
uint sampleCount = 2048)
{
float3 N = bsdfData.normalWS;

float disneyDiffuse = DisneyDiffuse(NdotV, NdotL, LdotH, bsdfData.perceptualRoughness);
// diffuse Albedo is apply here as describe in ImportanceSampleLambert function
float4 val = SampleEnv(lightData.envIndex, L, 0);
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0);
acc += bsdfData.diffuseColor * disneyDiffuse * weightOverPdf * val.rgb;
}
}

// Ref: Moving Frostbite to PBR (Appendix A)
float3 IntegrateSpecularGGXIBLRef( float3 V, EnvLightData lightData, BSDFData bsdfData,
float3 IntegrateSpecularGGXIBLRef( int lightLoopContext,
float3 V, EnvLightData lightData, BSDFData bsdfData,
uint sampleCount = 2048)
{
float3 N = bsdfData.normalWS;

// Fresnel component is apply here as describe in ImportanceSampleGGX function
float3 FweightOverPdf = F_Schlick(bsdfData.fresnel0, VdotH) * weightOverPdf;
float4 val = SampleEnv(lightData.envIndex, L, 0);
float4 val = SampleEnv(lightLoopContext, lightData.envIndex, L, 0);
acc += FweightOverPdf * val.rgb;
}

// ----------------------------------------------------------------------------
// _preIntegratedFGD and _CubemapLD are unique for each BRDF
void EvaluateBSDF_Env( float3 V, float3 positionWS, PreLightData prelightData, EnvLightData lightData, BSDFData bsdfData,
void EvaluateBSDF_Env( int lightLoopContext,
float3 V, float3 positionWS, PreLightData prelightData, EnvLightData lightData, BSDFData bsdfData,
out float4 diffuseLighting,
out float4 specularLighting)
{

// to classic remap like unreal/Frobiste. The function GetSpecularDominantDir can result in a better matching in this case
// We let GetSpecularDominantDir currently as it still an improvement but not as good as it could be
float mip = perceptualRoughnessToMipmapLevel(bsdfData.perceptualRoughness);
float4 preLD = SampleEnv(lightData.envIndex, R, mip);
float4 preLD = SampleEnv(lightLoopContext, lightData.envIndex, R, mip);
specularLighting.rgb = preLD.rgb * prelightData.specularFGD;
// Apply specular occlusion on it

2
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl


// In case lighting.hlsl is not include before including material.hlsl, define some neutral function, so it doesn't complain
#ifndef LIGHTING
float4 SampleEnv(int envIndex, float3 dirWS, float lod)
float4 SampleEnv(int lightLoopContext, int envIndex, float3 dirWS, float lod)
{
return float4(0.0, 0.0, 0.0, 0.0);
}

正在加载...
取消
保存