mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-01-07 01:43:35 +08:00
White balance node added
This commit is contained in:
parent
088c80aa2b
commit
f0dad0ce8e
64
addons/ShaderLib/Artistic/Adjustment/WhiteBalance.gd
Normal file
64
addons/ShaderLib/Artistic/Adjustment/WhiteBalance.gd
Normal file
@ -0,0 +1,64 @@
|
||||
@tool
|
||||
class_name VisualShaderNodeWhiteBalance extends VisualShaderNodeCustom
|
||||
|
||||
func _get_name() -> String:
|
||||
return "WhiteBalance"
|
||||
|
||||
func _get_category() -> String:
|
||||
return "Artistic/Adjustment"
|
||||
|
||||
func _get_description() -> String:
|
||||
return "Adjusts the temperature and tint of input \"in\" by the amount of inputs \"temperature\" and \"tint\" respectively."
|
||||
|
||||
func _get_return_icon_type() -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_input_port_count() -> int:
|
||||
return 3
|
||||
|
||||
func _get_input_port_name(port: int) -> String:
|
||||
match port:
|
||||
0:
|
||||
return "in"
|
||||
1:
|
||||
return "temperature"
|
||||
_:
|
||||
return "tint"
|
||||
|
||||
func _get_input_port_type(port: int) -> PortType:
|
||||
match port:
|
||||
0:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
_:
|
||||
return PORT_TYPE_SCALAR
|
||||
|
||||
func _get_input_port_default_value(port: int) -> Variant:
|
||||
match port:
|
||||
1, 2:
|
||||
return 0.0
|
||||
_:
|
||||
return null
|
||||
|
||||
func _get_output_port_count() -> int:
|
||||
return 1
|
||||
|
||||
func _get_output_port_name(port: int) -> String:
|
||||
return "out"
|
||||
|
||||
func _get_output_port_type(port: int) -> PortType:
|
||||
return PORT_TYPE_VECTOR_3D
|
||||
|
||||
func _get_global_code(mode: Shader.Mode) -> String:
|
||||
var code: String = preload("WhiteBalance.gdshaderinc").code
|
||||
return code
|
||||
|
||||
func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shader.Mode, type: VisualShader.Type) -> String:
|
||||
var input: String = "vec3(1.0)"
|
||||
|
||||
if input_vars[0]:
|
||||
input = input_vars[0]
|
||||
|
||||
var temperature: String = input_vars[1]
|
||||
var tint: String = input_vars[2]
|
||||
|
||||
return output_vars[0] + " = white_balance(%s, %s, %s);" % [input, temperature, tint]
|
@ -0,0 +1,36 @@
|
||||
vec3 white_balance(vec3 input, float temperature, float tint){
|
||||
float t1 = temperature * 10.0 / 6.0;
|
||||
float t2 = tint * 10.0 / 6.0;
|
||||
|
||||
float x = 0.31271 - t1 * (t1 < 0.0 ? 0.1 : 0.05);
|
||||
float standard_illuminant_y = 2.87 * x - 3.0 * x * x - 0.27509507;
|
||||
float y = standard_illuminant_y + t2 * 0.05;
|
||||
|
||||
vec3 w1 = vec3(0.949237, 1.03542, 1.08728);
|
||||
|
||||
float Y = 1.;
|
||||
float X = Y * x / y;
|
||||
float Z = Y * (1. - x - y) / y;
|
||||
float L = 0.7328 * X + 0.4296 * Y - 0.1624 * Z;
|
||||
float M = -0.7036 * X + 1.6975 * Y + 0.0061 * Z;
|
||||
float S = 0.0030 * X + 0.0136 * Y + 0.9834 * Z;
|
||||
vec3 w2 = vec3(L, M, S);
|
||||
|
||||
vec3 balance = vec3(w1.x / w2.x, w1.y / w2.y, w1.z / w2.z);
|
||||
|
||||
mat3 LIN_2_LMS_MAT = mat3(
|
||||
vec3(3.90405e-1, 5.49941e-1, 8.92632e-3),
|
||||
vec3(7.08416e-2, 9.63172e-1, 1.35775e-3),
|
||||
vec3(2.31082e-2, 1.28021e-1, 9.36245e-1)
|
||||
);
|
||||
|
||||
mat3 LMS_2_LIN_MAT = mat3(
|
||||
vec3(2.85847, -1.62879, -2.48910),
|
||||
vec3(-2.10182e-1, 1.15820e+0, 3.24281e-4),
|
||||
vec3(-4.18120e-2, -1.18169e-1, 1.06867e+0)
|
||||
);
|
||||
|
||||
vec3 lms = LIN_2_LMS_MAT * input;
|
||||
lms *= balance;
|
||||
return LMS_2_LIN_MAT * lms;
|
||||
}
|
@ -13,6 +13,7 @@ Delete the contents of **_addons/ShaderLib_** folder from your project. Make sur
|
||||
<h4><a href="/documentation/Nodes/Artistic/Adjustment/HueNode.md">  Hue node</a></h4>
|
||||
<h4><a href="/documentation/Nodes/Artistic/Adjustment/ReplaceColorNode.md">  Replace Color node</a></h4>
|
||||
<h4><a href="/documentation/Nodes/Artistic/Adjustment/SaturationNode.md">  Saturation node</a></h4>
|
||||
<h4><a href="/documentation/Nodes/Artistic/Adjustment/WhiteBalanceNode.md">  White Balance node</a></h4>
|
||||
|
||||
<h2>Geometry nodes</h2>
|
||||
|
||||
|
16
documentation/Nodes/Artistic/Adjustment/WhiteBalanceNode.md
Normal file
16
documentation/Nodes/Artistic/Adjustment/WhiteBalanceNode.md
Normal file
@ -0,0 +1,16 @@
|
||||
# White Balance node
|
||||
Adjusts the temperature and tint of input <b><i>in</i></b> by the amount of inputs <b><i>temperature</i></b> and <b><i>tint</i></b> respectively. Temperature has the effect of shifting the values towards yellow or blue. Tint has the effect of shifting towards pink or green.
|
||||
<hr>
|
||||
|
||||
**Inputs**
|
||||
|Name|Type|Binding|Description|
|
||||
|---|---|---|---|
|
||||
|in|vec3|none|Input value|
|
||||
|temperature|float|none|Temperature offset value|
|
||||
|tint|float|none|Tint offset value|
|
||||
|
||||
**Outputs**
|
||||
|Name|Type|Binding|Description|
|
||||
|---|---|---|---|
|
||||
|out|vec3|None|Output value|
|
||||
___
|
Loading…
x
Reference in New Issue
Block a user