Moved billboard shader into stkbillboard, cleaned up coding style somewhat.
This commit is contained in:
parent
f4cf41e466
commit
ee26611759
@ -591,15 +591,6 @@ namespace MeshShader
|
|||||||
assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
|
assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
|
||||||
}
|
}
|
||||||
|
|
||||||
BillboardShader::BillboardShader()
|
|
||||||
{
|
|
||||||
loadProgram(OBJECT,
|
|
||||||
GL_VERTEX_SHADER, "billboard.vert",
|
|
||||||
GL_FRAGMENT_SHADER, "billboard.frag");
|
|
||||||
|
|
||||||
assignUniforms("ModelViewMatrix", "ProjectionMatrix", "Position", "Size");
|
|
||||||
assignSamplerNames(m_program, 0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
|
|
||||||
}
|
|
||||||
|
|
||||||
ColorizeShader::ColorizeShader()
|
ColorizeShader::ColorizeShader()
|
||||||
{
|
{
|
||||||
|
@ -78,14 +78,6 @@ public:
|
|||||||
TransparentFogShader();
|
TransparentFogShader();
|
||||||
};
|
};
|
||||||
|
|
||||||
class BillboardShader : public Shader<BillboardShader, core::matrix4, core::matrix4,
|
|
||||||
core::vector3df, core::dimension2df>,
|
|
||||||
public TextureReadNew<ST_TRILINEAR_ANISOTROPIC_FILTERED>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BillboardShader();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class ColorizeShader : public Shader<ColorizeShader, core::matrix4, video::SColorf>
|
class ColorizeShader : public Shader<ColorizeShader, core::matrix4, video::SColorf>
|
||||||
{
|
{
|
||||||
|
@ -23,9 +23,31 @@
|
|||||||
|
|
||||||
using namespace irr;
|
using namespace irr;
|
||||||
|
|
||||||
|
|
||||||
static GLuint billboardvao = 0;
|
static GLuint billboardvao = 0;
|
||||||
|
|
||||||
static void createbillboardvao()
|
|
||||||
|
class BillboardShader : public Shader<BillboardShader, core::matrix4,
|
||||||
|
core::matrix4, core::vector3df,
|
||||||
|
core::dimension2df>,
|
||||||
|
public TextureReadNew<ST_TRILINEAR_ANISOTROPIC_FILTERED>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BillboardShader()
|
||||||
|
{
|
||||||
|
loadProgram(OBJECT, GL_VERTEX_SHADER, "billboard.vert",
|
||||||
|
GL_FRAGMENT_SHADER, "billboard.frag");
|
||||||
|
|
||||||
|
assignUniforms("ModelViewMatrix", "ProjectionMatrix", "Position",
|
||||||
|
"Size");
|
||||||
|
assignSamplerNames(m_program,
|
||||||
|
0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
|
||||||
|
} // BillboardShader
|
||||||
|
}; // BillboardShader
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
static void createBillboardVAO()
|
||||||
{
|
{
|
||||||
glGenVertexArrays(1, &billboardvao);
|
glGenVertexArrays(1, &billboardvao);
|
||||||
glBindVertexArray(billboardvao);
|
glBindVertexArray(billboardvao);
|
||||||
@ -33,19 +55,27 @@ static void createbillboardvao()
|
|||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glEnableVertexAttribArray(3);
|
glEnableVertexAttribArray(3);
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
|
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)));
|
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
|
||||||
|
(GLvoid*) (2 * sizeof(float)));
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
} // createBillboardVAO
|
||||||
|
|
||||||
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,
|
STKBillboard::STKBillboard(irr::scene::ISceneNode* parent,
|
||||||
irr::video::SColor colorTop, irr::video::SColor colorBottom) :
|
irr::scene::ISceneManager* mgr, irr::s32 id,
|
||||||
IBillboardSceneNode(parent, mgr, id, position), CBillboardSceneNode(parent, mgr, id, position, size, colorTop, colorBottom)
|
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 (!billboardvao)
|
if (!billboardvao)
|
||||||
createbillboardvao();
|
createBillboardVAO();
|
||||||
}
|
} // STKBillboard
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
void STKBillboard::OnRegisterSceneNode()
|
void STKBillboard::OnRegisterSceneNode()
|
||||||
{
|
{
|
||||||
if (IsVisible)
|
if (IsVisible)
|
||||||
@ -54,9 +84,9 @@ void STKBillboard::OnRegisterSceneNode()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ISceneNode::OnRegisterSceneNode();
|
ISceneNode::OnRegisterSceneNode();
|
||||||
}
|
} // OnRegisterSceneNode
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
void STKBillboard::render()
|
void STKBillboard::render()
|
||||||
{
|
{
|
||||||
if (irr_driver->getPhase() != TRANSPARENT_PASS)
|
if (irr_driver->getPhase() != TRANSPARENT_PASS)
|
||||||
@ -64,14 +94,16 @@ void STKBillboard::render()
|
|||||||
core::vector3df pos = getAbsolutePosition();
|
core::vector3df pos = getAbsolutePosition();
|
||||||
glBindVertexArray(billboardvao);
|
glBindVertexArray(billboardvao);
|
||||||
video::ITexture *tex = Material.getTexture(0);
|
video::ITexture *tex = Material.getTexture(0);
|
||||||
if (tex == NULL)
|
if (!tex )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
compressTexture(tex, true, true);
|
compressTexture(tex, true, true);
|
||||||
GLuint texid = getTextureGLuint(tex);
|
GLuint texid = getTextureGLuint(tex);
|
||||||
MeshShader::BillboardShader::getInstance()->use();
|
BillboardShader::getInstance()->use();
|
||||||
MeshShader::BillboardShader::getInstance()->setTextureUnits(texid);
|
BillboardShader::getInstance()->setTextureUnits(texid);
|
||||||
MeshShader::BillboardShader::getInstance()->setUniforms(irr_driver->getViewMatrix(), irr_driver->getProjMatrix(), pos, Size);
|
BillboardShader::getInstance()->setUniforms(irr_driver->getViewMatrix(),
|
||||||
|
irr_driver->getProjMatrix(),
|
||||||
|
pos, Size);
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
return;
|
} // render
|
||||||
}
|
|
||||||
|
@ -26,14 +26,15 @@
|
|||||||
class STKBillboard : public irr::scene::CBillboardSceneNode
|
class STKBillboard : public irr::scene::CBillboardSceneNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
STKBillboard(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id,
|
STKBillboard(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* mgr,
|
||||||
const irr::core::vector3df& position, const irr::core::dimension2d<irr::f32>& size,
|
irr::s32 id, const irr::core::vector3df& position,
|
||||||
irr::video::SColor colorTop = irr::video::SColor(0xFFFFFFFF),
|
const irr::core::dimension2d<irr::f32>& size,
|
||||||
irr::video::SColor colorBottom = irr::video::SColor(0xFFFFFFFF));
|
irr::video::SColor colorTop = irr::video::SColor(0xFFFFFFFF),
|
||||||
|
irr::video::SColor colorBottom = irr::video::SColor(0xFFFFFFFF));
|
||||||
|
|
||||||
virtual void OnRegisterSceneNode() OVERRIDE;
|
virtual void OnRegisterSceneNode() OVERRIDE;
|
||||||
|
|
||||||
virtual void render() OVERRIDE;
|
virtual void render() OVERRIDE;
|
||||||
};
|
}; // STKBillboard
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user