Add support for specular light
Note that specular light is applied unconditionnaly, thus every object will shine. TODO : Specular map should be defined using texture or a material flag. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14756 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
5db6705889
commit
34d83859cd
@ -7,14 +7,9 @@ void main()
|
||||
{
|
||||
vec2 texc = gl_TexCoord[0].xy;
|
||||
|
||||
vec4 col = texture2D(diffuse_and_spec, texc);
|
||||
vec3 diffuse = texture2D(diffuse_and_spec, texc).xyz;
|
||||
vec3 specular = texture2D(diffuse_and_spec, texc).www;
|
||||
float ao = texture2D(ambient_occlusion, texc).x;
|
||||
|
||||
col.xyz += ao * ambient;
|
||||
float spec = col.a - 0.05;
|
||||
//spec *= specular.a;
|
||||
col.xyz += spec * col.xyz;
|
||||
col.a = 1.0;
|
||||
|
||||
gl_FragColor = col;
|
||||
gl_FragColor = vec4(diffuse + specular + ao * ambient, 1.0);
|
||||
}
|
||||
|
@ -24,13 +24,12 @@ void main() {
|
||||
|
||||
// Light Direction
|
||||
vec3 L = normalize(xpos.xyz - center);
|
||||
vec3 eyedir = normalize(xpos.xyz);
|
||||
vec3 H = normalize(-L + eyedir);
|
||||
|
||||
float NdotL = max(0.0, dot(norm, -L)) * att;
|
||||
float NdotH = max(0.0, dot(norm, H));
|
||||
NdotH = pow(NdotH, spec);
|
||||
NdotH += 0.05; // offset so that the alpha test doesn't kill us
|
||||
// Reflected light dir
|
||||
vec3 R = reflect(-L, norm);
|
||||
float RdotE = max(0.0, dot(R, normalize(xpos)));
|
||||
float Specular = pow(RdotE, spec);
|
||||
|
||||
gl_FragColor = NdotL * vec4(NdotL * col, NdotH);
|
||||
gl_FragColor = vec4(NdotL * col, Specular + 0.001); // Irrlicht force alpha test, can't be 0
|
||||
}
|
||||
|
@ -12,6 +12,9 @@ void main() {
|
||||
|
||||
vec2 texc = gl_FragCoord.xy / screen;
|
||||
float z = texture2D(ntex, texc).a;
|
||||
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0;
|
||||
xpos = invproj * xpos;
|
||||
xpos.xyz /= xpos.w;
|
||||
|
||||
if (z < 0.03)
|
||||
{
|
||||
@ -28,18 +31,14 @@ void main() {
|
||||
vec3 L = center;
|
||||
|
||||
float NdotL = max(0.0, dot(norm, L));
|
||||
vec3 R = reflect(L, norm);
|
||||
float RdotE = max(0.0, dot(R, normalize(xpos)));
|
||||
float Specular = pow(RdotE, 200);
|
||||
|
||||
vec3 outcol = NdotL * col;
|
||||
|
||||
if (hasclouds == 1)
|
||||
{
|
||||
vec3 tmp = vec3(texc, z);
|
||||
tmp = tmp * 2.0 - 1.0;
|
||||
|
||||
vec4 xpos = vec4(tmp, 1.0);
|
||||
xpos = invproj * xpos;
|
||||
xpos.xyz /= xpos.w;
|
||||
|
||||
vec2 cloudcoord = (xpos.xz * 0.00833333) + wind;
|
||||
float cloud = texture2D(cloudtex, cloudcoord).x;
|
||||
//float cloud = step(0.5, cloudcoord.x) * step(0.5, cloudcoord.y);
|
||||
@ -47,6 +46,6 @@ void main() {
|
||||
outcol *= cloud;
|
||||
}
|
||||
|
||||
gl_FragData[0] = vec4(outcol, 0.05);
|
||||
gl_FragData[0] = vec4(NdotL * col, Specular+ 0.001); // Irrlicht force alpha test, can't be 0
|
||||
gl_FragData[1] = vec4(1.0);
|
||||
}
|
||||
|
@ -673,7 +673,7 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox,
|
||||
if (!m_lightviz)
|
||||
{
|
||||
m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_TMP1), true, false,
|
||||
video::SColor(1, 0, 0, 0));
|
||||
video::SColor(0, 0, 0, 0));
|
||||
} else
|
||||
{
|
||||
m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_COLOR), false, false);
|
||||
|
Loading…
Reference in New Issue
Block a user