@@ -125,9 +125,6 @@ export class ReactionDiffusionRenderer {
125125 if ( this . renderer . capabilities . maxVertexTextures === 0 ) {
126126 throw new Error ( "System does not support vertex shader textures!" ) ;
127127 }
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- }
131128
132129 // Detect color_buffer_float support
133130 // if (this.renderer.capabilities.isWebGL2 && !this.renderer.extensions.get("EXT_color_buffer_float")) {
@@ -240,12 +237,17 @@ export class ReactionDiffusionRenderer {
240237 this . computeRenderTargets . push ( newTarget ) ;
241238 }
242239
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 ;
244246 console . log ( `Display texture sized to (${ this . displayMaterialUniforms . resolution . value . x } , ${ this . displayMaterialUniforms . resolution . value . y } )` ) ;
245247
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 ;
247250 //console.log(`Compute texture sized to (${this.computeUniforms.resolution.value.x}, ${this.computeUniforms.resolution.value.y})`);
248-
249251 }
250252
251253 CreateMaterials ( ) {
@@ -279,6 +281,10 @@ export class ReactionDiffusionRenderer {
279281 type : "v2" ,
280282 value : new THREE . Vector2 ( )
281283 } ,
284+ texelSize : {
285+ type : "v2" ,
286+ value : new THREE . Vector2 ( )
287+ } ,
282288 time : {
283289 type : "f" ,
284290 value : 1.0
@@ -473,12 +479,13 @@ export class ReactionDiffusionRenderer {
473479 for ( var i = 0 ; i < width ; i ++ ) {
474480 for ( var j = 0 ; j < height ; j ++ ) {
475481
476- let nx = i / width - 0.5 ;
477- let ny = j / height - 0.5 ;
482+ let nx = i / width ;
483+ let ny = j / height ;
478484
479485 let r = simplex . noise2D ( frequency * nx , frequency * ny ) + 1 / 2 ; // Normalize from [-1, 1] to [0, 1]
480486 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
482489
483490 pixels [ px + 1 ] = r ;
484491
0 commit comments