Shaders’ Outpost

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

Moderators: another_commander, winston

Post Reply
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Shaders’ Outpost

Post by Arexack_Heretic »

Thread meant for compiling experiences, tuts, good advice and FAQ about the revolutionary concept of texture shaders.
(as available from version 1.68 upwards.)

8)


-insert links to relevant wiki and other handy resources-
https://bb.oolite.space/viewtopic.php?t= ... highlight=
https://bb.oolite.space/viewtopic.php?t=3368&start=15
https://bb.oolite.space/viewtopic.php?t=3407&start=105
Explaining texture-sampling and working the coordinates
Griff Ruining the Classics thread

Example_OXPs:
Griff Rocket Example 1 Custom specularity, laser_heat/exhaust_heat glow, constant glow
Griff Rocket Example 2 Custom specularity, laser_heat/exhaust_heat glow/engine_level glow
Griff Pod Example 3 Specularity Settings driven by a Texture Map, Laser_Heat Glow, Exhaust_Heat Glow, Constantly lit glow map for hull lights etc
Griff lighted hangar Bright illumination and red-alert versions
Thargoids: they had it 1st. The classic Aegidian example of a timer driven sine-function additive texture shader.
Shady PythonClass Cruiser Another classic example ship-oxp by Aegidian.
Hot 2Cool alloys Another timer-driven shader this time single direction and started on spawn_time, coloursamples applied instead of a texture.
Shady Billboard An illuminated billboard.
Ahruman's 'Electric' Billboard Advanced billboard that mimics led-array billboards.
Fixed texture for 'Electric' Billboard
Griff sign concept1 Uses discard-clipping.
Ahruman Animation concept Examplifies how animation can be accomplished by shader, also Uses colour-discard-clipping.
Cobra_OXP Example by Ahruman.
Krait OXP full Great example OXP by Griff.
Griff Krait OXP lowspec
Griff Boa optimized Another beauty. showoff ;) -no, go on we loves them.
Griff's optimized krait[/url]
Last edited by Arexack_Heretic on Thu Oct 25, 2007 8:43 pm, edited 12 times in total.
Riding the Rocket!
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2475
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Post by Griff »

Shader Example, featuring:-
. Customisable Specularity Settings
. Laser Heat Glow
. Exhaust Heat Glow
. Constantly lit glow map for hull lights etc

Image

Link to OXP:-
http://www.box.net/shared/ogotygiqui (550KB)


Customisable Specularity Settings
Edit the fragment shader to produce various specularity effects:-
Image

search for the following lines in the griff_rocket.fragment file, you can safely open them in any text editor:-

Code: Select all

      specular += gl_LightSource[idx].diffuse * pow(max(dot(reflection, eyeVector), 0.0), 5.0); \
   }
// The 5.0 at the end of the line above is the Specular Exponent setting, higher values = more glossy (highlight is smaller)

Code: Select all

   vec4 color = diffuse * colorMap + specular * 0.6; // the 0.6 in this line is the SpecularIntensity, higher values = stronger highlight
Next, i'll upload a variation of the fragment shader that links the hull lights to the engine_level so they brighten or dim depending on how fast the ship is flying
Last edited by Griff on Sat Jun 02, 2007 4:23 pm, edited 2 times in total.
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2475
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Post by Griff »

Shader Example 2, featuring:-
. Customisable Specularity Settings
. Laser Heat Glow
. Exhaust Heat Glow
. Glow map for hull lights etc, brightness linked to engine_level variable

Here's a new version of the above oxp that links the hull lights glow map to the engine level of the ship. I've modified the glowmap texture to have a lot more lurid coloured lights on it and given the ship a fuel injector so it can really work up some speed and get them lights blazing away!
Image

Download here:-
http://www.box.net/shared/h95rd0n25x

the only 2 differences between this version of the fragment shader and the previous one are as follows:-

first, this addition of this line
uniform float engine_level;
which adds a variable called engine_level which links the shader to information from the Oolite engine

and this line:-
color += glowMapEngine_level * Pulse(engine_level, 1.0);
which used to read :-
color += glowMapEngine_level * Pulse(2.0, 1.0);
which kept the light glow level constant at 2.0
Last edited by Griff on Sat Jun 02, 2007 4:23 pm, edited 1 time in total.
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2475
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Post by Griff »

Shader Example 3, featuring:-
. Specularity Settings driven by a Texture Map
. Laser Heat Glow
. Exhaust Heat Glow
. Constantly lit glow map for hull lights etc

It's possible to drive shader Specular Exponent & Specular Intensity values using a texturemap, which is great if you want to vary specularity across your ships surface, eg - give the cockpit window an intense, narrow highlight for a 'glassy' look whilst the engines and hull get a weak wide specular highlight for dull metal look
This isn't a very good example, but notice the orange area on this object (it's supposed to be leaking fuel!) is more shiny that the metal around it and the grill areas don't have a highlight to give the impression that they are openings into the object
Image

This shader requires an aditional texturemap, the Red Channel of which drives the Specular Exponent and the Green Channel drives the Specular Intensity, the Blue Channel is not used.
Image

Download Here:=
http://www.box.net/shared/m3lnqejld9
User avatar
TGHC
---- E L I T E ----
---- E L I T E ----
Posts: 2157
Joined: Mon Jan 31, 2005 4:16 pm
Location: Berkshire, UK

Post by TGHC »

Haven't got a clue what this all means, but visually it looks like once again you've produced some superb designs, well done matey.
The Grey Haired Commander has spoken!
OK so I'm a PC user - "you know whats scary? Out of billions of sperm I was the fastest"
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

Then red is providing the brightness and green the shineyness?
Riding the Rocket!
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Arexack_Heretic wrote:
Then red is providing the brightness and green the shineyness?
Exactly the opposite. :-)
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

ah yeah.
:oops:

I may try this on the Dubious_Profit. :)
Riding the Rocket!
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2475
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Post by Griff »

It's not a very good example i provided i'm afraid, the glossyness on the 'fuel leak' isn't high enough, the specular highlight should be a little dot and not a great big wide streak. It's easy to modify the fragment shader to add a multiplier to the intensity of the red channel to get the correct glossy effect, but you'd have to make sure it doesn't break the highlight across the rest of the object. Another solution would be to use the currently unused blue channel to drive a highly multiplied specular effect just for the more extremely glossy areas.

Edit: I've added another version of this shader that now allows you to use the previously unused blue channel in the specular map texture to add highly glossy areas to your object, notice the fuel leak now looks a lot more 'wet' as it's specular exponent has a much higher value than before.
Image
download here:-
http://www.box.net/shared/mprc65klvi

The only change to the fragment shader is this line

Code: Select all

float specExponent = specMap.r + 2.0 + specMap.b * 200;
which used to read

Code: Select all

float specExponent = specMap.r + 2.0;
you can see it just adds in the blue channel (multiplied by 200) of the specMap texture to the specular effect.
Last edited by Griff on Sun Jun 03, 2007 5:08 pm, edited 3 times in total.
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2475
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Post by Griff »

Illumination Shader for Docking Bays
Image

the zip contains two oxp's for docking bay illumination, one of which has a pulsing red ambient light effect to give a "red alert!" feeling, might be fun to use on a mission where you're sent to defend a station or carrier that is under attack?
I've meddled with ahrumans shader code quite a bit on this one so i hope i haven't broken it too much, it seems to work on my windows xp system.
Download here:-

http://www.box.net/shared/uuju6d5fji
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

I would rather have darkened dockingbays
(As I find the sunlight that shines through the station to illuminate the dock unreal)
with a few bright floodlights or red lights, etc, according to the atmosphere of the situation.

I may look at that pack as well and take some of your work.
(I just scripted a station with a devastated dock)
I already switched the green flashers to yellow and yellow ones to red. But a dark hole with some red lighting would be cool.
Riding the Rocket!
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2475
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Post by Griff »

Hi A_H
you can edit the level of lighting inside the docking bay by changing the brightness of the blue channel in the ambientmap texture

excuse the roughness of this image, it's a screen grab straight out of rendermonkey:-
Image

i've just reduced the brightness of the blue channel all the way down to black to remove the ambient lighting, the red channel is providing the glows on the redlights at the back of the bay as well as the pools of light on the floor.

applying this shader to the bay removes the effect of the sunlight on the bay so you don't get that sometime odd effect of light passing through the hull to light the walls/floor etc :)
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Griff wrote:
The only change to the fragment shader is this line

Code: Select all

float specExponent = specMap.r + 2.0 + specMap.b * 200;
which used to read

Code: Select all

float specExponent = specMap.r + 2.0;
you can see it just adds in the blue channel (multiplied by 200) of the specMap texture to the specular effect.
Yeah; the difference between 2 and 3 isn’t all that great, so the red channel won’t be doing much.

The exponent is effectively an exponential scale of shininess; the difference between 32 and 64 is comparable to the difference between 4 and 8. If you multiply by a large factor, you get a lot of detail at the high end, but only unsubtle stops at the low end. The mathematically precise way to compensate this is to use something like pow(2.0, specMap.b * 8.0) (for a range of 0 to 2**8 = 256), but a computationally simpler way is to use a quadratic curve, 256.0 * specMap.b * specMap.b.

Incidentally, the reason I add 1 to the exponent in the Krait shaders is that 0 is a useless value; it just makes half the object glow.
User avatar
Uncle Reno
---- E L I T E ----
---- E L I T E ----
Posts: 648
Joined: Mon Apr 24, 2006 12:54 pm
Location: UK

Post by Uncle Reno »

Griff wrote:
Edit: I've added another version of this shader that now allows you to use the previously unused blue channel in the specular map texture to add highly glossy areas to your object, notice the fuel leak now looks a lot more 'wet' as it's specular exponent has a much higher value than before.
Possibly it's just my system but that looks as if the metal has been eaten away and the highlight is some internal structure, having said that it does look good! :)
"Get back or I unleash my lethal spotted batoid!!"

What I do when not reading the Oolite bulletin board!
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

Excellent!
I'll use it for sure in b0.2

Reno is right.
The glossyness does not look good on that concave surface. Looks like a hole.
It would look just like liquid if on a 'flatter' surface though.
Riding the Rocket!
Post Reply