Browse Source

more mesh batch fixes

Nicolas Cannasse 6 years ago
parent
commit
4333ca11a1
4 changed files with 10 additions and 8 deletions
  1. 1 1
      hxsl/BatchShader.hx
  2. 1 1
      hxsl/Cache.hx
  3. 1 0
      hxsl/HlslOut.hx
  4. 7 6
      samples/MeshBatch.hx

+ 1 - 1
hxsl/BatchShader.hx

@@ -3,7 +3,7 @@ package hxsl;
 class BatchShader extends hxsl.Shader {
 
 	static var SRC = {
-		@const(4096) var Batch_Count : Int; // Max 64KB
+		@const(65536) var Batch_Count : Int;
 		@param var Batch_Buffer : Buffer<Vec4,Batch_Count>;
 	};
 

+ 1 - 1
hxsl/Cache.hx

@@ -444,7 +444,7 @@ class Cache {
 		var ebuffer = { e : TVar(vbuffer), p : pos, t : vbuffer.type };
 		var eoffset = { e : TVar(voffset), p : pos, t : voffset.type };
 		var tvec4 = TVec(4,VFloat);
-		var countBits = 12;
+		var countBits = 16;
 		vcount.qualifiers = [Const(1 << countBits)];
 
 		s.data = {

+ 1 - 0
hxsl/HlslOut.hx

@@ -275,6 +275,7 @@ class HlslOut {
 			case Mat3x4:
 				// float4x3 constructor uses row-order, we want column order here
 				decl("float4x3 mat3x4( float4 a, float4 b, float4 c ) { float4x3 m; m._m00_m10_m20_m30 = a; m._m01_m11_m21_m31 = b; m._m02_m12_m22_m32 = c; return m; }");
+				decl("float4x3 mat3x4( float4x4 m ) { float4x3 m2; m2._m00_m10_m20_m30 = m._m00_m10_m20_m30; m2._m01_m11_m21_m31 = m._m01_m11_m21_m31; m2._m02_m12_m22_m32 = m._m02_m12_m22_m32; return m2; }");
 			case Mat4:
 				decl("float4x4 mat4( float4 a, float4 b, float4 c, float4 d ) { float4x4 m; m._m00_m10_m20_m30 = a; m._m01_m11_m21_m31 = b; m._m02_m12_m22_m32 = c; m._m03_m13_m23_m33 = d; return m; }");
 			case Mat3:

+ 7 - 6
samples/MeshBatch.hx

@@ -8,8 +8,8 @@ class MeshInst {
 	public var speed : Float;
 
 	public function new() {
-		x = Math.random() * 20 - 10;
-		y = Math.random() * 20 - 10;
+		x = Math.random() * 40 - 20;
+		y = Math.random() * 40 - 20;
 		scale = 0.01;
 		speed = 1 + Math.random();
 		rot = Math.random() * Math.PI * 2;
@@ -20,7 +20,7 @@ class MeshInst {
 	public function update(dt:Float) {
 		scale += speed * dt;
 		rot += Math.abs(speed) * dt;
-		if( scale > speed && speed > 1 )
+		if( speed > 1 && scale > Math.sqrt(speed) )
 			speed *= -1;
 		return scale > 0;
 	}
@@ -40,15 +40,16 @@ class MeshBatch extends hxd.App {
 		cube.addNormals();
 		s3d.lightSystem.ambientLight.set(0.5,0.5,0.5);
 		batch = new h3d.scene.MeshBatch(cube,s3d);
-		batch.material.shadows = false;
 		meshes = [];
 		new h3d.scene.CameraController(20,s3d);
 	}
 
 	override function update(dt:Float) {
-		while( Std.random(meshes.length>>3) == 0 )
+		while( meshes.length < 680 )
 			meshes.push(new MeshInst());
-		batch.begin(128);
+		if( Std.random(100) == 0 )
+			batch.shadersChanged = true;
+		batch.begin(680);
 		for( m in meshes.copy() ) {
 			if( !m.update(dt) ) {
 				meshes.remove(m);