Ok here it is people. Take it, try it out, report anything suspicious.
Index: code/weapon/beam.cpp
===================================================================
--- code/weapon/beam.cpp (Revision 7338)
+++ code/weapon/beam.cpp (Arbeitskopie)
@@ -986,6 +986,9 @@
// mprintf(("killing beam becase it isn't ok to be fireing\n"));
beam_delete(moveup);
} else {
+ // add a muzzle light for the shooter
+ beam_add_light(moveup, OBJ_INDEX(moveup->objp), 0, NULL);
+
// if the warming up timestamp has expired, start firing
if(timestamp_elapsed(moveup->warmup_stamp)){
// start firing
@@ -993,9 +996,6 @@
// mprintf(("killing beam becase it shouldn't have started fireing yet\n"));
beam_delete(moveup);
}
-
- // add a muzzle light for the shooter
- beam_add_light(moveup, OBJ_INDEX(moveup->objp), 0, NULL);
}
}
@@ -1013,6 +1013,8 @@
// mprintf(("killing beam becase it isn't ok to fire\n"));
beam_delete(moveup);
} else {
+ // add a muzzle light for the shooter
+ beam_add_light(moveup, OBJ_INDEX(moveup->objp), 0, NULL);
// if we're done warming down, the beam is finished
if(timestamp_elapsed(moveup->warmdown_stamp)){
// mprintf(("euthaniseing beam\n"));
@@ -1544,7 +1546,10 @@
bwi = &wip->b_info;
// some noise
- noise = frand_range(1.0f - bwi->sections[0].flicker, 1.0f + bwi->sections[0].flicker);
+ if( bm->warmup_stamp<0&&bm->warmdown_stamp<0 ) // disable noise when warming up or down
+ noise = frand_range(1.0f - bwi->sections[0].flicker, 1.0f + bwi->sections[0].flicker);
+ else
+ noise = 1.0f;
// widest part of the beam
float light_rad = beam_get_widest(bm) * blight * noise;
@@ -1566,11 +1571,27 @@
float fg = (float)wip->laser_color_1.green / 255.0f;
float fb = (float)wip->laser_color_1.blue / 255.0f;
+ float pct = 0.0f;
+
+ if (bm->warmup_stamp != -1) { //calculate muzzle light intensity
+ // get warmup pct
+ pct = BEAM_WARMUP_PCT(bm);
+ } else
+ // if the beam is warming down
+ if (bm->warmdown_stamp != -1) {
+ // get warmup pct
+ pct = MAX(1.0f - BEAM_WARMDOWN_PCT(bm)*1.3f,0.0f);
+ }
+ // otherwise the beam is really firing
+ else {
+ pct = 1.0f;
+ }
// add a unique light
// noise *= 0.1f; // a little less noise here, since we want the beam to generally cast a bright light
- light_add_point_unique(&near_pt, light_rad * 0.0001f, light_rad, 1.0f, fr, fg, fb, OBJ_INDEX(objp));
+ light_add_point_unique(&near_pt, light_rad * 0.0001f, light_rad, pct, fr, fg, fb, OBJ_INDEX(objp));
}
+extern int Use_GLSL;
// call to add a light source to a large object
void beam_add_light_large(beam *bm, object *objp, vec3d *pt0, vec3d *pt1)
{
@@ -1609,7 +1630,25 @@
// add a unique light
noise *= 0.1f; // a little less noise here, since we want the beam to generally cast a bright light
- light_add_tube(pt0, pt1, 1.0f, light_rad, 1.0f * noise, fr, fg, fb, OBJ_INDEX(objp));
+
+ vec3d near_pt, a, b;
+ float dist;
+
+ vm_vec_sub(&a, pt1, pt0);
+ vm_vec_normalize_quick(&a);
+ vm_vec_dist_to_line(&objp->pos, pt0, pt1, &near_pt, &dist); // Calculate nearest point for fallback fake tube pointlight
+ vm_vec_scale_add(&b, &near_pt, &a, bwi->beam_muzzle_radius * (-3.0f)); // Valathil: Move the light away from the ship somewhat
+
+ if(dist> light_rad + objp->radius ){
+ return; // Too far away
+ }
+
+ if( Use_GLSL > 1)
+ light_add_tube(pt0, pt1, 1.0f, light_rad, 1.0f * noise, fr, fg, fb, OBJ_INDEX(objp));
+ else
+ light_add_tube(pt0, &b, 1.0f, light_rad, 1.0f * noise, fr, fg, fb, OBJ_INDEX(objp));
+
+
}
// mark an object as being lit
@@ -1675,35 +1714,15 @@
// from the beam passing by
case 1:
- // object type
- switch(Objects[l->objnum].type){
- case OBJ_SHIP:
- Assert(Objects[l->objnum].instance >= 0);
-
- // large ships
- if(Ship_info[Ships[Objects[l->objnum].instance].ship_info_index].flags & (SIF_BIG_SHIP | SIF_HUGE_SHIP)){
- beam_add_light_large(l->bm, &Objects[l->objnum], &l->bm->last_start, &l->bm->last_shot);
- }
- // small ships
- else {
- beam_add_light_small(l->bm, &Objects[l->objnum]);
- }
- break;
-
- // asteroids get small lights
- case OBJ_ASTEROID:
- beam_add_light_small(l->bm, &Objects[l->objnum]);
- break;
-
- // debris gets small lights
- case OBJ_DEBRIS:
- beam_add_light_small(l->bm, &Objects[l->objnum]);
- break;
- }
+ Assert(Objects[l->objnum].instance >= 0);
+ beam_add_light_large(l->bm, &Objects[l->objnum], &l->bm->last_start, &l->bm->last_shot); //Valathil: Everyone gets tube lights now WOHOO
break;
// from a collision
case 2:
+ // Valathil: Dont render impact lights for shaders, handled by tube lighting
+ if( Use_GLSL > 1)
+ break;
// a few meters from the collision point
vm_vec_sub(&dir, &l->bm->last_start, &l->c_point);
vm_vec_normalize_quick(&dir);
Index: code/graphics/gropengllight.cpp
===================================================================
--- code/graphics/gropengllight.cpp (Revision 7338)
+++ code/graphics/gropengllight.cpp (Arbeitskopie)
@@ -91,7 +91,7 @@
switch (FSLight->type) {
case LT_POINT: {
// this crap still needs work...
- GLLight->ConstantAtten = 0.0f;
+ GLLight->ConstantAtten = 1.0f;
GLLight->LinearAtten = (1.0f / MAX(FSLight->rada, FSLight->radb)) * 1.25f;
GLLight->Specular[0] *= static_point_factor;
@@ -102,15 +102,36 @@
}
case LT_TUBE: {
+
+ GLLight->ConstantAtten = 1.0f;
+ GLLight->LinearAtten = (1.0f / MAX(FSLight->rada, FSLight->radb)) * 1.25f;
+ GLLight->QuadraticAtten = (1.0f / MAX(FSLight->rada_squared, FSLight->radb_squared)) * 1.25f;
+
GLLight->Specular[0] *= static_tube_factor;
GLLight->Specular[1] *= static_tube_factor;
GLLight->Specular[2] *= static_tube_factor;
- GLLight->SpotDir[0] = FSLight->vec2.xyz.x * 1.5f;
- GLLight->SpotDir[1] = FSLight->vec2.xyz.y * 1.5f;
- GLLight->SpotDir[2] = FSLight->vec2.xyz.z * 1.5f;
- GLLight->SpotCutOff = 90.0f;
+ GLLight->Position[0] = FSLight->vec2.xyz.x; // Valathil: Use endpoint of tube as light position
+ GLLight->Position[1] = FSLight->vec2.xyz.y;
+ GLLight->Position[2] = FSLight->vec2.xyz.z;
+ GLLight->Position[3] = 1.0f;
+ if( Use_GLSL > 1) {
+
+ // Valathil: When using shaders pass the beam direction (not normalized IMPORTANT for calculation of tube)
+ vec3d a;
+ vm_vec_sub(&a, &FSLight->vec2, &FSLight->vec);
+ GLLight->SpotDir[0] = a.xyz.x;
+ GLLight->SpotDir[1] = a.xyz.y;
+ GLLight->SpotDir[2] = a.xyz.z;
+ GLLight->SpotCutOff = 90.0f; // Valathil: So shader dectects tube light
+ }
+ else {
+ GLLight->SpotDir[0] = 1.0f; // Valathil: When not using shaders pass a fake spotdir
+ GLLight->SpotDir[1] = 0.0f;
+ GLLight->SpotDir[2] = 0.0f;
+ GLLight->SpotCutOff = 180.0f; //Valathil: Should be a point light not a spot; using tube only for the light sorting
+ }
break;
}
main-f.sdr
#ifdef FLAG_LIGHT
uniform int n_lights;
#endif
#ifdef FLAG_DIFFUSE_MAP
uniform sampler2D sBasemap;
#endif
#ifdef FLAG_GLOW_MAP
uniform sampler2D sGlowmap;
#endif
#ifdef FLAG_SPEC_MAP
uniform sampler2D sSpecmap;
#endif
#ifdef FLAG_ENV_MAP
uniform samplerCube sEnvmap;
uniform bool alpha_spec;
varying vec3 envReflect;
#endif
#ifdef FLAG_NORMAL_MAP
uniform sampler2D sNormalmap;
varying mat3 tbnMatrix;
#endif
#ifdef FLAG_FOG
varying float fogDist;
#endif
varying vec4 position;
varying vec3 lNormal;
#if SHADER_MODEL == 2
#define MAX_LIGHTS 2
#else
#define MAX_LIGHTS 8
#endif
#define SPEC_INTENSITY_POINT 5.3 // Point light
#define SPEC_INTENSITY_DIRECTIONAL 3.0 // Directional light
#define SPECULAR_FACTOR 1.75
#define SPECULAR_ALPHA 0.1
#define SPEC_FACTOR_NO_SPEC_MAP 0.6
#define ENV_ALPHA_FACTOR 0.3
#define GLOW_MAP_INTENSITY 1.5
#define AMBIENT_LIGHT_BOOST 1.0
void main()
{
vec3 eyeDir = vec3(normalize(-position).xyz); // Camera is at (0,0,0) in ModelView space
vec4 lightAmbientDiffuse = vec4(0.0, 0.0, 0.0, 1.0);
vec4 lightDiffuse = vec4(0.0, 0.0, 0.0, 1.0);
vec4 lightAmbient = vec4(0.0, 0.0, 0.0, 1.0);
vec4 lightSpecular = vec4(0.0, 0.0, 0.0, 1.0);
vec2 texCoord = gl_TexCoord[0].xy;
#ifdef FLAG_LIGHT
#ifdef FLAG_NORMAL_MAP
// Normal map - convert from DXT5nm
vec3 normal;
normal.rg = (texture2D(sNormalmap, texCoord).ag * 2.0) - 1.0;
#ifdef FLAG_ENV_MAP
vec3 envOffset = vec3(0.0);
envOffset.xy = normal.xy;
#endif
normal.b = sqrt(1.0 - dot(normal.rg, normal.rg));
normal = tbnMatrix * normal;
float norm = length(normal);
if( length(normal) > 0.0) // fix broken normal maps
normal /= norm ;
else
normal = tbnMatrix * vec3(0.0, 0.0, 1.0);
#else
vec3 normal = lNormal;
#endif
vec3 lightDir;
lightAmbient = gl_FrontMaterial.emission + (gl_LightModel.ambient * gl_FrontMaterial.ambient);
float dist;
#pragma optionNV unroll all
for (int i = 0; i < MAX_LIGHTS; ++i) {
#if SHADER_MODEL > 2
if (i > n_lights)
break;
#endif
float specularIntensity = 1.0;
float diffuseIntensity = 1.0;
float attenuation = 1.0;
float tubeEffect = 0.0;
float NdotHV = 0.0;
vec3 beamDir = vec3(0.0);
// Attenuation and light direction
#if SHADER_MODEL > 2
if (gl_LightSource[i].position.w == 1.0) {
#else
if (gl_LightSource[i].position.w == 1.0 && i != 0) {
#endif
// Positional light source
dist = distance(gl_LightSource[i].position.xyz, position.xyz);
lightDir = (gl_LightSource[i].position.xyz - position.xyz);
specularIntensity = SPEC_INTENSITY_POINT;
#if SHADER_MODEL > 2
if (gl_LightSource[i].spotCutoff < 91.0) { // Tube light
vec3 nearest = gl_LightSource[i].position.xyz;
float beamlength = length(gl_LightSource[i].spotDirection);
beamDir = normalize(gl_LightSource[i].spotDirection);
float neardist = dot(position.xyz - gl_LightSource[i].position.xyz , beamDir); // Get nearest point on line
if(neardist < 0.0)
{
nearest = gl_LightSource[i].position.xyz + beamDir * (neardist); // Move back from the endpoint of the beam along the beam by the distance we calculated
lightDir = nearest - position.xyz;
dist = length(lightDir);
}
specularIntensity *= 10.0; // Stupid FS scales back the Tube lights for NO REASON
diffuseIntensity *= 5.0;
}
#endif
attenuation = 1.0 / (gl_LightSource[i].constantAttenuation + (gl_LightSource[i].linearAttenuation * dist) + (gl_LightSource[i].quadraticAttenuation * dist * dist));
} else {
// Directional light source
lightDir = normalize(gl_LightSource[i].position.xyz);
specularIntensity = SPEC_INTENSITY_DIRECTIONAL; // Directional light
}
// Ambient and Diffuse
lightAmbient += (gl_FrontLightProduct[i].ambient * attenuation);
lightDiffuse += (gl_FrontLightProduct[i].diffuse * (max(dot(normal, normalize(lightDir)), 0.0)) * attenuation) * diffuseIntensity;
lightDiffuse += (gl_FrontLightProduct[i].diffuse * (max(dot(normal, -beamDir), 0.0)) * attenuation) * diffuseIntensity; // 2nd diffuse pass to compensate for tube light direction
// Specular
NdotHV = clamp(dot(normal, normalize(eyeDir + normalize(lightDir))), 0.0, 1.0);
lightSpecular += ((gl_FrontLightProduct[i].specular * pow(NdotHV, gl_FrontMaterial.shininess)) * attenuation) * specularIntensity;
}
lightAmbientDiffuse = lightAmbient + lightDiffuse;
#else
lightAmbientDiffuse = gl_Color;
lightSpecular = gl_SecondaryColor;
#endif
#ifdef FLAG_DIFFUSE_MAP
// Base color
vec4 baseColor = texture2D(sBasemap, texCoord);
#else
vec4 baseColor = gl_Color;
#endif
vec4 fragmentColor;
fragmentColor.rgb = baseColor.rgb * max(lightAmbientDiffuse.rgb * AMBIENT_LIGHT_BOOST, gl_LightModel.ambient.rgb - 0.425);
fragmentColor.a = baseColor.a;
#ifdef FLAG_SPEC_MAP
// Spec color
fragmentColor.rgb += lightSpecular.rgb * (texture2D(sSpecmap, texCoord).rgb * SPECULAR_FACTOR);
fragmentColor.a += (dot(lightSpecular.a, lightSpecular.a) * SPECULAR_ALPHA);
#else
fragmentColor.rgb += lightSpecular.rgb * (baseColor.rgb * SPEC_FACTOR_NO_SPEC_MAP);
#endif
#ifdef FLAG_ENV_MAP
// Env color
#ifdef FLAG_NORMAL_MAP
vec3 envReflectNM = envReflect + envOffset;
vec3 envIntensity = (alpha_spec) ? vec3(texture2D(sSpecmap, texCoord).a) : texture2D(sSpecmap, texCoord).rgb;
fragmentColor.a += (dot(textureCube(sEnvmap, envReflectNM).rgb, textureCube(sEnvmap, envReflectNM).rgb) * ENV_ALPHA_FACTOR);
fragmentColor.rgb += textureCube(sEnvmap, envReflectNM).rgb * envIntensity;
#else
vec3 envIntensity = (alpha_spec) ? vec3(texture2D(sSpecmap, texCoord).a) : texture2D(sSpecmap, texCoord).rgb;
fragmentColor.a += (dot(textureCube(sEnvmap, envReflect).rgb, textureCube(sEnvmap, envReflect).rgb) * ENV_ALPHA_FACTOR);
fragmentColor.rgb += textureCube(sEnvmap, envReflect).rgb * envIntensity;
#endif
#endif
#ifdef FLAG_GLOW_MAP
// Glow color
fragmentColor.rgb += texture2D(sGlowmap, texCoord).rgb * GLOW_MAP_INTENSITY;
#endif
#ifdef FLAG_FOG
fragmentColor.rgb = mix(fragmentColor.rgb, gl_Fog.color.rgb, fogDist);
#endif
gl_FragColor = fragmentColor;
#ifdef FLAG_LIGHT
//gl_FragColor.rgb = vec3(dist/15000.0);
#endif
}