Page 1 of 1

wiki seems to be out of date on certain topics

Posted: Fri Apr 08, 2011 7:46 pm
by Okti
Hi All,

I was trying to find a way to change the textures of an entity. There are some OXP's doing that. But when I look at wiki, I could not find any documentation such as Textures for the shipdata.plist. and also files with .fragmentation is not documented at all. Any help on that will be apreciated.

Thanks

Okti

Re: wiki seems to be out of date on certain topics

Posted: Fri Apr 08, 2011 8:13 pm
by Thargoid
This page on the wiki is useful on the subject.

One such OXP which makes use of this is my Butterflies demo OXP. That one uses this technique to change the texture colour, but you can also use it to change the whole texture diffusion map.

Fragmentation sounds like shader stuff - time for the Griff signal ;)

Re: wiki seems to be out of date on certain topics

Posted: Sat Apr 09, 2011 6:54 am
by DaddyHoggy
Image

Re: wiki seems to be out of date on certain topics

Posted: Sat Apr 09, 2011 1:47 pm
by Griff
:D @ 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):
Image
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

Code: Select all

   gl_FragColor = vec4(baseTex);
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

Re: wiki seems to be out of date on certain topics

Posted: Sat Apr 09, 2011 8:30 pm
by Okti
Thanks for all the help,