Page 3 of 3

Re: A request for a simple example of using shaders

Posted: Mon Mar 11, 2013 11:02 pm
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.

Re: A request for a simple example of using shaders

Posted: Tue Mar 12, 2013 8:12 am
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

Re: A request for a simple example of using shaders

Posted: Mon Mar 18, 2013 10:29 pm
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.

Re: A request for a simple example of using shaders

Posted: Mon Mar 18, 2013 10:37 pm
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 ?

Re: A request for a simple example of using shaders

Posted: Mon Mar 18, 2013 10:55 pm
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.

Re: A request for a simple example of using shaders

Posted: Tue Mar 19, 2013 1:34 am
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:

Re: A request for a simple example of using shaders

Posted: Tue Mar 19, 2013 7:33 am
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: