@@ -101,8 +101,8 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
101
101
backgroundBlur : { value : 0.0 } ,
102
102
backgroundMap : { value : null } ,
103
103
backgroundAlpha : { value : 1.0 } ,
104
- // backgroundIntensity
105
- // backgroundRotation
104
+ backgroundIntensity : { value : 1.0 } ,
105
+ backgroundRotation : { value : new Matrix4 ( ) } ,
106
106
107
107
// randomness uniforms
108
108
seed : { value : 0 } ,
@@ -203,6 +203,8 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
203
203
#if FEATURE_BACKGROUND_MAP
204
204
205
205
uniform sampler2D backgroundMap;
206
+ uniform mat4 backgroundRotation;
207
+ uniform float backgroundIntensity;
206
208
207
209
#endif
208
210
@@ -237,6 +239,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
237
239
// globals
238
240
mat3 envRotation3x3;
239
241
mat3 invEnvRotation3x3;
242
+ mat3 backgroundRotation3x3;
240
243
float lightsDenom;
241
244
242
245
// sampling
@@ -265,14 +268,16 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
265
268
266
269
vec3 sampleBackground( vec3 direction, vec2 uv ) {
267
270
268
- vec3 sampleDir = normalize( direction + sampleHemisphere( direction, uv ) * 0.5 * backgroundBlur ) ;
271
+ vec3 sampleDir = sampleHemisphere( direction, uv ) * 0.5 * backgroundBlur;
269
272
270
273
#if FEATURE_BACKGROUND_MAP
271
274
272
- return sampleEquirectColor( backgroundMap, sampleDir );
275
+ sampleDir = normalize( backgroundRotation3x3 * direction + sampleDir );
276
+ return backgroundIntensity * sampleEquirectColor( backgroundMap, sampleDir );
273
277
274
278
#else
275
279
280
+ sampleDir = normalize( envRotation3x3 * direction + sampleDir );
276
281
return environmentIntensity * sampleEquirectColor( envMapInfo.map, sampleDir );
277
282
278
283
#endif
@@ -299,6 +304,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
299
304
// inverse environment rotation
300
305
envRotation3x3 = mat3( environmentRotation );
301
306
invEnvRotation3x3 = inverse( envRotation3x3 );
307
+ backgroundRotation3x3 = mat3( backgroundRotation );
302
308
lightsDenom =
303
309
( environmentIntensity == 0.0 || envMapInfo.totalSum == 0.0 ) && lights.count != 0u ?
304
310
float( lights.count ) :
@@ -371,7 +377,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
371
377
372
378
if ( state.firstRay || state.transmissiveRay ) {
373
379
374
- gl_FragColor.rgb += sampleBackground( envRotation3x3 * ray.direction, rand2( 2 ) ) * state.throughputColor;
380
+ gl_FragColor.rgb += sampleBackground( ray.direction, rand2( 2 ) ) * state.throughputColor;
375
381
gl_FragColor.a = backgroundAlpha;
376
382
377
383
} else {
0 commit comments