Page 12 of 32
Posted: Thu May 08, 2008 7:39 pm
by Griff
Ahruman, is the uniform binding throwingSparks working OK?
i'm getting this error when trying to bind it to a shader:
Code: Select all
oolite.exe[2252] [shader.uniform.bind.failed]: Could not bind uniform "nearly_dead" to -[ShipEntity ?] (no uniform of that name could be found).
in shipdata.plist i've got:
Code: Select all
uniforms = {
time = "universalTime";
engine_power = "speedFactor";
laser_heat_level = "laserHeatLevel";
nearly_dead = "throwingSparks";
hull_heat_level = "hullHeatLevel";
};
in the fragment shader i've got:
and what i'm doing with it is:
Code: Select all
if (nearly_dead = true)
{
color += cyanGlow(effectsMap.r * Pulse(min(engine_power, 1.0), 1.0)) * Blink_on_off(Pulse(1.0, 1.0));
color += effectsMap.a * diffuseMap * Blink_on_off(Pulse(1.0, 0.6));
}
else
{
color += cyanGlow(effectsMap.r * Pulse(min(engine_power, 1.0), 1.0));
color += effectsMap.a * diffuseMap * 3.0;
}
that bit of code flickers the exhaust glow effects off and off a bit like how the exhaust plume flickers.
what i'm seeing in oolite is the flickering effect as if the nearly_dead bool is true, even though the ship is not in the throwingSparks state, what's odd is if i edit the shader and change if (nearly_dead = true) to if (nearly_dead = false) i don't see the flickering effect, so it's as if the if else stuff is being acted on.
Edit: fixed by Cmdr James, i had the shader code wrong
Also, does hullHeatLevel always have a slightly positive value even when ships are just milling around aimlessly in space?
i've added in the hull heat glow effect from the shady cobra to the griff_krait shader and now all the kraits are glowing slightly red, as if hullHeatLevel starts off at some value such as 0.1 - this is for non-player craft, i haven't tested it with a player ship
Posted: Thu May 08, 2008 7:49 pm
by Cmdr James
Im not t all a javascript expert, but that isnt the way Id test the nearly_dead boolean in any other language.
I think it should be
and
I think your
is setting the value of nearlydead, rather than testing it.[/quote]
Posted: Thu May 08, 2008 8:00 pm
by Griff
thanks Cmdr James! that fixed it, i changed the shader code to
Code: Select all
if (nearly_dead)
{
color += cyanGlow(effectsMap.r * Pulse(min(engine_power, 1.0), 1.0)) * Blink_on_off(Pulse(1.0, 1.0));
color += effectsMap.a * diffuseMap * Blink_on_off(Pulse(1.0, 0.6));
}
if (!nearly_dead)
{
color += cyanGlow(effectsMap.r * Pulse(min(engine_power, 1.0), 1.0));
color += effectsMap.a * diffuseMap * 3.0;
}
and it's working great!
Posted: Thu May 08, 2008 8:13 pm
by Frame
for reference in code terms
== test´s Equality
= sets varible to be the value that follows...
Not being an Java coder, but i bet this also works like this in java script, like it does in C++
Posted: Thu May 08, 2008 8:19 pm
by Cmdr James
And of course, if its a boolean to start with, its a bit odd to test if its equal to true, as the test returns a boolean.
And, if you want to be pedantic, java is the same as C/C++/objective-C in the equality testing sense, but we are talking about javascript, which is no more like java than vb :p
Posted: Fri May 09, 2008 9:43 am
by Eric Walch
Griff wrote:Also, does hullHeatLevel always have a slightly positive value even when ships are just milling around aimlessly in space?
i've added in the hull heat glow effect from the shady cobra to the griff_krait shader and now all the kraits are glowing slightly red, as if hullHeatLevel starts off at some value such as 0.1 - this is for non-player craft, i haven't tested it with a player ship
At least until 1.70 there was just one ship temperature and that never dropped below a certain value of 60. A meaningless number. But in relative temperature with 1.0 as value were heat damage starts, this minimum value is 0.23 i don't know if 1.71 now also has a hull temperature different from cabin temperature.
Posted: Fri May 09, 2008 11:12 am
by Griff
ah, that explains it, thanks eric! with a hullheat level of 0.23 the ship has already started to begin glowing, i think a few tweaks to the shader should sort this.
edit i suppose just subtracting 0.23 away from the hullheatlevel in the shader code should do the trick, the max command should clamp it to 0.0 if the value falls below that
below is an image of the hull heat at 0.0, 0.23, 0.50, 0.75, 1.0
seems to be working ok, haven't tried it in oolite yet, i've tied the hull heat effect into the specularity map just to break up the effect a bit, it doesn't look that great but i don't want to have to add another texture map just to control this effect
Posted: Fri May 09, 2008 2:15 pm
by JensAyton
Griff wrote:Does Oolite support Cubemaps? (textureCube)
No.
launch, there's something odd going on with the environment map though, it streaks a lot along some of the polygons, maybe something to do with the topology of the model?
That’s pretty much the expected result for flat surfaces. It works better on doughnuts. :-)
Posted: Fri May 09, 2008 2:18 pm
by JensAyton
Cmdr James wrote:And of course, if its a boolean to start with, its a bit odd to test if its equal to true, as the test returns a boolean.
And, if you want to be pedantic, java is the same as C/C++/objective-C in the equality testing sense, but we are talking about javascript, which is no more like java than vb :p
But we should be talking about GLSL, which also uses C syntax for tests and assignments. :-)
As for the heat glow thing, I’d strongly recommend using the same heat glow function as the default shader, so all ships behave the same:
Code: Select all
// uHullHeatLevel bound to hullHeatLevel
// uTime bound to timeElapsedSinceSpawn
#ifndef OO_REDUCED_COMPLEXITY
// Irregular flickering function.
float Pulse(float value, float timeScale)
{
float t = uTime * timeScale;
float s0 = t;
s0 -= floor(s0);
float sum = abs( s0 - 0.5);
float s1 = t * 0.7 - 0.05;
s1 -= floor(s1);
sum += abs(s1 - 0.5) - 0.25;
float s2 = t * 1.3 - 0.3;
s2 -= floor(s2);
sum += abs(s2 - 0.5) - 0.25;
float s3 = t * 5.09 - 0.6;
s3 -= floor(s3);
sum += abs(s3 - 0.5) - 0.25;
return (sum * 0.1 + 0.9) * value;
}
// Colour ramp from black through reddish brown/dark orange to yellow-white.
vec4 TemperatureGlow(float level)
{
vec4 result = vec4(0);
result.r = level;
result.g = level * level * level;
result.b = max(level - 0.7, 0.0) * 2.0;
result.a = 1.0;
return result;
}
#endif
// ...
#ifndef OO_REDUCED_COMPLEXITY
// Heat glow
float hullHeat = max(uHullHeatLevel - 0.5, 0.0) * 2.0;
hullHeat = Pulse(hullHeat * hullHeat, 0.1);
totalColor += TemperatureGlow(hullHeat);
#endif
Posted: Fri May 09, 2008 7:36 pm
by Griff
well, everything works better with doughnuts, even a trumble infestation (if you can get to them before they do)
Posted: Fri May 09, 2008 8:21 pm
by Cmdr. Maegil
YAH! YAH!
Posted: Sun May 11, 2008 4:41 pm
by Griff
good point about the hull heat effect Ahruman, i've put your example code into the shader.
I've been playing about with the 'environment shader effect' a few posts above and worked it into a sort of 'Active Camouflage' effect that kicks in when a ship cloaks, basically the ships texturemap colour & specular effects are muted by multiplying them by 0, and a starfield texture is mapped onto the model instead, the starfild texture co-ords are being calculated using the vertex fragment position in eye space and LightSource[1].position.xyz, this gives the effect of the model moving 'through' it's texture rather than the texture being a static painting on the ships hull
now you see me......................................now you dont (well except for the engine glow & hull lights)
it's downloadable here
http://www.box.net/shared/bmgecao84c
edit: hmm, thinking about it, a shader binding to 'hasHostileTarget' would probably work better than a shader binding to 'isCloaked'.
here's a version that does that:
http://www.box.net/shared/pvc6p2dwsg fire a few shots into them to get them to switch to their camouflage mode
Posted: Mon May 12, 2008 8:29 am
by Griff
guys, i've got a programming question and i was wondering if some of you code wizzards could turn your mighty intellects towards the problem briefly, you don't have to go into detail just an overview of a good programming method would be cool, basically i'm trying to get a bit fancy with a shader effect, what i want to do is fade a texture in whilst fading another texture out depending on whether a bool is true or not.
this is what it've got so far, please feel free to point and laugh
Code: Select all
/* check if the ship is cloaked, if so:
1. fade out the colour & lighting thus making the ship a non-specular-reflecting black colour and
2. fade in the environment map as a replacement texture
The float 't' counts down and the float 'tt' counts up, the fract command throws away the integer and keeps only the
numbers after the decimal point somewhere in the range of .9999 to .0000 */
if (is_cloaked)
{
float t = fract(-time * 0.5);
float tt = fract(time * 0.5);
vec4 c = color * t;
color = vec4(c);
color += envMap * tt * diffuseMap.a;
}
if (!is_cloaked)
{
float t = fract(time * 0.5);
float tt = fract(-time * 0.5);
vec4 c = color * t;
color = vec4(c);
color += envMap * tt * diffuseMap.a;
}
I've got a terrible sinking feeling that i'm barking up the wrong tree with this method, the time variable obviously keeps marching onwards so the fade effects are completing, then resetting to maximum, then counting up/down again, then resetting to maximum, then counting up/down again etc. what do you recommend for fixing the values of t and tt when they get near to either .0000 or .9999?
would you do some sort of 'do while' loop?
do
{
block of code;
}
while (test condition);
edit: do while loops not supported on older cards
Posted: Mon May 12, 2008 12:59 pm
by Cmdr James
I dont quite understand the problem, but I can offer some randomish thoughts.
You can almost always replace a
with a simple
. If you have to, you can do something like
Code: Select all
while (firstRun || condition) {
doStuff();//do your fading and stuff
firstRun = false;
}
If you are unable to use a while, you can probably use a
, I would imagine that any programming language without some kind of looping of this kind would be more or less impossible (year, right, try using Transact-SQL and being forced to use GOTO :lable
)
if I understand right, then you can at least remove some duplication in your code
Code: Select all
float t = fract(-time * 0.5);
if (is_cloaked) {
t = -t;
}
vec4 c = color * t;
color = vec4(c);
color += envMap * -t * diffuseMap.a;
I think instead of using time, and taking the fractional part, you should maybe use
and then stopping once elapsed is greater or equal to some value (1.00, I guess)
Its possible that I have completely missed the point though, and Im not too sure what most of the variables you are using actually are, so take it with a pinch of salt
Posted: Mon May 12, 2008 1:56 pm
by Griff
Thanks for taking the time to pick through my crappy code Cmdr James!
Please don't tax yourself too much with it though, i'm posting questions about stuff i don't understand, and the shader does pretty much what i want it to now - this fading in and out stuff is just extra frills.
When the bool isCloaked = true
i think i need a little counter routine that counts up from 0.00 to 1.00 over a period of about say, 4 seconds, and when the counter gets to 1.00 it stays at that value until bool isCloaked = false, upon which it counts back down from 1.00 to 0.00
i want to use the counter value to control a % mixture of two texture maps when a ship switches in or out of a cloaked state
[ship becomes cloaked]
start_time=0.0 (to reset the clock)
time_elapsed = start_time + time
mix texture_map_2 to texture_map_1 using time_elapsed as a mix percentage
when time_elapsed =1.0 fix it at this value until ship becomes uncloaked, then count back down from 1.00 to 0.00 using the decreasing values as a texture mix % so the ship returns to it's normal texture map