Posted: Sun Apr 22, 2007 2:55 pm
There
For information and discussion about Oolite.
https://bb.oolite.space/
Because it always shows the current ship name targeted there when you use your ID system.TGHC wrote:but why does it say Krait in the missile indicator?
It’s not gone that far… yet. The material stuff lets you set an overall glow colour for a material, for instance, irrespective of shaders, but it doesn’t allow you to specify a glow map.Griff wrote:…although ahrumans recent posting about ship materials will bring all the goodness of shaders into some extra <key>'s that you just add to a ships shipdata.plist file to switch on the effects, all the complex stuff will happen behind the scenes!
I'm notGriff wrote:anyway, i imagine everyone's pretty tired of seeing this ship by now
Code: Select all
// Information from Oolite.
uniform sampler2D tex0;
uniform sampler2D tex1;
uniform float time;
uniform float metal_temperature;
// Information from vertex shader.
varying vec3 v_normal; // Surface normal
varying vec3 v_pos; // Vertex/fragment position in eye space
// Calculates the levels of R, G & B that make up the glow effect (MetalGlow). Red channel in effects map png proportional to level of effect.
vec4 MetalGlow(float level)
{
vec4 result;
result.rgb = vec3(1.0, 0.5, 0.25) * level;
result.a = 1.0;
return result;
}
// Irregular flickering function.
float Pulse(float value, float timeScale)
{
float t = time * timeScale;
float s0 = t;
s0 -= floor(s0);
float sum = abs( s0 - 0.5);
float s1 = t * 1.7 - 0.05;
s1 -= floor(s1);
sum += abs(s1 - 0.5);
float s2 = t * 2.3 - 0.3;
s2 -= floor(s2);
sum += abs(s2 - 0.5);
float s3 = t * 5.09;
s3 -= floor(s3);
sum += abs(s3 - 0.5);
return (sum * 0.25) * value;
}
// Calculate the contribution of a single light. Ought to be a function, but OS X's GLSlang implementation isn't sufficiently clever.
#define LIGHT(idx) \
{ \
vec3 lightVector = normalize(gl_LightSource[idx].position.xyz); \
vec3 reflection = normalize(-reflect(lightVector, v_normal)); \
diffuse += gl_FrontMaterial.diffuse * gl_LightSource[idx].diffuse * max(dot(v_normal, lightVector), 0.0); \
specular += gl_LightSource[idx].diffuse * pow(max(dot(reflection, eyeVector), 0.0), specExponent); \
}
void main(void)
{
vec4 diffuse = vec4(0.0), specular = vec4(0.0);
vec3 eyeVector = normalize(-v_pos);
// Load texture data
vec2 texCoord = gl_TexCoord[0].st;
vec4 ColorMap = texture2D(tex0, texCoord);
vec4 EffectsMap = texture2D(tex1, texCoord);
float specExponent = EffectsMap.b * 200.0 + 1.0;
float specIntensity = EffectsMap.g * 1.2;
/* Light 0 is the "showroom" light, used in the demo screen and shipyard.
Light 0 is currently disabled, because there's no way for the shader to know when it's turned off.
The solution for this will probably be for Oolite to set its diffuse and specular components to
black when it's not being used.
Light 1 is the sun.
*/
#ifdef OO_LIGHT_0_FIX
LIGHT(0);
#endif
LIGHT(1);
diffuse += gl_FrontMaterial.ambient * gl_LightModel.ambient;
specular = mix(specular, specular * diffuse, 0.0);
vec4 color = diffuse * ColorMap + specular * specIntensity;
float HeatAlphaR = EffectsMap.r * 2.0;
float HeatAlphaB = EffectsMap.r * 0.05;
color += MetalGlow(metal_temperature * HeatAlphaR + HeatAlphaB);
// ...and heat effects
float Heat = max(metal_temperature - 0.5, 0.0) * 2.0;
Heat = Pulse(metal_temperature, 0.1);
float Heat2 = Pulse(metal_temperature, 0.5);
float turnuptheheat = ((Heat + metal_temperature * HeatAlphaR) * HeatAlphaB) + ((Heat2 + metal_temperature * HeatAlphaB) * HeatAlphaR);
color += MetalGlow(turnuptheheat);
gl_FragColor = vec4(color.rgb, 1.0);
}
Nice!Griff wrote:i've vandalised Ahrumans laserglow shader into a glowing metal fragment shader for use on debris left behind by exploding ships, here is it at work on the 'alloy' metal fragment:-
No. However, in 1.69 or 1.70 this will be possible by setting the initial time (as a uniform) in the “ship script” for the fragment. This’ll involve something along the lines of:Griff wrote:I'm trying to get the glow amount to decrease over time, the glow amount is being set by a variable called metal_temperature in the shader code, can this be counted down from 1 to 0 in the shader code?
Code: Select all
// Ship script (JavaScript):
this.didSpawn = function()
{
this.setShaderUniform("startTime", time);
}
// Shader (GLSL):
uniform float time;
uniform float startTime;
// ...
float elapsedTime = time - startTime;
Ooh! That looks nice!Griff wrote:i've vandalised Ahrumans laserglow shader into a glowing metal fragment shader for use on debris left behind by exploding ships, here is it at work on the 'alloy' metal fragment