forked from LeenkxTeam/LNXSDK
moisesjpelaez - General Material Updates
This commit is contained in:
@ -302,6 +302,10 @@ class MeshObject extends Object {
|
|||||||
|
|
||||||
// Render mesh
|
// Render mesh
|
||||||
var ldata = lod.data;
|
var ldata = lod.data;
|
||||||
|
|
||||||
|
// Next pass rendering first (inverse order)
|
||||||
|
renderNextPass(g, context, bindParams, lod);
|
||||||
|
|
||||||
for (i in 0...ldata.geom.indexBuffers.length) {
|
for (i in 0...ldata.geom.indexBuffers.length) {
|
||||||
|
|
||||||
var mi = ldata.geom.materialIndices[i];
|
var mi = ldata.geom.materialIndices[i];
|
||||||
@ -405,4 +409,85 @@ class MeshObject extends Object {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function renderNextPass(g: Graphics, context: String, bindParams: Array<String>, lod: MeshObject) {
|
||||||
|
var ldata = lod.data;
|
||||||
|
for (i in 0...ldata.geom.indexBuffers.length) {
|
||||||
|
var mi = ldata.geom.materialIndices[i];
|
||||||
|
if (mi >= materials.length) continue;
|
||||||
|
|
||||||
|
var currentMaterial: MaterialData = materials[mi];
|
||||||
|
if (currentMaterial == null || currentMaterial.shader == null) continue;
|
||||||
|
|
||||||
|
var nextPassName: String = currentMaterial.shader.nextPass;
|
||||||
|
if (nextPassName == null || nextPassName == "") continue;
|
||||||
|
|
||||||
|
var nextMaterial: MaterialData = null;
|
||||||
|
for (mat in materials) {
|
||||||
|
// First try exact match
|
||||||
|
if (mat.name == nextPassName) {
|
||||||
|
nextMaterial = mat;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// If no exact match, try to match base name for linked materials
|
||||||
|
if (mat.name.indexOf("_") > 0 && mat.name.substr(mat.name.length - 6) == ".blend") {
|
||||||
|
var baseName = mat.name.substring(0, mat.name.indexOf("_"));
|
||||||
|
if (baseName == nextPassName) {
|
||||||
|
nextMaterial = mat;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextMaterial == null) continue;
|
||||||
|
|
||||||
|
var nextMaterialContext: MaterialContext = null;
|
||||||
|
var nextShaderContext: ShaderContext = null;
|
||||||
|
|
||||||
|
for (j in 0...nextMaterial.raw.contexts.length) {
|
||||||
|
if (nextMaterial.raw.contexts[j].name.substr(0, context.length) == context) {
|
||||||
|
nextMaterialContext = nextMaterial.contexts[j];
|
||||||
|
nextShaderContext = nextMaterial.shader.getContext(context);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nextShaderContext == null) continue;
|
||||||
|
if (skipContext(context, nextMaterial)) continue;
|
||||||
|
|
||||||
|
var elems = nextShaderContext.raw.vertex_elements;
|
||||||
|
|
||||||
|
// Uniforms
|
||||||
|
if (nextShaderContext.pipeState != lastPipeline) {
|
||||||
|
g.setPipeline(nextShaderContext.pipeState);
|
||||||
|
lastPipeline = nextShaderContext.pipeState;
|
||||||
|
}
|
||||||
|
Uniforms.setContextConstants(g, nextShaderContext, bindParams);
|
||||||
|
Uniforms.setObjectConstants(g, nextShaderContext, this);
|
||||||
|
Uniforms.setMaterialConstants(g, nextShaderContext, nextMaterialContext);
|
||||||
|
|
||||||
|
// VB / IB
|
||||||
|
#if lnx_deinterleaved
|
||||||
|
g.setVertexBuffers(ldata.geom.get(elems));
|
||||||
|
#else
|
||||||
|
if (ldata.geom.instancedVB != null) {
|
||||||
|
g.setVertexBuffers([ldata.geom.get(elems), ldata.geom.instancedVB]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g.setVertexBuffer(ldata.geom.get(elems));
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
g.setIndexBuffer(ldata.geom.indexBuffers[i]);
|
||||||
|
|
||||||
|
// Draw next pass for this specific geometry section
|
||||||
|
if (ldata.geom.instanced) {
|
||||||
|
g.drawIndexedVerticesInstanced(ldata.geom.instanceCount, ldata.geom.start, ldata.geom.count);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
g.drawIndexedVertices(ldata.geom.start, ldata.geom.count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user