Files
test/source/blender/gpu/shaders/material/gpu_shader_material_mapping.glsl
Clément Foucault 3b3a5731df GPU: Shader: Change vector and matrix type to use blender convention
This unify the C++ and GLSL codebase style.

The GLSL types are still in the backend compatibility
layers to support python shaders. However, the C++
shader compilation layer doesn't have them to enforce
correct type usage.

Note that this is going to break pretty much all PRs
in flight that targets shader code.

Rel #137261

Pull Request: https://projects.blender.org/blender/blender/pulls/137369
2025-04-14 13:46:41 +02:00

47 lines
1.4 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(float3 vec,
float4 m0,
float4 m1,
float4 m2,
float4 m3,
float3 minvec,
float3 maxvec,
out float3 outvec)
{
float4x4 mat = float4x4(m0, m1, m2, m3);
outvec = (mat * float4(vec, 1.0f)).xyz;
outvec = clamp(outvec, minvec, maxvec);
}
void mapping_point(
float3 vector, float3 location, float3 rotation, float3 scale, out float3 result)
{
result = (from_rotation(as_EulerXYZ(rotation)) * (vector * scale)) + location;
}
void mapping_texture(
float3 vector, float3 location, float3 rotation, float3 scale, out float3 result)
{
result = safe_divide(transpose(from_rotation(as_EulerXYZ(rotation))) * (vector - location),
scale);
}
void mapping_vector(
float3 vector, float3 location, float3 rotation, float3 scale, out float3 result)
{
result = from_rotation(as_EulerXYZ(rotation)) * (vector * scale);
}
void mapping_normal(
float3 vector, float3 location, float3 rotation, float3 scale, out float3 result)
{
result = normalize(from_rotation(as_EulerXYZ(rotation)) * safe_divide(vector, scale));
}