Skip to content

Commit aa1153b

Browse files
authored
Merge pull request #13980 from Mugen87/dev7
Examples: Clarify shader code
2 parents 60e365a + 7143d8d commit aa1153b

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

examples/webgl_buffergeometry_instancing_dynamic.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,17 @@
6666

6767
varying vec2 vUv;
6868

69+
// http://www.geeks3d.com/20141201/how-to-rotate-a-vertex-by-a-quaternion-in-glsl/
70+
71+
vec3 applyQuaternionToVector( vec4 q, vec3 v ){
72+
73+
return v + 2.0 * cross( q.xyz, cross( q.xyz, v ) + q.w * v );
74+
75+
}
76+
6977
void main() {
7078

71-
vec3 vPosition = position;
72-
vec3 vcV = cross( orientation.xyz, vPosition );
73-
vPosition = vcV * ( 2.0 * orientation.w ) + ( cross( orientation.xyz, vcV ) * 2.0 + vPosition );
79+
vec3 vPosition = applyQuaternionToVector( orientation, position );
7480

7581
vUv = uv;
7682

examples/webgl_buffergeometry_instancing_interleaved_dynamic.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,17 @@
6666

6767
varying vec2 vUv;
6868

69+
// http://www.geeks3d.com/20141201/how-to-rotate-a-vertex-by-a-quaternion-in-glsl/
70+
71+
vec3 applyQuaternionToVector( vec4 q, vec3 v ){
72+
73+
return v + 2.0 * cross( q.xyz, cross( q.xyz, v ) + q.w * v );
74+
75+
}
76+
6977
void main() {
7078

71-
vec3 vPosition = position;
72-
vec3 vcV = cross(orientation.xyz, vPosition);
73-
vPosition = vcV * (2.0 * orientation.w) + (cross(orientation.xyz, vcV) * 2.0 + vPosition);
79+
vec3 vPosition = applyQuaternionToVector( orientation, position );
7480

7581
vUv = uv;
7682

0 commit comments

Comments
 (0)