Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Emara <mail@OmarEmara.dev>2022-05-06 13:58:14 +0300
committerOmar Emara <mail@OmarEmara.dev>2022-05-06 13:58:14 +0300
commit8f6f28a0dc0ad7697863e4dcd78e85f87f9fb8db (patch)
tree5a7bb4ab3526801a7b323f8b18a012cd213af5bb /source/blender/gpu/shaders/material
parentf5428736a76add4bce46da452aed6bd04ee8e71b (diff)
GPU: Move common shaders into a common directory
This patch moves some of the utility library shaders into a common directory and makes the necessary renames across shaders. Additionally, material-specific transform functions were moved outside of math utils into a separate transform_utils.glsl file. This is needed in preparation for the viewport compositor, which will make use of some of those utilities and will require all material specific bit to be removed out of those files. Reviewed By: fclem Differential Revision: https://developer.blender.org/D14688
Diffstat (limited to 'source/blender/gpu/shaders/material')
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_color_ramp.glsl37
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_color_util.glsl161
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_combine_color.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_combine_hsv.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_fractal_noise.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_gamma.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_hair_info.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_hash.glsl230
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_hue_sat_val.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_map_range.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_mapping.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_math.glsl221
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl213
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_mix_rgb.glsl293
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_noise.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_point_info.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_separate_color.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_separate_hsv.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_tex_brick.glsl4
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_tex_environment.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_tex_musgrave.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_tex_noise.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_tex_voronoi.glsl4
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_tex_wave.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_tex_white_noise.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_transform_utils.glsl71
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl2
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_vector_rotate.glsl2
28 files changed, 94 insertions, 1178 deletions
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_color_ramp.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_color_ramp.glsl
deleted file mode 100644
index 17240da4050..00000000000
--- a/source/blender/gpu/shaders/material/gpu_shader_material_color_ramp.glsl
+++ /dev/null
@@ -1,37 +0,0 @@
-void valtorgb_opti_constant(
- float fac, float edge, vec4 color1, vec4 color2, out vec4 outcol, out float outalpha)
-{
- outcol = (fac > edge) ? color2 : color1;
- outalpha = outcol.a;
-}
-
-void valtorgb_opti_linear(
- float fac, vec2 mulbias, vec4 color1, vec4 color2, out vec4 outcol, out float outalpha)
-{
- fac = clamp(fac * mulbias.x + mulbias.y, 0.0, 1.0);
- outcol = mix(color1, color2, fac);
- outalpha = outcol.a;
-}
-
-void valtorgb_opti_ease(
- float fac, vec2 mulbias, vec4 color1, vec4 color2, out vec4 outcol, out float outalpha)
-{
- fac = clamp(fac * mulbias.x + mulbias.y, 0.0, 1.0);
- fac = fac * fac * (3.0 - 2.0 * fac);
- outcol = mix(color1, color2, fac);
- outalpha = outcol.a;
-}
-
-void valtorgb(float fac, sampler1DArray colormap, float layer, out vec4 outcol, out float outalpha)
-{
- outcol = texture(colormap, vec2(fac, layer));
- outalpha = outcol.a;
-}
-
-void valtorgb_nearest(
- float fac, sampler1DArray colormap, float layer, out vec4 outcol, out float outalpha)
-{
- fac = clamp(fac, 0.0, 1.0);
- outcol = texelFetch(colormap, ivec2(fac * (textureSize(colormap, 0).x - 1), layer), 0);
- outalpha = outcol.a;
-}
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_color_util.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_color_util.glsl
deleted file mode 100644
index fe89985ae7f..00000000000
--- a/source/blender/gpu/shaders/material/gpu_shader_material_color_util.glsl
+++ /dev/null
@@ -1,161 +0,0 @@
-void rgb_to_hsv(vec4 rgb, out vec4 outcol)
-{
- float cmax, cmin, h, s, v, cdelta;
- vec3 c;
-
- cmax = max(rgb[0], max(rgb[1], rgb[2]));
- cmin = min(rgb[0], min(rgb[1], rgb[2]));
- cdelta = cmax - cmin;
-
- v = cmax;
- if (cmax != 0.0) {
- s = cdelta / cmax;
- }
- else {
- s = 0.0;
- h = 0.0;
- }
-
- if (s == 0.0) {
- h = 0.0;
- }
- else {
- c = (vec3(cmax) - rgb.xyz) / cdelta;
-
- if (rgb.x == cmax) {
- h = c[2] - c[1];
- }
- else if (rgb.y == cmax) {
- h = 2.0 + c[0] - c[2];
- }
- else {
- h = 4.0 + c[1] - c[0];
- }
-
- h /= 6.0;
-
- if (h < 0.0) {
- h += 1.0;
- }
- }
-
- outcol = vec4(h, s, v, rgb.w);
-}
-
-void hsv_to_rgb(vec4 hsv, out vec4 outcol)
-{
- float i, f, p, q, t, h, s, v;
- vec3 rgb;
-
- h = hsv[0];
- s = hsv[1];
- v = hsv[2];
-
- if (s == 0.0) {
- rgb = vec3(v, v, v);
- }
- else {
- if (h == 1.0) {
- h = 0.0;
- }
-
- h *= 6.0;
- i = floor(h);
- f = h - i;
- rgb = vec3(f, f, f);
- p = v * (1.0 - s);
- q = v * (1.0 - (s * f));
- t = v * (1.0 - (s * (1.0 - f)));
-
- if (i == 0.0) {
- rgb = vec3(v, t, p);
- }
- else if (i == 1.0) {
- rgb = vec3(q, v, p);
- }
- else if (i == 2.0) {
- rgb = vec3(p, v, t);
- }
- else if (i == 3.0) {
- rgb = vec3(p, q, v);
- }
- else if (i == 4.0) {
- rgb = vec3(t, p, v);
- }
- else {
- rgb = vec3(v, p, q);
- }
- }
-
- outcol = vec4(rgb, hsv.w);
-}
-
-void rgb_to_hsl(vec4 rgb, out vec4 outcol)
-{
- float cmax, cmin, h, s, l;
-
- cmax = max(rgb[0], max(rgb[1], rgb[2]));
- cmin = min(rgb[0], min(rgb[1], rgb[2]));
- l = min(1.0, (cmax + cmin) / 2.0);
-
- if (cmax == cmin) {
- h = s = 0.0; /* achromatic */
- }
- else {
- float cdelta = cmax - cmin;
- s = l > 0.5 ? cdelta / (2.0 - cmax - cmin) : cdelta / (cmax + cmin);
- if (cmax == rgb[0]) {
- h = (rgb[1] - rgb[2]) / cdelta + (rgb[1] < rgb[2] ? 6.0 : 0.0);
- }
- else if (cmax == rgb[1]) {
- h = (rgb[2] - rgb[0]) / cdelta + 2.0;
- }
- else {
- h = (rgb[0] - rgb[1]) / cdelta + 4.0;
- }
- }
- h /= 6.0;
-
- outcol = vec4(h, s, l, rgb.w);
-}
-
-void hsl_to_rgb(vec4 hsl, out vec4 outcol)
-{
- float nr, ng, nb, chroma, h, s, l;
-
- h = hsl[0];
- s = hsl[1];
- l = hsl[2];
-
- nr = abs(h * 6.0 - 3.0) - 1.0;
- ng = 2.0 - abs(h * 6.0 - 2.0);
- nb = 2.0 - abs(h * 6.0 - 4.0);
-
- nr = clamp(nr, 0.0, 1.0);
- nb = clamp(nb, 0.0, 1.0);
- ng = clamp(ng, 0.0, 1.0);
-
- chroma = (1.0 - abs(2.0 * l - 1.0)) * s;
-
- outcol = vec4((nr - 0.5) * chroma + l, (ng - 0.5) * chroma + l, (nb - 0.5) * chroma + l, hsl.w);
-}
-
-void color_alpha_clear(vec4 color, out vec4 result)
-{
- result = vec4(color.rgb, 1.0);
-}
-
-void color_alpha_premultiply(vec4 color, out vec4 result)
-{
- result = vec4(color.rgb * color.a, 1.0);
-}
-
-void color_alpha_unpremultiply(vec4 color, out vec4 result)
-{
- if (color.a == 0.0 || color.a == 1.0) {
- result = vec4(color.rgb, 1.0);
- }
- else {
- result = vec4(color.rgb / color.a, 1.0);
- }
-}
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_combine_color.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_combine_color.glsl
index 3a250fcae8b..e68d0d98484 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_combine_color.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_combine_color.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_color_util.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)
void combine_color_rgb(float r, float g, float b, out vec4 col)
{
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_combine_hsv.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_combine_hsv.glsl
index e8f444080b9..4d9e16afe66 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_combine_hsv.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_combine_hsv.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_color_util.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)
void combine_hsv(float h, float s, float v, out vec4 col)
{
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_fractal_noise.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_fractal_noise.glsl
index 7f502f74c0c..6d52e97cca1 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_fractal_noise.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_fractal_noise.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_noise.glsl)
/* The fractal_noise functions are all exactly the same except for the input type. */
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_gamma.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_gamma.glsl
index 29fb09ceebd..64681cd795a 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_gamma.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_gamma.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
void node_gamma(vec4 col, float gamma, out vec4 outcol)
{
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_hair_info.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_hair_info.glsl
index a8b4b039370..8e878b6e14b 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_hair_info.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_hair_info.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
void node_hair_info(float hair_length,
out float is_strand,
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_hash.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_hash.glsl
deleted file mode 100644
index 32d61f06a65..00000000000
--- a/source/blender/gpu/shaders/material/gpu_shader_material_hash.glsl
+++ /dev/null
@@ -1,230 +0,0 @@
-/* ***** Jenkins Lookup3 Hash Functions ***** */
-
-/* Source: http://burtleburtle.net/bob/c/lookup3.c */
-
-#define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))
-
-#define mix(a, b, c) \
- { \
- a -= c; \
- a ^= rot(c, 4); \
- c += b; \
- b -= a; \
- b ^= rot(a, 6); \
- a += c; \
- c -= b; \
- c ^= rot(b, 8); \
- b += a; \
- a -= c; \
- a ^= rot(c, 16); \
- c += b; \
- b -= a; \
- b ^= rot(a, 19); \
- a += c; \
- c -= b; \
- c ^= rot(b, 4); \
- b += a; \
- }
-
-#define final(a, b, c) \
- { \
- c ^= b; \
- c -= rot(b, 14); \
- a ^= c; \
- a -= rot(c, 11); \
- b ^= a; \
- b -= rot(a, 25); \
- c ^= b; \
- c -= rot(b, 16); \
- a ^= c; \
- a -= rot(c, 4); \
- b ^= a; \
- b -= rot(a, 14); \
- c ^= b; \
- c -= rot(b, 24); \
- }
-
-uint hash_uint(uint kx)
-{
- uint a, b, c;
- a = b = c = 0xdeadbeefu + (1u << 2u) + 13u;
-
- a += kx;
- final(a, b, c);
-
- return c;
-}
-
-uint hash_uint2(uint kx, uint ky)
-{
- uint a, b, c;
- a = b = c = 0xdeadbeefu + (2u << 2u) + 13u;
-
- b += ky;
- a += kx;
- final(a, b, c);
-
- return c;
-}
-
-uint hash_uint3(uint kx, uint ky, uint kz)
-{
- uint a, b, c;
- a = b = c = 0xdeadbeefu + (3u << 2u) + 13u;
-
- c += kz;
- b += ky;
- a += kx;
- final(a, b, c);
-
- return c;
-}
-
-uint hash_uint4(uint kx, uint ky, uint kz, uint kw)
-{
- uint a, b, c;
- a = b = c = 0xdeadbeefu + (4u << 2u) + 13u;
-
- a += kx;
- b += ky;
- c += kz;
- mix(a, b, c);
-
- a += kw;
- final(a, b, c);
-
- return c;
-}
-
-#undef rot
-#undef final
-#undef mix
-
-uint hash_int(int kx)
-{
- return hash_uint(uint(kx));
-}
-
-uint hash_int2(int kx, int ky)
-{
- return hash_uint2(uint(kx), uint(ky));
-}
-
-uint hash_int3(int kx, int ky, int kz)
-{
- return hash_uint3(uint(kx), uint(ky), uint(kz));
-}
-
-uint hash_int4(int kx, int ky, int kz, int kw)
-{
- return hash_uint4(uint(kx), uint(ky), uint(kz), uint(kw));
-}
-
-/* Hashing uint or uint[234] into a float in the range [0, 1]. */
-
-float hash_uint_to_float(uint kx)
-{
- return float(hash_uint(kx)) / float(0xFFFFFFFFu);
-}
-
-float hash_uint2_to_float(uint kx, uint ky)
-{
- return float(hash_uint2(kx, ky)) / float(0xFFFFFFFFu);
-}
-
-float hash_uint3_to_float(uint kx, uint ky, uint kz)
-{
- return float(hash_uint3(kx, ky, kz)) / float(0xFFFFFFFFu);
-}
-
-float hash_uint4_to_float(uint kx, uint ky, uint kz, uint kw)
-{
- return float(hash_uint4(kx, ky, kz, kw)) / float(0xFFFFFFFFu);
-}
-
-/* Hashing float or vec[234] into a float in the range [0, 1]. */
-
-float hash_float_to_float(float k)
-{
- return hash_uint_to_float(floatBitsToUint(k));
-}
-
-float hash_vec2_to_float(vec2 k)
-{
- return hash_uint2_to_float(floatBitsToUint(k.x), floatBitsToUint(k.y));
-}
-
-float hash_vec3_to_float(vec3 k)
-{
- return hash_uint3_to_float(floatBitsToUint(k.x), floatBitsToUint(k.y), floatBitsToUint(k.z));
-}
-
-float hash_vec4_to_float(vec4 k)
-{
- return hash_uint4_to_float(
- floatBitsToUint(k.x), floatBitsToUint(k.y), floatBitsToUint(k.z), floatBitsToUint(k.w));
-}
-
-/* Hashing vec[234] into vec[234] of components in the range [0, 1]. */
-
-vec2 hash_vec2_to_vec2(vec2 k)
-{
- return vec2(hash_vec2_to_float(k), hash_vec3_to_float(vec3(k, 1.0)));
-}
-
-vec3 hash_vec3_to_vec3(vec3 k)
-{
- return vec3(
- hash_vec3_to_float(k), hash_vec4_to_float(vec4(k, 1.0)), hash_vec4_to_float(vec4(k, 2.0)));
-}
-
-vec4 hash_vec4_to_vec4(vec4 k)
-{
- return vec4(hash_vec4_to_float(k.xyzw),
- hash_vec4_to_float(k.wxyz),
- hash_vec4_to_float(k.zwxy),
- hash_vec4_to_float(k.yzwx));
-}
-
-/* Hashing float or vec[234] into vec3 of components in range [0, 1]. */
-
-vec3 hash_float_to_vec3(float k)
-{
- return vec3(
- hash_float_to_float(k), hash_vec2_to_float(vec2(k, 1.0)), hash_vec2_to_float(vec2(k, 2.0)));
-}
-
-vec3 hash_vec2_to_vec3(vec2 k)
-{
- return vec3(
- hash_vec2_to_float(k), hash_vec3_to_float(vec3(k, 1.0)), hash_vec3_to_float(vec3(k, 2.0)));
-}
-
-vec3 hash_vec4_to_vec3(vec4 k)
-{
- return vec3(hash_vec4_to_float(k.xyzw), hash_vec4_to_float(k.zxwy), hash_vec4_to_float(k.wzyx));
-}
-
-/* Other Hash Functions */
-
-float integer_noise(int n)
-{
- /* Integer bit-shifts for these calculations can cause precision problems on macOS.
- * Using uint resolves these issues. */
- uint nn;
- nn = (uint(n) + 1013u) & 0x7fffffffu;
- nn = (nn >> 13u) ^ nn;
- nn = (uint(nn * (nn * nn * 60493u + 19990303u)) + 1376312589u) & 0x7fffffffu;
- return 0.5 * (float(nn) / 1073741824.0);
-}
-
-float wang_hash_noise(uint s)
-{
- s = (s ^ 61u) ^ (s >> 16u);
- s *= 9u;
- s = s ^ (s >> 4u);
- s *= 0x27d4eb2du;
- s = s ^ (s >> 15u);
-
- return fract(float(s) / 4294967296.0);
-}
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_hue_sat_val.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_hue_sat_val.glsl
index 30b808508e9..5223828e176 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_hue_sat_val.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_hue_sat_val.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_color_util.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)
void hue_sat(float hue, float sat, float value, float fac, vec4 col, out vec4 outcol)
{
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_map_range.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_map_range.glsl
index 119ee3c0eaa..a81e6d36a55 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_map_range.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_map_range.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
float smootherstep(float edge0, float edge1, float x)
{
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_mapping.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_mapping.glsl
index 312c57231c5..b59257506c9 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_mapping.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_mapping.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
void mapping_mat4(
vec3 vec, vec4 m0, vec4 m1, vec4 m2, vec4 m3, vec3 minvec, vec3 maxvec, out vec3 outvec)
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_math.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_math.glsl
deleted file mode 100644
index 0948ce2c9fa..00000000000
--- a/source/blender/gpu/shaders/material/gpu_shader_material_math.glsl
+++ /dev/null
@@ -1,221 +0,0 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
-
-void math_add(float a, float b, float c, out float result)
-{
- result = a + b;
-}
-
-void math_subtract(float a, float b, float c, out float result)
-{
- result = a - b;
-}
-
-void math_multiply(float a, float b, float c, out float result)
-{
- result = a * b;
-}
-
-void math_divide(float a, float b, float c, out float result)
-{
- result = safe_divide(a, b);
-}
-
-void math_power(float a, float b, float c, out float result)
-{
- if (a >= 0.0) {
- result = compatible_pow(a, b);
- }
- else {
- float fraction = mod(abs(b), 1.0);
- if (fraction > 0.999 || fraction < 0.001) {
- result = compatible_pow(a, floor(b + 0.5));
- }
- else {
- result = 0.0;
- }
- }
-}
-
-void math_logarithm(float a, float b, float c, out float result)
-{
- result = (a > 0.0 && b > 0.0) ? log2(a) / log2(b) : 0.0;
-}
-
-void math_sqrt(float a, float b, float c, out float result)
-{
- result = (a > 0.0) ? sqrt(a) : 0.0;
-}
-
-void math_inversesqrt(float a, float b, float c, out float result)
-{
- result = inversesqrt(a);
-}
-
-void math_absolute(float a, float b, float c, out float result)
-{
- result = abs(a);
-}
-
-void math_radians(float a, float b, float c, out float result)
-{
- result = radians(a);
-}
-
-void math_degrees(float a, float b, float c, out float result)
-{
- result = degrees(a);
-}
-
-void math_minimum(float a, float b, float c, out float result)
-{
- result = min(a, b);
-}
-
-void math_maximum(float a, float b, float c, out float result)
-{
- result = max(a, b);
-}
-
-void math_less_than(float a, float b, float c, out float result)
-{
- result = (a < b) ? 1.0 : 0.0;
-}
-
-void math_greater_than(float a, float b, float c, out float result)
-{
- result = (a > b) ? 1.0 : 0.0;
-}
-
-void math_round(float a, float b, float c, out float result)
-{
- result = floor(a + 0.5);
-}
-
-void math_floor(float a, float b, float c, out float result)
-{
- result = floor(a);
-}
-
-void math_ceil(float a, float b, float c, out float result)
-{
- result = ceil(a);
-}
-
-void math_fraction(float a, float b, float c, out float result)
-{
- result = a - floor(a);
-}
-
-void math_modulo(float a, float b, float c, out float result)
-{
- result = compatible_fmod(a, b);
-}
-
-void math_trunc(float a, float b, float c, out float result)
-{
- result = trunc(a);
-}
-
-void math_snap(float a, float b, float c, out float result)
-{
- result = floor(safe_divide(a, b)) * b;
-}
-
-void math_pingpong(float a, float b, float c, out float result)
-{
- result = (b != 0.0) ? abs(fract((a - b) / (b * 2.0)) * b * 2.0 - b) : 0.0;
-}
-
-/* Adapted from godotengine math_funcs.h. */
-void math_wrap(float a, float b, float c, out float result)
-{
- result = wrap(a, b, c);
-}
-
-void math_sine(float a, float b, float c, out float result)
-{
- result = sin(a);
-}
-
-void math_cosine(float a, float b, float c, out float result)
-{
- result = cos(a);
-}
-
-void math_tangent(float a, float b, float c, out float result)
-{
- result = tan(a);
-}
-
-void math_sinh(float a, float b, float c, out float result)
-{
- result = sinh(a);
-}
-
-void math_cosh(float a, float b, float c, out float result)
-{
- result = cosh(a);
-}
-
-void math_tanh(float a, float b, float c, out float result)
-{
- result = tanh(a);
-}
-
-void math_arcsine(float a, float b, float c, out float result)
-{
- result = (a <= 1.0 && a >= -1.0) ? asin(a) : 0.0;
-}
-
-void math_arccosine(float a, float b, float c, out float result)
-{
- result = (a <= 1.0 && a >= -1.0) ? acos(a) : 0.0;
-}
-
-void math_arctangent(float a, float b, float c, out float result)
-{
- result = atan(a);
-}
-
-void math_arctan2(float a, float b, float c, out float result)
-{
- result = atan(a, b);
-}
-
-void math_sign(float a, float b, float c, out float result)
-{
- result = sign(a);
-}
-
-void math_exponent(float a, float b, float c, out float result)
-{
- result = exp(a);
-}
-
-void math_compare(float a, float b, float c, out float result)
-{
- result = (abs(a - b) <= max(c, 1e-5)) ? 1.0 : 0.0;
-}
-
-void math_multiply_add(float a, float b, float c, out float result)
-{
- result = a * b + c;
-}
-
-/* See: https://www.iquilezles.org/www/articles/smin/smin.htm. */
-void math_smoothmin(float a, float b, float c, out float result)
-{
- if (c != 0.0) {
- float h = max(c - abs(a - b), 0.0) / c;
- result = min(a, b) - h * h * h * c * (1.0 / 6.0);
- }
- else {
- result = min(a, b);
- }
-}
-
-void math_smoothmax(float a, float b, float c, out float result)
-{
- math_smoothmin(-a, -b, c, result);
- result = -result;
-}
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl
deleted file mode 100644
index 91a8996939a..00000000000
--- a/source/blender/gpu/shaders/material/gpu_shader_material_math_util.glsl
+++ /dev/null
@@ -1,213 +0,0 @@
-/* Float Math */
-
-float safe_divide(float a, float b)
-{
- return (b != 0.0) ? a / b : 0.0;
-}
-
-/* fmod function compatible with OSL using nvidia reference example. */
-float compatible_fmod(float a, float b)
-{
- float c = (b != 0.0) ? fract(abs(a / b)) * abs(b) : 0.0;
- return (a < 0.0) ? -c : c;
-}
-
-float compatible_pow(float x, float y)
-{
- if (y == 0.0) { /* x^0 -> 1, including 0^0 */
- return 1.0;
- }
-
- /* glsl pow doesn't accept negative x */
- if (x < 0.0) {
- if (mod(-y, 2.0) == 0.0) {
- return pow(-x, y);
- }
- else {
- return -pow(-x, y);
- }
- }
- else if (x == 0.0) {
- return 0.0;
- }
-
- return pow(x, y);
-}
-
-float wrap(float a, float b, float c)
-{
- float range = b - c;
- return (range != 0.0) ? a - (range * floor((a - c) / range)) : c;
-}
-
-vec3 wrap(vec3 a, vec3 b, vec3 c)
-{
- return vec3(wrap(a.x, b.x, c.x), wrap(a.y, b.y, c.y), wrap(a.z, b.z, c.z));
-}
-
-float hypot(float x, float y)
-{
- return sqrt(x * x + y * y);
-}
-
-int floor_to_int(float x)
-{
- return int(floor(x));
-}
-
-int quick_floor(float x)
-{
- return int(x) - ((x < 0) ? 1 : 0);
-}
-
-/* Vector Math */
-
-vec2 safe_divide(vec2 a, vec2 b)
-{
- return vec2(safe_divide(a.x, b.x), safe_divide(a.y, b.y));
-}
-
-vec3 safe_divide(vec3 a, vec3 b)
-{
- return vec3(safe_divide(a.x, b.x), safe_divide(a.y, b.y), safe_divide(a.z, b.z));
-}
-
-vec4 safe_divide(vec4 a, vec4 b)
-{
- return vec4(
- safe_divide(a.x, b.x), safe_divide(a.y, b.y), safe_divide(a.z, b.z), safe_divide(a.w, b.w));
-}
-
-vec2 safe_divide(vec2 a, float b)
-{
- return (b != 0.0) ? a / b : vec2(0.0);
-}
-
-vec3 safe_divide(vec3 a, float b)
-{
- return (b != 0.0) ? a / b : vec3(0.0);
-}
-
-vec4 safe_divide(vec4 a, float b)
-{
- return (b != 0.0) ? a / b : vec4(0.0);
-}
-
-vec3 compatible_fmod(vec3 a, vec3 b)
-{
- return vec3(compatible_fmod(a.x, b.x), compatible_fmod(a.y, b.y), compatible_fmod(a.z, b.z));
-}
-
-void invert_z(vec3 v, out vec3 outv)
-{
- v.z = -v.z;
- outv = v;
-}
-
-void vector_normalize(vec3 normal, out vec3 outnormal)
-{
- outnormal = normalize(normal);
-}
-
-void vector_copy(vec3 normal, out vec3 outnormal)
-{
- outnormal = normal;
-}
-
-/* Matirx Math */
-
-mat3 euler_to_mat3(vec3 euler)
-{
- float cx = cos(euler.x);
- float cy = cos(euler.y);
- float cz = cos(euler.z);
- float sx = sin(euler.x);
- float sy = sin(euler.y);
- float sz = sin(euler.z);
-
- mat3 mat;
- mat[0][0] = cy * cz;
- mat[0][1] = cy * sz;
- mat[0][2] = -sy;
-
- mat[1][0] = sy * sx * cz - cx * sz;
- mat[1][1] = sy * sx * sz + cx * cz;
- mat[1][2] = cy * sx;
-
- mat[2][0] = sy * cx * cz + sx * sz;
- mat[2][1] = sy * cx * sz - sx * cz;
- mat[2][2] = cy * cx;
- return mat;
-}
-
-void normal_transform_object_to_world(vec3 vin, out vec3 vout)
-{
- vout = normal_object_to_world(vin);
-}
-
-void normal_transform_world_to_object(vec3 vin, out vec3 vout)
-{
- vout = normal_world_to_object(vin);
-}
-
-void direction_transform_object_to_world(vec3 vin, out vec3 vout)
-{
- vout = transform_direction(ModelMatrix, vin);
-}
-
-void direction_transform_object_to_view(vec3 vin, out vec3 vout)
-{
- vout = transform_direction(ModelMatrix, vin);
- vout = transform_direction(ViewMatrix, vout);
-}
-
-void direction_transform_view_to_world(vec3 vin, out vec3 vout)
-{
- vout = transform_direction(ViewMatrixInverse, vin);
-}
-
-void direction_transform_view_to_object(vec3 vin, out vec3 vout)
-{
- vout = transform_direction(ViewMatrixInverse, vin);
- vout = transform_direction(ModelMatrixInverse, vout);
-}
-
-void direction_transform_world_to_view(vec3 vin, out vec3 vout)
-{
- vout = transform_direction(ViewMatrix, vin);
-}
-
-void direction_transform_world_to_object(vec3 vin, out vec3 vout)
-{
- vout = transform_direction(ModelMatrixInverse, vin);
-}
-
-void point_transform_object_to_world(vec3 vin, out vec3 vout)
-{
- vout = point_object_to_world(vin);
-}
-
-void point_transform_object_to_view(vec3 vin, out vec3 vout)
-{
- vout = point_object_to_view(vin);
-}
-
-void point_transform_view_to_world(vec3 vin, out vec3 vout)
-{
- vout = point_view_to_world(vin);
-}
-
-void point_transform_view_to_object(vec3 vin, out vec3 vout)
-{
- vout = point_view_to_object(vin);
-}
-
-void point_transform_world_to_view(vec3 vin, out vec3 vout)
-{
- vout = point_world_to_view(vin);
-}
-
-void point_transform_world_to_object(vec3 vin, out vec3 vout)
-{
- vout = point_world_to_object(vin);
-}
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_mix_rgb.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_mix_rgb.glsl
deleted file mode 100644
index 157a6a27c15..00000000000
--- a/source/blender/gpu/shaders/material/gpu_shader_material_mix_rgb.glsl
+++ /dev/null
@@ -1,293 +0,0 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_color_util.glsl)
-
-void mix_blend(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- outcol = mix(col1, col2, fac);
- outcol.a = col1.a;
-}
-
-void mix_add(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- outcol = mix(col1, col1 + col2, fac);
- outcol.a = col1.a;
-}
-
-void mix_mult(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- outcol = mix(col1, col1 * col2, fac);
- outcol.a = col1.a;
-}
-
-void mix_screen(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
-
- outcol = vec4(1.0) - (vec4(facm) + fac * (vec4(1.0) - col2)) * (vec4(1.0) - col1);
- outcol.a = col1.a;
-}
-
-void mix_overlay(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
-
- outcol = col1;
-
- if (outcol.r < 0.5) {
- outcol.r *= facm + 2.0 * fac * col2.r;
- }
- else {
- outcol.r = 1.0 - (facm + 2.0 * fac * (1.0 - col2.r)) * (1.0 - outcol.r);
- }
-
- if (outcol.g < 0.5) {
- outcol.g *= facm + 2.0 * fac * col2.g;
- }
- else {
- outcol.g = 1.0 - (facm + 2.0 * fac * (1.0 - col2.g)) * (1.0 - outcol.g);
- }
-
- if (outcol.b < 0.5) {
- outcol.b *= facm + 2.0 * fac * col2.b;
- }
- else {
- outcol.b = 1.0 - (facm + 2.0 * fac * (1.0 - col2.b)) * (1.0 - outcol.b);
- }
-}
-
-void mix_sub(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- outcol = mix(col1, col1 - col2, fac);
- outcol.a = col1.a;
-}
-
-void mix_div(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
-
- outcol = col1;
-
- if (col2.r != 0.0) {
- outcol.r = facm * outcol.r + fac * outcol.r / col2.r;
- }
- if (col2.g != 0.0) {
- outcol.g = facm * outcol.g + fac * outcol.g / col2.g;
- }
- if (col2.b != 0.0) {
- outcol.b = facm * outcol.b + fac * outcol.b / col2.b;
- }
-}
-
-void mix_diff(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- outcol = mix(col1, abs(col1 - col2), fac);
- outcol.a = col1.a;
-}
-
-void mix_dark(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- outcol.rgb = mix(col1.rgb, min(col1.rgb, col2.rgb), fac);
- outcol.a = col1.a;
-}
-
-void mix_light(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- outcol.rgb = mix(col1.rgb, max(col1.rgb, col2.rgb), fac);
- outcol.a = col1.a;
-}
-
-void mix_dodge(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- outcol = col1;
-
- if (outcol.r != 0.0) {
- float tmp = 1.0 - fac * col2.r;
- if (tmp <= 0.0) {
- outcol.r = 1.0;
- }
- else if ((tmp = outcol.r / tmp) > 1.0) {
- outcol.r = 1.0;
- }
- else {
- outcol.r = tmp;
- }
- }
- if (outcol.g != 0.0) {
- float tmp = 1.0 - fac * col2.g;
- if (tmp <= 0.0) {
- outcol.g = 1.0;
- }
- else if ((tmp = outcol.g / tmp) > 1.0) {
- outcol.g = 1.0;
- }
- else {
- outcol.g = tmp;
- }
- }
- if (outcol.b != 0.0) {
- float tmp = 1.0 - fac * col2.b;
- if (tmp <= 0.0) {
- outcol.b = 1.0;
- }
- else if ((tmp = outcol.b / tmp) > 1.0) {
- outcol.b = 1.0;
- }
- else {
- outcol.b = tmp;
- }
- }
-}
-
-void mix_burn(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- float tmp, facm = 1.0 - fac;
-
- outcol = col1;
-
- tmp = facm + fac * col2.r;
- if (tmp <= 0.0) {
- outcol.r = 0.0;
- }
- else if ((tmp = (1.0 - (1.0 - outcol.r) / tmp)) < 0.0) {
- outcol.r = 0.0;
- }
- else if (tmp > 1.0) {
- outcol.r = 1.0;
- }
- else {
- outcol.r = tmp;
- }
-
- tmp = facm + fac * col2.g;
- if (tmp <= 0.0) {
- outcol.g = 0.0;
- }
- else if ((tmp = (1.0 - (1.0 - outcol.g) / tmp)) < 0.0) {
- outcol.g = 0.0;
- }
- else if (tmp > 1.0) {
- outcol.g = 1.0;
- }
- else {
- outcol.g = tmp;
- }
-
- tmp = facm + fac * col2.b;
- if (tmp <= 0.0) {
- outcol.b = 0.0;
- }
- else if ((tmp = (1.0 - (1.0 - outcol.b) / tmp)) < 0.0) {
- outcol.b = 0.0;
- }
- else if (tmp > 1.0) {
- outcol.b = 1.0;
- }
- else {
- outcol.b = tmp;
- }
-}
-
-void mix_hue(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
-
- outcol = col1;
-
- vec4 hsv, hsv2, tmp;
- rgb_to_hsv(col2, hsv2);
-
- if (hsv2.y != 0.0) {
- rgb_to_hsv(outcol, hsv);
- hsv.x = hsv2.x;
- hsv_to_rgb(hsv, tmp);
-
- outcol = mix(outcol, tmp, fac);
- outcol.a = col1.a;
- }
-}
-
-void mix_sat(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
-
- outcol = col1;
-
- vec4 hsv, hsv2;
- rgb_to_hsv(outcol, hsv);
-
- if (hsv.y != 0.0) {
- rgb_to_hsv(col2, hsv2);
-
- hsv.y = facm * hsv.y + fac * hsv2.y;
- hsv_to_rgb(hsv, outcol);
- }
-}
-
-void mix_val(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
-
- vec4 hsv, hsv2;
- rgb_to_hsv(col1, hsv);
- rgb_to_hsv(col2, hsv2);
-
- hsv.z = facm * hsv.z + fac * hsv2.z;
- hsv_to_rgb(hsv, outcol);
-}
-
-void mix_color(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
-
- outcol = col1;
-
- vec4 hsv, hsv2, tmp;
- rgb_to_hsv(col2, hsv2);
-
- if (hsv2.y != 0.0) {
- rgb_to_hsv(outcol, hsv);
- hsv.x = hsv2.x;
- hsv.y = hsv2.y;
- hsv_to_rgb(hsv, tmp);
-
- outcol = mix(outcol, tmp, fac);
- outcol.a = col1.a;
- }
-}
-
-void mix_soft(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
- float facm = 1.0 - fac;
-
- vec4 one = vec4(1.0);
- vec4 scr = one - (one - col2) * (one - col1);
- outcol = facm * col1 + fac * ((one - col1) * col2 * col1 + col1 * scr);
-}
-
-void mix_linear(float fac, vec4 col1, vec4 col2, out vec4 outcol)
-{
- fac = clamp(fac, 0.0, 1.0);
-
- outcol = col1 + fac * (2.0 * (col2 - vec4(0.5)));
-}
-
-void clamp_color(vec3 vec, vec3 min, vec3 max, out vec3 out_vec)
-{
- out_vec = clamp(vec, min, max);
-}
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_noise.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_noise.glsl
index c84f34a834c..881e38ea11a 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_noise.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_noise.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
/* clang-format off */
#define FLOORFRAC(x, x_int, x_fract) { float x_floor = floor(x); x_int = int(x_floor); x_fract = x - x_floor; }
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_point_info.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_point_info.glsl
index ad3d4737193..251103ae57c 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_point_info.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_point_info.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
void node_point_info(out vec3 position, out float radius, out float random)
{
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_separate_color.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_separate_color.glsl
index 7425e53ce7b..2dd51029cef 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_separate_color.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_separate_color.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_color_util.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)
void separate_color_rgb(vec4 col, out float r, out float g, out float b)
{
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_separate_hsv.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_separate_hsv.glsl
index 180e0fd1940..8e475ec39a7 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_separate_hsv.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_separate_hsv.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_color_util.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_color_utils.glsl)
void separate_hsv(vec4 col, out float h, out float s, out float v)
{
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_tex_brick.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_tex_brick.glsl
index edc2fa32177..8d9773913ff 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_tex_brick.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_tex_brick.glsl
@@ -1,5 +1,5 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
-#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
vec2 calc_brick_texture(vec3 p,
float mortar_size,
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_tex_environment.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_tex_environment.glsl
index da131978f72..cf7d6ae18e6 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_tex_environment.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_tex_environment.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
void node_tex_environment_equirectangular(vec3 co, out vec3 uv)
{
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_tex_musgrave.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_tex_musgrave.glsl
index 1552a2facc3..961fe23e67e 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_tex_musgrave.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_tex_musgrave.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_noise.glsl)
/* 1D Musgrave fBm
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_tex_noise.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_tex_noise.glsl
index c90b2211dcf..3df6f7b29fb 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_tex_noise.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_tex_noise.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_noise.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_fractal_noise.glsl)
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_tex_voronoi.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_tex_voronoi.glsl
index dd12b602edf..0fb8ef15f5f 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_tex_voronoi.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_tex_voronoi.glsl
@@ -1,5 +1,5 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
-#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
/*
* Original code is under the MIT License, Copyright (c) 2013 Inigo Quilez.
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_tex_wave.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_tex_wave.glsl
index eed98232d0b..c24a9417219 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_tex_wave.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_tex_wave.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_noise.glsl)
#pragma BLENDER_REQUIRE(gpu_shader_material_fractal_noise.glsl)
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_tex_white_noise.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_tex_white_noise.glsl
index 030b58f0736..c5081372aa4 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_tex_white_noise.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_tex_white_noise.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_hash.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_hash.glsl)
/* White Noise */
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_transform_utils.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_transform_utils.glsl
new file mode 100644
index 00000000000..87048e5c5d6
--- /dev/null
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_transform_utils.glsl
@@ -0,0 +1,71 @@
+void normal_transform_object_to_world(vec3 vin, out vec3 vout)
+{
+ vout = normal_object_to_world(vin);
+}
+
+void normal_transform_world_to_object(vec3 vin, out vec3 vout)
+{
+ vout = normal_world_to_object(vin);
+}
+
+void direction_transform_object_to_world(vec3 vin, out vec3 vout)
+{
+ vout = transform_direction(ModelMatrix, vin);
+}
+
+void direction_transform_object_to_view(vec3 vin, out vec3 vout)
+{
+ vout = transform_direction(ModelMatrix, vin);
+ vout = transform_direction(ViewMatrix, vout);
+}
+
+void direction_transform_view_to_world(vec3 vin, out vec3 vout)
+{
+ vout = transform_direction(ViewMatrixInverse, vin);
+}
+
+void direction_transform_view_to_object(vec3 vin, out vec3 vout)
+{
+ vout = transform_direction(ViewMatrixInverse, vin);
+ vout = transform_direction(ModelMatrixInverse, vout);
+}
+
+void direction_transform_world_to_view(vec3 vin, out vec3 vout)
+{
+ vout = transform_direction(ViewMatrix, vin);
+}
+
+void direction_transform_world_to_object(vec3 vin, out vec3 vout)
+{
+ vout = transform_direction(ModelMatrixInverse, vin);
+}
+
+void point_transform_object_to_world(vec3 vin, out vec3 vout)
+{
+ vout = point_object_to_world(vin);
+}
+
+void point_transform_object_to_view(vec3 vin, out vec3 vout)
+{
+ vout = point_object_to_view(vin);
+}
+
+void point_transform_view_to_world(vec3 vin, out vec3 vout)
+{
+ vout = point_view_to_world(vin);
+}
+
+void point_transform_view_to_object(vec3 vin, out vec3 vout)
+{
+ vout = point_view_to_object(vin);
+}
+
+void point_transform_world_to_view(vec3 vin, out vec3 vout)
+{
+ vout = point_world_to_view(vin);
+}
+
+void point_transform_world_to_object(vec3 vin, out vec3 vout)
+{
+ vout = point_world_to_object(vin);
+}
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl
index 8f6bf17f195..018784c42a5 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_vector_math.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
void vector_math_add(vec3 a, vec3 b, vec3 c, float scale, out vec3 outVector, out float outValue)
{
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_vector_rotate.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_vector_rotate.glsl
index ff0fb1c0418..8f7bd26ca18 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_vector_rotate.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_vector_rotate.glsl
@@ -1,4 +1,4 @@
-#pragma BLENDER_REQUIRE(gpu_shader_material_math_util.glsl)
+#pragma BLENDER_REQUIRE(gpu_shader_common_math_utils.glsl)
vec3 rotate_around_axis(vec3 p, vec3 axis, float angle)
{