Remove old unused glsl code
This commit is contained in:
parent
49568f3fd9
commit
4252895d8b
@ -22,7 +22,6 @@
|
||||
#include "graphics/glwrap.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/shader.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "graphics/shared_gpu_objects.hpp"
|
||||
#include "graphics/texture_shader.hpp"
|
||||
#include "utils/cpp2011.hpp"
|
||||
|
@ -1,180 +0,0 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2014-2015 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "graphics/callbacks.hpp"
|
||||
|
||||
#include "graphics/camera.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/wind.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "utils/helpers.hpp"
|
||||
|
||||
using namespace video;
|
||||
using namespace core;
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
void WaterShaderProvider::OnSetConstants(IMaterialRendererServices *srv, int)
|
||||
{
|
||||
const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f;
|
||||
|
||||
float strength = time;
|
||||
strength = 1.4f - fabsf(noise2d(strength / 30.0f + 133)) * 0.8f;
|
||||
|
||||
m_dx_1 += GUIEngine::getLatestDt() * m_water_shader_speed_1 * strength;
|
||||
m_dy_1 += GUIEngine::getLatestDt() * m_water_shader_speed_1 * strength;
|
||||
|
||||
m_dx_2 += GUIEngine::getLatestDt() * m_water_shader_speed_2 * strength;
|
||||
m_dy_2 -= GUIEngine::getLatestDt() * m_water_shader_speed_2 * strength;
|
||||
|
||||
if (m_dx_1 > 1.0f) m_dx_1 -= 1.0f;
|
||||
if (m_dy_1 > 1.0f) m_dy_1 -= 1.0f;
|
||||
if (m_dx_2 > 1.0f) m_dx_2 -= 1.0f;
|
||||
if (m_dy_2 < 0.0f) m_dy_2 += 1.0f;
|
||||
|
||||
const float d1[2] = { m_dx_1, m_dy_1 };
|
||||
const float d2[2] = { m_dx_2, m_dy_2 };
|
||||
|
||||
srv->setVertexShaderConstant("delta1", d1, 2);
|
||||
srv->setVertexShaderConstant("delta2", d2, 2);
|
||||
|
||||
const float speed = irr_driver->getDevice()->getTimer()->getTime() / m_speed;
|
||||
const float height = m_height * strength;
|
||||
|
||||
srv->setVertexShaderConstant("height", &height, 1);
|
||||
srv->setVertexShaderConstant("speed", &speed, 1);
|
||||
srv->setVertexShaderConstant("waveLength", &m_length, 1);
|
||||
|
||||
// Can't use the firstdone optimization, as the callback is shared
|
||||
//if (!firstdone)
|
||||
{
|
||||
s32 decaltex = 0;
|
||||
srv->setPixelShaderConstant("DecalTex", &decaltex, 1);
|
||||
|
||||
s32 bumptex = 1;
|
||||
srv->setPixelShaderConstant("BumpTex1", &bumptex, 1);
|
||||
|
||||
bumptex = 2;
|
||||
srv->setPixelShaderConstant("BumpTex2", &bumptex, 1);
|
||||
|
||||
// Calculate light direction as coming from the sun.
|
||||
matrix4 normalm = srv->getVideoDriver()->getTransform(ETS_VIEW);
|
||||
normalm.makeInverse();
|
||||
normalm = normalm.getTransposed();
|
||||
vector3df tmp = m_sunpos;
|
||||
normalm.transformVect(tmp);
|
||||
tmp.normalize();
|
||||
|
||||
const float lightdir[] = {tmp.X, tmp.Y, tmp.Z};
|
||||
srv->setVertexShaderConstant("lightdir", lightdir, 3);
|
||||
|
||||
firstdone = true;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
void GrassShaderProvider::OnSetConstants(IMaterialRendererServices *srv, int userData)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
void MotionBlurProvider::OnSetConstants(IMaterialRendererServices *srv, int)
|
||||
{
|
||||
// We need the maximum texture coordinates:
|
||||
float max_tex_height = m_maxheight[m_current_camera];
|
||||
srv->setPixelShaderConstant("max_tex_height", &max_tex_height, 1);
|
||||
|
||||
// Scale the boost time to get a usable boost amount:
|
||||
float boost_amount = m_boost_time[m_current_camera] * 0.7f;
|
||||
|
||||
// Especially for single screen the top of the screen is less blurred
|
||||
// in the fragment shader by multiplying the blurr factor by
|
||||
// (max_tex_height - texcoords.t), where max_tex_height is the maximum
|
||||
// texture coordinate (1.0 or 0.5). In split screen this factor is too
|
||||
// small (half the value compared with non-split screen), so we
|
||||
// multiply this by 2.
|
||||
if(Camera::getNumCameras() > 1)
|
||||
boost_amount *= 2.0f;
|
||||
|
||||
srv->setPixelShaderConstant("boost_amount", &boost_amount, 1);
|
||||
srv->setPixelShaderConstant("center",
|
||||
&(m_center[m_current_camera].X), 2);
|
||||
srv->setPixelShaderConstant("direction",
|
||||
&(m_direction[m_current_camera].X), 2);
|
||||
|
||||
// Use a radius of 0.15 when showing a single kart, otherwise (2-4 karts
|
||||
// on splitscreen) use only 0.75.
|
||||
float radius = Camera::getNumCameras()==1 ? 0.15f : 0.075f;
|
||||
srv->setPixelShaderConstant("mask_radius", &radius, 1);
|
||||
|
||||
const int texunit = 0;
|
||||
srv->setPixelShaderConstant("color_buffer", &texunit, 1);
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
void MipVizProvider::OnSetConstants(IMaterialRendererServices *srv, int)
|
||||
{
|
||||
const ITexture * const tex = mat.TextureLayer[0].Texture;
|
||||
|
||||
const int notex = (mat.TextureLayer[0].Texture == NULL);
|
||||
srv->setVertexShaderConstant("notex", ¬ex, 1);
|
||||
if (!tex) return;
|
||||
|
||||
const dimension2du size = tex->getSize();
|
||||
|
||||
const float texsize[2] = {
|
||||
(float)size.Width,
|
||||
(float)size.Height
|
||||
};
|
||||
|
||||
srv->setVertexShaderConstant("texsize", texsize, 2);
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
void DisplaceProvider::OnSetConstants(IMaterialRendererServices *srv, int)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DisplaceProvider::update()
|
||||
{
|
||||
if (!Track::getCurrentTrack()) return;
|
||||
|
||||
const float time = irr_driver->getDevice()->getTimer()->getTime() / 1000.0f;
|
||||
const float speed = Track::getCurrentTrack()->getDisplacementSpeed();
|
||||
|
||||
float strength = time;
|
||||
strength = fabsf(noise2d(strength / 10.0f)) * 0.006f + 0.002f;
|
||||
|
||||
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.0025f;
|
||||
|
||||
wind = irr_driver->getWind() * strength * speed;
|
||||
wind.rotateXZBy(cosf(time));
|
||||
m_dir2[0] += wind.X;
|
||||
m_dir2[1] += wind.Z;
|
||||
}
|
@ -1,255 +0,0 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2014-2015 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_CALLBACKS_HPP
|
||||
#define HEADER_CALLBACKS_HPP
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
|
||||
#include <IShaderConstantSetCallBack.h>
|
||||
#include <SMaterial.h>
|
||||
#include <ISceneManager.h>
|
||||
#include <ICameraSceneNode.h>
|
||||
#include <IMaterialRendererServices.h>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace irr;
|
||||
|
||||
class CallBase: public video::IShaderConstantSetCallBack
|
||||
{
|
||||
public:
|
||||
CallBase()
|
||||
{
|
||||
firstdone = 0;
|
||||
}
|
||||
|
||||
virtual void OnSetMaterial(const video::SMaterial &material)
|
||||
{
|
||||
mat = material;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool firstdone;
|
||||
video::SMaterial mat;
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
class WaterShaderProvider: public CallBase
|
||||
{
|
||||
public:
|
||||
virtual void OnSetConstants(video::IMaterialRendererServices *srv, int);
|
||||
|
||||
void setSpeed(const float s1, const float s2)
|
||||
{
|
||||
m_water_shader_speed_1 = s1;
|
||||
m_water_shader_speed_2 = s2;
|
||||
}
|
||||
|
||||
WaterShaderProvider()
|
||||
{
|
||||
m_dx_1 = 0.0f;
|
||||
m_dx_2 = 0.0f;
|
||||
m_dy_1 = 0.0f;
|
||||
m_dy_2 = 0.0f;
|
||||
|
||||
m_water_shader_speed_1 =
|
||||
m_water_shader_speed_2 = 0.0f;
|
||||
m_sunpos = core::vector3df(0., 0., 0.);
|
||||
m_speed = 0.;
|
||||
m_height = 0.;
|
||||
m_length = 0.;
|
||||
}
|
||||
|
||||
void setSunPosition(const core::vector3df &in)
|
||||
{
|
||||
m_sunpos = in;
|
||||
m_sunpos.normalize();
|
||||
}
|
||||
|
||||
void setSpeed(float speed) { m_speed = speed; }
|
||||
void setHeight(float height) { m_height = height; }
|
||||
void setLength(float length) { m_length = length; }
|
||||
|
||||
private:
|
||||
core::vector3df m_sunpos;
|
||||
|
||||
float m_dx_1, m_dy_1, m_dx_2, m_dy_2;
|
||||
float m_water_shader_speed_1;
|
||||
float m_water_shader_speed_2;
|
||||
|
||||
float m_speed;
|
||||
float m_height;
|
||||
float m_length;
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
class GrassShaderProvider: public CallBase
|
||||
{
|
||||
public:
|
||||
virtual void OnSetConstants(video::IMaterialRendererServices *srv, int);
|
||||
|
||||
GrassShaderProvider()
|
||||
{
|
||||
m_amplitude =
|
||||
m_speed = 0.0f;
|
||||
}
|
||||
|
||||
void setSpeed(float speed)
|
||||
{
|
||||
m_speed = speed;
|
||||
}
|
||||
|
||||
void setAmplitude(float amp)
|
||||
{
|
||||
m_amplitude = amp;
|
||||
}
|
||||
|
||||
float getSpeed() const
|
||||
{
|
||||
return m_speed;
|
||||
}
|
||||
|
||||
float getAmplitude() const
|
||||
{
|
||||
return m_amplitude;
|
||||
}
|
||||
|
||||
private:
|
||||
float m_amplitude, m_speed;
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
class MotionBlurProvider: public CallBase
|
||||
{
|
||||
public:
|
||||
virtual void OnSetConstants(video::IMaterialRendererServices *srv, int);
|
||||
|
||||
void setMaxHeight(u32 who, float height)
|
||||
{
|
||||
assert(who < MAX_PLAYER_COUNT);
|
||||
m_maxheight[who] = height;
|
||||
}
|
||||
|
||||
float getMaxHeight(u32 who) const
|
||||
{
|
||||
return m_maxheight[who];
|
||||
}
|
||||
|
||||
void setBoostTime(u32 who, float time)
|
||||
{
|
||||
assert(who < MAX_PLAYER_COUNT);
|
||||
m_boost_time[who] = time;
|
||||
}
|
||||
|
||||
float getBoostTime(u32 who) const
|
||||
{
|
||||
return m_boost_time[who];
|
||||
}
|
||||
|
||||
void setCenter(u32 who, float X, float Y)
|
||||
{
|
||||
assert(who < MAX_PLAYER_COUNT);
|
||||
m_center[who].X = X;
|
||||
m_center[who].Y = Y;
|
||||
}
|
||||
|
||||
core::vector2df getCenter(u32 who) const
|
||||
{
|
||||
return core::vector2df(m_center[who].X, m_center[who].Y);
|
||||
}
|
||||
|
||||
void setDirection(u32 who, float X, float Y)
|
||||
{
|
||||
assert(who < MAX_PLAYER_COUNT);
|
||||
m_direction[who].X = X;
|
||||
m_direction[who].Y = Y;
|
||||
}
|
||||
|
||||
core::vector2df getDirection(u32 who) const
|
||||
{
|
||||
return core::vector2df(m_direction[who].X, m_direction[who].Y);
|
||||
}
|
||||
|
||||
void setCurrentCamera(u32 who)
|
||||
{
|
||||
m_current_camera = who;
|
||||
}
|
||||
|
||||
private:
|
||||
float m_maxheight[MAX_PLAYER_COUNT];
|
||||
u32 m_current_camera;
|
||||
float m_boost_time[MAX_PLAYER_COUNT];
|
||||
core::vector2df m_center[MAX_PLAYER_COUNT];
|
||||
core::vector2df m_direction[MAX_PLAYER_COUNT];
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
class MipVizProvider: public CallBase
|
||||
{
|
||||
public:
|
||||
virtual void OnSetConstants(video::IMaterialRendererServices *srv, int);
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
class DisplaceProvider: public CallBase
|
||||
{
|
||||
public:
|
||||
virtual void OnSetConstants(video::IMaterialRendererServices *srv, int);
|
||||
|
||||
DisplaceProvider()
|
||||
{
|
||||
m_screen[0] = (float)UserConfigParams::m_width;
|
||||
m_screen[1] = (float)UserConfigParams::m_height;
|
||||
|
||||
m_dir[0] = m_dir[1] = m_dir2[0] = m_dir2[1] = 0;
|
||||
}
|
||||
|
||||
void update();
|
||||
|
||||
float getDirX() const
|
||||
{
|
||||
return m_dir[0];
|
||||
}
|
||||
|
||||
float getDirY() const
|
||||
{
|
||||
return m_dir[1];
|
||||
}
|
||||
|
||||
float getDir2X() const
|
||||
{
|
||||
return m_dir2[0];
|
||||
}
|
||||
|
||||
float getDir2Y() const
|
||||
{
|
||||
return m_dir2[1];
|
||||
}
|
||||
|
||||
private:
|
||||
float m_screen[2];
|
||||
float m_dir[2], m_dir2[2];
|
||||
};
|
||||
|
||||
#endif
|
@ -19,10 +19,10 @@
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "font/font_manager.hpp"
|
||||
#include "graphics/callbacks.hpp"
|
||||
#include "graphics/2dutils.hpp"
|
||||
#include "graphics/b3d_mesh_loader.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/2dutils.hpp"
|
||||
#include "graphics/fixed_pipeline_renderer.hpp"
|
||||
#include "graphics/glwrap.hpp"
|
||||
#include "graphics/graphics_restrictions.hpp"
|
||||
@ -34,8 +34,7 @@
|
||||
#include "graphics/referee.hpp"
|
||||
#include "graphics/render_target.hpp"
|
||||
#include "graphics/shader_based_renderer.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "graphics/b3d_mesh_loader.hpp"
|
||||
#include "graphics/shared_gpu_objects.hpp"
|
||||
#include "graphics/sp_mesh_loader.hpp"
|
||||
#include "graphics/sp/sp_base.hpp"
|
||||
#include "graphics/sp/sp_dynamic_draw_call.hpp"
|
||||
@ -157,12 +156,6 @@ IrrDriver::~IrrDriver()
|
||||
ogrDestroy();
|
||||
#endif
|
||||
STKTexManager::getInstance()->kill();
|
||||
#ifndef SERVER_ONLY
|
||||
if (CVS->isGLSL())
|
||||
{
|
||||
Shaders::destroy();
|
||||
}
|
||||
#endif
|
||||
delete m_wind;
|
||||
delete m_renderer;
|
||||
assert(m_device != NULL);
|
||||
@ -612,11 +605,8 @@ void IrrDriver::initDevice()
|
||||
// m_glsl might be reset in rtt if an error occurs.
|
||||
if (CVS->isGLSL())
|
||||
{
|
||||
Shaders::init();
|
||||
|
||||
m_mrt.clear();
|
||||
m_mrt.reallocate(2);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -857,13 +847,9 @@ void IrrDriver::applyResolutionSettings()
|
||||
m_recording = false;
|
||||
#endif
|
||||
// initDevice will drop the current device.
|
||||
if (CVS->isGLSL())
|
||||
{
|
||||
Shaders::destroy();
|
||||
}
|
||||
delete m_renderer;
|
||||
SharedGPUObjects::reset();
|
||||
initDevice();
|
||||
ShaderBase::updateShaders();
|
||||
|
||||
font_manager = new FontManager();
|
||||
font_manager->loadFonts();
|
||||
@ -1961,89 +1947,6 @@ bool IrrDriver::supportsSplatting()
|
||||
} // supportsSplatting
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifndef SERVER_ONLY
|
||||
void IrrDriver::applyObjectPassShader(scene::ISceneNode * const node, bool rimlit)
|
||||
{
|
||||
if (!CVS->isGLSL())
|
||||
return;
|
||||
|
||||
// Don't override sky
|
||||
if (node->getType() == scene::ESNT_SKY_DOME ||
|
||||
node->getType() == scene::ESNT_SKY_BOX)
|
||||
return;
|
||||
|
||||
const u32 mcount = node->getMaterialCount();
|
||||
u32 i;
|
||||
const video::E_MATERIAL_TYPE ref =
|
||||
Shaders::getShader(rimlit ? ES_OBJECTPASS_RIMLIT : ES_OBJECTPASS_REF);
|
||||
const video::E_MATERIAL_TYPE pass =
|
||||
Shaders::getShader(rimlit ? ES_OBJECTPASS_RIMLIT : ES_OBJECTPASS);
|
||||
|
||||
const video::E_MATERIAL_TYPE origref = Shaders::getShader(ES_OBJECTPASS_REF);
|
||||
const video::E_MATERIAL_TYPE origpass = Shaders::getShader(ES_OBJECTPASS);
|
||||
|
||||
bool viamb = false;
|
||||
scene::IMesh *mesh = NULL;
|
||||
if (node->getType() == scene::ESNT_ANIMATED_MESH)
|
||||
{
|
||||
viamb = ((scene::IAnimatedMeshSceneNode *) node)->isReadOnlyMaterials();
|
||||
mesh = ((scene::IAnimatedMeshSceneNode *) node)->getMesh();
|
||||
}
|
||||
else if (node->getType() == scene::ESNT_MESH)
|
||||
{
|
||||
viamb = ((scene::IMeshSceneNode *) node)->isReadOnlyMaterials();
|
||||
mesh = ((scene::IMeshSceneNode *) node)->getMesh();
|
||||
}
|
||||
//else if (node->getType() == scene::ESNT_WATER_SURFACE)
|
||||
//{
|
||||
// viamb = (dynamic_cast<scene::IMeshSceneNode*>(node))->isReadOnlyMaterials();
|
||||
// mesh = (dynamic_cast<scene::IMeshSceneNode*>(node))->getMesh();
|
||||
//}
|
||||
|
||||
for (i = 0; i < mcount; i++)
|
||||
{
|
||||
video::SMaterial &nodemat = node->getMaterial(i);
|
||||
video::SMaterial &mbmat = mesh ? mesh->getMeshBuffer(i)->getMaterial()
|
||||
: nodemat;
|
||||
video::SMaterial *mat = &nodemat;
|
||||
|
||||
if (viamb)
|
||||
mat = &mbmat;
|
||||
|
||||
if (mat->MaterialType == video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF ||
|
||||
mat->MaterialType == origref)
|
||||
mat->MaterialType = ref;
|
||||
else if (mat->MaterialType == video::EMT_SOLID ||
|
||||
mat->MaterialType == origpass ||
|
||||
(mat->MaterialType >= video::EMT_LIGHTMAP &&
|
||||
mat->MaterialType <= video::EMT_LIGHTMAP_LIGHTING_M4))
|
||||
mat->MaterialType = pass;
|
||||
}
|
||||
|
||||
|
||||
core::list<scene::ISceneNode*> kids = node->getChildren();
|
||||
scene::ISceneNodeList::Iterator it = kids.begin();
|
||||
for (; it != kids.end(); ++it)
|
||||
{
|
||||
applyObjectPassShader(*it, rimlit);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void IrrDriver::applyObjectPassShader()
|
||||
{
|
||||
if (!CVS->isGLSL())
|
||||
return;
|
||||
|
||||
applyObjectPassShader(m_scene_manager->getRootSceneNode());
|
||||
}
|
||||
|
||||
#endif // !SERVER_ONLY
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
scene::ISceneNode *IrrDriver::addLight(const core::vector3df &pos,
|
||||
float energy, float radius,
|
||||
float r, float g, float b,
|
||||
@ -2068,14 +1971,8 @@ scene::ISceneNode *IrrDriver::addLight(const core::vector3df &pos,
|
||||
|
||||
if (sun)
|
||||
{
|
||||
//m_sun_interposer->setPosition(pos);
|
||||
//m_sun_interposer->updateAbsolutePosition();
|
||||
m_renderer->addSunLight(pos);
|
||||
|
||||
((WaterShaderProvider *) Shaders::getCallback(ES_WATER) )
|
||||
->setSunPosition(pos);
|
||||
}
|
||||
|
||||
return light;
|
||||
}
|
||||
else
|
||||
|
@ -455,10 +455,6 @@ public:
|
||||
m_background.push_back(n);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void applyObjectPassShader();
|
||||
void applyObjectPassShader(scene::ISceneNode * const node,
|
||||
bool rimlit = false);
|
||||
// ------------------------------------------------------------------------
|
||||
scene::ISceneNode *addLight(const core::vector3df &pos, float energy,
|
||||
float radius, float r, float g, float b,
|
||||
bool sun = false,
|
||||
|
@ -317,8 +317,5 @@ void LODNode::add(int level, scene::ISceneNode* node, bool reparent)
|
||||
node->drop();
|
||||
|
||||
node->updateAbsolutePosition();
|
||||
#ifndef SERVER_ONLY
|
||||
irr_driver->applyObjectPassShader(node);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/particle_kind_manager.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/material.hpp"
|
||||
#include "graphics/particle_kind_manager.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "io/xml_node.hpp"
|
||||
#include "modes/profile_world.hpp"
|
||||
@ -62,18 +61,12 @@ MaterialManager::~MaterialManager()
|
||||
}
|
||||
m_materials.clear();
|
||||
|
||||
for (std::map<video::E_MATERIAL_TYPE, Material*> ::iterator it =
|
||||
m_default_materials.begin(); it != m_default_materials.end(); it++)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
for (std::map<std::string, Material*> ::iterator it =
|
||||
m_default_sp_materials.begin(); it != m_default_sp_materials.end();
|
||||
it++)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
m_default_materials.clear();
|
||||
m_default_sp_materials.clear();
|
||||
} // ~MaterialManager
|
||||
|
||||
@ -183,13 +176,13 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t,
|
||||
video::E_MATERIAL_TYPE material_type)
|
||||
{
|
||||
if (t == NULL)
|
||||
return getDefaultMaterial(material_type);
|
||||
return getDefaultSPMaterial("solid");
|
||||
|
||||
Material* m = getMaterialFor(t);
|
||||
if (m != NULL)
|
||||
return m;
|
||||
|
||||
return getDefaultMaterial(material_type);
|
||||
return getDefaultSPMaterial("solid");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -207,9 +200,6 @@ void MaterialManager::setAllMaterialFlags(video::ITexture* t,
|
||||
mat->setMaterialProperties(&(mb->getMaterial()), mb);
|
||||
return;
|
||||
}
|
||||
|
||||
Material* default_material = getDefaultMaterial(mb->getMaterial().MaterialType);
|
||||
default_material->setMaterialProperties(&(mb->getMaterial()), mb);
|
||||
} // setAllMaterialFlags
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -230,39 +220,6 @@ Material* MaterialManager::getDefaultSPMaterial(const std::string& shader_name,
|
||||
return m;
|
||||
} // getDefaultSPMaterial
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
Material* MaterialManager::getDefaultMaterial(video::E_MATERIAL_TYPE shader_type)
|
||||
{
|
||||
auto it = m_default_materials.find(shader_type);
|
||||
if (it == m_default_materials.end())
|
||||
{
|
||||
Material* default_material = new Material("unicolor_white", false, false, false);
|
||||
|
||||
// TODO: workaround, should not hardcode these material types here?
|
||||
// Try to find a cleaner way
|
||||
// If graphics are disabled, shaders should not be accessed (getShader
|
||||
// asserts that shaders are initialised).
|
||||
#ifndef SERVER_ONLY
|
||||
if(!ProfileWorld::isNoGraphics() && CVS->isGLSL() &&
|
||||
shader_type == Shaders::getShader(ShaderType::ES_OBJECT_UNLIT))
|
||||
default_material->setShaderType(Material::SHADERTYPE_SOLID_UNLIT);
|
||||
else if (!ProfileWorld::isNoGraphics() && CVS->isGLSL() &&
|
||||
shader_type == Shaders::getShader(ShaderType::ES_OBJECTPASS_REF))
|
||||
default_material->setShaderType(Material::SHADERTYPE_ALPHA_TEST);
|
||||
//else if (!ProfileWorld::isNoGraphics() && CVS->isGLSL() &&
|
||||
// shader_type == Shaders::getShader(ShaderType::ES_OBJECTPASS))
|
||||
// default_material->setShaderType(Material::SHADERTYPE_ALPHA_BLEND);
|
||||
else
|
||||
default_material->setShaderType(Material::SHADERTYPE_SOLID);
|
||||
#endif
|
||||
m_default_materials[shader_type] = default_material;
|
||||
return default_material;
|
||||
}
|
||||
else
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@ -299,8 +256,6 @@ void MaterialManager::setAllUntexturedMaterialFlags(scene::IMeshBuffer *mb)
|
||||
material.MaterialType = irr::video::EMT_SOLID;
|
||||
}
|
||||
|
||||
Material* default_material = getDefaultMaterial(mb->getMaterial().MaterialType);
|
||||
default_material->setMaterialProperties(&(mb->getMaterial()), mb);
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
int MaterialManager::addEntity(Material *m)
|
||||
|
@ -50,9 +50,7 @@ private:
|
||||
|
||||
std::vector<Material*> m_materials;
|
||||
|
||||
std::map<video::E_MATERIAL_TYPE, Material*> m_default_materials;
|
||||
std::map<std::string, Material*> m_default_sp_materials;
|
||||
Material* getDefaultMaterial(video::E_MATERIAL_TYPE material_type);
|
||||
|
||||
public:
|
||||
MaterialManager();
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "graphics/post_processing.hpp"
|
||||
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/callbacks.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/frame_buffer.hpp"
|
||||
@ -29,10 +28,10 @@
|
||||
#include "graphics/mlaa_areamap.hpp"
|
||||
#include "graphics/glwrap.hpp"
|
||||
#include "graphics/rtts.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "graphics/shared_gpu_objects.hpp"
|
||||
#include "graphics/stk_texture.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "graphics/texture_shader.hpp"
|
||||
#include "graphics/weather.hpp"
|
||||
#include "graphics/sp/sp_dynamic_draw_call.hpp"
|
||||
#include "graphics/sp/sp_shader.hpp"
|
||||
@ -763,19 +762,6 @@ public:
|
||||
|
||||
PostProcessing::PostProcessing(IVideoDriver* video_driver)
|
||||
{
|
||||
// Initialization
|
||||
m_material.Wireframe = false;
|
||||
m_material.Lighting = false;
|
||||
m_material.ZWriteEnable = false;
|
||||
m_material.ZBuffer = ECFN_ALWAYS;
|
||||
m_material.setFlag(EMF_TRILINEAR_FILTER, true);
|
||||
|
||||
for (u32 i = 0; i < MATERIAL_MAX_TEXTURES; ++i)
|
||||
{
|
||||
m_material.TextureLayer[i].TextureWrapU =
|
||||
m_material.TextureLayer[i].TextureWrapV = ETC_CLAMP_TO_EDGE;
|
||||
}
|
||||
|
||||
// Load the MLAA area map
|
||||
io::IReadFile *areamap = irr_driver->getDevice()->getFileSystem()->
|
||||
createMemoryReadFile((void *) AreaMap33, sizeof(AreaMap33),
|
||||
@ -807,11 +793,6 @@ void PostProcessing::reset()
|
||||
const u32 n = Camera::getNumCameras();
|
||||
m_boost_time.resize(n);
|
||||
m_vertices.resize(n);
|
||||
m_center.resize(n);
|
||||
m_direction.resize(n);
|
||||
|
||||
MotionBlurProvider * const cb =
|
||||
(MotionBlurProvider *) Shaders::getCallback(ES_MOTIONBLUR);
|
||||
|
||||
for(unsigned int i=0; i<n; i++)
|
||||
{
|
||||
@ -850,57 +831,16 @@ void PostProcessing::reset()
|
||||
SColor white(0xFF, 0xFF, 0xFF, 0xFF);
|
||||
m_vertices[i].v0.Color = m_vertices[i].v1.Color =
|
||||
m_vertices[i].v2.Color = m_vertices[i].v3.Color = white;
|
||||
|
||||
m_center[i].X=(m_vertices[i].v0.TCoords.X
|
||||
+m_vertices[i].v2.TCoords.X) * 0.5f;
|
||||
|
||||
// Center is around 20 percent from bottom of screen:
|
||||
const float tex_height = m_vertices[i].v1.TCoords.Y
|
||||
- m_vertices[i].v0.TCoords.Y;
|
||||
m_direction[i].X = m_center[i].X;
|
||||
m_direction[i].Y = m_vertices[i].v0.TCoords.Y + 0.7f*tex_height;
|
||||
|
||||
setMotionBlurCenterY(i, 0.2f);
|
||||
|
||||
cb->setDirection(i, m_direction[i].X, m_direction[i].Y);
|
||||
cb->setMaxHeight(i, m_vertices[i].v1.TCoords.Y);
|
||||
} // for i <number of cameras
|
||||
} // reset
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void PostProcessing::setMotionBlurCenterY(const u32 num, const float y)
|
||||
{
|
||||
MotionBlurProvider * const cb =
|
||||
(MotionBlurProvider *) Shaders::getCallback(ES_MOTIONBLUR);
|
||||
|
||||
const float tex_height =
|
||||
m_vertices[num].v1.TCoords.Y - m_vertices[num].v0.TCoords.Y;
|
||||
m_center[num].Y = m_vertices[num].v0.TCoords.Y + y * tex_height;
|
||||
|
||||
cb->setCenter(num, m_center[num].X, m_center[num].Y);
|
||||
} // setMotionBlurCenterY
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Setup some PP data.
|
||||
*/
|
||||
void PostProcessing::begin()
|
||||
{
|
||||
m_any_boost = false;
|
||||
for (u32 i = 0; i < m_boost_time.size(); i++)
|
||||
m_any_boost |= m_boost_time[i] > 0.01f;
|
||||
} // begin
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Set the boost amount according to the speed of the camera */
|
||||
void PostProcessing::giveBoost(unsigned int camera_index)
|
||||
{
|
||||
if (CVS->isGLSL())
|
||||
{
|
||||
m_boost_time[camera_index] = 0.75f;
|
||||
|
||||
MotionBlurProvider * const cb =
|
||||
(MotionBlurProvider *)Shaders::getCallback(ES_MOTIONBLUR);
|
||||
cb->setBoostTime(camera_index, m_boost_time[camera_index]);
|
||||
m_boost_time.at(camera_index) = 0.75f;
|
||||
}
|
||||
} // giveBoost
|
||||
|
||||
@ -912,12 +852,6 @@ void PostProcessing::update(float dt)
|
||||
{
|
||||
if (!CVS->isGLSL())
|
||||
return;
|
||||
|
||||
MotionBlurProvider* const cb =
|
||||
(MotionBlurProvider*) Shaders::getCallback(ES_MOTIONBLUR);
|
||||
|
||||
if (cb == NULL) return;
|
||||
|
||||
for (unsigned int i=0; i<m_boost_time.size(); i++)
|
||||
{
|
||||
if (m_boost_time[i] > 0.0f)
|
||||
@ -925,8 +859,6 @@ void PostProcessing::update(float dt)
|
||||
m_boost_time[i] -= dt;
|
||||
if (m_boost_time[i] < 0.0f) m_boost_time[i] = 0.0f;
|
||||
}
|
||||
|
||||
cb->setBoostTime(i, m_boost_time[i]);
|
||||
}
|
||||
} // update
|
||||
|
||||
@ -1263,32 +1195,11 @@ void PostProcessing::renderMotionBlur(unsigned , const FrameBuffer &in_fbo,
|
||||
FrameBuffer &out_fbo,
|
||||
GLuint depth_stencil_texture)
|
||||
{
|
||||
MotionBlurProvider * const cb =
|
||||
(MotionBlurProvider *)Shaders::getCallback(ES_MOTIONBLUR);
|
||||
Camera *cam = Camera::getActiveCamera();
|
||||
unsigned camID = cam->getIndex();
|
||||
|
||||
scene::ICameraSceneNode * const camnode = cam->getCameraSceneNode();
|
||||
|
||||
// Calculate the kart's Y position on screen
|
||||
if (cam->getKart())
|
||||
{
|
||||
const core::vector3df pos = cam->getKart()->getNode()->getPosition();
|
||||
float ndc[4];
|
||||
core::matrix4 trans = camnode->getProjectionMatrix();
|
||||
trans *= camnode->getViewMatrix();
|
||||
|
||||
trans.transformVect(ndc, pos);
|
||||
const float karty = (ndc[1] / ndc[3]) * 0.5f + 0.5f;
|
||||
setMotionBlurCenterY(camID, karty);
|
||||
}
|
||||
else
|
||||
setMotionBlurCenterY(camID, 0.5f);
|
||||
|
||||
out_fbo.bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
float boost_time = cb->getBoostTime(cam->getIndex()) * 10;
|
||||
float boost_time = m_boost_time.at(cam->getIndex()) * 10.0f;
|
||||
MotionBlurShader::getInstance()->render(in_fbo, boost_time, depth_stencil_texture);
|
||||
} // renderMotionBlur
|
||||
|
||||
@ -1558,11 +1469,9 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode,
|
||||
{
|
||||
PROFILER_PUSH_CPU_MARKER("- Motion blur", 0xFF, 0x00, 0x00);
|
||||
ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_MOTIONBLUR));
|
||||
MotionBlurProvider * const cb =
|
||||
(MotionBlurProvider *)Shaders::getCallback(ES_MOTIONBLUR);
|
||||
|
||||
if (isRace && UserConfigParams::m_motionblur && World::getWorld() &&
|
||||
cb->getBoostTime(Camera::getActiveCamera()->getIndex()) > 0.) // motion blur
|
||||
m_boost_time.at(Camera::getActiveCamera()->getIndex()) > 0.0f) // motion blur
|
||||
{
|
||||
renderMotionBlur(0, *in_fbo, *out_fbo, irr_driver->getDepthStencilTexture());
|
||||
std::swap(in_fbo, out_fbo);
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include <IReferenceCounted.h>
|
||||
#include <S3DVertex.h>
|
||||
#include <SMaterial.h>
|
||||
#include <matrix4.h>
|
||||
#include <vector>
|
||||
|
||||
class FrameBuffer;
|
||||
@ -31,7 +31,7 @@ class STKTexture;
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace video { class IVideoDriver; class ITexture; }
|
||||
namespace video { class IVideoDriver; }
|
||||
namespace scene { class ICameraSceneNode; }
|
||||
}
|
||||
|
||||
@ -43,21 +43,11 @@ using namespace irr;
|
||||
class PostProcessing: public IReferenceCounted
|
||||
{
|
||||
private:
|
||||
video::SMaterial m_material;
|
||||
|
||||
/** Boost time, how long the boost should be displayed. This also
|
||||
* affects the strength of the effect: longer boost time will
|
||||
* have a stronger effect. */
|
||||
std::vector<float> m_boost_time;
|
||||
|
||||
bool m_any_boost;
|
||||
|
||||
/** The center of blurring, in texture coordinates [0,1]).*/
|
||||
std::vector<core::vector2df> m_center;
|
||||
|
||||
/** The center to which the blurring is aimed at, in [0,1]. */
|
||||
std::vector<core::vector2df> m_direction;
|
||||
|
||||
struct Quad { video::S3DVertex v0, v1, v2, v3; };
|
||||
|
||||
/** The vertices for the rectangle used for each camera. This includes
|
||||
@ -66,8 +56,6 @@ private:
|
||||
|
||||
STKTexture* m_areamap;
|
||||
|
||||
void setMotionBlurCenterY(const u32 num, const float y);
|
||||
|
||||
public:
|
||||
PostProcessing(video::IVideoDriver* video_driver);
|
||||
virtual ~PostProcessing();
|
||||
@ -75,7 +63,7 @@ public:
|
||||
void reset();
|
||||
/** Those should be called around the part where we render the scene to be
|
||||
* post-processed */
|
||||
void begin();
|
||||
void begin() {}
|
||||
void update(float dt);
|
||||
|
||||
void renderBloom(GLuint in);
|
||||
|
@ -162,8 +162,6 @@ Referee::Referee()
|
||||
m_scene_node->setFrameLoop(m_st_first_start_frame,
|
||||
m_st_last_start_frame);
|
||||
#ifndef SERVER_ONLY
|
||||
irr_driver->applyObjectPassShader(m_scene_node);
|
||||
|
||||
if (CVS->isGLSL() && CVS->isDefferedEnabled())
|
||||
{
|
||||
m_light = irr_driver->addLight(core::vector3df(0.0f, 0.0f, 0.6f), 0.7f, 2.0f,
|
||||
@ -199,9 +197,6 @@ Referee::Referee(const AbstractKart &kart)
|
||||
m_scene_node->setFrameLoop(m_st_first_rescue_frame,
|
||||
m_st_last_rescue_frame);
|
||||
|
||||
#ifndef SERVER_ONLY
|
||||
irr_driver->applyObjectPassShader(m_scene_node);
|
||||
#endif
|
||||
} // Referee
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -43,8 +43,6 @@ int ShaderBase::loadTFBProgram(const std::string &shader_name,
|
||||
#ifdef USE_GLES2
|
||||
loadAndAttachShader(GL_FRAGMENT_SHADER, "tfb_dummy.frag");
|
||||
#endif
|
||||
if (!CVS->isARBExplicitAttribLocationUsable())
|
||||
setAttribute(PARTICLES_SIM);
|
||||
|
||||
glTransformFeedbackVaryings(m_program, varying_count, varyings,
|
||||
GL_INTERLEAVED_ATTRIBS);
|
||||
@ -67,51 +65,6 @@ int ShaderBase::loadTFBProgram(const std::string &shader_name,
|
||||
return m_program;
|
||||
} // loadTFBProgram
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ShaderBase::bypassUBO() const
|
||||
{
|
||||
GLint VM = glGetUniformLocation(m_program, "ViewMatrix");
|
||||
glUniformMatrix4fv(VM, 1, GL_FALSE, irr_driver->getViewMatrix().pointer());
|
||||
|
||||
GLint PM = glGetUniformLocation(m_program, "ProjectionMatrix");
|
||||
glUniformMatrix4fv(PM, 1, GL_FALSE, irr_driver->getProjMatrix().pointer());
|
||||
|
||||
GLint PVM = glGetUniformLocation(m_program, "ProjectionViewMatrix");
|
||||
glUniformMatrix4fv(PVM, 1, GL_FALSE, irr_driver->getProjViewMatrix().pointer());
|
||||
|
||||
GLint IVM = glGetUniformLocation(m_program, "InverseViewMatrix");
|
||||
glUniformMatrix4fv(IVM, 1, GL_FALSE, irr_driver->getInvViewMatrix().pointer());
|
||||
|
||||
GLint IPM = glGetUniformLocation(m_program, "InverseProjectionMatrix");
|
||||
glUniformMatrix4fv(IPM, 1, GL_FALSE, irr_driver->getInvProjMatrix().pointer());
|
||||
|
||||
GLint Screen = glGetUniformLocation(m_program, "screen");
|
||||
glUniform2f(Screen, irr_driver->getCurrentScreenSize().X,
|
||||
irr_driver->getCurrentScreenSize().Y);
|
||||
|
||||
const SHCoefficients* sh_coeff = irr_driver->getSHCoefficients();
|
||||
|
||||
GLint bLmn = glGetUniformLocation(m_program, "blueLmn[0]");
|
||||
glUniform1fv(bLmn, 9, sh_coeff->blue_SH_coeff);
|
||||
|
||||
GLint gLmn = glGetUniformLocation(m_program, "greenLmn[0]");
|
||||
glUniform1fv(gLmn, 9, sh_coeff->green_SH_coeff);
|
||||
|
||||
GLint rLmn = glGetUniformLocation(m_program, "redLmn[0]");
|
||||
glUniform1fv(rLmn, 9, sh_coeff->red_SH_coeff);
|
||||
|
||||
GLint sun_dir = glGetUniformLocation(m_program, "sun_direction");
|
||||
const core::vector3df &sd = irr_driver->getSunDirection();
|
||||
glUniform3f(sun_dir, sd.X, sd.Y, sd.Z);
|
||||
|
||||
GLint sun_col = glGetUniformLocation(m_program, "sun_col");
|
||||
const video::SColorf& sc = irr_driver->getSunColor();
|
||||
glUniform3f(sun_col, sc.getRed(), sc.getGreen(), sc.getBlue());
|
||||
|
||||
GLint sun_angle = glGetUniformLocation(m_program, "sun_angle");
|
||||
glUniform1f(sun_angle, 0.54f);
|
||||
} // bypassUBO
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Constructor, which adds the shader to all instantiated shaders (for the
|
||||
* reload-all-shaders debug option).
|
||||
@ -121,72 +74,14 @@ ShaderBase::ShaderBase()
|
||||
} // ShaderBase
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ShaderBase::updateShaders()
|
||||
void ShaderBase::killShaders()
|
||||
{
|
||||
for (unsigned int i = 0; i < m_all_kill_functions.size(); i++)
|
||||
{
|
||||
m_all_kill_functions[i]();
|
||||
}
|
||||
m_all_kill_functions.clear();
|
||||
} // updateShaders
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void ShaderBase::setAttribute(AttributeType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case OBJECT:
|
||||
glBindAttribLocation(m_program, 0, "Position");
|
||||
glBindAttribLocation(m_program, 1, "Normal");
|
||||
glBindAttribLocation(m_program, 2, "Color");
|
||||
glBindAttribLocation(m_program, 3, "Texcoord");
|
||||
glBindAttribLocation(m_program, 4, "SecondTexcoord");
|
||||
glBindAttribLocation(m_program, 5, "Tangent");
|
||||
glBindAttribLocation(m_program, 6, "Bitangent");
|
||||
glBindAttribLocation(m_program, 7, "Origin");
|
||||
glBindAttribLocation(m_program, 8, "Orientation");
|
||||
glBindAttribLocation(m_program, 9, "Scale");
|
||||
glBindAttribLocation(m_program, 10, "misc_data");
|
||||
break;
|
||||
case PARTICLES_SIM:
|
||||
glBindAttribLocation(m_program, 0, "particle_position");
|
||||
glBindAttribLocation(m_program, 1, "lifetime");
|
||||
glBindAttribLocation(m_program, 2, "particle_velocity");
|
||||
glBindAttribLocation(m_program, 3, "size");
|
||||
glBindAttribLocation(m_program, 4, "particle_position_initial");
|
||||
glBindAttribLocation(m_program, 5, "lifetime_initial");
|
||||
glBindAttribLocation(m_program, 6, "particle_velocity_initial");
|
||||
glBindAttribLocation(m_program, 7, "size_initial");
|
||||
if (CVS->needsVertexIdWorkaround())
|
||||
{
|
||||
glBindAttribLocation(m_program, 8, "vertex_id");
|
||||
}
|
||||
break;
|
||||
case PARTICLES_RENDERING:
|
||||
glBindAttribLocation(m_program, 0, "Position");
|
||||
glBindAttribLocation(m_program, 1, "color_lifetime");
|
||||
glBindAttribLocation(m_program, 2, "size");
|
||||
glBindAttribLocation(m_program, 3, "Texcoord");
|
||||
glBindAttribLocation(m_program, 4, "quadcorner");
|
||||
glBindAttribLocation(m_program, 5, "rotationvec");
|
||||
glBindAttribLocation(m_program, 6, "anglespeed");
|
||||
break;
|
||||
case SKINNED_MESH:
|
||||
glBindAttribLocation(m_program, 0, "Position");
|
||||
glBindAttribLocation(m_program, 1, "Normal");
|
||||
glBindAttribLocation(m_program, 2, "Color");
|
||||
glBindAttribLocation(m_program, 3, "Data1");
|
||||
glBindAttribLocation(m_program, 4, "Data2");
|
||||
glBindAttribLocation(m_program, 5, "Joint");
|
||||
glBindAttribLocation(m_program, 6, "Weight");
|
||||
glBindAttribLocation(m_program, 7, "Origin");
|
||||
glBindAttribLocation(m_program, 8, "Orientation");
|
||||
glBindAttribLocation(m_program, 9, "Scale");
|
||||
glBindAttribLocation(m_program, 10, "misc_data");
|
||||
glBindAttribLocation(m_program, 15, "skinning_offset");
|
||||
break;
|
||||
}
|
||||
} // setAttribute
|
||||
} // killShaders
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
GLuint ShaderBase::createVAO()
|
||||
@ -207,6 +102,4 @@ GLuint ShaderBase::createVAO()
|
||||
return vao;
|
||||
} // createVAO
|
||||
|
||||
// ============================================================================
|
||||
|
||||
#endif // !SERVER_ONLY
|
||||
|
@ -55,8 +55,6 @@ protected:
|
||||
/** OpenGL's program id. */
|
||||
GLuint m_program;
|
||||
|
||||
void bypassUBO() const;
|
||||
|
||||
// ========================================================================
|
||||
/** Ends recursion. */
|
||||
template<typename ... Types>
|
||||
@ -86,15 +84,13 @@ protected:
|
||||
{
|
||||
loadAndAttachShader(shader_type, std::string(name), args...);
|
||||
} // loadAndAttachShader
|
||||
// ------------------------------------------------------------------------
|
||||
void setAttribute(AttributeType type);
|
||||
|
||||
public:
|
||||
ShaderBase();
|
||||
int loadTFBProgram(const std::string &vertex_file_path,
|
||||
const char **varyings,
|
||||
unsigned varyingscount);
|
||||
static void updateShaders();
|
||||
static void killShaders();
|
||||
GLuint createVAO();
|
||||
// ------------------------------------------------------------------------
|
||||
/** Activates the shader calling glUseProgram. */
|
||||
@ -375,27 +371,6 @@ public:
|
||||
|
||||
}; // Shader
|
||||
|
||||
// ============================================================================
|
||||
class SkinnedMeshShader
|
||||
{
|
||||
private:
|
||||
GLuint m_skinning_tex_location;
|
||||
public:
|
||||
SkinnedMeshShader() : m_skinning_tex_location(0) {}
|
||||
// ------------------------------------------------------------------------
|
||||
template <typename Shader>
|
||||
void init(Shader* s)
|
||||
{
|
||||
s->use();
|
||||
m_skinning_tex_location = s->getUniformLocation("skinning_tex");
|
||||
glUniform1i(m_skinning_tex_location, 15);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
void bindSkinningTexture()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "graphics/spherical_harmonics.hpp"
|
||||
#include "graphics/sp/sp_base.hpp"
|
||||
#include "graphics/sp/sp_shader.hpp"
|
||||
#include "graphics/texture_shader.hpp"
|
||||
#include "graphics/text_billboard_drawer.hpp"
|
||||
#include "items/item_manager.hpp"
|
||||
#include "items/powerup_manager.hpp"
|
||||
@ -561,6 +562,7 @@ void ShaderBasedRenderer::debugPhysics()
|
||||
debug_drawer->getLines();
|
||||
std::map<video::SColor, std::vector<float> >::const_iterator it;
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
Shaders::ColoredLine *line = Shaders::ColoredLine::getInstance();
|
||||
line->use();
|
||||
line->bindVertexArray();
|
||||
@ -578,6 +580,7 @@ void ShaderBasedRenderer::debugPhysics()
|
||||
glDrawArrays(GL_LINES, 0, count / 3);
|
||||
}
|
||||
}
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
@ -672,6 +675,7 @@ ShaderBasedRenderer::~ShaderBasedRenderer()
|
||||
delete m_skybox;
|
||||
delete m_rtts;
|
||||
ShaderFilesManager::kill();
|
||||
ShaderBase::killShaders();
|
||||
SP::destroy();
|
||||
}
|
||||
|
||||
|
@ -17,297 +17,12 @@
|
||||
|
||||
|
||||
#ifndef SERVER_ONLY
|
||||
|
||||
/**
|
||||
\page shaders_overview Shaders Overview
|
||||
|
||||
\section shader_declaration Shader declaration
|
||||
You need to create a class for each shader in shaders.cpp
|
||||
This class should inherit from the template ShaderHelper<>.
|
||||
The template first parameter is the shader class being declared and the following ones are the types
|
||||
of every uniform (except samplers) required by the shaders.
|
||||
|
||||
The template inheritance will provide the shader with a setUniforms() variadic function which calls
|
||||
the glUniform*() that pass uniforms value to the shader according to the type given as parameter
|
||||
to the template.
|
||||
|
||||
The class constructor is used to
|
||||
\li \ref shader_declaration_compile
|
||||
\li \ref shader_declaration_uniform_names
|
||||
\li \ref shader_declaration_bind_texture_unit
|
||||
|
||||
Of course it's possible to use the constructor to declare others things if needed.
|
||||
|
||||
\subsection shader_declaration_compile Compile the shader
|
||||
|
||||
The LoadProgram() function is provided to ease shader compilation and link.
|
||||
It takes a flat sequence of SHADER_TYPE, filename pairs that will be linked together.
|
||||
This way you can add any shader stage you want (geometry, domain/hull shader)
|
||||
|
||||
It is highly recommended to use explicit attribute location for a program input.
|
||||
However as not all hardware support this extension, default location are provided for
|
||||
input whose name is either Position (location 0) or Normal (location 1) or
|
||||
Texcoord (location 3) or Color (location 2) or SecondTexcoord (location 4).
|
||||
You can use these predefined name and location in your vao for shader
|
||||
that needs GL pre 3.3 support.
|
||||
|
||||
\subsection shader_declaration_uniform_names Declare uniforms
|
||||
|
||||
Use the assignUniforms() function to pass name of the uniforms in the program.
|
||||
The order of name declaration is the same as the argument passed to setUniforms function.
|
||||
|
||||
\subsection shader_declaration_bind_texture_unit Bind texture unit and name
|
||||
|
||||
Texture are optional but if you have one, you must give them determined texture unit (up to 32).
|
||||
You can do this using the assignTextureUnit function that takes pair of texture unit and sampler name
|
||||
as argument.
|
||||
|
||||
\section shader_usage
|
||||
|
||||
Shader's class are singleton that can be retrieved using ShaderClassName::getInstance() which automatically
|
||||
creates an instance the first time it is called.
|
||||
|
||||
As the program id of a shader instance is public it can be used to bind a program :
|
||||
\code
|
||||
glUseProgram(MyShaderClass::getInstance()->Program);
|
||||
\endcode
|
||||
|
||||
To set uniforms use the automatically generated function setUniforms:
|
||||
|
||||
\code
|
||||
MyShaderClass::getInstance()->setUniforms(Args...)
|
||||
\endcode
|
||||
|
||||
A Vertex Array must be bound (VAO creation process is currently left to the reader) :
|
||||
|
||||
\code
|
||||
glBindVertexAttrib(vao);
|
||||
\endcode
|
||||
|
||||
To actually perform the rendering you also need to call a glDraw* function (left to the reader as well) :
|
||||
|
||||
\code
|
||||
glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_SHORT);
|
||||
\endcode
|
||||
|
||||
*/
|
||||
|
||||
#include "graphics/shaders.hpp"
|
||||
|
||||
#include "graphics/callbacks.hpp"
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/glwrap.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/shared_gpu_objects.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "utils/log.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <IGPUProgrammingServices.h>
|
||||
|
||||
|
||||
bool Shaders::m_has_been_initialised = false;
|
||||
video::IShaderConstantSetCallBack *Shaders::m_callbacks[ES_COUNT];
|
||||
int Shaders::m_shaders[ES_COUNT];
|
||||
|
||||
// Use macro FOREACH_SHADER from shaders.hpp to create an array
|
||||
// with all shader names.
|
||||
#define STR(a) #a,
|
||||
const char *Shaders::shader_names[] = { FOREACH_SHADER(STR) };
|
||||
#undef STR
|
||||
|
||||
using namespace video;
|
||||
|
||||
void Shaders::init()
|
||||
{
|
||||
assert(!m_has_been_initialised);
|
||||
// Callbacks
|
||||
memset(m_callbacks, 0, sizeof(m_callbacks));
|
||||
|
||||
m_callbacks[ES_WATER] = new WaterShaderProvider();
|
||||
m_callbacks[ES_GRASS] = new GrassShaderProvider();
|
||||
m_callbacks[ES_MOTIONBLUR] = new MotionBlurProvider();
|
||||
m_callbacks[ES_MIPVIZ] = new MipVizProvider();
|
||||
m_callbacks[ES_DISPLACE] = new DisplaceProvider();
|
||||
|
||||
for (s32 i = 0; i < ES_COUNT; i++)
|
||||
m_shaders[i] = -1;
|
||||
|
||||
loadShaders();
|
||||
m_has_been_initialised = true;
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Frees all memory used by the shader manager.
|
||||
*/
|
||||
void Shaders::destroy()
|
||||
{
|
||||
assert(m_has_been_initialised);
|
||||
u32 i;
|
||||
for (i = 0; i < ES_COUNT; i++)
|
||||
{
|
||||
if (i == ES_GAUSSIAN3V || !m_callbacks[i]) continue;
|
||||
m_callbacks[i]->drop();
|
||||
m_callbacks[i] = NULL;
|
||||
}
|
||||
m_has_been_initialised = false;
|
||||
SharedGPUObjects::reset();
|
||||
} // destroy
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Shader loading related hook
|
||||
|
||||
static std::string loadHeader()
|
||||
{
|
||||
std::string result;
|
||||
std::ifstream Stream("header.txt", std::ios::in);
|
||||
|
||||
if (Stream.is_open())
|
||||
{
|
||||
std::string Line = "";
|
||||
while (getline(Stream, Line))
|
||||
result += "\n" + Line;
|
||||
Stream.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
} // loadHeader
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Shaders::loadShaders()
|
||||
{
|
||||
const std::string &dir = file_manager->getAsset(FileManager::SHADER, "");
|
||||
|
||||
IGPUProgrammingServices * const gpu = irr_driver->getVideoDriver()
|
||||
->getGPUProgrammingServices();
|
||||
|
||||
#define glsl(a, b, c) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) c)
|
||||
#define glslmat(a, b, c, d) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) c, d)
|
||||
#define glsl_noinput(a, b) gpu->addHighLevelShaderMaterialFromFiles((a).c_str(), (b).c_str(), (IShaderConstantSetCallBack*) 0)
|
||||
|
||||
// Save previous shaders (used in case some shaders don't compile)
|
||||
int saved_shaders[ES_COUNT];
|
||||
memcpy(saved_shaders, m_shaders, sizeof(m_shaders));
|
||||
|
||||
#if !defined(USE_GLES2)
|
||||
std::string name = "pass";
|
||||
#else
|
||||
std::string name = "pass_gles";
|
||||
#endif
|
||||
|
||||
// Ok, go
|
||||
m_shaders[ES_NORMAL_MAP] = glsl_noinput(dir + name + ".vert", dir + name + ".frag");
|
||||
m_shaders[ES_NORMAL_MAP_LIGHTMAP] = glsl_noinput(dir + name + ".vert", dir + name + ".frag");
|
||||
|
||||
m_shaders[ES_SKYBOX] = glslmat(dir + name + ".vert", dir + name + ".frag",
|
||||
m_callbacks[ES_SKYBOX], EMT_TRANSPARENT_ALPHA_CHANNEL);
|
||||
|
||||
m_shaders[ES_SPLATTING] = glsl_noinput(dir + name + ".vert", dir + name + ".frag");
|
||||
|
||||
m_shaders[ES_WATER] = glslmat(dir + name + ".vert", dir + name + ".frag",
|
||||
m_callbacks[ES_WATER], EMT_TRANSPARENT_ALPHA_CHANNEL);
|
||||
m_shaders[ES_WATER_SURFACE] = glsl(dir + name + ".vert", dir + name + ".frag",
|
||||
m_callbacks[ES_WATER]);
|
||||
|
||||
m_shaders[ES_SPHERE_MAP] = glsl_noinput(dir + name + ".vert", dir + name + ".frag");
|
||||
|
||||
m_shaders[ES_GRASS] = glslmat(dir + name + ".vert", dir + name + ".frag",
|
||||
m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL);
|
||||
m_shaders[ES_GRASS_REF] = glslmat(dir + name + ".vert", dir + name + ".frag",
|
||||
m_callbacks[ES_GRASS], EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
|
||||
|
||||
m_shaders[ES_MOTIONBLUR] = glsl(dir + name + ".vert", dir + name + ".frag",
|
||||
m_callbacks[ES_MOTIONBLUR]);
|
||||
|
||||
m_shaders[ES_GAUSSIAN3H] = glslmat(dir + name + ".vert", dir + name + ".frag",
|
||||
m_callbacks[ES_GAUSSIAN3H], EMT_SOLID);
|
||||
m_shaders[ES_GAUSSIAN3V] = glslmat(dir + name + ".vert", dir + name + ".frag",
|
||||
m_callbacks[ES_GAUSSIAN3V], EMT_SOLID);
|
||||
|
||||
m_shaders[ES_MIPVIZ] = glslmat(dir + name + ".vert", dir + name + ".frag",
|
||||
m_callbacks[ES_MIPVIZ], EMT_SOLID);
|
||||
|
||||
m_shaders[ES_OBJECTPASS] = glsl_noinput(dir + name + ".vert", dir + name + ".frag");
|
||||
m_shaders[ES_OBJECT_UNLIT] = glsl_noinput(dir + name + ".vert", dir + name + ".frag");
|
||||
m_shaders[ES_OBJECTPASS_REF] = glsl_noinput(dir + name + ".vert", dir + name + ".frag");
|
||||
m_shaders[ES_OBJECTPASS_RIMLIT] = glsl_noinput(dir + name + ".vert", dir + name + ".frag");
|
||||
|
||||
m_shaders[ES_DISPLACE] = glslmat(dir + name + ".vert", dir + name + ".frag",
|
||||
m_callbacks[ES_DISPLACE], EMT_TRANSPARENT_ALPHA_CHANNEL);
|
||||
|
||||
// Check that all successfully loaded
|
||||
for (s32 i = 0; i < ES_COUNT; i++) {
|
||||
|
||||
// Old Intel Windows drivers fail here.
|
||||
// It's an artist option, so not necessary to play.
|
||||
if (i == ES_MIPVIZ)
|
||||
continue;
|
||||
|
||||
check(i);
|
||||
}
|
||||
|
||||
#undef glsl
|
||||
#undef glslmat
|
||||
#undef glsl_noinput
|
||||
|
||||
// In case we're reloading and a shader didn't compile: keep the previous, working one
|
||||
for (s32 i = 0; i < ES_COUNT; i++)
|
||||
{
|
||||
if (m_shaders[i] == -1)
|
||||
m_shaders[i] = saved_shaders[i];
|
||||
}
|
||||
|
||||
initGL();
|
||||
} // loadShaders
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void Shaders::check(const int num)
|
||||
{
|
||||
if (m_shaders[num] == -1)
|
||||
{
|
||||
Log::error("shaders",
|
||||
"Shader %s failed to load. Update your drivers, if the issue "
|
||||
"persists, report a bug to us.", shader_names[num] + 3);
|
||||
}
|
||||
} // check
|
||||
|
||||
// ============================================================================
|
||||
Shaders::SkinnedTransparentShader::SkinnedTransparentShader()
|
||||
{
|
||||
if (!CVS->supportsHardwareSkinning()) return;
|
||||
loadProgram(SKINNED_MESH, GL_VERTEX_SHADER, "skinning.vert",
|
||||
GL_FRAGMENT_SHADER, "transparent.frag");
|
||||
if (SkinnedMeshShader* sms = dynamic_cast<SkinnedMeshShader*>(this))
|
||||
{
|
||||
sms->init(this);
|
||||
}
|
||||
assignUniforms("ModelMatrix", "texture_trans", "skinning_offset", "custom_alpha");
|
||||
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
|
||||
} // SkinnedTransparentShader
|
||||
|
||||
// ============================================================================
|
||||
Shaders::TransparentShader::TransparentShader()
|
||||
{
|
||||
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
|
||||
GL_FRAGMENT_SHADER, "transparent.frag");
|
||||
assignUniforms("ModelMatrix", "texture_trans", "custom_alpha");
|
||||
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
|
||||
} // TransparentShader
|
||||
|
||||
// ============================================================================
|
||||
Shaders::TransparentFogShader::TransparentFogShader()
|
||||
{
|
||||
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
|
||||
GL_FRAGMENT_SHADER, "transparentfog.frag");
|
||||
assignUniforms("ModelMatrix", "texture_trans", "fogmax", "startH",
|
||||
"endH", "start", "end", "col");
|
||||
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
|
||||
} // TransparentFogShader
|
||||
|
||||
// ============================================================================
|
||||
Shaders::ColoredLine::ColoredLine()
|
||||
{
|
||||
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
|
||||
loadProgram(OBJECT, GL_VERTEX_SHADER, "sp_pass.vert",
|
||||
GL_FRAGMENT_SHADER, "coloredquad.frag");
|
||||
|
||||
assignUniforms("color");
|
||||
@ -316,11 +31,23 @@ Shaders::ColoredLine::ColoredLine()
|
||||
glBindVertexArray(m_vao);
|
||||
glGenBuffers(1, &m_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, 6 * 1024 * sizeof(float), 0, GL_DYNAMIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, 6 * 1024 * sizeof(float), 0,
|
||||
GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);
|
||||
for (int i = 1; i < 16; i++)
|
||||
{
|
||||
glDisableVertexAttribArray(i);
|
||||
}
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
} // Shaders::ColoredLine
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
Shaders::ColoredLine::~ColoredLine()
|
||||
{
|
||||
glDeleteVertexArrays(1, &m_vao);
|
||||
glDeleteBuffers(1, &m_vbo);
|
||||
} // ~Shaders::ColoredLine
|
||||
|
||||
#endif // !SERVER_ONLY
|
||||
|
@ -21,134 +21,38 @@
|
||||
#define HEADER_SHADERS_HPP
|
||||
|
||||
#include "graphics/shader.hpp"
|
||||
#include "graphics/shared_gpu_objects.hpp"
|
||||
#include "graphics/texture_shader.hpp"
|
||||
|
||||
#include <IMeshSceneNode.h>
|
||||
#include <IShaderConstantSetCallBack.h>
|
||||
#include <EMaterialTypes.h>
|
||||
#include <SColor.h>
|
||||
|
||||
|
||||
using namespace irr;
|
||||
class ParticleSystemProxy;
|
||||
|
||||
#define FOREACH_SHADER(ACT) \
|
||||
ACT(ES_NORMAL_MAP) \
|
||||
ACT(ES_NORMAL_MAP_LIGHTMAP) \
|
||||
ACT(ES_SKYBOX) \
|
||||
ACT(ES_SPLATTING) \
|
||||
ACT(ES_WATER) \
|
||||
ACT(ES_WATER_SURFACE) \
|
||||
ACT(ES_SPHERE_MAP) \
|
||||
ACT(ES_GRASS) \
|
||||
ACT(ES_GRASS_REF) \
|
||||
ACT(ES_MOTIONBLUR) \
|
||||
ACT(ES_GAUSSIAN3H) \
|
||||
ACT(ES_GAUSSIAN3V) \
|
||||
ACT(ES_MIPVIZ) \
|
||||
ACT(ES_OBJECT_UNLIT) \
|
||||
ACT(ES_OBJECTPASS) \
|
||||
ACT(ES_OBJECTPASS_REF) \
|
||||
ACT(ES_OBJECTPASS_RIMLIT) \
|
||||
ACT(ES_DISPLACE) \
|
||||
|
||||
#define ENUM(a) a,
|
||||
|
||||
enum ShaderType
|
||||
namespace Shaders
|
||||
{
|
||||
FOREACH_SHADER(ENUM)
|
||||
ES_COUNT
|
||||
};
|
||||
#undef ENUM
|
||||
|
||||
|
||||
class Shaders
|
||||
// ========================================================================
|
||||
/** Shader to draw a colored line.
|
||||
*/
|
||||
class ColoredLine : public Shader<ColoredLine, irr::video::SColor>
|
||||
{
|
||||
private:
|
||||
static const char *shader_names[];
|
||||
static bool m_has_been_initialised;
|
||||
|
||||
static int m_shaders[ES_COUNT];
|
||||
|
||||
static video::IShaderConstantSetCallBack *m_callbacks[ES_COUNT];
|
||||
|
||||
static void check(const int num);
|
||||
static void loadShaders();
|
||||
GLuint m_vao, m_vbo;
|
||||
public:
|
||||
static void init();
|
||||
static void destroy();
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the material type of a shader.
|
||||
* \param num The shader type.
|
||||
*/
|
||||
static video::E_MATERIAL_TYPE getShader(const ShaderType num)
|
||||
ColoredLine();
|
||||
// --------------------------------------------------------------------
|
||||
~ColoredLine();
|
||||
// --------------------------------------------------------------------
|
||||
/** Bind the vertex array of this shader. */
|
||||
void bindVertexArray()
|
||||
{
|
||||
assert(m_has_been_initialised);
|
||||
assert(num < ES_COUNT);
|
||||
return (video::E_MATERIAL_TYPE)m_shaders[num];
|
||||
} // getShader
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the callback for the specified shader type.
|
||||
*/
|
||||
static video::IShaderConstantSetCallBack* getCallback(const ShaderType num)
|
||||
glBindVertexArray(m_vao);
|
||||
glVertexAttrib4f(8, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glVertexAttrib4f(9, 0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glVertexAttrib4f(10, 1.0f, 1.0f, 1.0f, 1.0f);
|
||||
} // bindVertexArray
|
||||
// --------------------------------------------------------------------
|
||||
/** Binds the vbo of this shader. */
|
||||
void bindBuffer()
|
||||
{
|
||||
return m_has_been_initialised ? m_callbacks[num] : NULL;
|
||||
} // getCallback
|
||||
|
||||
// ========================================================================
|
||||
/** Shader to draw a colored line.
|
||||
*/
|
||||
class ColoredLine : public Shader<ColoredLine, video::SColor>
|
||||
{
|
||||
private:
|
||||
GLuint m_vao, m_vbo;
|
||||
public:
|
||||
ColoredLine();
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
/** Bind the vertex array of this shader. */
|
||||
void bindVertexArray()
|
||||
{
|
||||
glBindVertexArray(m_vao);
|
||||
} // bindVertexArray
|
||||
// --------------------------------------------------------------------
|
||||
/** Binds the vbo of this shader. */
|
||||
void bindBuffer()
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
||||
} // bindBuffer
|
||||
}; // class ColoredLine
|
||||
|
||||
// ========================================================================
|
||||
class TransparentShader : public TextureShader<TransparentShader, 1,
|
||||
core::matrix4, core::vector2df,
|
||||
float >
|
||||
{
|
||||
public:
|
||||
TransparentShader();
|
||||
}; // TransparentShader
|
||||
|
||||
// ========================================================================
|
||||
class TransparentFogShader : public TextureShader<TransparentFogShader, 1,
|
||||
core::matrix4, core::vector2df, float, float,
|
||||
float, float, float, video::SColorf >
|
||||
{
|
||||
public:
|
||||
TransparentFogShader();
|
||||
}; // TransparentFogShader
|
||||
// ========================================================================
|
||||
class SkinnedTransparentShader : public TextureShader<SkinnedTransparentShader, 1,
|
||||
core::matrix4, core::vector2df,
|
||||
int, float >,
|
||||
public SkinnedMeshShader
|
||||
{
|
||||
public:
|
||||
SkinnedTransparentShader();
|
||||
}; // SkinnedTransparentShader
|
||||
|
||||
// ========================================================================
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
||||
} // bindBuffer
|
||||
}; // class ColoredLine
|
||||
|
||||
}; // class Shaders
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
#ifndef HEADER_SP_MESH_NODE_HPP
|
||||
#define HEADER_SP_MESH_NODE_HPP
|
||||
|
||||
#include "../../lib/irrlicht/source/Irrlicht/CAnimatedMeshSceneNode.h"
|
||||
#include "../../../lib/irrlicht/source/Irrlicht/CAnimatedMeshSceneNode.h"
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
@ -1,96 +0,0 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013-2015 Lauri Kasanen
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef SERVER_ONLY
|
||||
|
||||
#include "graphics/water.hpp"
|
||||
|
||||
#include "graphics/callbacks.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
|
||||
using namespace video;
|
||||
using namespace scene;
|
||||
using namespace core;
|
||||
|
||||
WaterNode::WaterNode(scene::ISceneManager* mgr, IMesh *mesh, float height, float speed,
|
||||
float length):
|
||||
IMeshSceneNode(mgr->getRootSceneNode(), mgr, -1)
|
||||
{
|
||||
m_mat = mesh->getMeshBuffer(0)->getMaterial();
|
||||
|
||||
m_mat.Lighting = false;
|
||||
|
||||
if (m_mat.MaterialType != Shaders::getShader(ES_WATER))
|
||||
{
|
||||
m_mat.MaterialType = Shaders::getShader(ES_WATER_SURFACE);
|
||||
} else
|
||||
{
|
||||
m_mat.BlendOperation = EBO_ADD;
|
||||
}
|
||||
|
||||
m_mat.setFlag(EMF_ZWRITE_ENABLE, false);
|
||||
|
||||
m_mesh = mesh;
|
||||
mesh->grab();
|
||||
mesh->setHardwareMappingHint(EHM_STATIC);
|
||||
m_box = mesh->getBoundingBox();
|
||||
|
||||
m_height = height;
|
||||
m_speed = speed;
|
||||
m_length = length;
|
||||
}
|
||||
|
||||
WaterNode::~WaterNode()
|
||||
{
|
||||
m_mesh->drop();
|
||||
}
|
||||
|
||||
void WaterNode::render()
|
||||
{
|
||||
if (SceneManager->getSceneNodeRenderPass() != scene::ESNRP_TRANSPARENT)
|
||||
return;
|
||||
|
||||
WaterShaderProvider * const cb =
|
||||
(WaterShaderProvider *) Shaders::getCallback(ES_WATER);
|
||||
cb->setSpeed(m_speed);
|
||||
cb->setHeight(m_height);
|
||||
cb->setLength(m_length);
|
||||
|
||||
IVideoDriver * const drv = irr_driver->getVideoDriver();
|
||||
drv->setTransform(ETS_WORLD, AbsoluteTransformation);
|
||||
drv->setMaterial(m_mat);
|
||||
|
||||
const u32 max = m_mesh->getMeshBufferCount();
|
||||
for (u32 i = 0; i < max; i++)
|
||||
{
|
||||
drv->drawMeshBuffer(m_mesh->getMeshBuffer(i));
|
||||
}
|
||||
}
|
||||
|
||||
void WaterNode::OnRegisterSceneNode()
|
||||
{
|
||||
if (IsVisible)
|
||||
{
|
||||
SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
|
||||
ISceneNode::OnRegisterSceneNode();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !SERVER_ONLY
|
||||
|
@ -1,70 +0,0 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013-2015 Lauri Kasanen
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_WATER_HPP
|
||||
#define HEADER_WATER_HPP
|
||||
|
||||
#include <IMeshSceneNode.h>
|
||||
#include <utils/cpp2011.hpp>
|
||||
|
||||
using namespace irr;
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace scene { class IMesh; }
|
||||
}
|
||||
|
||||
// The actual node
|
||||
class WaterNode: public scene::IMeshSceneNode
|
||||
{
|
||||
public:
|
||||
WaterNode(scene::ISceneManager* mgr, scene::IMesh *mesh, float height, float speed,
|
||||
float length);
|
||||
virtual ~WaterNode();
|
||||
|
||||
virtual void render() OVERRIDE;
|
||||
|
||||
virtual const core::aabbox3d<f32>& getBoundingBox() const OVERRIDE
|
||||
{
|
||||
return m_box;
|
||||
}
|
||||
|
||||
virtual void OnRegisterSceneNode() OVERRIDE;
|
||||
|
||||
virtual u32 getMaterialCount() const OVERRIDE { return 1; }
|
||||
virtual video::SMaterial& getMaterial(u32 i) OVERRIDE { return m_mat; }
|
||||
|
||||
virtual scene::ESCENE_NODE_TYPE getType() const OVERRIDE { return scene::ESNT_MESH; }
|
||||
|
||||
virtual void setMesh(scene::IMesh *) OVERRIDE {}
|
||||
virtual scene::IMesh *getMesh() OVERRIDE { return m_mesh; }
|
||||
virtual void setReadOnlyMaterials(bool) OVERRIDE {}
|
||||
virtual bool isReadOnlyMaterials() const OVERRIDE { return false; }
|
||||
|
||||
protected:
|
||||
video::SMaterial m_mat;
|
||||
core::aabbox3df m_box;
|
||||
|
||||
scene::IMesh *m_mesh;
|
||||
|
||||
float m_height;
|
||||
float m_speed;
|
||||
float m_length;
|
||||
};
|
||||
|
||||
#endif
|
@ -198,8 +198,6 @@ void Attachment::set(AttachmentType type, float time,
|
||||
}
|
||||
m_node->setVisible(true);
|
||||
#ifndef SERVER_ONLY
|
||||
irr_driver->applyObjectPassShader(m_node);
|
||||
|
||||
// Save event about the new attachment
|
||||
RewindManager *rwm = RewindManager::get();
|
||||
if(rwm->isEnabled() && !rwm->isRewinding())
|
||||
|
@ -79,7 +79,6 @@ Flyable::Flyable(AbstractKart *kart, PowerupManager::PowerupType type,
|
||||
// Add the graphical model
|
||||
#ifndef SERVER_ONLY
|
||||
setNode(irr_driver->addMesh(m_st_model[type], StringUtils::insertValues("flyable_%i", (int)type)));
|
||||
irr_driver->applyObjectPassShader(getNode());
|
||||
#ifdef DEBUG
|
||||
std::string debug_name("flyable: ");
|
||||
debug_name += type;
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "karts/explosion_animation.hpp"
|
||||
|
||||
#include "audio/sfx_manager.hpp"
|
||||
#include "graphics/callbacks.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
#include "items/attachment.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
#include "karts/rescue_animation.hpp"
|
||||
|
||||
#include "graphics/callbacks.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "graphics/camera.hpp"
|
||||
#include "graphics/referee.hpp"
|
||||
#include "items/attachment.hpp"
|
||||
|
@ -222,11 +222,6 @@ void World::init()
|
||||
// Load other custom models if needed
|
||||
loadCustomModels();
|
||||
|
||||
#ifndef SERVER_ONLY
|
||||
// Now that all models are loaded, apply the overrides
|
||||
irr_driver->applyObjectPassShader();
|
||||
#endif
|
||||
|
||||
// Must be called after all karts are created
|
||||
m_race_gui->init();
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "karts/explosion_animation.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/light.hpp"
|
||||
#include "graphics/shaders.hpp"
|
||||
#include "graphics/shader.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "graphics/sp/sp_base.hpp"
|
||||
#include "graphics/sp/sp_texture_manager.hpp"
|
||||
@ -250,7 +250,7 @@ bool handleContextMenuAction(s32 cmd_id)
|
||||
#ifndef SERVER_ONLY
|
||||
Log::info("Debug", "Reloading shaders...");
|
||||
ShaderFilesManager::getInstance()->clean();
|
||||
ShaderBase::updateShaders();
|
||||
ShaderBase::killShaders();
|
||||
#endif
|
||||
break;
|
||||
case DEBUG_GRAPHICS_RESET:
|
||||
|
Loading…
x
Reference in New Issue
Block a user