ShiroSmith 6 лет назад
Родитель
Сommit
3008a26521
4 измененных файлов с 39 добавлено и 3 удалено
  1. 1 1
      h3d/pass/ScreenFx.hx
  2. 19 2
      h3d/scene/MeshBatch.hx
  3. 10 0
      h3d/scene/pbr/Renderer.hx
  4. 9 0
      hxsl/Cache.hx

+ 1 - 1
h3d/pass/ScreenFx.hx

@@ -64,8 +64,8 @@ class ScreenFx<T:h3d.shader.ScreenShader> {
 	public function render() {
 		if( primitive == null )
 			primitive = h3d.prim.Plane2D.get();
-		var rts = manager.compileShaders(shaders);
 		shader.flipY = engine.driver.hasFeature(BottomLeftCoords) && engine.getCurrentTarget() != null ? -1 : 1;
+		var rts = manager.compileShaders(shaders);
 		engine.selectMaterial(pass);
 		engine.selectShader(rts);
 		if( buffers == null )

+ 19 - 2
h3d/scene/MeshBatch.hx

@@ -33,6 +33,12 @@ class MeshBatch extends Mesh {
 	var modelViewID = hxsl.Globals.allocID("global.modelView");
 	var modelViewInverseID = hxsl.Globals.allocID("global.modelViewInverse");
 
+	/**
+	 * 	If set, use this position in emitInstance() instead MeshBatch absolute position
+	**/
+	public var worldPosition : Matrix;
+	var invWorldPosition : Matrix;
+
 	/**
 		Set if shader list or shader constants has changed, before calling begin()
 	**/
@@ -74,6 +80,7 @@ class MeshBatch extends Mesh {
 
 	function initShadersMapping() {
 		var scene = getScene();
+		if( scene == null ) return;
 		cleanPasses();
 		shaderInstances = maxInstances;
 		for( p in material.getPasses() ) @:privateAccess {
@@ -150,6 +157,7 @@ class MeshBatch extends Mesh {
 		var buf = data.data;
 		var shaders = data.shaders;
 		var startPos = data.count * curInstances * 4;
+		var calcInv = false;
 		while( p != null ) {
 			var pos = startPos + p.pos;
 			inline function addMatrix(m:h3d.Matrix) {
@@ -172,9 +180,18 @@ class MeshBatch extends Mesh {
 			}
 			if( p.perObjectGlobal != null ) {
 				if( p.perObjectGlobal.gid == modelViewID ) {
-					addMatrix(absPos);
+					addMatrix(worldPosition != null ? worldPosition : absPos);
 				} else if( p.perObjectGlobal.gid == modelViewInverseID ) {
-					addMatrix(getInvPos());
+					if( worldPosition == null )
+						addMatrix(getInvPos());
+					else {
+						if( !calcInv ) {
+							calcInv = true;
+							if( invWorldPosition == null ) invWorldPosition = new h3d.Matrix();
+							invWorldPosition.initInverse(worldPosition);
+						}
+						addMatrix(invWorldPosition);
+					}
 				} else
 					throw "Unsupported global param "+p.perObjectGlobal.path;
 				p = p.next;

+ 10 - 0
h3d/scene/pbr/Renderer.hx

@@ -122,6 +122,16 @@ class Renderer extends h3d.scene.Renderer {
 		return output.compileShader(pass);
 	}
 
+	override function getPassByName(name:String):h3d.pass.Base {
+		switch( name ) {
+		case "overlay", "beforeTonemapping", "albedo", "distortion":
+			return defaultPass;
+		case "alpha", "additive":
+			return output;
+		}
+		return super.getPassByName(name);
+	}
+
 	override function start() {
 		if( pbrLightPass == null ) {
 			pbrLightPass = new h3d.mat.Pass("lights");

+ 9 - 0
hxsl/Cache.hx

@@ -495,6 +495,15 @@ class Cache {
 				]) };
 			case TVec(4,VFloat):
 				readOffset(index);
+			case TVec(3,VFloat):
+				{ p : pos, t : v.type, e : TSwiz(readOffset(index),v.pos&3 == 0 ? [X,Y,Z] : [Y,Z,W]) };
+			case TVec(2,VFloat):
+				var swiz = switch( v.pos & 3 ) {
+				case 0: [X,Y];
+				case 1: [Y,Z];
+				default: [Z,W];
+				}
+				{ p : pos, t : v.type, e : TSwiz(readOffset(index),swiz) };
 			case TFloat:
 				{ p : pos, t : v.type, e : TSwiz(readOffset(index),swiz[v.pos&3]) }
 			default: