Revamp render engine debug JS script

This commit is contained in:
Zach Pomerantz 2016-02-08 12:29:06 -08:00
parent 991d6328ef
commit dbc59ccc2b
8 changed files with 468 additions and 216 deletions

View file

@ -0,0 +1,101 @@
//
// AO.qml
// examples/utilities/tools/render
//
// Created by Zach Pomerantz on 2/8/2016
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.5
import QtQuick.Controls 1.4
Item {
width: 200
height: 200
property QtObject config: Render.getConfig("AmbientOcclusion")
Timer {
interval: 500
running: true
repeat: true
onTriggered: { parent.timer.text = config.gpuTime.toFixed(2) }
}
Label { text: qsTr("Ambient Occlusion") }
Label { id: timer; x: 140 }
CheckBox {
y: 1 * 25
text: qsTr("Dithering")
partiallyCheckedEnabled: false
checked: parent.config.ditheringEnabled
onCheckedChanged: { parent.config.ditheringEnabled = checked }
}
ConfigSlider {
y: 2 * 25
config: parent.config
prop: "resolutionLevel"
label: qsTr("Resolution Level")
min: 0; max: 4
}
ConfigSlider {
y: 3 * 25
config: parent.config
prop: "obscuranceLevel"
label: qsTr("Obscurance Level")
min: 0; max: 1
}
ConfigSlider {
y: 4 * 25
config: parent.config
prop: "radius"
label: qsTr("Radius")
min: 0; max: 2
}
ConfigSlider {
y: 5 * 25
config: parent.config
prop: "numSamples"
label: qsTr("Samples")
min: 0; max: 32
}
ConfigSlider {
y: 6 * 25
config: parent.config
prop: "numSpiralTurns"
label: qsTr("Spiral Turns")
min: 0; max: 30
}
ConfigSlider {
y: 7 * 25
config: parent.config
prop: "falloffBias"
label: qsTr("Falloff Bias")
min: 0; max: 0.2
}
ConfigSlider {
y: 8 * 25
config: parent.config
prop: "edgeSharpness"
label: qsTr("Edge Sharpness")
min: 0; max: 1
}
ConfigSlider {
y: 9 * 25
config: parent.config
prop: "blurRadius"
label: qsTr("Blur Radius")
min: 0; max: 6
}
ConfigSlider {
y: 10 * 25
config: parent.config
prop: "blurDeviation"
label: qsTr("Blur Deviation")
min: 0; max: 3
}
}

View file

@ -0,0 +1,99 @@
//
// Buffer.qml
// examples/utilities/tools/render
//
// Created by Zach Pomerantz on 2/8/2016
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.5
import QtQuick.Controls 1.4
Item {
width: 200
height: 270
Label {
text: qsTr("Debug Buffer")
}
ExclusiveGroup { id: buffer }
function setDebugMode(mode) {
var debug = Render.getConfig("DebugDeferredBuffer");
console.log(mode);
debug.enabled = (mode != 0);
debug.mode = mode;
}
RadioButton {
x: 8; y: 19 + 0 * 23
text: qsTr("Off")
exclusiveGroup: buffer
checked: true
onCheckedChanged: { if (checked) { setDebugMode(0) } }
}
RadioButton {
x: 8; y: 19 + 1 * 23
text: qsTr("Diffuse")
exclusiveGroup: buffer
onCheckedChanged: { if (checked) { setDebugMode(1) } }
}
RadioButton {
x: 8; y: 19 + 2 * 23
text: qsTr("Metallic")
exclusiveGroup: buffer
onCheckedChanged: { if (checked) { setDebugMode(2) } }
}
RadioButton {
x: 8; y: 19 + 3 * 23
text: qsTr("Roughness")
exclusiveGroup: buffer
onCheckedChanged: { if (checked) { setDebugMode(3) } }
}
RadioButton {
x: 8; y: 19 + 4 * 23
text: qsTr("Normal")
exclusiveGroup: buffer
onCheckedChanged: { if (checked) { setDebugMode(4) } }
}
RadioButton {
x: 8; y: 19 + 5 * 23
text: qsTr("Depth")
exclusiveGroup: buffer
onCheckedChanged: { if (checked) { setDebugMode(5) } }
}
RadioButton {
x: 8; y: 19 + 6 * 23
text: qsTr("Lighting")
exclusiveGroup: buffer
onCheckedChanged: { if (checked) { setDebugMode(6) } }
}
RadioButton {
x: 8; y: 19 + 7 * 23
text: qsTr("Shadow")
exclusiveGroup: buffer
onCheckedChanged: { if (checked) { setDebugMode(7) } }
}
RadioButton {
x: 8; y: 19 + 8 * 23
text: qsTr("Pyramid Depth")
exclusiveGroup: buffer
onCheckedChanged: { if (checked) { setDebugMode(8) } }
}
RadioButton {
x: 8; y: 19 + 9 * 23
text: qsTr("Ambient Occlusion")
exclusiveGroup: buffer
onCheckedChanged: { if (checked) { setDebugMode(9) } }
}
RadioButton {
x: 8; y: 19 + 10 * 23
text: qsTr("Custom Shader")
exclusiveGroup: buffer
onCheckedChanged: { if (checked) { setDebugMode(10) } }
}
}

View file

@ -0,0 +1,58 @@
//
// ConfigSlider.qml
// examples/utilities/tools/render
//
// Created by Zach Pomerantz on 2/8/2016
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.5
import QtQuick.Controls 1.4
Item {
width: 400
height: 24
property string label
property QtObject config
property string prop
property real min: 0.0
property real max: 1.0
function init() {
stat.text = config[prop].toFixed(2);
slider.value = (config[prop] - min) / (max - min);
}
Component.onCompleted: init()
function update() {
var val = min + (max - min) * slider.value;
stat.text = val.toFixed(2);
config[prop] = val;
}
Label {
text: parent.label
y: 7
anchors.left: parent.left
anchors.leftMargin: 8
}
Label {
id: stat
y: 7
anchors.left: parent.left
anchors.leftMargin: 140
}
Slider {
id: slider
y: 3
width: 192
height: 20
onValueChanged: parent.update()
anchors.right: parent.right
anchors.rightMargin: 8
}
}

View file

@ -0,0 +1,59 @@
//
// ItemsSlider.qml
// examples/utilities/tools/render
//
// Created by Zach Pomerantz on 2/8/2016
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.5
import QtQuick.Controls 1.4
Item {
width: 400
height: 24
property string label
property QtObject config
function update() {
var val = slider.value;
var max = config.numDrawn;
var drawn = Math.round(val * max);
stat.text = drawn + " / " + max;
config.maxDrawn = (val == 1.0 ? -1 : drawn);
}
Timer {
interval: 500
running: true
repeat: true
onTriggered: parent.update()
}
Label {
text: parent.label
y: 7
anchors.left: parent.left
anchors.leftMargin: 8
}
Label {
id: stat
y: 7
anchors.left: parent.left
anchors.leftMargin: 108
}
Slider {
id: slider
y: 3
width: 192
height: 20
value: 1.0
onValueChanged: update()
anchors.right: parent.right
anchors.rightMargin: 8
}
}

View file

@ -0,0 +1,49 @@
//
// Tone.qml
// examples/utilities/tools/render
//
// Created by Zach Pomerantz on 2/8/2016
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.5
import QtQuick.Controls 1.4
Item {
width: 400
height: 24
property string label: qsTr("Tone Mapping Exposure")
function update() {
var val = (slider.value - 0.5) * 20;
stat.text = val.toFixed(2);
Render.getConfig("ToneMapping").exposure = val;
}
Label {
text: parent.label
y: 7
anchors.left: parent.left
anchors.leftMargin: 8
}
Label {
id: stat
y: 7
anchors.left: parent.left
anchors.leftMargin: 150
}
Slider {
id: slider
y: 3
width: 192
height: 20
value: Render.getConfig("ToneMapping").exposure
onValueChanged: parent.update()
anchors.right: parent.right
anchors.rightMargin: 8
}
}

View file

@ -0,0 +1,38 @@
//
// debug.js
// examples/utilities/tools/render
//
// Zach Pomerantz, created on 1/27/2016.
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
oldConfig = Render.toJSON();
Render.RenderShadowTask.enabled = true;
Render.RenderDeferredTask.AmbientOcclusion.enabled = true;
Render.RenderDeferredTask.DebugDeferredBuffer.enabled = false;
// Set up the qml ui
var qml = Script.resolvePath('main.qml');
var window = new OverlayWindow({
title: 'Render Engine Configuration',
source: qml,
width: 400, height: 900,
});
window.setPosition(25, 50);
window.closed.connect(function() { Script.stop(); });
// Debug buffer sizing
var resizing = false;
Controller.mousePressEvent.connect(function() { resizing = true; });
Controller.mouseReleaseEvent.connect(function() { resizing = false; });
Controller.mouseMoveEvent.connect(function(e) { resizing && setDebugBufferSize(e.x); });
function setDebugBufferSize(x) {
x = (2.0 * (x / Window.innerWidth) - 1.0); // scale
x = Math.min(Math.max(-1, x), 1); // clamp
Render.RenderDeferredTask.DebugDeferredBuffer.size = {x: x, y: -1, z: 1, w: 1};
}
Script.scriptEnding.connect(function() { Render.fromJSON(oldConfig); } );

View file

@ -0,0 +1,64 @@
//
// main.qml
// examples/utilities/tools/render
//
// Created by Zach Pomerantz on 2/8/2016
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.5
import QtQuick.Controls 1.4
Item {
// Items
ItemsSlider {
y: 0 * 25
label: qsTr("Opaque")
config: Render.getConfig("DrawOpaqueDeferred")
}
ItemsSlider {
y: 1 * 25
label: qsTr("Transparent")
config: Render.getConfig("DrawTransparentDeferred")
}
ItemsSlider {
y: 2 * 25
label: qsTr("Overlay3D")
config: Render.getConfig("DrawOverlay3D")
}
// Draw status
Item {
y: 100
CheckBox {
text: qsTr("Display Status")
partiallyCheckedEnabled: false
onCheckedChanged: { Render.getConfig("DrawStatus").showDisplay = checked }
}
CheckBox {
x: 200
text: qsTr("Network/Physics Status")
partiallyCheckedEnabled: false
onCheckedChanged: { Render.getConfig("DrawStatus").showNetwork = checked }
}
}
// Tone mapping
ConfigSlider {
y: 125
config: Render.getConfig("ToneMapping")
prop: "exposure"
label: qsTr("Tone Mapping Exposure")
min: -10; max: 10
}
// Ambient occlusion
AO { y: 175 }
// Debug buffer
Buffer { y: 475 }
}

View file

@ -1,216 +0,0 @@
//
// renderEngineDebug.js
// examples/utilities/tools
//
// Sam Gateau
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
Script.include("cookies.js");
var MENU = "Developer>Render>Debug Deferred Buffer";
var ACTIONS = ["Off", "Diffuse", "Metallic", "Roughness", "Normal", "Depth", "Lighting", "Shadow", "PyramidDepth", "AmbientOcclusion", "OcclusionBlurred", "Custom"];
var SETTINGS_KEY = "EngineDebugScript.DebugMode";
Number.prototype.clamp = function(min, max) {
return Math.min(Math.max(this, min), max);
};
var panel = new Panel(10, 100);
function CounterWidget(parentPanel, name, counter) {
var subPanel = parentPanel.newSubPanel(name);
var widget = parentPanel.items[name];
widget.editTitle({ width: 270 });
subPanel.newSlider('Max Drawn', -1, 1,
function(value) { counter.maxDrawn = value; }, // setter
function() { return counter.maxDrawn; }, // getter
function(value) { return value; });
var slider = subPanel.getWidget('Max Drawn');
this.update = function () {
var numDrawn = counter.numDrawn; // avoid double polling
var numMax = Math.max(numDrawn, 1);
var title = [
' ' + name,
numDrawn + ' / ' + counter.numFeed
].join('\t');
widget.editTitle({ text: title });
slider.setMaxValue(numMax);
};
};
var opaquesCounter = new CounterWidget(panel, "Opaques", Render.opaque);
var transparentsCounter = new CounterWidget(panel, "Transparents", Render.transparent);
var overlaysCounter = new CounterWidget(panel, "Overlays", Render.overlay3D);
var resizing = false;
var previousMode = Settings.getValue(SETTINGS_KEY, -1);
previousMode = 8;
Menu.addActionGroup(MENU, ACTIONS, ACTIONS[previousMode + 1]);
Render.deferredDebugMode = previousMode;
Render.deferredDebugSize = { x: 0.0, y: -1.0, z: 1.0, w: 1.0 }; // Reset to default size
function setEngineDeferredDebugSize(eventX) {
var scaledX = (2.0 * (eventX / Window.innerWidth) - 1.0).clamp(-1.0, 1.0);
Render.deferredDebugSize = { x: scaledX, y: -1.0, z: 1.0, w: 1.0 };
}
function shouldStartResizing(eventX) {
var x = Math.abs(eventX - Window.innerWidth * (1.0 + Render.deferredDebugSize.x) / 2.0);
var mode = Render.deferredDebugMode;
return mode !== -1 && x < 20;
}
function menuItemEvent(menuItem) {
var index = ACTIONS.indexOf(menuItem);
if (index >= 0) {
Render.deferredDebugMode = (index - 1);
}
}
// see libraries/render/src/render/Engine.h
var showDisplayStatusFlag = 1;
var showNetworkStatusFlag = 2;
panel.newCheckbox("Display status",
function(value) { Render.displayItemStatus = (value ?
Render.displayItemStatus | showDisplayStatusFlag :
Render.displayItemStatus & ~showDisplayStatusFlag); },
function() { return (Render.displayItemStatus & showDisplayStatusFlag) > 0; },
function(value) { return (value & showDisplayStatusFlag) > 0; }
);
panel.newCheckbox("Network/Physics status",
function(value) { Render.displayItemStatus = (value ?
Render.displayItemStatus | showNetworkStatusFlag :
Render.displayItemStatus & ~showNetworkStatusFlag); },
function() { return (Render.displayItemStatus & showNetworkStatusFlag) > 0; },
function(value) { return (value & showNetworkStatusFlag) > 0; }
);
panel.newSlider("Tone Mapping Exposure", -10, 10,
function (value) { Render.tone.exposure = value; },
function() { return Render.tone.exposure; },
function (value) { return (value); });
panel.newSlider("Ambient Occlusion Resolution Level", 0.0, 4.0,
function (value) { Render.ambientOcclusion.resolutionLevel = value; },
function() { return Render.ambientOcclusion.resolutionLevel; },
function (value) { return (value); });
panel.newSlider("Ambient Occlusion Radius", 0.0, 2.0,
function (value) { Render.ambientOcclusion.radius = value; },
function() { return Render.ambientOcclusion.radius; },
function (value) { return (value.toFixed(2)); });
panel.newSlider("Ambient Occlusion Level", 0.0, 1.0,
function (value) { Render.ambientOcclusion.level = value; },
function() { return Render.ambientOcclusion.level; },
function (value) { return (value.toFixed(2)); });
panel.newSlider("Ambient Occlusion Num Samples", 1, 32,
function (value) { Render.ambientOcclusion.numSamples = value; },
function() { return Render.ambientOcclusion.numSamples; },
function (value) { return (value); });
panel.newSlider("Ambient Occlusion Num Spiral Turns", 0.0, 30.0,
function (value) { Render.ambientOcclusion.numSpiralTurns = value; },
function() { return Render.ambientOcclusion.numSpiralTurns; },
function (value) { return (value.toFixed(2)); });
panel.newCheckbox("Ambient Occlusion Dithering",
function (value) { Render.ambientOcclusion.ditheringEnabled = value; },
function() { return Render.ambientOcclusion.ditheringEnabled; },
function (value) { return (value); });
panel.newSlider("Ambient Occlusion Falloff Bias", 0.0, 0.2,
function (value) { Render.ambientOcclusion.falloffBias = value; },
function() { return Render.ambientOcclusion.falloffBias; },
function (value) { return (value.toFixed(2)); });
panel.newSlider("Ambient Occlusion Edge Sharpness", 0.0, 1.0,
function (value) { Render.ambientOcclusion.edgeSharpness = value; },
function() { return Render.ambientOcclusion.edgeSharpness; },
function (value) { return (value.toFixed(2)); });
panel.newSlider("Ambient Occlusion Blur Radius", 0.0, 6.0,
function (value) { Render.ambientOcclusion.blurRadius = value; },
function() { return Render.ambientOcclusion.blurRadius; },
function (value) { return (value); });
panel.newSlider("Ambient Occlusion Blur Deviation", 0.0, 3.0,
function (value) { Render.ambientOcclusion.blurDeviation = value; },
function() { return Render.ambientOcclusion.blurDeviation; },
function (value) { return (value.toFixed(2)); });
panel.newSlider("Ambient Occlusion GPU time", 0.0, 10.0,
function (value) {},
function() { return Render.ambientOcclusion.gpuTime; },
function (value) { return (value.toFixed(2) + " ms"); });
var tickTackPeriod = 500;
function updateCounters() {
opaquesCounter.update();
transparentsCounter.update();
overlaysCounter.update();
panel.update("Ambient Occlusion GPU time");
}
Script.setInterval(updateCounters, tickTackPeriod);
function mouseMoveEvent(event) {
if (resizing) {
setEngineDeferredDebugSize(event.x);
} else {
panel.mouseMoveEvent(event);
}
}
function mousePressEvent(event) {
if (shouldStartResizing(event.x)) {
resizing = true;
} else {
panel.mousePressEvent(event);
}
}
function mouseReleaseEvent(event) {
if (resizing) {
resizing = false;
} else {
panel.mouseReleaseEvent(event);
}
}
Controller.mouseMoveEvent.connect(mouseMoveEvent);
Controller.mousePressEvent.connect(mousePressEvent);
Controller.mouseReleaseEvent.connect(mouseReleaseEvent);
Menu.menuItemEvent.connect(menuItemEvent);
function scriptEnding() {
panel.destroy();
Menu.removeActionGroup(MENU);
// Reset
Settings.setValue(SETTINGS_KEY, Render.deferredDebugMode);
Render.deferredDebugMode = -1;
Render.deferredDebugSize = { x: 0.0, y: -1.0, z: 1.0, w: 1.0 };
Render.opaque.maxDrawn = -1;
Render.transparent.maxDrawn = -1;
Render.overlay3D.maxDrawn = -1;
}
Script.scriptEnding.connect(scriptEnding);
// Collapse items
panel.mousePressEvent({ x: panel.x, y: panel.items["Overlays"].y});
panel.mousePressEvent({ x: panel.x, y: panel.items["Transparents"].y});
panel.mousePressEvent({ x: panel.x, y: panel.items["Opaques"].y});