|
@@ -86,7 +86,7 @@ class ComputeIndirect extends hxsl.Shader {
|
|
|
@const var MAX_MATERIAL_COUNT : Int = 16;
|
|
|
@param var materialCount : Int;
|
|
|
@param var matIndex : Int;
|
|
|
- // x : indexCount, y : startIndex, z : minScreenRatio, w : unused
|
|
|
+ // x : indexCount, y : startIndex, z : minScreenRatio, w : in first lod => minScreenRatioCulling
|
|
|
@param var matInfos : Buffer<Vec4, MAX_MATERIAL_COUNT>;
|
|
|
|
|
|
@const var ENABLE_CULLING : Bool;
|
|
@@ -144,9 +144,13 @@ class ComputeIndirect extends hxsl.Shader {
|
|
|
if ( ENABLE_LOD ) {
|
|
|
var screenRatio = scaledRadius / distToCam;
|
|
|
screenRatio = screenRatio * screenRatio;
|
|
|
- for ( i in 0...lodCount ) {
|
|
|
+ var minScreenRatioCulling = matInfos[matOffset].w;
|
|
|
+ var culledByScreenRatio = screenRatio < minScreenRatioCulling;
|
|
|
+ culled = culled || culledByScreenRatio;
|
|
|
+ var lodStart = culledByScreenRatio ? lodCount : 0;
|
|
|
+ for ( i in lodStart...lodCount ) {
|
|
|
var minScreenRatio = matInfos[i + matOffset].z;
|
|
|
- if ( screenRatio > minScreenRatio )
|
|
|
+ if ( screenRatio > minScreenRatio )
|
|
|
break;
|
|
|
lod++;
|
|
|
}
|
|
@@ -711,12 +715,13 @@ class MeshBatch extends MultiMaterial {
|
|
|
var tmpMatInfos = alloc.allocFloats( 4 * ( materialCount + emittedSubParts.length ) );
|
|
|
pos = 0;
|
|
|
for ( subPart in emittedSubParts ) {
|
|
|
+ var maxLod = subPart.lodIndexCount.length;
|
|
|
var lodConfig = subPart.lodConfig;
|
|
|
tmpMatInfos[pos++] = subPart.indexCount;
|
|
|
tmpMatInfos[pos++] = subPart.indexStart;
|
|
|
tmpMatInfos[pos++] = ( 0 < lodConfig.length ) ? lodConfig[0] : 0.0;
|
|
|
- pos++;
|
|
|
- for ( i in 0...subPart.lodIndexCount.length ) {
|
|
|
+ tmpMatInfos[pos++] = ( maxLod < lodConfig.length && maxLod > 0 ) ? lodConfig[lodConfig.length - 1] : 0.0;
|
|
|
+ for ( i in 0...maxLod ) {
|
|
|
tmpMatInfos[pos++] = subPart.lodIndexCount[i];
|
|
|
tmpMatInfos[pos++] = subPart.lodIndexStart[i];
|
|
|
tmpMatInfos[pos++] = ( i + 1 < lodConfig.length ) ? lodConfig[i + 1] : 0.0;
|
|
@@ -733,6 +738,8 @@ class MeshBatch extends MultiMaterial {
|
|
|
matInfos = alloc.allocBuffer( materialCount * lodCount, hxd.BufferFormat.VEC4_DATA, Uniform );
|
|
|
var lodConfig = hmd.getLodConfig();
|
|
|
var startIndex : Int = 0;
|
|
|
+ var lodConfigHasCulling = lodConfig.length > lodCount - 1;
|
|
|
+ var minScreenRatioCulling = lodConfigHasCulling ? lodConfig[lodConfig.length-1] : 0.0;
|
|
|
for ( i => lod in @:privateAccess hmd.lods ) {
|
|
|
for ( j in 0...materialCount ) {
|
|
|
var indexCount = lod.indexCounts[j];
|
|
@@ -740,6 +747,7 @@ class MeshBatch extends MultiMaterial {
|
|
|
tmpMatInfos[matIndex * 4 + 0] = indexCount;
|
|
|
tmpMatInfos[matIndex * 4 + 1] = startIndex;
|
|
|
tmpMatInfos[matIndex * 4 + 2] = ( i < lodConfig.length ) ? lodConfig[i] : 0.0;
|
|
|
+ tmpMatInfos[matIndex * 4 + 3] = minScreenRatioCulling;
|
|
|
startIndex += indexCount;
|
|
|
}
|
|
|
}
|