Posted: Wed Aug 12, 2009 7:03 pm
Here's the recoiling turret shader
This is a Vertex Shader.
in shipdata.plist the only uniform used is this
which binds the Oolite laserHeatLevel to the shaders "laser_heat_level".
The important lines to tweak are, Line 4:
float recoil_offset = laser_heat_level * 28.0;
the 28.0 controls how much of a recoil there is going to be, laser_heat_level is in the range 0.0-1.0 so at it's maximum it can only subtract 1 'unit' from a vertex's Z position, at Oolite ship scales this isn't very far at all so the 28.0 multiplier will mean that at it's maximum effect the barrel recoils 28 'units'.
the next important line is line 16:
if (vertex_Z_pos>50.0)
you'll need to modify the 50.0 to whatever the Z axis cutoff point for deformation is in your model. In the boa turret, the ball section stops at about Z.pos
= 49.9 and the barrel base starts at Z.pos =50.1. having this 'if.. else..' check on the vertex's Z position and then only applying the deform if the Z
position is greater than 50.0 means that only the barrel section of the turret model will recoil and not the 'ball' section, the turret basically moves back into and through the ball section.
Here's a screen shot of the ball turret object, notice the flattened side of the ball and the tiny gap between the ball and the tube, this acts as the cutoff point for the deform effect
This is a Vertex Shader.
Code: Select all
varying vec3 v_normal; // Surface normal
varying vec3 v_pos; // Vertex/fragment position in eye space
uniform float laser_heat_level;
float recoil_offset = laser_heat_level * 28.0; // tweak the 28.0
float vertex_Z_pos = gl_Vertex.z;
void main()
{
v_normal = normalize(gl_NormalMatrix * gl_Normal);
v_pos = vec3(gl_ModelViewMatrix * gl_Vertex);
// make a copy of current vertex's positon data but subtract the 'recoil_offset' from the Z component
vec4 recoil_deform_effect = vec4(gl_Vertex.x, gl_Vertex.y, gl_Vertex.z - recoil_offset, gl_Vertex.w);
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
// check the current vertex's Z position, if it's greater than 50 use the modified position from 2 lines above, else use the unmodified position data
if (vertex_Z_pos>50.0) // check the vert Z co-ords of your model in Wings and modify the 50.0 as required
gl_Position = gl_ModelViewProjectionMatrix * recoil_deform_effect;
else
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
}
Code: Select all
laser_heat_level = { binding = "laserHeatLevel"; bindToSubentity = YES; };
The important lines to tweak are, Line 4:
float recoil_offset = laser_heat_level * 28.0;
the 28.0 controls how much of a recoil there is going to be, laser_heat_level is in the range 0.0-1.0 so at it's maximum it can only subtract 1 'unit' from a vertex's Z position, at Oolite ship scales this isn't very far at all so the 28.0 multiplier will mean that at it's maximum effect the barrel recoils 28 'units'.
the next important line is line 16:
if (vertex_Z_pos>50.0)
you'll need to modify the 50.0 to whatever the Z axis cutoff point for deformation is in your model. In the boa turret, the ball section stops at about Z.pos
= 49.9 and the barrel base starts at Z.pos =50.1. having this 'if.. else..' check on the vertex's Z position and then only applying the deform if the Z
position is greater than 50.0 means that only the barrel section of the turret model will recoil and not the 'ball' section, the turret basically moves back into and through the ball section.
Here's a screen shot of the ball turret object, notice the flattened side of the ball and the tiny gap between the ball and the tube, this acts as the cutoff point for the deform effect