From 4c8ef161206730e9f97a38acd41ed1eb795867ee Mon Sep 17 00:00:00 2001 From: Stanwade <923926049@qq.com> Date: Fri, 13 Aug 2021 23:17:23 +0800 Subject: [PATCH] Add temperature & threshold improved --- Mine-imator Purple.yyp | 9 ++ datafiles/Data/Languages/english.milanguage | 2 + ...action_tl_frame_cam_clrcor_temperature.gml | 7 ++ .../action_tl_frame_cam_clrcor_temperature.yy | 8 ++ .../app_startup_interface_tabs.gml | 2 + .../app_startup_lists/app_startup_lists.gml | 1 + scripts/enums/enums.gml | 1 + .../shader_color_correction_set.gml | 1 + scripts/shader_startup/shader_startup.gml | 1 + .../tab_frame_editor_camera.gml | 4 + scripts/tl_update_values/tl_update_values.gml | 1 + scripts/tl_value_default/tl_value_default.gml | 1 + .../shader_color_correction.fsh | 101 +++++++++++++++++- .../shader_high_bloom_threshold.fsh | 17 ++- views/242e7506-a799-4232-bb73-c9058f7c416b.yy | 3 +- 15 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 scripts/action_tl_frame_cam_clrcor_temperature/action_tl_frame_cam_clrcor_temperature.gml create mode 100644 scripts/action_tl_frame_cam_clrcor_temperature/action_tl_frame_cam_clrcor_temperature.yy diff --git a/Mine-imator Purple.yyp b/Mine-imator Purple.yyp index ad7f08dc..70615b36 100644 --- a/Mine-imator Purple.yyp +++ b/Mine-imator Purple.yyp @@ -14814,6 +14814,14 @@ "resourceType": "GMScript" } }, + { + "Key": "e0d4dfb7-ed8f-4849-b31a-d03c592aaa4b", + "Value": { + "id": "998695d1-cfc7-4689-912b-cb9768906292", + "resourcePath": "scripts\\action_tl_frame_cam_clrcor_temperature\\action_tl_frame_cam_clrcor_temperature.yy", + "resourceType": "GMScript" + } + }, { "Key": "e11bf2f0-afda-4217-b121-497bf48ffe38", "Value": { @@ -17394,6 +17402,7 @@ "b358d9f8-a534-4e3e-b7a5-6182248292ad", "7b98c592-8fe0-48fc-a1e9-3a1c482fac88", "ba0a482e-6a70-4abd-a6cf-9c35ee6b9d74", + "e0d4dfb7-ed8f-4849-b31a-d03c592aaa4b", "b3a28a22-643a-4921-ac7c-0380d429e864", "4d5b374d-f7fa-432c-908b-d9b0ec8e857d", "af0fc81b-dc27-4fb0-9a46-ee4e6c071a40", diff --git a/datafiles/Data/Languages/english.milanguage b/datafiles/Data/Languages/english.milanguage index 52db7b0b..cb180daf 100644 --- a/datafiles/Data/Languages/english.milanguage +++ b/datafiles/Data/Languages/english.milanguage @@ -3021,6 +3021,8 @@ "colorcorrectionsaturationtip": "Determines how saturated the final render will be.", "colorcorrectionvibrance": "Vibrance", "colorcorrectionvibrancetip": "Saturates less-saturated colors in the render.", + "colorcorrectiontemperature": "Temperature", + "colorcorrectiontemperaturetip": "The temperature of the image.", "colorcorrectioncolorburn": "Color burn", "colorcorrectioncolorburntip": "Applies a color to the render with a Color Burn blend mode.", "grain": "Film grain", diff --git a/scripts/action_tl_frame_cam_clrcor_temperature/action_tl_frame_cam_clrcor_temperature.gml b/scripts/action_tl_frame_cam_clrcor_temperature/action_tl_frame_cam_clrcor_temperature.gml new file mode 100644 index 00000000..35a228bb --- /dev/null +++ b/scripts/action_tl_frame_cam_clrcor_temperature/action_tl_frame_cam_clrcor_temperature.gml @@ -0,0 +1,7 @@ +/// action_tl_frame_cam_clrcor_temperature(value, add) +/// @arg value +/// @arg add + +tl_value_set_start(action_tl_frame_cam_clrcor_temperature, true) +tl_value_set(e_value.CAM_TEMPERATURE, argument0 / 100, argument1) +tl_value_set_done() diff --git a/scripts/action_tl_frame_cam_clrcor_temperature/action_tl_frame_cam_clrcor_temperature.yy b/scripts/action_tl_frame_cam_clrcor_temperature/action_tl_frame_cam_clrcor_temperature.yy new file mode 100644 index 00000000..223d62b6 --- /dev/null +++ b/scripts/action_tl_frame_cam_clrcor_temperature/action_tl_frame_cam_clrcor_temperature.yy @@ -0,0 +1,8 @@ +{ + "id": "e0d4dfb7-ed8f-4849-b31a-d03c592aaa4b", + "modelName": "GMScript", + "mvc": "1.0", + "name": "action_tl_frame_cam_clrcor_temperature", + "IsCompatibility": false, + "IsDnD": false +} \ No newline at end of file diff --git a/scripts/app_startup_interface_tabs/app_startup_interface_tabs.gml b/scripts/app_startup_interface_tabs/app_startup_interface_tabs.gml index 106262d1..d5e43ee6 100644 --- a/scripts/app_startup_interface_tabs/app_startup_interface_tabs.gml +++ b/scripts/app_startup_interface_tabs/app_startup_interface_tabs.gml @@ -537,6 +537,8 @@ with (frame_editor) tbx_saturation.suffix = "%" tbx_vibrance = new_textbox_integer() tbx_vibrance.suffix = "%" + tbx_temperature = new_textbox_integer() + tbx_temperature.suffix = "K" tbx_grain_strength = new_textbox_ninteger() tbx_grain_strength.suffix = "%" diff --git a/scripts/app_startup_lists/app_startup_lists.gml b/scripts/app_startup_lists/app_startup_lists.gml index 67977c84..6e69956f 100644 --- a/scripts/app_startup_lists/app_startup_lists.gml +++ b/scripts/app_startup_lists/app_startup_lists.gml @@ -98,6 +98,7 @@ ds_list_add(value_name_list, "CAM_BRIGHTNESS", "CAM_SATURATION", "CAM_VIBRANCE", + "CAM_TEMPERATURE", "CAM_COLOR_BURN", "CAM_GRAIN", "CAM_GRAIN_STRENGTH", diff --git a/scripts/enums/enums.gml b/scripts/enums/enums.gml index af3ce07a..6bf408a8 100644 --- a/scripts/enums/enums.gml +++ b/scripts/enums/enums.gml @@ -187,6 +187,7 @@ enum e_value CAM_BRIGHTNESS, CAM_SATURATION, CAM_VIBRANCE, + CAM_TEMPERATURE, CAM_COLOR_BURN, CAM_GRAIN, CAM_GRAIN_STRENGTH, diff --git a/scripts/shader_color_correction_set/shader_color_correction_set.gml b/scripts/shader_color_correction_set/shader_color_correction_set.gml index e716e699..37fca27b 100644 --- a/scripts/shader_color_correction_set/shader_color_correction_set.gml +++ b/scripts/shader_color_correction_set/shader_color_correction_set.gml @@ -4,4 +4,5 @@ render_set_uniform("uContrast", render_camera.value[e_value.CAM_CONTRAST] + 1) render_set_uniform("uBrightness", render_camera.value[e_value.CAM_BRIGHTNESS]) render_set_uniform("uSaturation", render_camera.value[e_value.CAM_SATURATION]) render_set_uniform("uVibrance", render_camera.value[e_value.CAM_VIBRANCE]) +render_set_uniform("uTemperature", render_camera.value[e_value.CAM_TEMPERATURE]) render_set_uniform_color("uColorBurn", render_camera.value[e_value.CAM_COLOR_BURN], 1) \ No newline at end of file diff --git a/scripts/shader_startup/shader_startup.gml b/scripts/shader_startup/shader_startup.gml index d4b10b83..ed314da4 100644 --- a/scripts/shader_startup/shader_startup.gml +++ b/scripts/shader_startup/shader_startup.gml @@ -368,6 +368,7 @@ with (shader_map[?shader_color_correction]) new_shader_uniform("uBrightness") new_shader_uniform("uSaturation") new_shader_uniform("uVibrance") + new_shader_uniform("uTemperature") new_shader_uniform("uColorBurn") } diff --git a/scripts/tab_frame_editor_camera/tab_frame_editor_camera.gml b/scripts/tab_frame_editor_camera/tab_frame_editor_camera.gml index 19f29b82..2d9585ab 100644 --- a/scripts/tab_frame_editor_camera/tab_frame_editor_camera.gml +++ b/scripts/tab_frame_editor_camera/tab_frame_editor_camera.gml @@ -369,6 +369,10 @@ if (tl_edit.value[e_value.CAM_COLOR_CORRECTION] && checkbox_expand_frameeditor_c draw_meter("frameeditorcameracolorcorrectionvibrance", dx, dy, dw, round(tl_edit.value[e_value.CAM_VIBRANCE] * 100), 50, 0, 100, 0, 1, tab.camera.tbx_vibrance, action_tl_frame_cam_clrcor_vibrance, capwid) tab_next() + tab_control_meter() + draw_meter("frameeditorcameracolorcorrectiontemperature", dx, dy, dw, round(tl_edit.value[e_value.CAM_TEMPERATURE] * 100), 50, -1000, 1000, 0, 1, tab.camera.tbx_temperature, action_tl_frame_cam_clrcor_temperature, capwid) + tab_next() + tab_control_color() draw_button_color("frameeditorcameracolorcorrectioncolorburn", dx, dy, dw, tl_edit.value[e_value.CAM_COLOR_BURN], c_white, false, action_tl_frame_cam_clrcor_color_burn) tab_next() diff --git a/scripts/tl_update_values/tl_update_values.gml b/scripts/tl_update_values/tl_update_values.gml index e7bfafc4..d5a066c8 100644 --- a/scripts/tl_update_values/tl_update_values.gml +++ b/scripts/tl_update_values/tl_update_values.gml @@ -236,6 +236,7 @@ if (value_type[e_value_type.CAMERA]) tl_update_values_ease(e_value.CAM_SATURATION, trans, p) tl_update_values_ease(e_value.CAM_VIBRANCE, trans, p) tl_update_values_ease(e_value.CAM_COLOR_BURN, trans, p) + tl_update_values_ease(e_value.CAM_TEMPERATURE, trans, p) tl_update_values_ease(e_value.CAM_GRAIN, trans, p) tl_update_values_ease(e_value.CAM_GRAIN_STRENGTH, trans, p) diff --git a/scripts/tl_value_default/tl_value_default.gml b/scripts/tl_value_default/tl_value_default.gml index cf1bc8e2..50468ae4 100644 --- a/scripts/tl_value_default/tl_value_default.gml +++ b/scripts/tl_value_default/tl_value_default.gml @@ -61,6 +61,7 @@ switch (argument0) case e_value.CAM_BRIGHTNESS: return 0 case e_value.CAM_SATURATION: return 1 case e_value.CAM_VIBRANCE: return 0 + case e_value.CAM_TEMPERATURE: return 0 case e_value.CAM_COLOR_BURN: return c_white case e_value.CAM_GRAIN_STRENGTH: return .10 case e_value.CAM_GRAIN_SATURATION: return .10 diff --git a/shaders/shader_color_correction/shader_color_correction.fsh b/shaders/shader_color_correction/shader_color_correction.fsh index a7c3da81..b7c3c4e4 100644 --- a/shaders/shader_color_correction/shader_color_correction.fsh +++ b/shaders/shader_color_correction/shader_color_correction.fsh @@ -5,6 +5,12 @@ uniform float uBrightness; uniform float uSaturation; uniform float uVibrance; uniform vec4 uColorBurn; +uniform float uTemperature; + +const lowp vec3 warmFilter =vec3(0.93,0.54,0.0); +const mediump mat3 RGBtoYIQ = mat3(0.299, 0.587, 0.114, 0.596, -0.274, -0.322, 0.212, -0.523, 0.311); +const mediump mat3 YIQtoRGB = mat3(1.0, 0.956, 0.621, 1.0, -0.272, -0.647, 1.0, -1.105, 1.702); +const mediump vec3 luminanceWeighting = vec3(0.2125,0.7154,0.0721); vec4 rgbtohsb(vec4 c) { @@ -17,13 +23,25 @@ vec4 rgbtohsb(vec4 c) return vec4(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x, c.a); } + void main() { // Get base vec4 baseColor = texture2D(gm_BaseTexture, vTexCoord); // Brightness and contrast - baseColor.rgb = (baseColor.rgb - vec3(0.5)) * vec3(uContrast) + vec3(uBrightness + 0.5); + //baseColor.rgb = (baseColor.rgb - vec3(0.5)) * vec3(uContrast) + vec3(uBrightness + 0.5); + //Obsolete old algorithm + + baseColor.rgb = (baseColor.rgb - vec3(0.5)) * vec3(uContrast) + vec3(0.5); + if(uBrightness>0.0) + { + baseColor.rgb = baseColor.rgb + baseColor.rgb * (1.0/(1.0-uBrightness)-1.0); + } + else + { + baseColor.rgb = baseColor.rgb + baseColor.rgb * uBrightness; + } baseColor.rgb = clamp(baseColor.rgb, vec3(0.0), vec3(1.0)); // Saturation @@ -39,8 +57,87 @@ void main() baseColor.rgb = mix(satIntensity, baseColor.rgb, 1.0 + (vibrance * uVibrance)); baseColor.rgb = clamp(baseColor.rgb, vec3(0.0), vec3(1.0)); + // Color burn baseColor.rgb = 1.0 - (1.0 - baseColor.rgb) / uColorBurn.rgb; + // color temperature + mediump vec3 yiq = RGBtoYIQ * baseColor.rgb; + yiq.b = clamp(yiq.b,-0.5226,0.5226); + lowp vec3 RGB = YIQtoRGB * yiq; + lowp float A = (RGB.r <0.5? (2.0* RGB.r * warmFilter.r) : (1.0-2.0* (1.0 - RGB.r) * (1.0- warmFilter.r))); + lowp float B = (RGB.g <0.5? (2.0* RGB.g * warmFilter.g) : (1.0-2.0* (1.0 - RGB.g) * (1.0- warmFilter.g))); + lowp float C = (RGB.b <0.5? (2.0* RGB.b * warmFilter.b) : (1.0-2.0* (1.0 - RGB.b) * (1.0- warmFilter.b))); + lowp vec3 processed = vec3(A,B,C); + + gl_FragColor = vec4(mix(RGB, processed,uTemperature), baseColor.a); + +} + + +//HSL brightness adjustment(Replaceable) +/*void main() +{ + vec4 baseColor = texture2D(gm_BaseTexture, vTexCoord); + + //Convert the RGB value in the range of 0-1 to 0-255 + float r = baseColor.r * 255.0; + float g = baseColor.g * 255.0; + float b = baseColor.b * 255.0; + + //float L=((max(r,max(g,b))+min(r,min(g,b)))/2.0); + //Another brightness calculation formula(Replaceable) + float L=0.3*r+0.6*g+0.1*b; + float rHS = 0.0; + float gHS = 0.0; + float bHS = 0.0; + + if(L > 128.0) + { + rHS = (r * 128.0 - (L - 128.0) * 256.0) / (256.0 - L); + gHS = (g * 128.0 - (L - 128.0) * 256.0) / (256.0 - L); + bHS = (b * 128.0 - (L - 128.0) * 256.0) / (256.0 - L); + } + else + { + rHS = r * 128.0 / L; + gHS = g * 128.0 / L; + bHS = b * 128.0 / L; + } + + float delta = uBrightness*256.0; + float newL = L + delta - 128.0; + float newR = .0; + float newG = .0; + float newB = .0; + + if(newL > 0.0) { + newR = rHS + (256.0 - rHS) * newL / 128.0; + newG = gHS + (256.0 - gHS) * newL / 128.0; + newB = bHS + (256.0 - bHS) * newL / 128.0; + } else { + newR = rHS + rHS * newL / 128.0; + newG = gHS + gHS * newL / 128.0; + newB = bHS + bHS * newL / 128.0; + + } + baseColor.rgb =vec3(newR/255.0, newG/255.0, newB/255.0); + baseColor.rgb = (baseColor.rgb - vec3(0.5)) * vec3(uContrast) + vec3(0.5); + baseColor.rgb = clamp(baseColor.rgb, vec3(0.0), vec3(1.0)); + + vec3 W = vec3(0.2125, 0.7154, 0.0721); + vec3 satIntensity = vec3(dot(baseColor.rgb, W)); + baseColor.rgb = mix(satIntensity, baseColor.rgb, uSaturation); + baseColor.rgb = clamp(baseColor.rgb, vec3(0.0), vec3(1.0)); + + satIntensity = vec3(dot(baseColor.rgb, W)); + float sat = rgbtohsb(baseColor).g; + float vibrance = 1.0 - pow(pow(sat, 8.0), .15); + baseColor.rgb = mix(satIntensity, baseColor.rgb, 1.0 + (vibrance * uVibrance)); + baseColor.rgb = clamp(baseColor.rgb, vec3(0.0), vec3(1.0)); + + baseColor.rgb = 1.0 - (1.0 - baseColor.rgb) / uColorBurn.rgb; + gl_FragColor = baseColor; -} \ No newline at end of file + +}*/ diff --git a/shaders/shader_high_bloom_threshold/shader_high_bloom_threshold.fsh b/shaders/shader_high_bloom_threshold/shader_high_bloom_threshold.fsh index 38b1f047..b1b2054f 100644 --- a/shaders/shader_high_bloom_threshold/shader_high_bloom_threshold.fsh +++ b/shaders/shader_high_bloom_threshold/shader_high_bloom_threshold.fsh @@ -2,7 +2,9 @@ uniform float uThreshold; varying vec2 vTexCoord; -void main() +//legacy code by Nimikata + +/*void main() { vec4 baseColor = texture2D(gm_BaseTexture, vTexCoord); @@ -10,4 +12,17 @@ void main() gl_FragColor = baseColor; else gl_FragColor = vec4(vec3(0.0), 1.0); +}*/ + +void main() +{ + vec4 baseColor = texture2D(gm_BaseTexture, vTexCoord); + float brightness = 0.299*baseColor.r + 0.587*baseColor.g + 0.114*baseColor.b; + if(brightness > uThreshold) { + gl_FragColor = baseColor; + } + else + { + gl_FragColor = vec4(vec3(0.0), 1.0); + } } \ No newline at end of file diff --git a/views/242e7506-a799-4232-bb73-c9058f7c416b.yy b/views/242e7506-a799-4232-bb73-c9058f7c416b.yy index 7844a32c..89ddb373 100644 --- a/views/242e7506-a799-4232-bb73-c9058f7c416b.yy +++ b/views/242e7506-a799-4232-bb73-c9058f7c416b.yy @@ -9,7 +9,8 @@ "a5002786-20f1-4e50-9894-270217f12d7b", "b358d9f8-a534-4e3e-b7a5-6182248292ad", "7b98c592-8fe0-48fc-a1e9-3a1c482fac88", - "ba0a482e-6a70-4abd-a6cf-9c35ee6b9d74" + "ba0a482e-6a70-4abd-a6cf-9c35ee6b9d74", + "e0d4dfb7-ed8f-4849-b31a-d03c592aaa4b" ], "filterType": "GMScript", "folderName": "Color correction", -- Gitee