Skip to content

Commit

Permalink
bring back comment
Browse files Browse the repository at this point in the history
  • Loading branch information
pailhead committed May 29, 2018
1 parent f6ca12b commit 479eff5
Showing 1 changed file with 65 additions and 1 deletion.
66 changes: 65 additions & 1 deletion examples/webgl_materials_extended_instancing.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,74 @@


<script>

/*eslint-disable*/
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();

/**
* Requirement:
*
* Render the same geometry multiple times with varying scale and position.
*
* Problem:
*
* Rendering a scene graph with multiple Mesh objects sharing the same geometry
* causes many draw calls to happen, incurring overhead.
*
* Solution:
*
* Use instancing with InstancedBufferGeometry to draw multiple instances within
* one draw call.
*
* Pitfall:
*
* Instancing requires GLSL code not present in built-in materials in order to work.
*
* Solution:
*
* Couple additional GLSL code with materials, and inject it at parse time into the built-in materials.
*
*/


/**
* All the built in materials are based on shader templates that can be found here:
* https://github.com/mrdoob/three.js/tree/dev/src/renderers/shaders/ShaderLib
*
* Each Material consists of a vertex and fragment shader which are suffixed with _vert and _frag.
*
* These templates consist of a list of #include statements which point to various GLSL chunks that
* can be found here:
* https://github.com/mrdoob/three.js/tree/dev/src/renderers/shaders/ShaderChunk
*
* Some of the functionality overlaps, for example the MeshStandardMaterial is much more complex than
* MeshBasicMaterial, but both need to perform the same discrete steps for basic 3d transformations.
*
*/


/**
* We want to perform instancing in lieu of setting Mesh.position.
* A chunk present in most of the vertex shaders is:
* https://github.com/mrdoob/three.js/blob/dev/src/renderers/shaders/ShaderChunk/begin_vertex.glsl
*
* This is one line of GLSL code:
*
* vec3 transformed = vec3( position );
*
* It declares a vec3 variable called "transformed" and copies the value from the position buffer.
* After this chunk executes, "transformed" holds the value from Geometry.vertices, this is referred to
* as "model space".
*
* The next stage of the transformation uses the "modelViewMatrix" to transform the vertex into view space.
* https://github.com/mrdoob/three.js/blob/dev/src/renderers/shaders/ShaderChunk/project_vertex.glsl
*
* The modelViewMatrix is derived from the data we set with Mesh.position. We can insert another level
* of transformation in between this. The Mesh doing the instancing assumes the role of a Group, and a
* buffer on InstancedBufferGeometry assumes the role of many Mesh objects that are a child of that Group.
*
*/


//we will need some kind of input to the shader
//this example will set a uniform scale and a position offset
var global_instance_chunk =
Expand Down

0 comments on commit 479eff5

Please sign in to comment.