Skip to content

Commit b49b44b

Browse files
committed
Alias Fix
Wood rings and cell structure suffered from aliasing. Improved by blurring rings based on camera distance and changing cell size based on camera distance.
1 parent e01ab4c commit b49b44b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

examples/jsm/materials/ProceduralWood.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,14 @@ const spaceWarp = TSL.Fn( ( [ p, warpStrength, xyScale, zScale ] ) => {
205205

206206
const woodRings = TSL.Fn( ( [ w, ringCount, ringBias, ringSizeVariance, ringVarianceScale, barkThickness ] ) => {
207207

208-
const rings = noiseFbm( w.mul( ringVarianceScale ), TSL.float( 1 ), TSL.float( 0.5 ), TSL.float( 2 ), TSL.int( 1 ) ).mul( ringSizeVariance ).add( w ).mul( ringCount ).fract().mul( barkThickness );
208+
const rings = noiseFbm( w.mul( ringVarianceScale ), TSL.float( 1 ), TSL.float( 0.5 ), TSL.float( 1 ), TSL.int( 1 ) ).mul( ringSizeVariance ).add( w ).mul( ringCount ).fract().mul( barkThickness );
209209

210-
return TSL.min( mapRange( rings, 0, ringBias, 0, 1, TSL.bool( true ) ), mapRange( rings, ringBias, 1, 1, 0, TSL.bool( true ) ) );
210+
const sharpRings = TSL.min( mapRange( rings, 0, ringBias, 0, 1, TSL.bool( true ) ), mapRange( rings, ringBias, 1, 1, 0, TSL.bool( true ) ) );
211+
212+
const blurAmount = TSL.max(TSL.positionView.length().div(10), 1);
213+
const blurredRings = TSL.smoothstep( blurAmount.negate(), blurAmount, sharpRings.sub( 0.5 ) ).mul( 0.5 ).add( 0.5 );
214+
215+
return blurredRings;
211216

212217
} );
213218

@@ -257,7 +262,7 @@ const wood = TSL.Fn( ( [
257262
const detailWarp = spaceWarp( mainWarp, fineWarpStrength, fineWarpScale, 0.17 );
258263
const rings = woodRings( detailWarp.length(), ringCount, ringBias, ringSizeVariance, ringVarianceScale, barkThickness );
259264
const detail = woodDetail( detailWarp, p, detailWarp.length(), splotchScale );
260-
const cells = cellStructure( mainWarp, cellScale, cellSize );
265+
const cells = cellStructure( mainWarp, cellScale, cellSize.div(TSL.max(TSL.positionView.length().mul(10), 1)) );
261266
const baseColor = TSL.mix( darkGrainColor, lightGrainColor, rings );
262267

263268
return softLightMix( splotchIntensity, softLightMix( 0.407, baseColor, cells ), detail );

0 commit comments

Comments
 (0)