接上篇看一下PostInitBuiltinData函数:
// InitBuiltinData must be call before calling PostInitBuiltinData
void PostInitBuiltinData( float3 V, PositionInputs posInput, SurfaceData surfaceData,
inout BuiltinData builtinData)
{
// Apply control from the indirect lighting volume settings - This is apply here so we don't affect emissive
// color in case of lit deferred for example and avoid material to have to deal with it
builtinData.bakeDiffuseLighting *= _IndirectLightingMultiplier.x;
builtinData.backBakeDiffuseLighting *= _IndirectLightingMultiplier.x;
#ifdef MODIFY_BAKED_DIFFUSE_LIGHTING
ModifyBakedDiffuseLighting(V, posInput, surfaceData, builtinData);
#endif
ApplyDebugToBuiltinData(builtinData);
}
前两行可以通过外部参数控制。
如果定义了MODIFY_BAKED_DIFFUSE_LIGHTING,我们可以修改diffuseColor和bakeDiffuseLighting的值。与上篇说的一样,Standard材质在Lit.hlsl中定义了MODIFY_BAKED_DIFFUSE_LIGHTING和ModifyBakedDiffuseLighting:
void ModifyBakedDiffuseLighting(float3 V, PositionInputs posInput, SurfaceData surfaceData, inout BuiltinData builtinData)
{
// In case of deferred, all lighting model operation are done before storage in GBuffer, as we store emissive with bakeDiffuseLighting
// To get the data we need to do the whole process - compiler should optimize everything
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(posInput.positionSS, surfaceData);
PreLightData preLightData = GetPreLightData(V, posInput, bsdfData);
// Add GI transmission contribution to bakeDiffuseLighting, we then drop backBakeDiffuseLighting (i.e it is not used anymore, this save VGPR in forward and in deferred we can't store it anyway)
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_TRANSMISSION))
{
builtinData.bakeDiffuseLighting += builtinData.backBakeDiffuseLighting * bsdfData.transmittance;
}
// For SSS we need to take into account the state of diffuseColor
if (HasFlag(bsdfData.materialFeatures, MATERIALFEATUREFLAGS_LIT_SUBSURFACE_SCATTERING))
{
bsdfData.diffuseColor = GetModifiedDiffuseColorForSSS(bsdfData);
}
// Premultiply (back) bake diffuse lighting information with DisneyDiffuse pre-integration
builtinData.bakeDiffuseLighting *= preLightData.diffuseFGD * bsdfData.diffuseColor;
}
先看这里用

本文深入探讨Unity2018的High Definition Render Pipeline (HDRP)中Standard材质的PostInitBuiltinData函数,讲解如何在 Forward 模式下利用NormalBufferTexture获取normal和roughness,并分析GetPreLightData和GetPreIntegratedFGDGGXAndDisneyDiffuse函数。文中引用SIGGRAPH 2017 Course、Unity官方博客等资源,解析了IBL的diffuse项计算及LTC在BRDF中的应用。
最低0.47元/天 解锁文章
2124

被折叠的 条评论
为什么被折叠?



