|
|
|
|
|
|
|
|
|
|
// This struct is define in the material. the Lightloop must not access it |
|
|
|
// PostEvaluateBSDF call at the end will convert Lighting to diffuse and specular lighting |
|
|
|
AggregateLighting aggregatelighting; |
|
|
|
ZERO_INITIALIZE(AggregateLighting, aggregatelighting); // LightLoop is in charge of initializing the struct |
|
|
|
AggregateLighting aggregateLighting; |
|
|
|
ZERO_INITIALIZE(AggregateLighting, aggregateLighting); // LightLoop is in charge of initializing the struct |
|
|
|
|
|
|
|
uint i = 0; // Declare once to avoid the D3D11 compiler warning. |
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
DirectLighting lighting = EvaluateBSDF_Directional(context, V, posInput, preLightData, _DirectionalLightDatas[i], bsdfData); |
|
|
|
AccumulateDirectLighting(aggregatelighting, lighting); |
|
|
|
AccumulateDirectLighting(aggregateLighting, lighting); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
int punctualIndex = FetchIndex(punctualLightStart, i); |
|
|
|
DirectLighting lighting = EvaluateBSDF_Punctual(context, V, posInput, preLightData, _LightDatas[punctualIndex], bsdfData, _LightDatas[punctualIndex].lightType); |
|
|
|
AccumulateDirectLighting(aggregatelighting, lighting); |
|
|
|
AccumulateDirectLighting(aggregateLighting, lighting); |
|
|
|
} |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
DirectLighting lighting = EvaluateBSDF_Punctual(context, V, posInput, preLightData, _LightDatas[i], bsdfData, _LightDatas[i].lightType); |
|
|
|
AccumulateDirectLighting(aggregatelighting, lighting); |
|
|
|
AccumulateDirectLighting(aggregateLighting, lighting); |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
while (i < areaLightCount && lightType == GPULIGHTTYPE_LINE) |
|
|
|
{ |
|
|
|
DirectLighting lighting = EvaluateBSDF_Area(context, V, posInput, preLightData, _LightDatas[areaIndex], bsdfData, GPULIGHTTYPE_LINE); |
|
|
|
AccumulateDirectLighting(aggregatelighting, lighting); |
|
|
|
AccumulateDirectLighting(aggregateLighting, lighting); |
|
|
|
|
|
|
|
i++; |
|
|
|
areaIndex = i < areaLightCount ? FetchIndex(areaLightStart, i) : 0; |
|
|
|
|
|
|
while (i < areaLightCount && lightType == GPULIGHTTYPE_RECTANGLE) |
|
|
|
{ |
|
|
|
DirectLighting lighting = EvaluateBSDF_Area(context, V, posInput, preLightData, _LightDatas[areaIndex], bsdfData, GPULIGHTTYPE_RECTANGLE); |
|
|
|
AccumulateDirectLighting(aggregatelighting, lighting); |
|
|
|
AccumulateDirectLighting(aggregateLighting, lighting); |
|
|
|
|
|
|
|
i++; |
|
|
|
areaIndex = i < areaLightCount ? FetchIndex(areaLightStart, i) : 0; |
|
|
|
|
|
|
for (i = _PunctualLightCount; i < _PunctualLightCount + _AreaLightCount; ++i) |
|
|
|
{ |
|
|
|
DirectLighting lighting = EvaluateBSDF_Area(context, V, posInput, preLightData, _LightDatas[i], bsdfData, _LightDatas[i].lightType); |
|
|
|
AccumulateDirectLighting(aggregatelighting, lighting); |
|
|
|
AccumulateDirectLighting(aggregateLighting, lighting); |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
if (featureFlags & LIGHTFEATUREFLAGS_SSREFRACTION) |
|
|
|
{ |
|
|
|
ImageBasedLighting lighting = EvaluateBSDF_SSRefraction(context, V, posInput, preLightData, bsdfData, refractionHierarchyWeight); |
|
|
|
AccumulateImageBasedLighting(aggregatelighting, lighting); |
|
|
|
AccumulateImageBasedLighting(aggregateLighting, lighting); |
|
|
|
AccumulateImageBasedLighting(aggregatelighting, lighting); |
|
|
|
AccumulateImageBasedLighting(aggregateLighting, lighting); |
|
|
|
} |
|
|
|
|
|
|
|
if (featureFlags & LIGHTFEATUREFLAGS_ENV || featureFlags & LIGHTFEATUREFLAGS_SKY) |
|
|
|
|
|
|
#endif |
|
|
|
ImageBasedLighting lighting = EvaluateBSDF_Env( context, V, posInput, preLightData, _EnvLightDatas[envLightIndex], bsdfData, _EnvLightDatas[envLightIndex].envShapeType, |
|
|
|
reflectionHierarchyWeight); |
|
|
|
AccumulateImageBasedLighting(aggregatelighting, lighting); |
|
|
|
AccumulateImageBasedLighting(aggregateLighting, lighting); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
context.sampleReflection = SINGLE_PASS_CONTEXT_SAMPLE_SKY; |
|
|
|
EnvLightData envLightSky = InitSkyEnvLightData(0); // The sky data are generated on the fly so the compiler can optimize the code |
|
|
|
ImageBasedLighting lighting = EvaluateBSDF_Env(context, V, posInput, preLightData, envLightSky, bsdfData, ENVSHAPETYPE_SKY, reflectionHierarchyWeight); |
|
|
|
AccumulateImageBasedLighting(aggregatelighting, lighting); |
|
|
|
AccumulateImageBasedLighting(aggregateLighting, lighting); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
PostEvaluateBSDF( context, V, posInput, preLightData, bsdfData, bakeDiffuseLighting, aggregatelighting, |
|
|
|
PostEvaluateBSDF( context, V, posInput, preLightData, bsdfData, bakeDiffuseLighting, aggregateLighting, |
|
|
|
diffuseLighting, specularLighting); |
|
|
|
|
|
|
|
ApplyDebug(context, posInput.positionWS, diffuseLighting, specularLighting); |