Skip to content

Commit a224736

Browse files
authored
Slots for custom post processing effects (#6827)
* Slots for custom post processing effects Post processing effects such as tint or dithering have their uniforms hardcoded, which means the only want to create new post-process effects for a mod is to overwrite an existing effect. Requested for DEM2, this PR creates 4 blank slots for mods to create new post processing effects--2 floats and 2 vec3. This approach to create blank slots for modders follows the successful strategy used for Custom_Controls 1-5. Note, this PR also adds `tint` to the default `post_processing.tbl` which had it missing (even though tint is a valid effect with a valid uniform buffer already). Happy to discuss more or edit however. * fix ordering
1 parent d055d03 commit a224736

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ layout (std140) uniform genericData {
1818

1919
vec3 tint;
2020
float dither;
21+
22+
// these are blank, valid slots for modders to create custom effects
23+
// that can be defined in post_processing.tbl and coded below
24+
vec3 custom_effect_vec3_a;
25+
float custom_effect_float_a;
26+
27+
vec3 custom_effect_vec3_b;
28+
float custom_effect_float_b;
2129
};
2230

2331
void main()

code/def_files/data/tables/post_processing.tbl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,14 @@ $AlwaysOn: false
6363
$Default: 0.0
6464
$Div: 50
6565
$Add: 0
66-
66+
67+
$Name: tint
68+
$Uniform: tint
69+
$Define: FLAG_TINT
70+
$AlwaysOn: false
71+
$Default: 0.0
72+
$Div: 1
73+
$Add: 0
74+
$RGB: 0.2,0.2,0.2
75+
6776
#End

code/graphics/opengl/gropenglpostprocessing.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,18 @@ void gr_opengl_post_process_end()
597597
case graphics::PostEffectUniformType::Tint:
598598
data->tint = postEffects[idx].rgb;
599599
break;
600+
case graphics::PostEffectUniformType::CustomEffectVEC3A:
601+
data->custom_effect_vec3_a = postEffects[idx].rgb;
602+
break;
603+
case graphics::PostEffectUniformType::CustomEffectFloatA:
604+
data->custom_effect_float_a = value;
605+
break;
606+
case graphics::PostEffectUniformType::CustomEffectVEC3B:
607+
data->custom_effect_vec3_b = postEffects[idx].rgb;
608+
break;
609+
case graphics::PostEffectUniformType::CustomEffectFloatB:
610+
data->custom_effect_float_b = value;
611+
break;
600612
}
601613
}
602614
}

code/graphics/post_processing.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ PostEffectUniformType mapUniformNameToType(const SCP_string& uniform_name)
3030
return PostEffectUniformType::Dither;
3131
} else if (!stricmp(uniform_name.c_str(), "tint")) {
3232
return PostEffectUniformType::Tint;
33+
} else if (!stricmp(uniform_name.c_str(), "custom_effect_vec3_a")) {
34+
return PostEffectUniformType::CustomEffectVEC3A;
35+
} else if (!stricmp(uniform_name.c_str(), "custom_effect_float_a")) {
36+
return PostEffectUniformType::CustomEffectFloatA;
37+
} else if (!stricmp(uniform_name.c_str(), "custom_effect_vec3_b")) {
38+
return PostEffectUniformType::CustomEffectVEC3B;
39+
} else if (!stricmp(uniform_name.c_str(), "custom_effect_float_b")) {
40+
return PostEffectUniformType::CustomEffectFloatB;
3341
} else {
3442
error_display(0, "Unknown uniform name '%s'!", uniform_name.c_str());
3543
return PostEffectUniformType::Invalid;

code/graphics/post_processing.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ enum class PostEffectUniformType {
1717
Cutoff,
1818
Tint,
1919
Dither,
20+
CustomEffectVEC3A,
21+
CustomEffectFloatA,
22+
CustomEffectVEC3B,
23+
CustomEffectFloatB,
2024
};
2125

2226
struct post_effect_t {

code/graphics/util/uniform_structs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ struct post_data {
398398

399399
vec3d tint;
400400
float dither;
401+
402+
vec3d custom_effect_vec3_a;
403+
float custom_effect_float_a;
404+
405+
vec3d custom_effect_vec3_b;
406+
float custom_effect_float_b;
401407
};
402408

403409
struct irrmap_data {

0 commit comments

Comments
 (0)