Port PointLight shader

This commit is contained in:
Vincent Lejeune 2014-08-22 00:30:14 +02:00
parent cee48821d3
commit 547018f0ab
4 changed files with 17 additions and 49 deletions

View File

@ -1,6 +1,5 @@
uniform sampler2D ntex;
uniform sampler2D dtex;
uniform float spec;
flat in vec3 center;
flat in float energy;

View File

@ -45,17 +45,14 @@ static void renderPointLights(unsigned count)
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glUseProgram(LightShader::PointLightShader::Program);
glBindVertexArray(LightShader::PointLightShader::vao);
glBindBuffer(GL_ARRAY_BUFFER, LightShader::PointLightShader::vbo);
glUseProgram(LightShader::PointLightShader::getInstance()->Program);
glBindVertexArray(LightShader::PointLightShader::getInstance()->vao);
glBindBuffer(GL_ARRAY_BUFFER, LightShader::PointLightShader::getInstance()->vbo);
glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(LightShader::PointLightInfo), PointLightsInfo);
setTexture(0, irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), GL_NEAREST, GL_NEAREST);
setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
LightShader::PointLightShader
::setUniforms(core::vector2df(float(UserConfigParams::m_width),
float(UserConfigParams::m_height)),
200, 0, 1);
LightShader::PointLightShader::getInstance()->setUniforms();
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
}

View File

@ -408,7 +408,6 @@ void Shaders::loadShaders()
initShadowVPMUBO();
initParticleQuadVBO();
MeshShader::BubbleShader::init();
LightShader::PointLightShader::init();
MeshShader::SkyboxShader::init();
MeshShader::ViewFrustrumShader::init();
UtilShader::ColoredLine::init();
@ -1421,19 +1420,7 @@ namespace MeshShader
namespace LightShader
{
GLuint PointLightShader::Program;
GLuint PointLightShader::attrib_Position;
GLuint PointLightShader::attrib_Color;
GLuint PointLightShader::attrib_Energy;
GLuint PointLightShader::attrib_Radius;
GLuint PointLightShader::uniform_ntex;
GLuint PointLightShader::uniform_dtex;
GLuint PointLightShader::uniform_spec;
GLuint PointLightShader::vbo;
GLuint PointLightShader::vao;
void PointLightShader::init()
PointLightShader::PointLightShader()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/pointlight.vert").c_str(),
@ -1441,13 +1428,9 @@ namespace LightShader
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getSpecular.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getPosFromUVDepth.frag").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/pointlight.frag").c_str());
attrib_Position = glGetAttribLocation(Program, "Position");
attrib_Color = glGetAttribLocation(Program, "Color");
attrib_Energy = glGetAttribLocation(Program, "Energy");
attrib_Radius = glGetAttribLocation(Program, "Radius");
uniform_ntex = glGetUniformLocation(Program, "ntex");
uniform_dtex = glGetUniformLocation(Program, "dtex");
uniform_spec = glGetUniformLocation(Program, "spec");
AssignUniforms();
AssignSamplerNames(Program, 0, "ntex", 1, "dtex");
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
@ -1456,6 +1439,11 @@ namespace LightShader
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, MAXLIGHT * sizeof(PointLightInfo), 0, GL_DYNAMIC_DRAW);
GLuint attrib_Position = glGetAttribLocation(Program, "Position");
GLuint attrib_Color = glGetAttribLocation(Program, "Color");
GLuint attrib_Energy = glGetAttribLocation(Program, "Energy");
GLuint attrib_Radius = glGetAttribLocation(Program, "Radius");
glEnableVertexAttribArray(attrib_Position);
glVertexAttribPointer(attrib_Position, 3, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), 0);
glEnableVertexAttribArray(attrib_Energy);
@ -1470,17 +1458,6 @@ namespace LightShader
glVertexAttribDivisor(attrib_Color, 1);
glVertexAttribDivisor(attrib_Radius, 1);
}
void PointLightShader::setUniforms(const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex)
{
if (irr_driver->needUBOWorkaround())
bypassUBO(Program);
glUniform1f(uniform_spec, 200);
glUniform1i(uniform_ntex, TU_ntex);
glUniform1i(uniform_dtex, TU_dtex);
}
}

View File

@ -691,17 +691,12 @@ namespace LightShader
};
class PointLightShader
class PointLightShader : public ShaderHelperSingleton<PointLightShader>, TextureRead<Nearest_Filtered, Nearest_Filtered>
{
public:
static GLuint Program;
static GLuint attrib_Position, attrib_Energy, attrib_Color, attrib_Radius;
static GLuint uniform_ntex, uniform_dtex, uniform_spec;
static GLuint vbo;
static GLuint vao;
static void init();
static void setUniforms(const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex);
GLuint vbo;
GLuint vao;
PointLightShader();
};
}