Skip to content

Commit 269e892

Browse files
authored
NodeMaterial: Fix getAlphaHashThreshold() properties conflict (#29977)
* Fix `getAlphaHashThreshold()` properties conflict * cleanup
1 parent 92e60c2 commit 269e892

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/nodes/functions/material/getAlphaHashThreshold.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,47 @@ const getAlphaHashThreshold = /*@__PURE__*/ Fn( ( [ position ] ) => {
2424
const maxDeriv = max(
2525
length( dFdx( position.xyz ) ),
2626
length( dFdy( position.xyz ) )
27-
).toVar( 'maxDeriv' );
27+
);
2828

2929
const pixScale = float( 1 ).div( float( ALPHA_HASH_SCALE ).mul( maxDeriv ) ).toVar( 'pixScale' );
3030

3131
// Find two nearest log-discretized noise scales
3232
const pixScales = vec2(
3333
exp2( floor( log2( pixScale ) ) ),
3434
exp2( ceil( log2( pixScale ) ) )
35-
).toVar( 'pixScales' );
35+
);
3636

3737
// Compute alpha thresholds at our two noise scales
3838
const alpha = vec2(
3939
hash3D( floor( pixScales.x.mul( position.xyz ) ) ),
4040
hash3D( floor( pixScales.y.mul( position.xyz ) ) ),
41-
).toVar( 'alpha' );
41+
);
4242

4343
// Factor to interpolate lerp with
44-
const lerpFactor = fract( log2( pixScale ) ).toVar( 'lerpFactor' );
44+
const lerpFactor = fract( log2( pixScale ) );
4545

4646
// Interpolate alpha threshold from noise at two scales
47-
const x = add( mul( lerpFactor.oneMinus(), alpha.x ), mul( lerpFactor, alpha.y ) ).toVar( 'x' );
47+
const x = add( mul( lerpFactor.oneMinus(), alpha.x ), mul( lerpFactor, alpha.y ) );
4848

4949
// Pass into CDF to compute uniformly distrib threshold
50-
const a = min( lerpFactor, lerpFactor.oneMinus() ).toVar( 'a' );
50+
const a = min( lerpFactor, lerpFactor.oneMinus() );
5151
const cases = vec3(
5252
x.mul( x ).div( mul( 2.0, a ).mul( sub( 1.0, a ) ) ),
5353
x.sub( mul( 0.5, a ) ).div( sub( 1.0, a ) ),
54-
sub( 1.0, sub( 1.0, x ).mul( sub( 1.0, x ) ).div( mul( 2.0, a ).mul( sub( 1.0, a ) ) ) ) ).toVar( 'cases' );
54+
sub( 1.0, sub( 1.0, x ).mul( sub( 1.0, x ) ).div( mul( 2.0, a ).mul( sub( 1.0, a ) ) ) ) );
5555

5656
// Find our final, uniformly distributed alpha threshold (ατ)
5757
const threshold = x.lessThan( a.oneMinus() ).select( x.lessThan( a ).select( cases.x, cases.y ), cases.z );
5858

5959
// Avoids ατ == 0. Could also do ατ =1-ατ
6060
return clamp( threshold, 1.0e-6, 1.0 );
6161

62+
} ).setLayout( {
63+
name: 'getAlphaHashThreshold',
64+
type: 'float',
65+
inputs: [
66+
{ name: 'position', type: 'vec3' }
67+
]
6268
} );
6369

6470
export default getAlphaHashThreshold;

0 commit comments

Comments
 (0)