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
crashfix_debugdraw
florent.teppe 2 years ago
parent 21971c08ba
commit 43b0ae1ce7

@ -27,9 +27,6 @@
#include "../mwbase/statemanager.hpp"
#include "../mwbase/luamanager.hpp"
#include "../mwrender/renderingmanager.hpp"
#include <components/debug/debugdraw.hpp>
#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();

@ -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<MWRenderDebug::DebugDrawer>(mResourceSystem->getSceneManager()->getShaderManager(), mRootNode);
mDebugDraw = std::make_unique<Debug::DebugDrawer>(mResourceSystem->getSceneManager()->getShaderManager(), mRootNode);
mResourceSystem->getSceneManager()->setIncrementalCompileOperation(mViewer->getIncrementalCompileOperation());
mEffectManager = std::make_unique<EffectManager>(sceneRoot, mResourceSystem);
@ -907,7 +906,7 @@ namespace MWRender
reportStats();
mResourceSystem->getSceneManager()->getShaderManager().update(*mViewer);
mDebugDraw->update();
float rainIntensity = mSky->getPrecipitationAlpha();
mWater->setRainIntensity(rainIntensity);

@ -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<NpcAnimation> mPlayerAnimation;
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> mPlayerNode;
std::unique_ptr<Camera> mCamera;
std::unique_ptr<MWRenderDebug::DebugDrawer> mDebugDraw;
std::unique_ptr<Debug::DebugDrawer> mDebugDraw;
osg::ref_ptr<StateUpdater> mStateUpdater;
osg::ref_ptr<SharedUniformStateUpdater> mSharedUniformStateUpdater;

@ -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)
{
@ -319,7 +319,7 @@ namespace MWRenderDebug
class DebugDrawCallback : public SceneUtil::NodeCallback<DebugDrawCallback>
{
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<osg::Group> parentNode)
Debug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager, osg::ref_ptr<osg::Group> 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()
Debug::DebugDrawer::~DebugDrawer()
{
}
void MWRenderDebug::DebugDrawer::update()
{
}
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<osg::Vec3Array*>(mDebugLines->mLinesGeom[indexWrite]->getVertexArray());

@ -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<osg::Group> 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);

@ -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

@ -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();
}

@ -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.);
}

@ -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.);
}
}

@ -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;
}
}
Loading…
Cancel
Save