Rework moving textures support.

This commit is contained in:
Vincent Lejeune 2014-02-27 01:13:23 +01:00
parent 7532ea1768
commit 9941b18d7f
11 changed files with 55 additions and 167 deletions

View File

@ -1,22 +0,0 @@
#version 330
uniform sampler2D Albedo;
uniform sampler2D DiffuseMap;
uniform sampler2D SpecularMap;
uniform sampler2D SSAO;
uniform vec2 screen;
uniform vec3 ambient;
in vec2 uv;
out vec4 FragColor;
void main(void)
{
vec2 tc = gl_FragCoord.xy / screen;
vec4 color = texture(Albedo, uv);
vec3 DiffuseComponent = texture(DiffuseMap, tc).xyz;
vec3 SpecularComponent = texture(SpecularMap, tc).xyz;
float ao = texture(SSAO, tc).x;
vec3 LightFactor = ao * ambient + DiffuseComponent + SpecularComponent * (1. - color.a);
FragColor = vec4(color.xyz * LightFactor * (0.4 + ao*0.6), 1.);
//FragColor = vec4(color.xyz * LightFactor, 1.);
}

View File

@ -1,16 +0,0 @@
#version 330
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TextureMatrix;
in vec3 Position;
in vec2 Texcoord;
in vec2 SecondTexcoord;
out vec2 uv;
out vec2 uv_bis;
void main(void)
{
uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy;
uv_bis = SecondTexcoord;
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
}

View File

@ -1,5 +1,10 @@
#version 330
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TextureMatrix =
mat4(1., 0., 0., 0.,
0., 1., 0., 0.,
0., 0., 1., 0.,
0., 0., 0., 1.);
in vec3 Position;
in vec2 Texcoord;
@ -9,7 +14,7 @@ out vec2 uv_bis;
void main(void)
{
uv = Texcoord;
uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy;
uv_bis = SecondTexcoord;
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
}

View File

@ -1,6 +1,11 @@
#version 330
uniform mat4 ModelViewProjectionMatrix;
uniform mat4 TransposeInverseModelView;
uniform mat4 TextureMatrix =
mat4(1., 0., 0., 0.,
0., 1., 0., 0.,
0., 0., 1., 0.,
0., 0., 0., 1.);
in vec3 Position;
in vec3 Normal;
@ -10,7 +15,7 @@ out vec2 uv;
void main(void)
{
uv = Texcoord;
uv = (TextureMatrix * vec4(Texcoord, 1., 1.)).xy;
gl_Position = ModelViewProjectionMatrix * vec4(Position, 1.);
nor = (TransposeInverseModelView * vec4(Normal, 0.)).xyz;
}

View File

@ -242,7 +242,6 @@ void Shaders::loadShaders()
MeshShader::ObjectPass1Shader::init();
MeshShader::ObjectRefPass1Shader::init();
MeshShader::ObjectPass2Shader::init();
MeshShader::MovingTextureShader::init();
MeshShader::DetailledObjectPass2Shader::init();
MeshShader::ObjectRimLimitShader::init();
MeshShader::UntexturedObjectShader::init();
@ -325,6 +324,7 @@ namespace MeshShader
GLuint ObjectRefPass1Shader::attrib_texcoord;
GLuint ObjectRefPass1Shader::uniform_MVP;
GLuint ObjectRefPass1Shader::uniform_TIMV;
GLuint ObjectRefPass1Shader::uniform_TM;
GLuint ObjectRefPass1Shader::uniform_tex;
void ObjectRefPass1Shader::init()
@ -335,12 +335,14 @@ namespace MeshShader
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView");
uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
uniform_tex = glGetUniformLocation(Program, "tex");
}
void ObjectRefPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_tex)
void ObjectRefPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix, unsigned TU_tex)
{
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer());
glUniform1i(uniform_tex, TU_tex);
}
@ -349,6 +351,7 @@ namespace MeshShader
GLuint ObjectPass2Shader::attrib_position;
GLuint ObjectPass2Shader::attrib_texcoord;
GLuint ObjectPass2Shader::uniform_MVP;
GLuint ObjectPass2Shader::uniform_TM;
GLuint ObjectPass2Shader::uniform_Albedo;
GLuint ObjectPass2Shader::uniform_DiffuseMap;
GLuint ObjectPass2Shader::uniform_SpecularMap;
@ -362,6 +365,7 @@ namespace MeshShader
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
uniform_Albedo = glGetUniformLocation(Program, "Albedo");
uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
@ -370,9 +374,10 @@ namespace MeshShader
uniform_ambient = glGetUniformLocation(Program, "ambient");
}
void ObjectPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO)
void ObjectPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO)
{
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
glUniform1i(uniform_Albedo, TU_Albedo);
glUniform1i(uniform_DiffuseMap, TU_DiffuseMap);
glUniform1i(uniform_SpecularMap, TU_SpecularMap);
@ -382,46 +387,6 @@ namespace MeshShader
glUniform3f(uniform_ambient, s.r, s.g, s.b);
}
GLuint MovingTextureShader::Program;
GLuint MovingTextureShader::attrib_position;
GLuint MovingTextureShader::attrib_texcoord;
GLuint MovingTextureShader::uniform_MVP;
GLuint MovingTextureShader::uniform_TM;
GLuint MovingTextureShader::uniform_Albedo;
GLuint MovingTextureShader::uniform_DiffuseMap;
GLuint MovingTextureShader::uniform_SpecularMap;
GLuint MovingTextureShader::uniform_SSAO;
GLuint MovingTextureShader::uniform_screen;
GLuint MovingTextureShader::uniform_ambient;
void MovingTextureShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/movingtexture.vert").c_str(), file_manager->getAsset("shaders/movingtexture.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
uniform_Albedo = glGetUniformLocation(Program, "Albedo");
uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
uniform_SSAO = glGetUniformLocation(Program, "SSAO");
uniform_screen = glGetUniformLocation(Program, "screen");
uniform_ambient = glGetUniformLocation(Program, "ambient");
}
void MovingTextureShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO)
{
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
glUniform1i(uniform_Albedo, TU_Albedo);
glUniform1i(uniform_DiffuseMap, TU_DiffuseMap);
glUniform1i(uniform_SpecularMap, TU_SpecularMap);
glUniform1i(uniform_SSAO, TU_SSAO);
glUniform2f(uniform_screen, UserConfigParams::m_width, UserConfigParams::m_height);
const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
glUniform3f(uniform_ambient, s.r, s.g, s.b);
}
GLuint DetailledObjectPass2Shader::Program;
GLuint DetailledObjectPass2Shader::attrib_position;
GLuint DetailledObjectPass2Shader::attrib_texcoord;
@ -566,6 +531,7 @@ namespace MeshShader
GLuint ObjectRefPass2Shader::attrib_position;
GLuint ObjectRefPass2Shader::attrib_texcoord;
GLuint ObjectRefPass2Shader::uniform_MVP;
GLuint ObjectRefPass2Shader::uniform_TM;
GLuint ObjectRefPass2Shader::uniform_Albedo;
GLuint ObjectRefPass2Shader::uniform_DiffuseMap;
GLuint ObjectRefPass2Shader::uniform_SpecularMap;
@ -580,6 +546,7 @@ namespace MeshShader
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
uniform_TM = glGetUniformLocation(Program, "TextureMatrix");
uniform_Albedo = glGetUniformLocation(Program, "Albedo");
uniform_DiffuseMap = glGetUniformLocation(Program, "DiffuseMap");
uniform_SpecularMap = glGetUniformLocation(Program, "SpecularMap");
@ -588,9 +555,10 @@ namespace MeshShader
uniform_ambient = glGetUniformLocation(Program, "ambient");
}
void ObjectRefPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO)
void ObjectRefPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO)
{
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glUniformMatrix4fv(uniform_TM, 1, GL_FALSE, TextureMatrix.pointer());
glUniform1i(uniform_Albedo, TU_Albedo);
glUniform1i(uniform_DiffuseMap, TU_DiffuseMap);
glUniform1i(uniform_SpecularMap, TU_SpecularMap);

View File

@ -42,10 +42,10 @@ class ObjectRefPass1Shader
public:
static GLuint Program;
static GLuint attrib_position, attrib_normal, attrib_texcoord;
static GLuint uniform_MVP, uniform_TIMV, uniform_tex;
static GLuint uniform_MVP, uniform_TM, uniform_TIMV, uniform_tex;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, unsigned TU_texture);
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix, unsigned TU_texture);
};
class ObjectPass2Shader
@ -53,20 +53,9 @@ class ObjectPass2Shader
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_MVP, uniform_Albedo, uniform_DiffuseMap, uniform_SpecularMap, uniform_SSAO, uniform_screen, uniform_ambient;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO);
};
class MovingTextureShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_MVP, uniform_TM, uniform_Albedo, uniform_DiffuseMap, uniform_SpecularMap, uniform_SSAO, uniform_screen, uniform_ambient;
static void init();
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO);
};
@ -119,10 +108,10 @@ class ObjectRefPass2Shader
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_MVP, uniform_Albedo, uniform_DiffuseMap, uniform_SpecularMap, uniform_SSAO, uniform_screen, uniform_ambient;
static GLuint uniform_MVP, uniform_TM, uniform_Albedo, uniform_DiffuseMap, uniform_SpecularMap, uniform_SSAO, uniform_screen, uniform_ambient;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO);
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO);
};
class GrassPass1Shader

View File

@ -33,9 +33,9 @@ void STKAnimatedMesh::drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE
computeMVP(ModelViewProjectionMatrix);
if (World::getWorld()->getTrack()->isFogEnabled())
drawTransparentFogObject(mesh, ModelViewProjectionMatrix, core::matrix4::EM4CONST_IDENTITY);
drawTransparentFogObject(mesh, ModelViewProjectionMatrix, TextureMatrix);
else
drawTransparentObject(mesh, ModelViewProjectionMatrix, core::matrix4::EM4CONST_IDENTITY);
drawTransparentObject(mesh, ModelViewProjectionMatrix, TextureMatrix);
return;
}
@ -50,7 +50,7 @@ void STKAnimatedMesh::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
computeTIMV(TransposeInverseModelView);
if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
drawObjectRefPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
drawObjectRefPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, TextureMatrix);
else
drawObjectPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
break;
@ -58,7 +58,7 @@ void STKAnimatedMesh::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
case SOLID_LIT_PASS:
{
if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
drawObjectRefPass2(mesh, ModelViewProjectionMatrix);
drawObjectRefPass2(mesh, ModelViewProjectionMatrix, TextureMatrix);
else if (type == irr_driver->getShader(ES_OBJECTPASS_RIMLIT))
drawObjectRimLimit(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
else if (type == irr_driver->getShader(ES_OBJECT_UNLIT))
@ -66,7 +66,7 @@ void STKAnimatedMesh::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
else if (mesh.textures[1])
drawDetailledObjectPass2(mesh, ModelViewProjectionMatrix);
else
drawObjectPass2(mesh, ModelViewProjectionMatrix);
drawObjectPass2(mesh, ModelViewProjectionMatrix, TextureMatrix);
break;
}
default:
@ -125,6 +125,7 @@ void STKAnimatedMesh::render()
// render original meshes
for (u32 i = 0; i<m->getMeshBufferCount(); ++i)
{
TextureMatrix = getMaterial(i).getTextureMatrix(0);
video::IMaterialRenderer* rnd = driver->getMaterialRenderer(Materials[i].MaterialType);
bool transparent = (rnd && rnd->isTransparent());
@ -141,7 +142,7 @@ void STKAnimatedMesh::render()
if (isObject(material.MaterialType))
{
irr_driver->IncreaseObjectCount();
initvaostate(GLmeshes[i], material.MaterialType, false);
initvaostate(GLmeshes[i], material.MaterialType);
if (irr_driver->getPhase() == SOLID_NORMAL_AND_DEPTH_PASS)
{
glBindVertexArray(0);

View File

@ -12,7 +12,7 @@ class STKAnimatedMesh : public irr::scene::CAnimatedMeshSceneNode
protected:
bool firstTime;
std::vector<GLMesh> GLmeshes;
core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView;
core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView, TextureMatrix;
void drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type);
void drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type);
void drawShadow(const GLMesh &mesh);

View File

@ -173,7 +173,7 @@ void drawObjectPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjecti
glDrawElements(ptype, count, itype, 0);
}
void drawObjectRefPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView)
void drawObjectRefPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
@ -183,7 +183,7 @@ void drawObjectRefPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProje
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
glUseProgram(MeshShader::ObjectRefPass1Shader::Program);
MeshShader::ObjectRefPass1Shader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, 0);
MeshShader::ObjectRefPass1Shader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, TextureMatrix, 0);
glBindVertexArray(mesh.vao_first_pass);
glDrawElements(ptype, count, itype, 0);
@ -322,7 +322,7 @@ void drawSplatting(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionM
glDrawElements(ptype, count, itype, 0);
}
void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)
void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
@ -349,7 +349,7 @@ void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjec
}
glUseProgram(MeshShader::ObjectRefPass2Shader::Program);
MeshShader::ObjectRefPass2Shader::setUniforms(ModelViewProjectionMatrix, 0, 1, 2, 3);
MeshShader::ObjectRefPass2Shader::setUniforms(ModelViewProjectionMatrix, TextureMatrix, 0, 1, 2, 3);
glBindVertexArray(mesh.vao_second_pass);
glDrawElements(ptype, count, itype, 0);
@ -507,7 +507,7 @@ void drawDetailledObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelView
glDrawElements(ptype, count, itype, 0);
}
void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix)
void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
@ -535,46 +535,12 @@ void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectio
}
glUseProgram(MeshShader::ObjectPass2Shader::Program);
MeshShader::ObjectPass2Shader::setUniforms(ModelViewProjectionMatrix, 0, 1, 2, 3);
MeshShader::ObjectPass2Shader::setUniforms(ModelViewProjectionMatrix, TextureMatrix, 0, 1, 2, 3);
glBindVertexArray(mesh.vao_second_pass);
glDrawElements(ptype, count, itype, 0);
}
void drawMovingTexture(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix)
{
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
setTexture(0, mesh.textures[0], GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
if (irr_driver->getLightViz())
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
else
{
GLint swizzleMask[] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
setTexture(1, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST);
setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST);
setTexture(3, getTextureGLuint(irr_driver->getRTT(RTT_SSAO)), GL_NEAREST, GL_NEAREST);
if (!UserConfigParams::m_ssao)
{
GLint swizzleMask[] = { GL_ONE, GL_ONE, GL_ONE, GL_ONE };
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
}
glUseProgram(MeshShader::MovingTextureShader::Program);
MeshShader::MovingTextureShader::setUniforms(ModelViewProjectionMatrix, TextureMatrix, 0, 1, 2, 3);
glBindVertexArray(mesh.vao_second_pass);
glDrawElements(ptype, count, itype, 0);
}
void drawTransparentObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix)
{
GLenum ptype = mesh.PrimitiveType;
@ -668,7 +634,7 @@ bool isObject(video::E_MATERIAL_TYPE type)
return false;
}
void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type, bool MovingTexture)
void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type)
{
switch (irr_driver->getPhase())
{
@ -739,11 +705,6 @@ void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type, bool MovingTexture)
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::UntexturedObjectShader::attrib_position, -1, -1, -1, -1, -1, MeshShader::UntexturedObjectShader::attrib_color, mesh.Stride);
}
else if (MovingTexture)
{
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::MovingTextureShader::attrib_position, MeshShader::MovingTextureShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
}
else
{
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,

View File

@ -25,7 +25,7 @@ struct GLMesh {
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, bool moving_texture);
void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type);
void computeMVP(core::matrix4 &ModelViewProjectionMatrix);
void computeTIMV(core::matrix4 &TransposeInverseModelView);
bool isObject(video::E_MATERIAL_TYPE type);
@ -33,15 +33,14 @@ bool isObject(video::E_MATERIAL_TYPE type);
// 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);
void drawObjectRefPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
void drawObjectRefPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix);
void drawGrassPass1(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, core::vector3df windDir);
// Pass 2 shader (ie shaders that outputs final color)
void drawDetailledObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
void drawMovingTexture(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
void drawObjectPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TextureMatrix);
void drawSphereMap(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView);
void drawSplatting(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);
void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, core::vector3df windDir);

View File

@ -174,7 +174,7 @@ void STKMeshSceneNode::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type
if (type == irr_driver->getShader(ES_NORMAL_MAP))
drawNormalPass(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
else if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
drawObjectRefPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView);
drawObjectRefPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, TextureMatrix);
else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF))
drawGrassPass1(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, windDir);
else
@ -188,7 +188,7 @@ void STKMeshSceneNode::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type
else if (type == irr_driver->getShader(ES_SPLATTING))
drawSplatting(mesh, ModelViewProjectionMatrix);
else if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
drawObjectRefPass2(mesh, ModelViewProjectionMatrix);
drawObjectRefPass2(mesh, ModelViewProjectionMatrix, TextureMatrix);
else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF))
drawGrassPass2(mesh, ModelViewProjectionMatrix, windDir);
else if (type == irr_driver->getShader(ES_OBJECTPASS_RIMLIT))
@ -199,10 +199,8 @@ void STKMeshSceneNode::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type
drawDetailledObjectPass2(mesh, ModelViewProjectionMatrix);
else if (!mesh.textures[0])
drawUntexturedObject(mesh, ModelViewProjectionMatrix);
else if (!TextureMatrix.isIdentity())
drawMovingTexture(mesh, ModelViewProjectionMatrix, TextureMatrix);
else
drawObjectPass2(mesh, ModelViewProjectionMatrix);
drawObjectPass2(mesh, ModelViewProjectionMatrix, TextureMatrix);
break;
}
default:
@ -242,7 +240,7 @@ void STKMeshSceneNode::render()
continue;
if (irr_driver->getPhase() == DISPLACEMENT_PASS)
{
initvaostate(GLmeshes[i], material.MaterialType, false);
initvaostate(GLmeshes[i], material.MaterialType);
drawDisplace(GLmeshes[i]);
continue;
}
@ -258,18 +256,18 @@ void STKMeshSceneNode::render()
// and solid only in solid pass
if (irr_driver->getPhase() == GLOW_PASS)
{
initvaostate(GLmeshes[i], material.MaterialType, TextureMatrix.isIdentity());
initvaostate(GLmeshes[i], material.MaterialType);
drawGlow(GLmeshes[i]);
}
else if (irr_driver->getPhase() == SHADOW_PASS)
{
initvaostate(GLmeshes[i], material.MaterialType, TextureMatrix.isIdentity());
initvaostate(GLmeshes[i], material.MaterialType);
drawShadow(GLmeshes[i], material.MaterialType);
}
else
{
irr_driver->IncreaseObjectCount();
initvaostate(GLmeshes[i], material.MaterialType, TextureMatrix.isIdentity());
initvaostate(GLmeshes[i], material.MaterialType);
if (transparent)
drawTransparent(GLmeshes[i], material.MaterialType);
else