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

This commit is contained in:
hiker 2014-01-22 10:01:41 +11:00
commit a6108181e8
13 changed files with 108 additions and 36 deletions

View File

@ -1,23 +1,21 @@
#version 130
uniform sampler2D ntex;
uniform sampler2D cloudtex;
//uniform sampler2D cloudtex;
uniform vec3 center;
uniform vec3 direction;
uniform vec3 col;
uniform vec2 screen;
uniform mat4 invproj;
uniform int hasclouds;
uniform vec2 wind;
//uniform int hasclouds;
//uniform vec2 wind;
in vec2 uv;
out vec4 Diff;
out vec4 Spec;
out vec4 SpecularMap;
void main() {
vec2 texc = gl_FragCoord.xy / screen;
float z = texture(ntex, texc).a;
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0;
float z = texture(ntex, uv).a;
vec4 xpos = 2.0 * vec4(uv, z, 1.0) - 1.0;
xpos = invproj * xpos;
xpos.xyz /= xpos.w;
@ -29,11 +27,11 @@ void main() {
return;
}
vec3 norm = texture(ntex, texc).xyz;
vec3 norm = texture(ntex, uv).xyz;
norm = (norm - 0.5) * 2.0;
// Normalized on the cpu
vec3 L = center;
vec3 L = direction;
float NdotL = max(0.0, dot(norm, L));
vec3 R = reflect(L, norm);
@ -42,14 +40,14 @@ void main() {
vec3 outcol = NdotL * col;
if (hasclouds == 1)
/* if (hasclouds == 1)
{
vec2 cloudcoord = (xpos.xz * 0.00833333) + wind;
float cloud = texture(cloudtex, cloudcoord).x;
//float cloud = step(0.5, cloudcoord.x) * step(0.5, cloudcoord.y);
outcol *= cloud;
}
}*/
Diff = vec4(NdotL * col, 1.);
Spec = vec4(Specular * col, 1.);

View File

@ -94,7 +94,7 @@ COpenGLExtensionHandler::COpenGLExtensionHandler() :
#endif // _IRR_OPENGL_USE_EXTPOINTER_
{
for (u32 i=0; i<IRR_OpenGL_Feature_Count; ++i)
FeatureAvailable[i]=false;
FeatureAvailable[i]=true;
DimAliasedLine[0]=1.f;
DimAliasedLine[1]=1.f;
DimAliasedPoint[0]=1.f;

View File

@ -930,6 +930,8 @@ class COpenGLExtensionHandler
//! queries the features of the driver, returns true if feature is available
bool queryOpenGLFeature(EOpenGLFeatures feature) const
{
if (COpenGLExtensionHandler::IRR_EXT_packed_depth_stencil)
return true;
return FeatureAvailable[feature];
}

View File

@ -368,6 +368,21 @@ public:
m_color[1] = g;
m_color[2] = b;
}
float getRed() const
{
return m_color[0];
}
float getGreen() const
{
return m_color[1];
}
float getBlue() const
{
return m_color[2];
}
void setPosition(float x, float y, float z)
{
@ -383,6 +398,11 @@ public:
m_pos[1] = pos.Y;
m_pos[2] = pos.Z;
}
core::vector3df getPosition() const
{
return core::vector3df(m_pos[0], m_pos[1], m_pos[2]);
}
void setShadowMatrix(const core::matrix4 &mat)
{

View File

@ -333,6 +333,24 @@ void PostProcessing::renderPointlight(ITexture *in, const std::vector<float> &po
glDisable(GL_BLEND);
}
void PostProcessing::renderSunlight()
{
SunLightProvider * const cb = (SunLightProvider *) irr_driver->getCallback(ES_SUNLIGHT);
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_ONE, GL_ONE);
glBlendEquation(GL_FUNC_ADD);
glUseProgram(FullScreenShader::SunLightShader::Program);
glBindVertexArray(FullScreenShader::SunLightShader::vao);
GLuint ntex_id = static_cast<irr::video::COpenGLTexture*>(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH))->getOpenGLTextureName();
setTexture(0, ntex_id, GL_NEAREST, GL_NEAREST);
FullScreenShader::SunLightShader::setUniforms(cb->getPosition(), irr_driver->getInvProjMatrix(), cb->getRed(), cb->getGreen(), cb->getBlue(), 0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
}
void PostProcessing::renderLightbBlend(ITexture *diffuse, ITexture *specular, ITexture *ao, ITexture *specmap, bool debug)
{
const SColorf s = irr_driver->getSceneManager()->getAmbientLight();

View File

@ -74,7 +74,7 @@ public:
/** Generate diffuse and specular map */
void renderPointlight(video::ITexture *in, const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy);
void renderSunlight();
/** Blend all light related map */
void renderLightbBlend(video::ITexture *diffuse, video::ITexture *specular, video::ITexture *ao, video::ITexture *specmap, bool debug);

View File

@ -740,6 +740,7 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox,
if (!m_lights[i]->isPointLight())
{
m_lights[i]->render();
m_post_processing->renderSunlight();
continue;
}
const core::vector3df &lightpos = (m_lights[i]->getAbsolutePosition() - campos);

View File

@ -236,6 +236,7 @@ void Shaders::loadShaders()
FullScreenShader::PointLightShader::init();
FullScreenShader::PPDisplaceShader::init();
FullScreenShader::SSAOShader::init();
FullScreenShader::SunLightShader::init();
MeshShader::ColorizeShader::init();
MeshShader::NormalMapShader::init();
MeshShader::ObjectPass1Shader::init();
@ -949,6 +950,31 @@ namespace FullScreenShader
vao = createVAO(Program);
}
GLuint SunLightShader::Program;
GLuint SunLightShader::uniform_ntex;
GLuint SunLightShader::uniform_direction;
GLuint SunLightShader::uniform_col;
GLuint SunLightShader::uniform_invproj;
GLuint SunLightShader::vao;
void SunLightShader::init()
{
Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/sunlight.frag").c_str());
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_direction = glGetUniformLocation(Program, "direction");
uniform_col = glGetUniformLocation(Program, "col");
uniform_invproj = glGetUniformLocation(Program, "invproj");
vao = createVAO(Program);
}
void SunLightShader::setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex)
{
glUniformMatrix4fv(uniform_invproj, 1, GL_FALSE, InvProjMatrix.pointer());
glUniform3f(uniform_direction, direction.X, direction.Y, direction.Z);
glUniform3f(uniform_col, r, g, b);
glUniform1i(uniform_ntex, TU_ntex);
}
GLuint LightBlendShader::Program;
GLuint LightBlendShader::uniform_diffuse;
GLuint LightBlendShader::uniform_specular;

View File

@ -274,6 +274,17 @@ public:
static void init();
};
class SunLightShader
{
public:
static GLuint Program;
static GLuint uniform_ntex, uniform_direction, uniform_col, uniform_invproj;
static GLuint vao;
static void init();
static void setUniforms(const core::vector3df &direction, const core::matrix4 &InvProjMatrix, float r, float g, float b, unsigned TU_ntex);
};
class LightBlendShader
{
public:

View File

@ -87,12 +87,7 @@ void SunNode::render()
vector3df pos = getPosition();
cb->setPosition(pos.X, pos.Y, pos.Z);
if (!UserConfigParams::m_shadows || !World::getWorld()->getTrack()->hasShadows())
{
sq->render(false);
return;
}
return;
array<IRenderTarget> mrt;
mrt.reallocate(2);

View File

@ -594,7 +594,7 @@ void RibbonWidget::unfocused(const int playerID, Widget* new_focus)
{
if (new_focus != NULL && new_focus != this && !m_active_children.contains(new_focus))
{
if (m_selection[playerID] >= 0 && m_selection[playerID] < int(m_children.size()))
if (m_selection[playerID] >= 0 && m_selection[playerID] < int(m_active_children.size()))
{
m_active_children.get(m_selection[playerID])->unfocused(playerID, new_focus);
}

View File

@ -19,6 +19,7 @@
#include "guiengine/engine.hpp"
#include "guiengine/scalable_font.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/glwrap.hpp"
#include "states_screens/cutscene_gui.hpp"
// -----------------------------------------------------------------------------
@ -41,7 +42,7 @@ void CutsceneGUI::renderGlobal(float dt)
{
if (m_fade_level > 0.0f)
{
irr_driver->getVideoDriver()->draw2DRectangle(
GL32_draw2DRectangle(
video::SColor((int)(m_fade_level*255), 0,0,0),
core::rect<s32>(0, 0,
UserConfigParams::m_width,

View File

@ -26,6 +26,7 @@ using namespace irr;
#include "challenges/unlock_manager.hpp"
#include "config/user_config.hpp"
#include "graphics/camera.hpp"
#include "graphics/glwrap.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
#include "guiengine/engine.hpp"
@ -143,8 +144,7 @@ void RaceGUIOverworld::renderGlobal(float dt)
!GUIEngine::ModalDialog::isADialogActive())
{
static video::SColor black = video::SColor(255,0,0,0);
irr_driver->getVideoDriver()
->draw2DRectangle(black,
GL32_draw2DRectangle(black,
core::rect<s32>(UserConfigParams::m_width/2,
UserConfigParams::m_height/2,
UserConfigParams::m_width,
@ -233,7 +233,7 @@ void RaceGUIOverworld::drawTrophyPoints()
if (!m_close_to_a_challenge)
{
irr_driver->getVideoDriver()->draw2DImage(m_trophy1, dest, source, NULL,
draw2DImage(m_trophy1, dest, source, NULL,
NULL, true /* alpha */);
}
@ -248,7 +248,7 @@ void RaceGUIOverworld::drawTrophyPoints()
dest += core::position2di(size*2, 0);
if (!m_close_to_a_challenge)
{
irr_driver->getVideoDriver()->draw2DImage(m_trophy2, dest, source, NULL,
draw2DImage(m_trophy2, dest, source, NULL,
NULL, true /* alpha */);
}
@ -263,7 +263,7 @@ void RaceGUIOverworld::drawTrophyPoints()
dest += core::position2di(size*2, 0);
if (!m_close_to_a_challenge)
{
irr_driver->getVideoDriver()->draw2DImage(m_trophy3, dest, source, NULL,
draw2DImage(m_trophy3, dest, source, NULL,
NULL, true /* alpha */);
}
dest += core::position2di((int)(size*1.5f), 0);
@ -277,7 +277,7 @@ void RaceGUIOverworld::drawTrophyPoints()
dest = core::rect<s32>(pos.UpperLeftCorner.X - size - 5, pos.UpperLeftCorner.Y,
pos.UpperLeftCorner.X - 5, pos.UpperLeftCorner.Y + size);
irr_driver->getVideoDriver()->draw2DImage(m_open_challenge, dest, source, NULL,
draw2DImage(m_open_challenge, dest, source, NULL,
NULL, true /* alpha */);
pos.LowerRightCorner.Y = dest.LowerRightCorner.Y;
@ -330,7 +330,7 @@ void RaceGUIOverworld::drawGlobalMiniMap()
core::rect<s32> dest(m_map_left, upper_y,
m_map_left + m_map_width, lower_y);
core::rect<s32> source(core::position2di(0, 0), mini_map->getOriginalSize());
irr_driver->getVideoDriver()->draw2DImage(mini_map, dest, source, 0, 0, true);
draw2DImage(mini_map, dest, source, 0, 0, true);
}
Vec3 kart_xyz;
@ -376,11 +376,11 @@ void RaceGUIOverworld::drawGlobalMiniMap()
const core::rect<s32> rect(core::position2d<s32>(0,0),
m_icons_frame->getTexture()->getOriginalSize());
irr_driver->getVideoDriver()->draw2DImage(m_icons_frame->getTexture(), position,
draw2DImage(m_icons_frame->getTexture(), position,
rect, NULL, colors, true);
} // if isPlayerController
irr_driver->getVideoDriver()->draw2DImage(m_marker, position, source,
draw2DImage(m_marker, position, source,
NULL, NULL, true);
} // for i<getNumKarts
} // for only_draw_player_kart
@ -420,7 +420,7 @@ void RaceGUIOverworld::drawGlobalMiniMap()
lower_y -(int)(draw_at.getY()-marker_size/2));
m_current_challenge = &(challenges[n]);
}
irr_driver->getVideoDriver()->draw2DImage(m_icons[state],
draw2DImage(m_icons[state],
dest, source, NULL, NULL, true);
}
@ -546,7 +546,7 @@ void RaceGUIOverworld::drawEnergyMeter(int x, int y, const AbstractKart *kart,
x -= w;
// Background
irr_driver->getVideoDriver()->draw2DImage(m_gauge_empty, core::rect<s32>(x, y, x+w, y+h) /* dest rect */,
draw2DImage(m_gauge_empty, core::rect<s32>(x, y, x+w, y+h) /* dest rect */,
core::rect<s32>(0, 0, 64, 256) /* source rect */,
NULL /* clip rect */, NULL /* colors */,
true /* alpha */);
@ -565,7 +565,7 @@ void RaceGUIOverworld::drawEnergyMeter(int x, int y, const AbstractKart *kart,
if (state >= 1.0f) y1 = y;
core::rect<s32> clip(x, y1, x + w, y + h);
irr_driver->getVideoDriver()->draw2DImage(m_gauge_goal, core::rect<s32>(x, y, x+w, y+h) /* dest rect */,
draw2DImage(m_gauge_goal, core::rect<s32>(x, y, x+w, y+h) /* dest rect */,
core::rect<s32>(0, 0, 64, 256) /* source rect */,
&clip, NULL /* colors */, true /* alpha */);
}
@ -581,7 +581,7 @@ void RaceGUIOverworld::drawEnergyMeter(int x, int y, const AbstractKart *kart,
if (state >= 1.0f) y1 = y;
core::rect<s32> clip(x, y1, x + w, y + h);
irr_driver->getVideoDriver()->draw2DImage(m_gauge_full, core::rect<s32>(x, y, x+w, y+h) /* dest rect */,
draw2DImage(m_gauge_full, core::rect<s32>(x, y, x+w, y+h) /* dest rect */,
core::rect<s32>(0, 0, 64, 256) /* source rect */,
&clip, NULL /* colors */, true /* alpha */);
}