This commit is contained in:
Benau 2017-10-15 19:14:07 +08:00
parent a7debc286a
commit 4573e51e98
21 changed files with 114 additions and 296 deletions

View File

@ -3,6 +3,7 @@ uniform sampler2D dtex;
in vec2 tc; in vec2 tc;
in vec4 pc; in vec4 pc;
flat in float billboard_mix;
out vec4 FragColor; out vec4 FragColor;
#stk_include "utils/getPosFromUVDepth.frag" #stk_include "utils/getPosFromUVDepth.frag"
@ -15,5 +16,6 @@ void main(void)
float EnvZ = texture(dtex, xy).x; float EnvZ = texture(dtex, xy).x;
vec4 EnvPos = getPosFromUVDepth(vec3(xy, EnvZ), InverseProjectionMatrix); vec4 EnvPos = getPosFromUVDepth(vec3(xy, EnvZ), InverseProjectionMatrix);
float alpha = clamp((EnvPos.z - FragmentPos.z) * 0.3, 0., 1.); float alpha = clamp((EnvPos.z - FragmentPos.z) * 0.3, 0., 1.);
FragColor = texture(tex, tc) * pc * alpha; float billboard_alpha = mix(1.0, texture(tex, tc).a, billboard_mix);
FragColor = texture(tex, tc) * billboard_alpha * pc * alpha;
} }

View File

@ -1,4 +1,5 @@
uniform int flips; uniform int flips;
uniform float billboard;
#ifdef Explicit_Attrib_Location_Usable #ifdef Explicit_Attrib_Location_Usable
@ -22,6 +23,7 @@ in vec2 quadcorner;
in float anglespeed; in float anglespeed;
#endif #endif
flat out float billboard_mix;
out vec2 tc; out vec2 tc;
out vec4 pc; out vec4 pc;
@ -32,11 +34,14 @@ void main(void)
gl_Position = vec4(0.); gl_Position = vec4(0.);
pc = vec4(0.0); pc = vec4(0.0);
tc = vec2(0.0); tc = vec2(0.0);
billboard_mix = 0.0;
return; return;
} }
float lifetime = color_lifetime.w; float lifetime = color_lifetime.w;
pc = vec4(color_lifetime.zyx, 1.0) * smoothstep(1.0, 0.8, lifetime); float alpha = mix(smoothstep(1.0, 0.8, lifetime), lifetime, billboard);
billboard_mix = billboard;
pc = vec4(color_lifetime.zyx, 1.0) * alpha;
tc = Texcoord; tc = Texcoord;
#if !defined(sRGB_Framebuffer_Usable) && !defined(Advanced_Lighting_Enabled) #if !defined(sRGB_Framebuffer_Usable) && !defined(Advanced_Lighting_Enabled)

View File

@ -1,5 +1,5 @@
# Modify this file to change the last-modified date when you add/remove a file. # Modify this file to change the last-modified date when you add/remove a file.
# This will then trigger a new cmake run automatically. # This will then trigger a new cmake run automatically.
file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp") file(GLOB_RECURSE STK_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.hpp")
file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp") file(GLOB_RECURSE STK_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.cpp")
file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*") file(GLOB_RECURSE STK_SHADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "data/shaders/*")

View File

@ -32,7 +32,7 @@
// ============================================================================ // ============================================================================
/** A Shader to render particles. /** A Shader to render particles.
*/ */
class ParticleRenderer : public TextureShader<ParticleRenderer, 2, int> class ParticleRenderer : public TextureShader<ParticleRenderer, 2, int, float>
{ {
public: public:
ParticleRenderer() ParticleRenderer()
@ -40,7 +40,7 @@ public:
loadProgram(PARTICLES_RENDERING, loadProgram(PARTICLES_RENDERING,
GL_VERTEX_SHADER, "simple_particle.vert", GL_VERTEX_SHADER, "simple_particle.vert",
GL_FRAGMENT_SHADER, "simple_particle.frag"); GL_FRAGMENT_SHADER, "simple_particle.frag");
assignUniforms("flips"); assignUniforms("flips", "billboard");
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED, assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED,
1, "dtex", ST_NEAREST_FILTERED); 1, "dtex", ST_NEAREST_FILTERED);
} // ParticleRenderer } // ParticleRenderer
@ -91,7 +91,7 @@ void CPUParticleManager::addParticleNode(STKParticle* node)
m_material_map[tex_name] = m; m_material_map[tex_name] = m;
if (m == NULL) if (m == NULL)
{ {
Log::error("CPUParticleManager", "Missing material"); Log::error("CPUParticleManager", "Missing material for particle");
} }
} }
m = m_material_map.at(tex_name); m = m_material_map.at(tex_name);
@ -106,6 +106,34 @@ void CPUParticleManager::addParticleNode(STKParticle* node)
m_particles_queue[tex_name].push_back(node); m_particles_queue[tex_name].push_back(node);
} // addParticleNode } // addParticleNode
// ----------------------------------------------------------------------------
void CPUParticleManager::addBillboardNode(scene::IBillboardSceneNode* node)
{
video::ITexture* t = node->getMaterial(0).getTexture(0);
if (t == NULL)
{
return;
}
std::string tex_name = t->getName().getPtr();
tex_name = std::string("_bb_") + tex_name;
Material* m = NULL;
if (m_material_map.find(tex_name) == m_material_map.end())
{
m = material_manager->getMaterialFor(t);
m_material_map[tex_name] = m;
if (m == NULL)
{
Log::error("CPUParticleManager", "Missing material for billboard");
}
}
m = m_material_map.at(tex_name);
if (m == NULL)
{
return;
}
m_billboards_queue[tex_name].push_back(node);
} // addBillboardNode
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void CPUParticleManager::generateAll() void CPUParticleManager::generateAll()
{ {
@ -126,6 +154,17 @@ void CPUParticleManager::generateAll()
m_particles_queue.at(p.first)[0]->getMaxCount())); m_particles_queue.at(p.first)[0]->getMaxCount()));
} }
} }
for (auto& p : m_billboards_queue)
{
if (p.second.empty())
{
continue;
}
for (auto& q : p.second)
{
m_particles_generated[p.first].emplace_back(q);
}
}
} // generateAll } // generateAll
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -220,6 +259,7 @@ void CPUParticleManager::drawAll()
for (auto& p : particle_drawn) for (auto& p : particle_drawn)
{ {
const bool flips = isFlipsMaterial(p.second); const bool flips = isFlipsMaterial(p.second);
const float billboard = p.second.substr(0, 4) == "_bb_" ? 1.0f : 0.0f;
Material* cur_mat = p.first; Material* cur_mat = p.first;
if (cur_mat->getShaderType() != st) if (cur_mat->getShaderType() != st)
{ {
@ -264,7 +304,7 @@ void CPUParticleManager::drawAll()
ParticleRenderer::getInstance()->setTextureUnits ParticleRenderer::getInstance()->setTextureUnits
(cur_mat->getTexture()->getOpenGLTextureName(), (cur_mat->getTexture()->getOpenGLTextureName(),
irr_driver->getDepthStencilTexture()); irr_driver->getDepthStencilTexture());
ParticleRenderer::getInstance()->setUniforms(flips); ParticleRenderer::getInstance()->setUniforms(flips, billboard);
} }
else else
{ {

View File

@ -26,6 +26,7 @@
#include "utils/singleton.hpp" #include "utils/singleton.hpp"
#include <dimension2d.h> #include <dimension2d.h>
#include <IBillboardSceneNode.h>
#include <vector3d.h> #include <vector3d.h>
#include <SColor.h> #include <SColor.h>
@ -57,6 +58,15 @@ struct CPUParticle
m_size[0] = MiniGLM::toFloat16(size); m_size[0] = MiniGLM::toFloat16(size);
m_size[1] = m_size[0]; m_size[1] = m_size[0];
} }
// ------------------------------------------------------------------------
CPUParticle(scene::IBillboardSceneNode* node)
{
m_position = node->getAbsolutePosition();
video::SColor unused_bottom;
node->getColor(m_color_lifetime, unused_bottom);
m_size[0] = MiniGLM::toFloat16(node->getSize().Width);
m_size[1] = MiniGLM::toFloat16(node->getSize().Height);
}
}; };
class STKParticle; class STKParticle;
@ -68,6 +78,9 @@ private:
std::unordered_map<std::string, std::vector<STKParticle*> > std::unordered_map<std::string, std::vector<STKParticle*> >
m_particles_queue; m_particles_queue;
std::unordered_map<std::string, std::vector<scene::IBillboardSceneNode*> >
m_billboards_queue;
std::unordered_map<std::string, std::vector<CPUParticle> > std::unordered_map<std::string, std::vector<CPUParticle> >
m_particles_generated; m_particles_generated;
@ -90,6 +103,8 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void addParticleNode(STKParticle* node); void addParticleNode(STKParticle* node);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void addBillboardNode(scene::IBillboardSceneNode* node);
// ------------------------------------------------------------------------
void generateAll(); void generateAll();
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void uploadAll(); void uploadAll();
@ -102,6 +117,10 @@ public:
{ {
p.second.clear(); p.second.clear();
} }
for (auto& p : m_billboards_queue)
{
p.second.clear();
}
for (auto& p : m_particles_generated) for (auto& p : m_particles_generated)
{ {
p.second.clear(); p.second.clear();

View File

@ -28,7 +28,6 @@
#include "graphics/shadow_matrices.hpp" #include "graphics/shadow_matrices.hpp"
#include "graphics/shaders.hpp" #include "graphics/shaders.hpp"
#include "graphics/stk_animated_mesh.hpp" #include "graphics/stk_animated_mesh.hpp"
#include "graphics/stk_billboard.hpp"
#include "graphics/stk_mesh.hpp" #include "graphics/stk_mesh.hpp"
#include "graphics/stk_particle.hpp" #include "graphics/stk_particle.hpp"
#include "tracks/track.hpp" #include "tracks/track.hpp"
@ -63,8 +62,6 @@ void DrawCalls::clearLists()
ListMatSplatting::getInstance()->clear(); ListMatSplatting::getInstance()->clear();
m_immediate_draw_list.clear(); m_immediate_draw_list.clear();
m_billboard_list.clear();
m_particles_list.clear();
CPUParticleManager::getInstance()->reset(); CPUParticleManager::getInstance()->reset();
} }
@ -571,10 +568,11 @@ void DrawCalls::parseSceneManager(core::list<scene::ISceneNode*> &List,
continue; continue;
} }
if (STKBillboard *node = dynamic_cast<STKBillboard *>(*I)) if (scene::IBillboardSceneNode *node =
dynamic_cast<scene::IBillboardSceneNode *>(*I))
{ {
if (!isCulledPrecise(cam, *I)) if (!isCulledPrecise(cam, *I))
m_billboard_list.push_back(node); CPUParticleManager::getInstance()->addBillboardNode(node);
continue; continue;
} }
@ -725,14 +723,6 @@ void DrawCalls::renderImmediateDrawList() const
node->render(); node->render();
} }
// ----------------------------------------------------------------------------
void DrawCalls::renderBillboardList() const
{
glActiveTexture(GL_TEXTURE0);
for(auto billboard: m_billboard_list)
billboard->render();
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void DrawCalls::renderParticlesList() const void DrawCalls::renderParticlesList() const
{ {

View File

@ -26,13 +26,11 @@
#include <unordered_map> #include <unordered_map>
class GlowCommandBuffer; class GlowCommandBuffer;
class ParticleSystemProxy;
class ReflectiveShadowMapCommandBuffer; class ReflectiveShadowMapCommandBuffer;
class ShadowMatrices; class ShadowMatrices;
class ShadowCommandBuffer; class ShadowCommandBuffer;
class SolidCommandBuffer; class SolidCommandBuffer;
class STKAnimatedMesh; class STKAnimatedMesh;
class STKBillboard;
class STKMeshCommon; class STKMeshCommon;
class DrawCalls class DrawCalls
@ -43,8 +41,6 @@ private:
GLsync m_sync; GLsync m_sync;
std::vector<irr::scene::ISceneNode *> m_immediate_draw_list; std::vector<irr::scene::ISceneNode *> m_immediate_draw_list;
std::vector<STKBillboard *> m_billboard_list;
std::vector<ParticleSystemProxy *> m_particles_list;
std::set<STKAnimatedMesh*> m_mesh_for_skinning; std::set<STKAnimatedMesh*> m_mesh_for_skinning;
std::vector<float> m_bounding_boxes; std::vector<float> m_bounding_boxes;
@ -96,7 +92,6 @@ public:
void setFenceSync() { m_sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } void setFenceSync() { m_sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); }
void renderImmediateDrawList() const; void renderImmediateDrawList() const;
void renderBillboardList() const;
void renderParticlesList() const; void renderParticlesList() const;
void drawIndirectSolidFirstPass() const; void drawIndirectSolidFirstPass() const;

View File

@ -299,8 +299,6 @@ void AbstractGeometryPasses::renderTransparent(const DrawCalls& draw_calls,
ListAdditiveTransparent::getInstance()); ListAdditiveTransparent::getInstance());
} }
draw_calls.renderBillboardList();
if (!CVS->isDefferedEnabled()) if (!CVS->isDefferedEnabled())
return; return;

View File

@ -35,7 +35,6 @@
#include "graphics/shader_based_renderer.hpp" #include "graphics/shader_based_renderer.hpp"
#include "graphics/shaders.hpp" #include "graphics/shaders.hpp"
#include "graphics/stk_animated_mesh.hpp" #include "graphics/stk_animated_mesh.hpp"
#include "graphics/stk_billboard.hpp"
#include "graphics/stk_mesh_loader.hpp" #include "graphics/stk_mesh_loader.hpp"
#include "graphics/sp_mesh_loader.hpp" #include "graphics/sp_mesh_loader.hpp"
#include "graphics/stk_mesh_scene_node.hpp" #include "graphics/stk_mesh_scene_node.hpp"
@ -1203,33 +1202,36 @@ PerCameraNode *IrrDriver::addPerCameraNode(scene::ISceneNode* node,
m_scene_manager, -1, camera, node); m_scene_manager, -1, camera, node);
} // addNode } // addNode
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/** Adds a billboard node to scene. /** Adds a billboard node to scene.
*/ */
scene::ISceneNode *IrrDriver::addBillboard(const core::dimension2d< f32 > size, scene::ISceneNode *IrrDriver::addBillboard(const core::dimension2d< f32 > size,
video::ITexture *texture, const std::string& tex_name,
scene::ISceneNode* parent, scene::ISceneNode* parent)
bool alphaTesting)
{ {
scene::IBillboardSceneNode* node; scene::IBillboardSceneNode* node;
#ifndef SERVER_ONLY node = m_scene_manager->addBillboardSceneNode(parent, size);
if (CVS->isGLSL())
{ const bool full_path = tex_name.find('/') != std::string::npos;
if (!parent)
parent = m_scene_manager->getRootSceneNode(); Material* m = material_manager->getMaterial(tex_name, full_path,
/*make_permanent*/false, /*complain_if_not_found*/true,
/*strip_path*/full_path, /*install*/false);
video::ITexture* tex = m->getTexture(true/*srgb*/,
m->getShaderType() == Material::SHADERTYPE_ADDITIVE ||
m->getShaderType() == Material::SHADERTYPE_ALPHA_BLEND ?
true : false/*premul_alpha*/);
node = new STKBillboard(parent, m_scene_manager, -1,
vector3df(0., 0., 0.), size);
node->drop();
}
else
#endif
node = m_scene_manager->addBillboardSceneNode(parent, size);
assert(node->getMaterialCount() > 0); assert(node->getMaterialCount() > 0);
node->setMaterialTexture(0, texture); node->setMaterialTexture(0, tex);
if(alphaTesting) if (!(m->getShaderType() == Material::SHADERTYPE_ADDITIVE ||
node->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF); m->getShaderType() == Material::SHADERTYPE_ALPHA_BLEND))
{
// Alpha test for billboard otherwise
m->setShaderType(Material::SHADERTYPE_ALPHA_TEST);
}
m->setMaterialProperties(&(node->getMaterial(0)), NULL);
return node; return node;
} // addBillboard } // addBillboard

View File

@ -245,9 +245,8 @@ public:
scene::ICameraSceneNode* cam, scene::ICameraSceneNode* cam,
scene::ISceneNode *parent = NULL); scene::ISceneNode *parent = NULL);
scene::ISceneNode *addBillboard(const core::dimension2d< f32 > size, scene::ISceneNode *addBillboard(const core::dimension2d< f32 > size,
video::ITexture *texture, const std::string& tex_name,
scene::ISceneNode* parent=NULL, bool alphaTesting = false); scene::ISceneNode* parent=NULL);
scene::IParticleSystemSceneNode scene::IParticleSystemSceneNode
*addParticleNode(bool default_emitter=true); *addParticleNode(bool default_emitter=true);
scene::ISceneNode *addSkyDome(video::ITexture *texture, int hori_res, scene::ISceneNode *addSkyDome(video::ITexture *texture, int hori_res,

View File

@ -330,7 +330,7 @@ Material *MaterialManager::getMaterial(const std::string& fname,
bool is_full_path, bool is_full_path,
bool make_permanent, bool make_permanent,
bool complain_if_not_found, bool complain_if_not_found,
bool strip_path) bool strip_path, bool install)
{ {
if(fname=="") if(fname=="")
{ {
@ -361,7 +361,7 @@ Material *MaterialManager::getMaterial(const std::string& fname,
} }
// Add the new material // Add the new material
Material* m = new Material(fname, is_full_path, complain_if_not_found); Material* m = new Material(fname, is_full_path, complain_if_not_found, install);
m_materials.push_back(m); m_materials.push_back(m);
if(make_permanent) if(make_permanent)
{ {

View File

@ -76,7 +76,7 @@ public:
bool is_full_path=false, bool is_full_path=false,
bool make_permanent=false, bool make_permanent=false,
bool complain_if_not_found=true, bool complain_if_not_found=true,
bool strip_path=true); bool strip_path=true, bool install=true);
void addSharedMaterial(const std::string& filename, bool deprecated = false); void addSharedMaterial(const std::string& filename, bool deprecated = false);
bool pushTempMaterial (const std::string& filename, bool deprecated = false); bool pushTempMaterial (const std::string& filename, bool deprecated = false);
bool pushTempMaterial (const XMLNode *root, const std::string& filename, bool deprecated = false); bool pushTempMaterial (const XMLNode *root, const std::string& filename, bool deprecated = false);

View File

@ -33,7 +33,6 @@
#include "graphics/rtts.hpp" #include "graphics/rtts.hpp"
#include "graphics/shaders.hpp" #include "graphics/shaders.hpp"
#include "graphics/skybox.hpp" #include "graphics/skybox.hpp"
#include "graphics/stk_billboard.hpp"
#include "graphics/stk_mesh_scene_node.hpp" #include "graphics/stk_mesh_scene_node.hpp"
#include "graphics/spherical_harmonics.hpp" #include "graphics/spherical_harmonics.hpp"
#include "items/item_manager.hpp" #include "items/item_manager.hpp"
@ -663,7 +662,6 @@ ShaderBasedRenderer::~ShaderBasedRenderer()
delete m_skybox; delete m_skybox;
delete m_rtts; delete m_rtts;
ShaderFilesManager::kill(); ShaderFilesManager::kill();
STKBillboard::destroyBillboardVAO();
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -963,8 +961,6 @@ void ShaderBasedRenderer::preloadShaderFiles()
(GraphicsRestrictions::GR_FRAMEBUFFER_SRGB_WORKAROUND1)) (GraphicsRestrictions::GR_FRAMEBUFFER_SRGB_WORKAROUND1))
sfm->addShaderFile("passthrough.frag", GL_FRAGMENT_SHADER); sfm->addShaderFile("passthrough.frag", GL_FRAGMENT_SHADER);
sfm->addShaderFile("billboard.vert", GL_VERTEX_SHADER);
sfm->addShaderFile("billboard.frag", GL_FRAGMENT_SHADER);
sfm->addShaderFile("alphatest_particle.vert", GL_VERTEX_SHADER); sfm->addShaderFile("alphatest_particle.vert", GL_VERTEX_SHADER);
sfm->addShaderFile("alphatest_particle.frag", GL_FRAGMENT_SHADER); sfm->addShaderFile("alphatest_particle.frag", GL_FRAGMENT_SHADER);
sfm->addShaderFile("simple_particle.vert", GL_VERTEX_SHADER); sfm->addShaderFile("simple_particle.vert", GL_VERTEX_SHADER);

View File

@ -199,10 +199,10 @@ void SharedGPUObjects::initParticleQuadVBO()
{ {
static const GLfloat QUAD_VERTEX[] = static const GLfloat QUAD_VERTEX[] =
{ {
-.5, -.5, 0., 0., -.5, .5, 0., 0.,
.5, -.5, 1., 0., .5, .5, 1., 0.,
-.5, .5, 0., 1., -.5, -.5, 0., 1.,
.5, .5, 1., 1., .5, -.5, 1., 1.,
}; };
glGenBuffers(1, &m_particle_quad_vbo); glGenBuffers(1, &m_particle_quad_vbo);
glBindBuffer(GL_ARRAY_BUFFER, m_particle_quad_vbo); glBindBuffer(GL_ARRAY_BUFFER, m_particle_quad_vbo);

View File

@ -19,9 +19,6 @@
#include "graphics/stars.hpp" #include "graphics/stars.hpp"
#include "graphics/irr_driver.hpp" #include "graphics/irr_driver.hpp"
#include "graphics/material.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/stk_tex_manager.hpp"
#include "karts/abstract_kart.hpp" #include "karts/abstract_kart.hpp"
#include "karts/kart_model.hpp" #include "karts/kart_model.hpp"
#include "utils/constants.hpp" #include "utils/constants.hpp"
@ -39,14 +36,6 @@ Stars::Stars(AbstractKart *kart)
{ {
m_parent_kart_node = kart->getNode(); m_parent_kart_node = kart->getNode();
m_enabled = false; m_enabled = false;
TexConfig stc(true/*srgb*/, true/*premul_alpha*/);
video::ITexture* texture = STKTexManager::getInstance()->getTexture
("starparticle.png", &stc);
Material* star_material =
material_manager->getMaterial("starparticle.png");
m_center = core::vector3df(0.0f, m_center = core::vector3df(0.0f,
kart->getKartModel()->getModel() kart->getKartModel()->getModel()
->getBoundingBox().MaxEdge.Y, ->getBoundingBox().MaxEdge.Y,
@ -56,12 +45,10 @@ Stars::Stars(AbstractKart *kart)
{ {
scene::ISceneNode* billboard = scene::ISceneNode* billboard =
irr_driver->addBillboard(core::dimension2df(STAR_SIZE, STAR_SIZE), irr_driver->addBillboard(core::dimension2df(STAR_SIZE, STAR_SIZE),
texture, kart->getNode()); "starparticle.png", kart->getNode());
#ifdef DEBUG #ifdef DEBUG
billboard->setName("star"); billboard->setName("star");
#endif #endif
star_material->setMaterialProperties(&(billboard->getMaterial(0)), NULL);
billboard->setMaterialTexture(0, star_material->getTexture());
billboard->setVisible(false); billboard->setVisible(false);

View File

@ -1,143 +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 SERVER_ONLY
#include "graphics/stk_billboard.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/shared_gpu_objects.hpp"
#include "graphics/texture_shader.hpp"
#include <ISceneManager.h>
using namespace irr;
GLuint STKBillboard::m_billboard_vao = 0;
class BillboardShader : public TextureShader<BillboardShader, 1,
core::matrix4, core::vector3df,
core::dimension2df>
{
public:
BillboardShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "billboard.vert",
GL_FRAGMENT_SHADER, "billboard.frag");
assignUniforms("color_matrix", "Position", "Size");
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // BillboardShader
}; // BillboardShader
// ============================================================================
void STKBillboard::createBillboardVAO()
{
glGenVertexArrays(1, &m_billboard_vao);
glBindVertexArray(m_billboard_vao);
glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getBillboardVBO());
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(3);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
(GLvoid*) (2 * sizeof(float)));
glBindVertexArray(0);
} // createBillboardVAO
// ----------------------------------------------------------------------------
void STKBillboard::destroyBillboardVAO()
{
if (m_billboard_vao != 0)
{
glDeleteVertexArrays(1, &m_billboard_vao);
m_billboard_vao = 0;
}
} // destroyBillboardVAO
// ----------------------------------------------------------------------------
STKBillboard::STKBillboard(irr::scene::ISceneNode* parent,
irr::scene::ISceneManager* mgr, irr::s32 id,
const irr::core::vector3df& position,
const irr::core::dimension2d<irr::f32>& size,
irr::video::SColor colorTop,
irr::video::SColor colorBottom)
: IBillboardSceneNode(parent, mgr, id, position),
CBillboardSceneNode(parent, mgr, id, position, size,
colorTop, colorBottom)
{
if (!m_billboard_vao)
createBillboardVAO();
} // STKBillboard
// ----------------------------------------------------------------------------
void STKBillboard::OnRegisterSceneNode()
{
if (IsVisible)
{
SceneManager->registerNodeForRendering(this, scene::ESNRP_TRANSPARENT);
}
ISceneNode::OnRegisterSceneNode();
} // OnRegisterSceneNode
// ----------------------------------------------------------------------------
void STKBillboard::render()
{
if (irr_driver->getPhase() != TRANSPARENT_PASS)
return;
core::vector3df pos = getAbsolutePosition();
glBindVertexArray(m_billboard_vao);
video::ITexture *tex = Material.getTexture(0);
if (!tex)
return;
::Material* material = material_manager->getMaterialFor(tex,
video::E_MATERIAL_TYPE::EMT_ONETEXTURE_BLEND);
if (material->getShaderType() == Material::SHADERTYPE_ADDITIVE)
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
else
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
video::SColor col[2];
getColor(col[0], col[1]);
const float colors[] =
{
col[1].getRed() / 255.f, col[1].getGreen() / 255.f,
col[1].getBlue() / 255.f, col[1].getAlpha() / 255.f,
col[0].getRed() / 255.f, col[0].getGreen() / 255.f,
col[0].getBlue() / 255.f, col[0].getAlpha() / 255.f,
col[1].getRed() / 255.f, col[1].getGreen() / 255.f,
col[1].getBlue() / 255.f, col[1].getAlpha() / 255.f,
col[0].getRed() / 255.f, col[0].getGreen() / 255.f,
col[0].getBlue() / 255.f, col[0].getAlpha() / 255.f,
};
core::matrix4 color_matrix;
color_matrix.setM(colors);
BillboardShader::getInstance()->use();
BillboardShader::getInstance()->setTextureUnits(tex->getOpenGLTextureName());
BillboardShader::getInstance()->setUniforms(color_matrix, pos, Size);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
} // render
#endif // !SERVER_ONLY

View File

@ -1,45 +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 STKBILLBOARD_HPP
#define STKBILLBOARD_HPP
#include "../lib/irrlicht/source/Irrlicht/CBillboardSceneNode.h"
#include <IBillboardSceneNode.h>
#include <irrTypes.h>
#include "graphics/gl_headers.hpp"
#include "utils/cpp2011.hpp"
class STKBillboard : public irr::scene::CBillboardSceneNode
{
private:
static GLuint m_billboard_vao;
static void createBillboardVAO();
public:
STKBillboard(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr,
irr::s32 id, const irr::core::vector3df& position,
const irr::core::dimension2d<irr::f32>& size,
irr::video::SColor colorTop = irr::video::SColor(0xFFFFFFFF),
irr::video::SColor colorBottom = irr::video::SColor(0xFFFFFFFF));
virtual void OnRegisterSceneNode() OVERRIDE;
virtual void render() OVERRIDE;
static void destroyBillboardVAO();
}; // STKBillboard
#endif

View File

@ -20,7 +20,6 @@
#include "graphics/stk_text_billboard.hpp" #include "graphics/stk_text_billboard.hpp"
#include "graphics/shaders.hpp" #include "graphics/shaders.hpp"
#include "graphics/irr_driver.hpp" #include "graphics/irr_driver.hpp"
#include "graphics/stk_billboard.hpp"
#include "graphics/stk_mesh_scene_node.hpp" #include "graphics/stk_mesh_scene_node.hpp"
#include "graphics/stk_tex_manager.hpp" #include "graphics/stk_tex_manager.hpp"
#include <SMesh.h> #include <SMesh.h>

View File

@ -25,7 +25,6 @@
#include "graphics/central_settings.hpp" #include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp" #include "graphics/irr_driver.hpp"
#include "graphics/render_info.hpp" #include "graphics/render_info.hpp"
#include "graphics/stk_tex_manager.hpp"
#include "karts/kart.hpp" #include "karts/kart.hpp"
#include "karts/kart_model.hpp" #include "karts/kart_model.hpp"
#include "karts/kart_properties.hpp" #include "karts/kart_properties.hpp"
@ -331,13 +330,6 @@ void SoccerWorld::initKartList()
std::string blue_path = std::string blue_path =
file_manager->getAsset(FileManager::GUI, "soccer_player_blue.png"); file_manager->getAsset(FileManager::GUI, "soccer_player_blue.png");
TexConfig btc(true/*srgb*/, true/*premul_alpha*/);
video::ITexture* red = STKTexManager::getInstance()->getTexture
(red_path, &btc);
video::ITexture* blue = STKTexManager::getInstance()->getTexture
(blue_path, &btc);
//Assigning indicators //Assigning indicators
for(unsigned int i = 0; i < kart_amount; i++) for(unsigned int i = 0; i < kart_amount; i++)
{ {
@ -351,9 +343,9 @@ void SoccerWorld::initKartList()
SoccerTeam team = getKartTeam(i); SoccerTeam team = getKartTeam(i);
arrow_node = irr_driver->addBillboard( arrow_node = irr_driver->addBillboard(
core::dimension2d<irr::f32>(0.3f,0.3f), core::dimension2d<irr::f32>(0.3f,0.3f),
team == SOCCER_TEAM_BLUE ? blue : red, team == SOCCER_TEAM_BLUE ? blue_path : red_path,
m_karts[i]->getNode(), true); m_karts[i]->getNode());
arrow_node->setPosition(core::vector3df(0, arrow_pos_height, 0)); arrow_node->setPosition(core::vector3df(0, arrow_pos_height, 0));
} }

View File

@ -22,7 +22,6 @@
#include "config/user_config.hpp" #include "config/user_config.hpp"
#include "graphics/camera.hpp" #include "graphics/camera.hpp"
#include "graphics/irr_driver.hpp" #include "graphics/irr_driver.hpp"
#include "graphics/stk_tex_manager.hpp"
#include "io/file_manager.hpp" #include "io/file_manager.hpp"
#include "karts/kart.hpp" #include "karts/kart.hpp"
#include "karts/controller/spare_tire_ai.hpp" #include "karts/controller/spare_tire_ai.hpp"
@ -179,15 +178,11 @@ void ThreeStrikesBattle::kartAdded(AbstractKart* kart, scene::ISceneNode* node)
// Add heart billboard above it // Add heart billboard above it
std::string heart_path = std::string heart_path =
file_manager->getAsset(FileManager::GUI, "heart.png"); file_manager->getAsset(FileManager::GUI, "heart.png");
TexConfig btc(true/*srgb*/, true/*premul_alpha*/);
video::ITexture* heart = STKTexManager::getInstance()->getTexture
(heart_path, &btc);
float height = kart->getKartHeight() + 0.5f; float height = kart->getKartHeight() + 0.5f;
scene::ISceneNode* billboard = irr_driver->addBillboard scene::ISceneNode* billboard = irr_driver->addBillboard
(core::dimension2d<irr::f32>(0.8f, 0.8f), heart, kart->getNode(), (core::dimension2d<irr::f32>(0.8f, 0.8f), heart_path,
true); kart->getNode());
billboard->setPosition(core::vector3df(0, height, 0)); billboard->setPosition(core::vector3df(0, height, 0));
return; return;
} }

View File

@ -32,7 +32,6 @@
#include "graphics/particle_kind_manager.hpp" #include "graphics/particle_kind_manager.hpp"
#include "graphics/stk_mesh_scene_node.hpp" #include "graphics/stk_mesh_scene_node.hpp"
#include "graphics/stk_particle.hpp" #include "graphics/stk_particle.hpp"
#include "graphics/stk_tex_manager.hpp"
#include "graphics/render_info.hpp" #include "graphics/render_info.hpp"
#include "io/file_manager.hpp" #include "io/file_manager.hpp"
#include "io/xml_node.hpp" #include "io/xml_node.hpp"
@ -823,20 +822,8 @@ TrackObjectPresentationBillboard::TrackObjectPresentationBillboard(
xml_node.get("start", &m_fade_out_start); xml_node.get("start", &m_fade_out_start);
xml_node.get("end", &m_fade_out_end ); xml_node.get("end", &m_fade_out_end );
} }
TexConfig tc(true/*srgb*/, true/*premul_alpha*/);
video::ITexture* texture = STKTexManager::getInstance()->getTexture
(file_manager->searchTexture(texture_name), &tc);
if (texture == NULL)
{
Log::warn("TrackObjectPresentation", "Billboard texture '%s' not found",
texture_name.c_str());
}
m_node = irr_driver->addBillboard(core::dimension2df(width, height), m_node = irr_driver->addBillboard(core::dimension2df(width, height),
texture, parent); texture_name, parent);
Material *stk_material = material_manager->getMaterial(texture_name);
stk_material->setMaterialProperties(&(m_node->getMaterial(0)), NULL);
m_node->setPosition(m_init_xyz); m_node->setPosition(m_init_xyz);
} // TrackObjectPresentationBillboard } // TrackObjectPresentationBillboard