Visualize vertex normals in normal view.
This commit is contained in:
parent
bcc2196ccf
commit
c07aed260a
20
data/shaders/normal_visualizer.geom
Normal file
20
data/shaders/normal_visualizer.geom
Normal file
@ -0,0 +1,20 @@
|
||||
layout(triangles) in;
|
||||
layout(line_strip, max_vertices = 6) out;
|
||||
|
||||
in vec3 nor[];
|
||||
|
||||
void main()
|
||||
{
|
||||
for(int i=0; i < gl_in.length(); i++)
|
||||
{
|
||||
vec4 pos = gl_in[i].gl_Position;
|
||||
gl_Position = pos;
|
||||
EmitVertex();
|
||||
|
||||
vec3 normal = nor[i];
|
||||
gl_Position = pos + .2 * vec4(normal, 0.);
|
||||
EmitVertex();
|
||||
|
||||
EndPrimitive();
|
||||
}
|
||||
}
|
@ -362,6 +362,7 @@ private:
|
||||
void renderGLSL(float dt);
|
||||
void renderSolidFirstPass();
|
||||
void renderSolidSecondPass();
|
||||
void renderNormalsVisualisation();
|
||||
void renderTransparent();
|
||||
void renderParticles();
|
||||
void computeSunVisibility();
|
||||
|
@ -318,6 +318,13 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po
|
||||
renderSolidSecondPass();
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
|
||||
if (getNormals())
|
||||
{
|
||||
m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).Bind();
|
||||
renderNormalsVisualisation();
|
||||
m_rtts->getFBO(FBO_COLORS).Bind();
|
||||
}
|
||||
|
||||
if (UserConfigParams::m_dynamic_lights && World::getWorld() != NULL &&
|
||||
World::getWorld()->isFogEnabled())
|
||||
{
|
||||
|
@ -332,6 +332,41 @@ void IrrDriver::renderSolidSecondPass()
|
||||
}
|
||||
}
|
||||
|
||||
template<enum E_VERTEX_TYPE VertexType, typename... TupleType>
|
||||
static void renderMeshNormals(std::vector<STK::Tuple<TupleType...> > &meshes)
|
||||
{
|
||||
glUseProgram(MeshShader::NormalVisualizer::getInstance()->Program);
|
||||
glBindVertexArray(getVAO(VertexType));
|
||||
for (unsigned i = 0; i < meshes.size(); i++)
|
||||
{
|
||||
GLMesh &mesh = *(STK::tuple_get<0>(meshes[i]));
|
||||
|
||||
if (mesh.VAOType != VertexType)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
Log::error("Materials", "Wrong vertex Type associed to pass 2 (hint texture : %s)", mesh.textures[0]->getName().getPath().c_str());
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
draw(MeshShader::NormalVisualizer::getInstance(), STK::tuple_get<0>(meshes[i]), STK::tuple_get<1>(meshes[i]), STK::tuple_get<2>(meshes[i]), video::SColor(255, 0, 255, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void IrrDriver::renderNormalsVisualisation()
|
||||
{
|
||||
renderMeshNormals<video::EVT_STANDARD>(ListMatDefault::Arguments);
|
||||
renderMeshNormals<video::EVT_STANDARD>(ListMatAlphaRef::Arguments);
|
||||
renderMeshNormals<video::EVT_STANDARD>(ListMatSphereMap::Arguments);
|
||||
renderMeshNormals<video::EVT_STANDARD>(ListMatGrass::Arguments);
|
||||
renderMeshNormals<video::EVT_2TCOORDS>(ListMatDetails::Arguments);
|
||||
renderMeshNormals<video::EVT_STANDARD>(ListMatUnlit::Arguments);
|
||||
renderMeshNormals<video::EVT_2TCOORDS>(ListMatSplatting::Arguments);
|
||||
renderMeshNormals<video::EVT_TANGENTS>(ListMatNormalMap::Arguments);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static video::ITexture *displaceTex = 0;
|
||||
|
||||
void IrrDriver::renderTransparent()
|
||||
|
@ -572,6 +572,11 @@ void glUniform3fWraper(GLuint a, float b, float c, float d)
|
||||
glUniform3f(a, b, c, d);
|
||||
}
|
||||
|
||||
void glUniform4iWraper(GLuint a, int b, int c, int d, int e)
|
||||
{
|
||||
glUniform4i(a, b, c, d, e);
|
||||
}
|
||||
|
||||
void glUniform2fWraper(GLuint a, float b, float c)
|
||||
{
|
||||
glUniform2f(a, b, c);
|
||||
@ -1229,6 +1234,18 @@ namespace MeshShader
|
||||
glUniform1i(uniform_tex, TU_tex);
|
||||
}
|
||||
|
||||
NormalVisualizer::NormalVisualizer()
|
||||
{
|
||||
Program = LoadProgram(
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/object_pass.vert").c_str(),
|
||||
GL_GEOMETRY_SHADER, file_manager->getAsset("shaders/normal_visualizer.geom").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/coloredquad.frag").c_str());
|
||||
AssignUniforms("ModelMatrix", "InverseModelMatrix", "color");
|
||||
|
||||
GLuint uniform_ViewProjectionMatrixesUBO = glGetUniformBlockIndex(Program, "MatrixesData");
|
||||
glUniformBlockBinding(Program, uniform_ViewProjectionMatrixesUBO, 0);
|
||||
}
|
||||
|
||||
GLuint ViewFrustrumShader::Program;
|
||||
GLuint ViewFrustrumShader::attrib_position;
|
||||
GLuint ViewFrustrumShader::uniform_color;
|
||||
|
@ -51,6 +51,7 @@ public:
|
||||
|
||||
void glUniformMatrix4fvWraper(GLuint, size_t, unsigned, const float *mat);
|
||||
void glUniform3fWraper(GLuint, float, float, float);
|
||||
void glUniform4iWraper(GLuint, int, int, int, int);
|
||||
void glUniform2fWraper(GLuint a, float b, float c);
|
||||
void glUniform1fWrapper(GLuint, float);
|
||||
bool needsUBO();
|
||||
@ -79,6 +80,13 @@ struct UniformHelper
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const video::SColor &col, Args... arg)
|
||||
{
|
||||
glUniform4iWraper(uniforms[N], col.getRed(), col.getGreen(), col.getBlue(), col.getAlpha());
|
||||
setUniformsHelper<N + 1>(uniforms, arg...);
|
||||
}
|
||||
|
||||
template<unsigned N = 0, typename... Args>
|
||||
static void setUniformsHelper(const std::vector<GLuint> &uniforms, const core::vector3df &v, Args... arg)
|
||||
{
|
||||
@ -407,6 +415,12 @@ public:
|
||||
static void setUniforms(const core::matrix4 &ModelMatrix, const core::vector2df &screen, unsigned TU_tex);
|
||||
};
|
||||
|
||||
class NormalVisualizer : public ShaderHelperSingleton<NormalVisualizer, core::matrix4, core::matrix4, video::SColor>
|
||||
{
|
||||
public:
|
||||
NormalVisualizer();
|
||||
};
|
||||
|
||||
class ViewFrustrumShader
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user