Skip to content

Commit

Permalink
Add force-half-precision parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
colejd committed Feb 2, 2021
1 parent 48c7f1d commit 11ff68e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"`.
- `<div class="reaction-diffusion-container" force-half-precision="true"></div>`
- Valid values are "true" or "false". If you don't specify, it'll default to "false".

## Building

Expand Down
6 changes: 5 additions & 1 deletion src/rd-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/reaction-diffusion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 11ff68e

Please sign in to comment.