@@ -125,9 +125,6 @@ export class ReactionDiffusionRenderer {
125
125
if ( this . renderer . capabilities . maxVertexTextures === 0 ) {
126
126
throw new Error ( "System does not support vertex shader textures!" ) ;
127
127
}
128
- if ( this . renderer . capabilities . maxVaryings < 5 ) {
129
- throw new Error ( "System does not support the number of varying vectors (>= 5) needed to function!" ) ;
130
- }
131
128
132
129
// Detect color_buffer_float support
133
130
// if (this.renderer.capabilities.isWebGL2 && !this.renderer.extensions.get("EXT_color_buffer_float")) {
@@ -240,12 +237,17 @@ export class ReactionDiffusionRenderer {
240
237
this . computeRenderTargets . push ( newTarget ) ;
241
238
}
242
239
243
- this . displayMaterialUniforms . resolution . value = new THREE . Vector2 ( width * this . internalResolutionMultiplier , height * this . internalResolutionMultiplier ) ;
240
+ // Determine actual resolution
241
+ let realResolution = new THREE . Vector2 ( width * this . internalResolutionMultiplier , height * this . internalResolutionMultiplier ) ;
242
+ // Determine texel size (size of a pixel when resolution is normalized between 0 and 1)
243
+ let texelSize = new THREE . Vector2 ( 1.0 / realResolution . width , 1.0 / realResolution . height ) ;
244
+
245
+ this . displayMaterialUniforms . resolution . value = realResolution ;
244
246
console . log ( `Display texture sized to (${ this . displayMaterialUniforms . resolution . value . x } , ${ this . displayMaterialUniforms . resolution . value . y } )` ) ;
245
247
246
- this . computeUniforms . resolution . value = new THREE . Vector2 ( width * this . internalResolutionMultiplier , height * this . internalResolutionMultiplier ) ;
248
+ this . computeUniforms . resolution . value = realResolution ;
249
+ this . computeUniforms . texelSize . value = texelSize ;
247
250
//console.log(`Compute texture sized to (${this.computeUniforms.resolution.value.x}, ${this.computeUniforms.resolution.value.y})`);
248
-
249
251
}
250
252
251
253
CreateMaterials ( ) {
@@ -279,6 +281,10 @@ export class ReactionDiffusionRenderer {
279
281
type : "v2" ,
280
282
value : new THREE . Vector2 ( )
281
283
} ,
284
+ texelSize : {
285
+ type : "v2" ,
286
+ value : new THREE . Vector2 ( )
287
+ } ,
282
288
time : {
283
289
type : "f" ,
284
290
value : 1.0
@@ -473,12 +479,13 @@ export class ReactionDiffusionRenderer {
473
479
for ( var i = 0 ; i < width ; i ++ ) {
474
480
for ( var j = 0 ; j < height ; j ++ ) {
475
481
476
- let nx = i / width - 0.5 ;
477
- let ny = j / height - 0.5 ;
482
+ let nx = i / width ;
483
+ let ny = j / height ;
478
484
479
485
let r = simplex . noise2D ( frequency * nx , frequency * ny ) + 1 / 2 ; // Normalize from [-1, 1] to [0, 1]
480
486
r = Math . pow ( r , 20 ) ; // Makes peaks more dramatic. See https://www.redblobgames.com/maps/terrain-from-noise/
481
- r = Math . min ( r , 1 ) ; // Cap value at 1.0
487
+ if ( r > 1.0 ) r = 1 ; // Cap value at 1.0
488
+ if ( r < 0.5 ) r = 0 ; // High pass at 0.5
482
489
483
490
pixels [ px + 1 ] = r ;
484
491
0 commit comments