Bläddra i källkod

Merge pull request #20587 from Mugen87/dev51

WebGLRenderer: Enable half float attributes.
Mr.doob 4 år sedan
förälder
incheckning
8e3b6b83a6

+ 2 - 1
docs/api/en/core/bufferAttributeTypes/BufferAttributeTypes.html

@@ -19,6 +19,7 @@
 		<code>
 		THREE.Float64BufferAttribute
 		THREE.Float32BufferAttribute
+		THREE.Float16BufferAttribute
 		THREE.Uint32BufferAttribute
 		THREE.Int32BufferAttribute
 		THREE.Uint16BufferAttribute
@@ -59,6 +60,6 @@
 
 		<p>
 			[link:https://github.com/mrdoob/three.js/blob/master/src/core/BufferAttribute.js src/core/BufferAttribute.js]
-		</p>	
+		</p>
 	</body>
 </html>

+ 1 - 0
docs/api/zh/core/bufferAttributeTypes/BufferAttributeTypes.html

@@ -19,6 +19,7 @@
 		<code>
 		THREE.Float64BufferAttribute
 		THREE.Float32BufferAttribute
+		THREE.Float16BufferAttribute
 		THREE.Uint32BufferAttribute
 		THREE.Int32BufferAttribute
 		THREE.Uint16BufferAttribute

+ 10 - 0
src/core/BufferAttribute.d.ts

@@ -251,6 +251,16 @@ export class Uint32BufferAttribute extends BufferAttribute {
 
 }
 
+export class Float16BufferAttribute extends BufferAttribute {
+
+	constructor(
+		array: Iterable<number> | ArrayLike<number> | ArrayBuffer | number,
+		itemSize: number,
+		normalized?: boolean
+	);
+
+}
+
 export class Float32BufferAttribute extends BufferAttribute {
 
 	constructor(

+ 10 - 0
src/core/BufferAttribute.js

@@ -478,6 +478,15 @@ function Uint32BufferAttribute( array, itemSize, normalized ) {
 Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
 Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
 
+function Float16BufferAttribute( array, itemSize, normalized ) {
+
+	BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
+
+}
+
+Float16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
+Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
+Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
 
 function Float32BufferAttribute( array, itemSize, normalized ) {
 
@@ -503,6 +512,7 @@ Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
 export {
 	Float64BufferAttribute,
 	Float32BufferAttribute,
+	Float16BufferAttribute,
 	Uint32BufferAttribute,
 	Int32BufferAttribute,
 	Uint16BufferAttribute,

+ 17 - 1
src/renderers/webgl/WebGLAttributes.js

@@ -28,7 +28,23 @@ function WebGLAttributes( gl, capabilities ) {
 
 		} else if ( array instanceof Uint16Array ) {
 
-			type = gl.UNSIGNED_SHORT;
+			if ( attribute.isFloat16BufferAttribute ) {
+
+				if ( isWebGL2 ) {
+
+					type = gl.HALF_FLOAT;
+
+				} else {
+
+					console.warn( 'THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.' );
+
+				}
+
+			} else {
+
+				type = gl.UNSIGNED_SHORT;
+
+			}
 
 		} else if ( array instanceof Int16Array ) {