1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-31 18:41:20 +00:00

Merge pull request #106940 from allenwp/agx-add-white-contrast

Add `white`, `contrast`, and future HDR support to the AgX tonemapper.
This commit is contained in:
Thaddeus Crews
2025-12-03 11:42:29 -06:00
24 changed files with 546 additions and 241 deletions

View File

@@ -227,12 +227,30 @@ float Environment::get_tonemap_white() const {
return tonemap_white;
}
void Environment::set_tonemap_agx_white(float p_white) {
tonemap_agx_white = p_white;
_update_tonemap();
}
float Environment::get_tonemap_agx_white() const {
return tonemap_agx_white;
}
void Environment::set_tonemap_agx_contrast(float p_agx_contrast) {
tonemap_agx_contrast = p_agx_contrast;
RS::get_singleton()->environment_set_tonemap_agx_contrast(environment, p_agx_contrast);
}
float Environment::get_tonemap_agx_contrast() const {
return tonemap_agx_contrast;
}
void Environment::_update_tonemap() {
RS::get_singleton()->environment_set_tonemap(
environment,
RS::EnvironmentToneMapper(tone_mapper),
tonemap_exposure,
tonemap_white);
tone_mapper == TONE_MAPPER_AGX ? tonemap_agx_white : tonemap_white);
}
// SSR
@@ -1116,7 +1134,14 @@ void Environment::_validate_property(PropertyInfo &p_property) const {
}
if (p_property.name == "tonemap_white" && (tone_mapper == TONE_MAPPER_LINEAR || tone_mapper == TONE_MAPPER_AGX)) {
// Whitepoint adjustment is not available with AgX or linear as it's hardcoded there.
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
}
if (p_property.name == "tonemap_agx_white" && tone_mapper != TONE_MAPPER_AGX) {
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
}
if (p_property.name == "tonemap_agx_contrast" && tone_mapper != TONE_MAPPER_AGX) {
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
}
@@ -1252,11 +1277,17 @@ void Environment::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tonemap_exposure"), &Environment::get_tonemap_exposure);
ClassDB::bind_method(D_METHOD("set_tonemap_white", "white"), &Environment::set_tonemap_white);
ClassDB::bind_method(D_METHOD("get_tonemap_white"), &Environment::get_tonemap_white);
ClassDB::bind_method(D_METHOD("set_tonemap_agx_white", "white"), &Environment::set_tonemap_agx_white);
ClassDB::bind_method(D_METHOD("get_tonemap_agx_white"), &Environment::get_tonemap_agx_white);
ClassDB::bind_method(D_METHOD("set_tonemap_agx_contrast", "contrast"), &Environment::set_tonemap_agx_contrast);
ClassDB::bind_method(D_METHOD("get_tonemap_agx_contrast"), &Environment::get_tonemap_agx_contrast);
ADD_GROUP("Tonemap", "tonemap_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "tonemap_mode", PROPERTY_HINT_ENUM, "Linear,Reinhard,Filmic,ACES,AgX"), "set_tonemapper", "get_tonemapper");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "tonemap_exposure", PROPERTY_HINT_RANGE, "0,4,0.01,or_greater"), "set_tonemap_exposure", "get_tonemap_exposure");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "tonemap_white", PROPERTY_HINT_RANGE, "1,16,0.01,or_greater"), "set_tonemap_white", "get_tonemap_white");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "tonemap_agx_white", PROPERTY_HINT_RANGE, "2,16.5,0.01,or_greater"), "set_tonemap_agx_white", "get_tonemap_agx_white");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "tonemap_agx_contrast", PROPERTY_HINT_RANGE, "1.0,2.0,0.01,or_greater"), "set_tonemap_agx_contrast", "get_tonemap_agx_contrast");
// SSR

View File

@@ -115,6 +115,8 @@ private:
ToneMapper tone_mapper = TONE_MAPPER_LINEAR;
float tonemap_exposure = 1.0;
float tonemap_white = 1.0;
float tonemap_agx_white = 16.29; // Default to Blender's AgX white.
float tonemap_agx_contrast = 1.25; // Default to approximately Blender's AgX contrast.
void _update_tonemap();
// SSR
@@ -271,6 +273,10 @@ public:
float get_tonemap_exposure() const;
void set_tonemap_white(float p_white);
float get_tonemap_white() const;
void set_tonemap_agx_white(float p_white);
float get_tonemap_agx_white() const;
void set_tonemap_agx_contrast(float p_agx_contrast);
float get_tonemap_agx_contrast() const;
// SSR
void set_ssr_enabled(bool p_enabled);