您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
70 行
3.0 KiB
70 行
3.0 KiB
//-----------------------------------------------------------------------------
|
|
// LightLoop
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// bakeDiffuseLighting is part of the prototype so a user is able to implement a "base pass" with GI and multipass direct light (aka old unity rendering path)
|
|
void LightLoop( float3 V, float3 positionWS, PreLightData prelightData, BSDFData bsdfData, float3 bakeDiffuseLighting,
|
|
out float3 diffuseLighting,
|
|
out float3 specularLighting)
|
|
{
|
|
LightLoopContext context;
|
|
ZERO_INITIALIZE(LightLoopContext, context);
|
|
|
|
diffuseLighting = float3(0.0, 0.0, 0.0);
|
|
specularLighting = float3(0.0, 0.0, 0.0);
|
|
|
|
int i = 0; // Declare once to avoid the D3D11 compiler warning.
|
|
|
|
for (i = 0; i < _PunctualLightCount; ++i)
|
|
{
|
|
float3 localDiffuseLighting, localSpecularLighting;
|
|
|
|
EvaluateBSDF_Punctual(context, V, positionWS, prelightData, _PunctualLightList[i], bsdfData,
|
|
localDiffuseLighting, localSpecularLighting);
|
|
|
|
diffuseLighting += localDiffuseLighting;
|
|
specularLighting += localSpecularLighting;
|
|
}
|
|
|
|
for (i = 0; i < _AreaLightCount; ++i)
|
|
{
|
|
float3 localDiffuseLighting, localSpecularLighting;
|
|
|
|
EvaluateBSDF_Area(context, V, positionWS, prelightData, _AreaLightList[i], bsdfData,
|
|
localDiffuseLighting, localSpecularLighting);
|
|
|
|
diffuseLighting += localDiffuseLighting;
|
|
specularLighting += localSpecularLighting;
|
|
}
|
|
|
|
float3 iblDiffuseLighting = float3(0.0, 0.0, 0.0);
|
|
float3 iblSpecularLighting = float3(0.0, 0.0, 0.0);
|
|
|
|
for (i = 0; i < _EnvLightCount; ++i)
|
|
{
|
|
float3 localDiffuseLighting, localSpecularLighting;
|
|
float2 weight;
|
|
context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_REFLECTION_PROBES;
|
|
EvaluateBSDF_Env(context, V, positionWS, prelightData, _EnvLightList[i], bsdfData, localDiffuseLighting, localSpecularLighting, weight);
|
|
iblDiffuseLighting = lerp(iblDiffuseLighting, localDiffuseLighting, weight.x); // Should be remove by the compiler if it is smart as all is constant 0
|
|
iblSpecularLighting = lerp(iblSpecularLighting, localSpecularLighting, weight.y);
|
|
}
|
|
|
|
/*
|
|
// Sky Ibl
|
|
{
|
|
float3 localDiffuseLighting, localSpecularLighting;
|
|
float2 weight;
|
|
context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_SKY;
|
|
EvaluateBSDF_Env(context, V, positionWS, prelightData, _EnvLightSky, bsdfData, localDiffuseLighting, localSpecularLighting, weight);
|
|
iblDiffuseLighting = lerp(iblDiffuseLighting, localDiffuseLighting, weight.x); // Should be remove by the compiler if it is smart as all is constant 0
|
|
iblSpecularLighting = lerp(iblSpecularLighting, localSpecularLighting, weight.y);
|
|
}
|
|
*/
|
|
|
|
diffuseLighting += iblDiffuseLighting;
|
|
specularLighting += iblSpecularLighting;
|
|
|
|
// Add indirect diffuse + emissive (if any)
|
|
diffuseLighting += bakeDiffuseLighting;
|
|
}
|