Cleanup: Compositor: Remove common_math_utils includes
This patches removes common_math_utils includes from compositor shaders and replaces them with math lib includes. This involves moving some functions from that file to to the math lib files. Pull Request: https://projects.blender.org/blender/blender/pulls/135157
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "gpu_shader_common_math_utils.glsl"
|
||||
#include "gpu_shader_compositor_texture_utilities.glsl"
|
||||
#include "gpu_shader_math_vector_lib.glsl"
|
||||
|
||||
vec4 load_input(ivec2 texel)
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "gpu_shader_common_math_utils.glsl"
|
||||
#include "gpu_shader_compositor_texture_utilities.glsl"
|
||||
#include "gpu_shader_math_vector_lib.glsl"
|
||||
|
||||
/* Given the texel in the range [-radius, radius] in both axis, load the appropriate weight from
|
||||
* the weights texture, where the given texel (0, 0) corresponds the center of weights texture.
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
* for digital images." Proceedings of the 29th annual conference on Computer graphics and
|
||||
* interactive techniques. 2002. */
|
||||
|
||||
#include "gpu_shader_common_math_utils.glsl"
|
||||
#include "gpu_shader_compositor_texture_utilities.glsl"
|
||||
#include "gpu_shader_math_vector_lib.glsl"
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "gpu_shader_common_color_utils.glsl"
|
||||
#include "gpu_shader_common_math_utils.glsl"
|
||||
#include "gpu_shader_math_matrix_lib.glsl"
|
||||
|
||||
/* Algorithm from the book Video Demystified. Chapter 7. Chroma Keying. */
|
||||
void node_composite_chroma_matte(vec4 color,
|
||||
@@ -25,7 +25,7 @@ void node_composite_chroma_matte(vec4 color,
|
||||
|
||||
/* Rotate the color onto the space of the key such that x axis of the color space passes through
|
||||
* the key color. */
|
||||
color_cc = vector_to_rotation_matrix(key_cc * vec2(1.0, -1.0)) * color_cc;
|
||||
color_cc = from_direction(key_cc * vec2(1.0, -1.0)) * color_cc;
|
||||
|
||||
/* Compute foreground key. If positive, the value is in the [0, 1] range. */
|
||||
float foreground_key = color_cc.x - (abs(color_cc.y) / acceptance);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "gpu_shader_common_color_utils.glsl"
|
||||
#include "gpu_shader_common_math_utils.glsl"
|
||||
#include "gpu_shader_math_vector_lib.glsl"
|
||||
|
||||
void node_composite_color_correction(vec4 color,
|
||||
float mask,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "gpu_shader_common_math_utils.glsl"
|
||||
#include "gpu_shader_math_base_lib.glsl"
|
||||
|
||||
void node_composite_difference_matte(
|
||||
vec4 color, vec4 key, float tolerance, float falloff, out vec4 result, out float matte)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include "gpu_shader_common_math_utils.glsl"
|
||||
#include "gpu_shader_math_vector_lib.glsl"
|
||||
|
||||
void node_composite_gamma(vec4 color, float gamma, out vec4 result)
|
||||
{
|
||||
|
||||
@@ -68,17 +68,6 @@ float compatible_pow(float x, float y)
|
||||
return pow(x, y);
|
||||
}
|
||||
|
||||
/* A version of pow that returns a fallback value if the computation is undefined. From the spec:
|
||||
* The result is undefined if x < 0 or if x = 0 and y is less than or equal 0. */
|
||||
float fallback_pow(float x, float y, float fallback)
|
||||
{
|
||||
if (x < 0.0 || (x == 0.0 && y <= 0.0)) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return pow(x, y);
|
||||
}
|
||||
|
||||
float wrap(float a, float b, float c)
|
||||
{
|
||||
float range = b - c;
|
||||
@@ -171,24 +160,8 @@ void vector_copy(vec3 normal, out vec3 outnormal)
|
||||
outnormal = normal;
|
||||
}
|
||||
|
||||
vec3 fallback_pow(vec3 a, float b, vec3 fallback)
|
||||
{
|
||||
return vec3(fallback_pow(a.x, b, fallback.x),
|
||||
fallback_pow(a.y, b, fallback.y),
|
||||
fallback_pow(a.z, b, fallback.z));
|
||||
}
|
||||
|
||||
/* Matrix Math */
|
||||
|
||||
/* Return a 2D rotation matrix with the angle that the input 2D vector makes with the x axis.
|
||||
* Assumes the vector is normalized. */
|
||||
mat2 vector_to_rotation_matrix(vec2 vector)
|
||||
{
|
||||
float cos_angle = vector.x;
|
||||
float sin_angle = vector.y;
|
||||
return mat2(cos_angle, sin_angle, -sin_angle, cos_angle);
|
||||
}
|
||||
|
||||
mat3 euler_to_mat3(vec3 euler)
|
||||
{
|
||||
float cx = cos(euler.x);
|
||||
|
||||
@@ -214,6 +214,19 @@ float cos_from_sin(float s)
|
||||
return safe_sqrt(1.0 - square(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* A version of pow that returns a fallback value if the computation is undefined. From the spec:
|
||||
* The result is undefined if x < 0 or if x = 0 and y is less than or equal 0.
|
||||
*/
|
||||
float fallback_pow(float x, float y, float fallback)
|
||||
{
|
||||
if (x < 0.0 || (x == 0.0 && y <= 0.0)) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return pow(x, y);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
#endif /* GPU_SHADER_MATH_BASE_LIB_GLSL */
|
||||
|
||||
@@ -235,6 +235,12 @@ mat4x4 from_loc_rot(vec3 location, EulerXYZ rotation);
|
||||
*/
|
||||
mat4x4 from_loc_rot_scale(vec3 location, EulerXYZ rotation, vec3 scale);
|
||||
|
||||
/**
|
||||
* Creates a 2D rotation matrix with the angle that the given direction makes with the x axis.
|
||||
* Assumes the direction vector is normalized.
|
||||
*/
|
||||
mat2x2 from_direction(vec2 direction);
|
||||
|
||||
/**
|
||||
* Create a rotation matrix from 2 basis vectors.
|
||||
* The matrix determinant is given to be positive and it can be converted to other rotation types.
|
||||
@@ -1028,6 +1034,13 @@ mat4x4 from_loc_rot_scale(vec3 location, AxisAngle rotation, vec3 scale)
|
||||
return ret;
|
||||
}
|
||||
|
||||
mat2x2 from_direction(vec2 direction)
|
||||
{
|
||||
float cos_angle = direction.x;
|
||||
float sin_angle = direction.y;
|
||||
return mat2x2(cos_angle, sin_angle, -sin_angle, cos_angle);
|
||||
}
|
||||
|
||||
mat3x3 from_up_axis(vec3 up)
|
||||
{
|
||||
/* Duff, Tom, et al. "Building an orthonormal basis, revisited." JCGT 6.1 (2017). */
|
||||
|
||||
@@ -146,6 +146,14 @@ vec2 safe_rcp(vec2 a);
|
||||
vec3 safe_rcp(vec3 a);
|
||||
vec4 safe_rcp(vec4 a);
|
||||
|
||||
/**
|
||||
* A version of pow that returns a fallback value if the computation is undefined. From the spec:
|
||||
* The result is undefined if x < 0 or if x = 0 and y is less than or equal 0.
|
||||
*/
|
||||
vec2 fallback_pow(vec2 a, float b, vec2 fallback);
|
||||
vec3 fallback_pow(vec3 a, float b, vec3 fallback);
|
||||
vec4 fallback_pow(vec4 a, float b, vec4 fallback);
|
||||
|
||||
/**
|
||||
* Per component linear interpolation.
|
||||
*/
|
||||
@@ -580,6 +588,24 @@ vec4 safe_rcp(vec4 a)
|
||||
return select(vec4(0.0), (1.0 / a), notEqual(a, vec4(0.0)));
|
||||
}
|
||||
|
||||
vec2 fallback_pow(vec2 a, float b, vec2 fallback)
|
||||
{
|
||||
return vec2(fallback_pow(a.x, b, fallback.x), fallback_pow(a.y, b, fallback.y));
|
||||
}
|
||||
vec3 fallback_pow(vec3 a, float b, vec3 fallback)
|
||||
{
|
||||
return vec3(fallback_pow(a.x, b, fallback.x),
|
||||
fallback_pow(a.y, b, fallback.y),
|
||||
fallback_pow(a.z, b, fallback.z));
|
||||
}
|
||||
vec4 fallback_pow(vec4 a, float b, vec4 fallback)
|
||||
{
|
||||
return vec4(fallback_pow(a.x, b, fallback.x),
|
||||
fallback_pow(a.y, b, fallback.y),
|
||||
fallback_pow(a.z, b, fallback.z),
|
||||
fallback_pow(a.w, b, fallback.w));
|
||||
}
|
||||
|
||||
vec2 interpolate(vec2 a, vec2 b, float t)
|
||||
{
|
||||
return mix(a, b, t);
|
||||
|
||||
Reference in New Issue
Block a user