From 11ff68e72b0e8e01aee3e314113d715296da875e Mon Sep 17 00:00:00 2001 From: Jonathan Cole Date: Mon, 1 Feb 2021 22:58:17 -0500 Subject: [PATCH] Add force-half-precision parameter --- readme.md | 3 +++ src/rd-renderer.js | 6 +++++- src/reaction-diffusion.js | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index e61b83b..4a692ca 100644 --- a/readme.md +++ b/readme.md @@ -32,6 +32,9 @@ Demo at [jons.website/projects/reaction-diffusion](https://jons.website/projects - This is a float value greater than 0. Higher numbers mean the peaks are closer together. - If you don't set this value, a circular non-random seed is used instead. - A good way to debug this is to set the time scale to 0. That way, the simulation will stay with whatever the initial seed is. + * For speed, you can force half-precision float precision by setting `force-half-precision="true"`. + - `
` + - Valid values are "true" or "false". If you don't specify, it'll default to "false". ## Building diff --git a/src/rd-renderer.js b/src/rd-renderer.js index 81b7244..1d11237 100644 --- a/src/rd-renderer.js +++ b/src/rd-renderer.js @@ -43,7 +43,7 @@ export class ReactionDiffusionRenderer { this.CheckWebGLSupport(); // Configure renderer based on available texture float precision - if (this.DetectTextureFloat()) { + if (this.DetectTextureFloat() && !this.forceHalfPrecision) { console.log("Using full-precision float textures"); this.imageType = THREE.FloatType; @@ -110,6 +110,10 @@ export class ReactionDiffusionRenderer { this.allowInteraction = optionalParams.allowInteraction; console.log(`Using allow-interaction value from HTML attributes = ${optionalParams.allowInteraction}`); } + if (optionalParams.forceHalfPrecision != null) { + this.forceHalfPrecision = optionalParams.forceHalfPrecision + console.log(`Using force-half-precision value from HTML attributes = ${optionalParams.forceHalfPrecision}`); + } this.ReformRenderTargets(width, height); this.Reset(); diff --git a/src/reaction-diffusion.js b/src/reaction-diffusion.js index 16fea59..066215a 100644 --- a/src/reaction-diffusion.js +++ b/src/reaction-diffusion.js @@ -86,6 +86,9 @@ export class ReactionDiffusion { let allowInteraction = container.getAttribute("allow-interaction"); if (allowInteraction) params["allowInteraction"] = allowInteraction == "true"; + let forceHalfPrecision = container.getAttribute("force-half-precision"); + if (forceHalfPrecision) params["forceHalfPrecision"] = forceHalfPrecision == "true"; + return params; }