55 iorToF0Func ,
66 schlickFresnelFunc ,
77 schlickFresnelVecFunc ,
8+ sampleTexelFunc ,
89} from './utils.wgsl' ;
910import {
1011 ggxSmithVisibilityFunc ,
@@ -48,7 +49,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
4849 let vTBN = mat3x3f( tangent, bitangent, faceNormal );
4950
5051 let uvPrime = material.normalMapTransform * vec3( uv, 1.0 );
51- var texNormal = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.normalMap ) , 0 ).xyz;
52+ var texNormal = sampleTexel ( textures, textureSampler, uvPrime.xy, material.normalMap, 0 ).xyz;
5253 texNormal = texNormal * 2.0 - 1.0;
5354 texNormal = texNormal * vec3f( material.normalScale, 1.0 );
5455 normal = normalize( vTBN * texNormal );
@@ -71,7 +72,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
7172 if ( material.map != -1 ) {
7273
7374 let uvPrime = material.mapTransform * vec3f( uv, 1 );
74- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.map ) , 0 );
75+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.map, 0 );
7576 albedo *= vec4f( texColor.rgb, 1.0 );
7677
7778 }
@@ -80,7 +81,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
8081 if ( material.roughnessMap != -1 ) {
8182
8283 let uvPrime = material.roughnessMapTransform * vec3f( uv, 1 );
83- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.roughnessMap ) , 0 );
84+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.roughnessMap, 0 );
8485 roughness *= texColor.g;
8586
8687 }
@@ -89,7 +90,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
8990 if ( material.metalnessMap != -1 ) {
9091
9192 let uvPrime = material.metalnessMapTransform * vec3f( uv, 1 );
92- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.metalnessMap ) , 0 );
93+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.metalnessMap, 0 );
9394 metalness *= texColor.b;
9495
9596 }
@@ -98,7 +99,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
9899 if ( material.emissiveMap != -1 ) {
99100
100101 let uvPrime = material.emissiveMapTransform * vec3f( uv, 1 );
101- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.emissiveMap ) , 0 );
102+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.emissiveMap, 0 );
102103 emission *= texColor.rgb;
103104
104105 }
@@ -107,7 +108,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
107108 if ( material.transmissionMap != -1 ) {
108109
109110 let uvPrime = material.transmissionMapTransform * vec3f( uv, 1 );
110- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.transmissionMap ) , 0 );
111+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.transmissionMap, 0 );
111112 transmission *= texColor.r;
112113
113114 }
@@ -116,7 +117,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
116117 if ( material.clearcoatMap != -1 ) {
117118
118119 let uvPrime = material.clearcoatMapTransform * vec3f( uv, 1 );
119- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.clearcoatMap ) , 0 );
120+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.clearcoatMap, 0 );
120121 clearcoat *= texColor.r;
121122
122123 }
@@ -125,7 +126,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
125126 if ( material.clearcoatRoughnessMap != -1 ) {
126127
127128 let uvPrime = material.clearcoatRoughnessMapTransform * vec3f( uv, 1 );
128- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.clearcoatRoughnessMap ) , 0 );
129+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.clearcoatRoughnessMap, 0 );
129130 clearcoatRoughness *= texColor.r;
130131
131132 }
@@ -142,7 +143,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
142143 let vTBN = mat3x3f( tangent, bitangent, faceNormal );
143144
144145 let uvPrime = material.clearcoatNormalMapTransform * vec3( uv, 1.0 );
145- var texNormal = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.clearcoatNormalMap ) , 0 ).xyz;
146+ var texNormal = sampleTexel ( textures, textureSampler, uvPrime.xy, material.clearcoatNormalMap, 0 ).xyz;
146147 texNormal = texNormal * 2.0 - 1.0;
147148 texNormal = texNormal * vec3f( material.clearcoatNormalScale, 1.0 );
148149 clearcoatNormal = normalize( vTBN * texNormal );
@@ -156,7 +157,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
156157 if ( material.sheenColorMap != -1 ) {
157158
158159 let uvPrime = material.sheenColorMapTransform * vec3f( uv, 1 );
159- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.sheenColorMap ) , 0 );
160+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.sheenColorMap, 0 );
160161 sheenColor *= texColor.rgb;
161162
162163 }
@@ -165,7 +166,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
165166 if ( material.sheenRoughnessMap != -1 ) {
166167
167168 let uvPrime = material.sheenRoughnessMapTransform * vec3f( uv, 1 );
168- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.sheenRoughnessMap ) , 0 );
169+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.sheenRoughnessMap, 0 );
169170 sheenRoughness *= texColor.r;
170171
171172 }
@@ -174,7 +175,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
174175 if ( material.iridescenceMap != -1 ) {
175176
176177 let uvPrime = material.iridescenceMapTransform * vec3f( uv, 1 );
177- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.iridescenceMap ) , 0 );
178+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.iridescenceMap, 0 );
178179 iridescence *= texColor.r;
179180
180181 }
@@ -183,7 +184,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
183184 if ( material.iridescenceThicknessMap != -1 ) {
184185
185186 let uvPrime = material.iridescenceThicknessMapTransform * vec3f( uv, 1 );
186- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.iridescenceThicknessMap ) , 0 );
187+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.iridescenceThicknessMap, 0 );
187188
188189 iridescenceThickness = mix(
189190 material.iridescenceThicknessMinimum,
@@ -197,7 +198,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
197198 if ( material.specularColorMap != -1 ) {
198199
199200 let uvPrime = material.specularColorMapTransform * vec3f( uv, 1 );
200- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.specularColorMap ) , 0 );
201+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.specularColorMap, 0 );
201202 specularColor *= texColor.rgb;
202203
203204 }
@@ -206,7 +207,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
206207 if ( material.specularIntensityMap != -1 ) {
207208
208209 let uvPrime = material.specularIntensityMapTransform * vec3f( uv, 1 );
209- let texColor = textureSampleLevel ( textures, textureSampler, uvPrime.xy, i32( material.specularIntensityMap ) , 0 );
210+ let texColor = sampleTexel ( textures, textureSampler, uvPrime.xy, material.specularIntensityMap, 0 );
210211 specularIntensity *= texColor.r;
211212
212213 }
@@ -265,6 +266,7 @@ export const getSurfaceRecordFunc = wgslFn( /* wgsl */ `
265266 inverseMat3x3Func ,
266267 iorToF0Func ,
267268 getBasisFromNormalFunc ,
269+ sampleTexelFunc ,
268270 surfaceRecordStruct ,
269271] ) ;
270272
0 commit comments