Skip to content

Commit

Permalink
Merge pull request #655 from dongho-shin/dev/add-alphaMapTransform
Browse files Browse the repository at this point in the history
Add alphaMapTransform
  • Loading branch information
gkjohnson authored Jun 26, 2024
2 parents 5fa2b31 + 6347f8e commit 3dec77c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/materials/pathtracing/PhysicalPathTracingMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PhysicalCameraUniform } from '../../uniforms/PhysicalCameraUniform.js';
import { EquirectHdrInfoUniform } from '../../uniforms/EquirectHdrInfoUniform.js';
import { LightsInfoUniformStruct } from '../../uniforms/LightsInfoUniformStruct.js';
import { AttributesTextureArray } from '../../uniforms/AttributesTextureArray.js';
import { MaterialsTexture } from '../../uniforms/MaterialsTexture.js';
import { MaterialsTexture, MATERIAL_PIXELS } from '../../uniforms/MaterialsTexture.js';
import { RenderTarget2DArray } from '../../uniforms/RenderTarget2DArray.js';
import { StratifiedSamplesTexture } from '../../uniforms/StratifiedSamplesTexture.js';
import { BlueNoiseTexture } from '../../textures/BlueNoiseTexture.js';
Expand Down Expand Up @@ -66,6 +66,7 @@ export class PhysicalPathTracingMaterial extends MaterialBase {
ATTR_TANGENT: 1,
ATTR_UV: 2,
ATTR_COLOR: 3,
MATERIAL_PIXELS: MATERIAL_PIXELS,
},

uniforms: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export const attenuate_hit_function = /* glsl */`
// alphaMap
if ( material.alphaMap != - 1 ) {
albedo.a *= texture2D( textures, vec3( uv, material.alphaMap ) ).x;
vec3 uvPrime = material.alphaMapTransform * vec3( uv, 1 );
albedo.a *= texture2D( textures, vec3( uvPrime.xy, material.alphaMap ) ).x;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const get_surface_record_function = /* glsl */`
// alphaMap
if ( material.alphaMap != - 1 ) {
albedo.a *= texture2D( textures, vec3( uv, material.alphaMap ) ).x;
vec3 uvPrime = material.alphaMapTransform * vec3( uv, 1 );
albedo.a *= texture2D( textures, vec3( uvPrime.xy, material.alphaMap ) ).x;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shader/bvh/inside_fog_volume_function.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const inside_fog_volume_function = /* glsl */`
// returns whether the given material is a fog material or not
bool isMaterialFogVolume( sampler2D materials, uint materialIndex ) {
uint i = materialIndex * 45u;
uint i = materialIndex * uint( MATERIAL_PIXELS );
vec4 s14 = texelFetch1D( materials, i + 14u );
return bool( int( s14.b ) & 4 );
Expand Down
4 changes: 3 additions & 1 deletion src/shader/structs/material_struct.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const material_struct = /* glsl */ `
mat3 iridescenceThicknessMapTransform;
mat3 specularColorMapTransform;
mat3 specularIntensityMapTransform;
mat3 alphaMapTransform;
};
Expand All @@ -101,7 +102,7 @@ export const material_struct = /* glsl */ `
Material readMaterialInfo( sampler2D tex, uint index ) {
uint i = index * 45u;
uint i = index * uint( MATERIAL_PIXELS );
vec4 s0 = texelFetch1D( tex, i + 0u );
vec4 s1 = texelFetch1D( tex, i + 1u );
Expand Down Expand Up @@ -200,6 +201,7 @@ export const material_struct = /* glsl */ `
m.iridescenceThicknessMapTransform = m.iridescenceThicknessMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 24u );
m.specularColorMapTransform = m.specularColorMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 26u );
m.specularIntensityMapTransform = m.specularIntensityMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 28u );
m.alphaMapTransform = m.alphaMap == - 1 ? mat3( 1.0 ) : readTextureTransform( tex, firstTextureTransformIdx + 30u );
return m;
Expand Down
5 changes: 4 additions & 1 deletion src/uniforms/MaterialsTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DataTexture, RGBAFormat, ClampToEdgeWrapping, FloatType, FrontSide, Bac
import { getTextureHash } from '../core/utils/sceneUpdateUtils.js';
import { bufferToHash } from '../utils/bufferToHash.js';

const MATERIAL_PIXELS = 45;
export const MATERIAL_PIXELS = 47;
const MATERIAL_STRIDE = MATERIAL_PIXELS * 4;

class MaterialFeatures {
Expand Down Expand Up @@ -427,6 +427,9 @@ export class MaterialsTexture extends DataTexture {
// specularIntensityMap transform 43
index += writeTextureMatrixToArray( m, 'specularIntensityMap', floatArray, index );

// alphaMap transform 45
index += writeTextureMatrixToArray( m, 'alphaMap', floatArray, index );

}

// check if the contents have changed
Expand Down

0 comments on commit 3dec77c

Please sign in to comment.