Object Occlusion Culling
This commit is contained in:
@ -82,20 +82,41 @@ class MeshBatch {
|
||||
|
||||
Uniforms.setContextConstants(g, scontext, bindParams);
|
||||
|
||||
RenderPath.sortMeshesDistance(b.meshes);
|
||||
var isShadowCtx = context == "shadowmap" || context == "shadowmap_transparent";
|
||||
if (!isShadowCtx) RenderPath.sortMeshesDistance(b.meshes);
|
||||
|
||||
for (m in b.meshes) {
|
||||
if (!m.visible) continue; // Skip render if object is hidden
|
||||
#if lnx_occlusion_culling
|
||||
if (!m.occlusionVisible && (context == "mesh" || context == "depth" || context == "translucent")) continue;
|
||||
if (!m.shadowOcclusionVisible && isShadowCtx) continue;
|
||||
#end
|
||||
if (m.cullMesh(context, Scene.active.camera, RenderPath.active.light)) continue;
|
||||
|
||||
// Get context
|
||||
var materialContexts: Array<MaterialContext> = [];
|
||||
var shaderContexts: Array<ShaderContext> = [];
|
||||
m.getContexts(context, m.materials, materialContexts, shaderContexts);
|
||||
var materialContexts: Array<MaterialContext> = null;
|
||||
var shaderContexts: Array<ShaderContext> = null;
|
||||
if (m.cachedMaterialContexts != null && MeshObject.matsEqual(m.cachedMats.get(context), m.materials)) {
|
||||
materialContexts = m.cachedMaterialContexts.get(context);
|
||||
shaderContexts = m.cachedShaderContexts.get(context);
|
||||
}
|
||||
if (materialContexts == null) {
|
||||
materialContexts = [];
|
||||
shaderContexts = [];
|
||||
m.getContexts(context, m.materials, materialContexts, shaderContexts);
|
||||
if (m.cachedMaterialContexts == null) {
|
||||
m.cachedMats = new Map();
|
||||
m.cachedMaterialContexts = new Map();
|
||||
m.cachedShaderContexts = new Map();
|
||||
}
|
||||
m.cachedMats.set(context, m.materials);
|
||||
m.cachedMaterialContexts.set(context, materialContexts);
|
||||
m.cachedShaderContexts.set(context, shaderContexts);
|
||||
}
|
||||
|
||||
Uniforms.posUnpack = m.data.scalePos;
|
||||
Uniforms.texUnpack = m.data.scaleTex;
|
||||
m.transform.update();
|
||||
if (!isShadowCtx) m.transform.update();
|
||||
|
||||
// Render mesh
|
||||
Uniforms.setObjectConstants(g, scontext, m);
|
||||
|
||||
@ -60,6 +60,16 @@ typedef TMeshData = {
|
||||
@:optional public var scale_pos: Null<FastFloat>; // Unpack pos from (-1,1) coords
|
||||
@:optional public var scale_tex: Null<FastFloat>; // Unpack tex from (-1,1) coords
|
||||
@:optional public var morph_target: TMorphTarget;
|
||||
@:optional public var occluder_proxy: TOccluderProxy;
|
||||
}
|
||||
|
||||
#if js
|
||||
typedef TOccluderProxy = {
|
||||
#else
|
||||
@:structInit class TOccluderProxy {
|
||||
#end
|
||||
public var positions: Float32Array;
|
||||
public var indices: Uint32Array;
|
||||
}
|
||||
|
||||
#if js
|
||||
|
||||
Reference in New Issue
Block a user