1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
#include "post_processing.h"
#include "graphics/grinternal.h"
#include "options/Option.h"
#include "parse/parselo.h"
#include "ship/ship.h"
#include "starfield/supernova.h"
namespace graphics {
namespace {
PostEffectUniformType mapUniformNameToType(const SCP_string& uniform_name)
{
if (!stricmp(uniform_name.c_str(), "noise_amount")) {
return PostEffectUniformType::NoiseAmount;
} else if (!stricmp(uniform_name.c_str(), "saturation")) {
return PostEffectUniformType::Saturation;
} else if (!stricmp(uniform_name.c_str(), "brightness")) {
return PostEffectUniformType::Brightness;
} else if (!stricmp(uniform_name.c_str(), "contrast")) {
return PostEffectUniformType::Contrast;
} else if (!stricmp(uniform_name.c_str(), "film_grain")) {
return PostEffectUniformType::FilmGrain;
} else if (!stricmp(uniform_name.c_str(), "tv_stripes")) {
return PostEffectUniformType::TvStripes;
} else if (!stricmp(uniform_name.c_str(), "cutoff")) {
return PostEffectUniformType::Cutoff;
} else if (!stricmp(uniform_name.c_str(), "dither")) {
return PostEffectUniformType::Dither;
} else if (!stricmp(uniform_name.c_str(), "tint")) {
return PostEffectUniformType::Tint;
} else if (!stricmp(uniform_name.c_str(), "custom_effect_vec3_a")) {
return PostEffectUniformType::CustomEffectVEC3A;
} else if (!stricmp(uniform_name.c_str(), "custom_effect_float_a")) {
return PostEffectUniformType::CustomEffectFloatA;
} else if (!stricmp(uniform_name.c_str(), "custom_effect_vec3_b")) {
return PostEffectUniformType::CustomEffectVEC3B;
} else if (!stricmp(uniform_name.c_str(), "custom_effect_float_b")) {
return PostEffectUniformType::CustomEffectFloatB;
} else {
error_display(0, "Unknown uniform name '%s'!", uniform_name.c_str());
return PostEffectUniformType::Invalid;
}
}
// used by In-Game Options menu
bool Post_processing_enable_lightshafts = true;
void parse_lightshafts_func()
{
bool enabled;
stuff_boolean(&enabled);
Post_processing_enable_lightshafts = enabled;
}
// used by In-Game Options menu
bool Post_processing_enable_sunglare = true;
void parse_sunglare_func()
{
bool enabled;
stuff_boolean(&enabled);
Post_processing_enable_sunglare = enabled;
}
auto LightshaftsOption = options::OptionBuilder<bool>("Graphics.Lightshafts",
std::pair<const char*, int>{"Lightshafts", 1724},
std::pair<const char*, int>{"Enables or disables lightshafts (requires post-processing)", 1725})
.category(std::make_pair("Graphics", 1825))
.default_func([]() { return Post_processing_enable_lightshafts;})
.level(options::ExpertLevel::Advanced)
.bind_to(&Post_processing_enable_lightshafts)
.importance(60)
.parser(parse_lightshafts_func)
.finish();
auto SunglareOption = options::OptionBuilder<bool>("Graphics.Sunglare",
std::pair<const char*, int>{"Sunglare", 1880},
std::pair<const char*, int>{"Enables or disables glare from suns", 1881})
.category(std::make_pair("Graphics", 1825))
.default_func([]() { return Post_processing_enable_sunglare;})
.level(options::ExpertLevel::Advanced)
.bind_to(&Post_processing_enable_sunglare)
.importance(61)
.parser(parse_sunglare_func)
.finish();
int Post_processing_bloom_intensity = 25; // using default value of Cmdline_bloom_intensity
void parse_bloom_intensity_func()
{
int value;
stuff_int(&value);
CLAMP(value, 0, 200);
Post_processing_bloom_intensity = value;
}
static auto BloomIntensityOption __UNUSED = options::OptionBuilder<int>("Graphics.BloomIntensity",
std::pair<const char*, int>{"Bloom intensity", 1701},
std::pair<const char*, int>{"Sets the bloom intensity (requires post-processing)", 1702})
.category(std::make_pair("Graphics", 1825))
.range(0, 200)
.level(options::ExpertLevel::Advanced)
.default_func([](){return Post_processing_bloom_intensity;})
.bind_to(&Post_processing_bloom_intensity)
.importance(55)
.flags({options::OptionFlags::RangeTypeInteger})
.parser(parse_bloom_intensity_func)
.finish();
} // namespace
bool PostProcessingManager::parse_table()
{
bool warned = false;
try {
if (cf_exists_full("post_processing.tbl", CF_TYPE_TABLES))
read_file_text("post_processing.tbl", CF_TYPE_TABLES);
else
read_file_text_from_default(defaults_get_file("post_processing.tbl"));
reset_parse();
if (optional_string("#Effects")) {
while (!required_string_one_of(3, "$Name:", "#Ship Effects", "#End")) {
post_effect_t eff;
required_string("$Name:");
stuff_string(eff.name, F_NAME);
required_string("$Uniform:");
SCP_string tbuf;
stuff_string(tbuf, F_NAME);
eff.uniform_type = mapUniformNameToType(tbuf);
required_string("$Define:");
stuff_string(eff.define_name, F_NAME);
required_string("$AlwaysOn:");
stuff_boolean(&eff.always_on);
required_string("$Default:");
stuff_float(&eff.default_intensity);
eff.intensity = eff.default_intensity;
required_string("$Div:");
stuff_float(&eff.div);
required_string("$Add:");
stuff_float(&eff.add);
if (optional_string("$RGB:")) {
stuff_vec3d(&eff.rgb);
}
// Post_effects index is used for flag checks, so we can't have more than 32
if (m_postEffects.size() < 32) {
m_postEffects.push_back(eff);
} else if (!warned) {
mprintf(("WARNING: post_processing.tbl can only have a max of 32 effects! Ignoring extra...\n"));
warned = true;
}
}
}
// Built-in per-ship effects
ship_effect se1;
strcpy_s(se1.name, "FS1 Ship select");
se1.shader_effect = 0;
se1.disables_rendering = false;
se1.invert_timer = false;
Ship_effects.push_back(se1);
if (optional_string("#Ship Effects")) {
while (!required_string_one_of(3, "$Name:", "#Light Shafts", "#End")) {
ship_effect se;
char tbuf[NAME_LENGTH] = {0};
required_string("$Name:");
stuff_string(tbuf, F_NAME, NAME_LENGTH);
strcpy_s(se.name, tbuf);
required_string("$Shader Effect:");
stuff_int(&se.shader_effect);
required_string("$Disables Rendering:");
stuff_boolean(&se.disables_rendering);
required_string("$Invert timer:");
stuff_boolean(&se.invert_timer);
Ship_effects.push_back(se);
}
}
if (optional_string("#Light Shafts")) {
required_string("$AlwaysOn:");
stuff_boolean(&m_lightshaftParams.on);
required_string("$Density:");
stuff_float(&m_lightshaftParams.density);
required_string("$Falloff:");
stuff_float(&m_lightshaftParams.falloff);
required_string("$Weight:");
stuff_float(&m_lightshaftParams.weight);
required_string("$Intensity:");
stuff_float(&m_lightshaftParams.intensity);
required_string("$Sample Number:");
stuff_int(&m_lightshaftParams.samplenum);
m_lightshaftParams.cpintensity = m_lightshaftParams.weight;
float falloff = m_lightshaftParams.falloff;
for (int i = 1; i < m_lightshaftParams.samplenum; ++i)
{
m_lightshaftParams.cpintensity += m_lightshaftParams.weight * falloff;
falloff *= m_lightshaftParams.falloff; // this replaces pow(falloff, i)
}
m_lightshaftParams.cpintensity *= m_lightshaftParams.intensity;
}
required_string("#End");
return true;
} catch (const parse::ParseException& e) {
mprintf(("Unable to parse 'post_processing.tbl'! Error message = %s.\n", e.what()));
return false;
}
}
void PostProcessingManager::clear()
{
m_postEffects.clear();
m_lightshaftParams = lightshaft_parameters();
}
const SCP_vector<graphics::post_effect_t>& PostProcessingManager::getPostEffects() const { return m_postEffects; }
SCP_vector<graphics::post_effect_t>& PostProcessingManager::getPostEffects() { return m_postEffects; }
const lightshaft_parameters& PostProcessingManager::getLightshaftParams() const { return m_lightshaftParams; }
lightshaft_parameters& PostProcessingManager::getLightshaftParams() { return m_lightshaftParams; }
bool PostProcessingManager::bloomShadersOk() const
{
return m_bloomShadersOk;
}
void PostProcessingManager::setBloomShadersOk(bool ok)
{
m_bloomShadersOk = ok;
}
} // namespace graphics
bool gr_lightshafts_enabled()
{
if (gr_screen.mode == GR_STUB) {
return false;
}
// supernova glare should switch to legacy lightshafts
if (supernova_stage() >= SUPERNOVA_STAGE::CLOSE) {
return false;
}
if (!graphics::Post_processing_manager->getLightshaftParams().on) {
return false;
}
return graphics::LightshaftsOption->getValue();
}
bool gr_sunglare_enabled()
{
if (gr_screen.mode == GR_STUB) {
return false;
}
// supernova glare gets to override this and actually display glare
if (supernova_stage() >= SUPERNOVA_STAGE::CLOSE) {
return true;
}
return graphics::SunglareOption->getValue();
}
int gr_bloom_intensity()
{
if (gr_screen.mode == GR_STUB) {
return 0;
}
if (graphics::Post_processing_manager == nullptr || !graphics::Post_processing_manager->bloomShadersOk()) {
return 0;
}
return graphics::BloomIntensityOption->getValue();
}
void gr_set_bloom_intensity(int intensity)
{
if (gr_screen.mode == GR_STUB) {
return;
}
graphics::Post_processing_bloom_intensity = intensity;
options::OptionsManager::instance()->set_ingame_range_option("Graphics.BloomIntensity", intensity);
}
|