Commit 501c077b authored by Christopher Tenter's avatar Christopher Tenter
Browse files

- fix specular lighting of directional lights in the shader pipeline

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18403 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ecd37a04
......@@ -565,7 +565,15 @@ void IRenderer::renderObject(ACG::RenderObject* _obj,
void IRenderer::addLight(const LightData& _light)
{
if (numLights_ < SG_MAX_SHADER_LIGHTS)
lights_[numLights_++] = _light;
{
lights_[numLights_] = _light;
// normalize direction
if (_light.ltype != SG_LIGHT_POINT)
lights_[numLights_].dir.normalize();
++numLights_;
}
}
......@@ -575,6 +583,26 @@ int IRenderer::getNumRenderObjects() const
}
int IRenderer::getNumLights() const
{
return numLights_;
}
ACG::RenderObject* IRenderer::getRenderObject( int i )
{
if (sortedObjects_.empty())
return &renderObjects_[i];
return sortedObjects_[i];
}
IRenderer::LightData* IRenderer::getLight( int i )
{
return &lights_[i];
}
void IRenderer::dumpRenderObjectsToFile(const char* _fileName, ACG::RenderObject** _sortedList) const
{
QFile fileOut(_fileName);
......
......@@ -323,9 +323,18 @@ public:
//=========================================================================
protected:
/// Get the number of current light sources
/// Get the number of collected render objects sources
int getNumRenderObjects() const;
/// Get the number of current light sources
int getNumLights() const;
/// Get render objects in the sorted list by index
ACG::RenderObject* getRenderObject(int i);
/// Get light by index
LightData* getLight(int i);
protected:
/// Number of Lights
......
......@@ -32,7 +32,7 @@ vec3 LitPointLight(vec3 vPosition,
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
vec3 h = normalize(vLightDir - normalize(vPosition)); // half vector between light and view direction
vec3 h = normalize(vLightDir - vec3(0,0,-1)); // half vector between light and view direction
float hdotn = max(dot(h, vNormal), 0.0);
cLight += (pow(hdotn, SHININESS) * cLightSpecular) * g_cSpecular;
......@@ -59,7 +59,7 @@ vec3 LitDirLight(vec3 vPosition,
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
vec3 h = normalize(vLightDir - normalize(vPosition)); // half vector between light and view direction
vec3 h = normalize(vLightDir - vec3(0,0,-1)); // half vector between light and view direction
float hdotn = max(dot(h, vNormal), 0.0);
cLight += (pow(hdotn, SHININESS) * cLightSpecular) * g_cSpecular;
......@@ -92,7 +92,7 @@ vec3 LitSpotLight(vec3 vPosition,
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
vec3 h = normalize(vLightDir - normalize(vPosition)); // half vector between light and view direction
vec3 h = normalize(vLightDir - vec3(0,0,-1)); // half vector between light and view direction
float hdotn = max(dot(h, vNormal), 0.0);
cLight += (pow(hdotn, SHININESS) * cLightSpecular) * g_cSpecular;
......
......@@ -68,7 +68,8 @@ vec3 LitPointLight_Cel(vec3 vPosition,
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
vec3 h = normalize(vLightDir - normalize(vPosition)); // half vector between light and view direction
// vec3 h = normalize(vLightDir - normalize(vPosition)); // half vector between light and view direction
vec3 h = normalize(vLightDir - vec3(0,0,-1)); // half vector between light and view direction
float hdotn = max(dot(h, vNormal), 0.0);
// hdotn = QuantizeSpecular_Cel(hdotn, paletteSize);
cLight += QuantizeSpecular_Cel(pow(hdotn, SHININESS), paletteSize) * cLightSpecular * g_cSpecular;
......@@ -98,7 +99,7 @@ vec3 LitDirLight_Cel(vec3 vPosition,
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
vec3 h = normalize(vLightDir - normalize(vPosition)); // half vector between light and view direction
vec3 h = normalize(vLightDir - vec3(0,0,-1)); // half vector between light and view direction
float hdotn = max(dot(h, vNormal), 0.0);
// hdotn = QuantizeSpecular_Cel(hdotn, paletteSize);
cLight += QuantizeSpecular_Cel(pow(hdotn, SHININESS), paletteSize) * cLightSpecular * g_cSpecular;
......@@ -134,7 +135,7 @@ vec3 LitSpotLight_Cel(vec3 vPosition,
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
vec3 h = normalize(vLightDir - normalize(vPosition)); // half vector between light and view direction
vec3 h = normalize(vLightDir - vec3(0,0,-1)); // half vector between light and view direction
float hdotn = max(dot(h, vNormal), 0.0);
// hdotn = QuantizeSpecular_Cel(hdotn, paletteSize);
cLight += QuantizeSpecular_Cel(pow(hdotn, SHININESS), paletteSize) * cLightSpecular * g_cSpecular;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment