浏览代码

Relocate and enable the reference line light code path

/main
Evgenii Golubev 8 年前
当前提交
9d05529b
共有 1 个文件被更改,包括 55 次插入48 次删除
  1. 103
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.hlsl

103
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.hlsl


}
//-----------------------------------------------------------------------------
// EvaluateBSDFLine - Reference
//-----------------------------------------------------------------------------
void IntegrateBSDFLineRef(float3 V, float3 positionWS, PreLightData preLightData,
LightData lightData, BSDFData bsdfData,
out float3 diffuseLighting, out float3 specularLighting,
int sampleCount = 64)
{
diffuseLighting = float3(0.0, 0.0, 0.0);
specularLighting = float3(0.0, 0.0, 0.0);
const float len = lightData.size.x;
const float3 p0 = lightData.positionWS - lightData.right * (0.5 * len);
const float3 dir = lightData.right;
const float dt = len * rcp(sampleCount);
const float off = 0.5 * dt;
// Uniformly sample the line segment with the Pdf = 1 / len.
const float invPdf = len;
for (int i = 0; i < sampleCount; ++i)
{
// Place the sample in the middle of the interval.
float t = off + i * dt;
float3 sPos = p0 + t * dir;
float3 unL = sPos - positionWS;
float dist2 = dot(unL, unL);
float3 L = normalize(unL);
float sinLD = length(cross(L, dir));
float NdotL = saturate(dot(bsdfData.normalWS, L));
float3 lightDiff, lightSpec;
BSDF(V, L, positionWS, preLightData, bsdfData, lightDiff, lightSpec);
diffuseLighting += lightDiff * (sinLD / dist2 * NdotL);
specularLighting += lightSpec * (sinLD / dist2 * NdotL);
}
// The factor of 2 is due to the fact: Integral{0, 2 PI}{max(0, cos(x))dx} = 2.
float normFactor = 2.0 * invPdf * rcp(sampleCount);
diffuseLighting *= normFactor * lightData.diffuseScale * lightData.color;
specularLighting *= normFactor * lightData.specularScale * lightData.color;
}
//-----------------------------------------------------------------------------
// EvaluateBSDF_Area
//-----------------------------------------------------------------------------

out float3 specularLighting)
{
#ifdef LIT_DISPLAY_REFERENCE_AREA
IntegrateGGXAreaRef(V, positionWS, preLightData, lightData, bsdfData, diffuseLighting, specularLighting);
if (lightData.lightType == GPULIGHTTYPE_LINE)
{
IntegrateBSDFLineRef(V, positionWS, preLightData, lightData, bsdfData, diffuseLighting, specularLighting);
}
else
{
IntegrateGGXAreaRef(V, positionWS, preLightData, lightData, bsdfData, diffuseLighting, specularLighting);
}
#else
// TODO: This could be precomputed
float halfWidth = lightData.size.x * 0.5;

specularLighting = fresnelTerm * lightData.color * ltcValue;
}
#endif
}
//-----------------------------------------------------------------------------
// EvaluateBSDFLine - Reference
//-----------------------------------------------------------------------------
void IntegrateBSDFLineRef(float3 V, float3 positionWS, PreLightData preLightData,
LightData lightData, BSDFData bsdfData,
out float3 diffuseLighting, out float3 specularLighting,
int sampleCount = 64)
{
diffuseLighting = float3(0.0, 0.0, 0.0);
specularLighting = float3(0.0, 0.0, 0.0);
const float len = lightData.size.x;
const float3 p0 = lightData.positionWS - lightData.right * (0.5 * len);
const float3 dir = lightData.right;
const float dt = len * rcp(sampleCount);
const float off = 0.5 * dt;
// Uniformly sample the line segment with the Pdf = 1 / len.
const float invPdf = len;
for (int i = 0; i < sampleCount; ++i)
{
// Place the sample in the middle of the interval.
float t = off + i * dt;
float3 sPos = p0 + t * dir;
float3 unL = sPos - positionWS;
float dist2 = dot(unL, unL);
float3 L = normalize(L);
float sinLD = length(cross(L, dir));
float NdotL = saturate(dot(bsdfData.normalWS, L));
float3 lightDiff, lightSpec;
BSDF(V, L, positionWS, preLightData, bsdfData, lightDiff, lightSpec);
diffuseLighting += lightDiff * (sinLD / dist2 * NdotL);
specularLighting += lightSpec * (sinLD / dist2 * NdotL);
}
// The factor of 2 is due to the fact: Integral{0, 2 PI}{max(0, cos(x))dx} = 2.
float normFactor = 2.0 * invPdf * rcp(sampleCount);
diffuseLighting *= normFactor * lightData.diffuseScale * lightData.color;
specularLighting *= normFactor * lightData.specularScale * lightData.color;
}
//-----------------------------------------------------------------------------

正在加载...
取消
保存