mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-23 19:20:56 +00:00
debug draw shader uses the generic functions
renamed files roundabout way to change case with windows noticing fixed type fix filename in cmakelist.txt ported shader and c++ code so glsl 120 can be used instead of 330 new debug shader and old one are almost unified for some reason, even though I get no compilation issue, old debug draws don't work, only the new one implemented by this MR remove useless const cast
This commit is contained in:
parent
bd1bbc0ab8
commit
21971c08ba
@ -32,9 +32,6 @@ static void generateWireCube(osg::Geometry& geom, float dim)
|
||||
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
|
||||
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
|
||||
|
||||
geom.setVertexAttribArray(0, vertices, osg::Array::BIND_PER_VERTEX);
|
||||
geom.setVertexAttribArray(1, normals, osg::Array::BIND_PER_VERTEX);
|
||||
|
||||
osg::Vec2i indexPos[] = { osg::Vec2i(0, 0), osg::Vec2i(1, 0), osg::Vec2i(1, 1), osg::Vec2i(0, 1) };
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
@ -55,11 +52,13 @@ static void generateWireCube(osg::Geometry& geom, float dim)
|
||||
vertices->push_back(vert1 * dim);
|
||||
vertices->push_back(vert3 * dim);
|
||||
}
|
||||
for (unsigned long i = 0; i < vertices->size(); i++)
|
||||
for (std::size_t i = 0; i < vertices->size(); i++)
|
||||
{
|
||||
normals->push_back(osg::Vec3(1., 1., 1.));
|
||||
}
|
||||
|
||||
geom.setVertexArray( vertices);
|
||||
geom.setNormalArray( normals, osg::Array::BIND_PER_VERTEX);
|
||||
geom.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size()));
|
||||
}
|
||||
|
||||
@ -103,8 +102,8 @@ static void generateCube(osg::Geometry& geom, float dim)
|
||||
indices->push_back(newFace2[i]);
|
||||
}
|
||||
}
|
||||
geom.setVertexAttribArray(0, vertices, osg::Array::BIND_PER_VERTEX);
|
||||
geom.setVertexAttribArray(1, normals, osg::Array::BIND_PER_VERTEX);
|
||||
geom.setVertexArray(vertices);
|
||||
geom.setNormalArray( normals, osg::Array::BIND_PER_VERTEX);
|
||||
geom.addPrimitiveSet(indices);
|
||||
}
|
||||
|
||||
@ -209,8 +208,8 @@ static void generateCylinder(osg::Geometry& geom, float radius, float height, in
|
||||
indices->push_back(bot2);
|
||||
}
|
||||
|
||||
geom.setVertexAttribArray(0, vertices, osg::Array::BIND_PER_VERTEX);
|
||||
geom.setVertexAttribArray(1, normals, osg::Array::BIND_PER_VERTEX);
|
||||
geom.setVertexArray(vertices);
|
||||
geom.setNormalArray(normals, osg::Array::BIND_PER_VERTEX);
|
||||
geom.addPrimitiveSet(indices);
|
||||
}
|
||||
|
||||
@ -240,10 +239,10 @@ namespace MWRenderDebug
|
||||
return;
|
||||
}
|
||||
|
||||
osg::Uniform* uTrans = const_cast<osg::Uniform*>(stateSet->getUniform("trans"));
|
||||
osg::Uniform* uCol = const_cast<osg::Uniform*>(stateSet->getUniform("color"));
|
||||
osg::Uniform* uScale = const_cast<osg::Uniform*>(stateSet->getUniform("scale"));
|
||||
osg::Uniform* uUseNormalAsColor = const_cast<osg::Uniform*>(stateSet->getUniform("useNormalAsColor"));
|
||||
const osg::Uniform* uTrans = stateSet->getUniform("trans");
|
||||
const osg::Uniform* uCol = stateSet->getUniform("color");
|
||||
const osg::Uniform* uScale = stateSet->getUniform("scale");
|
||||
const osg::Uniform* uUseNormalAsColor = stateSet->getUniform("useNormalAsColor");
|
||||
|
||||
auto transLocation = pcp->getUniformLocation(uTrans->getNameID());
|
||||
auto colLocation = pcp->getUniformLocation(uCol->getNameID());
|
||||
@ -283,8 +282,8 @@ namespace MWRenderDebug
|
||||
}
|
||||
}
|
||||
mShapesToDraw.clear();
|
||||
static_cast<osg::Vec3Array*>(mLinesToDraw->getVertexAttribArray(0))->clear();
|
||||
static_cast<osg::Vec3Array*>(mLinesToDraw->getVertexAttribArray(1))->clear();
|
||||
static_cast<osg::Vec3Array*>(mLinesToDraw->getVertexArray())->clear();
|
||||
static_cast<osg::Vec3Array*>(mLinesToDraw->getNormalArray())->clear();
|
||||
}
|
||||
|
||||
struct DebugLines
|
||||
@ -299,8 +298,8 @@ namespace MWRenderDebug
|
||||
lines.setUseDisplayList(false);
|
||||
lines.setCullingActive(false);
|
||||
|
||||
lines.setVertexAttribArray(0, vertices, osg::Array::BIND_PER_VERTEX);
|
||||
lines.setVertexAttribArray(1, color, osg::Array::BIND_PER_VERTEX);
|
||||
lines.setVertexArray( vertices);
|
||||
lines.setNormalArray(color, osg::Array::BIND_PER_VERTEX);
|
||||
|
||||
lines.addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, vertices->size()));
|
||||
}
|
||||
@ -328,7 +327,7 @@ namespace MWRenderDebug
|
||||
int indexRead = getIdexBufferReadFromFrame(mDebugDrawer.mCurrentFrame);
|
||||
auto& lines = mDebugDrawer.mDebugLines;
|
||||
lines->mLinesGeom[indexRead]->removePrimitiveSet(0, 1);
|
||||
lines->mLinesGeom[indexRead]->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, static_cast<osg::Vec3Array*>(lines->mLinesGeom[indexRead]->getVertexAttribArray(0))->size()));
|
||||
lines->mLinesGeom[indexRead]->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, static_cast<osg::Vec3Array*>(lines->mLinesGeom[indexRead]->getVertexArray())->size()));
|
||||
|
||||
nv->pushOntoNodePath(mDebugDrawer.mCustomDebugDrawer[indexRead]);
|
||||
nv->apply(*mDebugDrawer.mCustomDebugDrawer[indexRead]);
|
||||
@ -342,8 +341,8 @@ namespace MWRenderDebug
|
||||
MWRenderDebug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager, osg::ref_ptr<osg::Group> parentNode)
|
||||
{
|
||||
mCurrentFrame = 0;
|
||||
auto vertexShader = shaderManager.getShader("debugDraw_vertex.glsl", Shader::ShaderManager::DefineMap(), osg::Shader::Type::VERTEX);
|
||||
auto fragmentShader = shaderManager.getShader("debugDraw_fragment.glsl", Shader::ShaderManager::DefineMap(), osg::Shader::Type::FRAGMENT);
|
||||
auto vertexShader = shaderManager.getShader("debug_vertex.glsl", Shader::ShaderManager::DefineMap(), osg::Shader::Type::VERTEX);
|
||||
auto fragmentShader = shaderManager.getShader("debug_fragment.glsl", Shader::ShaderManager::DefineMap(), osg::Shader::Type::FRAGMENT);
|
||||
|
||||
auto program = shaderManager.getProgram(vertexShader, fragmentShader);
|
||||
mDebugLines = std::make_unique<DebugLines>();
|
||||
@ -355,6 +354,7 @@ MWRenderDebug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager, os
|
||||
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->setAttributeAndModes(program, osg::StateAttribute::ON);
|
||||
stateset->setMode(GL_DEPTH_TEST, GL_TRUE);
|
||||
@ -375,7 +375,7 @@ MWRenderDebug::DebugDrawer::DebugDrawer(Shader::ShaderManager& shaderManager, os
|
||||
wireCube->setUseVertexBufferObjects(true);
|
||||
generateWireCube(*wireCube, 1.);
|
||||
|
||||
for (unsigned long i = 0; i < mShapesToDraw.size(); i++)
|
||||
for (std::size_t i = 0; i < mShapesToDraw.size(); i++)
|
||||
{
|
||||
mCustomDebugDrawer[i] = new DebugCustomDraw(mShapesToDraw[i], mDebugLines->mLinesGeom[i]);
|
||||
mCustomDebugDrawer[i]->setStateSet(stateset);
|
||||
@ -416,8 +416,8 @@ void MWRenderDebug::DebugDrawer::addDrawCall(const DrawCall& draw)
|
||||
void MWRenderDebug::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]->getVertexAttribArray(0));
|
||||
auto colors = static_cast<osg::Vec3Array*>(mDebugLines->mLinesGeom[indexWrite]->getVertexAttribArray(1));
|
||||
auto vertices = static_cast<osg::Vec3Array*>(mDebugLines->mLinesGeom[indexWrite]->getVertexArray());
|
||||
auto colors = static_cast<osg::Vec3Array*>(mDebugLines->mLinesGeom[indexWrite]->getNormalArray());
|
||||
|
||||
vertices->push_back(start);
|
||||
vertices->push_back(end);
|
||||
|
@ -46,8 +46,8 @@ set(SHADER_FILES
|
||||
gui_fragment.glsl
|
||||
debug_vertex.glsl
|
||||
debug_fragment.glsl
|
||||
debugDraw_vertex.glsl
|
||||
debugDraw_fragment.glsl
|
||||
debugdraw_vertex.glsl
|
||||
debugdraw_fragment.glsl
|
||||
sky_vertex.glsl
|
||||
sky_fragment.glsl
|
||||
skypasses.glsl
|
||||
|
@ -1,15 +0,0 @@
|
||||
#version 330 compatibility
|
||||
|
||||
in vec3 vertexColor;
|
||||
in vec3 vertexNormal;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightDir = normalize(vec3(-1., -0.5, -2.));
|
||||
|
||||
float lightAttenuation = dot(-lightDir, vertexNormal) * 0.5 + 0.5;
|
||||
|
||||
fragColor = vec4(vertexColor * lightAttenuation, 1.);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#version 330 compatibility
|
||||
|
||||
uniform mat4 projectionMatrix;
|
||||
|
||||
uniform vec3 color;
|
||||
uniform vec3 trans;
|
||||
uniform vec3 scale;
|
||||
uniform int useNormalAsColor;
|
||||
|
||||
layout(location = 0) in vec3 aPos;
|
||||
layout(location = 1) in vec3 aNormal;
|
||||
|
||||
out vec3 vertexColor;
|
||||
out vec3 vertexNormal;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = projectionMatrix * gl_ModelViewMatrix * vec4(aPos * scale + trans, 1.);
|
||||
|
||||
vertexNormal = useNormalAsColor == 1 ? vec3(1., 1., 1.) : aNormal;
|
||||
vertexColor = useNormalAsColor == 1 ? aNormal : color.xyz;
|
||||
}
|
@ -2,7 +2,22 @@
|
||||
|
||||
#include "vertexcolors.glsl"
|
||||
|
||||
varying vec3 vertexNormal;
|
||||
|
||||
uniform int useAdvancedShader = 0;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragData[0] = getDiffuseColor();
|
||||
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(passColor.xyz * lightAttenuation, 1.);
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,28 @@
|
||||
|
||||
#include "openmw_vertex.h.glsl"
|
||||
|
||||
uniform vec3 color;
|
||||
uniform vec3 trans;
|
||||
uniform vec3 scale;
|
||||
uniform int useNormalAsColor;
|
||||
uniform int useAdvancedShader = 0;
|
||||
|
||||
centroid varying vec4 passColor;
|
||||
varying vec3 vertexNormal;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mw_modelToClip(gl_Vertex);
|
||||
|
||||
passColor = gl_Color;
|
||||
gl_Position = mw_modelToClip( vec4(gl_Vertex.xyz * scale + trans,1));
|
||||
if(useAdvancedShader == 0)
|
||||
{
|
||||
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;
|
||||
passColor = vec4(colorOut, 1.);
|
||||
}
|
||||
|
||||
}
|
||||
|
23
files/shaders/debugdraw_fragment.glsl
Normal file
23
files/shaders/debugdraw_fragment.glsl
Normal file
@ -0,0 +1,23 @@
|
||||
#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.);
|
||||
}
|
||||
}
|
27
files/shaders/debugdraw_vertex.glsl
Normal file
27
files/shaders/debugdraw_vertex.glsl
Normal file
@ -0,0 +1,27 @@
|
||||
#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…
x
Reference in New Issue
Block a user