|
@@ -31,6 +31,13 @@ class MeshBatch extends Mesh {
|
|
|
var indexCount : Int;
|
|
|
var modelViewID = hxsl.Globals.allocID("global.modelView");
|
|
|
var modelViewInverseID = hxsl.Globals.allocID("global.modelViewInverse");
|
|
|
+ var colorSave = new h3d.Vector();
|
|
|
+ var colorMult : h3d.shader.ColorMult;
|
|
|
+
|
|
|
+ /**
|
|
|
+ Tells if we can use material.color as a global multiply over each instance color (default: true)
|
|
|
+ **/
|
|
|
+ public var allowGlobalMaterialColor : Bool = true;
|
|
|
|
|
|
/**
|
|
|
* If set, use this position in emitInstance() instead MeshBatch absolute position
|
|
@@ -135,11 +142,27 @@ class MeshBatch extends Mesh {
|
|
|
public function begin( maxCount : Int ) {
|
|
|
if( maxCount > shaderInstances )
|
|
|
shadersChanged = true;
|
|
|
+ colorSave.load(material.color);
|
|
|
curInstances = 0;
|
|
|
maxInstances = maxCount;
|
|
|
if( shadersChanged ) {
|
|
|
+ if( colorMult != null ) {
|
|
|
+ material.mainPass.removeShader(colorMult);
|
|
|
+ colorMult = null;
|
|
|
+ }
|
|
|
initShadersMapping();
|
|
|
shadersChanged = false;
|
|
|
+ if( allowGlobalMaterialColor ) {
|
|
|
+ if( colorMult == null ) {
|
|
|
+ colorMult = new h3d.shader.ColorMult();
|
|
|
+ material.mainPass.addShader(colorMult);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if( colorMult != null ) {
|
|
|
+ material.mainPass.removeShader(colorMult);
|
|
|
+ colorMult = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -226,6 +249,7 @@ class MeshBatch extends Mesh {
|
|
|
syncData(p);
|
|
|
p = p.next;
|
|
|
}
|
|
|
+ if( allowGlobalMaterialColor ) material.color.load(colorSave);
|
|
|
curInstances++;
|
|
|
}
|
|
|
|
|
@@ -238,6 +262,7 @@ class MeshBatch extends Mesh {
|
|
|
p = p.next;
|
|
|
}
|
|
|
instanced.commands.setCommand(curInstances,indexCount);
|
|
|
+ if( colorMult != null ) colorMult.color.load(material.color);
|
|
|
}
|
|
|
|
|
|
override function emit(ctx:RenderContext) {
|