Skip to content

Commit 055a95f

Browse files
committed
Relocate and enable the reference line light code path
1 parent 1e9188b commit 055a95f

File tree

1 file changed

+55
-48
lines changed
  • Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit

1 file changed

+55
-48
lines changed

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

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,53 @@ void IntegrateGGXAreaRef( float3 V, float3 positionWS, PreLightData preLightDa
801801
specularLighting /= float(sampleCount);
802802
}
803803

804+
//-----------------------------------------------------------------------------
805+
// EvaluateBSDFLine - Reference
806+
//-----------------------------------------------------------------------------
807+
808+
void IntegrateBSDFLineRef(float3 V, float3 positionWS, PreLightData preLightData,
809+
LightData lightData, BSDFData bsdfData,
810+
out float3 diffuseLighting, out float3 specularLighting,
811+
int sampleCount = 64)
812+
{
813+
diffuseLighting = float3(0.0, 0.0, 0.0);
814+
specularLighting = float3(0.0, 0.0, 0.0);
815+
816+
const float len = lightData.size.x;
817+
const float3 p0 = lightData.positionWS - lightData.right * (0.5 * len);
818+
const float3 dir = lightData.right;
819+
const float dt = len * rcp(sampleCount);
820+
const float off = 0.5 * dt;
821+
822+
// Uniformly sample the line segment with the Pdf = 1 / len.
823+
const float invPdf = len;
824+
825+
for (int i = 0; i < sampleCount; ++i)
826+
{
827+
// Place the sample in the middle of the interval.
828+
float t = off + i * dt;
829+
float3 sPos = p0 + t * dir;
830+
float3 unL = sPos - positionWS;
831+
float dist2 = dot(unL, unL);
832+
float3 L = normalize(unL);
833+
float sinLD = length(cross(L, dir));
834+
float NdotL = saturate(dot(bsdfData.normalWS, L));
835+
836+
float3 lightDiff, lightSpec;
837+
838+
BSDF(V, L, positionWS, preLightData, bsdfData, lightDiff, lightSpec);
839+
840+
diffuseLighting += lightDiff * (sinLD / dist2 * NdotL);
841+
specularLighting += lightSpec * (sinLD / dist2 * NdotL);
842+
}
843+
844+
// The factor of 2 is due to the fact: Integral{0, 2 PI}{max(0, cos(x))dx} = 2.
845+
float normFactor = 2.0 * invPdf * rcp(sampleCount);
846+
847+
diffuseLighting *= normFactor * lightData.diffuseScale * lightData.color;
848+
specularLighting *= normFactor * lightData.specularScale * lightData.color;
849+
}
850+
804851
//-----------------------------------------------------------------------------
805852
// EvaluateBSDF_Area
806853
//-----------------------------------------------------------------------------
@@ -811,7 +858,14 @@ void EvaluateBSDF_Area( LightLoopContext lightLoopContext,
811858
out float3 specularLighting)
812859
{
813860
#ifdef LIT_DISPLAY_REFERENCE_AREA
814-
IntegrateGGXAreaRef(V, positionWS, preLightData, lightData, bsdfData, diffuseLighting, specularLighting);
861+
if (lightData.lightType == GPULIGHTTYPE_LINE)
862+
{
863+
IntegrateBSDFLineRef(V, positionWS, preLightData, lightData, bsdfData, diffuseLighting, specularLighting);
864+
}
865+
else
866+
{
867+
IntegrateGGXAreaRef(V, positionWS, preLightData, lightData, bsdfData, diffuseLighting, specularLighting);
868+
}
815869
#else
816870
// TODO: This could be precomputed
817871
float halfWidth = lightData.size.x * 0.5;
@@ -906,53 +960,6 @@ void EvaluateBSDF_Area( LightLoopContext lightLoopContext,
906960
#endif
907961
}
908962

909-
//-----------------------------------------------------------------------------
910-
// EvaluateBSDFLine - Reference
911-
//-----------------------------------------------------------------------------
912-
913-
void IntegrateBSDFLineRef(float3 V, float3 positionWS, PreLightData preLightData,
914-
LightData lightData, BSDFData bsdfData,
915-
out float3 diffuseLighting, out float3 specularLighting,
916-
int sampleCount = 64)
917-
{
918-
diffuseLighting = float3(0.0, 0.0, 0.0);
919-
specularLighting = float3(0.0, 0.0, 0.0);
920-
921-
const float len = lightData.size.x;
922-
const float3 p0 = lightData.positionWS - lightData.right * (0.5 * len);
923-
const float3 dir = lightData.right;
924-
const float dt = len * rcp(sampleCount);
925-
const float off = 0.5 * dt;
926-
927-
// Uniformly sample the line segment with the Pdf = 1 / len.
928-
const float invPdf = len;
929-
930-
for (int i = 0; i < sampleCount; ++i)
931-
{
932-
// Place the sample in the middle of the interval.
933-
float t = off + i * dt;
934-
float3 sPos = p0 + t * dir;
935-
float3 unL = sPos - positionWS;
936-
float dist2 = dot(unL, unL);
937-
float3 L = normalize(L);
938-
float sinLD = length(cross(L, dir));
939-
float NdotL = saturate(dot(bsdfData.normalWS, L));
940-
941-
float3 lightDiff, lightSpec;
942-
943-
BSDF(V, L, positionWS, preLightData, bsdfData, lightDiff, lightSpec);
944-
945-
diffuseLighting += lightDiff * (sinLD / dist2 * NdotL);
946-
specularLighting += lightSpec * (sinLD / dist2 * NdotL);
947-
}
948-
949-
// The factor of 2 is due to the fact: Integral{0, 2 PI}{max(0, cos(x))dx} = 2.
950-
float normFactor = 2.0 * invPdf * rcp(sampleCount);
951-
952-
diffuseLighting *= normFactor * lightData.diffuseScale * lightData.color;
953-
specularLighting *= normFactor * lightData.specularScale * lightData.color;
954-
}
955-
956963
//-----------------------------------------------------------------------------
957964
// EvaluateBSDF_Env - Reference
958965
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)