Просмотр исходного кода

fix directx + skinning : don't eliminate unused input

ncannasse 7 лет назад
Родитель
Сommit
4fca8f44dc
4 измененных файлов с 66 добавлено и 21 удалено
  1. 8 2
      h3d/scene/Skin.hx
  2. 2 19
      h3d/shader/Skin.hx
  3. 21 0
      h3d/shader/SkinBase.hx
  4. 35 0
      h3d/shader/SkinTangent.hx

+ 8 - 2
h3d/scene/Skin.hx

@@ -74,7 +74,7 @@ class Skin extends MultiMaterial {
 	var jointsUpdated : Bool;
 	var jointsAbsPosInv : h3d.Matrix;
 	var paletteChanged : Bool;
-	var skinShader : h3d.shader.Skin;
+	var skinShader : h3d.shader.SkinBase;
 	var jointsGraphics : Graphics;
 
 	public var showJoints : Bool;
@@ -155,7 +155,13 @@ class Skin extends MultiMaterial {
 		jointsUpdated = true;
 		primitive = s.primitive;
 		if( shaderInit ) {
-			skinShader = new h3d.shader.Skin();
+			var hasNormalMap = false;
+			for( m in materials )
+				if( m != null && m.normalMap != null ) {
+					hasNormalMap = true;
+					break;
+				}
+			skinShader = hasNormalMap ? new h3d.shader.SkinTangent() : new h3d.shader.Skin();
 			var maxBones = 0;
 			if( skinData.splitJoints != null ) {
 				for( s in skinData.splitJoints )

+ 2 - 19
h3d/shader/Skin.hx

@@ -1,25 +1,18 @@
 package h3d.shader;
 
-class Skin extends hxsl.Shader {
+class Skin extends SkinBase {
 
 	static var SRC = {
 
 		@input var input : {
 			var position : Vec3;
 			var normal : Vec3;
-			var tangent : Vec3;
 			var weights : Vec3;
 			var indexes : Bytes4;
 		};
 
-		var relativePosition : Vec3;
-		var transformedPosition : Vec3;
-		var transformedNormal : Vec3;
 		var transformedTangent : Vec4;
 
-		@const var MaxBones : Int;
-		@ignore @param var bonesMatrixes : Array<Mat3x4,MaxBones>;
-
 		function vertex() {
 			transformedPosition =
 				(relativePosition * bonesMatrixes[input.indexes.x]) * input.weights.x +
@@ -29,18 +22,8 @@ class Skin extends hxsl.Shader {
 				(input.normal * mat3(bonesMatrixes[input.indexes.x])) * input.weights.x +
 				(input.normal * mat3(bonesMatrixes[input.indexes.y])) * input.weights.y +
 				(input.normal * mat3(bonesMatrixes[input.indexes.z])) * input.weights.z);
-			transformedTangent = vec4(normalize(
-				(input.tangent.xyz * mat3(bonesMatrixes[input.indexes.x])) * input.weights.x +
-				(input.tangent.xyz * mat3(bonesMatrixes[input.indexes.y])) * input.weights.y +
-				(input.tangent.xyz * mat3(bonesMatrixes[input.indexes.z])) * input.weights.z
-			), transformedTangent.w);
 		}
 
-	}
-
-	public function new() {
-		super();
-		MaxBones = 34;
-	}
+	};
 
 }

+ 21 - 0
h3d/shader/SkinBase.hx

@@ -0,0 +1,21 @@
+package h3d.shader;
+
+class SkinBase extends hxsl.Shader {
+	
+	static var SRC = {
+		
+		var relativePosition : Vec3;
+		var transformedPosition : Vec3;
+		var transformedNormal : Vec3;
+
+		@const var MaxBones : Int;
+		@ignore @param var bonesMatrixes : Array<Mat3x4,MaxBones>;
+		
+	};
+
+	public function new() {
+		super();
+		MaxBones = 34;
+	}
+	
+}

+ 35 - 0
h3d/shader/SkinTangent.hx

@@ -0,0 +1,35 @@
+package h3d.shader;
+
+class SkinTangent extends SkinBase {
+
+	static var SRC = {
+
+		@input var input : {
+			var position : Vec3;
+			var normal : Vec3;
+			var tangent : Vec3;
+			var weights : Vec3;
+			var indexes : Bytes4;
+		};
+
+		var transformedTangent : Vec4;
+
+		function vertex() {
+			transformedPosition =
+				(relativePosition * bonesMatrixes[input.indexes.x]) * input.weights.x +
+				(relativePosition * bonesMatrixes[input.indexes.y]) * input.weights.y +
+				(relativePosition * bonesMatrixes[input.indexes.z]) * input.weights.z;
+			transformedNormal = normalize(
+				(input.normal * mat3(bonesMatrixes[input.indexes.x])) * input.weights.x +
+				(input.normal * mat3(bonesMatrixes[input.indexes.y])) * input.weights.y +
+				(input.normal * mat3(bonesMatrixes[input.indexes.z])) * input.weights.z);
+			transformedTangent = vec4(normalize(
+				(input.tangent.xyz * mat3(bonesMatrixes[input.indexes.x])) * input.weights.x +
+				(input.tangent.xyz * mat3(bonesMatrixes[input.indexes.y])) * input.weights.y +
+				(input.tangent.xyz * mat3(bonesMatrixes[input.indexes.z])) * input.weights.z
+			), transformedTangent.w);
+		}
+
+	};
+
+}