Reenable custom light radius

This commit is contained in:
Vincent Lejeune 2014-05-12 19:36:45 +02:00
parent e8b4926b0b
commit 96babc81ad
5 changed files with 18 additions and 8 deletions

View File

@ -22,6 +22,7 @@ layout (std140) uniform MatrixesData
flat in vec3 center;
flat in float energy;
flat in vec3 col;
flat in float radius;
out vec4 Diffuse;
out vec4 Specular;
@ -46,8 +47,7 @@ void main()
vec3 light_col = col.xyz;
float d = distance(light_pos, xpos.xyz);
float att = energy * 20. / (1. + d * d);
float max_d = 5. * energy;
att *= (max_d - d) / max_d;
att *= (radius - d) / radius;
if (att <= 0.) discard;
// Light Direction

View File

@ -17,10 +17,12 @@ layout (std140) uniform MatrixesData
in vec3 Position;
in float Energy;
in vec3 Color;
in float Radius;
flat out vec3 center;
flat out float energy;
flat out vec3 col;
flat out float radius;
const float zNear = 1.;
@ -86,12 +88,11 @@ vec4 ComputeClipRegion(vec3 lightPosView, float lightRadius)
void main(void)
{
float radius = 5. * Energy;
vec4 Center = ViewMatrix * vec4(Position, 1.);
Center /= Center.w;
vec2 ProjectedCornerPosition;
vec4 clip = ComputeClipRegion(Center.xyz, radius);
vec4 clip = ComputeClipRegion(Center.xyz, Radius);
switch (gl_VertexID)
{
case 0:
@ -110,7 +111,7 @@ void main(void)
// Work out nearest depth for quad Z
// Clamp to near plane in case this light intersects the near plane... don't want our quad to be clipped
float quadDepth = max(zNear, Center.z - radius);
float quadDepth = max(zNear, Center.z - Radius);
// Project quad depth into clip space
vec4 quadClip = ProjectionMatrix * vec4(0., 0., quadDepth, 1.0f);
@ -119,4 +120,5 @@ void main(void)
col = Color;
center = Position;
energy = Energy;
radius = Radius;
}

View File

@ -789,7 +789,7 @@ static void renderPointLights(unsigned count)
setTexture(1, irr_driver->getDepthStencilTexture(), GL_NEAREST, GL_NEAREST);
LightShader::PointLightShader
::setUniforms(core::vector2df(float(UserConfigParams::m_width),
float(UserConfigParams::m_height) ),
float(UserConfigParams::m_height) ),
200, 0, 1);
glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, count);
@ -870,6 +870,9 @@ void IrrDriver::renderLights(scene::ICameraSceneNode * const camnode, float dt)
PointLightsInfo[lightnum].red = col.X;
PointLightsInfo[lightnum].green = col.Y;
PointLightsInfo[lightnum].blue = col.Z;
// Light radius
PointLightsInfo[lightnum].radius = 20 * light_node->getEffectiveEnergy();
}
}
if (lightnum > MAXLIGHT)

View File

@ -1825,6 +1825,7 @@ namespace LightShader
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;
@ -1843,6 +1844,7 @@ namespace LightShader
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");
@ -1861,10 +1863,13 @@ namespace LightShader
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)));
glVertexAttribDivisor(attrib_Position, 1);
glVertexAttribDivisor(attrib_Energy, 1);
glVertexAttribDivisor(attrib_Color, 1);
glVertexAttribDivisor(attrib_Radius, 1);
}
void PointLightShader::setUniforms(const core::vector2df &screen, unsigned spec, unsigned TU_ntex, unsigned TU_dtex)

View File

@ -440,7 +440,7 @@ namespace LightShader
float red;
float green;
float blue;
float padding;
float radius;
};
@ -448,7 +448,7 @@ namespace LightShader
{
public:
static GLuint Program;
static GLuint attrib_Position, attrib_Energy, attrib_Color;
static GLuint attrib_Position, attrib_Energy, attrib_Color, attrib_Radius;
static GLuint uniform_ntex, uniform_dtex, uniform_spec, uniform_screen;
static GLuint vbo;
static GLuint vao;