STKAnimatedMesh: Plug the Light prepass system
Now animated object are rendered like static object with our pipelines. rimlimit shader needs to be ported though.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include <ISceneManager.h>
|
||||
#include <IMaterialRenderer.h>
|
||||
#include <ISkinnedMesh.h>
|
||||
#include "graphics/irr_driver.hpp"
|
||||
|
||||
using namespace irr;
|
||||
|
||||
@@ -12,6 +13,63 @@ const core::vector3df& rotation,
|
||||
const core::vector3df& scale) :
|
||||
CAnimatedMeshSceneNode(mesh, parent, mgr, id, position, rotation, scale)
|
||||
{
|
||||
firstTime = true;
|
||||
}
|
||||
|
||||
|
||||
void STKAnimatedMesh::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
|
||||
{
|
||||
switch (irr_driver->getPhase())
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH), false, false);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
computeMVP(ModelViewProjectionMatrix);
|
||||
computeTIMV(TransposeInverseModelView);
|
||||
|
||||
if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
|
||||
drawObjectRefPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
|
||||
else
|
||||
drawObjectPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
|
||||
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getMainSetup(), false, false);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
|
||||
drawObjectRefPass2(mesh, ModelViewProjectionMatrix);
|
||||
else
|
||||
drawObjectPass2(mesh, ModelViewProjectionMatrix);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
assert(0 && "wrong pass");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
isObjectPass(video::E_MATERIAL_TYPE type)
|
||||
{
|
||||
if (type == irr_driver->getShader(ES_OBJECTPASS))
|
||||
return true;
|
||||
if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void STKAnimatedMesh::render()
|
||||
@@ -38,6 +96,13 @@ void STKAnimatedMesh::render()
|
||||
|
||||
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
|
||||
|
||||
if (firstTime)
|
||||
for (u32 i = 0; i<m->getMeshBufferCount(); ++i)
|
||||
{
|
||||
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);
|
||||
GLmeshes.push_back(allocateMeshBuffer(mb));
|
||||
}
|
||||
firstTime = false;
|
||||
|
||||
// render original meshes
|
||||
for (u32 i = 0; i<m->getMeshBufferCount(); ++i)
|
||||
@@ -47,15 +112,32 @@ void STKAnimatedMesh::render()
|
||||
|
||||
// only render transparent buffer if this is the transparent render pass
|
||||
// and solid only in solid pass
|
||||
if (transparent == isTransparentPass)
|
||||
if (transparent != isTransparentPass)
|
||||
continue;
|
||||
scene::IMeshBuffer* mb = m->getMeshBuffer(i);
|
||||
const video::SMaterial& material = ReadOnlyMaterials ? mb->getMaterial() : Materials[i];
|
||||
if (RenderFromIdentity)
|
||||
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||
else if (Mesh->getMeshType() == scene::EAMT_SKINNED)
|
||||
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation * ((scene::SSkinMeshBuffer*)mb)->Transformation);
|
||||
if (isObjectPass(material.MaterialType))
|
||||
{
|
||||
initvaostate(GLmeshes[i], material.MaterialType);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, GLmeshes[i].vertex_buffer);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, mb->getVertexCount() * GLmeshes[i].Stride, mb->getVertices());
|
||||
drawSolid(GLmeshes[i], material.MaterialType);
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
video::SMaterial material;
|
||||
material.MaterialType = irr_driver->getShader(ES_RAIN);
|
||||
material.BlendOperation = video::EBO_NONE;
|
||||
material.ZWriteEnable = true;
|
||||
material.Lighting = false;
|
||||
irr_driver->getVideoDriver()->setMaterial(material);
|
||||
static_cast<irr::video::COpenGLDriver*>(irr_driver->getVideoDriver())->setRenderStates3DMode();
|
||||
}
|
||||
else
|
||||
{
|
||||
scene::IMeshBuffer* mb = m->getMeshBuffer(i);
|
||||
const video::SMaterial& material = ReadOnlyMaterials ? mb->getMaterial() : Materials[i];
|
||||
if (RenderFromIdentity)
|
||||
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||
else if (Mesh->getMeshType() == scene::EAMT_SKINNED)
|
||||
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation * ((scene::SSkinMeshBuffer*)mb)->Transformation);
|
||||
printf("Material type is %d\n", material.MaterialType);
|
||||
driver->setMaterial(material);
|
||||
driver->drawMeshBuffer(mb);
|
||||
}
|
||||
|
||||
@@ -4,9 +4,16 @@
|
||||
#include "../lib/irrlicht/source/Irrlicht/CAnimatedMeshSceneNode.h"
|
||||
#include <IAnimatedMesh.h>
|
||||
#include <irrTypes.h>
|
||||
#include "graphics/stkmesh.hpp"
|
||||
|
||||
|
||||
class STKAnimatedMesh : public irr::scene::CAnimatedMeshSceneNode
|
||||
{
|
||||
protected:
|
||||
bool firstTime;
|
||||
std::vector<GLMesh> GLmeshes;
|
||||
core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView;
|
||||
void drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type);
|
||||
public:
|
||||
STKAnimatedMesh(irr::scene::IAnimatedMesh* mesh, irr::scene::ISceneNode* parent,
|
||||
irr::scene::ISceneManager* mgr, irr::s32 id,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "graphics/callbacks.hpp"
|
||||
#include "utils/helpers.hpp"
|
||||
|
||||
static
|
||||
|
||||
GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_texcoord, GLuint attrib_second_texcoord, GLuint attrib_normal, GLuint attrib_tangent, GLuint attrib_bitangent, GLuint attrib_color, size_t stride)
|
||||
{
|
||||
GLuint vao;
|
||||
@@ -58,7 +58,6 @@ GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_t
|
||||
return vao;
|
||||
}
|
||||
|
||||
static
|
||||
GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb)
|
||||
{
|
||||
initGL();
|
||||
@@ -171,7 +170,6 @@ STKMesh::~STKMesh()
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void computeMVP(core::matrix4 &ModelViewProjectionMatrix)
|
||||
{
|
||||
ModelViewProjectionMatrix = irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION);
|
||||
@@ -179,7 +177,6 @@ void computeMVP(core::matrix4 &ModelViewProjectionMatrix)
|
||||
ModelViewProjectionMatrix *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD);
|
||||
}
|
||||
|
||||
static
|
||||
void computeTIMV(core::matrix4 &TransposeInverseModelView)
|
||||
{
|
||||
TransposeInverseModelView = irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW);
|
||||
@@ -668,7 +665,7 @@ static bool isObject(video::E_MATERIAL_TYPE type)
|
||||
return false;
|
||||
}
|
||||
|
||||
static void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type)
|
||||
void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type)
|
||||
{
|
||||
switch (irr_driver->getPhase())
|
||||
{
|
||||
|
||||
@@ -22,6 +22,12 @@ struct GLMesh {
|
||||
size_t Stride;
|
||||
};
|
||||
|
||||
GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_texcoord, GLuint attrib_second_texcoord, GLuint attrib_normal, GLuint attrib_tangent, GLuint attrib_bitangent, GLuint attrib_color, size_t stride);
|
||||
GLMesh allocateMeshBuffer(scene::IMeshBuffer* mb);
|
||||
void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type);
|
||||
void computeMVP(core::matrix4 &ModelViewProjectionMatrix);
|
||||
void computeTIMV(core::matrix4 &TransposeInverseModelView);
|
||||
|
||||
// Pass 1 shader (ie shaders that outputs normals and depth)
|
||||
void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
|
||||
void drawNormalPass(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
|
||||
|
||||
Reference in New Issue
Block a user