Przeglądaj źródła

Examples: Clarify shader code

Mugen87 7 lat temu
rodzic
commit
7143d8ddca

+ 9 - 3
examples/webgl_buffergeometry_instancing_dynamic.html

@@ -66,11 +66,17 @@
 
 		varying vec2 vUv;
 
+		// http://www.geeks3d.com/20141201/how-to-rotate-a-vertex-by-a-quaternion-in-glsl/
+
+		vec3 applyQuaternionToVector( vec4 q, vec3 v ){
+
+			return v + 2.0 * cross( q.xyz, cross( q.xyz, v ) + q.w * v );
+
+		}
+
 		void main() {
 
-			vec3 vPosition = position;
-			vec3 vcV = cross( orientation.xyz, vPosition );
-			vPosition = vcV * ( 2.0 * orientation.w ) + ( cross( orientation.xyz, vcV ) * 2.0 + vPosition );
+			vec3 vPosition = applyQuaternionToVector( orientation, position );
 
 			vUv = uv;
 

+ 9 - 3
examples/webgl_buffergeometry_instancing_interleaved_dynamic.html

@@ -66,11 +66,17 @@
 
 		varying vec2 vUv;
 
+		// http://www.geeks3d.com/20141201/how-to-rotate-a-vertex-by-a-quaternion-in-glsl/
+
+		vec3 applyQuaternionToVector( vec4 q, vec3 v ){
+
+			return v + 2.0 * cross( q.xyz, cross( q.xyz, v ) + q.w * v );
+
+		}
+
 		void main() {
 
-			vec3 vPosition = position;
-			vec3 vcV = cross(orientation.xyz, vPosition);
-			vPosition = vcV * (2.0 * orientation.w) + (cross(orientation.xyz, vcV) * 2.0 + vPosition);
+			vec3 vPosition = applyQuaternionToVector( orientation, position );
 
 			vUv = uv;