Improve how normal maps work on movimng objects
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10312 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -8,6 +8,9 @@ uniform sampler2D BumpTex; //The bump-map
|
||||
varying vec3 LightDir; //Receiving the transformed light direction
|
||||
void main()
|
||||
{
|
||||
vec4 LightDirTransformed4 = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(LightDir[0], LightDir[1], LightDir[2], 0);
|
||||
vec3 LightDirTransformed = vec3(LightDirTransformed4[0], LightDirTransformed4[1], LightDirTransformed4[2]);
|
||||
|
||||
//Get the color of the bump-map
|
||||
vec3 BumpNorm = vec3(texture2D(BumpTex, gl_TexCoord[0].xy));
|
||||
//Get the color of the texture
|
||||
@@ -15,7 +18,7 @@ uniform sampler2D BumpTex; //The bump-map
|
||||
//Expand the bump-map into a normalized signed vector
|
||||
BumpNorm = (BumpNorm -0.5) * 2.0;
|
||||
//Find the dot product between the light direction and the normal
|
||||
float NdotL = max(dot(BumpNorm, LightDir), 0.0) / 3.0 * 2.1 + 0.5;
|
||||
float NdotL = max(dot(BumpNorm, LightDirTransformed), 0.0) / 3.0 * 2.1 + 0.5;
|
||||
//Calculate the final color gl_FragColor
|
||||
vec3 diffuse = NdotL * passcolor.xyz * DecalCol;
|
||||
//Set the color of the fragment... If you want specular lighting or other types add it here
|
||||
|
||||
@@ -5,6 +5,7 @@ uniform sampler2D tex_detail0;
|
||||
uniform sampler2D tex_detail1;
|
||||
uniform sampler2D tex_detail2;
|
||||
uniform sampler2D tex_detail3;
|
||||
uniform sampler2D tex_detail4;
|
||||
|
||||
void main()
|
||||
{
|
||||
@@ -13,8 +14,11 @@ void main()
|
||||
vec4 detail1 = texture2D(tex_detail1, gl_TexCoord[1].st);
|
||||
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.r - layout.g - layout.b) * detail3 +
|
||||
(1.0 - layout.a) * detail4;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,12 @@ public:
|
||||
services->setPixelShaderConstant("BumpTex", (float*)&bumptex, 1);
|
||||
|
||||
// TODO: check the position of the sun
|
||||
const float lightdir[] = {0.5f, 0.5f, 1.0f};
|
||||
/*
|
||||
You have to calculate the light position in (model)view Space. It can be done, by transforming the light positions and rotations
|
||||
with the modelviewmatrix, after the camera is set. You should do this calculations before the shader runs, but it is also possible
|
||||
to pass the camera matrix (calculation in modelviewspace) or ModelMatrix (calculation in WorldSpace) to a shader.
|
||||
*/
|
||||
const float lightdir[] = {-0.5f, -0.5f, -1.0f};
|
||||
services->setVertexShaderConstant("lightdir", lightdir, 3);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user