@ the griff signal, doesn't look like a welsh sky though, not enough rain clouds, also needs more sheep
fragment & vertex shaders are written in GLSL
http://en.wikipedia.org/wiki/GLSL (GLSL version 2.1 i think is what Oolite uses)
I don't really know much about the language but i can certainly write out how texture re-colouring is done in the shaders in my shipset if it's any help.
first in the shipdata.plist, we'll list the texture files, in this example a diffuse texture (or 'skin' texture) and a normal map
Code: Select all
textures =
(
"griff_adder_diffuse.png",
"griff_adder_normalmap.png"
);
next, we need to send these textures to the fragment shader as an 'uniform' - we're going to call them UColorMap and uNormalMap, the bit to be careful of here is that you set the value numbers to the order they are listed earlier as 'Textures' - start numbering them at # 0
Code: Select all
uniforms =
{
uColorMap = { type = texture; value = 0; };
uNormalMap = { type = texture; value = 1; };
};
right, lets have a look at the fragment shader, in the first few lines we need to declare our uniforms, sampler2D is used when decalaring a 2d image, it's a Vec4 and the 4 components can be thought of as the RGBA channel values in a .png
Code: Select all
uniform sampler2D uColorMap;
uniform sampler2D uNormalMap;
I'm going to stop mentioning the normal map from here on in as it's just confusing me, i'll just concentrate on what happens to re-colour the uColorMap, first we'll use data from the vertex shader ("VTexCoord") to look up the particular uColourMap pixel we need for this polygon fragment and store it in a Vec4 called 'baseTex'
Code: Select all
vec4 baseTex = texture2D(uColorMap, vTexCoord);
next, we'll use a greyscale image stored in the alpha channel of the normal map as a 'mask' to control the re-colouring (where the pixels in this mask image are dark there will be little re-colouring, where the pixels are light there will be the most re-colouring, we'll store the mask data in a floating point variable called 'PaintMap'
Code: Select all
float PaintMap = texture2D(uNormalMap, vTexCoord).a;
now we just multiply the mask by our paint colour -in this example a vec4(1.0, 0.5, 0.0, 1.0) which gives us a nice orange (the 4 numbers correspond to RGBA):
and add it into the baseTex
Code: Select all
baseTex += PaintMap * vec4(1.0, 0.5, 0.0, 1.0);
and that's it, our baseTex has now been tinted orange, let's send it on to the video buffer
and that's it! The fragment shader has now processed this particular polygon fragment and starts again on the next polygon fragment until they're all done, then it all starts again for the next frame