javascript - Three.js same shader with multiple objects different parameters -


i'm working three.js , trying write shader render many spheres of same attributes except radii. radii varying in real time , i'm not sure efficient way change radii of individual spheres.

here have far test. seems uniform variable radius doesn't affect radius of sphere @ all.

<!doctype html> <html> <title>test sphere</title> <head> </head> <body> <div id="test"></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r71/three.min.js"></script> <script type="x-shader/x-vertex" id="vertexshader">     /**      * multiply each vertex      * model-view matrix ,      * projection matrix (both provided      * three.js) final      * vertex position      */      uniform float radius;      void main() {       gl_position = radius * projectionmatrix *                     modelviewmatrix *                     vec4(position,1.0);     }  </script>  <script type="x-shader/x-vertex" id="fragmentshader">     /**      * set colour lovely pink.      * note color 4d float      * vector, r,g,b , , each part      * runs 0.0 1.0      */     void main() {       gl_fragcolor = vec4(1.0,  // r                           0.0,  // g                           1.0,  // b                           1.0); //     }  </script>  <script> var light; var material; var scene, camera;  var puthere = document.getelementbyid("test"); container = document.createelement( 'div' ); puthere.appendchild( container );  scene = new three.scene(); camera = new three.perspectivecamera( 75, window.innerwidth / window.innerheight, 1, 1000 ); camera.position.z = 300; renderer = new three.webglrenderer(); renderer.setpixelratio( window.devicepixelratio ); renderer.setsize( window.innerwidth, window.innerheight ) container.appendchild( renderer.domelement );  var uniforms = {     radius: { type: "f", value: 10.0 } };  material = new three.shadermaterial( {     uniforms: uniforms,     vertexshader: document.getelementbyid( 'vertexshader' ).textcontent,     fragmentshader: document.getelementbyid( 'fragmentshader' ).textcontent } );  var geometry = new three.spheregeometry( 1, 32, 32 ); sphere = new three.mesh( geometry, material ); // material.needsupdate = true; scene.add( sphere ); scene.add( camera ); renderer.render( scene, camera ); setinterval( function() {     console.log( "here" );     sphere.material.uniforms.radius.value += 10;     renderer.render( scene, camera ); }, 100);  </script>  </body> </html> 


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -