Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion doc/classes/VisualShaderNodeColorFunc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<constant name="FUNC_LINEAR_TO_SRGB" value="4" enum="Function">
Converts color from linear encoding to nonlinear sRGB encoding using the following formula:
[codeblock]
vec3 c = clamp(c, vec3(0.0), vec3(1.0));
const vec3 a = vec3(0.055f);
return mix((vec3(1.0f) + a) * pow(c.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * c.rgb, lessThan(c.rgb, vec3(0.0031308f)));
[/codeblock]
Expand Down
1 change: 0 additions & 1 deletion drivers/gles3/shaders/tonemap_inc.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ layout(std140) uniform TonemapData { //ubo:0

// This expects 0-1 range input.
vec3 linear_to_srgb(vec3 color) {
//color = clamp(color, vec3(0.0), vec3(1.0));
//const vec3 a = vec3(0.055f);
//return mix((vec3(1.0f) + a) * pow(color.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * color.rgb, lessThan(color.rgb, vec3(0.0031308f)));
// Approximation from http://chilliant.blogspot.com/2012/08/srgb-approximations-for-hlsl.html
Expand Down
2 changes: 1 addition & 1 deletion scene/resources/visual_shader_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3260,7 +3260,7 @@ String VisualShaderNodeColorFunc::generate_code(Shader::Mode p_mode, VisualShade
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 += " vec3 c = " + p_input_vars[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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ layout(set = 1, binding = 0) uniform sampler2D source_color2;
layout(location = 0) out vec4 frag_color;

vec3 linear_to_srgb(vec3 color) {
//if going to srgb, clamp from 0 to 1.
color = clamp(color, vec3(0.0), vec3(1.0));
const vec3 a = vec3(0.055f);
return mix((vec3(1.0f) + a) * pow(color.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * color.rgb, lessThan(color.rgb, vec3(0.0031308f)));
}
Expand Down Expand Up @@ -179,6 +177,7 @@ void main() {
}
if (bool(params.flags & FLAG_SRGB)) {
color.rgb = linear_to_srgb(color.rgb);
color.rgb = clamp(color.rgb, vec3(0.0), vec3(1.0));
}
if (bool(params.flags & FLAG_ALPHA_TO_ONE)) {
color.a = 1.0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ params;
#define textureLinear(tex, uv) srgb_to_linear(textureLod(tex, uv, 0.0).rgb)

vec3 linear_to_srgb(vec3 color) {
// If going to srgb, clamp from 0 to 1.
color = clamp(color, vec3(0.0), vec3(1.0));
const vec3 a = vec3(0.055f);
return mix((vec3(1.0f) + a) * pow(color.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * color.rgb, lessThan(color.rgb, vec3(0.0031308f)));
}
Expand Down Expand Up @@ -138,6 +136,7 @@ void main() {
out_color.rgb = blending_weight.x * textureLinear(color_tex, blending_coord.xy);
out_color.rgb += blending_weight.y * textureLinear(color_tex, blending_coord.zw);
out_color.rgb = linear_to_srgb(out_color.rgb);
out_color.rgb = clamp(out_color.rgb, vec3(0.0), vec3(1.0));
out_color.a = texture(color_tex, tex_coord).a;
}
if (bool(params.use_debanding)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ layout(push_constant, std430) uniform Params {
params;

vec3 linear_to_srgb(vec3 color) {
//if going to srgb, clamp from 0 to 1.
color = clamp(color, vec3(0.0), vec3(1.0));
const vec3 a = vec3(0.055f);
return mix((vec3(1.0f) + a) * pow(color.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * color.rgb, lessThan(color.rgb, vec3(0.0031308f)));
}
Expand Down Expand Up @@ -181,5 +179,5 @@ void main() {

#endif

imageStore(screen_buffer, screen_pos, vec4(linear_to_srgb(light), 1.0));
imageStore(screen_buffer, screen_pos, vec4(clamp(linear_to_srgb(light), vec3(0.0), vec3(1.0)), 1.0));
}