STKMesh: Support grass shader
This commit is contained in:
parent
99dad9c304
commit
24443829db
18
data/shaders/grass_pass1.vert
Normal file
18
data/shaders/grass_pass1.vert
Normal file
@ -0,0 +1,18 @@
|
||||
#version 130
|
||||
uniform vec3 windDir;
|
||||
uniform mat4 ModelViewProjectionMatrix;
|
||||
uniform mat4 TransposeInverseModelView;
|
||||
|
||||
in vec3 Position;
|
||||
in vec3 Normal;
|
||||
in vec2 Texcoord;
|
||||
in vec4 Color;
|
||||
noperspective out vec3 nor;
|
||||
out vec2 uv;
|
||||
|
||||
void main()
|
||||
{
|
||||
uv = Texcoord;
|
||||
nor = (TransposeInverseModelView * vec4(Normal, 1.)).xyz;
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(Position + windDir * Color.r, 1.);
|
||||
}
|
14
data/shaders/grass_pass2.vert
Normal file
14
data/shaders/grass_pass2.vert
Normal file
@ -0,0 +1,14 @@
|
||||
#version 130
|
||||
uniform vec3 windDir;
|
||||
uniform mat4 ModelViewProjectionMatrix;
|
||||
|
||||
in vec3 Position;
|
||||
in vec2 Texcoord;
|
||||
in vec4 Color;
|
||||
out vec2 uv;
|
||||
|
||||
void main()
|
||||
{
|
||||
uv = Texcoord;
|
||||
gl_Position = ModelViewProjectionMatrix * vec4(Position + windDir * Color.r, 1.);
|
||||
}
|
@ -117,6 +117,16 @@ public:
|
||||
m_amplitude = amp;
|
||||
}
|
||||
|
||||
float getSpeed() const
|
||||
{
|
||||
return m_speed;
|
||||
}
|
||||
|
||||
float getAmplitude() const
|
||||
{
|
||||
return m_amplitude;
|
||||
}
|
||||
|
||||
private:
|
||||
float m_amplitude, m_speed;
|
||||
};
|
||||
|
@ -113,9 +113,9 @@ void Shaders::loadShaders()
|
||||
m_shaders[ES_SPHERE_MAP] = glslmat(dir + "objectpass.vert", dir + "objectpass_spheremap.frag",
|
||||
m_callbacks[ES_OBJECTPASS], EMT_SOLID);
|
||||
|
||||
m_shaders[ES_GRASS] = glslmat(dir + "grass.vert", dir + "grass.frag",
|
||||
m_shaders[ES_GRASS] = glslmat(dir + "grass.vert", dir + "grass.frag",
|
||||
m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL);
|
||||
m_shaders[ES_GRASS_REF] = glslmat(dir + "grass.vert", dir + "grass.frag",
|
||||
m_shaders[ES_GRASS_REF] = glslmat(dir + "grass.vert", dir + "grass.frag",
|
||||
m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
|
||||
|
||||
m_shaders[ES_BUBBLES] = glslmat(dir + "bubble.vert", dir + "bubble.frag",
|
||||
@ -244,6 +244,8 @@ void Shaders::loadShaders()
|
||||
MeshShader::ObjectRefPass2Shader::init();
|
||||
MeshShader::SphereMapShader::init();
|
||||
MeshShader::SplattingShader::init();
|
||||
MeshShader::GrassPass1Shader::init();
|
||||
MeshShader::GrassPass2Shader::init();
|
||||
}
|
||||
|
||||
Shaders::~Shaders()
|
||||
@ -282,7 +284,6 @@ namespace MeshShader
|
||||
|
||||
void ObjectPass1Shader::init()
|
||||
{
|
||||
initGL();
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/object_pass1.vert").c_str(), file_manager->getAsset("shaders/object_pass1.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
attrib_normal = glGetAttribLocation(Program, "Normal");
|
||||
@ -306,7 +307,6 @@ namespace MeshShader
|
||||
|
||||
void ObjectRefPass1Shader::init()
|
||||
{
|
||||
initGL();
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/objectref_pass1.vert").c_str(), file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
attrib_normal = glGetAttribLocation(Program, "Normal");
|
||||
@ -327,7 +327,6 @@ namespace MeshShader
|
||||
GLuint ObjectPass2Shader::attrib_position;
|
||||
GLuint ObjectPass2Shader::attrib_texcoord;
|
||||
GLuint ObjectPass2Shader::uniform_MVP;
|
||||
GLuint ObjectPass2Shader::uniform_TIMV;
|
||||
GLuint ObjectPass2Shader::uniform_Albedo;
|
||||
GLuint ObjectPass2Shader::uniform_DiffuseMap;
|
||||
GLuint ObjectPass2Shader::uniform_SpecularMap;
|
||||
@ -337,7 +336,6 @@ namespace MeshShader
|
||||
|
||||
void ObjectPass2Shader::init()
|
||||
{
|
||||
initGL();
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/object_pass2.vert").c_str(), file_manager->getAsset("shaders/object_pass2.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
|
||||
@ -366,7 +364,6 @@ namespace MeshShader
|
||||
GLuint ObjectRefPass2Shader::attrib_position;
|
||||
GLuint ObjectRefPass2Shader::attrib_texcoord;
|
||||
GLuint ObjectRefPass2Shader::uniform_MVP;
|
||||
GLuint ObjectRefPass2Shader::uniform_TIMV;
|
||||
GLuint ObjectRefPass2Shader::uniform_Albedo;
|
||||
GLuint ObjectRefPass2Shader::uniform_DiffuseMap;
|
||||
GLuint ObjectRefPass2Shader::uniform_SpecularMap;
|
||||
@ -401,6 +398,79 @@ namespace MeshShader
|
||||
glUniform3f(uniform_ambient, s.r, s.g, s.b);
|
||||
}
|
||||
|
||||
GLuint GrassPass1Shader::Program;
|
||||
GLuint GrassPass1Shader::attrib_position;
|
||||
GLuint GrassPass1Shader::attrib_texcoord;
|
||||
GLuint GrassPass1Shader::attrib_normal;
|
||||
GLuint GrassPass1Shader::attrib_color;
|
||||
GLuint GrassPass1Shader::uniform_MVP;
|
||||
GLuint GrassPass1Shader::uniform_TIMV;
|
||||
GLuint GrassPass1Shader::uniform_tex;
|
||||
GLuint GrassPass1Shader::uniform_windDir;
|
||||
|
||||
void GrassPass1Shader::init()
|
||||
{
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/grass_pass1.vert").c_str(), file_manager->getAsset("shaders/objectref_pass1.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
|
||||
attrib_normal = glGetAttribLocation(Program, "Normal");
|
||||
attrib_color = glGetAttribLocation(Program, "Color");
|
||||
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
|
||||
uniform_TIMV = glGetUniformLocation(Program, "TransposeInverseModelView");
|
||||
uniform_tex = glGetUniformLocation(Program, "tex");
|
||||
uniform_windDir = glGetUniformLocation(Program, "windDir");
|
||||
}
|
||||
|
||||
void GrassPass1Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::vector3df &windDirection, unsigned TU_tex)
|
||||
{
|
||||
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
|
||||
glUniformMatrix4fv(uniform_TIMV, 1, GL_FALSE, TransposeInverseModelView.pointer());
|
||||
glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z);
|
||||
glUniform1i(uniform_tex, TU_tex);
|
||||
}
|
||||
|
||||
GLuint GrassPass2Shader::Program;
|
||||
GLuint GrassPass2Shader::attrib_position;
|
||||
GLuint GrassPass2Shader::attrib_texcoord;
|
||||
GLuint GrassPass2Shader::attrib_color;
|
||||
GLuint GrassPass2Shader::uniform_MVP;
|
||||
GLuint GrassPass2Shader::uniform_Albedo;
|
||||
GLuint GrassPass2Shader::uniform_DiffuseMap;
|
||||
GLuint GrassPass2Shader::uniform_SpecularMap;
|
||||
GLuint GrassPass2Shader::uniform_SSAO;
|
||||
GLuint GrassPass2Shader::uniform_screen;
|
||||
GLuint GrassPass2Shader::uniform_ambient;
|
||||
GLuint GrassPass2Shader::uniform_windDir;
|
||||
|
||||
void GrassPass2Shader::init()
|
||||
{
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/grass_pass2.vert").c_str(), file_manager->getAsset("shaders/objectref_pass2.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
|
||||
attrib_color = glGetAttribLocation(Program, "Color");
|
||||
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
|
||||
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");
|
||||
uniform_windDir = glGetUniformLocation(Program, "windDir");
|
||||
}
|
||||
|
||||
void GrassPass2Shader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO)
|
||||
{
|
||||
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.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);
|
||||
glUniform3f(uniform_windDir, windDirection.X, windDirection.Y, windDirection.Z);
|
||||
}
|
||||
|
||||
GLuint NormalMapShader::Program;
|
||||
GLuint NormalMapShader::attrib_position;
|
||||
GLuint NormalMapShader::attrib_texcoord;
|
||||
@ -412,7 +482,6 @@ namespace MeshShader
|
||||
|
||||
void NormalMapShader::init()
|
||||
{
|
||||
initGL();
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/normalmap.vert").c_str(), file_manager->getAsset("shaders/normalmap.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
|
||||
@ -439,7 +508,6 @@ namespace MeshShader
|
||||
|
||||
void SphereMapShader::init()
|
||||
{
|
||||
initGL();
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/object_pass1.vert").c_str(), file_manager->getAsset("shaders/objectpass_spheremap.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
attrib_normal = glGetAttribLocation(Program, "Normal");
|
||||
@ -473,7 +541,6 @@ namespace MeshShader
|
||||
|
||||
void SplattingShader::init()
|
||||
{
|
||||
initGL();
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/splatting.vert").c_str(), file_manager->getAsset("shaders/splatting.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
|
||||
@ -514,7 +581,6 @@ namespace MeshShader
|
||||
|
||||
void ColorizeShader::init()
|
||||
{
|
||||
initGL();
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/object_pass2.vert").c_str(), file_manager->getAsset("shaders/colorize.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
|
||||
|
@ -53,7 +53,7 @@ class ObjectPass2Shader
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint attrib_position, attrib_texcoord;
|
||||
static GLuint uniform_MVP, uniform_TIMV, uniform_Albedo, uniform_DiffuseMap, uniform_SpecularMap, uniform_SSAO, uniform_screen, uniform_ambient;
|
||||
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);
|
||||
@ -64,12 +64,34 @@ class ObjectRefPass2Shader
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint attrib_position, attrib_texcoord;
|
||||
static GLuint uniform_MVP, uniform_TIMV, uniform_Albedo, uniform_DiffuseMap, uniform_SpecularMap, uniform_SSAO, uniform_screen, uniform_ambient;
|
||||
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 GrassPass1Shader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint attrib_position, attrib_texcoord, attrib_normal, attrib_color;
|
||||
static GLuint uniform_MVP, uniform_TIMV, uniform_tex, uniform_windDir;
|
||||
|
||||
static void init();
|
||||
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::vector3df &windDirection, unsigned TU_tex);
|
||||
};
|
||||
|
||||
class GrassPass2Shader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint attrib_position, attrib_texcoord, attrib_color;
|
||||
static GLuint uniform_MVP, uniform_Albedo, uniform_DiffuseMap, uniform_SpecularMap, uniform_SSAO, uniform_screen, uniform_ambient, uniform_windDir;
|
||||
|
||||
static void init();
|
||||
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector3df &windDirection, unsigned TU_Albedo, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO);
|
||||
};
|
||||
|
||||
class NormalMapShader
|
||||
{
|
||||
public:
|
||||
|
@ -4,9 +4,10 @@
|
||||
#include <IMaterialRenderer.h>
|
||||
#include "config/user_config.hpp"
|
||||
#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, 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)
|
||||
{
|
||||
GLuint vao;
|
||||
glGenVertexArrays(1, &vao);
|
||||
@ -23,6 +24,8 @@ GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_t
|
||||
glEnableVertexAttribArray(attrib_tangent);
|
||||
if ((GLint)attrib_bitangent != -1)
|
||||
glEnableVertexAttribArray(attrib_bitangent);
|
||||
if ((GLint)attrib_color != -1)
|
||||
glEnableVertexAttribArray(attrib_color);
|
||||
glVertexAttribPointer(attrib_position, 3, GL_FLOAT, GL_FALSE, stride, 0);
|
||||
if ((GLint)attrib_texcoord != -1)
|
||||
glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, stride, (GLvoid*) 28);
|
||||
@ -47,6 +50,8 @@ GLuint createVAO(GLuint vbo, GLuint idx, GLuint attrib_position, GLuint attrib_t
|
||||
Log::error("material", "Bitangents not present in VBO");
|
||||
glVertexAttribPointer(attrib_bitangent, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*)48);
|
||||
}
|
||||
if ((GLint)attrib_color != -1)
|
||||
glVertexAttribPointer(attrib_color, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, (GLvoid*)24);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, idx);
|
||||
glBindVertexArray(0);
|
||||
@ -237,6 +242,61 @@ void STKMesh::drawObjectRefPass1(const GLMesh &mesh)
|
||||
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getMainSetup(), false, false);
|
||||
}
|
||||
|
||||
static
|
||||
core::vector3df getWind()
|
||||
{
|
||||
const core::vector3df pos = irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD).getTranslation();
|
||||
const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f;
|
||||
GrassShaderProvider *gsp = (GrassShaderProvider *)irr_driver->getCallback(ES_GRASS);
|
||||
float m_speed = gsp->getSpeed(), m_amplitude = gsp->getAmplitude();
|
||||
|
||||
float strength = (pos.X + pos.Y + pos.Z) * 1.2f + time * m_speed;
|
||||
strength = noise2d(strength / 10.0f) * m_amplitude * 5;
|
||||
// * 5 is to work with the existing amplitude values.
|
||||
|
||||
// Pre-multiply on the cpu
|
||||
return irr_driver->getWind() * strength;
|
||||
}
|
||||
|
||||
void STKMesh::drawGrassPass1(const GLMesh &mesh)
|
||||
{
|
||||
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH), false, false);
|
||||
|
||||
glStencilFunc(GL_ALWAYS, 0, ~0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_BLEND);
|
||||
GLenum ptype = mesh.PrimitiveType;
|
||||
GLenum itype = mesh.IndexType;
|
||||
size_t count = mesh.IndexCount;
|
||||
|
||||
ModelViewProjectionMatrix = irr_driver->getVideoDriver()->getTransform(video::ETS_PROJECTION);
|
||||
ModelViewProjectionMatrix *= irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW);
|
||||
ModelViewProjectionMatrix *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD);
|
||||
TransposeInverseModelView = irr_driver->getVideoDriver()->getTransform(video::ETS_VIEW);
|
||||
TransposeInverseModelView *= irr_driver->getVideoDriver()->getTransform(video::ETS_WORLD);
|
||||
TransposeInverseModelView.makeInverse();
|
||||
TransposeInverseModelView = TransposeInverseModelView.getTransposed();
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, mesh.textures[0]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
glUseProgram(MeshShader::GrassPass1Shader::Program);
|
||||
MeshShader::GrassPass1Shader::setUniforms(ModelViewProjectionMatrix, TransposeInverseModelView, getWind(), 0);
|
||||
|
||||
glBindVertexArray(mesh.vao_first_pass);
|
||||
glDrawElements(ptype, count, itype, 0);
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glStencilFunc(GL_ALWAYS, 1, ~0);
|
||||
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getMainSetup(), false, false);
|
||||
}
|
||||
|
||||
void STKMesh::drawNormalPass(const GLMesh &mesh)
|
||||
{
|
||||
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH), false, false);
|
||||
@ -426,6 +486,48 @@ void STKMesh::drawObjectRefPass2(const GLMesh &mesh)
|
||||
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false);
|
||||
}
|
||||
|
||||
void STKMesh::drawGrassPass2(const GLMesh &mesh)
|
||||
{
|
||||
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);
|
||||
GLenum ptype = mesh.PrimitiveType;
|
||||
GLenum itype = mesh.IndexType;
|
||||
size_t count = mesh.IndexCount;
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, mesh.textures[0]);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP1))->getOpenGLTextureName());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_TMP2))->getOpenGLTextureName());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_SSAO))->getOpenGLTextureName());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
glUseProgram(MeshShader::GrassPass2Shader::Program);
|
||||
MeshShader::GrassPass2Shader::setUniforms(ModelViewProjectionMatrix, getWind(), 0, 1, 2, 3);
|
||||
|
||||
glBindVertexArray(mesh.vao_second_pass);
|
||||
glDrawElements(ptype, count, itype, 0);
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false);
|
||||
}
|
||||
|
||||
void STKMesh::drawSecondPass(const GLMesh &mesh)
|
||||
{
|
||||
irr_driver->getVideoDriver()->setRenderTarget(irr_driver->getRTT(RTT_COLOR), false, false);
|
||||
@ -498,6 +600,8 @@ void STKMesh::draw(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
|
||||
drawNormalPass(mesh);
|
||||
else if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
|
||||
drawObjectRefPass1(mesh);
|
||||
else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF))
|
||||
drawGrassPass1(mesh);
|
||||
else
|
||||
drawFirstPass(mesh);
|
||||
break;
|
||||
@ -508,6 +612,8 @@ void STKMesh::draw(const GLMesh &mesh, video::E_MATERIAL_TYPE type)
|
||||
drawSplatting(mesh);
|
||||
else if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
|
||||
drawObjectRefPass2(mesh);
|
||||
else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF))
|
||||
drawGrassPass2(mesh);
|
||||
else
|
||||
drawSecondPass(mesh);
|
||||
break;
|
||||
@ -541,6 +647,10 @@ static bool isObject(video::E_MATERIAL_TYPE type)
|
||||
return true;
|
||||
if (type == irr_driver->getShader(ES_SPLATTING))
|
||||
return true;
|
||||
if (type == irr_driver->getShader(ES_GRASS))
|
||||
return true;
|
||||
if (type == irr_driver->getShader(ES_GRASS_REF))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -551,41 +661,50 @@ static void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type)
|
||||
if (type == irr_driver->getShader(ES_NORMAL_MAP))
|
||||
{
|
||||
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||
MeshShader::NormalMapShader::attrib_position, MeshShader::NormalMapShader::attrib_texcoord, -1, -1, MeshShader::NormalMapShader::attrib_tangent, MeshShader::NormalMapShader::attrib_bitangent, mesh.Stride);
|
||||
MeshShader::NormalMapShader::attrib_position, MeshShader::NormalMapShader::attrib_texcoord, -1, -1, MeshShader::NormalMapShader::attrib_tangent, MeshShader::NormalMapShader::attrib_bitangent, -1, mesh.Stride);
|
||||
}
|
||||
else if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
|
||||
{
|
||||
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||
MeshShader::ObjectPass1Shader::attrib_position, MeshShader::ObjectRefPass1Shader::attrib_texcoord, -1, MeshShader::ObjectPass1Shader::attrib_normal, -1, -1, mesh.Stride);
|
||||
MeshShader::ObjectPass1Shader::attrib_position, MeshShader::ObjectRefPass1Shader::attrib_texcoord, -1, MeshShader::ObjectPass1Shader::attrib_normal, -1, -1, -1, mesh.Stride);
|
||||
}
|
||||
else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF))
|
||||
{
|
||||
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||
MeshShader::GrassPass1Shader::attrib_position, MeshShader::GrassPass1Shader::attrib_texcoord, -1, MeshShader::GrassPass1Shader::attrib_normal, -1, -1, MeshShader::GrassPass1Shader::attrib_color, mesh.Stride);
|
||||
}
|
||||
else
|
||||
{
|
||||
mesh.vao_first_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||
MeshShader::ObjectPass1Shader::attrib_position, -1, -1, MeshShader::ObjectPass1Shader::attrib_normal, -1, -1, mesh.Stride);
|
||||
MeshShader::ObjectPass1Shader::attrib_position, -1, -1, MeshShader::ObjectPass1Shader::attrib_normal, -1, -1, -1, mesh.Stride);
|
||||
}
|
||||
|
||||
if (type == irr_driver->getShader(ES_SPHERE_MAP))
|
||||
{
|
||||
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||
MeshShader::SphereMapShader::attrib_position, -1, -1, MeshShader::SphereMapShader::attrib_normal, -1, -1, mesh.Stride);
|
||||
MeshShader::SphereMapShader::attrib_position, -1, -1, MeshShader::SphereMapShader::attrib_normal, -1, -1, -1, mesh.Stride);
|
||||
}
|
||||
else if (type == irr_driver->getShader(ES_SPLATTING))
|
||||
{
|
||||
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||
MeshShader::SplattingShader::attrib_position, MeshShader::SplattingShader::attrib_texcoord, MeshShader::SplattingShader::attrib_second_texcoord, -1, -1, -1, mesh.Stride);
|
||||
MeshShader::SplattingShader::attrib_position, MeshShader::SplattingShader::attrib_texcoord, MeshShader::SplattingShader::attrib_second_texcoord, -1, -1, -1, -1, mesh.Stride);
|
||||
}
|
||||
else if (type == irr_driver->getShader(ES_OBJECTPASS_REF))
|
||||
{
|
||||
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||
MeshShader::ObjectRefPass2Shader::attrib_position, MeshShader::ObjectRefPass2Shader::attrib_texcoord, -1, -1, -1, -1, mesh.Stride);
|
||||
|
||||
MeshShader::ObjectRefPass2Shader::attrib_position, MeshShader::ObjectRefPass2Shader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
|
||||
}
|
||||
else if (type == irr_driver->getShader(ES_GRASS) || type == irr_driver->getShader(ES_GRASS_REF))
|
||||
{
|
||||
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||
MeshShader::GrassPass2Shader::attrib_position, MeshShader::GrassPass2Shader::attrib_texcoord, -1, -1, -1, -1, MeshShader::GrassPass2Shader::attrib_color, mesh.Stride);
|
||||
}
|
||||
else
|
||||
{
|
||||
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
|
||||
MeshShader::ObjectPass2Shader::attrib_position, MeshShader::ObjectPass2Shader::attrib_texcoord, -1, -1, -1, -1, mesh.Stride);
|
||||
MeshShader::ObjectPass2Shader::attrib_position, MeshShader::ObjectPass2Shader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
|
||||
}
|
||||
mesh.vao_glow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ColorizeShader::attrib_position, -1, -1, -1, -1, -1, mesh.Stride);
|
||||
mesh.vao_glow_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer, MeshShader::ColorizeShader::attrib_position, -1, -1, -1, -1, -1, -1, mesh.Stride);
|
||||
}
|
||||
|
||||
void STKMesh::render()
|
||||
|
@ -32,12 +32,14 @@ protected:
|
||||
void drawFirstPass(const GLMesh &mesh);
|
||||
void drawNormalPass(const GLMesh &mesh);
|
||||
void drawObjectRefPass1(const GLMesh &mesh);
|
||||
void drawGrassPass1(const GLMesh &mesh);
|
||||
|
||||
// Pass 2 shader (ie shaders that outputs final color)
|
||||
void drawSphereMap(const GLMesh &mesh);
|
||||
void drawSplatting(const GLMesh &mesh);
|
||||
void drawSecondPass(const GLMesh &mesh);
|
||||
void drawObjectRefPass2(const GLMesh &mesh);
|
||||
void STKMesh::drawGrassPass2(const GLMesh &mesh);
|
||||
|
||||
// Pass 3 shader (glow)
|
||||
void drawGlow(const GLMesh &mesh, float r, float g, float b);
|
||||
|
Loading…
Reference in New Issue
Block a user