Page 2 of 2
Re: Progress
Posted: Mon Feb 13, 2012 5:52 pm
by JensAyton
Smivs wrote:Something like the code posted above for the adder but annotated/commented to describe the function of each element.
This is exactly what I was referring to when I asked for specific questions above, because that
is annotated to describe the function of each element and there is no way for me to know what more you need based on such a vague request. (I find it hard to believe that it’s unclear why a light map would have a name and a colour, and the other uncommented attributes are
extensively documented.) I could write a ten thousand word essay and still not answer your questions, because I don’t know what they are since you
haven’t asked any.
Re: Shaders’ Outpost
Posted: Mon Feb 13, 2012 9:16 pm
by Griff
I didn't have the adder set up in rendermonkey so this example uses the griff coriolis (but the adder would work in exactly the same way)
Here's a typical glowmap, as it only needs to show where the lights are placed on the ship and how bright they will be, we can use a single channel image, this particular one will be put in the alpha channel of the normal map - white pixels in this image will be added onto the ship as glowing lights, black pixels will have no effect
here's the code that the shader synthesiser needs in order to set up the alpha channel of the coriolis-normalmap.png as a glow map
( //'s are used to write comments in the shader synthesiser code - these lines are ignored by the computer when the code is run)
Code: Select all
// Light map 1: lamp/window glow map.
name = "coriolis-normalmap.png";
extract_channel = "a";
Since the glow map above doesn't have any colour information in it, we can tell Oolite what colour the glows will be with the following shader synthesiser code:
the 3 sets of numbers in that line are the red, green and blue values for the glow colour, here's a gif showing different colour settings and how they effect the glow map
This bit of shader synthersiser code turns the glowmap a very strong red whenever it's AI switches to attack mode
(simulates the ship switching to a red-alert mode, look at the colour values (1.5, -0.4, -0.4), that's a lot of red being mixed in and the negative values for green and red are removing those colours if they are present in the base texture map to further strengthen the final red colour
Code: Select all
// Turn red (and subtract base green and blue) in combat. Ignored in simple shader mode.
conditional_color =
{
binding = "hasHostileTarget";
color = (1.5, -0.4, -0.4);
};
you can of course set this 'red-alert' colour to whatever you want, even (0.0, 0.0, 0.0) if you want to switch the lights off when the ship is attacking
Re: Progress
Posted: Mon Feb 13, 2012 10:57 pm
by DaddyHoggy
Very nice Griff - simply explained.
Re: Understanding visual effects
Posted: Mon Feb 13, 2012 11:30 pm
by Griff
I'll try and get some examples together over the next few days to explain some of the specular settings such as self_color and scale_factor, plus what the specular_exponent does and how you can use these to suggest 'wet' or 'plasticy' surfaces or dull metallic ones and maybe some sort of 'workflow' tutorials on how to line up your glow maps with your base texture and saving them into the alpha channels in the .png
Re: Understanding visual effects
Posted: Mon Feb 13, 2012 11:36 pm
by DaddyHoggy
Griff wrote:I'll try and get some examples together over the next few days to explain some of the specular settings such as self_color and scale_factor, plus what the specular_exponent does and how you can use these to suggest 'wet' or 'plasticy' surfaces or dull metallic ones and maybe some sort of 'workflow' tutorials on how to line up your glow maps with your base texture and saving them into the alpha channels in the .png
Now that would be would be very much appreciated! I may yet do a glowy, normal mapped ship! (I have several ship designs on my PC at the moment but not for public consumption as they look terrible!)
Re: Understanding visual effects
Posted: Mon Feb 13, 2012 11:40 pm
by Smivs
Sounds great, Griff. Thanks.
Re: Understanding visual effects
Posted: Tue Feb 14, 2012 8:06 pm
by Storm
I think I just about understand the use of lighting channels now, thanks guys!
Will make it that much easier when I start playing around with skins for my models properly.
Re: Understanding visual effects
Posted: Tue Feb 14, 2012 10:30 pm
by Griff
Let's have a look at this bit of the shader synthersiser example
Code: Select all
specular_color_map =
{
name = "oolite-adder-diffuse.png";
extract_channel = "a";
self_color = true; // Modulate specular colour with diffuse colour.
scale_factor = 6; // Multiply all channels by a constant.
};
specular_exponent = 5;
Here's a typical spec map:
this one looks like it's been quickly generated by greyscaling the diffuse texture and adjusting it with brightness & contrast tools - this particular map is a 'Specular Intensity' map, it's just letting oolite know which parts of the ship are going to appear shiny when light falls on them (the lighter pixels in the map) and which are going to be dull (the darker pixels in the map).
Putting some noise and grime in your spec intensity map can really break up the specular highlight 'spot' in game and make the surface feel a lot more realistic. Like the glow map in the earlier post, all this map's information can fit in a single channel
self_color
You can have the shader synthesiser colour your specular highlight with your ships texture map.
here's an example of self_color set to true:
hmm, rather drab looking, the darkness of the diffuse texture is really subduing our specular highlight, we can compensate for this with the
scale_factor setting (this is like a gain control for the strength of the specular highlight), if we set this to 6.0 we get a much
stronger highlight on our ship (at the risk of over blowing out some areas of the ship (edit your spec intensity map to correct for this)
Here's an example of a self colouring specular highlight with a scale_factor of 6.0
If you prefer, you can set self_color to false and only use the systems sun to colour your highlight, this results in nice strong highlights
(so be careful with the scale_factor setting, don't set it too high), here's an example of self colour set to false and a scale factor of 1.5
here's the same example but with a scale factor of 3.0
notice much stronger the specularity effect is compared to the self_color = true; examples
specular_exponent
This is basically the size of the highlight 'spot', set it quite low (5.0 or so) for metals, set it higher for organic and wet or plastic surfaces
here's an example of a specular exponent of 5.0:
here's an example of a specular exponent of 80.0:
the above exampes had self_colour set to false and a scale_factor of 1.0
Here's a quicktime.mov of the cobra showing self_colour = true and some mucking about with the scale factor and Exponent settings...
http://www.box.com/s/o83l272kh93ucs0rym22
...and here's something similar but with self_color = false;
http://www.box.com/s/hiqzoyzu41xcdye58fbi
Re: Understanding visual effects
Posted: Tue Feb 14, 2012 11:42 pm
by JensAyton
Specular reflection physics
You don’t need to understand optics and colour theory to work with material parameters, but it helps!!! (Feel free to put that on a mug or something.)
The specular reflection term is a cheap way of simulating shiny materials. Any real object reflects everything in its surroundings; very matte (“diffuse”) objects like ping-pong balls blur the reflections to the point where they’re unrecognisable, while very smooth materials like glass give a sharp reflection, and other materials like unpolished metal are somewhere in between.
Reflecting everything around each ship would be quite expensive. Specular highlighting is a cheap approximation which only “reflects” bright light sources – in this case, the sun. In moderately reflective surfaces, these tend to be the most obvious reflections.
A smooth material, like a glass ball, will have a tight reflection, i.e. a high exponent. An anodised aluminium ball will have a very blurry reflection, i.e. a low exponent. An ideal ping-pong ball has no specular reflection, with all reflected light being diffuse.
Objects with a tight reflection tend to also have more intense reflections. This is because, all else being equal, the same amount of reflected light is concentrated on a smaller area of the object. (Equivalently, more of the light falling on any particular point on the object will be reflected in a particular direction, and a camera that happens to intersect that ray will receive more light from that point.)
All else being equal, an object with a higher specular intensity will have lower diffuse intensity, i.e. a darker diffuse colour. This is necessarily true because the diffuse and specular terms are fed by the same supply of incoming light.
These are merely guidelines. The lighting in Oolite, with its low dynamic range, is nowhere near physically accurate. But these two factors – tighter specular means more specular intensity, and more specular intensity means darker diffuse colour – should help if you want to contrast different materials.
Specular colour
Self-colouring is an attribute of electrical conductors (metals and semiconductors). Gold reflects white light as yellow, while gold-coloured plastic reflects bright light as white. Coloured anodized aluminium, where dyes are integrated into the oxidized surface layer, exhibit a degree of self-colouring. Most non-metallic, non-transparent, shiny objects actually consist of a clear resin with pigments or dyes suspended in it. This applies to coloured plastic, coloured glass, polished wood, and most sorts of paint. The specular part of the reflection happens at the surface of the resin, while the pigment particles scatter (and hence diffuse) the light, so the specular highlight is uncoloured.
This means that the use of self-colouring in Griff’s ships is somewhat unlikely, but you can’t deny that it looks good. This type of effect, and indeed far weirder ones, can be achieved – see the wide range of finishes available for cars – so I guess it depends on how much the average spaceship captain wants to spend on pimping a ride only pirates will get a close look at.
If you want to mix self-coloured and uncoloured specular highlights, you can use a colour specular map and make the uncoloured parts greyscale. Just exclude the extract_channel
, or set it to “rgb”.
Old model
Specular maps are available in 1.76, but work slightly differently. The self_color
and scale_factor
parameters aren’t supported. Instead of specular_color_map
, it’s called specular_map
, and the alpha channel is treated as a specular exponent map, with specular_exponent
defining the maximum value. If you leave the texture completely opaque, the specular exponent will be even across the surface and it will work like in Griff’s example.
Re: Understanding visual effects
Posted: Wed Feb 15, 2012 7:02 am
by DaddyHoggy
Nicely explained Ahruman (much better than my physics teachers ever managed when I was doing my physics degree)
Re: Understanding visual effects
Posted: Wed Feb 15, 2012 7:31 am
by JensAyton
DaddyHoggy wrote:Nicely explained Ahruman (much better than my physics teachers ever managed when I was doing my physics degree)
That’s because your physics teacher had to compress all of known reality into a little digestible chunk without lying too much, while I have a much simpler model to work from. :-)