Commit 2bdde5ff authored by Christopher Tenter's avatar Christopher Tenter

- specular lighting with half-vector,

  positions are still slightly off
- added debug-dump function for renderobjects

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15773 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 5912267f
...@@ -508,7 +508,7 @@ void Renderer::bindObjectVBO(ACG::RenderObject* _obj, ...@@ -508,7 +508,7 @@ void Renderer::bindObjectVBO(ACG::RenderObject* _obj,
// activate vertex declaration // activate vertex declaration
(const_cast<VertexDeclaration*>(_obj->vertexDecl))->activateShaderPipeline(_prog); _obj->vertexDecl->activateShaderPipeline(_prog);
} }
...@@ -759,7 +759,7 @@ void Renderer::collectLightNodes( ACG::SceneGraph::BaseNode* _node ) ...@@ -759,7 +759,7 @@ void Renderer::collectLightNodes( ACG::SceneGraph::BaseNode* _node )
traverseLightNodes(_node); traverseLightNodes(_node);
} }
int Renderer::getNumRenderObjects() int Renderer::getNumRenderObjects() const
{ {
// int i = 0; // int i = 0;
// for (InternalRenderObject* r = renderObjects_; r; ++i, r = r->next); // for (InternalRenderObject* r = renderObjects_; r; ++i, r = r->next);
...@@ -1006,6 +1006,24 @@ QString Renderer::checkOpenGL() ...@@ -1006,6 +1006,24 @@ QString Renderer::checkOpenGL()
return QString(""); return QString("");
} }
void Renderer::dumpRenderObjectsToText(const char* _fileName, RenderObject** _sortedList) const
{
QFile fileOut(_fileName);
if (fileOut.open(QFile::WriteOnly | QFile::Truncate))
{
QTextStream outStrm(&fileOut);
for (int i = 0; i < getNumRenderObjects(); ++i)
{
if (_sortedList)
outStrm << "\n" << _sortedList[i]->toString();
else
outStrm << "\n" << renderObjects_[i].toString();
}
fileOut.close();
}
}
......
...@@ -178,7 +178,15 @@ protected: ...@@ -178,7 +178,15 @@ protected:
void traverseLightNodes(ACG::SceneGraph::BaseNode* _node); void traverseLightNodes(ACG::SceneGraph::BaseNode* _node);
int getNumRenderObjects(); int getNumRenderObjects() const;
/**
Dump list of renderobjects to text file.
@param _fileName name of text file to write to
@param _sortedList dump sorted renderobjects in order, may be 0 to use the unsorted list instead
*/
void dumpRenderObjectsToText(const char* _fileName, ACG::RenderObject** _sortedList = 0) const;
......
#define SHININESS g_vMaterial.x #define SHININESS g_vMaterial.x
#define TRANSPARENCY g_vMaterial.y #define TRANSPARENCY g_vMaterial.y
#define ALPHA g_vMaterial.y #define ALPHA g_vMaterial.y
vec3 LitPointLight(vec3 vPosition, vec3 LitPointLight(vec3 vPosition,
vec3 vNormal, vec3 vNormal,
vec3 vLightPos, vec3 vLightPos,
vec3 cLightAmbient, vec3 cLightAmbient,
vec3 cLightDiffuse, vec3 cLightDiffuse,
vec3 cLightSpecular, vec3 cLightSpecular,
vec3 vLightAtten) vec3 vLightAtten)
{ {
vec3 vLightVS = vPosition - vLightPos; vec3 vLightVS = vPosition - vLightPos;
float fLen2 = dot(vLightVS, vLightVS); float fLen2 = dot(vLightVS, vLightVS);
float fLen = sqrt(fLen2); float fLen = sqrt(fLen2);
vec3 vLightDir = vLightVS / fLen; vec3 vLightDir = vLightVS / fLen;
// ambient // ambient
vec3 cLight = cLightAmbient * g_cAmbient; vec3 cLight = cLightAmbient * g_cAmbient;
// diffuse // diffuse
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0); float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
cLight += ldotn * cLightDiffuse * g_cDiffuse; cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular // specular
cLight += (floor(ldotn + 0.9) * pow(ldotn, SHININESS) ) * cLightSpecular * g_cSpecular; vec3 h = normalize(vec3(0, 0, 1) + vLightDir);
float hdotn = max(dot(h, vNormal), 0.0);
cLight += (pow(hdotn, SHININESS) * cLightSpecular) * g_cSpecular;
// attenuate
float fAtten = vLightAtten.x + vLightAtten.y * fLen + vLightAtten.z * fLen2;
// attenuate
return cLight / fAtten; float fAtten = vLightAtten.x + vLightAtten.y * fLen + vLightAtten.z * fLen2;
}
return cLight / fAtten;
}
vec3 LitDirLight(vec3 vNormal,
vec3 vLightDir,
vec3 cLightAmbient, vec3 LitDirLight(vec3 vNormal,
vec3 cLightDiffuse, vec3 vLightDir,
vec3 cLightSpecular) vec3 cLightAmbient,
{ vec3 cLightDiffuse,
// ambient vec3 cLightSpecular)
vec3 cLight = cLightAmbient * g_cAmbient; {
// ambient
// diffuse vec3 cLight = cLightAmbient * g_cAmbient;
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
cLight += ldotn * cLightDiffuse * g_cDiffuse; // diffuse
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
// specular cLight += ldotn * cLightDiffuse * g_cDiffuse;
cLight += (floor(ldotn + 0.9) * pow(ldotn, SHININESS) ) * cLightSpecular * g_cSpecular;
// specular
return cLight; vec3 h = normalize(vec3(0, 0, 1) + vLightDir);
} float hdotn = max(dot(h, vNormal), 0.0);
cLight += (pow(hdotn, SHININESS) * cLightSpecular) * g_cSpecular;
return cLight;
vec3 LitSpotLight(vec3 vPosition, }
vec3 vNormal,
vec3 vLightPos,
vec3 vSpotLightDir,
vec3 cLightAmbient, vec3 LitSpotLight(vec3 vPosition,
vec3 cLightDiffuse, vec3 vNormal,
vec3 cLightSpecular, vec3 vLightPos,
vec3 vLightAtten, vec3 vSpotLightDir,
vec2 vLightSpotAngleExp) vec3 cLightAmbient,
{ vec3 cLightDiffuse,
vec3 vLightVS = vPosition - vLightPos; vec3 cLightSpecular,
float fLen2 = dot(vLightVS, vLightVS); vec3 vLightAtten,
float fLen = sqrt(fLen2); vec2 vLightSpotAngleExp)
{
vec3 vLightDir = vLightVS / fLen; vec3 vLightVS = vPosition - vLightPos;
float fLen2 = dot(vLightVS, vLightVS);
// ambient float fLen = sqrt(fLen2);
vec3 cLight = cLightAmbient * g_cAmbient;
vec3 vLightDir = vLightVS / fLen;
// diffuse
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0); // ambient
cLight += ldotn * cLightDiffuse * g_cDiffuse; vec3 cLight = cLightAmbient * g_cAmbient;
// specular // diffuse
cLight += (floor(ldotn + 0.9) * pow(ldotn, SHININESS) ) * cLightSpecular * g_cSpecular; float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// attenuate // specular
float fAtten = vLightAtten.x + vLightAtten.y * fLen + vLightAtten.z * fLen2; vec3 h = normalize(vec3(0, 0, 1) + vLightDir);
float hdotn = max(dot(h, vNormal), 0.0);
// spot angle falloff cLight += (pow(hdotn, SHININESS) * cLightSpecular) * g_cSpecular;
float fSpot = -dot(vLightDir, vSpotLightDir);
fSpot *= step(vLightSpotAngleExp.x, fSpot);
fSpot *= pow(fSpot, vLightSpotAngleExp.y);
// attenuate
return cLight * (fSpot / fAtten); float fAtten = vLightAtten.x + vLightAtten.y * fLen + vLightAtten.z * fLen2;
}
// spot angle falloff
float fSpot = -dot(vLightDir, vSpotLightDir);
fSpot *= step(vLightSpotAngleExp.x, fSpot);
fSpot *= pow(fSpot, vLightSpotAngleExp.y);
return cLight * (fSpot / fAtten);
}
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