Skip to content

Commit 8a8b6c6

Browse files
committed
Separate the layer fetch functions
1 parent 7de09b1 commit 8a8b6c6

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

src/materials/PhysicalPathTracingMaterial.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Matrix4, Matrix3, Vector2 } from 'three';
22
import { MaterialBase } from './MaterialBase.js';
33
import {
4-
MeshBVHUniformStruct, FloatVertexAttributeTexture, UIntVertexAttributeTexture,
4+
MeshBVHUniformStruct, UIntVertexAttributeTexture,
55
shaderStructs, shaderIntersectFunction,
66
} from 'three-mesh-bvh';
77
import { shaderMaterialStructs, shaderLightStruct } from '../shader/shaderStructs.js';
@@ -11,6 +11,7 @@ import { shaderMaterialSampling } from '../shader/shaderMaterialSampling.js';
1111
import { shaderEnvMapSampling } from '../shader/shaderEnvMapSampling.js';
1212
import { shaderLightSampling } from '../shader/shaderLightSampling.js';
1313
import { shaderUtils } from '../shader/shaderUtils.js';
14+
import { shaderLayerTexelFetchFunctions } from '../shader/shaderLayerTexelFetchFunctions.js';
1415
import { PhysicalCameraUniform } from '../uniforms/PhysicalCameraUniform.js';
1516
import { EquirectHdrInfoUniform } from '../uniforms/EquirectHdrInfoUniform.js';
1617
import { LightsInfoUniformStruct } from '../uniforms/LightsInfoUniformStruct.js';
@@ -106,6 +107,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
106107
${ shaderMaterialStructs }
107108
${ shaderLightStruct }
108109
110+
${ shaderLayerTexelFetchFunctions }
109111
${ shaderUtils }
110112
${ shaderMaterialSampling }
111113
${ shaderEnvMapSampling }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
export const shaderLayerTexelFetchFunctions = /*glsl */`
3+
4+
// add texel fetch functions for texture arrays
5+
vec4 texelFetch1D( sampler2DArray tex, int layer, uint index ) {
6+
7+
uint width = uint( textureSize( tex, 0 ).x );
8+
uvec2 uv;
9+
uv.x = index % width;
10+
uv.y = index / width;
11+
12+
return texelFetch( tex, ivec3( uv, layer ), 0 );
13+
14+
}
15+
16+
vec4 textureSampleBarycoord( sampler2DArray tex, int layer, vec3 barycoord, uvec3 faceIndices ) {
17+
18+
return
19+
barycoord.x * texelFetch1D( tex, layer, faceIndices.x ) +
20+
barycoord.y * texelFetch1D( tex, layer, faceIndices.y ) +
21+
barycoord.z * texelFetch1D( tex, layer, faceIndices.z );
22+
23+
}
24+
25+
`;

src/shader/shaderUtils.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -361,25 +361,4 @@ export const shaderUtils = /* glsl */`
361361
362362
}
363363
364-
// add texel fetch functions for texture arrays
365-
vec4 texelFetch1D( sampler2DArray tex, int layer, uint index ) {
366-
367-
uint width = uint( textureSize( tex, 0 ).x );
368-
uvec2 uv;
369-
uv.x = index % width;
370-
uv.y = index / width;
371-
372-
return texelFetch( tex, ivec3( uv, layer ), 0 );
373-
374-
}
375-
376-
vec4 textureSampleBarycoord( sampler2DArray tex, int layer, vec3 barycoord, vec3 faceIndices ) {
377-
378-
return
379-
barycoord.x * texelFetch1D( tex, layer, faceIndices.x ) +
380-
barycoord.y * texelFetch1D( tex, layer, faceIndices.y ) +
381-
barycoord.z * texelFetch1D( tex, layer, faceIndices.z );
382-
383-
}
384-
385364
`;

0 commit comments

Comments
 (0)