Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Understanding visual effects

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: another_commander, winston

User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Progress

Post 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 [EliteWiki] 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.
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2478
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Re: Shaders’ Outpost

Post 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
Image
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:

Code: Select all

color = (0.9926, 0.9686, 0.7325);
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
Image

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
Last edited by Griff on Mon Feb 13, 2012 11:24 pm, edited 2 times in total.
User avatar
DaddyHoggy
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 8501
Joined: Tue Dec 05, 2006 9:43 pm
Location: Newbury, UK
Contact:

Re: Progress

Post by DaddyHoggy »

Very nice Griff - simply explained.
Selezen wrote:
Apparently I was having a DaddyHoggy moment.
Oolite Life is now revealed here
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2478
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Re: Understanding visual effects

Post 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
User avatar
DaddyHoggy
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 8501
Joined: Tue Dec 05, 2006 9:43 pm
Location: Newbury, UK
Contact:

Re: Understanding visual effects

Post 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!)
Selezen wrote:
Apparently I was having a DaddyHoggy moment.
Oolite Life is now revealed here
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Understanding visual effects

Post by Smivs »

Sounds great, Griff. Thanks.
Commander Smivs, the friendliest Gourd this side of Riedquat.
Storm
Dangerous
Dangerous
Posts: 91
Joined: Mon Jan 30, 2012 10:27 pm
Location: UK

Re: Understanding visual effects

Post 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.
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2478
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Re: Understanding visual effects

Post 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:
Image
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:
Image
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
Image

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
Image
here's the same example but with a scale factor of 3.0
Image
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:
Image
here's an example of a specular exponent of 80.0:
Image
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
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Understanding visual effects

Post 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.
User avatar
DaddyHoggy
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 8501
Joined: Tue Dec 05, 2006 9:43 pm
Location: Newbury, UK
Contact:

Re: Understanding visual effects

Post by DaddyHoggy »

Nicely explained Ahruman (much better than my physics teachers ever managed when I was doing my physics degree)
Selezen wrote:
Apparently I was having a DaddyHoggy moment.
Oolite Life is now revealed here
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Understanding visual effects

Post 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. :-)
Post Reply