Sfoglia il codice sorgente

make sure normalMap shader is always before textureShader (tangent before uv)

ncannasse 7 anni fa
parent
commit
dffd93747e
2 ha cambiato i file con 15 aggiunte e 1 eliminazioni
  1. 4 1
      h3d/mat/Material.hx
  2. 11 0
      h3d/mat/Pass.hx

+ 4 - 1
h3d/mat/Material.hx

@@ -176,7 +176,10 @@ class Material extends BaseMaterial {
 		} else {
 			if( normalShader == null ) {
 				normalShader = new h3d.shader.NormalMap();
-				mainPass.addShader(normalShader);
+				if( textureShader != null )
+					mainPass.addShaderAtIndex(normalShader, mainPass.getShaderIndex(textureShader));
+				else
+					mainPass.addShader(normalShader);
 			}
 			normalShader.texture = t;
 		}

+ 11 - 0
h3d/mat/Pass.hx

@@ -133,6 +133,17 @@ class Pass implements hxd.impl.Serializable {
 		return s;
 	}
 
+	function getShaderIndex(s:hxsl.Shader) : Int {
+		var index = 0;
+		var cur = shaders;
+		while( cur != parentShaders ) {
+			if( cur.s == s ) return index;
+			cur = cur.next;
+			index++;
+		}
+		return -1;
+	}
+
 	public function removeShader(s) {
 		var sl = shaders, prev = null;
 		while( sl != null ) {