|
@@ -12,7 +12,10 @@
|
|
|
|
|
|
<h1>[name]</h1>
|
|
|
|
|
|
- <div class="desc">Material rendered with custom shaders. A shader is a small program written in [link:https://www.opengl.org/documentation/glsl/ GLSL] to run on the GPU. You may want to use a custom shader if you need to:
|
|
|
+ <div class="desc">
|
|
|
+ A material rendered with custom shaders. A shader is a small program written in
|
|
|
+ [link:https://www.khronos.org/files/opengles_shading_language.pdf_ES GLSL] that runs on the GPU.
|
|
|
+ You may want to use a custom shader if you need to:
|
|
|
<ul>
|
|
|
<li>implement an effect not included with any of the built-in [page:Material materials]</li>
|
|
|
<li>combine many objects into a single [page:Geometry] or [page:BufferGeometry] in order to improve performance</li>
|
|
@@ -20,13 +23,64 @@
|
|
|
There are the following notes to bear in mind when using a *ShaderMaterial*:
|
|
|
|
|
|
<ul>
|
|
|
- <li>A *ShaderMaterial* will only be rendered properly by [page:WebGLRenderer], since the GLSL code in the *vertexShader* and *fragmentShader* properties must be compiled and run on the GPU using WebGL.</li>
|
|
|
- <li>As of THREE r72, directly assigning attributes in a *ShaderMaterial* is no longer supported. A [page:BufferGeometry] instance (instead of a [page:Geometry] instance) must be used instead, using [page:BufferAttribute] instances to define custom attributes.</li>
|
|
|
- <li>As of THREE r77, [page:WebGLRenderTarget] or [page:WebGLRenderTargetCube] instances are no longer supposed to be used as uniforms. Their [page:Texture texture] property must be used instead.</li>
|
|
|
+ <li>
|
|
|
+ A *ShaderMaterial* will only be rendered properly by [page:WebGLRenderer],
|
|
|
+ since the GLSL code in the [link:https://en.wikipedia.org/wiki/Shader#Vertex_shaders vertexShader]
|
|
|
+ and [link:https://en.wikipedia.org/wiki/Shader#Pixel_shaders fragmentShader] properties must
|
|
|
+ be compiled and run on the GPU using WebGL.
|
|
|
+ </li>
|
|
|
+ <li>
|
|
|
+ As of THREE r72, directly assigning attributes in a ShaderMaterial is no longer supported.
|
|
|
+ A [page:BufferGeometry] instance (instead of a [page:Geometry] instance) must be used instead,
|
|
|
+ using [page:BufferAttribute] instances to define custom attributes.
|
|
|
+ </li>
|
|
|
+ <li>
|
|
|
+ As of THREE r77, [page:WebGLRenderTarget] or [page:WebGLRenderTargetCube] instances
|
|
|
+ are no longer supposed to be used as uniforms. Their [page:Texture texture] property
|
|
|
+ must be used instead.
|
|
|
+ </li>
|
|
|
+ <li>
|
|
|
+ Built in attributes an uniforms are passed to the shaders along with your code.
|
|
|
+ If you don't want the [page:WebGLProgram] to add anything to your shader code, you can use
|
|
|
+ [page:RawShaderMaterial] instead of this class.
|
|
|
+ </li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
|
|
|
- <h3>Example</h3>
|
|
|
+ <h2>Examples</h2>
|
|
|
+
|
|
|
+ <div>
|
|
|
+ [example:webgl_animation_cloth webgl / animation / cloth ]<br />
|
|
|
+ [example:webgl_buffergeometry_custom_attributes_particles webgl / buffergeometry / custom / attributes / particles]<br />
|
|
|
+ [example:webgl_buffergeometry_selective_draw webgl / buffergeometry / selective / draw]<br />
|
|
|
+ [example:webgl_custom_attributes webgl / custom / attributes]<br />
|
|
|
+ [example:webgl_custom_attributes_lines webgl / custom / attributes / lines]<br />
|
|
|
+ [example:webgl_custom_attributes_points webgl / custom / attributes / points]<br />
|
|
|
+ [example:webgl_custom_attributes_points2 webgl / custom / attributes / points2]<br />
|
|
|
+ [example:webgl_custom_attributes_points3 webgl / custom / attributes / points3]<br />
|
|
|
+ [example:webgl_depth_texture webgl / depth / texture]<br />
|
|
|
+ [example:webgl_gpgpu_birds webgl / gpgpu / birds]<br />
|
|
|
+ [example:webgl_gpgpu_protoplanet webgl / gpgpu / protoplanet]<br />
|
|
|
+ [example:webgl_gpgpu_water webgl / gpgpu / water]<br />
|
|
|
+ [example:webgl_hdr webgl / hdr]<br />
|
|
|
+ [example:webgl_interactive_points webgl / interactive / points]<br />
|
|
|
+ [example:webgl_kinect webgl / kinect]<br />
|
|
|
+ [example:webgl_lights_hemisphere webgl / lights / hemisphere]<br />
|
|
|
+ [example:webgl_marchingcubes webgl / marchingcubes]<br />
|
|
|
+ [example:webgl_materials_bumpmap_skin webgl / materials / bumpmap / skin]<br />
|
|
|
+ [example:webgl_materials_envmaps webgl / materials / envmaps]<br />
|
|
|
+ [example:webgl_materials_lightmap webgl / materials / lightmap]<br />
|
|
|
+ [example:webgl_materials_parallaxmap webgl / materials / parallaxmap]<br />
|
|
|
+ [example:webgl_materials_shaders_fresnel webgl / materials / shaders / fresnel]<br />
|
|
|
+ [example:webgl_materials_skin webgl_materials / skin]<br />
|
|
|
+ [example:webgl_materials_texture_hdr webgl / materials / texture / hdr]<br />
|
|
|
+ [example:webgl_materials_wireframe webgl / materials / wireframe]<br />
|
|
|
+ [example:webgl_modifier_tessellation webgl / modifier / tessellation]<br />
|
|
|
+ [example:webgl_nearestneighbour webgl / nearestneighbour]<br />
|
|
|
+ [example:webgl_postprocessing_dof2 webgl / postprocessing / dof2]<br />
|
|
|
+ [example:webgl_postprocessing_godrays webgl / postprocessing / godrays]
|
|
|
+
|
|
|
+ </div>
|
|
|
|
|
|
<code>
|
|
|
var material = new THREE.ShaderMaterial( {
|
|
@@ -44,118 +98,180 @@
|
|
|
} );
|
|
|
</code>
|
|
|
|
|
|
- <h3>Vertex shaders and fragment shaders</h3>
|
|
|
- <p>You can specify two different types of shaders for each material:</p>
|
|
|
- <ul>
|
|
|
- <li>The *vertex shader* runs first; it receives *attributes*, calculates/manipulates the position of each individual vertex, and passes additional data (*varying*s) to the fragment shader.</li>
|
|
|
- <li>The *fragment shader* runs second; it sets the color of each individual "fragment" (pixel) rendered to the screen.</li>
|
|
|
- </ul>
|
|
|
- <p>There are three types of variables in shaders: uniforms, attributes, and varyings:</p>
|
|
|
- <ul>
|
|
|
- <li>*Uniforms* are variables that have the same value for all vertices---lighting, fog, and shadow maps are examples of data that would be stored in uniforms. Uniforms can be accessed by both the vertex shader and the fragment shader.</li>
|
|
|
- <li>*Attributes* are variables associated with each vertex---for instance, the vertex position, face normal, and vertex color are all examples of data that would be stored in attributes. Attributes can <em>only</em> be accessed within the vertex shader.</li>
|
|
|
- <li>*Varyings* are variables that are passed from the vertex shader to the fragment shader. For each fragment, the value of each varying will be smoothly interpolated from the values of adjacent vertices.</li>
|
|
|
- </ul>
|
|
|
- <p>Note that <em>within</em> the shader itself, uniforms and attributes act like constants; you can only modify their values by passing different values to the buffers from your JavaScript code.</p>
|
|
|
- <h3>Built-in attributes and uniforms</h3>
|
|
|
- <p>
|
|
|
- [page:WebGLRenderer] provides many attributes and uniforms to shaders by default; definitions of these variables are prepended to your *fragmentShader* and *vertexShader* code by [page:WebGLProgram] when the shader is compiled; you don't need to declare them yourself. These variables are described in [page:WebGLProgram].
|
|
|
- </p>
|
|
|
- <p>
|
|
|
- Some of these uniforms or attributes (e.g. those pertaining lighting, fog, etc.) require properties to be set on the material in order for [page:WebGLRenderer] to copy the appropriate values to the GPU---make sure to set these flags if you want to use these features in your own shader.
|
|
|
- </p>
|
|
|
- <p>
|
|
|
- If you don't want [page:WebGLProgram] to add anything to your shader code, you can use [page:RawShaderMaterial] instead of this class.
|
|
|
- </p>
|
|
|
-
|
|
|
- <h3>Custom attributes and uniforms</h3>
|
|
|
- <p>Both custom attributes and uniforms must be declared in your GLSL shader code (within *vertexShader* and/or *fragmentShader*). Custom uniforms must be defined in <em>both</em> the *uniforms* property of your *ShaderMaterial*, whereas any custom attributes must be defined via [page:BufferAttribute] instances. Note that *varying*s only need to be declared within the shader code (not within the material).
|
|
|
- </p>
|
|
|
-
|
|
|
- <p>To declare a custom attribute, please reference the [page:BufferGeometry] page for an overview, and the [page:BufferAttribute] page for a detailed look at the *BufferAttribute* API.</p>
|
|
|
- <p>When creating your attributes, each typed array that you create to hold your attribute's data must be a multiple of your data type's size. For example, if your attribute is a [page:Vector3 THREE.Vector3] type, and you have 3000 vertices in your [page:BufferGeometry], your typed array value must be created with a length of 3000 * 3, or 9000 (one value per-component). A table of each data type's size is shown below for reference:</p>
|
|
|
-
|
|
|
- <table>
|
|
|
- <caption><a id="attribute-sizes">Attribute sizes</a></caption>
|
|
|
- <thead>
|
|
|
- <tr>
|
|
|
- <th>GLSL type</th>
|
|
|
- <th>JavaScript type</th>
|
|
|
- <th>Size</th>
|
|
|
- </tr>
|
|
|
- </thead>
|
|
|
- <tbody>
|
|
|
- <tr>
|
|
|
- <td>float</td>
|
|
|
- <td>[page:Number]</td>
|
|
|
- <td>1</td>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <td>vec2</td>
|
|
|
- <td>[page:Vector2 THREE.Vector2]</td>
|
|
|
- <td>2</td>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <td>vec3</td>
|
|
|
- <td>[page:Vector3 THREE.Vector3]</td>
|
|
|
- <td>3</td>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <td>vec3</td>
|
|
|
- <td>[page:Color THREE.Color]</td>
|
|
|
- <td>3</td>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <td>vec4</td>
|
|
|
- <td>[page:Vector4 THREE.Vector4]</td>
|
|
|
- <td>4</td>
|
|
|
- </tr>
|
|
|
- </tbody>
|
|
|
- </table>
|
|
|
-
|
|
|
- <p>Note that attribute buffers are <em>not</em> refreshed automatically when their values change. To update custom attributes, set the *needsUpdate* flag to true on the [page:BufferAttribute] of the geometry (see [page:BufferGeometry] for further details).</p>
|
|
|
-
|
|
|
- <p>
|
|
|
- To declare a custom [page:Uniform], use the *uniforms* property:
|
|
|
- <code>
|
|
|
- uniforms: {
|
|
|
- time: { value: 1.0 },
|
|
|
- resolution: { value: new THREE.Vector2() }
|
|
|
- }
|
|
|
- </code>
|
|
|
- </p>
|
|
|
+ <h2>Vertex shaders and fragment shaders</h2>
|
|
|
|
|
|
- <h2>Constructor</h2>
|
|
|
+ <div>
|
|
|
+ <p>You can specify two different types of shaders for each material:</p>
|
|
|
+ <ul>
|
|
|
+ <li>
|
|
|
+ The vertex shader runs first; it receives *attributes*, calculates / manipulates
|
|
|
+ the position of each individual vertex, and passes additional data (*varying*s) to the fragment shader.
|
|
|
+ </li>
|
|
|
+ <li>
|
|
|
+ The fragment ( or pixel ) shader runs second; it sets the color of each individual "fragment"
|
|
|
+ (pixel) rendered to the screen.
|
|
|
+ </li>
|
|
|
+ </ul>
|
|
|
+ <p>There are three types of variables in shaders: uniforms, attributes, and varyings:</p>
|
|
|
+ <ul>
|
|
|
+ <li>
|
|
|
+ *Uniforms* are variables that have the same value for all vertices - lighting, fog,
|
|
|
+ and shadow maps are examples of data that would be stored in uniforms.
|
|
|
+ Uniforms can be accessed by both the vertex shader and the fragment shader.
|
|
|
+ </li>
|
|
|
+ <li>
|
|
|
+ *Attributes* are variables associated with each vertex---for instance, the vertex position,
|
|
|
+ face normal, and vertex color are all examples of data that would be stored in attributes.
|
|
|
+ Attributes can <em>only</em> be accessed within the vertex shader.
|
|
|
+ </li>
|
|
|
+ <li>
|
|
|
+ *Varyings* are variables that are passed from the vertex shader to the fragment shader.
|
|
|
+ For each fragment, the value of each varying will be smoothly interpolated from the values of adjacent vertices.
|
|
|
+ </li>
|
|
|
+ </ul>
|
|
|
+ <p>
|
|
|
+ Note that <em>within</em> the shader itself, uniforms and attributes act like constants;
|
|
|
+ you can only modify their values by passing different values to the buffers from your JavaScript code.
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+
|
|
|
+
|
|
|
+ <h2>Built-in attributes and uniforms</h2>
|
|
|
+
|
|
|
+ <div>
|
|
|
+ <p>
|
|
|
+ The [page:WebGLRenderer] provides many attributes and uniforms to shaders by default;
|
|
|
+ definitions of these variables are prepended to your *fragmentShader* and *vertexShader*
|
|
|
+ code by the [page:WebGLProgram] when the shader is compiled; you don't need to declare them yourself.
|
|
|
+ See [page:WebGLProgram] for details of these variables.
|
|
|
+ </p>
|
|
|
+ <p>
|
|
|
+ Some of these uniforms or attributes (e.g. those pertaining lighting, fog, etc.)
|
|
|
+ require properties to be set on the material in order for [page:WebGLRenderer] to copy
|
|
|
+ the appropriate values to the GPU - make sure to set these flags if you want to use these
|
|
|
+ features in your own shader.
|
|
|
+ </p>
|
|
|
+ <p>
|
|
|
+ If you don't want [page:WebGLProgram] to add anything to your shader code, you can use
|
|
|
+ [page:RawShaderMaterial] instead of this class.
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+
|
|
|
+
|
|
|
+ <h2>Custom attributes and uniforms</h2>
|
|
|
|
|
|
- <h3>[name]( [page:Object parameters] )</h3>
|
|
|
<div>
|
|
|
- parameters -- An object containing various parameters setting up shaders and their uniforms.
|
|
|
+ <p>
|
|
|
+ Both custom attributes and uniforms must be declared in your GLSL shader code
|
|
|
+ (within *vertexShader* and/or *fragmentShader*). Custom uniforms must be defined in <em>both</em>
|
|
|
+ the *uniforms* property of your *ShaderMaterial*, whereas any custom attributes must be
|
|
|
+ defined via [page:BufferAttribute] instances. Note that *varying*s only need to
|
|
|
+ be declared within the shader code (not within the material).
|
|
|
+ </p>
|
|
|
+ <p>
|
|
|
+ To declare a custom attribute, please reference the [page:BufferGeometry] page for an overview,
|
|
|
+ and the [page:BufferAttribute] page for a detailed look at the *BufferAttribute* API.
|
|
|
+ </p>
|
|
|
+ <p>
|
|
|
+ When creating your attributes, each typed array that you create to hold your
|
|
|
+ attribute's data must be a multiple of your data type's size. For example, if your
|
|
|
+ attribute is a [page:Vector3 THREE.Vector3] type, and you have 3000 vertices in your
|
|
|
+ [page:BufferGeometry], your typed array value must be created with a length of 3000 * 3,
|
|
|
+ or 9000 (one value per-component). A table of each data type's size is shown below for reference:
|
|
|
+ </p>
|
|
|
+
|
|
|
+ <table>
|
|
|
+ <caption><a id="attribute-sizes">Attribute sizes</a></caption>
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>GLSL type</th>
|
|
|
+ <th>JavaScript type</th>
|
|
|
+ <th>Size</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody>
|
|
|
+ <tr>
|
|
|
+ <td>float</td>
|
|
|
+ <td>[page:Number]</td>
|
|
|
+ <td>1</td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>vec2</td>
|
|
|
+ <td>[page:Vector2 THREE.Vector2]</td>
|
|
|
+ <td>2</td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>vec3</td>
|
|
|
+ <td>[page:Vector3 THREE.Vector3]</td>
|
|
|
+ <td>3</td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>vec3</td>
|
|
|
+ <td>[page:Color THREE.Color]</td>
|
|
|
+ <td>3</td>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <td>vec4</td>
|
|
|
+ <td>[page:Vector4 THREE.Vector4]</td>
|
|
|
+ <td>4</td>
|
|
|
+ </tr>
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+
|
|
|
+ <p>
|
|
|
+ Note that attribute buffers are <em>not</em> refreshed automatically when their values change. To update custom attributes,
|
|
|
+ set the *needsUpdate* flag to true on the [page:BufferAttribute] of the geometry (see [page:BufferGeometry]
|
|
|
+ for further details).
|
|
|
+ </p>
|
|
|
+
|
|
|
+ <p>
|
|
|
+ To declare a custom [page:Uniform], use the *uniforms* property:
|
|
|
+ <code>
|
|
|
+ uniforms: {
|
|
|
+ time: { value: 1.0 },
|
|
|
+ resolution: { value: new THREE.Vector2() }
|
|
|
+ }
|
|
|
+ </code>
|
|
|
+ </p>
|
|
|
+
|
|
|
</div>
|
|
|
+
|
|
|
+ <h2>Constructor</h2>
|
|
|
+
|
|
|
+ <h3>[name]( [page:Object parameters] )</h3>
|
|
|
<div>
|
|
|
- shading — Define shading type. Default is THREE.SmoothShading.<br />
|
|
|
- fog — Define whether the material color is affected by global fog settings. Default is true.<br />
|
|
|
- wireframe — render geometry as wireframe. Default is false.<br />
|
|
|
- wireframeLinewidth — Line thickness. Default is 1.<br />
|
|
|
- vertexColors — Define how the vertices gets colored. Default is THREE.NoColors.<br />
|
|
|
- skinning — Define whether the material uses skinning. Default is false.<br />
|
|
|
- morphTargets — Define whether the material uses morphTargets. Default is false.
|
|
|
+ [page:Object parameters] - (optional) an object with one or more properties defining the material's appearance.
|
|
|
+ Any property of the material (including any property inherited from [page:Material]) can be passed in here.
|
|
|
</div>
|
|
|
|
|
|
<h2>Properties</h2>
|
|
|
<div>See the base [page:Material] class for common properties.</div>
|
|
|
|
|
|
- <h3>[property:Object uniforms]</h3>
|
|
|
+ <h3>[property:Boolean clipping]</h3>
|
|
|
<div>
|
|
|
- Object specifying the uniforms to be passed to the shader code; keys are uniform names, values are definitions of the form
|
|
|
- <code>
|
|
|
- { value: 1.0 }
|
|
|
- </code>
|
|
|
- where *value* is the value of the uniform. Names must match the name of the uniform, as defined in the GLSL code. Note that uniforms are refreshed on every frame, so updating the value of the uniform will immediately update the value available to the GLSL code.
|
|
|
+ Defines whether this material supports clipping; true to let the renderer pass the clippingPlanes uniform. Default is false.
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <h3>[property:Object defaultAttributeValues]</h3>
|
|
|
+ <div>
|
|
|
+ When the rendered geometry doesn't include these attributes but the material does,
|
|
|
+ these default values will be passed to the shaders. This avoids errors when buffer data is missing.
|
|
|
+
|
|
|
+ <code>
|
|
|
+this.defaultAttributeValues = {
|
|
|
+ 'color': [ 1, 1, 1 ],
|
|
|
+ 'uv': [ 0, 0 ],
|
|
|
+ 'uv2': [ 0, 0 ]
|
|
|
+};
|
|
|
+ </code>
|
|
|
+
|
|
|
</div>
|
|
|
|
|
|
+
|
|
|
<h3>[property:Object defines]</h3>
|
|
|
<div>
|
|
|
- Defines custom constants using *#define* directives within the GLSL code for both the vertex shader and the fragment shader; each key/value pair yields another directive:
|
|
|
+ Defines custom constants using *#define* directives within the GLSL code for both the
|
|
|
+ vertex shader and the fragment shader; each key/value pair yields another directive:
|
|
|
<code>
|
|
|
defines: {
|
|
|
FOO: 15,
|
|
@@ -170,78 +286,149 @@
|
|
|
in the GLSL code.
|
|
|
</div>
|
|
|
|
|
|
- <h3>[property:String vertexShader]</h3>
|
|
|
+ <h3>[property:Object extensions]</h3>
|
|
|
<div>
|
|
|
- Vertex shader GLSL code. This is the actual code for the shader. In the example above, the *vertexShader* and *fragmentShader* code is extracted from the DOM; it could be passed as a string directly or loaded via AJAX instead.
|
|
|
+ An object with the folowing properties:
|
|
|
+ <code>
|
|
|
+this.extensions = {
|
|
|
+ derivatives: false, // set to use derivatives
|
|
|
+ fragDepth: false, // set to use fragment depth values
|
|
|
+ drawBuffers: false, // set to use draw buffers
|
|
|
+ shaderTextureLOD: false // set to use shader texture LOD
|
|
|
+};
|
|
|
+ </code>
|
|
|
</div>
|
|
|
|
|
|
- <h3>[property:String fragmentShader]</h3>
|
|
|
+
|
|
|
+ <h3>[property:Boolean fog]</h3>
|
|
|
<div>
|
|
|
- Fragment shader GLSL code. This is the actual code for the shader. In the example above, the *vertexShader* and *fragmentShader* code is extracted from the DOM; it could be passed as a string directly or loaded via AJAX instead.
|
|
|
+ Define whether the material color is affected by global fog settings; true to pass
|
|
|
+ fog uniforms to the shader. Default is false.
|
|
|
</div>
|
|
|
|
|
|
- <h3>[property:Number shading]</h3>
|
|
|
+
|
|
|
+ <h3>[property:String fragmentShader]</h3>
|
|
|
<div>
|
|
|
- Define shading type, which determines whether normals are smoothed between vertices; possible values are [page:Materials THREE.SmoothShading] or [page:Materials THREE.FlatShading]. Default is THREE.SmoothShading.
|
|
|
+ Fragment shader GLSL code. This is the actual code for the shader. In the example above,
|
|
|
+ the *vertexShader* and *fragmentShader* code is extracted from the DOM; it could be passed
|
|
|
+ as a string directly or loaded via AJAX instead.
|
|
|
</div>
|
|
|
|
|
|
- <h3>[property:Number linewidth]</h3>
|
|
|
- <div>Controls line thickness; only effective if the material is attached to a [page:Line]. Default is 1.</div>
|
|
|
- <div>Due to limitations in the <a href="https://code.google.com/p/angleproject/" target="_blank">ANGLE layer</a>, on Windows platforms linewidth will always be 1 regardless of the set value.</div>
|
|
|
+ <h3>[property:String index0AttributeName]</h3>
|
|
|
+ <div>
|
|
|
+ If set, this calls [link:https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/bindAttribLocation gl.bindAttribLocation]
|
|
|
+ to bind a generic vertex index to an attribute variable.
|
|
|
+ Default is undefined.
|
|
|
|
|
|
- <h3>[property:Boolean wireframe]</h3>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <h3>[property:Boolean isShaderMaterial]</h3>
|
|
|
<div>
|
|
|
- Render geometry as wireframe (using GL_LINES instead of GL_TRIANGLES). Default is false (i.e. render as flat polygons).
|
|
|
+ Used to check whether this or derived classes are shader materials. Default is *true*.<br /><br />
|
|
|
+
|
|
|
+ You should not change this, as it used internally for optimisation.
|
|
|
</div>
|
|
|
|
|
|
- <h3>[property:Number wireframeLinewidth]</h3>
|
|
|
- <div>Controls wireframe thickness; only effective if the material is attached to a [page:Mesh] and *wireframe* is true. Default is 1.</div>
|
|
|
- <div>Due to limitations in the <a href="https://code.google.com/p/angleproject/" target="_blank">ANGLE layer</a>, on Windows platforms linewidth will always be 1 regardless of the set value.</div>
|
|
|
|
|
|
- <h3>[property:Boolean fog]</h3>
|
|
|
- <div>Define whether the material color is affected by global fog settings; true to pass fog uniforms to the shader. Default is false.</div>
|
|
|
+
|
|
|
|
|
|
<h3>[property:Boolean lights]</h3>
|
|
|
<div>
|
|
|
Defines whether this material uses lighting; true to pass uniform data related to lighting to this shader. Default is false.
|
|
|
</div>
|
|
|
|
|
|
- <h3>[property:Boolean clipping]</h3>
|
|
|
+ <h3>[property:Float linewidth]</h3>
|
|
|
+ <div>Controls wireframe thickness. Default is 1.<br /><br />
|
|
|
+
|
|
|
+ Due to limitations in the [link:https://code.google.com/p/angleproject ANGLE layer],
|
|
|
+ on Windows platforms linewidth will always be 1 regardless of the set value.
|
|
|
+ </div>
|
|
|
+
|
|
|
+
|
|
|
+ <h3>[property:Boolean morphTargets]</h3>
|
|
|
<div>
|
|
|
- Defines whether this material supports clipping; true to let the renderer pass the clippingPlanes uniform. Default is false.
|
|
|
+ Defines whether the material uses morphTargets; true morphTarget attributes to this shader
|
|
|
</div>
|
|
|
|
|
|
- <h3>[property:Number vertexColors]</h3>
|
|
|
+ <h3>[property:boolean morphNormals]</h3>
|
|
|
<div>
|
|
|
- Define how the vertices are colored, by defining how the *colors* attribute gets populated. Possible values are [page:Materials THREE.NoColors], [page:Materials THREE.FaceColors] and [page:Materials THREE.VertexColors]. Default is THREE.NoColors.
|
|
|
+ Defines whether the material uses morphNormals. Set as true to pass morphNormal attributes from the [page:Geometry]
|
|
|
+ to the shader. Default is *false*.
|
|
|
</div>
|
|
|
|
|
|
+
|
|
|
+ <h3>[property:WebGLProgram program]</h3>
|
|
|
+ <div>
|
|
|
+ The compiled shader program associated with this material, generated by [page:WebGLRenderer].
|
|
|
+ You should not need to access this property.
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <h3>[property:Number shading]</h3>
|
|
|
+ <div>
|
|
|
+ Define shading type, which determines whether normals are smoothed between vertices;
|
|
|
+ possible values are [page:Materials THREE.SmoothShading] or [page:Materials THREE.FlatShading]. Default is THREE.SmoothShading.
|
|
|
+ </div>
|
|
|
+
|
|
|
+
|
|
|
<h3>[property:Boolean skinning]</h3>
|
|
|
<div>
|
|
|
Define whether the material uses skinning; true to pass skinning attributes to the shader. Default is false.
|
|
|
</div>
|
|
|
|
|
|
- <h3>[property:Boolean morphTargets]</h3>
|
|
|
+ <h3>[property:Object uniforms]</h3>
|
|
|
<div>
|
|
|
- Defines whether the material uses morphTargets; true morphTarget attributes to this shader
|
|
|
+ An object of the form:
|
|
|
+ <code>
|
|
|
+{ "uniform1": { value: 1.0 }, "uniform2": { value: 2 } }
|
|
|
+ </code>
|
|
|
+ specifying the uniforms to be passed to the shader code; keys are uniform names, values are definitions of the form
|
|
|
+ <code>
|
|
|
+ { value: 1.0 }
|
|
|
+ </code>
|
|
|
+ where *value* is the value of the uniform. Names must match the name of the uniform,
|
|
|
+ as defined in the GLSL code. Note that uniforms are refreshed on every frame,
|
|
|
+ so updating the value of the uniform will immediately update the value available to the GLSL code.
|
|
|
</div>
|
|
|
|
|
|
- <h3>[property:boolean morphNormals]</h3>
|
|
|
+
|
|
|
+ <h3>[property:Number vertexColors]</h3>
|
|
|
<div>
|
|
|
- Defines whether the material uses morphNormals. Set as true to pass morphNormal attributes from the [page:Geometry]
|
|
|
- to the shader. Default is *false*.
|
|
|
+ Define how the vertices are colored, by defining how the *colors* attribute gets populated.
|
|
|
+ Possible values are [page:Materials THREE.NoColors], [page:Materials THREE.FaceColors] and
|
|
|
+ [page:Materials THREE.VertexColors]. Default is THREE.NoColors.
|
|
|
</div>
|
|
|
|
|
|
- <h3>[property:WebGLProgram program]</h3>
|
|
|
+ <h3>[property:String vertexShader]</h3>
|
|
|
+ <div>
|
|
|
+ Vertex shader GLSL code. This is the actual code for the shader. In the example above,
|
|
|
+ the *vertexShader* and *fragmentShader* code is extracted from the DOM; it could be passed
|
|
|
+ as a string directly or loaded via AJAX instead.
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <h3>[property:Boolean wireframe]</h3>
|
|
|
<div>
|
|
|
- The compiled shader program associated with this material, generated by [page:WebGLRenderer]. You should not need to access this property.
|
|
|
+ Render geometry as wireframe (using GL_LINES instead of GL_TRIANGLES). Default is false (i.e. render as flat polygons).
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <h3>[property:Float wireframeLinewidth]</h3>
|
|
|
+ <div>Controls wireframe thickness. Default is 1.<br /><br />
|
|
|
+
|
|
|
+ Due to limitations in the [link:https://code.google.com/p/angleproject ANGLE layer],
|
|
|
+ on Windows platforms linewidth will always be 1 regardless of the set value.
|
|
|
</div>
|
|
|
|
|
|
+
|
|
|
+
|
|
|
<h2>Methods</h2>
|
|
|
+ <div>See the base [page:Material] class for common methods.</div>
|
|
|
|
|
|
<h3>[method:ShaderMaterial clone]() [page:ShaderMaterial this]</h3>
|
|
|
<div>
|
|
|
- Generates a shallow copy of this material. Note that the vertexShader and fragmentShader are copied <em>by reference</em>, as are the definitions of the *attributes*; this means that clones of the material will share the same compiled [page:WebGLProgram]. However, the *uniforms* are copied <em>by value</em>, which allows you to have different sets of uniforms for different copies of the material.
|
|
|
+ Generates a shallow copy of this material. Note that the vertexShader and fragmentShader
|
|
|
+ are copied <em>by reference</em>, as are the definitions of the *attributes*; this means
|
|
|
+ that clones of the material will share the same compiled [page:WebGLProgram]. However, the
|
|
|
+ *uniforms* are copied <em>by value</em>, which allows you to have different sets of uniforms
|
|
|
+ for different copies of the material.
|
|
|
</div>
|
|
|
|
|
|
<h2>Source</h2>
|