@@ -13,7 +13,7 @@ import { shaderLightSampling } from '../shader/shaderLightSampling.js';
1313import { shaderUtils } from '../shader/shaderUtils.js' ;
1414import { PhysicalCameraUniform } from '../uniforms/PhysicalCameraUniform.js' ;
1515import { EquirectHdrInfoUniform } from '../uniforms/EquirectHdrInfoUniform.js' ;
16- import { LightsTexture } from '../uniforms/LightsTexture .js' ;
16+ import { LightsInfoUniformStruct } from '../uniforms/LightsInfoUniformStruct .js' ;
1717import { IESProfilesTexture } from '../uniforms/IESProfilesTexture.js' ;
1818
1919export class PhysicalPathTracingMaterial extends MaterialBase {
@@ -55,8 +55,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
5555 materialIndexAttribute : { value : new UIntVertexAttributeTexture ( ) } ,
5656 materials : { value : new MaterialsTexture ( ) } ,
5757 textures : { value : new RenderTarget2DArray ( ) . texture } ,
58- lights : { value : new LightsTexture ( ) } ,
59- lightCount : { value : 0 } ,
58+ lights : { value : new LightsInfoUniformStruct ( ) } ,
6059 iesProfiles : { value : new IESProfilesTexture ( ) . texture } ,
6160 cameraWorldMatrix : { value : new Matrix4 ( ) } ,
6261 invProjectionMatrix : { value : new Matrix4 ( ) } ,
@@ -138,8 +137,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
138137 uniform int seed;
139138 uniform float opacity;
140139 uniform sampler2D materials;
141- uniform sampler2D lights;
142- uniform uint lightCount;
140+ uniform LightsInfo lights;
143141 uniform sampler2DArray iesProfiles;
144142
145143 ${ shaderLightSampling }
@@ -420,7 +418,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
420418
421419 bool hit = bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist );
422420
423- LightSampleRec lightHit = lightsClosestHit( lights, lightCount , rayOrigin, rayDirection );
421+ LightSampleRec lightHit = lightsClosestHit( lights.tex, lights.count , rayOrigin, rayDirection );
424422
425423 if ( lightHit.hit && ( lightHit.dist < dist || !hit ) ) {
426424
@@ -433,7 +431,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
433431 #if FEATURE_MIS
434432
435433 // weight the contribution
436- float misWeight = misHeuristic( sampleRec.pdf, lightHit.pdf / float( lightCount + 1u ) );
434+ float misWeight = misHeuristic( sampleRec.pdf, lightHit.pdf / float( lights.count + 1u ) );
437435 gl_FragColor.rgb += lightHit.emission * throughputColor * misWeight;
438436
439437 #else
@@ -463,7 +461,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
463461 // get the PDF of the hit envmap point
464462 vec3 envColor;
465463 float envPdf = envMapSample( environmentRotation * rayDirection, envMapInfo, envColor );
466- envPdf /= float( lightCount + 1u );
464+ envPdf /= float( lights.count + 1u );
467465
468466 // and weight the contribution
469467 float misWeight = misHeuristic( sampleRec.pdf, envPdf );
@@ -788,10 +786,10 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
788786 #if FEATURE_MIS
789787
790788 // uniformly pick a light or environment map
791- if( rand() > 1.0 / float( lightCount + 1u ) ) {
789+ if( rand() > 1.0 / float( lights.count + 1u ) ) {
792790
793791 // sample a light or environment
794- LightSampleRec lightSampleRec = randomLightSample( lights, iesProfiles, lightCount , rayOrigin );
792+ LightSampleRec lightSampleRec = randomLightSample( lights.tex , iesProfiles, lights.count , rayOrigin );
795793
796794 bool isSampleBelowSurface = dot( faceNormal, lightSampleRec.direction ) < 0.0;
797795 if ( isSampleBelowSurface ) {
@@ -814,7 +812,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
814812 if ( lightMaterialPdf > 0.0 && isValidSampleColor ) {
815813
816814 // weight the direct light contribution
817- float lightPdf = lightSampleRec.pdf / float( lightCount + 1u );
815+ float lightPdf = lightSampleRec.pdf / float( lights.count + 1u );
818816 float misWeight = misHeuristic( lightPdf, lightMaterialPdf );
819817 gl_FragColor.rgb += lightSampleRec.emission * throughputColor * sampleColor * misWeight / lightPdf;
820818
@@ -854,7 +852,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
854852 if ( envMaterialPdf > 0.0 && isValidSampleColor ) {
855853
856854 // weight the direct light contribution
857- envPdf /= float( lightCount + 1u );
855+ envPdf /= float( lights.count + 1u );
858856 float misWeight = misHeuristic( envPdf, envMaterialPdf );
859857 gl_FragColor.rgb += attenuatedColor * environmentIntensity * envColor * throughputColor * sampleColor * misWeight / envPdf;
860858
0 commit comments