From 43b0ae1ce7f0fc9a5e85169da29d9d42bbd44246 Mon Sep 17 00:00:00 2001 From: "florent.teppe" Date: Fri, 2 Sep 2022 13:40:41 +0200 Subject: [PATCH] all debug renders now use the same shader and it works remove debug draw shader, now that debug and debugdraw serve the same function remove debug draw code from actors to clean replaced int uniforms with bool for better readability clang format cleanup, remove unused func, and mistake whitespace fix namespace added more colors fixed missing whitespace --- apps/openmw/mwmechanics/actors.cpp | 22 ------------- apps/openmw/mwrender/renderingmanager.cpp | 5 ++- apps/openmw/mwrender/renderingmanager.hpp | 8 +++-- components/debug/debugdraw.cpp | 38 ++++++++++------------- components/debug/debugdraw.hpp | 6 ++-- files/shaders/CMakeLists.txt | 2 -- files/shaders/debug_fragment.glsl | 4 +-- files/shaders/debug_vertex.glsl | 14 +++++---- files/shaders/debugdraw_fragment.glsl | 23 -------------- files/shaders/debugdraw_vertex.glsl | 27 ---------------- 10 files changed, 38 insertions(+), 111 deletions(-) delete mode 100644 files/shaders/debugdraw_fragment.glsl delete mode 100644 files/shaders/debugdraw_vertex.glsl diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 1c98fb8a5c..40aa628f01 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -27,9 +27,6 @@ #include "../mwbase/statemanager.hpp" #include "../mwbase/luamanager.hpp" -#include "../mwrender/renderingmanager.hpp" -#include - #include "../mwmechanics/aibreathe.hpp" #include "../mwrender/vismask.hpp" @@ -1610,28 +1607,9 @@ namespace MWMechanics continue; } - world->setActorActive(actor.getPtr(), true); const bool isDead = actor.getPtr().getClass().getCreatureStats(actor.getPtr()).isDead(); - auto actorPos = actor.getPtr().getRefData().getPosition().asVec3(); - auto& debugRender = world->getRenderingManager()->getDebugDrawer(); - if (isDead) - { - debugRender.drawCube(actorPos, osg::Vec3(50.,50.,50.),MWRenderDebug::colorGreen); - } - else if (isPlayer) - { - debugRender.addDrawCall(MWRenderDebug::DrawCall::cylinder(actorPos, osg::Vec3(50.,50.,75.),MWRenderDebug::colorRed )); - } - else - { - debugRender.addDrawCall(MWRenderDebug::DrawCall::wireCube(actorPos)); - } - debugRender.addLine(actorPos, actorPos + osg::Vec3(0., 0., 200.),MWRenderDebug::colorBlue); - - - if (!isDead && (!godmode || !isPlayer) && actor.getPtr().getClass().getCreatureStats(actor.getPtr()).isParalyzed()) ctrl.skipAnim(); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index d67809a7aa..90598f0dbc 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -84,7 +84,6 @@ #include "groundcover.hpp" #include "postprocessor.hpp" - namespace MWRender { class PerViewUniformStateUpdater final : public SceneUtil::StateSetUpdater @@ -491,7 +490,7 @@ namespace MWRender mViewer->getIncrementalCompileOperation()->setTargetFrameRate(Settings::Manager::getFloat("target framerate", "Cells")); } - mDebugDraw = std::make_unique(mResourceSystem->getSceneManager()->getShaderManager(), mRootNode); + mDebugDraw = std::make_unique(mResourceSystem->getSceneManager()->getShaderManager(), mRootNode); mResourceSystem->getSceneManager()->setIncrementalCompileOperation(mViewer->getIncrementalCompileOperation()); mEffectManager = std::make_unique(sceneRoot, mResourceSystem); @@ -907,7 +906,7 @@ namespace MWRender reportStats(); mResourceSystem->getSceneManager()->getShaderManager().update(*mViewer); - mDebugDraw->update(); + float rainIntensity = mSky->getPrecipitationAlpha(); mWater->setRainIntensity(rainIntensity); diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 6edad3d2d0..3304628714 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -74,10 +74,12 @@ namespace MWWorld { class GroundcoverStore; } -namespace MWRenderDebug + +namespace Debug { struct DebugDrawer; } + namespace MWRender { class StateUpdater; @@ -237,7 +239,7 @@ namespace MWRender void exportSceneGraph(const MWWorld::Ptr& ptr, const std::string& filename, const std::string& format); - MWRenderDebug::DebugDrawer& getDebugDrawer() const { return *mDebugDraw; } + Debug::DebugDrawer& getDebugDrawer() const { return *mDebugDraw; } LandManager* getLandManager() const; @@ -311,7 +313,7 @@ namespace MWRender osg::ref_ptr mPlayerAnimation; osg::ref_ptr mPlayerNode; std::unique_ptr mCamera; - std::unique_ptr mDebugDraw; + std::unique_ptr mDebugDraw; osg::ref_ptr mStateUpdater; osg::ref_ptr mSharedUniformStateUpdater; diff --git a/components/debug/debugdraw.cpp b/components/debug/debugdraw.cpp index ee29dc95f5..1180ceb513 100644 --- a/components/debug/debugdraw.cpp +++ b/components/debug/debugdraw.cpp @@ -57,8 +57,8 @@ static void generateWireCube(osg::Geometry& geom, float dim) normals->push_back(osg::Vec3(1., 1., 1.)); } - geom.setVertexArray( vertices); - geom.setNormalArray( normals, osg::Array::BIND_PER_VERTEX); + geom.setVertexArray(vertices); + geom.setNormalArray(normals, osg::Array::BIND_PER_VERTEX); geom.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size())); } @@ -103,7 +103,7 @@ static void generateCube(osg::Geometry& geom, float dim) } } geom.setVertexArray(vertices); - geom.setNormalArray( normals, osg::Array::BIND_PER_VERTEX); + geom.setNormalArray(normals, osg::Array::BIND_PER_VERTEX); geom.addPrimitiveSet(indices); } @@ -223,7 +223,7 @@ static int getIdexBufferWriteFromFrame(const long long int& nFrame) return (nFrame + 1) % 2; } -namespace MWRenderDebug +namespace Debug { void DebugCustomDraw::drawImplementation(osg::RenderInfo& renderInfo) const { @@ -252,11 +252,11 @@ namespace MWRenderDebug ext->glUniform3f(transLocation, 0., 0., 0.); ext->glUniform3f(colLocation, 1., 1., 1.); ext->glUniform3f(scaleLocation, 1., 1., 1.); - ext->glUniform1i(normalAsColorLocation, 1); + ext->glUniform1i(normalAsColorLocation, true); mLinesToDraw->drawImplementation(renderInfo); - ext->glUniform1i(normalAsColorLocation, 0); + ext->glUniform1i(normalAsColorLocation, false); for (const auto& shapeToDraw : mShapesToDraw) { @@ -298,7 +298,7 @@ namespace MWRenderDebug lines.setUseDisplayList(false); lines.setCullingActive(false); - lines.setVertexArray( vertices); + lines.setVertexArray(vertices); lines.setNormalArray(color, osg::Array::BIND_PER_VERTEX); lines.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size())); @@ -319,7 +319,7 @@ namespace MWRenderDebug class DebugDrawCallback : public SceneUtil::NodeCallback { public: - DebugDrawCallback(MWRenderDebug::DebugDrawer& debugDrawer) : mDebugDrawer(debugDrawer) {} + DebugDrawCallback(Debug::DebugDrawer& debugDrawer) : mDebugDrawer(debugDrawer) {} void operator()(osg::Node* node, osg::NodeVisitor* nv) { @@ -334,11 +334,11 @@ namespace MWRenderDebug nv->popFromNodePath(); } - MWRenderDebug::DebugDrawer& mDebugDrawer; + Debug::DebugDrawer& mDebugDrawer; }; } -MWRenderDebug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager, osg::ref_ptr parentNode) +Debug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager, osg::ref_ptr parentNode) { mCurrentFrame = 0; auto vertexShader = shaderManager.getShader("debug_vertex.glsl", Shader::ShaderManager::DefineMap(), osg::Shader::Type::VERTEX); @@ -353,8 +353,8 @@ MWRenderDebug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager, os stateset->addUniform(new osg::Uniform("color", osg::Vec3f(1., 1., 1.))); stateset->addUniform(new osg::Uniform("trans", osg::Vec3f(0., 0., 0.))); stateset->addUniform(new osg::Uniform("scale", osg::Vec3f(1., 1., 1.))); - stateset->addUniform(new osg::Uniform("useNormalAsColor", 0)); - stateset->addUniform(new osg::Uniform("useAdvancedShader", 1)); + stateset->addUniform(new osg::Uniform("useNormalAsColor", false)); + stateset->addUniform(new osg::Uniform("useAdvancedShader", true)); stateset->setAttributeAndModes(program, osg::StateAttribute::ON); stateset->setMode(GL_DEPTH_TEST, GL_TRUE); @@ -388,32 +388,28 @@ MWRenderDebug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager, os parentNode->addChild(mDebugDrawSceneObjects); } -MWRenderDebug::DebugDrawer::~DebugDrawer() -{ -} - -void MWRenderDebug::DebugDrawer::update() +Debug::DebugDrawer::~DebugDrawer() { } -void MWRenderDebug::DebugDrawer::drawCube(osg::Vec3f mPosition, osg::Vec3f mDims, osg::Vec3f mColor) +void Debug::DebugDrawer::drawCube(osg::Vec3f mPosition, osg::Vec3f mDims, osg::Vec3f mColor) { mShapesToDraw[getIdexBufferWriteFromFrame(this->mCurrentFrame)].push_back({ mPosition, mDims, mColor, DrawShape::Cube }); } -void MWRenderDebug::DebugDrawer::drawCubeMinMax(osg::Vec3f min, osg::Vec3f max, osg::Vec3f color) +void Debug::DebugDrawer::drawCubeMinMax(osg::Vec3f min, osg::Vec3f max, osg::Vec3f color) { osg::Vec3 dims = max - min; osg::Vec3 pos = min + dims * 0.5f; drawCube(pos, dims, color); } -void MWRenderDebug::DebugDrawer::addDrawCall(const DrawCall& draw) +void Debug::DebugDrawer::addDrawCall(const DrawCall& draw) { mShapesToDraw[getIdexBufferWriteFromFrame(this->mCurrentFrame)].push_back(draw); } -void MWRenderDebug::DebugDrawer::addLine(const osg::Vec3& start, const osg::Vec3& end, const osg::Vec3 color) +void Debug::DebugDrawer::addLine(const osg::Vec3& start, const osg::Vec3& end, const osg::Vec3 color) { const int indexWrite = getIdexBufferWriteFromFrame(this->mCurrentFrame); auto vertices = static_cast(mDebugLines->mLinesGeom[indexWrite]->getVertexArray()); diff --git a/components/debug/debugdraw.hpp b/components/debug/debugdraw.hpp index df8b59641a..a40bcb0863 100644 --- a/components/debug/debugdraw.hpp +++ b/components/debug/debugdraw.hpp @@ -19,12 +19,15 @@ namespace Shader class ShaderManager; } -namespace MWRenderDebug +namespace Debug { static const osg::Vec3f colorWhite = osg::Vec3(1., 1., 1.); static const osg::Vec3f colorRed = osg::Vec3(1., 0., 0.); static const osg::Vec3f colorBlue = osg::Vec3(0., 0., 1.); static const osg::Vec3f colorGreen = osg::Vec3(0., 1., 0.); + static const osg::Vec3f colorMagenta = osg::Vec3(1., 0., 1.); + static const osg::Vec3f colorYellow = osg::Vec3(1., 1., 0.); + static const osg::Vec3f colorCyan = osg::Vec3(0., 1., 1.); static const osg::Vec3f colorBlack = osg::Vec3(0., 0., 0.); static const osg::Vec3f colorDarkGrey = osg::Vec3(0.25, 0.25, 0.25); @@ -74,7 +77,6 @@ namespace MWRenderDebug DebugDrawer(Shader::ShaderManager& shaderManager, osg::ref_ptr parentNode); ~DebugDrawer(); - void update(); void drawCube(osg::Vec3f mPosition, osg::Vec3f mDims = osg::Vec3(50., 50., 50.), osg::Vec3f mColor = colorWhite); void drawCubeMinMax(osg::Vec3f min, osg::Vec3f max, osg::Vec3f mColor = colorWhite); void addDrawCall(const DrawCall& draw); diff --git a/files/shaders/CMakeLists.txt b/files/shaders/CMakeLists.txt index 93a627c887..d688f9e7d9 100644 --- a/files/shaders/CMakeLists.txt +++ b/files/shaders/CMakeLists.txt @@ -46,8 +46,6 @@ set(SHADER_FILES gui_fragment.glsl debug_vertex.glsl debug_fragment.glsl - debugdraw_vertex.glsl - debugdraw_fragment.glsl sky_vertex.glsl sky_fragment.glsl skypasses.glsl diff --git a/files/shaders/debug_fragment.glsl b/files/shaders/debug_fragment.glsl index 92ba2b6b94..a92b406d46 100644 --- a/files/shaders/debug_fragment.glsl +++ b/files/shaders/debug_fragment.glsl @@ -4,7 +4,7 @@ varying vec3 vertexNormal; -uniform int useAdvancedShader = 0; +uniform bool useAdvancedShader = false; void main() { @@ -12,7 +12,7 @@ void main() float lightAttenuation = dot(-lightDir, vertexNormal) * 0.5 + 0.5; - if(useAdvancedShader == 0) + if(!useAdvancedShader) { gl_FragData[0] = getDiffuseColor(); } diff --git a/files/shaders/debug_vertex.glsl b/files/shaders/debug_vertex.glsl index dbadb64788..df710fe6f7 100644 --- a/files/shaders/debug_vertex.glsl +++ b/files/shaders/debug_vertex.glsl @@ -5,24 +5,26 @@ uniform vec3 color; uniform vec3 trans; uniform vec3 scale; -uniform int useNormalAsColor; -uniform int useAdvancedShader = 0; +uniform bool useNormalAsColor; +uniform bool useAdvancedShader = false; centroid varying vec4 passColor; varying vec3 vertexNormal; void main() { - gl_Position = mw_modelToClip( vec4(gl_Vertex.xyz * scale + trans,1)); - if(useAdvancedShader == 0) + if(!useAdvancedShader) { + gl_Position = mw_modelToClip( vec4(gl_Vertex)); vertexNormal = vec3(1., 1., 1.); passColor = gl_Color; } else { - vertexNormal = useNormalAsColor == 1 ? vec3(1., 1., 1.) : gl_Normal.xyz; - vec3 colorOut = useNormalAsColor == 1 ? gl_Normal.xyz : color; + gl_Position = mw_modelToClip( vec4(gl_Vertex.xyz * scale + trans,1)); + + vertexNormal = useNormalAsColor ? vec3(1., 1., 1.) : gl_Normal.xyz; + vec3 colorOut = useNormalAsColor? gl_Normal.xyz : color; passColor = vec4(colorOut, 1.); } diff --git a/files/shaders/debugdraw_fragment.glsl b/files/shaders/debugdraw_fragment.glsl deleted file mode 100644 index 6bde7ede82..0000000000 --- a/files/shaders/debugdraw_fragment.glsl +++ /dev/null @@ -1,23 +0,0 @@ -#version 120 -#include "vertexcolors.glsl" - -varying vec3 vertexColor; -varying vec3 vertexNormal; - -uniform int useAdvancedShader = 0; - -void main() -{ - vec3 lightDir = normalize(vec3(-1., -0.5, -2.)); - - float lightAttenuation = dot(-lightDir, vertexNormal) * 0.5 + 0.5; - - if(useAdvancedShader == 0) - { - gl_FragData[0] = getDiffuseColor(); - } - else - { - gl_FragData[0] = vec4(vertexColor * lightAttenuation, 1.); - } -} diff --git a/files/shaders/debugdraw_vertex.glsl b/files/shaders/debugdraw_vertex.glsl deleted file mode 100644 index d48a1b2cb1..0000000000 --- a/files/shaders/debugdraw_vertex.glsl +++ /dev/null @@ -1,27 +0,0 @@ -#version 120 -#include "openmw_vertex.h.glsl" - -uniform vec3 color; -uniform vec3 trans; -uniform vec3 scale; -uniform int useNormalAsColor; -uniform int useAdvancedShader = 0; - -varying vec3 vertexColor; -varying vec3 vertexNormal; - -void main() -{ - gl_Position = mw_modelToClip( vec4(gl_Vertex.xyz * scale + trans,1)); - - if(useAdvancedShader == 0) - { - vertexNormal = vec3(1., 1., 1.); - vertexColor = gl_Color.xyz; - } - else - { - vertexNormal = useNormalAsColor == 1 ? vec3(1., 1., 1.) : gl_Normal.xyz; - vertexColor = useNormalAsColor == 1 ? gl_Normal.xyz : color.xyz; - } -}