Skip to content

Commit 2cba774

Browse files
committed
Reworks the lighting settings according to the discussion in scp-fs2open#1634.
This fixes scp-fs2open#1634
1 parent 66c9baf commit 2cba774

8 files changed

Lines changed: 26 additions & 25 deletions

File tree

code/def_files/data/effects/deferred-f.sdr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@ void main()
131131
vec3 halfVec = normalize(lightDir + eyeDir);
132132
float NdotL = clamp(dot(normal.xyz, lightDir), 0.0, 1.0);
133133
vec4 fragmentColor = vec4(color * (diffuseLightColor * NdotL * attenuation), 1.0);
134-
fragmentColor.rgb += SpecularGGX(specColor.rgb, lightDir, normal.xyz, halfVec, eyeDir, gloss, fresnel, NdotL).rgb * specLightColor * attenuation;
134+
fragmentColor.rgb += computeLighting(specColor.rgb, lightDir, normal.xyz, halfVec, eyeDir, gloss, fresnel, NdotL).rgb * specLightColor * attenuation;
135135
fragOut0 = max(fragmentColor, vec4(0.0));
136136
}

code/def_files/data/effects/lighting.sdr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,12 @@ vec3 SpecularGGX(vec3 specColor, vec3 light, vec3 normal, vec3 halfVec, vec3 vie
4747

4848
return distribution * fresnel * visibility * dotNL;
4949
}
50+
51+
vec3 computeLighting(vec3 specColor, vec3 light, vec3 normal, vec3 halfVec, vec3 view, float gloss, float fresnelFactor, float dotNL)
52+
{
53+
#ifdef FLAG_LIGHT_MODEL_BLINN_PHONG
54+
return SpecularBlinnPhong(specColor, light, normal, halfVec, 1.0, fresnelFactor, dotNL);
55+
#else
56+
return SpecularGGX(specColor, light, normal, halfVec, view, gloss, fresnelFactor, dotNL);
57+
#endif
58+
}

code/def_files/data/effects/main-f.sdr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ vec3 CalculateLighting(vec3 normal, vec3 diffuseMaterial, vec3 specularMaterial,
209209
float NdotL = clamp(dot(normal, lightDir), 0.0f, 1.0f);
210210
// Ambient, Diffuse, and Specular
211211
lightDiffuse += (lights[i].diffuse_color.rgb * diffuseFactor * NdotL * attenuation) * shadow;
212-
lightSpecular += lights[i].spec_color * SpecularGGX(specularMaterial, lightDir, normal, halfVec, eyeDir, gloss, fresnel, NdotL) * attenuation * shadow;
212+
lightSpecular += lights[i].spec_color * computeLighting(specularMaterial, lightDir, normal, halfVec, eyeDir, gloss, fresnel, NdotL) * attenuation * shadow;
213213
}
214214
return diffuseMaterial * (lightAmbient + lightDiffuse) + lightSpecular;
215215
}

code/graphics/opengl/gropenglshader.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ static SCP_string opengl_shader_get_header(shader_type type_id, int flags, shade
336336
sflags << "#define WORKAROUND_CLIPPING_PLANES\n";
337337
}
338338

339+
if (Detail.lighting < 3) {
340+
sflags << "#define FLAG_LIGHT_MODEL_BLINN_PHONG\n";
341+
}
342+
339343
if (type_id == SDR_TYPE_POST_PROCESS_MAIN || type_id == SDR_TYPE_POST_PROCESS_LIGHTSHAFTS || type_id == SDR_TYPE_POST_PROCESS_FXAA) {
340344
// ignore looking for variants. main post process, lightshafts, and FXAA shaders need special headers to be hacked in
341345
opengl_post_shader_header(sflags, type_id, flags);

code/lighting/lighting.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -353,15 +353,6 @@ void light_apply_rgb( ubyte *param_r, ubyte *param_g, ubyte *param_b, const vec3
353353
int idx;
354354
float rval, gval, bval;
355355

356-
if (Detail.lighting==0) {
357-
// No static light
358-
ubyte lVal = ubyte(fl2i(static_light_level*255.0f));
359-
*param_r = lVal;
360-
*param_g = lVal;
361-
*param_b = lVal;
362-
return;
363-
}
364-
365356
if ( Lighting_off ) {
366357
*param_r = 255;
367358
*param_g = 255;

code/model/modelrender.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ void model_render_buffers(model_draw_list* scene, model_material *rendering_mate
11111111
texture_maps[TM_SPEC_GLOSS_TYPE] = model_interp_get_texture(&tmap->textures[TM_SPEC_GLOSS_TYPE], base_frametime);
11121112
}
11131113

1114-
if ((Detail.lighting > 2) && (detail_level < 2)) {
1114+
if (detail_level < 2) {
11151115
// likewise, etc.
11161116
texture_info *norm_map = &tmap->textures[TM_NORMAL_TYPE];
11171117
texture_info *height_map = &tmap->textures[TM_HEIGHT_TYPE];
@@ -1143,10 +1143,10 @@ void model_render_buffers(model_draw_list* scene, model_material *rendering_mate
11431143
if (debug_flags & MR_DEBUG_NO_DIFFUSE) texture_maps[TM_BASE_TYPE] = -1;
11441144
if (debug_flags & MR_DEBUG_NO_GLOW) texture_maps[TM_GLOW_TYPE] = -1;
11451145
if (debug_flags & MR_DEBUG_NO_SPEC) texture_maps[TM_SPECULAR_TYPE] = -1;
1146-
if (!(debug_flags & MR_DEBUG_NO_NORMAL)) texture_maps[TM_NORMAL_TYPE] = model_interp_get_texture(norm_map, base_frametime);
1147-
if (!(debug_flags & MR_DEBUG_NO_HEIGHT)) texture_maps[TM_HEIGHT_TYPE] = model_interp_get_texture(height_map, base_frametime);
1148-
if (!(debug_flags & MR_DEBUG_NO_AMBIENT)) texture_maps[TM_AMBIENT_TYPE] = model_interp_get_texture(ambient_map, base_frametime);
11491146
if (!(debug_flags & MR_DEBUG_NO_MISC)) texture_maps[TM_MISC_TYPE] = model_interp_get_texture(misc_map, base_frametime);
1147+
if (!(debug_flags & MR_DEBUG_NO_NORMAL) && Detail.lighting > 0) texture_maps[TM_NORMAL_TYPE] = model_interp_get_texture(norm_map, base_frametime);
1148+
if (!(debug_flags & MR_DEBUG_NO_AMBIENT) && Detail.lighting > 0) texture_maps[TM_AMBIENT_TYPE] = model_interp_get_texture(ambient_map, base_frametime);
1149+
if (!(debug_flags & MR_DEBUG_NO_HEIGHT) && Detail.lighting > 1) texture_maps[TM_HEIGHT_TYPE] = model_interp_get_texture(height_map, base_frametime);
11501150
}
11511151
} else {
11521152
alpha = forced_alpha;
@@ -1810,7 +1810,7 @@ void model_render_glowpoint(int point_num, vec3d *pos, matrix *orient, glow_poin
18101810
}
18111811
}
18121812

1813-
if ( Deferred_lighting && gpo && gpo->is_lightsource ) {
1813+
if ( Detail.lighting > 3 && Deferred_lighting && gpo && gpo->is_lightsource ) {
18141814
if ( gpo->lightcone ) {
18151815
vec3d cone_dir_rot;
18161816
vec3d cone_dir_model;

code/object/object.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ void obj_move_all_post(object *objp, float frametime)
11831183
weapon_process_post( objp, frametime );
11841184

11851185
// Cast light
1186-
if ( Detail.lighting > 2 ) {
1186+
if ( Detail.lighting > 3 ) {
11871187
// Weapons cast light
11881188

11891189
int group_id = Weapons[objp->instance].group_id;
@@ -1233,7 +1233,7 @@ void obj_move_all_post(object *objp, float frametime)
12331233

12341234
// Make any electrical arcs on ships cast light
12351235
if (Arc_light) {
1236-
if ( (Detail.lighting > 2) && (objp != Viewer_obj) ) {
1236+
if ( (Detail.lighting > 3) && (objp != Viewer_obj) ) {
12371237
int i;
12381238
ship *shipp;
12391239
shipp = &Ships[objp->instance];
@@ -1276,7 +1276,7 @@ void obj_move_all_post(object *objp, float frametime)
12761276
if ( !physics_paused )
12771277
fireball_process_post(objp,frametime);
12781278

1279-
if (Detail.lighting > 3) {
1279+
if (Detail.lighting > 2) {
12801280
float r = 0.0f, g = 0.0f, b = 0.0f;
12811281

12821282
fireball_get_color(Fireballs[objp->instance].fireball_info_index, &r, &g, &b);
@@ -1323,7 +1323,7 @@ void obj_move_all_post(object *objp, float frametime)
13231323

13241324
// Make any electrical arcs on debris cast light
13251325
if (Arc_light) {
1326-
if ( Detail.lighting > 2 ) {
1326+
if ( Detail.lighting > 3 ) {
13271327
int i;
13281328
debris *db;
13291329
db = &Debris[objp->instance];

code/weapon/beam.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ int Beam_good_shot_octants[BEAM_NUM_GOOD_OCTANTS][4] = {
8686
{ 4, 0, 1, 0 },
8787
};
8888

89-
// beam lighting effects
90-
int Beam_lighting = 1;
91-
9289
// debug stuff - keep track of how many collision tests we perform a second and how many we toss a second
9390
#define BEAM_TEST_STAMP_TIME 4000 // every 4 seconds
9491
int Beam_test_stamp = -1;
@@ -1607,7 +1604,7 @@ void beam_add_light_small(beam *bm, object *objp, vec3d *pt_override = NULL)
16071604
float noise;
16081605

16091606
// no lighting
1610-
if(!Beam_lighting){
1607+
if(Detail.lighting < 1){
16111608
return;
16121609
}
16131610

@@ -1677,7 +1674,7 @@ void beam_add_light_large(beam *bm, object *objp, vec3d *pt0, vec3d *pt1)
16771674
float noise;
16781675

16791676
// no lighting
1680-
if(!Beam_lighting){
1677+
if(Detail.lighting < 2){
16811678
return;
16821679
}
16831680

0 commit comments

Comments
 (0)