Moved more shaders.

This commit is contained in:
hiker 2015-05-18 08:49:41 +10:00
parent 3cb0c6f4c2
commit 78220d5ed7
6 changed files with 160 additions and 169 deletions

View File

@ -43,6 +43,22 @@
#define MIN2(a, b) ((a) > (b) ? (b) : (a))
// ============================================================================
class InstancedColorizeShader : public Shader<InstancedColorizeShader>
{
public:
InstancedColorizeShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "utils/getworldmatrix.vert",
GL_VERTEX_SHADER, "glow_object.vert",
GL_FRAGMENT_SHADER, "glow_object.frag");
assignUniforms();
} // InstancedColorizeShader
}; // InstancedColorizeShader
// ============================================================================
extern std::vector<float> BoundingBoxes;
void IrrDriver::renderGLSL(float dt)
@ -694,7 +710,7 @@ void IrrDriver::renderGlow(std::vector<GlowData>& glows)
if (CVS->supportsIndirectInstancingRendering())
{
glBindBuffer(GL_DRAW_INDIRECT_BUFFER, GlowPassCmd::getInstance()->drawindirectcmd);
MeshShader::InstancedColorizeShader::getInstance()->use();
InstancedColorizeShader::getInstance()->use();
glBindVertexArray(VAOManager::getInstance()->getInstanceVAO(video::EVT_STANDARD, InstanceTypeGlow));
if (CVS->isAZDOEnabled())

View File

@ -413,6 +413,90 @@ public:
} // InstancedObjectUnlitShader
}; // InstancedObjectUnlitShader
// ============================================================================
class RefShadowShader : public TextureShader<RefShadowShader, 1,
int, core::matrix4>
{
public:
RefShadowShader()
{
// Geometry shader needed
if (CVS->getGLSLVersion() < 150)
return;
if (CVS->isAMDVertexShaderLayerUsable())
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "shadow.vert",
GL_FRAGMENT_SHADER, "shadowref.frag");
}
else
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "shadow.vert",
GL_GEOMETRY_SHADER, "shadow.geom",
GL_FRAGMENT_SHADER, "shadowref.frag");
}
assignUniforms("layer", "ModelMatrix");
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // RefShadowShader
}; // RefShadowShader
// ============================================================================
class InstancedRefShadowShader : public TextureShader<InstancedRefShadowShader,
1, int>
{
public:
InstancedRefShadowShader()
{
// Geometry shader needed
if (CVS->getGLSLVersion() < 150)
return;
if (CVS->isAMDVertexShaderLayerUsable())
{
loadProgram(OBJECT,GL_VERTEX_SHADER, "utils/getworldmatrix.vert",
GL_VERTEX_SHADER, "instanciedshadow.vert",
GL_FRAGMENT_SHADER, "instanced_shadowref.frag");
}
else
{
loadProgram(OBJECT,GL_VERTEX_SHADER, "utils/getworldmatrix.vert",
GL_VERTEX_SHADER, "instanciedshadow.vert",
GL_GEOMETRY_SHADER, "instanced_shadow.geom",
GL_FRAGMENT_SHADER, "instanced_shadowref.frag");
}
assignUniforms("layer");
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // InstancedRefShadowShader
}; // InstancedRefShadowShader
// ============================================================================
class DisplaceMaskShader : public Shader<DisplaceMaskShader, core::matrix4>
{
public:
DisplaceMaskShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "displace.vert",
GL_FRAGMENT_SHADER, "white.frag");
assignUniforms("ModelMatrix");
} // DisplaceMaskShader
}; // DisplaceMaskShader
// ============================================================================
class DisplaceShader : public TextureShader<DisplaceShader, 4, core::matrix4,
core::vector2df, core::vector2df>
{
public:
DisplaceShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "displace.vert",
GL_FRAGMENT_SHADER, "displace.frag");
assignUniforms("ModelMatrix", "dir", "dir2");
assignSamplerNames(0, "displacement_tex", ST_BILINEAR_FILTERED,
1, "color_tex", ST_BILINEAR_FILTERED,
2, "mask_tex", ST_BILINEAR_FILTERED,
3, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
} // DisplaceShader
}; // DisplaceShader
// ============================================================================
struct DefaultMaterial
{
@ -448,12 +532,12 @@ struct AlphaRef
{
typedef InstancedObjectRefPass1Shader InstancedFirstPassShader;
typedef InstancedObjectRefPass2Shader InstancedSecondPassShader;
typedef MeshShader::InstancedRefShadowShader InstancedShadowPassShader;
typedef InstancedRefShadowShader InstancedShadowPassShader;
typedef CInstancedRSMShader InstancedRSMShader;
typedef ListInstancedMatAlphaRef InstancedList;
typedef ObjectRefPass1Shader FirstPassShader;
typedef ObjectRefPass2Shader SecondPassShader;
typedef MeshShader::RefShadowShader ShadowPassShader;
typedef RefShadowShader ShadowPassShader;
typedef CRSMShader RSMShader;
typedef ListMatAlphaRef List;
static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD;
@ -507,12 +591,12 @@ struct UnlitMat
{
typedef InstancedObjectRefPass1Shader InstancedFirstPassShader;
typedef InstancedObjectUnlitShader InstancedSecondPassShader;
typedef MeshShader::InstancedRefShadowShader InstancedShadowPassShader;
typedef InstancedRefShadowShader InstancedShadowPassShader;
typedef CInstancedRSMShader InstancedRSMShader;
typedef ListInstancedMatUnlit InstancedList;
typedef ObjectRefPass1Shader FirstPassShader;
typedef ObjectUnlitShader SecondPassShader;
typedef MeshShader::RefShadowShader ShadowPassShader;
typedef RefShadowShader ShadowPassShader;
typedef CRSMShader RSMShader;
typedef ListMatUnlit List;
static const enum video::E_VERTEX_TYPE VertexType = video::EVT_STANDARD;
@ -1504,8 +1588,8 @@ void IrrDriver::renderTransparent()
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
MeshShader::DisplaceMaskShader::getInstance()->use();
MeshShader::DisplaceMaskShader::getInstance()->setUniforms(AbsoluteTransformation);
DisplaceMaskShader::getInstance()->use();
DisplaceMaskShader::getInstance()->setUniforms(AbsoluteTransformation);
glDrawElementsBaseVertex(ptype, (int)count, itype,
(GLvoid *)mesh.vaoOffset, (int)mesh.vaoBaseVertex);
}
@ -1528,13 +1612,13 @@ void IrrDriver::renderTransparent()
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
// Render the effect
MeshShader::DisplaceShader::getInstance()->setTextureUnits(
DisplaceShader::getInstance()->setTextureUnits(
getTextureGLuint(displaceTex),
irr_driver->getRenderTargetTexture(RTT_COLOR),
irr_driver->getRenderTargetTexture(RTT_TMP1),
getTextureGLuint(mesh.textures[0]));
MeshShader::DisplaceShader::getInstance()->use();
MeshShader::DisplaceShader::getInstance()->setUniforms(AbsoluteTransformation,
DisplaceShader::getInstance()->use();
DisplaceShader::getInstance()->setUniforms(AbsoluteTransformation,
core::vector2df(cb->getDirX(), cb->getDirY()),
core::vector2df(cb->getDir2X(), cb->getDir2Y()));

View File

@ -25,6 +25,34 @@
#define MAX2(a, b) ((a) > (b) ? (a) : (b))
#define MIN2(a, b) ((a) > (b) ? (b) : (a))
class SkyboxShader : public TextureShader<SkyboxShader,1>
{
private:
GLuint m_vao;
public:
SkyboxShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "sky.vert",
GL_FRAGMENT_SHADER, "sky.frag");
assignUniforms();
assignSamplerNames(0, "tex", ST_TRILINEAR_CUBEMAP);
glGenVertexArrays(1, &m_vao);
glBindVertexArray(m_vao);
glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getSkyTriVBO());
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);
glBindVertexArray(0);
} // SkyboxShader
// ------------------------------------------------------------------------
void bindVertexArray()
{
glBindVertexArray(m_vao);
} // bindVertexArray
}; // SkyboxShader
// ============================================================================
static float getTexelValue(unsigned i, unsigned j, size_t width, size_t height, float *Coeff, float *Y00, float *Y1minus1, float *Y10, float *Y11,
float *Y2minus2, float * Y2minus1, float * Y20, float *Y21, float *Y22)
{
@ -403,11 +431,11 @@ void IrrDriver::renderSkybox(const scene::ICameraSceneNode *camera)
glDisable(GL_BLEND);
MeshShader::SkyboxShader::getInstance()->use();
glBindVertexArray(MeshShader::SkyboxShader::getInstance()->vao);
MeshShader::SkyboxShader::getInstance()->setUniforms();
SkyboxShader::getInstance()->use();
SkyboxShader::getInstance()->bindVertexArray();
SkyboxShader::getInstance()->setUniforms();
MeshShader::SkyboxShader::getInstance()->setTextureUnits(SkyboxCubeMap);
SkyboxShader::getInstance()->setTextureUnits(SkyboxCubeMap);
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindVertexArray(0);

View File

@ -441,112 +441,6 @@ namespace MeshShader
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
}
ColorizeShader::ColorizeShader()
{
loadProgram(OBJECT,
GL_VERTEX_SHADER, "object_pass.vert",
GL_FRAGMENT_SHADER, "colorize.frag");
assignUniforms("ModelMatrix", "col");
}
InstancedColorizeShader::InstancedColorizeShader()
{
loadProgram(OBJECT,
GL_VERTEX_SHADER, "utils/getworldmatrix.vert",
GL_VERTEX_SHADER, "glow_object.vert",
GL_FRAGMENT_SHADER, "glow_object.frag");
assignUniforms();
}
RefShadowShader::RefShadowShader()
{
// Geometry shader needed
if (CVS->getGLSLVersion() < 150)
return;
if (CVS->isAMDVertexShaderLayerUsable())
{
loadProgram(OBJECT,
GL_VERTEX_SHADER, "shadow.vert",
GL_FRAGMENT_SHADER, "shadowref.frag");
}
else
{
loadProgram(OBJECT,
GL_VERTEX_SHADER, "shadow.vert",
GL_GEOMETRY_SHADER, "shadow.geom",
GL_FRAGMENT_SHADER, "shadowref.frag");
}
assignUniforms("layer", "ModelMatrix");
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
}
InstancedRefShadowShader::InstancedRefShadowShader()
{
// Geometry shader needed
if (CVS->getGLSLVersion() < 150)
return;
if (CVS->isAMDVertexShaderLayerUsable())
{
loadProgram(OBJECT,
GL_VERTEX_SHADER, "utils/getworldmatrix.vert",
GL_VERTEX_SHADER, "instanciedshadow.vert",
GL_FRAGMENT_SHADER, "instanced_shadowref.frag");
}
else
{
loadProgram(OBJECT,
GL_VERTEX_SHADER, "utils/getworldmatrix.vert",
GL_VERTEX_SHADER, "instanciedshadow.vert",
GL_GEOMETRY_SHADER, "instanced_shadow.geom",
GL_FRAGMENT_SHADER, "instanced_shadowref.frag");
}
assignUniforms("layer");
assignSamplerNames(0, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
}
DisplaceMaskShader::DisplaceMaskShader()
{
loadProgram(OBJECT,
GL_VERTEX_SHADER, "displace.vert",
GL_FRAGMENT_SHADER, "white.frag");
assignUniforms("ModelMatrix");
}
DisplaceShader::DisplaceShader()
{
loadProgram(OBJECT,
GL_VERTEX_SHADER, "displace.vert",
GL_FRAGMENT_SHADER, "displace.frag");
assignUniforms("ModelMatrix", "dir", "dir2");
assignSamplerNames(0, "displacement_tex", ST_BILINEAR_FILTERED,
1, "color_tex", ST_BILINEAR_FILTERED,
2, "mask_tex", ST_BILINEAR_FILTERED,
3, "tex", ST_TRILINEAR_ANISOTROPIC_FILTERED);
}
SkyboxShader::SkyboxShader()
{
loadProgram(OBJECT,
GL_VERTEX_SHADER, "sky.vert",
GL_FRAGMENT_SHADER, "sky.frag");
assignUniforms();
assignSamplerNames(0, "tex", ST_TRILINEAR_CUBEMAP);
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, SharedGPUObjects::getSkyTriVBO());
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);
glBindVertexArray(0);
}
NormalVisualizer::NormalVisualizer()
{
loadProgram(OBJECT,

View File

@ -66,53 +66,6 @@ public:
};
class ColorizeShader : public Shader<ColorizeShader, core::matrix4, video::SColorf>
{
public:
ColorizeShader();
};
class InstancedColorizeShader : public Shader<InstancedColorizeShader>
{
public:
InstancedColorizeShader();
};
class RefShadowShader : public TextureShader<RefShadowShader, 1, int, core::matrix4>
{
public:
RefShadowShader();
};
class InstancedRefShadowShader : public TextureShader<InstancedRefShadowShader, 1, int>
{
public:
InstancedRefShadowShader();
};
class DisplaceMaskShader : public Shader<DisplaceMaskShader, core::matrix4>
{
public:
DisplaceMaskShader();
};
class DisplaceShader : public TextureShader<DisplaceShader, 4, core::matrix4,
core::vector2df, core::vector2df>
{
public:
DisplaceShader();
};
class SkyboxShader : public TextureShader<SkyboxShader,1>
{
public:
SkyboxShader();
GLuint vao;
};
class NormalVisualizer : public Shader<NormalVisualizer, video::SColor>
{
public:

View File

@ -32,6 +32,22 @@
#include "utils/tuple.hpp"
#include "utils/cpp2011.hpp"
// ============================================================================
class ColorizeShader : public Shader<ColorizeShader, core::matrix4,
video::SColorf>
{
public:
ColorizeShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "object_pass.vert",
GL_FRAGMENT_SHADER, "colorize.frag");
assignUniforms("ModelMatrix", "col");
}
}; // ColorizeShader
// ============================================================================
STKMeshSceneNode::STKMeshSceneNode(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::ISceneManager* mgr,
irr::s32 id, const std::string& debug_name,
const irr::core::vector3df& position,
@ -108,7 +124,7 @@ void STKMeshSceneNode::drawGlow(const GLMesh &mesh)
GLenum ptype = mesh.PrimitiveType;
GLenum itype = mesh.IndexType;
size_t count = mesh.IndexCount;
MeshShader::ColorizeShader::getInstance()->setUniforms(AbsoluteTransformation, video::SColorf(glowcolor.getRed() / 255.f, glowcolor.getGreen() / 255.f, glowcolor.getBlue() / 255.f));
ColorizeShader::getInstance()->setUniforms(AbsoluteTransformation, video::SColorf(glowcolor.getRed() / 255.f, glowcolor.getGreen() / 255.f, glowcolor.getBlue() / 255.f));
glDrawElementsBaseVertex(ptype, count, itype, (GLvoid *)mesh.vaoOffset, mesh.vaoBaseVertex);
}
@ -366,7 +382,7 @@ void STKMeshSceneNode::render()
if (irr_driver->getPhase() == GLOW_PASS)
{
MeshShader::ColorizeShader::getInstance()->use();
ColorizeShader::getInstance()->use();
for (u32 i = 0; i < Mesh->getMeshBufferCount(); ++i)
{
scene::IMeshBuffer* mb = Mesh->getMeshBuffer(i);