A request for a simple example of using shaders

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

Moderators: another_commander, winston

User avatar
Shipbuilder
---- E L I T E ----
---- E L I T E ----
Posts: 877
Joined: Thu May 10, 2012 9:41 pm
Location: Derby

Re: A request for a simple example of using shaders

Post by Shipbuilder »

Thanks for that Griff.

I have had a go at incorporating this however the damage texture still didn't work and also the normal map details disappear when in direct sunlight :?

I'm going to get the Fireball OXP issued tomorrow and then I intend to concentrate on getting to grips with shaders.

I'm going to start the Elite style ship hopefully Wednesday and produce the how to apply shaders guide as I progress.
The GalTech Industries Corporation - Building ships to populate the galaxies.

Increase the variety of ships within your Ooniverse by downloading my OXPs

Flying the [wiki]Serpent_Class_Cruiser[/wiki] "Thargoid's Bane"
User avatar
Griff
Oolite 2 Art Director
Oolite 2 Art Director
Posts: 2476
Joined: Fri Jul 14, 2006 12:29 pm
Location: Probably hugging his Air Fryer

Re: A request for a simple example of using shaders

Post by Griff »

re: damage texture not working - is this on a player ship? if i remember correctly you have to calculate energy levels differently for a player ship, the uniforms that send the relevant energy levels data from oolite to the shader are in a different format for players than they are for NPC ships, i remember being stuck on this for a while then someone (possibly Frame or Svengali) posed up a few lines of code to get it working, i'll have a dig through my shipset shaders to find the particular lines you need.
edit:
ok, i think this is the code you need for the damage glow texture on a player ship,
in your players ship in shipdata.plist, in the shaders\uniforms section write:

Code: Select all

	damage_amount = "damage";	
in your players ship fragment shader, have

Code: Select all

   uniform int    damage_amount;
then further down in the 'void main(void)' section of your shader have this code

Code: Select all

// Damage Calculator
float tempvar = float(damage_amount); 
float DamageAmount = mod(tempvar, 100.0) / 100.0;
so now we've got a new floating point number called DamageAmount (note: case sensitive) that we can use as an opacity setting for mixing in your damage texture

Code: Select all

 finalColor += IlluminationMap2 * DamageAmount;
If you want the texture drawn at full opacity when the ship is full of energy and gradually have it fade out as the ship energy level falls then subtract DamageAmount from 1.0 and use that result as the opacity level

Code: Select all

  finalColor += IlluminationMap2 * (1.0 - DamageAmount);
at least i think that'll work i haven't tested it! - you could do that to your Lights texture map so they fade as the ship gets more and more beaten up and the energy banks start draining :D
User avatar
Shipbuilder
---- E L I T E ----
---- E L I T E ----
Posts: 877
Joined: Thu May 10, 2012 9:41 pm
Location: Derby

Re: A request for a simple example of using shaders

Post by Shipbuilder »

Griff - Thanks for the info regarding the damaged texture for player ships I'll give it a go this week and let you know how I get on.
The GalTech Industries Corporation - Building ships to populate the galaxies.

Increase the variety of ships within your Ooniverse by downloading my OXPs

Flying the [wiki]Serpent_Class_Cruiser[/wiki] "Thargoid's Bane"
User avatar
Shipbuilder
---- E L I T E ----
---- E L I T E ----
Posts: 877
Joined: Thu May 10, 2012 9:41 pm
Location: Derby

Re: A request for a simple example of using shaders

Post by Shipbuilder »

I am getting close to being in a position where I should be able to release the first version of my How to use shaders guide that I have been putting together. I'm currently reading through the first draft to try to spot any errors :?

I also plan to release a number of resource packs to accompany the guide.

Does anyone know if this should be released with a licence or should I simply provide a download link/Wiki page ?
The GalTech Industries Corporation - Building ships to populate the galaxies.

Increase the variety of ships within your Ooniverse by downloading my OXPs

Flying the [wiki]Serpent_Class_Cruiser[/wiki] "Thargoid's Bane"
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: A request for a simple example of using shaders

Post by cim »

Shipbuilder wrote:
Does anyone know if this should be released with a licence or should I simply provide a download link/Wiki page ?
If you're intending that people be able to play around with the code samples and perhaps incorporate bits into their own work, then it's much clearer to have a license. There are basically two options for this:
1) Pick a license that you personally approve of to encourage more OXPs to be released under that license (picking anything other than CC-BY-NC-SA 3.0 at this point is likely to mean very few people use your code, of course, since that's probably the most common OXP license)
2) Pick a very permissive license like the MIT license (if you want to be formal) or a "do what you want with this" statement (if you want to be informal) so that people can use it in any project they like.
User avatar
Diziet Sma
---- E L I T E ----
---- E L I T E ----
Posts: 6311
Joined: Mon Apr 06, 2009 12:20 pm
Location: Aboard the Pitviper S.E. "Blackwidow"

Re: A request for a simple example of using shaders

Post by Diziet Sma »

Shipbuilder wrote:
I am getting close to being in a position where I should be able to release the first version of my How to use shaders guide that I have been putting together. I'm currently reading through the first draft to try to spot any errors :?

I also plan to release a number of resource packs to accompany the guide.

Does anyone know if this should be released with a licence or should I simply provide a download link/Wiki page ?
Further to the above, I'd like to see the guide itself made available as a wiki reference page, a PDF and a forum thread.. :mrgreen:
Most games have some sort of paddling-pool-and-water-wings beginning to ease you in: Oolite takes the rather more Darwinian approach of heaving you straight into the ocean, often with a brick or two in your pockets for luck. ~ Disembodied
User avatar
Shipbuilder
---- E L I T E ----
---- E L I T E ----
Posts: 877
Joined: Thu May 10, 2012 9:41 pm
Location: Derby

Re: A request for a simple example of using shaders

Post by Shipbuilder »

Diziet Sma wrote:
Shipbuilder wrote:
I am getting close to being in a position where I should be able to release the first version of my How to use shaders guide that I have been putting together. I'm currently reading through the first draft to try to spot any errors :?

I also plan to release a number of resource packs to accompany the guide.

Does anyone know if this should be released with a licence or should I simply provide a download link/Wiki page ?
Further to the above, I'd like to see the guide itself made available as a wiki reference page, a PDF and a forum thread.. :mrgreen:
This is exactly what I have planned. :wink:
The GalTech Industries Corporation - Building ships to populate the galaxies.

Increase the variety of ships within your Ooniverse by downloading my OXPs

Flying the [wiki]Serpent_Class_Cruiser[/wiki] "Thargoid's Bane"
Post Reply