Moved shaders into render_lighting, fixed coding style for

render_lighting.
This commit is contained in:
hiker 2015-05-18 21:33:26 +10:00
parent 6def0c752c
commit 8e4ee298e0
6 changed files with 219 additions and 163 deletions

View File

@ -719,7 +719,7 @@ public:
void onUnloadWorld();
void renderScene(scene::ICameraSceneNode * const camnode, unsigned pointlightcount, std::vector<GlowData>& glows, float dt, bool hasShadows, bool forceRTT);
unsigned UpdateLightsInfo(scene::ICameraSceneNode * const camnode, float dt);
unsigned updateLightsInfo(scene::ICameraSceneNode * const camnode, float dt);
void UpdateSplitAndLightcoordRangeFromComputeShaders(size_t width, size_t height);
void computeMatrixesAndCameras(scene::ICameraSceneNode * const camnode, size_t width, size_t height);
void uploadLightingData();

View File

@ -228,7 +228,7 @@ void IrrDriver::renderGLSL(float dt)
glEnable(GL_FRAMEBUFFER_SRGB);
PROFILER_PUSH_CPU_MARKER("Update Light Info", 0xFF, 0x0, 0x0);
unsigned plc = UpdateLightsInfo(camnode, dt);
unsigned plc = updateLightsInfo(camnode, dt);
PROFILER_POP_CPU_MARKER();
PROFILER_PUSH_CPU_MARKER("UBO upload", 0x0, 0xFF, 0x0);
computeMatrixesAndCameras(camnode, viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X, viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y);

View File

@ -33,8 +33,134 @@
#define MAX2(a, b) ((a) > (b) ? (a) : (b))
#define MIN2(a, b) ((a) > (b) ? (b) : (a))
static LightShader::PointLightInfo PointLightsInfo[MAXLIGHT];
class LightBaseClass
{
public:
struct PointLightInfo
{
float posX;
float posY;
float posZ;
float energy;
float red;
float green;
float blue;
float radius;
};
public:
static const unsigned int MAXLIGHT = 32;
public:
static struct PointLightInfo m_point_lights_info[MAXLIGHT];
}; // LightBaseClass
// ============================================================================
LightBaseClass::PointLightInfo m_point_lights_info[LightBaseClass::MAXLIGHT];
// ============================================================================
class PointLightShader : public TextureShader < PointLightShader, 2 >
, private LightBaseClass
{
public:
GLuint vbo;
GLuint vao;
PointLightShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "pointlight.vert",
GL_FRAGMENT_SHADER, "utils/decodeNormal.frag",
GL_FRAGMENT_SHADER, "utils/SpecularBRDF.frag",
GL_FRAGMENT_SHADER, "utils/DiffuseBRDF.frag",
GL_FRAGMENT_SHADER, "utils/getPosFromUVDepth.frag",
GL_FRAGMENT_SHADER, "pointlight.frag");
assignUniforms();
assignSamplerNames(0, "ntex", ST_NEAREST_FILTERED,
1, "dtex", ST_NEAREST_FILTERED);
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, MAXLIGHT * sizeof(PointLightInfo), 0,
GL_DYNAMIC_DRAW);
GLuint attrib_Position = glGetAttribLocation(m_program, "Position");
GLuint attrib_Color = glGetAttribLocation(m_program, "Color");
GLuint attrib_Energy = glGetAttribLocation(m_program, "Energy");
GLuint attrib_Radius = glGetAttribLocation(m_program, "Radius");
glEnableVertexAttribArray(attrib_Position);
glVertexAttribPointer(attrib_Position, 3, GL_FLOAT, GL_FALSE,
sizeof(PointLightInfo), 0);
glEnableVertexAttribArray(attrib_Energy);
glVertexAttribPointer(attrib_Energy, 1, GL_FLOAT, GL_FALSE,
sizeof(PointLightInfo),
(GLvoid*)(3 * sizeof(float)));
glEnableVertexAttribArray(attrib_Color);
glVertexAttribPointer(attrib_Color, 3, GL_FLOAT, GL_FALSE,
sizeof(PointLightInfo),
(GLvoid*)(4 * sizeof(float)));
glEnableVertexAttribArray(attrib_Radius);
glVertexAttribPointer(attrib_Radius, 1, GL_FLOAT, GL_FALSE,
sizeof(PointLightInfo),
(GLvoid*)(7 * sizeof(float)));
glVertexAttribDivisorARB(attrib_Position, 1);
glVertexAttribDivisorARB(attrib_Energy, 1);
glVertexAttribDivisorARB(attrib_Color, 1);
glVertexAttribDivisorARB(attrib_Radius, 1);
} // PointLightShader
}; // PointLightShader
// ============================================================================
class PointLightScatterShader : public TextureShader<PointLightScatterShader,
1, float, core::vector3df>
{
public:
GLuint vbo;
GLuint vao;
PointLightScatterShader()
{
loadProgram(OBJECT, GL_VERTEX_SHADER, "pointlight.vert",
GL_FRAGMENT_SHADER, "utils/getPosFromUVDepth.frag",
GL_FRAGMENT_SHADER, "pointlightscatter.frag");
assignUniforms("density", "fogcol");
assignSamplerNames(0, "dtex", ST_NEAREST_FILTERED);
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, PointLightShader::getInstance()->vbo);
GLuint attrib_Position = glGetAttribLocation(m_program, "Position");
GLuint attrib_Color = glGetAttribLocation(m_program, "Color");
GLuint attrib_Energy = glGetAttribLocation(m_program, "Energy");
GLuint attrib_Radius = glGetAttribLocation(m_program, "Radius");
glEnableVertexAttribArray(attrib_Position);
glVertexAttribPointer(attrib_Position, 3, GL_FLOAT, GL_FALSE,
sizeof(LightBaseClass::PointLightInfo), 0);
glEnableVertexAttribArray(attrib_Energy);
glVertexAttribPointer(attrib_Energy, 1, GL_FLOAT, GL_FALSE,
sizeof(LightBaseClass::PointLightInfo),
(GLvoid*)(3 * sizeof(float)));
glEnableVertexAttribArray(attrib_Color);
glVertexAttribPointer(attrib_Color, 3, GL_FLOAT, GL_FALSE,
sizeof(LightBaseClass::PointLightInfo),
(GLvoid*)(4 * sizeof(float)));
glEnableVertexAttribArray(attrib_Radius);
glVertexAttribPointer(attrib_Radius, 1, GL_FLOAT, GL_FALSE,
sizeof(LightBaseClass::PointLightInfo),
(GLvoid*)(7 * sizeof(float)));
glVertexAttribDivisorARB(attrib_Position, 1);
glVertexAttribDivisorARB(attrib_Energy, 1);
glVertexAttribDivisorARB(attrib_Color, 1);
glVertexAttribDivisorARB(attrib_Radius, 1);
} // PointLightScatterShader
};
// ============================================================================
static void renderPointLights(unsigned count)
{
glEnable(GL_BLEND);
@ -43,18 +169,24 @@ static void renderPointLights(unsigned count)
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
LightShader::PointLightShader::getInstance()->use();
glBindVertexArray(LightShader::PointLightShader::getInstance()->vao);
glBindBuffer(GL_ARRAY_BUFFER, LightShader::PointLightShader::getInstance()->vbo);
glBufferSubData(GL_ARRAY_BUFFER, 0, count * sizeof(LightShader::PointLightInfo), PointLightsInfo);
PointLightShader::getInstance()->use();
glBindVertexArray(PointLightShader::getInstance()->vao);
glBindBuffer(GL_ARRAY_BUFFER, PointLightShader::getInstance()->vbo);
glBufferSubData(GL_ARRAY_BUFFER, 0,
count * sizeof(LightBaseClass::PointLightInfo),
m_point_lights_info);
LightShader::PointLightShader::getInstance()->setTextureUnits(irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), irr_driver->getDepthStencilTexture());
LightShader::PointLightShader::getInstance()->setUniforms();
PointLightShader::getInstance()->setTextureUnits(
irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH),
irr_driver->getDepthStencilTexture());
PointLightShader::getInstance()->setUniforms();
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
}
} // renderPointLights
unsigned IrrDriver::UpdateLightsInfo(scene::ICameraSceneNode * const camnode, float dt)
// ----------------------------------------------------------------------------
unsigned IrrDriver::updateLightsInfo(scene::ICameraSceneNode * const camnode,
float dt)
{
const u32 lightcount = (u32)m_lights.size();
const core::vector3df &campos = camnode->getAbsolutePosition();
@ -70,7 +202,8 @@ unsigned IrrDriver::UpdateLightsInfo(scene::ICameraSceneNode * const camnode, fl
m_lights[i]->render();
continue;
}
const core::vector3df &lightpos = (m_lights[i]->getAbsolutePosition() - campos);
const core::vector3df &lightpos =
(m_lights[i]->getAbsolutePosition() - campos);
unsigned idx = (unsigned)(lightpos.getLength() / 10);
if (idx > 14)
idx = 14;
@ -83,7 +216,7 @@ unsigned IrrDriver::UpdateLightsInfo(scene::ICameraSceneNode * const camnode, fl
{
for (unsigned j = 0; j < BucketedLN[i].size(); j++)
{
if (++lightnum >= MAXLIGHT)
if (++lightnum >= LightBaseClass::MAXLIGHT)
{
LightNode* light_node = BucketedLN[i].at(j);
light_node->setEnergyMultiplier(0.0f);
@ -99,22 +232,23 @@ unsigned IrrDriver::UpdateLightsInfo(scene::ICameraSceneNode * const camnode, fl
}
const core::vector3df &pos = light_node->getAbsolutePosition();
PointLightsInfo[lightnum].posX = pos.X;
PointLightsInfo[lightnum].posY = pos.Y;
PointLightsInfo[lightnum].posZ = pos.Z;
m_point_lights_info[lightnum].posX = pos.X;
m_point_lights_info[lightnum].posY = pos.Y;
m_point_lights_info[lightnum].posZ = pos.Z;
PointLightsInfo[lightnum].energy = light_node->getEffectiveEnergy();
m_point_lights_info[lightnum].energy =
light_node->getEffectiveEnergy();
const core::vector3df &col = light_node->getColor();
PointLightsInfo[lightnum].red = col.X;
PointLightsInfo[lightnum].green = col.Y;
PointLightsInfo[lightnum].blue = col.Z;
m_point_lights_info[lightnum].red = col.X;
m_point_lights_info[lightnum].green = col.Y;
m_point_lights_info[lightnum].blue = col.Z;
// Light radius
PointLightsInfo[lightnum].radius = light_node->getRadius();
m_point_lights_info[lightnum].radius = light_node->getRadius();
}
}
if (lightnum > MAXLIGHT)
if (lightnum > LightBaseClass::MAXLIGHT)
{
irr_driver->setLastLightBucketDistance(i * 10);
break;
@ -123,10 +257,11 @@ unsigned IrrDriver::UpdateLightsInfo(scene::ICameraSceneNode * const camnode, fl
lightnum++;
return lightnum;
}
} // updateLightsInfo
// ----------------------------------------------------------------------------
/** Upload lighting info to the dedicated uniform buffer
*/
*/
void IrrDriver::uploadLightingData()
{
float Lighting[36];
@ -144,10 +279,12 @@ void IrrDriver::uploadLightingData()
glBindBuffer(GL_UNIFORM_BUFFER, SharedGPUObjects::getLightingDataUBO());
glBufferSubData(GL_UNIFORM_BUFFER, 0, 36 * sizeof(float), Lighting);
}
} // uploadLightingData
// ----------------------------------------------------------------------------
extern float shadowSplit[5];
// ----------------------------------------------------------------------------
void IrrDriver::renderLights(unsigned pointlightcount, bool hasShadow)
{
//RH
@ -159,24 +296,34 @@ void IrrDriver::renderLights(unsigned pointlightcount, bool hasShadow)
glBindVertexArray(SharedGPUObjects::getFullScreenQuadVAO());
if (CVS->needRHWorkaround())
{
FullScreenShader::NVWorkaroundRadianceHintsConstructionShader::getInstance()->use();
FullScreenShader::NVWorkaroundRadianceHintsConstructionShader::getInstance()->setTextureUnits(
m_rtts->getRSM().getRTT()[0], m_rtts->getRSM().getRTT()[1], m_rtts->getRSM().getDepthTexture());
FullScreenShader::NVWorkaroundRadianceHintsConstructionShader
::getInstance()->use();
FullScreenShader::NVWorkaroundRadianceHintsConstructionShader
::getInstance()->setTextureUnits(
m_rtts->getRSM().getRTT()[0],
m_rtts->getRSM().getRTT()[1],
m_rtts->getRSM().getDepthTexture());
for (unsigned i = 0; i < 32; i++)
{
FullScreenShader::NVWorkaroundRadianceHintsConstructionShader::getInstance()->setUniforms(rsm_matrix, rh_matrix, rh_extend, i, irr_driver->getSunColor());
FullScreenShader::NVWorkaroundRadianceHintsConstructionShader
::getInstance()->setUniforms(rsm_matrix, rh_matrix,
rh_extend, i,
irr_driver->getSunColor());
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
}
else
{
FullScreenShader::RadianceHintsConstructionShader::getInstance()->use();
FullScreenShader::RadianceHintsConstructionShader::getInstance()->setTextureUnits(
FullScreenShader::RadianceHintsConstructionShader::getInstance()
->setTextureUnits(
m_rtts->getRSM().getRTT()[0],
m_rtts->getRSM().getRTT()[1],
m_rtts->getRSM().getDepthTexture()
);
FullScreenShader::RadianceHintsConstructionShader::getInstance()->setUniforms(rsm_matrix, rh_matrix, rh_extend, irr_driver->getSunColor());
FullScreenShader::RadianceHintsConstructionShader::getInstance()
->setUniforms(rsm_matrix, rh_matrix, rh_extend,
irr_driver->getSunColor());
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, 32);
}
}
@ -190,14 +337,18 @@ void IrrDriver::renderLights(unsigned pointlightcount, bool hasShadow)
if (CVS->isGlobalIlluminationEnabled() && hasShadow)
{
ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_GI));
m_post_processing->renderGI(rh_matrix, rh_extend, m_rtts->getRH().getRTT()[0], m_rtts->getRH().getRTT()[1], m_rtts->getRH().getRTT()[2]);
m_post_processing->renderGI(rh_matrix, rh_extend,
m_rtts->getRH().getRTT()[0],
m_rtts->getRH().getRTT()[1],
m_rtts->getRH().getRTT()[2]);
}
m_rtts->getFBO(FBO_COMBINED_DIFFUSE_SPECULAR).Bind();
{
ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_ENVMAP));
m_post_processing->renderEnvMap(blueSHCoeff, greenSHCoeff, redSHCoeff, SkyboxSpecularProbe);
m_post_processing->renderEnvMap(blueSHCoeff, greenSHCoeff,
redSHCoeff, SkyboxSpecularProbe);
}
// Render sunlight if and only if track supports shadow
@ -213,12 +364,21 @@ void IrrDriver::renderLights(unsigned pointlightcount, bool hasShadow)
if (CVS->isESMEnabled())
{
FullScreenShader::ShadowedSunLightShaderESM::getInstance()->setTextureUnits(irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), irr_driver->getDepthStencilTexture(), m_rtts->getShadowFBO().getRTT()[0]);
DrawFullScreenEffect<FullScreenShader::ShadowedSunLightShaderESM>(shadowSplit[1], shadowSplit[2], shadowSplit[3], shadowSplit[4]);
FullScreenShader::ShadowedSunLightShaderESM::getInstance()
->setTextureUnits(
irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH),
irr_driver->getDepthStencilTexture(),
m_rtts->getShadowFBO().getRTT()[0]);
DrawFullScreenEffect<FullScreenShader
::ShadowedSunLightShaderESM>(shadowSplit[1], shadowSplit[2],
shadowSplit[3], shadowSplit[4]);
}
else
{
FullScreenShader::ShadowedSunLightShaderPCF::getInstance()->setTextureUnits(irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH), irr_driver->getDepthStencilTexture(), m_rtts->getShadowFBO().getDepthTexture());
FullScreenShader::ShadowedSunLightShaderPCF::getInstance()
->setTextureUnits(irr_driver->getRenderTargetTexture(RTT_NORMAL_AND_DEPTH),
irr_driver->getDepthStencilTexture(),
m_rtts->getShadowFBO().getDepthTexture());
DrawFullScreenEffect<FullScreenShader::ShadowedSunLightShaderPCF>(shadowSplit[1],
shadowSplit[2],
shadowSplit[3],
@ -227,14 +387,16 @@ void IrrDriver::renderLights(unsigned pointlightcount, bool hasShadow)
}
}
else
m_post_processing->renderSunlight(irr_driver->getSunDirection(), irr_driver->getSunColor());
m_post_processing->renderSunlight(irr_driver->getSunDirection(),
irr_driver->getSunColor());
}
{
ScopedGPUTimer timer(irr_driver->getGPUTimer(Q_POINTLIGHTS));
renderPointLights(MIN2(pointlightcount, MAXLIGHT));
renderPointLights(MIN2(pointlightcount, LightBaseClass::MAXLIGHT));
}
}
} // renderLights
// ----------------------------------------------------------------------------
void IrrDriver::renderSSAO()
{
m_rtts->getFBO(FBO_SSAO).Bind();
@ -242,11 +404,15 @@ void IrrDriver::renderSSAO()
glClear(GL_COLOR_BUFFER_BIT);
m_post_processing->renderSSAO();
// Blur it to reduce noise.
FrameBuffer::Blit(m_rtts->getFBO(FBO_SSAO), m_rtts->getFBO(FBO_HALF1_R), GL_COLOR_BUFFER_BIT, GL_LINEAR);
m_post_processing->renderGaussian17TapBlur(irr_driver->getFBO(FBO_HALF1_R), irr_driver->getFBO(FBO_HALF2_R));
FrameBuffer::Blit(m_rtts->getFBO(FBO_SSAO),
m_rtts->getFBO(FBO_HALF1_R),
GL_COLOR_BUFFER_BIT, GL_LINEAR);
m_post_processing->renderGaussian17TapBlur(irr_driver->getFBO(FBO_HALF1_R),
irr_driver->getFBO(FBO_HALF2_R));
}
} // renderSSAO
// ----------------------------------------------------------------------------
void IrrDriver::renderAmbientScatter()
{
const Track * const track = World::getWorld()->getTrack();
@ -265,10 +431,12 @@ void IrrDriver::renderAmbientScatter()
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE);
FullScreenShader::FogShader::getInstance()->setTextureUnits(irr_driver->getDepthStencilTexture());
FullScreenShader::FogShader::getInstance()
->setTextureUnits(irr_driver->getDepthStencilTexture());
DrawFullScreenEffect<FullScreenShader::FogShader>(1.f / (40.f * start), col);
}
} // renderAmbientScatter
// ----------------------------------------------------------------------------
void IrrDriver::renderLightsScatter(unsigned pointlightcount)
{
getFBO(FBO_HALF1).Bind();
@ -293,13 +461,13 @@ void IrrDriver::renderLightsScatter(unsigned pointlightcount)
glEnable(GL_DEPTH_TEST);
core::vector3df col2(1., 1., 1.);
LightShader::PointLightScatterShader::getInstance()->use();
glBindVertexArray(LightShader::PointLightScatterShader::getInstance()->vao);
PointLightScatterShader::getInstance()->use();
glBindVertexArray(PointLightScatterShader::getInstance()->vao);
LightShader::PointLightScatterShader::getInstance()->setTextureUnits(irr_driver->getDepthStencilTexture());
LightShader::PointLightScatterShader::getInstance()->setUniforms(1.f / (40.f * start), col2);
PointLightScatterShader::getInstance()->setTextureUnits(irr_driver->getDepthStencilTexture());
PointLightScatterShader::getInstance()->setUniforms(1.f / (40.f * start), col2);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, MIN2(pointlightcount, MAXLIGHT));
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, MIN2(pointlightcount, LightBaseClass::MAXLIGHT));
glDisable(GL_BLEND);
m_post_processing->renderGaussian6Blur(getFBO(FBO_HALF1), getFBO(FBO_HALF2), 5., 5.);
@ -309,4 +477,4 @@ void IrrDriver::renderLightsScatter(unsigned pointlightcount)
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
getFBO(FBO_COLORS).Bind();
m_post_processing->renderPassThrough(getRenderTargetTexture(RTT_HALF1), getFBO(FBO_COLORS).getWidth(), getFBO(FBO_COLORS).getHeight());
}
} // renderLightsScatter

View File

@ -300,7 +300,7 @@ FrameBuffer* RTT::render(scene::ICameraSceneNode* camera, float dt)
// TODO: put this outside of the rendering loop
irr_driver->generateDiffuseCoefficients();
irr_driver->computeMatrixesAndCameras(camera, m_width, m_height);
unsigned plc = irr_driver->UpdateLightsInfo(camera, dt);
unsigned plc = irr_driver->updateLightsInfo(camera, dt);
irr_driver->uploadLightingData();
irr_driver->renderScene(camera, plc, glows, dt, false, true);
FrameBuffer* frame_buffer = irr_driver->getPostProcessing()->render(camera, false);

View File

@ -443,85 +443,6 @@ namespace MeshShader
}
namespace LightShader
{
PointLightShader::PointLightShader()
{
loadProgram(OBJECT,
GL_VERTEX_SHADER, "pointlight.vert",
GL_FRAGMENT_SHADER, "utils/decodeNormal.frag",
GL_FRAGMENT_SHADER, "utils/SpecularBRDF.frag",
GL_FRAGMENT_SHADER, "utils/DiffuseBRDF.frag",
GL_FRAGMENT_SHADER, "utils/getPosFromUVDepth.frag",
GL_FRAGMENT_SHADER, "pointlight.frag");
assignUniforms();
assignSamplerNames(0, "ntex", ST_NEAREST_FILTERED,
1, "dtex", ST_NEAREST_FILTERED);
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, MAXLIGHT * sizeof(PointLightInfo), 0, GL_DYNAMIC_DRAW);
GLuint attrib_Position = glGetAttribLocation(m_program, "Position");
GLuint attrib_Color = glGetAttribLocation(m_program, "Color");
GLuint attrib_Energy = glGetAttribLocation(m_program, "Energy");
GLuint attrib_Radius = glGetAttribLocation(m_program, "Radius");
glEnableVertexAttribArray(attrib_Position);
glVertexAttribPointer(attrib_Position, 3, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), 0);
glEnableVertexAttribArray(attrib_Energy);
glVertexAttribPointer(attrib_Energy, 1, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), (GLvoid*)(3 * sizeof(float)));
glEnableVertexAttribArray(attrib_Color);
glVertexAttribPointer(attrib_Color, 3, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), (GLvoid*)(4 * sizeof(float)));
glEnableVertexAttribArray(attrib_Radius);
glVertexAttribPointer(attrib_Radius, 1, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), (GLvoid*)(7 * sizeof(float)));
glVertexAttribDivisorARB(attrib_Position, 1);
glVertexAttribDivisorARB(attrib_Energy, 1);
glVertexAttribDivisorARB(attrib_Color, 1);
glVertexAttribDivisorARB(attrib_Radius, 1);
}
PointLightScatterShader::PointLightScatterShader()
{
loadProgram(OBJECT,
GL_VERTEX_SHADER, "pointlight.vert",
GL_FRAGMENT_SHADER, "utils/getPosFromUVDepth.frag",
GL_FRAGMENT_SHADER, "pointlightscatter.frag");
assignUniforms("density", "fogcol");
assignSamplerNames(0, "dtex", ST_NEAREST_FILTERED);
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, PointLightShader::getInstance()->vbo);
GLuint attrib_Position = glGetAttribLocation(m_program, "Position");
GLuint attrib_Color = glGetAttribLocation(m_program, "Color");
GLuint attrib_Energy = glGetAttribLocation(m_program, "Energy");
GLuint attrib_Radius = glGetAttribLocation(m_program, "Radius");
glEnableVertexAttribArray(attrib_Position);
glVertexAttribPointer(attrib_Position, 3, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), 0);
glEnableVertexAttribArray(attrib_Energy);
glVertexAttribPointer(attrib_Energy, 1, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), (GLvoid*)(3 * sizeof(float)));
glEnableVertexAttribArray(attrib_Color);
glVertexAttribPointer(attrib_Color, 3, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), (GLvoid*)(4 * sizeof(float)));
glEnableVertexAttribArray(attrib_Radius);
glVertexAttribPointer(attrib_Radius, 1, GL_FLOAT, GL_FALSE, sizeof(PointLightInfo), (GLvoid*)(7 * sizeof(float)));
glVertexAttribDivisorARB(attrib_Position, 1);
glVertexAttribDivisorARB(attrib_Energy, 1);
glVertexAttribDivisorARB(attrib_Color, 1);
glVertexAttribDivisorARB(attrib_Radius, 1);
}
}
static GLuint createVAO(GLuint Program)
{

View File

@ -67,39 +67,6 @@ public:
}
#define MAXLIGHT 32
namespace LightShader
{
struct PointLightInfo
{
float posX;
float posY;
float posZ;
float energy;
float red;
float green;
float blue;
float radius;
};
class PointLightShader : public TextureShader<PointLightShader, 2>
{
public:
GLuint vbo;
GLuint vao;
PointLightShader();
};
class PointLightScatterShader : public TextureShader<PointLightScatterShader, 1, float, core::vector3df>
{
public:
GLuint vbo;
GLuint vao;
PointLightScatterShader();
};
}
template<typename T, typename... Args>