Merge pull request #2157 from N8n5h/debug-console-atlas

Add shadow map atlases info to the debug console
This commit is contained in:
Lubos Lenco 2021-04-14 11:14:18 +02:00 committed by GitHub
commit 00af258b14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 110 additions and 1 deletions

View file

@ -112,6 +112,12 @@ class Inc {
lastFrame = RenderPath.active.frame;
#end
// add new lights to the atlases
#if arm_debug
// reset data on rejected lights
for (atlas in ShadowMapAtlas.shadowMapAtlases) {
atlas.rejectedLights = [];
}
#end
for (light in iron.Scene.active.lights) {
if (!light.lightInAtlas && !light.culledLight && light.visible && light.shadowMapScale > 0.0
&& light.data.raw.strength > 0.0 && light.data.raw.cast_shadow) {
@ -544,6 +550,11 @@ class ShadowMapAtlas {
public var updateRenderTarget = false;
public static var shadowMapAtlases:Map<String, ShadowMapAtlas> = new Map(); // map a shadowmap atlas to their light type
#if arm_debug
public var lightType: String;
public var rejectedLights: Array<LightObject> = [];
#end
function new(light: LightObject) {
var maxTileSize = shadowMapAtlasSize(light);
@ -557,6 +568,14 @@ class ShadowMapAtlas {
computeTileSizes(maxTileSize, depth);
#end
#if arm_debug
#if arm_shadowmap_atlas_single_map
this.lightType = "any";
#else
this.lightType = light.data.raw.type;
#end
#end
}
/**
@ -575,8 +594,13 @@ class ShadowMapAtlas {
// find a free tile for this light
var mainTile = ShadowMapTile.assignTiles(light, atlas, null);
if (mainTile == null)
if (mainTile == null) {
#if arm_debug
if (!atlas.rejectedLights.contains(light))
atlas.rejectedLights.push(light);
#end
return;
}
atlas.activeTiles.push(mainTile);
// notify the tile on light remove

View file

@ -8,6 +8,10 @@ import iron.object.MeshObject;
import zui.Zui;
import zui.Id;
using armory.object.TransformExtension;
#if arm_shadowmap_atlas
import armory.renderpath.Inc.ShadowMapTile;
import armory.renderpath.Inc.ShadowMapAtlas;
#end
#end
#if arm_debug
@ -423,6 +427,7 @@ class DebugConsole extends Trait {
light.data.raw.strength = ui.slider(lightHandle, "Strength", 0.0, 5.0, true) * 10;
#if arm_shadowmap_atlas
ui.text("status: " + (light.culledLight ? "culled" : "rendered"));
ui.text("shadow map size: " + light.data.raw.shadowmap_size);
#end
}
else if (Std.is(selectedObject, iron.object.CameraObject)) {
@ -520,6 +525,86 @@ class DebugConsole extends Trait {
ui.unindent();
}
#if arm_shadowmap_atlas
if (ui.panel(Id.handle({selected: false}), "Shadow Map Atlases")) {
inline function highLightNext(color: kha.Color = null) {
ui.g.color = color != null ? color : kha.Color.fromFloats(0.175, 0.175, 0.175);
ui.g.fillRect(ui._x, ui._y, ui._windowW, ui.ELEMENT_H());
ui.g.color = 0xffffffff;
}
ui.indent(false);
ui.text("Constants:");
highLightNext();
ui.text('Tiles Used Per Point Light: ${ ShadowMapTile.tilesLightType("point") }');
ui.text('Tiles Used Per Spot Light: ${ ShadowMapTile.tilesLightType("spot") }');
highLightNext();
ui.text('Tiles Used For Sun: ${ ShadowMapTile.tilesLightType("sun") }');
ui.unindent(false);
ui.indent(false);
var i = 0;
for (atlas in ShadowMapAtlas.shadowMapAtlases) {
if (ui.panel(Id.handle({selected: false}).nest(i), atlas.target )) {
ui.indent(false);
// general atlas information
ui.text('Current Size: ${atlas.sizew}, ${atlas.sizeh} px');
highLightNext();
ui.text('Max Size: ${atlas.maxAtlasSizeConst}, ${atlas.maxAtlasSizeConst} px');
ui.text('Tile Size: ${atlas.baseTileSizeConst}, ${atlas.baseTileSizeConst} px');
highLightNext();
#if arm_shadowmap_atlas_lod
// show detailed information per light
if (ui.panel(Id.handle({selected: false}).nest(i).nest(0), )) {
ui.indent(false);
var j = 1;
for (tile in atlas.activeTiles) {
if (ui.panel(Id.handle({selected: false}).nest(i).nest(j), tile.light.name)) {
ui.indent(false);
ui.text('Shadow Map Size: ${tile.size}, ${tile.size} px');
ui.unindent();
}
j++;
}
ui.unindent(false);
}
#else
// show total lights occupied
ui.text('Current Active Lights: ${atlas.activeTiles.length}');
#end
#if arm_shadowmap_atlas_lod
// WIP
#else
var unusedTiles = atlas.tiles.length;
#if arm_shadowmap_atlas_single_map
for (tile in atlas.activeTiles)
unusedTiles -= ShadowMapTile.tilesLightType(tile.light.data.raw.type);
#else
unusedTiles -= atlas.activeTiles.length * ShadowMapTile.tilesLightType(atlas.lightType);
#end
ui.text('Unused tiles: ${unusedTiles}');
#end
var rejectedLightsNames = "";
if (atlas.rejectedLights.length > 0) {
for (l in atlas.rejectedLights)
rejectedLightsNames += l.name + ", ";
rejectedLightsNames = rejectedLightsNames.substr(0, rejectedLightsNames.length - 2);
highLightNext(kha.Color.fromFloats(0.447, 0.247, 0.188));
ui.text('Not enough space in atlas for ${atlas.rejectedLights.length} light${atlas.rejectedLights.length > 1 ? "s" : ""}:');
ui.indent();
ui.text(${rejectedLightsNames});
ui.unindent(false);
}
ui.unindent(false);
}
i++;
}
ui.unindent(false);
ui.unindent(false);
}
#end
if (ui.panel(Id.handle({selected: false}), "Render Targets")) {
ui.indent();
#if (kha_opengl || kha_webgl)