瀏覽代碼

DataUtils: Clamp param of toHalfFloat(). (#22444)

* DataUtils: Clamp param of toHalfFloat().

* DataUtils: Add warning to toHalfFloat().
Michael Herzog 3 年之前
父節點
當前提交
1a9481bae5
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      src/extras/DataUtils.js

+ 8 - 0
src/extras/DataUtils.js

@@ -7,6 +7,14 @@ class DataUtils {
 
 
 	static toHalfFloat( val ) {
 	static toHalfFloat( val ) {
 
 
+		if ( val > 65504 ) {
+
+			console.warn( 'THREE.DataUtils.toHalfFloat(): value exceeds 65504.' );
+
+			val = 65504; // maximum representable value in float16
+
+		}
+
 		// Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
 		// Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
 
 
 		/* This method is faster than the OpenEXR implementation (very often
 		/* This method is faster than the OpenEXR implementation (very often