Skip to content

Commit 11ff68e

Browse files
committed
Add force-half-precision parameter
1 parent 48c7f1d commit 11ff68e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Demo at [jons.website/projects/reaction-diffusion](https://jons.website/projects
3232
- This is a float value greater than 0. Higher numbers mean the peaks are closer together.
3333
- If you don't set this value, a circular non-random seed is used instead.
3434
- 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.
35+
* For speed, you can force half-precision float precision by setting `force-half-precision="true"`.
36+
- `<div class="reaction-diffusion-container" force-half-precision="true"></div>`
37+
- Valid values are "true" or "false". If you don't specify, it'll default to "false".
3538

3639
## Building
3740

src/rd-renderer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class ReactionDiffusionRenderer {
4343
this.CheckWebGLSupport();
4444

4545
// Configure renderer based on available texture float precision
46-
if (this.DetectTextureFloat()) {
46+
if (this.DetectTextureFloat() && !this.forceHalfPrecision) {
4747
console.log("Using full-precision float textures");
4848
this.imageType = THREE.FloatType;
4949

@@ -110,6 +110,10 @@ export class ReactionDiffusionRenderer {
110110
this.allowInteraction = optionalParams.allowInteraction;
111111
console.log(`Using allow-interaction value from HTML attributes = ${optionalParams.allowInteraction}`);
112112
}
113+
if (optionalParams.forceHalfPrecision != null) {
114+
this.forceHalfPrecision = optionalParams.forceHalfPrecision
115+
console.log(`Using force-half-precision value from HTML attributes = ${optionalParams.forceHalfPrecision}`);
116+
}
113117

114118
this.ReformRenderTargets(width, height);
115119
this.Reset();

src/reaction-diffusion.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ export class ReactionDiffusion {
8686
let allowInteraction = container.getAttribute("allow-interaction");
8787
if (allowInteraction) params["allowInteraction"] = allowInteraction == "true";
8888

89+
let forceHalfPrecision = container.getAttribute("force-half-precision");
90+
if (forceHalfPrecision) params["forceHalfPrecision"] = forceHalfPrecision == "true";
91+
8992
return params;
9093
}
9194

0 commit comments

Comments
 (0)