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,
// 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 )
traverseLightNodes(_node);
}
int Renderer::getNumRenderObjects()
int Renderer::getNumRenderObjects() const
{
// int i = 0;
// for (InternalRenderObject* r = renderObjects_; r; ++i, r = r->next);
......@@ -1006,6 +1006,24 @@ QString Renderer::checkOpenGL()
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:
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 TRANSPARENCY g_vMaterial.y
#define ALPHA g_vMaterial.y
vec3 LitPointLight(vec3 vPosition,
vec3 vNormal,
vec3 vLightPos,
vec3 cLightAmbient,
vec3 cLightDiffuse,
vec3 cLightSpecular,
vec3 vLightAtten)
{
vec3 vLightVS = vPosition - vLightPos;
float fLen2 = dot(vLightVS, vLightVS);
float fLen = sqrt(fLen2);
vec3 vLightDir = vLightVS / fLen;
// ambient
vec3 cLight = cLightAmbient * g_cAmbient;
// diffuse
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
cLight += (floor(ldotn + 0.9) * pow(ldotn, SHININESS) ) * cLightSpecular * g_cSpecular;
// attenuate
float fAtten = vLightAtten.x + vLightAtten.y * fLen + vLightAtten.z * fLen2;
return cLight / fAtten;
}
vec3 LitDirLight(vec3 vNormal,
vec3 vLightDir,
vec3 cLightAmbient,
vec3 cLightDiffuse,
vec3 cLightSpecular)
{
// ambient
vec3 cLight = cLightAmbient * g_cAmbient;
// diffuse
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
cLight += (floor(ldotn + 0.9) * pow(ldotn, SHININESS) ) * cLightSpecular * g_cSpecular;
return cLight;
}
vec3 LitSpotLight(vec3 vPosition,
vec3 vNormal,
vec3 vLightPos,
vec3 vSpotLightDir,
vec3 cLightAmbient,
vec3 cLightDiffuse,
vec3 cLightSpecular,
vec3 vLightAtten,
vec2 vLightSpotAngleExp)
{
vec3 vLightVS = vPosition - vLightPos;
float fLen2 = dot(vLightVS, vLightVS);
float fLen = sqrt(fLen2);
vec3 vLightDir = vLightVS / fLen;
// ambient
vec3 cLight = cLightAmbient * g_cAmbient;
// diffuse
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
cLight += (floor(ldotn + 0.9) * pow(ldotn, SHININESS) ) * cLightSpecular * g_cSpecular;
// attenuate
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);
}
#define SHININESS g_vMaterial.x
#define TRANSPARENCY g_vMaterial.y
#define ALPHA g_vMaterial.y
vec3 LitPointLight(vec3 vPosition,
vec3 vNormal,
vec3 vLightPos,
vec3 cLightAmbient,
vec3 cLightDiffuse,
vec3 cLightSpecular,
vec3 vLightAtten)
{
vec3 vLightVS = vPosition - vLightPos;
float fLen2 = dot(vLightVS, vLightVS);
float fLen = sqrt(fLen2);
vec3 vLightDir = vLightVS / fLen;
// ambient
vec3 cLight = cLightAmbient * g_cAmbient;
// diffuse
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
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;
return cLight / fAtten;
}
vec3 LitDirLight(vec3 vNormal,
vec3 vLightDir,
vec3 cLightAmbient,
vec3 cLightDiffuse,
vec3 cLightSpecular)
{
// ambient
vec3 cLight = cLightAmbient * g_cAmbient;
// diffuse
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
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 cLightDiffuse,
vec3 cLightSpecular,
vec3 vLightAtten,
vec2 vLightSpotAngleExp)
{
vec3 vLightVS = vPosition - vLightPos;
float fLen2 = dot(vLightVS, vLightVS);
float fLen = sqrt(fLen2);
vec3 vLightDir = vLightVS / fLen;
// ambient
vec3 cLight = cLightAmbient * g_cAmbient;
// diffuse
float ldotn = clamp(dot(vLightDir, vNormal), 0.0, 1.0);
cLight += ldotn * cLightDiffuse * g_cDiffuse;
// specular
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;
// 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