Skip to content

Commit 3dec77c

Browse files
authored
Merge pull request gkjohnson#655 from dongho-shin/dev/add-alphaMapTransform
Add alphaMapTransform
2 parents 5fa2b31 + 6347f8e commit 3dec77c

File tree

6 files changed

+14
-6
lines changed

6 files changed

+14
-6
lines changed

‎src/materials/pathtracing/PhysicalPathTracingMaterial.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { PhysicalCameraUniform } from '../../uniforms/PhysicalCameraUniform.js';
1010
import { EquirectHdrInfoUniform } from '../../uniforms/EquirectHdrInfoUniform.js';
1111
import { LightsInfoUniformStruct } from '../../uniforms/LightsInfoUniformStruct.js';
1212
import { AttributesTextureArray } from '../../uniforms/AttributesTextureArray.js';
13-
import { MaterialsTexture } from '../../uniforms/MaterialsTexture.js';
13+
import { MaterialsTexture, MATERIAL_PIXELS } from '../../uniforms/MaterialsTexture.js';
1414
import { RenderTarget2DArray } from '../../uniforms/RenderTarget2DArray.js';
1515
import { StratifiedSamplesTexture } from '../../uniforms/StratifiedSamplesTexture.js';
1616
import { BlueNoiseTexture } from '../../textures/BlueNoiseTexture.js';
@@ -66,6 +66,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
6666
ATTR_TANGENT: 1,
6767
ATTR_UV: 2,
6868
ATTR_COLOR: 3,
69+
MATERIAL_PIXELS: MATERIAL_PIXELS,
6970
},
7071

7172
uniforms: {

‎src/materials/pathtracing/glsl/attenuate_hit_function.glsl.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export const attenuate_hit_function = /* glsl */`
9797
// alphaMap
9898
if ( material.alphaMap != - 1 ) {
9999
100-
albedo.a *= texture2D( textures, vec3( uv, material.alphaMap ) ).x;
100+
vec3 uvPrime = material.alphaMapTransform * vec3( uv, 1 );
101+
albedo.a *= texture2D( textures, vec3( uvPrime.xy, material.alphaMap ) ).x;
101102
102103
}
103104

‎src/materials/pathtracing/glsl/get_surface_record_function.glsl.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export const get_surface_record_function = /* glsl */`
4848
// alphaMap
4949
if ( material.alphaMap != - 1 ) {
5050
51-
albedo.a *= texture2D( textures, vec3( uv, material.alphaMap ) ).x;
51+
vec3 uvPrime = material.alphaMapTransform * vec3( uv, 1 );
52+
albedo.a *= texture2D( textures, vec3( uvPrime.xy, material.alphaMap ) ).x;
5253
5354
}
5455

‎src/shader/bvh/inside_fog_volume_function.glsl.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const inside_fog_volume_function = /* glsl */`
77
// returns whether the given material is a fog material or not
88
bool isMaterialFogVolume( sampler2D materials, uint materialIndex ) {
99
10-
uint i = materialIndex * 45u;
10+
uint i = materialIndex * uint( MATERIAL_PIXELS );
1111
vec4 s14 = texelFetch1D( materials, i + 14u );
1212
return bool( int( s14.b ) & 4 );
1313

‎src/shader/structs/material_struct.glsl.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export const material_struct = /* glsl */ `
8181
mat3 iridescenceThicknessMapTransform;
8282
mat3 specularColorMapTransform;
8383
mat3 specularIntensityMapTransform;
84+
mat3 alphaMapTransform;
8485
8586
};
8687
@@ -101,7 +102,7 @@ export const material_struct = /* glsl */ `
101102
102103
Material readMaterialInfo( sampler2D tex, uint index ) {
103104
104-
uint i = index * 45u;
105+
uint i = index * uint( MATERIAL_PIXELS );
105106
106107
vec4 s0 = texelFetch1D( tex, i + 0u );
107108
vec4 s1 = texelFetch1D( tex, i + 1u );
@@ -200,6 +201,7 @@ export const material_struct = /* glsl */ `
200201
m.iridescenceThicknessMapTransform = m.iridescenceThicknessMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 24u );
201202
m.specularColorMapTransform = m.specularColorMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 26u );
202203
m.specularIntensityMapTransform = m.specularIntensityMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 28u );
204+
m.alphaMapTransform = m.alphaMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 30u );
203205
204206
return m;
205207

‎src/uniforms/MaterialsTexture.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DataTexture, RGBAFormat, ClampToEdgeWrapping, FloatType, FrontSide, Bac
22
import { getTextureHash } from '../core/utils/sceneUpdateUtils.js';
33
import { bufferToHash } from '../utils/bufferToHash.js';
44

5-
const MATERIAL_PIXELS = 45;
5+
export const MATERIAL_PIXELS = 47;
66
const MATERIAL_STRIDE = MATERIAL_PIXELS * 4;
77

88
class MaterialFeatures {
@@ -427,6 +427,9 @@ export class MaterialsTexture extends DataTexture {
427427
// specularIntensityMap transform 43
428428
index += writeTextureMatrixToArray( m, 'specularIntensityMap', floatArray, index );
429429

430+
// alphaMap transform 45
431+
index += writeTextureMatrixToArray( m, 'alphaMap', floatArray, index );
432+
430433
}
431434

432435
// check if the contents have changed

0 commit comments

Comments
 (0)