Shader patch
Posted: Fri Apr 04, 2008 1:12 am
In default.fp, line 45, the function is commented out, but anyhow, it's buggy when you try to use shininess from spec's alpha. Needs a clamp.
From,change to
The following is not a bug fix, but is a major improvement. The shininessMap function currently in use, which computes shininess from specularity, needs to be a lot less linear. The way it is now, most materials get way too much shininess; almost as bad as before shaders. Just squaring the luma was a great improvement; but then I found something even better: dotting the spec.rgb by itself, before averaging. This allows colored materials, such as bronze and paints to get more shininess than grey metals, all specularities being equal.
From,change to,
Next is two bugs in one line of code: envLod is never used. Also, the last multiplying term in that line, envColor.rgb does not belong. Wherever it comes from, it doesn't matter, really. The color of a reflection should be the color of the background it reflects, times the specular color. No other terms are warranted; and removing it improved the visuals. But I also added a 2.0 multiplier to compensate for the dimming in code of the environment spheremaps when they are generated from the background textures. MUCH better, now. From,change to,
Starting to work...
Also, I don't know why, but I set my shader to "nicest", yet the engine is using default.vp and default.fp.
EDIT:
Just found another bug: The shininessMap() function is being called from two places, which is a waste of instructions, since all functions are inlined, in shaders. Looking into it...
EDIT2:
Make that multiple times...
There's a "lighting" macro that, for each light, instantiates a "call" to a big function, lightingLight(); which in turn "calls" shininessMap(); then shininessMap is "called" again from envMapping(), which is "called" from main()
EDIT3:
Another bug, 99% probably: That lightingLight function is multiplying environmental reflections by selfshadow. I don't know how this selfshadow stuff works, but I do know for a fact that specular reflections aren't affected by shadows. Mirrors don't receive shadows. This is probably why, as I've noticed, env mapped reflections look darker when you look at a ship from the shadowed side. That's totally incorrect.
From,
Code: Select all
//float shininessMap(float shininess, vec4 specmap) { return specmap.a*shininess; } // alpha-based shininess modulation
Code: Select all
//float shininessMap(float shininess, vec4 specmap) { return clamp(specmap.a*shininess,1.0,255.0); } // alpha-based shininess modulation
From,
Code: Select all
float shininessMap(float shininess, vec4 specmap){ return clamp(dot(specmap.rgb,vec3(1.0/3.0))*shininess,1.0,256.0); } // luma-based shininess modulation
Code: Select all
float shininessMap(float shininess, vec4 specmap) // luma-based shininess modulation
{
float temp = dot( specmap.rgb, specmap.rgb );
temp *= 0.333;
return clamp( temp*shininess, 1.0, 255.0 );
}
Code: Select all
vec3 envMapping(in vec3 reflection, in float shininess, in vec4 specmap)
{
float envLod = shininess2Lod(shininessMap(shininess,specmap));
return texture2D(envMap, EnvMapGen(reflection)).rgb * specmap.rgb * envColor.rgb;
}
Code: Select all
vec3 envMapping(in vec3 reflection, in float shininess, in vec4 specmap)
{
float envLod = shininess2Lod(shininessMap(shininess,specmap));
return texture2DLod(envMap, EnvMapGen(reflection), envLod).rgb * specmap.rgb * vec3(2.0);
}
Also, I don't know why, but I set my shader to "nicest", yet the engine is using default.vp and default.fp.
EDIT:
Just found another bug: The shininessMap() function is being called from two places, which is a waste of instructions, since all functions are inlined, in shaders. Looking into it...
EDIT2:
Make that multiple times...
There's a "lighting" macro that, for each light, instantiates a "call" to a big function, lightingLight(); which in turn "calls" shininessMap(); then shininessMap is "called" again from envMapping(), which is "called" from main()
EDIT3:
Another bug, 99% probably: That lightingLight function is multiplying environmental reflections by selfshadow. I don't know how this selfshadow stuff works, but I do know for a fact that specular reflections aren't affected by shadows. Mirrors don't receive shadows. This is probably why, as I've noticed, env mapped reflections look darker when you look at a ship from the shadowed side. That's totally incorrect.