Expose rendering in wireframe mode

This commit is contained in:
samcake 2017-03-15 12:23:44 -07:00
parent 495deba771
commit ea2f1359bc
8 changed files with 55 additions and 19 deletions

View file

@ -133,6 +133,7 @@ void LightingModel::setSpotLight(bool enable) {
bool LightingModel::isSpotLightEnabled() const {
return (bool)_parametersBuffer.get<Parameters>().enableSpotLight;
}
void LightingModel::setShowLightContour(bool enable) {
if (enable != isShowLightContourEnabled()) {
_parametersBuffer.edit<Parameters>().showLightContour = (float)enable;
@ -142,6 +143,14 @@ bool LightingModel::isShowLightContourEnabled() const {
return (bool)_parametersBuffer.get<Parameters>().showLightContour;
}
void LightingModel::setWireframe(bool enable) {
if (enable != isWireframeEnabled()) {
_parametersBuffer.edit<Parameters>().enableWireframe = (float)enable;
}
}
bool LightingModel::isWireframeEnabled() const {
return (bool)_parametersBuffer.get<Parameters>().enableWireframe;
}
MakeLightingModel::MakeLightingModel() {
_lightingModel = std::make_shared<LightingModel>();
}
@ -167,6 +176,7 @@ void MakeLightingModel::configure(const Config& config) {
_lightingModel->setSpotLight(config.enableSpotLight);
_lightingModel->setShowLightContour(config.showLightContour);
_lightingModel->setWireframe(config.enableWireframe);
}
void MakeLightingModel::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, LightingModelPointer& lightingModel) {

View file

@ -64,6 +64,9 @@ public:
void setShowLightContour(bool enable);
bool isShowLightContourEnabled() const;
void setWireframe(bool enable);
bool isWireframeEnabled() const;
UniformBufferView getParametersBuffer() const { return _parametersBuffer; }
protected:
@ -89,13 +92,12 @@ protected:
float enablePointLight{ 1.0f };
float enableSpotLight{ 1.0f };
float showLightContour{ 0.0f }; // false by default
float showLightContour { 0.0f }; // false by default
float enableObscurance{ 1.0f };
float enableMaterialTexturing { 1.0f };
float spares{ 0.0f };
float enableWireframe { 0.0f }; // false by default
Parameters() {}
};
@ -129,6 +131,7 @@ class MakeLightingModelConfig : public render::Job::Config {
Q_PROPERTY(bool enablePointLight MEMBER enablePointLight NOTIFY dirty)
Q_PROPERTY(bool enableSpotLight MEMBER enableSpotLight NOTIFY dirty)
Q_PROPERTY(bool enableWireframe MEMBER enableWireframe NOTIFY dirty)
Q_PROPERTY(bool showLightContour MEMBER showLightContour NOTIFY dirty)
public:
@ -152,9 +155,10 @@ public:
bool enablePointLight{ true };
bool enableSpotLight{ true };
bool showLightContour { false }; // false by default
bool enableWireframe { false }; // false by default
signals:
void dirty();
};

View file

@ -17,7 +17,7 @@ struct LightingModel {
vec4 _UnlitEmissiveLightmapBackground;
vec4 _ScatteringDiffuseSpecularAlbedo;
vec4 _AmbientDirectionalPointSpot;
vec4 _ShowContourObscuranceSpare2;
vec4 _ShowContourObscuranceWireframe;
};
uniform lightingModelBuffer{
@ -37,7 +37,7 @@ float isBackgroundEnabled() {
return lightingModel._UnlitEmissiveLightmapBackground.w;
}
float isObscuranceEnabled() {
return lightingModel._ShowContourObscuranceSpare2.y;
return lightingModel._ShowContourObscuranceWireframe.y;
}
float isScatteringEnabled() {
@ -67,9 +67,12 @@ float isSpotEnabled() {
}
float isShowLightContour() {
return lightingModel._ShowContourObscuranceSpare2.x;
return lightingModel._ShowContourObscuranceWireframe.x;
}
float isWireframeEnabled() {
return lightingModel._ShowContourObscuranceWireframe.z;
}
<@endfunc@>
<$declareLightingModel()$>

View file

@ -259,7 +259,14 @@ void DrawDeferred::run(const SceneContextPointer& sceneContext, const RenderCont
// Setup lighting model for all items;
batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer());
renderShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn);
// From the lighting model define a global shapKey ORED with individiual keys
ShapeKey::Builder keyBuilder;
if (lightingModel->isWireframeEnabled()) {
keyBuilder.withWireframe();
}
ShapeKey globalKey = keyBuilder.build();
renderShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn, globalKey);
args->_batch = nullptr;
});
@ -295,10 +302,17 @@ void DrawStateSortDeferred::run(const SceneContextPointer& sceneContext, const R
// Setup lighting model for all items;
batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer());
// From the lighting model define a global shapKey ORED with individiual keys
ShapeKey::Builder keyBuilder;
if (lightingModel->isWireframeEnabled()) {
keyBuilder.withWireframe();
}
ShapeKey globalKey = keyBuilder.build();
if (_stateSort) {
renderStateSortShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn);
renderStateSortShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn, globalKey);
} else {
renderShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn);
renderShapes(sceneContext, renderContext, _shapePlumber, inItems, _maxDrawn, globalKey);
}
args->_batch = nullptr;
});

View file

@ -39,9 +39,9 @@ void render::renderItems(const SceneContextPointer& sceneContext, const RenderCo
}
}
void renderShape(RenderArgs* args, const ShapePlumberPointer& shapeContext, const Item& item) {
void renderShape(RenderArgs* args, const ShapePlumberPointer& shapeContext, const Item& item, const ShapeKey& globalKey) {
assert(item.getKey().isShape());
const auto& key = item.getShapeKey();
auto key = item.getShapeKey() | globalKey;
if (key.isValid() && !key.hasOwnPipeline()) {
args->_pipeline = shapeContext->pickPipeline(args, key);
if (args->_pipeline) {
@ -56,7 +56,7 @@ void renderShape(RenderArgs* args, const ShapePlumberPointer& shapeContext, cons
}
void render::renderShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext,
const ShapePlumberPointer& shapeContext, const ItemBounds& inItems, int maxDrawnItems) {
const ShapePlumberPointer& shapeContext, const ItemBounds& inItems, int maxDrawnItems, const ShapeKey& globalKey) {
auto& scene = sceneContext->_scene;
RenderArgs* args = renderContext->args;
@ -66,12 +66,12 @@ void render::renderShapes(const SceneContextPointer& sceneContext, const RenderC
}
for (auto i = 0; i < numItemsToDraw; ++i) {
auto& item = scene->getItem(inItems[i].id);
renderShape(args, shapeContext, item);
renderShape(args, shapeContext, item, globalKey);
}
}
void render::renderStateSortShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext,
const ShapePlumberPointer& shapeContext, const ItemBounds& inItems, int maxDrawnItems) {
const ShapePlumberPointer& shapeContext, const ItemBounds& inItems, int maxDrawnItems, const ShapeKey& globalKey) {
auto& scene = sceneContext->_scene;
RenderArgs* args = renderContext->args;
@ -91,7 +91,7 @@ void render::renderStateSortShapes(const SceneContextPointer& sceneContext, cons
{
assert(item.getKey().isShape());
const auto key = item.getShapeKey();
auto key = item.getShapeKey() | globalKey;
if (key.isValid() && !key.hasOwnPipeline()) {
auto& bucket = sortedShapes[key];
if (bucket.empty()) {

View file

@ -17,8 +17,8 @@
namespace render {
void renderItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inItems, int maxDrawnItems = -1);
void renderShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ShapePlumberPointer& shapeContext, const ItemBounds& inItems, int maxDrawnItems = -1);
void renderStateSortShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ShapePlumberPointer& shapeContext, const ItemBounds& inItems, int maxDrawnItems = -1);
void renderShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ShapePlumberPointer& shapeContext, const ItemBounds& inItems, int maxDrawnItems = -1, const ShapeKey& globalKey = ShapeKey());
void renderStateSortShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ShapePlumberPointer& shapeContext, const ItemBounds& inItems, int maxDrawnItems = -1, const ShapeKey& globalKey = ShapeKey());
class DrawLightConfig : public Job::Config {
Q_OBJECT

View file

@ -46,6 +46,10 @@ public:
ShapeKey() : _flags{ 0 } {}
ShapeKey(const Flags& flags) : _flags{flags} {}
friend ShapeKey operator&(const ShapeKey& _Left, const ShapeKey& _Right) { return ShapeKey(_Left._flags & _Right._flags); }
friend ShapeKey operator|(const ShapeKey& _Left, const ShapeKey& _Right) { return ShapeKey(_Left._flags | _Right._flags); }
friend ShapeKey operator^(const ShapeKey& _Left, const ShapeKey& _Right) { return ShapeKey(_Left._flags ^ _Right._flags); }
class Builder {
public:
Builder() {}

View file

@ -25,7 +25,7 @@ Column {
"Lightmap:LightingModel:enableLightmap",
"Background:LightingModel:enableBackground",
"ssao:AmbientOcclusion:enabled",
"Textures:LightingModel:enableMaterialTexturing",
"Textures:LightingModel:enableMaterialTexturing"
]
CheckBox {
text: modelData.split(":")[0]
@ -45,6 +45,7 @@ Column {
"Diffuse:LightingModel:enableDiffuse",
"Specular:LightingModel:enableSpecular",
"Albedo:LightingModel:enableAlbedo",
"Wireframe:LightingModel:enableWireframe"
]
CheckBox {
text: modelData.split(":")[0]