Skip to content

Commit 2bd6222

Browse files
committed
remove non-MIS spotlight support
1 parent ff2b571 commit 2bd6222

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

src/materials/PhysicalPathTracingMaterial.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,19 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
430430
431431
#if FEATURE_MIS
432432
433-
// weight the contribution
434-
float misWeight = misHeuristic( sampleRec.pdf, lightHit.pdf / float( lights.count + 1u ) );
435-
gl_FragColor.rgb += lightHit.emission * throughputColor * misWeight;
433+
// NOTE: we skip MIS for spotlights since we haven't fixed the forward
434+
// path tracing code path, yet
435+
if ( lightHit.type == SPOT_LIGHT_TYPE ) {
436+
437+
gl_FragColor.rgb += lightHit.emission * throughputColor;
438+
439+
} else {
440+
441+
// weight the contribution
442+
float misWeight = misHeuristic( sampleRec.pdf, lightHit.pdf / float( lights.count + 1u ) );
443+
gl_FragColor.rgb += lightHit.emission * throughputColor * misWeight;
444+
445+
}
436446
437447
#else
438448

src/shader/shaderLightSampling.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct LightSampleRec {
3939
vec3 direction;
4040
float pdf;
4141
vec3 emission;
42+
int type;
4243
4344
};
4445
@@ -80,39 +81,41 @@ LightSampleRec lightsClosestHit( sampler2D lights, uint lightCount, vec3 rayOrig
8081
lightSampleRec.pdf = ( dist * dist ) / ( light.area * cosTheta );
8182
lightSampleRec.emission = light.color * light.intensity;
8283
lightSampleRec.direction = rayDirection;
84+
lightSampleRec.type = light.type;
8385
8486
}
8587
8688
} else if ( light.type == SPOT_LIGHT_TYPE ) {
8789
88-
float radius = light.radius;
89-
vec3 lightNormal = normalize( cross( light.u, light.v ) );
90-
float angle = acos( light.coneCos );
91-
float angleTan = tan( angle );
92-
float startDistance = radius / max( angleTan, EPSILON );
90+
// TODO: forward path tracing sampling needs to be made consistent with direct light sampling logic
91+
// float radius = light.radius;
92+
// vec3 lightNormal = normalize( cross( light.u, light.v ) );
93+
// float angle = acos( light.coneCos );
94+
// float angleTan = tan( angle );
95+
// float startDistance = radius / max( angleTan, EPSILON );
9396
94-
u = light.u / radius;
95-
v = light.v / radius;
97+
// u = light.u / radius;
98+
// v = light.v / radius;
9699
97-
if (
98-
intersectsCircle( light.position - normal * startDistance, normal, u, v, rayOrigin, rayDirection, dist ) &&
99-
( dist < lightSampleRec.dist || ! lightSampleRec.hit )
100-
) {
100+
// if (
101+
// intersectsCircle( light.position - normal * startDistance, normal, u, v, rayOrigin, rayDirection, dist ) &&
102+
// ( dist < lightSampleRec.dist || ! lightSampleRec.hit )
103+
// ) {
101104
102-
float cosTheta = dot( rayDirection, normal );
103-
float spotAttenuation = light.iesProfile != - 1 ?
104-
getPhotometricAttenuation( iesProfiles, light.iesProfile, rayDirection, normal, u, v )
105-
: getSpotAttenuation( light.coneCos, light.penumbraCos, cosTheta );
105+
// float cosTheta = dot( rayDirection, normal );
106+
// float spotAttenuation = light.iesProfile != - 1 ?
107+
// getPhotometricAttenuation( iesProfiles, light.iesProfile, rayDirection, normal, u, v )
108+
// : getSpotAttenuation( light.coneCos, light.penumbraCos, cosTheta );
106109
107-
float distanceAttenuation = getDistanceAttenuation( dist, light.distance, light.decay );
110+
// float distanceAttenuation = getDistanceAttenuation( dist, light.distance, light.decay );
108111
109-
lightSampleRec.hit = true;
110-
lightSampleRec.dist = dist;
111-
lightSampleRec.direction = rayDirection;
112-
lightSampleRec.emission = light.color * light.intensity * distanceAttenuation * spotAttenuation;
113-
lightSampleRec.pdf = ( dist * dist ) / ( light.area * cosTheta );
112+
// lightSampleRec.hit = true;
113+
// lightSampleRec.dist = dist;
114+
// lightSampleRec.direction = rayDirection;
115+
// lightSampleRec.emission = light.color * light.intensity * distanceAttenuation * spotAttenuation;
116+
// lightSampleRec.pdf = ( dist * dist ) / ( light.area * cosTheta );
114117
115-
}
118+
// }
116119
117120
}
118121
@@ -126,6 +129,7 @@ LightSampleRec randomAreaLightSample( Light light, vec3 rayOrigin ) {
126129
127130
LightSampleRec lightSampleRec;
128131
lightSampleRec.hit = true;
132+
lightSampleRec.type = light.type;
129133
130134
lightSampleRec.emission = light.color * light.intensity;
131135
@@ -191,6 +195,7 @@ LightSampleRec randomSpotLightSample( Light light, sampler2DArray iesProfiles, v
191195
float distanceAttenuation = getDistanceAttenuation( dist, light.distance, light.decay );
192196
LightSampleRec lightSampleRec;
193197
lightSampleRec.hit = true;
198+
lightSampleRec.type = light.type;
194199
lightSampleRec.dist = dist;
195200
lightSampleRec.direction = direction;
196201
lightSampleRec.emission = light.color * light.intensity * distanceAttenuation * spotAttenuation;
@@ -200,7 +205,6 @@ LightSampleRec randomSpotLightSample( Light light, sampler2DArray iesProfiles, v
200205
lightSampleRec.pdf = 1.0;
201206
// lightSampleRec.pdf = lightDistSq / ( light.area * cosTheta );
202207
203-
204208
return lightSampleRec;
205209
206210
}

0 commit comments

Comments
 (0)