Skip to content

Commit 8af4653

Browse files
Ludobakamrdoob
authored andcommitted
Created Uniform documentation (mrdoob#9632)
* Created Uniform documentation and removed Uniform types from ShaderMaterial * Fixed spaces to tabs
1 parent 10adc95 commit 8af4653

File tree

3 files changed

+216
-147
lines changed

3 files changed

+216
-147
lines changed

docs/api/core/Uniform.html

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<base href="../../" />
6+
<script src="list.js"></script>
7+
<script src="page.js"></script>
8+
<link type="text/css" rel="stylesheet" href="page.css" />
9+
</head>
10+
<body>
11+
<h1>[name]</h1>
12+
13+
<div class="desc">Uniforms are global [link:https://www.opengl.org/documentation/glsl/ GLSL] variables. They are passed to shader programs.
14+
</div>
15+
16+
<h3>Example</h3>
17+
<p>
18+
When declaring a uniform of a [page:ShaderMaterial], it is declared by value or by object.
19+
</p>
20+
<code>
21+
uniforms: {
22+
time: { value: 1.0 },
23+
resolution: new THREE.Uniform(new THREE.Vector2())
24+
}
25+
</code>
26+
27+
<h3>Uniform types</h3>
28+
29+
<p>
30+
Each uniform must have a *value* property. The type of the value must correspond to the type of the uniform variable in the GLSL code as specified for the primitive GLSL types in the table below. Uniform structures and arrays are also supported. GLSL arrays of primitive type must either be specified as an array of the corresponding THREE objects or as a flat array containing the data of all the objects. In other words; GLSL primitives in arrays must not be represented by arrays. This rule does not apply transitively. An array of *vec2* arrays, each with a length of five vectors, must be an array of arrays, of either five *THREE.Vector2* objects or ten *number*s.
31+
</p>
32+
<table>
33+
<caption><a id="uniform-types">Uniform types</a></caption>
34+
<thead>
35+
<tr>
36+
<th>GLSL type</th>
37+
<th>JavaScript type</th>
38+
</tr>
39+
</thead>
40+
<tbody>
41+
42+
<tr>
43+
<td>int</td>
44+
<td>[page:Number]</td>
45+
</tr>
46+
<tr>
47+
<td>float</td>
48+
<td>[page:Number]</td>
49+
</tr>
50+
<tr>
51+
<td>bool</td>
52+
<td>[page:Boolean]</td>
53+
</tr>
54+
<tr>
55+
<td>bool</td>
56+
<td>[page:Number]</td>
57+
</tr>
58+
59+
<tr>
60+
<td>vec2</td>
61+
<td>[page:Vector2 THREE.Vector2]</td>
62+
</tr>
63+
<tr>
64+
<td>vec2</td>
65+
<td>[page:Float32Array Float32Array] (*)</td>
66+
</tr>
67+
<tr>
68+
<td>vec2</td>
69+
<td>[page:Array Array] (*)</td>
70+
</tr>
71+
<tr>
72+
<td>vec3</td>
73+
<td>[page:Vector3 THREE.Vector3]</td>
74+
</tr>
75+
<tr>
76+
<td>vec3</td>
77+
<td>[page:Color THREE.Color]</td>
78+
</tr>
79+
<tr>
80+
<td>vec3</td>
81+
<td>[page:Float32Array Float32Array] (*)</td>
82+
</tr>
83+
<tr>
84+
<td>vec3</td>
85+
<td>[page:Array Array] (*)</td>
86+
</tr>
87+
<tr>
88+
<td>vec4</td>
89+
<td>[page:Vector4 THREE.Vector4]</td>
90+
</tr>
91+
<tr>
92+
<td>vec4</td>
93+
<td>[page:Quaternion THREE.Quaternion]</td>
94+
</tr>
95+
<tr>
96+
<td>vec4</td>
97+
<td>[page:Float32Array Float32Array] (*)</td>
98+
</tr>
99+
<tr>
100+
<td>vec4</td>
101+
<td>[page:Array Array] (*)</td>
102+
</tr>
103+
104+
<tr>
105+
<td>mat2</td>
106+
<td>[page:Float32Array Float32Array] (*)</td>
107+
</td>
108+
<tr>
109+
<td>mat2</td>
110+
<td>[page:Array Array] (*)</td>
111+
</td>
112+
<tr>
113+
<td>mat3</td>
114+
<td>[page:Matrix3 THREE.Matrix3]</td>
115+
</tr>
116+
<tr>
117+
<td>mat3</td>
118+
<td>[page:Float32Array Float32Array] (*)</td>
119+
</tr>
120+
<tr>
121+
<td>mat3</td>
122+
<td>[page:Array Array] (*)</td>
123+
</tr>
124+
<tr>
125+
<td>mat4</td>
126+
<td>[page:Matrix3 THREE.Matrix4]</td>
127+
</tr>
128+
<tr>
129+
<td>mat4</td>
130+
<td>[page:Float32Array Float32Array] (*)</td>
131+
</tr>
132+
<tr>
133+
<td>mat4</td>
134+
<td>[page:Array Array] (*)</td>
135+
</tr>
136+
137+
<tr>
138+
<td>ivec2, bvec2</td>
139+
<td>[page:Float32Array Float32Array] (*)</td>
140+
</tr>
141+
<tr>
142+
<td>ivec2, bvec2</td>
143+
<td>[page:Array Array] (*)</td>
144+
</tr>
145+
<tr>
146+
<td>ivec3, bvec3</td>
147+
<td>[page:Int32Array Int32Array] (*)</td>
148+
</tr>
149+
<tr>
150+
<td>ivec3, bvec3</td>
151+
<td>[page:Array Array] (*)</td>
152+
</tr>
153+
<tr>
154+
<td>ivec4, bvec4</td>
155+
<td>[page:Int32Array Int32Array] (*)</td>
156+
</tr>
157+
<tr>
158+
<td>ivec4, bvec4</td>
159+
<td>[page:Array Array] (*)</td>
160+
</tr>
161+
162+
<tr>
163+
<td>sampler2D</td>
164+
<td>[page:Texture THREE.Texture]</td>
165+
</tr>
166+
<tr>
167+
<td>samplerCube</td>
168+
<td>[page:CubeTexture THREE.CubeTexture]</tr>
169+
</tr>
170+
171+
</tbody>
172+
</table>
173+
</p>
174+
<p>
175+
(*) Same for an (innermost) array (dimension) of the same GLSL type, containing the components of all vectors or matrices in the array.
176+
</p>
177+
178+
<h2>Constructor</h2>
179+
180+
<h3>[name]( [page:Object value] )</h3>
181+
<div>
182+
value -- An object containing the value to set up the uniform. It's type must be one of the Uniform Types described above.
183+
</div>
184+
185+
<h2>Properties</h2>
186+
187+
<h3>[property:Object value]</h3>
188+
<div>
189+
Current value of the uniform.
190+
</div>
191+
192+
<h3>[property:Boolean dynamic]</h3>
193+
<div>
194+
Sets wether this uniform is updated at each render call when used by a renderer.
195+
You must set this attribute by calling [page:.onUpdate].
196+
</div>
197+
198+
<h2>Methods</h2>
199+
200+
<h3>[method:Uniform onUpdate]( [page:Function callback] ) [page:Uniform this]</h3>
201+
<div>
202+
Set the callback function to update this uniform at each render call. The callback has two optional parameters :
203+
<ul>
204+
<li>[page:Object object] : The current object associated to the [page:Material] using this [page:Uniform]</li>
205+
<li>[page:Camera camera] : The current camera used by the current [page:WebGLRenderer]</li>
206+
</ul>
207+
</div>
208+
209+
<h2>Source</h2>
210+
211+
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
212+
</body>
213+
</html>

docs/api/materials/ShaderMaterial.html

Lines changed: 1 addition & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -120,158 +120,13 @@ <h3>Custom attributes and uniforms</h3>
120120
</p>
121121

122122
<p>
123-
To declare a custom uniform, use the *uniforms* property:
123+
To declare a custom [page:Uniform], use the *uniforms* property:
124124
<code>
125125
uniforms: {
126126
time: { value: 1.0 },
127127
resolution: { value: new THREE.Vector2() }
128128
}
129129
</code>
130-
Each uniform must have a *value* property. The type of the value must correspond to the type of the uniform variable in the GLSL code as specified for the primitive GLSL types in the table below. Uniform structures and arrays are also supported. GLSL arrays of primitive type must either be specified as an array of the corresponding THREE objects or as a flat array containing the data of all the objects. In other words; GLSL primitives in arrays must not be represented by arrays. This rule does not apply transitively. An array of *vec2* arrays, each with a length of five vectors, must be an array of arrays, of either five *THREE.Vector2* objects or ten *number*s.
131-
<table>
132-
<caption><a id="uniform-types">Uniform types</a></caption>
133-
<thead>
134-
<tr>
135-
<th>GLSL type</th>
136-
<th>JavaScript type</th>
137-
</tr>
138-
</thead>
139-
<tbody>
140-
141-
<tr>
142-
<td>int</td>
143-
<td>[page:Number]</td>
144-
</tr>
145-
<tr>
146-
<td>float</td>
147-
<td>[page:Number]</td>
148-
</tr>
149-
<tr>
150-
<td>bool</td>
151-
<td>[page:Boolean]</td>
152-
</tr>
153-
<tr>
154-
<td>bool</td>
155-
<td>[page:Number]</td>
156-
</tr>
157-
158-
<tr>
159-
<td>vec2</td>
160-
<td>[page:Vector2 THREE.Vector2]</td>
161-
</tr>
162-
<tr>
163-
<td>vec2</td>
164-
<td>[page:Float32Array Float32Array] (*)</td>
165-
</tr>
166-
<tr>
167-
<td>vec2</td>
168-
<td>[page:Array Array] (*)</td>
169-
</tr>
170-
<tr>
171-
<td>vec3</td>
172-
<td>[page:Vector3 THREE.Vector3]</td>
173-
</tr>
174-
<tr>
175-
<td>vec3</td>
176-
<td>[page:Color THREE.Color]</td>
177-
</tr>
178-
<tr>
179-
<td>vec3</td>
180-
<td>[page:Float32Array Float32Array] (*)</td>
181-
</tr>
182-
<tr>
183-
<td>vec3</td>
184-
<td>[page:Array Array] (*)</td>
185-
</tr>
186-
<tr>
187-
<td>vec4</td>
188-
<td>[page:Vector4 THREE.Vector4]</td>
189-
</tr>
190-
<tr>
191-
<td>vec4</td>
192-
<td>[page:Quaternion THREE.Quaternion]</td>
193-
</tr>
194-
<tr>
195-
<td>vec4</td>
196-
<td>[page:Float32Array Float32Array] (*)</td>
197-
</tr>
198-
<tr>
199-
<td>vec4</td>
200-
<td>[page:Array Array] (*)</td>
201-
</tr>
202-
203-
<tr>
204-
<td>mat2</td>
205-
<td>[page:Float32Array Float32Array] (*)</td>
206-
</td>
207-
<tr>
208-
<td>mat2</td>
209-
<td>[page:Array Array] (*)</td>
210-
</td>
211-
<tr>
212-
<td>mat3</td>
213-
<td>[page:Matrix3 THREE.Matrix3]</td>
214-
</tr>
215-
<tr>
216-
<td>mat3</td>
217-
<td>[page:Float32Array Float32Array] (*)</td>
218-
</tr>
219-
<tr>
220-
<td>mat3</td>
221-
<td>[page:Array Array] (*)</td>
222-
</tr>
223-
<tr>
224-
<td>mat4</td>
225-
<td>[page:Matrix3 THREE.Matrix4]</td>
226-
</tr>
227-
<tr>
228-
<td>mat4</td>
229-
<td>[page:Float32Array Float32Array] (*)</td>
230-
</tr>
231-
<tr>
232-
<td>mat4</td>
233-
<td>[page:Array Array] (*)</td>
234-
</tr>
235-
236-
<tr>
237-
<td>ivec2, bvec2</td>
238-
<td>[page:Float32Array Float32Array] (*)</td>
239-
</tr>
240-
<tr>
241-
<td>ivec2, bvec2</td>
242-
<td>[page:Array Array] (*)</td>
243-
</tr>
244-
<tr>
245-
<td>ivec3, bvec3</td>
246-
<td>[page:Int32Array Int32Array] (*)</td>
247-
</tr>
248-
<tr>
249-
<td>ivec3, bvec3</td>
250-
<td>[page:Array Array] (*)</td>
251-
</tr>
252-
<tr>
253-
<td>ivec4, bvec4</td>
254-
<td>[page:Int32Array Int32Array] (*)</td>
255-
</tr>
256-
<tr>
257-
<td>ivec4, bvec4</td>
258-
<td>[page:Array Array] (*)</td>
259-
</tr>
260-
261-
<tr>
262-
<td>sampler2D</td>
263-
<td>[page:Texture THREE.Texture]</td>
264-
</tr>
265-
<tr>
266-
<td>samplerCube</td>
267-
<td>[page:CubeTexture THREE.CubeTexture]</tr>
268-
</tr>
269-
270-
</tbody>
271-
</table>
272-
</p>
273-
<p>
274-
(*) Same for an (innermost) array (dimension) of the same GLSL type, containing the components of all vectors or matrices in the array.
275130
</p>
276131

277132
<h2>Constructor</h2>

docs/list.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ var list = {
3131
[ "Face3", "api/core/Face3" ],
3232
[ "Geometry", "api/core/Geometry" ],
3333
[ "Object3D", "api/core/Object3D" ],
34-
[ "Raycaster", "api/core/Raycaster" ]
34+
[ "Raycaster", "api/core/Raycaster" ],
35+
[ "Uniform", "api/core/Uniform"]
3536
],
3637

3738
"Lights": [

0 commit comments

Comments
 (0)