diff options
Diffstat (limited to 'intern/cycles/kernel/osl')
-rw-r--r-- | intern/cycles/kernel/osl/services.cpp | 12 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/services.h | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/shaders/CMakeLists.txt | 1 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/shaders/node_magic_texture.osl | 15 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/shaders/node_vector_map_range.osl | 74 |
5 files changed, 98 insertions, 6 deletions
diff --git a/intern/cycles/kernel/osl/services.cpp b/intern/cycles/kernel/osl/services.cpp index 389c1e2b746..4007005dee7 100644 --- a/intern/cycles/kernel/osl/services.cpp +++ b/intern/cycles/kernel/osl/services.cpp @@ -28,6 +28,7 @@ #include "scene/colorspace.h" #include "scene/mesh.h" #include "scene/object.h" +#include "scene/pointcloud.h" #include "scene/scene.h" #include "kernel/osl/closures.h" @@ -113,6 +114,8 @@ ustring OSLRenderServices::u_curve_thickness("geom:curve_thickness"); ustring OSLRenderServices::u_curve_length("geom:curve_length"); ustring OSLRenderServices::u_curve_tangent_normal("geom:curve_tangent_normal"); ustring OSLRenderServices::u_curve_random("geom:curve_random"); +ustring OSLRenderServices::u_is_point("geom:is_point"); +ustring OSLRenderServices::u_point_radius("geom:point_radius"); ustring OSLRenderServices::u_normal_map_normal("geom:normal_map_normal"); ustring OSLRenderServices::u_path_ray_length("path:ray_length"); ustring OSLRenderServices::u_path_ray_depth("path:ray_depth"); @@ -994,6 +997,15 @@ bool OSLRenderServices::get_object_standard_attribute(const KernelGlobalsCPU *kg float3 f = curve_tangent_normal(kg, sd); return set_attribute_float3(f, type, derivatives, val); } + /* point attributes */ + else if (name == u_is_point) { + float f = (sd->type & PRIMITIVE_ALL_POINT) != 0; + return set_attribute_float(f, type, derivatives, val); + } + else if (name == u_point_radius) { + float f = point_radius(kg, sd); + return set_attribute_float(f, type, derivatives, val); + } else if (name == u_normal_map_normal) { if (sd->type & PRIMITIVE_ALL_TRIANGLE) { float3 f = triangle_smooth_normal_unnormalized(kg, sd, sd->Ng, sd->prim, sd->u, sd->v); diff --git a/intern/cycles/kernel/osl/services.h b/intern/cycles/kernel/osl/services.h index d9f57c642ad..9526c92b8fb 100644 --- a/intern/cycles/kernel/osl/services.h +++ b/intern/cycles/kernel/osl/services.h @@ -297,6 +297,8 @@ class OSLRenderServices : public OSL::RendererServices { static ustring u_curve_length; static ustring u_curve_tangent_normal; static ustring u_curve_random; + static ustring u_is_point; + static ustring u_point_radius; static ustring u_normal_map_normal; static ustring u_path_ray_length; static ustring u_path_ray_depth; diff --git a/intern/cycles/kernel/osl/shaders/CMakeLists.txt b/intern/cycles/kernel/osl/shaders/CMakeLists.txt index 6b62e7bb52f..4cafdb2a6d7 100644 --- a/intern/cycles/kernel/osl/shaders/CMakeLists.txt +++ b/intern/cycles/kernel/osl/shaders/CMakeLists.txt @@ -92,6 +92,7 @@ set(SRC_OSL node_value.osl node_vector_curves.osl node_vector_math.osl + node_vector_map_range.osl node_vector_rotate.osl node_vector_transform.osl node_velvet_bsdf.osl diff --git a/intern/cycles/kernel/osl/shaders/node_magic_texture.osl b/intern/cycles/kernel/osl/shaders/node_magic_texture.osl index 476c6895f05..0ed83aae3b8 100644 --- a/intern/cycles/kernel/osl/shaders/node_magic_texture.osl +++ b/intern/cycles/kernel/osl/shaders/node_magic_texture.osl @@ -17,14 +17,17 @@ #include "stdcycles.h" /* Magic */ - -color magic(point p, int n, float distortion) +color magic(point p, float scale, int n, float distortion) { float dist = distortion; - float x = sin((p[0] + p[1] + p[2]) * 5.0); - float y = cos((-p[0] + p[1] - p[2]) * 5.0); - float z = -cos((-p[0] - p[1] + p[2]) * 5.0); + float a = mod(p.x * scale, M_2PI); + float b = mod(p.y * scale, M_2PI); + float c = mod(p.z * scale, M_2PI); + + float x = sin((a + b + c) * 5.0); + float y = cos((-a + b - c) * 5.0); + float z = -cos((-a - b + c) * 5.0); if (n > 0) { x *= dist; @@ -103,6 +106,6 @@ shader node_magic_texture(int use_mapping = 0, if (use_mapping) p = transform(mapping, p); - Color = magic(p * Scale, depth, Distortion); + Color = magic(p, Scale, depth, Distortion); Fac = (Color[0] + Color[1] + Color[2]) * (1.0 / 3.0); } diff --git a/intern/cycles/kernel/osl/shaders/node_vector_map_range.osl b/intern/cycles/kernel/osl/shaders/node_vector_map_range.osl new file mode 100644 index 00000000000..1a59691fc45 --- /dev/null +++ b/intern/cycles/kernel/osl/shaders/node_vector_map_range.osl @@ -0,0 +1,74 @@ +/* + * Copyright 2011-2021 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "stdcycles.h" + +float safe_divide(float a, float b) +{ + return (b != 0.0) ? a / b : 0.0; +} + +point safe_divide(point a, point b) +{ + return point(safe_divide(a.x, b.x), safe_divide(a.y, b.y), safe_divide(a.z, b.z)); +} + +shader node_vector_map_range(string range_type = "linear", + int use_clamp = 0, + point VectorIn = point(1.0, 1.0, 1.0), + point From_Min_FLOAT3 = point(0.0, 0.0, 0.0), + point From_Max_FLOAT3 = point(1.0, 1.0, 1.0), + point To_Min_FLOAT3 = point(0.0, 0.0, 0.0), + point To_Max_FLOAT3 = point(1.0, 1.0, 1.0), + point Steps_FLOAT3 = point(4.0, 4.0, 4.0), + output point VectorOut = point(0.0, 0.0, 0.0)) +{ + point factor = VectorIn; + point from_min = From_Min_FLOAT3; + point from_max = From_Max_FLOAT3; + point to_min = To_Min_FLOAT3; + point to_max = To_Max_FLOAT3; + point steps = Steps_FLOAT3; + + if (range_type == "stepped") { + factor = safe_divide((factor - from_min), (from_max - from_min)); + factor = point((steps.x > 0.0) ? floor(factor.x * (steps.x + 1.0)) / steps.x : 0.0, + (steps.y > 0.0) ? floor(factor.y * (steps.y + 1.0)) / steps.y : 0.0, + (steps.z > 0.0) ? floor(factor.z * (steps.z + 1.0)) / steps.z : 0.0); + } + else if (range_type == "smoothstep") { + factor = safe_divide((factor - from_min), (from_max - from_min)); + factor = clamp(factor, 0.0, 1.0); + factor = (3.0 - 2.0 * factor) * (factor * factor); + } + else if (range_type == "smootherstep") { + factor = safe_divide((factor - from_min), (from_max - from_min)); + factor = clamp(factor, 0.0, 1.0); + factor = factor * factor * factor * (factor * (factor * 6.0 - 15.0) + 10.0); + } + else { + factor = safe_divide((factor - from_min), (from_max - from_min)); + } + VectorOut = to_min + factor * (to_max - to_min); + if (use_clamp > 0) { + VectorOut.x = (to_min.x > to_max.x) ? clamp(VectorOut.x, to_max.x, to_min.x) : + clamp(VectorOut.x, to_min.x, to_max.x); + VectorOut.y = (to_min.y > to_max.y) ? clamp(VectorOut.y, to_max.y, to_min.y) : + clamp(VectorOut.y, to_min.y, to_max.y); + VectorOut.z = (to_min.z > to_max.z) ? clamp(VectorOut.z, to_max.z, to_min.z) : + clamp(VectorOut.z, to_min.z, to_max.z); + } +} |