Add lambert lighting to the splatting shader to make it look less flat

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10435 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-12-18 00:48:35 +00:00
parent cb668a211a
commit 1ce4443ed8
3 changed files with 23 additions and 7 deletions

View File

@ -6,6 +6,8 @@ uniform sampler2D tex_detail1;
uniform sampler2D tex_detail2;
uniform sampler2D tex_detail3;
uniform sampler2D tex_detail4;
varying vec3 normal;
varying vec3 lightdir2;
void main()
{
@ -15,10 +17,11 @@ void main()
vec4 detail2 = texture2D(tex_detail2, gl_TexCoord[1].st);
vec4 detail3 = texture2D(tex_detail3, gl_TexCoord[1].st);
vec4 detail4 = texture2D(tex_detail4, gl_TexCoord[1].st);
gl_FragColor = layout.r * detail0 +
layout.g * detail1 +
layout.b * detail2 +
(1.0 - layout.r - layout.g - layout.b) * detail3 +
(1.0 - layout.a) * detail4;
gl_FragColor = (layout.r * detail0 +
layout.g * detail1 +
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 :)
}

View File

@ -1,7 +1,15 @@
varying vec3 normal;
varying vec3 lightdir2;
uniform vec3 lightdir;
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
gl_Position = ftransform();
gl_Position = ftransform();
//normal = normalize(gl_NormalMatrix * gl_Normal);
normal = normalize(gl_Normal);
lightdir2 = normalize(lightdir);
}

View File

@ -99,6 +99,11 @@ public:
// Irrlicht knows this is actually a GLint and makes the conversion
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);
}
};