From 9006b8320b2fc62922ea231918153504fada1ce4 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Wed, 29 Jul 2020 09:46:11 +0200 Subject: [PATCH] Examples: Clean up. --- examples/js/misc/GPUComputationRenderer.js | 13 ++++++++++--- examples/jsm/misc/GPUComputationRenderer.js | 2 -- examples/webgl_gpgpu_birds.html | 9 +++++++-- examples/webgl_gpgpu_birds_gltf.html | 6 +++++- examples/webgl_gpgpu_protoplanet.html | 6 +++++- examples/webgl_gpgpu_water.html | 7 ++++++- 6 files changed, 33 insertions(+), 10 deletions(-) diff --git a/examples/js/misc/GPUComputationRenderer.js b/examples/js/misc/GPUComputationRenderer.js index 67e268de90e8c..7d96eed124443 100644 --- a/examples/js/misc/GPUComputationRenderer.js +++ b/examples/js/misc/GPUComputationRenderer.js @@ -1,7 +1,5 @@ console.warn( "THREE.GPUComputationRenderer: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation." ); /** - * @author yomboprime https://github.com/yomboprime - * * GPUComputationRenderer, based on SimulationRenderer by zz85 * * The GPUComputationRenderer uses the concept of variables. These variables are RGBA float textures that hold 4 floats @@ -104,6 +102,8 @@ THREE.GPUComputationRenderer = function ( sizeX, sizeY, renderer ) { this.currentTextureIndex = 0; + var dataType = THREE.FloatType; + var scene = new THREE.Scene(); var camera = new THREE.Camera(); @@ -119,6 +119,13 @@ THREE.GPUComputationRenderer = function ( sizeX, sizeY, renderer ) { scene.add( mesh ); + this.setDataType = function ( type ) { + + dataType = type; + return this; + + }; + this.addVariable = function ( variableName, computeFragmentShader, initialValueTexture ) { var material = this.createShaderMaterial( computeFragmentShader ); @@ -311,7 +318,7 @@ THREE.GPUComputationRenderer = function ( sizeX, sizeY, renderer ) { minFilter: minFilter, magFilter: magFilter, format: THREE.RGBAFormat, - type: ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) ? THREE.HalfFloatType : THREE.FloatType, + type: dataType, stencilBuffer: false, depthBuffer: false } ); diff --git a/examples/jsm/misc/GPUComputationRenderer.js b/examples/jsm/misc/GPUComputationRenderer.js index fd9a678db62c8..c532337968177 100644 --- a/examples/jsm/misc/GPUComputationRenderer.js +++ b/examples/jsm/misc/GPUComputationRenderer.js @@ -1,6 +1,4 @@ /** - * @author yomboprime https://github.com/yomboprime - * * GPUComputationRenderer, based on SimulationRenderer by zz85 * * The GPUComputationRenderer uses the concept of variables. These variables are RGBA float textures that hold 4 floats diff --git a/examples/webgl_gpgpu_birds.html b/examples/webgl_gpgpu_birds.html index b4ff47be9a82c..50a42a23ceab0 100644 --- a/examples/webgl_gpgpu_birds.html +++ b/examples/webgl_gpgpu_birds.html @@ -484,7 +484,9 @@ gpuCompute = new GPUComputationRenderer( WIDTH, WIDTH, renderer ); if ( isSafari() ) { + gpuCompute.setDataType( THREE.HalfFloatType ); + } var dtPosition = gpuCompute.createTexture(); @@ -519,16 +521,19 @@ positionVariable.wrapT = THREE.RepeatWrapping; var error = gpuCompute.init(); + if ( error !== null ) { - console.error( error ); + console.error( error ); } } function isSafari() { - return !!navigator.userAgent.match(/Safari/i) && !navigator.userAgent.match(/Chrome/i); + + return !! navigator.userAgent.match( /Safari/i ) && ! navigator.userAgent.match( /Chrome/i ); + } function initBirds() { diff --git a/examples/webgl_gpgpu_birds_gltf.html b/examples/webgl_gpgpu_birds_gltf.html index ca53021b58349..1bb5d523e74b4 100644 --- a/examples/webgl_gpgpu_birds_gltf.html +++ b/examples/webgl_gpgpu_birds_gltf.html @@ -432,7 +432,9 @@ gpuCompute = new GPUComputationRenderer( WIDTH, WIDTH, renderer ); if ( isSafari() ) { + gpuCompute.setDataType( THREE.HalfFloatType ); + } var dtPosition = gpuCompute.createTexture(); @@ -477,7 +479,9 @@ } function isSafari() { - return !!navigator.userAgent.match(/Safari/i) && !navigator.userAgent.match(/Chrome/i); + + return !! navigator.userAgent.match( /Safari/i ) && ! navigator.userAgent.match( /Chrome/i ); + } function initBirds() { diff --git a/examples/webgl_gpgpu_protoplanet.html b/examples/webgl_gpgpu_protoplanet.html index d4fe1b71bdfa4..e6c937fd7664a 100644 --- a/examples/webgl_gpgpu_protoplanet.html +++ b/examples/webgl_gpgpu_protoplanet.html @@ -317,7 +317,9 @@ gpuCompute = new GPUComputationRenderer( WIDTH, WIDTH, renderer ); if ( isSafari() ) { + gpuCompute.setDataType( THREE.HalfFloatType ); + } var dtPosition = gpuCompute.createTexture(); @@ -347,7 +349,9 @@ } function isSafari() { - return !!navigator.userAgent.match(/Safari/i) && !navigator.userAgent.match(/Chrome/i); + + return !! navigator.userAgent.match( /Safari/i ) && ! navigator.userAgent.match( /Chrome/i ); + } function restartSimulation() { diff --git a/examples/webgl_gpgpu_water.html b/examples/webgl_gpgpu_water.html index 16aafe3b181e3..dfef245bda276 100644 --- a/examples/webgl_gpgpu_water.html +++ b/examples/webgl_gpgpu_water.html @@ -445,7 +445,9 @@ gpuCompute = new GPUComputationRenderer( WIDTH, WIDTH, renderer ); if ( isSafari() ) { + gpuCompute.setDataType( THREE.HalfFloatType ); + } var heightmap0 = gpuCompute.createTexture(); @@ -497,7 +499,9 @@ } function isSafari() { - return !!navigator.userAgent.match(/Safari/i) && !navigator.userAgent.match(/Chrome/i); + + return !! navigator.userAgent.match( /Safari/i ) && ! navigator.userAgent.match( /Chrome/i ); + } function fillTexture( texture ) { @@ -516,6 +520,7 @@ mult *= 1.25; } + return r; }