瀏覽代碼

added floatSkinIndexes

ncannasse 10 年之前
父節點
當前提交
dc1c46c293
共有 2 個文件被更改,包括 16 次插入3 次删除
  1. 4 0
      h3d/shader/Skin.hx
  2. 12 3
      hxd/fmt/fbx/HMDOut.hx

+ 4 - 0
h3d/shader/Skin.hx

@@ -18,6 +18,9 @@ class Skin extends hxsl.Shader {
 		@param var bonesMatrixes : Array<Mat3x4,MaxBones>;
 
 		function vertex() {
+			#if floatSkinIndexes
+			error("TODO : access bonesMatrixes as vertex array");
+			#else
 			transformedPosition =
 				(input.position * bonesMatrixes[input.indexes.x]) * input.weights.x +
 				(input.position * bonesMatrixes[input.indexes.y]) * input.weights.y +
@@ -26,6 +29,7 @@ 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);
+			#end
 		}
 
 	}

+ 12 - 3
hxd/fmt/fbx/HMDOut.hx

@@ -11,6 +11,11 @@ class HMDOut extends BaseLibrary {
 	var tmp = haxe.io.Bytes.alloc(4);
 	public var absoluteTexturePath : Bool;
 	public var optimizeSkin = true;
+	/*
+		Store the skin indexes as multiple premultiplied floats instead of as packed into a single 4 bytes ints.
+		This is necessary for GPUs that does not respect OpenGLES spec and does not allow non-constant indexing in vertex shader (Adreno 20X)
+	*/
+	public var floatSkinIndexes = #if floatSkinIndexes true #else false #end;
 
 	function int32tof( v : Int ) : Float {
 		tmp.set(0, v & 0xFF);
@@ -65,8 +70,8 @@ class HMDOut extends BaseLibrary {
 		if( skin != null ) {
 			if( bonesPerVertex <= 0 || bonesPerVertex > 4 ) throw "assert";
 			g.vertexFormat.push(new GeometryFormat("weights", [DFloat, DVec2, DVec3, DVec4][bonesPerVertex-1]));
-			g.vertexFormat.push(new GeometryFormat("indexes", DBytes4));
-			stride += 1 + bonesPerVertex;
+			g.vertexFormat.push(new GeometryFormat("indexes", floatSkinIndexes ? [DFloat, DVec2, DVec3, DVec4][bonesPerVertex-1] : DBytes4));
+			stride += bonesPerVertex + (floatSkinIndexes ? bonesPerVertex : 1);
 		}
 		g.vertexStride = stride;
 		g.vertexCount = 0;
@@ -136,7 +141,11 @@ class HMDOut extends BaseLibrary {
 						tmpBuf[p++] = skin.vertexWeights[k + i];
 						idx = (skin.vertexJoints[k + i] << (8*i)) | idx;
 					}
-					tmpBuf[p++] = int32tof(idx);
+					if( floatSkinIndexes ) {
+						for( i in 0...skin.bonesPerVertex )
+							tmpBuf[p++] = skin.vertexJoints[k + i] * 3;
+					} else
+						tmpBuf[p++] = int32tof(idx);
 				}
 
 				var total = 0.;