summaryrefslogtreecommitdiffstats
path: root/scene/resources
diff options
context:
space:
mode:
authorThaddeus Crews <repiteo@outlook.com>2024-11-22 14:54:47 -0600
committerThaddeus Crews <repiteo@outlook.com>2024-11-22 14:54:47 -0600
commit7faad0cc7acc688d23bea48d144f60f7034a0823 (patch)
tree01c9a5cbed4a70e666a2fec3744ac75aaa80e356 /scene/resources
parent17e8cf0d87a1c7b4b3c068202be16f51a31369e6 (diff)
parent2191df0cea66f895e3c51f624052c83dcc5d3f47 (diff)
downloadredot-engine-7faad0cc7acc688d23bea48d144f60f7034a0823.tar.gz
Merge pull request #97388 from tetrapod00/visualshader-linear-srgb
VisualShader: Add LinearToSRGB and SRGBToLinear to ColorFunc node
Diffstat (limited to 'scene/resources')
-rw-r--r--scene/resources/visual_shader_nodes.cpp27
-rw-r--r--scene/resources/visual_shader_nodes.h2
2 files changed, 28 insertions, 1 deletions
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index 3db1ab9338..5350672a86 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -3243,6 +3243,29 @@ String VisualShaderNodeColorFunc::generate_code(Shader::Mode p_mode, VisualShade
code += " " + p_output_vars[0] + " = vec3(r, g, b);\n";
code += " }\n";
break;
+ case FUNC_LINEAR_TO_SRGB:
+ code += " {\n";
+ if (RenderingServer::get_singleton()->is_low_end()) {
+ code += " vec3 c = " + p_input_vars[0] + ";\n";
+ code += " " + p_output_vars[0] + " = max(vec3(1.055) * pow(c, vec3(0.416666667)) - vec3(0.055), vec3(0.0));\n";
+ } else {
+ code += " vec3 c = clamp(" + p_input_vars[0] + ", vec3(0.0), vec3(1.0));\n";
+ code += " const vec3 a = vec3(0.055f);\n";
+ code += " " + p_output_vars[0] + " = mix((vec3(1.0f) + a) * pow(c.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * c.rgb, lessThan(c.rgb, vec3(0.0031308f)));\n";
+ }
+ code += " }\n";
+ break;
+ case FUNC_SRGB_TO_LINEAR:
+ code += " {\n";
+ if (RenderingServer::get_singleton()->is_low_end()) {
+ code += " vec3 c = " + p_input_vars[0] + ";\n";
+ code += " " + p_output_vars[0] + " = c * (c * (c * 0.305306011 + 0.682171111) + 0.012522878);\n";
+ } else {
+ code += " vec3 c = " + p_input_vars[0] + ";\n";
+ code += " " + p_output_vars[0] + " = mix(pow((c.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), c.rgb * (1.0 / 12.92), lessThan(c.rgb, vec3(0.04045)));\n";
+ }
+ code += " }\n";
+ break;
default:
break;
}
@@ -3273,12 +3296,14 @@ void VisualShaderNodeColorFunc::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeColorFunc::set_function);
ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeColorFunc::get_function);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Grayscale,HSV2RGB,RGB2HSV,Sepia"), "set_function", "get_function");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Grayscale,HSV2RGB,RGB2HSV,Sepia,LinearToSRGB,SRGBToLinear"), "set_function", "get_function");
BIND_ENUM_CONSTANT(FUNC_GRAYSCALE);
BIND_ENUM_CONSTANT(FUNC_HSV2RGB);
BIND_ENUM_CONSTANT(FUNC_RGB2HSV);
BIND_ENUM_CONSTANT(FUNC_SEPIA);
+ BIND_ENUM_CONSTANT(FUNC_LINEAR_TO_SRGB);
+ BIND_ENUM_CONSTANT(FUNC_SRGB_TO_LINEAR);
BIND_ENUM_CONSTANT(FUNC_MAX);
}
diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h
index 67dc8f7353..36b9560ced 100644
--- a/scene/resources/visual_shader_nodes.h
+++ b/scene/resources/visual_shader_nodes.h
@@ -1353,6 +1353,8 @@ public:
FUNC_HSV2RGB,
FUNC_RGB2HSV,
FUNC_SEPIA,
+ FUNC_LINEAR_TO_SRGB,
+ FUNC_SRGB_TO_LINEAR,
FUNC_MAX,
};