Merge branch 'master' of github.com:supertuxkart/stk-code

This commit is contained in:
hiker 2014-03-05 08:42:39 +11:00
commit 02fa3ceed0
10 changed files with 146 additions and 61 deletions

View File

@ -1,19 +1,32 @@
uniform sampler2D tex;
uniform sampler2D Albedo;
uniform sampler2D DiffuseMap;
uniform sampler2D SpecularMap;
uniform sampler2D SSAO;
uniform vec2 screen;
uniform vec3 ambient;
uniform sampler2D caustictex;
uniform vec2 dir;
uniform vec2 dir2;
#if __VERSION__ >= 130
in vec2 uv;
out vec4 FragColor;
#else
varying vec2 uv;
#define FragColor gl_FragColor
#endif
void main()
{
vec2 tc = gl_TexCoord[0].xy;
vec2 tc = gl_FragCoord.xy / screen;
vec3 DiffuseComponent = texture(DiffuseMap, tc).xyz;
vec3 SpecularComponent = texture(SpecularMap, tc).xyz;
vec4 color = texture(Albedo, uv);
float ao = texture(SSAO, tc).x;
vec3 col = texture(tex, tc).xyz;
float caustic = texture(caustictex, tc + dir).x;
float caustic2 = texture(caustictex, (tc.yx + dir2 * vec2(-0.6, 0.3)) * vec2(0.6)).x;
float caustic = texture(caustictex, uv + dir).x;
float caustic2 = texture(caustictex, (uv.yx + dir2 * vec2(-0.6, 0.3)) * vec2(0.6)).x;
col += caustic * caustic2 * 10.0;
FragColor = vec4(col, 1.0);
vec3 LightFactor = ao * ambient + DiffuseComponent + SpecularComponent + caustic * caustic2 * 10;
FragColor = vec4(color.xyz * LightFactor, 1.);
}

View File

@ -541,43 +541,6 @@ void ShadowGenProvider::OnSetConstants(IMaterialRendererServices *srv, int)
//-------------------------------------
void CausticsProvider::OnSetConstants(IMaterialRendererServices *srv, int)
{
const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f;
const float speed = World::getWorld()->getTrack()->getCausticsSpeed();
float strength = time;
strength = fabsf(noise2d(strength / 10.0f)) * 0.006f + 0.001f;
vector3df wind = irr_driver->getWind() * strength * speed;
m_dir[0] += wind.X;
m_dir[1] += wind.Z;
strength = time * 0.56f + sinf(time);
strength = fabsf(noise2d(0.0, strength / 6.0f)) * 0.0095f + 0.001f;
wind = irr_driver->getWind() * strength * speed;
wind.rotateXZBy(cosf(time));
m_dir2[0] += wind.X;
m_dir2[1] += wind.Z;
srv->setVertexShaderConstant("dir", m_dir, 2);
srv->setVertexShaderConstant("dir2", m_dir2, 2);
if (!firstdone)
{
int tex = 0;
srv->setVertexShaderConstant("tex", &tex, 1);
tex = 1;
srv->setVertexShaderConstant("caustictex", &tex, 1);
firstdone = true;
}
}
//-------------------------------------
void DisplaceProvider::OnSetConstants(IMaterialRendererServices *srv, int)
{
core::matrix4 ProjectionMatrix = srv->getVideoDriver()->getTransform(ETS_PROJECTION);

View File

@ -542,19 +542,6 @@ public:
//
class CausticsProvider: public CallBase
{
public:
CausticsProvider() { m_dir[0] = m_dir[1] = m_dir2[0] = m_dir2[1] = 0; }
virtual void OnSetConstants(video::IMaterialRendererServices *srv, int);
private:
float m_dir[2], m_dir2[2];
};
//
class DisplaceProvider: public CallBase
{
public:

View File

@ -1007,7 +1007,7 @@ void IrrDriver::renderDisplacement(video::SOverrideMaterial &overridemat,
glDisable(GL_ALPHA_TEST);
glDepthMask(GL_FALSE);
glDisable(GL_BLEND);
glClear(GL_STENCIL_BITS);
glClear(GL_STENCIL_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS, 1, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

View File

@ -49,7 +49,6 @@ Shaders::Shaders()
m_callbacks[ES_COLLAPSE] = new CollapseProvider();
m_callbacks[ES_MULTIPLY_ADD] = new MultiplyProvider();
m_callbacks[ES_SHADOWGEN] = new ShadowGenProvider();
m_callbacks[ES_CAUSTICS] = new CausticsProvider();
m_callbacks[ES_DISPLACE] = new DisplaceProvider();
for(s32 i=0 ; i < ES_COUNT ; i++)
@ -183,7 +182,7 @@ void Shaders::loadShaders()
m_callbacks[ES_SHADOWGEN], EMT_SOLID);
m_shaders[ES_CAUSTICS] = glslmat(dir + "pass.vert", dir + "pass.frag",
m_callbacks[ES_CAUSTICS], EMT_TRANSPARENT_ALPHA_CHANNEL);
m_callbacks[ES_CAUSTICS], EMT_SOLID);
m_shaders[ES_DISPLACE] = glsl(dir + "pass.vert", dir + "pass.frag",
m_callbacks[ES_DISPLACE]);
@ -249,6 +248,7 @@ void Shaders::loadShaders()
MeshShader::SplattingShader::init();
MeshShader::GrassPass1Shader::init();
MeshShader::GrassPass2Shader::init();
MeshShader::CausticsShader::init();
MeshShader::BubbleShader::init();
MeshShader::TransparentShader::init();
MeshShader::TransparentFogShader::init();
@ -746,6 +746,52 @@ namespace MeshShader
glUniform3f(uniform_ambient, s.r, s.g, s.b);
}
GLuint CausticsShader::Program;
GLuint CausticsShader::attrib_position;
GLuint CausticsShader::attrib_texcoord;
GLuint CausticsShader::uniform_MVP;
GLuint CausticsShader::uniform_dir;
GLuint CausticsShader::uniform_dir2;
GLuint CausticsShader::uniform_Albedo;
GLuint CausticsShader::uniform_caustictex;
GLuint CausticsShader::uniform_DiffuseMap;
GLuint CausticsShader::uniform_SpecularMap;
GLuint CausticsShader::uniform_SSAO;
GLuint CausticsShader::uniform_screen;
GLuint CausticsShader::uniform_ambient;
void CausticsShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/object_pass2.vert").c_str(), file_manager->getAsset("shaders/caustics.frag").c_str());
attrib_position = glGetAttribLocation(Program, "Position");
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
uniform_MVP = glGetUniformLocation(Program, "ModelViewProjectionMatrix");
uniform_dir = glGetUniformLocation(Program, "dir");
uniform_dir2 = glGetUniformLocation(Program, "dir2");
uniform_Albedo = glGetUniformLocation(Program, "Albedo");
uniform_caustictex = glGetUniformLocation(Program, "caustictex");
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 CausticsShader::setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_albedo, unsigned TU_DiffuseMap, unsigned TU_Specmap, unsigned TU_SSAO, unsigned TU_caustictex)
{
glUniformMatrix4fv(uniform_MVP, 1, GL_FALSE, ModelViewProjectionMatrix.pointer());
glUniform2f(uniform_dir, dir.X, dir.Y);
glUniform2f(uniform_dir2, dir2.X, dir2.Y);
glUniform1i(uniform_Albedo, TU_albedo);
glUniform1i(uniform_caustictex, TU_caustictex);
glUniform2f(uniform_screen, screen.X, screen.Y);
glUniform1i(uniform_DiffuseMap, TU_DiffuseMap);
glUniform1i(uniform_SpecularMap, TU_Specmap);
glUniform1i(uniform_SSAO, TU_SSAO);
const video::SColorf s = irr_driver->getSceneManager()->getAmbientLight();
glUniform3f(uniform_ambient, s.r, s.g, s.b);
}
GLuint BubbleShader::Program;
GLuint BubbleShader::attrib_position;
GLuint BubbleShader::attrib_texcoord;

View File

@ -169,6 +169,17 @@ public:
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, unsigned TU_tex_layout, unsigned TU_tex_detail0, unsigned TU_tex_detail1, unsigned TU_tex_detail2, unsigned TU_tex_detail3, unsigned TU_DiffuseMap, unsigned TU_SpecularMap, unsigned TU_SSAO);
};
class CausticsShader
{
public:
static GLuint Program;
static GLuint attrib_position, attrib_texcoord;
static GLuint uniform_MVP, uniform_dir, uniform_dir2, uniform_Albedo, uniform_DiffuseMap, uniform_SpecularMap, uniform_SSAO, uniform_screen, uniform_ambient, uniform_caustictex;
static void init();
static void setUniforms(const core::matrix4 &ModelViewProjectionMatrix, const core::vector2df &dir, const core::vector2df &dir2, const core::vector2df &screen, unsigned TU_albedo, unsigned TU_DiffuseMap, unsigned TU_Specmap, unsigned TU_SSAO, unsigned TU_caustictex);
};
class BubbleShader
{
public:

View File

@ -355,6 +355,41 @@ void drawObjectRefPass2(const GLMesh &mesh, const core::matrix4 &ModelViewProjec
glDrawElements(ptype, count, itype, 0);
}
void drawCaustics(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, core::vector2df dir, core::vector2df dir2)
{
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->getTexture(file_manager->getAsset("textures/caustics.png").c_str())), GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, true);
setTexture(2, getTextureGLuint(irr_driver->getRTT(RTT_TMP1)), GL_NEAREST, GL_NEAREST);
setTexture(3, getTextureGLuint(irr_driver->getRTT(RTT_TMP2)), GL_NEAREST, GL_NEAREST);
setTexture(4, 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::CausticsShader::Program);
MeshShader::CausticsShader::setUniforms(ModelViewProjectionMatrix, dir, dir2, core::vector2df(UserConfigParams::m_width, UserConfigParams::m_height), 0, 2, 3, 4, 1);
glBindVertexArray(mesh.vao_second_pass);
glDrawElements(ptype, count, itype, 0);
}
void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, core::vector3df windDir)
{
GLenum ptype = mesh.PrimitiveType;
@ -625,6 +660,8 @@ bool isObject(video::E_MATERIAL_TYPE type)
return true;
if (type == irr_driver->getShader(ES_OBJECT_UNLIT))
return true;
if (type == irr_driver->getShader(ES_CAUSTICS))
return true;
if (type == video::EMT_TRANSPARENT_ALPHA_CHANNEL)
return true;
if (type == video::EMT_ONETEXTURE_BLEND)
@ -695,6 +732,11 @@ void initvaostate(GLMesh &mesh, video::E_MATERIAL_TYPE type)
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::ObjectUnlitShader::attrib_position, MeshShader::ObjectUnlitShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
}
else if (type == irr_driver->getShader(ES_CAUSTICS))
{
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,
MeshShader::CausticsShader::attrib_position, MeshShader::CausticsShader::attrib_texcoord, -1, -1, -1, -1, -1, mesh.Stride);
}
else if (mesh.textures[1])
{
mesh.vao_second_pass = createVAO(mesh.vertex_buffer, mesh.index_buffer,

View File

@ -44,6 +44,7 @@ void drawUntexturedObject(const GLMesh &mesh, const core::matrix4 &ModelViewProj
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 drawCaustics(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, core::vector2df dir, core::vector2df dir2);
void drawGrassPass2(const GLMesh &mesh, const core::matrix4 & ModelViewProjectionMatrix, core::vector3df windDir);
void drawObjectRimLimit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix, const core::matrix4 &TransposeInverseModelView, const core::matrix4 &TextureMatrix);
void drawObjectUnlit(const GLMesh &mesh, const core::matrix4 &ModelViewProjectionMatrix);

View File

@ -210,6 +210,27 @@ void STKMeshSceneNode::drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type
drawObjectRimLimit(mesh, ModelViewProjectionMatrix, TransposeInverseModelView, TextureMatrix);
else if (type == irr_driver->getShader(ES_OBJECT_UNLIT))
drawObjectUnlit(mesh, ModelViewProjectionMatrix);
else if (type == irr_driver->getShader(ES_CAUSTICS))
{
const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f;
const float speed = World::getWorld()->getTrack()->getCausticsSpeed();
float strength = time;
strength = fabsf(noise2d(strength / 10.0f)) * 0.006f + 0.001f;
vector3df wind = irr_driver->getWind() * strength * speed;
caustic_dir.X += wind.X;
caustic_dir.Y += wind.Z;
strength = time * 0.56f + sinf(time);
strength = fabsf(noise2d(0.0, strength / 6.0f)) * 0.0095f + 0.001f;
wind = irr_driver->getWind() * strength * speed;
wind.rotateXZBy(cosf(time));
caustic_dir2.X += wind.X;
caustic_dir2.Y += wind.Z;
drawCaustics(mesh, ModelViewProjectionMatrix, caustic_dir, caustic_dir2);
}
else if (mesh.textures[1] && type != irr_driver->getShader(ES_NORMAL_MAP))
drawDetailledObjectPass2(mesh, ModelViewProjectionMatrix);
else if (!mesh.textures[0])

View File

@ -9,6 +9,7 @@ protected:
std::vector<GLMesh> GLmeshes;
core::matrix4 ModelViewProjectionMatrix, TransposeInverseModelView, TextureMatrix;
core::vector3df windDir;
core::vector2df caustic_dir, caustic_dir2;
void drawSolid(const GLMesh &mesh, video::E_MATERIAL_TYPE type);
void drawTransparent(const GLMesh &mesh, video::E_MATERIAL_TYPE type);