Kaynağa Gözat

WebGLRenderer: Allow precision per material. Fixes #6378.

Mr.doob 10 yıl önce
ebeveyn
işleme
91569e4c12
2 değiştirilmiş dosya ile 18 ekleme ve 1 silme
  1. 4 0
      src/materials/Material.js
  2. 14 1
      src/renderers/WebGLRenderer.js

+ 4 - 0
src/materials/Material.js

@@ -32,6 +32,8 @@ THREE.Material = function () {
 
 	this.colorWrite = true;
 
+	this.precision = null; // override the renderer's default precision for this material
+
 	this.polygonOffset = false;
 	this.polygonOffsetFactor = 0;
 	this.polygonOffsetUnits = 0;
@@ -196,6 +198,8 @@ THREE.Material.prototype = {
 		this.depthTest = source.depthTest;
 		this.depthWrite = source.depthWrite;
 
+		this.precision = source.precision;
+
 		this.polygonOffset = source.polygonOffset;
 		this.polygonOffsetFactor = source.polygonOffsetFactor;
 		this.polygonOffsetUnits = source.polygonOffsetUnits;

+ 14 - 1
src/renderers/WebGLRenderer.js

@@ -1882,10 +1882,23 @@ THREE.WebGLRenderer = function ( parameters ) {
 		var maxLightCount = allocateLights( lights );
 		var maxShadows = allocateShadows( lights );
 		var maxBones = allocateBones( object );
+		var precision = _precision;
+
+		if ( material.precision !== null ) {
+
+			precision = state.getMaxPrecision( material.precision );
+
+			if ( precision !== material.precision ) {
+
+				console.warn( 'THREE.WebGLRenderer.initMaterial:', material.precision, 'not supported, using', precision, 'instead.' );
+
+			}
+
+		}
 
 		var parameters = {
 
-			precision: _precision,
+			precision: precision,
 			supportsVertexTextures: _supportsVertexTextures,
 
 			map: !! material.map,