Improve Lambert shading in splatting : actually use the sun direction

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10438 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-12-18 02:39:05 +00:00
parent 1ce4443ed8
commit 683b0e1903
4 changed files with 27 additions and 5 deletions

View File

@ -23,5 +23,5 @@ void main()
layout.b * detail2 +
(1.0 - layout.r - layout.g - layout.b) * detail3 +
(1.0 - layout.a) * detail4)
* min(1.0, 0.2 + 1.5*dot(lightdir2, normal)); // 0.2 is the ambient light. *1.5 is from trial are error to make it look nice :)
* min(1.0, 0.2 + dot(lightdir2, normal)); // 0.2 is the ambient light.
}

View File

@ -31,6 +31,8 @@
#include "io/file_manager.hpp"
#include "io/xml_node.hpp"
#include "utils/string_utils.hpp"
#include "modes/world.hpp"
#include "tracks/track.hpp"
#include <IGPUProgrammingServices.h>
#include <IMaterialRendererServices.h>
@ -73,13 +75,27 @@ public:
class SplattingProvider : public video::IShaderConstantSetCallBack
{
core::vector3df m_light_direction;
bool m_light_dir_calculated;
public:
LEAK_CHECK()
SplattingProvider()
{
m_light_dir_calculated = false;
}
virtual void OnSetConstants(
irr::video::IMaterialRendererServices *services,
s32 userData)
{
if (!m_light_dir_calculated)
{
m_light_dir_calculated = true;
m_light_direction = -World::getWorld()->getTrack()->getSunRotation().rotationToDirection();
}
// Irrlicht knows this is actually a GLint and makes the conversion
int tex_layout = 0;
services->setPixelShaderConstant("tex_layout", (float*)&tex_layout, 1);
@ -100,10 +116,7 @@ public:
int tex_detail3 = 4;
services->setPixelShaderConstant("tex_detail3", (float*)&tex_detail3, 1);
// TODO: check the position of the sun
core::vector3df lightdir(-0.1f, 0.1f, 0.0f);
lightdir.normalize();
services->setVertexShaderConstant("lightdir", &lightdir.X, 3);
services->setVertexShaderConstant("lightdir", &m_light_direction.X, 3);
}
};

View File

@ -1631,3 +1631,10 @@ std::vector< std::vector<float> > Track::buildHeightMap()
return out;
}
// ----------------------------------------------------------------------------
core::vector3df Track::getSunRotation()
{
return m_sun->getRotation();
}

View File

@ -387,6 +387,8 @@ public:
CheckManager* getCheckManager() { return m_check_manager; }
core::vector3df getSunRotation();
TrackObjectManager* getTrackObjectManager() { return m_track_object_manager; }
}; // class Track