fragment shader ...
Posted: Wed Feb 11, 2009 11:41 am
The fragment shader starts by pulling info from the plist and the vertex shader ... I have to figure out what is needed:
The vertex shader seems to build a tangent space ... comparing the griff-boa fs to the griff-boa vs suggest I need to get these:
I'm going to need functions to cover the hull heat glow and the engine heat glow (which, between last post and this I decided will be orangy - not cyan - to fit with the diffuse map color. Hull lights etc will be constant.
Now - this bit:
... is a bit dense to me - I don't get it. It looks kinda like the normal-vector calculations in the shady-cobra vertex shader. Anyway, it's used in a #define ...
... so I figure this is setting up how the normal map effects get added. I'm a little worried that there will be a clash between the two definitions of SpecExponent but some systems let you pass values like that.
Now should be ready for the main function - starts out initializing what is going to end up as holding the final color/lighting stuff that gets applied, and loads the textures. There's an exrta bit for normal maps which I'm not used to.
I think that "- 0.5" on the end of the first "normal =" line is some sort of scaling?
Note that the griff boa sets specular intensity to a constant - but I want to use the alpha channel in the texture for this ... which will be fun when I get around to playing with it.
From here I need to add in the effects, and the specular:
In-ter-rest-ting ... the alpha channel in the fx map is used as an illumination map. I've not actually played with this purposely.
Now - apart from syntax errors - which I never see before hitting "send" - I'm sure I've missed something out...
Code: Select all
// Information from Oolite.
uniform sampler2D uColorMap; // Diffuse and Specular Intensity map
uniform sampler2D uFXMap; // Effects & Light Illumination Map
uniform sampler2D uNormalMap; // Normal Map
const float SpecExponent = 4.0;
uniform vec3 SpecularRGB
uniform float time;
uniform float eng_pow;
uniform float hull_heat;
Code: Select all
varying vec2 vTexCoord;
varying vec3 vEyeVector; // These are all in tangent space
varying vec3 vLight0Vector;
varying vec3 vLight1Vector;
Code: Select all
// redGlow effect
vec4 redGlow(float level)
{
vec4 result;
result.rgb = vec3(1.9, 0.5, 0.2) * level * 2.0;
result.a = 1.0;
return result;
}
// EngineGlow effect
vec4 EngineGlow(float level)
{
vec4 result;
result.rgb = vec3(1.9, 0.5, 0.20) * level;
result.a = 1.0;
return result;
}
Code: Select all
void Light(in vec3 lightVector, in vec3 normal, in vec4 lightColor, in vec3 eyeVector,
in float specExponent, inout vec4 totalDiffuse, inout vec4 totalSpecular)
{
lightVector = normalize(lightVector);
vec3 reflection = normalize(-reflect(lightVector, normal));
totalDiffuse += gl_FrontMaterial.diffuse * lightColor * max(dot(normal, lightVector), 0.0);
totalSpecular += lightColor * pow(max(dot(reflection, eyeVector), 0.0), specExponent);
}
Code: Select all
#define LIGHT(idx, vector) Light(vector, normal, gl_LightSource[idx].diffuse, eyeVector, SpecExponent, diffuse, specular)
Now should be ready for the main function - starts out initializing what is going to end up as holding the final color/lighting stuff that gets applied, and loads the textures. There's an exrta bit for normal maps which I'm not used to.
Code: Select all
void main()
{
vec4 diffuse = vec4(0.0), specular = vec4(0);
vec3 eyeVector = normalize(vEyeVector);
vec2 texCoord = vTexCoord; // what's this?
// Load texture data
vec4 colorMap = texture2D(uColorMap, texCoord);
vec4 fxMap = texture2D(uFXMap, texCoord);
vec3 normal = normalize( texture2D(uNormalMap, texCoord).xyz - 0.5);
normal = normalize(normal);
float specIntensity = 15.0 * colorMap.a * colorMap.a;
Note that the griff boa sets specular intensity to a constant - but I want to use the alpha channel in the texture for this ... which will be fun when I get around to playing with it.
From here I need to add in the effects, and the specular:
Code: Select all
#ifdef OO_LIGHT_0_FIX
LIGHT(0, normalize(vLight0Vector));
#endif
LIGHT(1, normalize(vLight1Vector)); // change the 0 to 1 when exporting back to oolite
diffuse += gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
diffuse += fxMap.a; // use fxmap alpha channel as an illumination map
vec4 color = diffuse * colorMap;
color += redGlow(effectsMap.b * Pulse(min(eng_pow, 1.0), 1.0)); // adds red 'engine heat' glow
color += EngineGlow(effectsMap.r * eng_pow); // adds orange/red exhaust-vent glow
// calculate the specular, color it using a weighted sum of diffuse map and imported color
color += 3.0 * ((0.7*SpecularRGB)+(0.3*colorMap)) * specular * specIntensity;
color.a = 1.0;
gl_FragColor = color;
}
Now - apart from syntax errors - which I never see before hitting "send" - I'm sure I've missed something out...