diff options
author | Charlie Jolly <charlie> | 2020-02-17 18:15:46 +0300 |
---|---|---|
committer | Charlie Jolly <mistajolly@gmail.com> | 2020-02-17 18:43:18 +0300 |
commit | 20a4cdfd700d3722fdcaa3b3952ccea1b0e6ee47 (patch) | |
tree | 16eee69e8e1d3bdfb902e05df15b055f7141fd4d /source/blender/gpu | |
parent | ab3a6e050c856345d10f8e36155913288559e4dc (diff) |
Cycles: Vector Rotate Node using Axis and Angle method
This node provides the ability to rotate a vector around a `center` point using either `Axis Angle` , `Single Axis` or `Euler` methods.
Reviewed By: #cycles, brecht
Differential Revision: https://developer.blender.org/D3789
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_material_library.c | 8 | ||||
-rw-r--r-- | source/blender/gpu/shaders/material/gpu_shader_material_vector_rotate.glsl | 82 |
3 files changed, 90 insertions, 1 deletions
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index 0ab3e775566..8a900938d2a 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -303,6 +303,7 @@ data_to_c_simple(shaders/material/gpu_shader_material_uv_map.glsl SRC) data_to_c_simple(shaders/material/gpu_shader_material_vector_curves.glsl SRC) data_to_c_simple(shaders/material/gpu_shader_material_vector_displacement.glsl SRC) data_to_c_simple(shaders/material/gpu_shader_material_vector_math.glsl SRC) +data_to_c_simple(shaders/material/gpu_shader_material_vector_rotate.glsl SRC) data_to_c_simple(shaders/material/gpu_shader_material_velvet.glsl SRC) data_to_c_simple(shaders/material/gpu_shader_material_vertex_color.glsl SRC) data_to_c_simple(shaders/material/gpu_shader_material_volume_absorption.glsl SRC) diff --git a/source/blender/gpu/intern/gpu_material_library.c b/source/blender/gpu/intern/gpu_material_library.c index e7ec1bb12a2..959e5ef7440 100644 --- a/source/blender/gpu/intern/gpu_material_library.c +++ b/source/blender/gpu/intern/gpu_material_library.c @@ -119,6 +119,7 @@ extern char datatoc_gpu_shader_material_uv_map_glsl[]; extern char datatoc_gpu_shader_material_vector_curves_glsl[]; extern char datatoc_gpu_shader_material_vector_displacement_glsl[]; extern char datatoc_gpu_shader_material_vector_math_glsl[]; +extern char datatoc_gpu_shader_material_vector_rotate_glsl[]; extern char datatoc_gpu_shader_material_velvet_glsl[]; extern char datatoc_gpu_shader_material_vertex_color_glsl[]; extern char datatoc_gpu_shader_material_volume_absorption_glsl[]; @@ -527,6 +528,11 @@ static GPUMaterialLibrary gpu_shader_material_vector_math_library = { .dependencies = {&gpu_shader_material_math_util_library, NULL}, }; +static GPUMaterialLibrary gpu_shader_material_vector_rotate_library = { + .code = datatoc_gpu_shader_material_vector_rotate_glsl, + .dependencies = {&gpu_shader_material_math_util_library, NULL}, +}; + static GPUMaterialLibrary gpu_shader_material_velvet_library = { .code = datatoc_gpu_shader_material_velvet_glsl, .dependencies = {&gpu_shader_material_diffuse_library, NULL}, @@ -647,6 +653,7 @@ static GPUMaterialLibrary *gpu_material_libraries[] = { &gpu_shader_material_vector_curves_library, &gpu_shader_material_vector_displacement_library, &gpu_shader_material_vector_math_library, + &gpu_shader_material_vector_rotate_library, &gpu_shader_material_velvet_library, &gpu_shader_material_vertex_color_library, &gpu_shader_material_volume_absorption_library, @@ -879,4 +886,3 @@ char *gpu_material_library_generate_code(GSet *used_libraries, const char *frag_ return result; } - 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 new file mode 100644 index 00000000000..7d707706a03 --- /dev/null +++ b/source/blender/gpu/shaders/material/gpu_shader_material_vector_rotate.glsl @@ -0,0 +1,82 @@ +vec3 rotate_around_axis(vec3 p, vec3 axis, float angle) +{ + float costheta = cos(angle); + float sintheta = sin(angle); + vec3 r; + + r.x = ((costheta + (1.0 - costheta) * axis.x * axis.x) * p.x) + + (((1.0 - costheta) * axis.x * axis.y - axis.z * sintheta) * p.y) + + (((1.0 - costheta) * axis.x * axis.z + axis.y * sintheta) * p.z); + + r.y = (((1.0 - costheta) * axis.x * axis.y + axis.z * sintheta) * p.x) + + ((costheta + (1.0 - costheta) * axis.y * axis.y) * p.y) + + (((1.0 - costheta) * axis.y * axis.z - axis.x * sintheta) * p.z); + + r.z = (((1.0 - costheta) * axis.x * axis.z - axis.y * sintheta) * p.x) + + (((1.0 - costheta) * axis.y * axis.z + axis.x * sintheta) * p.y) + + ((costheta + (1.0 - costheta) * axis.z * axis.z) * p.z); + + return r; +} + +void node_vector_rotate_axis_angle( + vec3 vector_in, vec3 center, vec3 axis, float angle, vec3 rotation, out vec3 vec) +{ + vec = (length(axis) != 0.0) ? + rotate_around_axis(vector_in - center, normalize(axis), angle) + center : + vector_in; +} + +void node_vector_rotate_axis_x( + vec3 vector_in, vec3 center, vec3 axis, float angle, vec3 rotation, out vec3 vec) +{ + vec = rotate_around_axis(vector_in - center, vec3(1.0, 0.0, 0.0), angle) + center; +} + +void node_vector_rotate_axis_y( + vec3 vector_in, vec3 center, vec3 axis, float angle, vec3 rotation, out vec3 vec) +{ + vec = rotate_around_axis(vector_in - center, vec3(0.0, 1.0, 0.0), angle) + center; +} + +void node_vector_rotate_axis_z( + vec3 vector_in, vec3 center, vec3 axis, float angle, vec3 rotation, out vec3 vec) +{ + vec = rotate_around_axis(vector_in - center, vec3(0.0, 0.0, 1.0), angle) + center; +} + +void node_vector_rotate_euler_xyz( + vec3 vector_in, vec3 center, vec3 axis, float angle, vec3 rotation, out vec3 vec) +{ + vec = euler_to_mat3(rotation) * (vector_in - center) + center; +} + +void node_vector_rotate_euler_xzy( + vec3 vector_in, vec3 center, vec3 axis, float angle, vec3 rotation, out vec3 vec) +{ + vec = euler_to_mat3(-rotation.xzy) * (vector_in - center) + center; +} + +void node_vector_rotate_euler_yxz( + vec3 vector_in, vec3 center, vec3 axis, float angle, vec3 rotation, out vec3 vec) +{ + vec = euler_to_mat3(-rotation.yxz) * (vector_in - center) + center; +} + +void node_vector_rotate_euler_yzx( + vec3 vector_in, vec3 center, vec3 axis, float angle, vec3 rotation, out vec3 vec) +{ + vec = euler_to_mat3(rotation.yzx) * (vector_in - center) + center; +} + +void node_vector_rotate_euler_zxy( + vec3 vector_in, vec3 center, vec3 axis, float angle, vec3 rotation, out vec3 vec) +{ + vec = euler_to_mat3(rotation.zxy) * (vector_in - center) + center; +} + +void node_vector_rotate_euler_zyx( + vec3 vector_in, vec3 center, vec3 axis, float angle, vec3 rotation, out vec3 vec) +{ + vec = euler_to_mat3(-rotation.zyx) * (vector_in - center) + center; +} |