Files
test2/source/blender/gpu/shaders/material/gpu_shader_material_mapping.glsl
Omar Emara 6365110312 Cleanup: GPU: Remove common_math.glsl includes
This patch refactors GPU shaders to remove includes to the utility
gpu_shader_common_math.glsl file. This is done because it has duplicate
functions that exist in other files, and it was really created for use
in GPU material nodes.

The safe_divide and hypot functions were removed since they exist in
gpu_shader_math_base_lib.glsl.

The compatible_[mod|pow] and wrap functions were moved into
gpu_shader_math_base_lib.glsl.

The floor_to_int function was inlined since it was trivial and only used
in one place.

The quick_floor was removed because it was unused.

The euler_to_mat3 function was replaced with the from_rotation function
from gpu_shader_math_matrix_lib.glsl.

Now the file only contains some GPU material node utility functions.

Pull Request: https://projects.blender.org/blender/blender/pulls/135160
2025-02-26 13:37:20 +01:00

37 lines
1.2 KiB
GLSL

/* SPDX-FileCopyrightText: 2019-2022 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "gpu_shader_math_matrix_lib.glsl"
#include "gpu_shader_math_rotation_lib.glsl"
#include "gpu_shader_math_vector_lib.glsl"
void mapping_mat4(
vec3 vec, vec4 m0, vec4 m1, vec4 m2, vec4 m3, vec3 minvec, vec3 maxvec, out vec3 outvec)
{
mat4 mat = mat4(m0, m1, m2, m3);
outvec = (mat * vec4(vec, 1.0)).xyz;
outvec = clamp(outvec, minvec, maxvec);
}
void mapping_point(vec3 vector, vec3 location, vec3 rotation, vec3 scale, out vec3 result)
{
result = (from_rotation(as_EulerXYZ(rotation)) * (vector * scale)) + location;
}
void mapping_texture(vec3 vector, vec3 location, vec3 rotation, vec3 scale, out vec3 result)
{
result = safe_divide(transpose(from_rotation(as_EulerXYZ(rotation))) * (vector - location),
scale);
}
void mapping_vector(vec3 vector, vec3 location, vec3 rotation, vec3 scale, out vec3 result)
{
result = from_rotation(as_EulerXYZ(rotation)) * (vector * scale);
}
void mapping_normal(vec3 vector, vec3 location, vec3 rotation, vec3 scale, out vec3 result)
{
result = normalize(from_rotation(as_EulerXYZ(rotation)) * safe_divide(vector, scale));
}