diff options
Diffstat (limited to 'intern')
20 files changed, 418 insertions, 1053 deletions
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 48bdcd88c9d..2e558cf3e97 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -191,8 +191,8 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Node * node = new FresnelNode(); break; } - case BL::ShaderNode::type_BLEND_WEIGHT: { - node = new BlendWeightNode(); + case BL::ShaderNode::type_LAYER_WEIGHT: { + node = new LayerWeightNode(); break; } case BL::ShaderNode::type_ADD_SHADER: { @@ -316,26 +316,17 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Node * node = env; break; } - case BL::ShaderNode::type_TEX_NOISE: { - BL::ShaderNodeTexNoise b_noise_node(b_node); - NoiseTextureNode *noise = new NoiseTextureNode(); - get_tex_mapping(&noise->tex_mapping, b_noise_node.texture_mapping()); - node = noise; - break; - } - case BL::ShaderNode::type_TEX_BLEND: { - BL::ShaderNodeTexBlend b_blend_node(b_node); - BlendTextureNode *blend = new BlendTextureNode(); - blend->progression = BlendTextureNode::progression_enum[(int)b_blend_node.progression()]; - blend->axis = BlendTextureNode::axis_enum[(int)b_blend_node.axis()]; - get_tex_mapping(&blend->tex_mapping, b_blend_node.texture_mapping()); - node = blend; + case BL::ShaderNode::type_TEX_GRADIENT: { + BL::ShaderNodeTexGradient b_gradient_node(b_node); + GradientTextureNode *gradient = new GradientTextureNode(); + gradient->type = GradientTextureNode::type_enum[(int)b_gradient_node.gradient_type()]; + get_tex_mapping(&gradient->tex_mapping, b_gradient_node.texture_mapping()); + node = gradient; break; } case BL::ShaderNode::type_TEX_VORONOI: { BL::ShaderNodeTexVoronoi b_voronoi_node(b_node); VoronoiTextureNode *voronoi = new VoronoiTextureNode(); - voronoi->distance_metric = VoronoiTextureNode::distance_metric_enum[(int)b_voronoi_node.distance_metric()]; voronoi->coloring = VoronoiTextureNode::coloring_enum[(int)b_voronoi_node.coloring()]; get_tex_mapping(&voronoi->tex_mapping, b_voronoi_node.texture_mapping()); node = voronoi; @@ -349,67 +340,29 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Node * node = magic; break; } - case BL::ShaderNode::type_TEX_MARBLE: { - BL::ShaderNodeTexMarble b_marble_node(b_node); - MarbleTextureNode *marble = new MarbleTextureNode(); - marble->depth = b_marble_node.turbulence_depth(); - marble->basis = MarbleTextureNode::basis_enum[(int)b_marble_node.noise_basis()]; - marble->type = MarbleTextureNode::type_enum[(int)b_marble_node.marble_type()]; - marble->wave = MarbleTextureNode::wave_enum[(int)b_marble_node.wave_type()]; - marble->hard = b_marble_node.noise_type() == BL::ShaderNodeTexMarble::noise_type_HARD; - get_tex_mapping(&marble->tex_mapping, b_marble_node.texture_mapping()); - node = marble; - break; - } - case BL::ShaderNode::type_TEX_CLOUDS: { - BL::ShaderNodeTexClouds b_clouds_node(b_node); - CloudsTextureNode *clouds = new CloudsTextureNode(); - clouds->depth = b_clouds_node.turbulence_depth(); - clouds->basis = CloudsTextureNode::basis_enum[(int)b_clouds_node.noise_basis()]; - clouds->hard = b_clouds_node.noise_type() == BL::ShaderNodeTexClouds::noise_type_HARD; - get_tex_mapping(&clouds->tex_mapping, b_clouds_node.texture_mapping()); - node = clouds; + case BL::ShaderNode::type_TEX_WAVE: { + BL::ShaderNodeTexWave b_wave_node(b_node); + WaveTextureNode *wave = new WaveTextureNode(); + wave->type = WaveTextureNode::type_enum[(int)b_wave_node.wave_type()]; + get_tex_mapping(&wave->tex_mapping, b_wave_node.texture_mapping()); + node = wave; break; } - case BL::ShaderNode::type_TEX_WOOD: { - BL::ShaderNodeTexWood b_wood_node(b_node); - WoodTextureNode *wood = new WoodTextureNode(); - wood->type = WoodTextureNode::type_enum[(int)b_wood_node.wood_type()]; - wood->basis = WoodTextureNode::basis_enum[(int)b_wood_node.noise_basis()]; - wood->hard = b_wood_node.noise_type() == BL::ShaderNodeTexWood::noise_type_HARD; - wood->wave = WoodTextureNode::wave_enum[(int)b_wood_node.wave_type()]; - get_tex_mapping(&wood->tex_mapping, b_wood_node.texture_mapping()); - node = wood; + case BL::ShaderNode::type_TEX_NOISE: { + BL::ShaderNodeTexNoise b_noise_node(b_node); + NoiseTextureNode *noise = new NoiseTextureNode(); + get_tex_mapping(&noise->tex_mapping, b_noise_node.texture_mapping()); + node = noise; break; } case BL::ShaderNode::type_TEX_MUSGRAVE: { BL::ShaderNodeTexMusgrave b_musgrave_node(b_node); MusgraveTextureNode *musgrave = new MusgraveTextureNode(); musgrave->type = MusgraveTextureNode::type_enum[(int)b_musgrave_node.musgrave_type()]; - musgrave->basis = MusgraveTextureNode::basis_enum[(int)b_musgrave_node.noise_basis()]; get_tex_mapping(&musgrave->tex_mapping, b_musgrave_node.texture_mapping()); node = musgrave; break; } - case BL::ShaderNode::type_TEX_STUCCI: { - BL::ShaderNodeTexStucci b_stucci_node(b_node); - StucciTextureNode *stucci = new StucciTextureNode(); - stucci->type = StucciTextureNode::type_enum[(int)b_stucci_node.stucci_type()]; - stucci->basis = StucciTextureNode::basis_enum[(int)b_stucci_node.noise_basis()]; - stucci->hard = b_stucci_node.noise_type() == BL::ShaderNodeTexStucci::noise_type_HARD; - get_tex_mapping(&stucci->tex_mapping, b_stucci_node.texture_mapping()); - node = stucci; - break; - } - case BL::ShaderNode::type_TEX_DISTORTED_NOISE: { - BL::ShaderNodeTexDistortedNoise b_distnoise_node(b_node); - DistortedNoiseTextureNode *distnoise = new DistortedNoiseTextureNode(); - distnoise->basis = DistortedNoiseTextureNode::basis_enum[(int)b_distnoise_node.noise_basis()]; - distnoise->distortion_basis = DistortedNoiseTextureNode::basis_enum[(int)b_distnoise_node.noise_distortion()]; - get_tex_mapping(&distnoise->tex_mapping, b_distnoise_node.texture_mapping()); - node = distnoise; - break; - } case BL::ShaderNode::type_TEX_COORD: { node = new TextureCoordinateNode();; break; diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt index cf10f035585..893c4bb6081 100644 --- a/intern/cycles/kernel/CMakeLists.txt +++ b/intern/cycles/kernel/CMakeLists.txt @@ -42,33 +42,29 @@ set(svm_headers svm/emissive.h svm/svm.h svm/svm_attribute.h - svm/svm_blend.h svm/svm_bsdf.h svm/svm_closure.h - svm/svm_clouds.h svm/svm_convert.h svm/svm_displace.h - svm/svm_distorted_noise.h svm/svm_fresnel.h svm/svm_geometry.h + svm/svm_gradient.h svm/svm_image.h svm/svm_light_path.h svm/svm_magic.h svm/svm_mapping.h - svm/svm_marble.h svm/svm_math.h svm/svm_mix.h svm/svm_musgrave.h svm/svm_noise.h svm/svm_noisetex.h svm/svm_sky.h - svm/svm_stucci.h svm/svm_tex_coord.h svm/svm_texture.h svm/svm_types.h svm/svm_value.h svm/svm_voronoi.h - svm/svm_wood.h + svm/svm_wave.h svm/volume.h ) diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index 9628f96bcab..2615272691c 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -120,29 +120,25 @@ CCL_NAMESPACE_END #include "svm_texture.h" #include "svm_attribute.h" -#include "svm_blend.h" +#include "svm_gradient.h" #include "svm_closure.h" -#include "svm_clouds.h" +#include "svm_noisetex.h" #include "svm_convert.h" #include "svm_displace.h" -#include "svm_distorted_noise.h" #include "svm_fresnel.h" #include "svm_geometry.h" #include "svm_image.h" #include "svm_light_path.h" #include "svm_magic.h" #include "svm_mapping.h" -#include "svm_marble.h" +#include "svm_wave.h" #include "svm_math.h" #include "svm_mix.h" #include "svm_musgrave.h" -#include "svm_noisetex.h" #include "svm_sky.h" -#include "svm_stucci.h" #include "svm_tex_coord.h" #include "svm_value.h" #include "svm_voronoi.h" -#include "svm_wood.h" CCL_NAMESPACE_BEGIN @@ -206,12 +202,6 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT offset = node.y; break; #ifdef __TEXTURES__ - case NODE_TEX_NOISE_F: - svm_node_tex_noise_f(sd, stack, node.y, node.z); - break; - case NODE_TEX_NOISE_V: - svm_node_tex_noise_v(sd, stack, node.y, node.z); - break; case NODE_TEX_IMAGE: svm_node_tex_image(kg, sd, stack, node); break; @@ -221,11 +211,11 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT case NODE_TEX_SKY: svm_node_tex_sky(kg, sd, stack, node.y, node.z); break; - case NODE_TEX_BLEND: - svm_node_tex_blend(sd, stack, node); + case NODE_TEX_GRADIENT: + svm_node_tex_gradient(sd, stack, node); break; - case NODE_TEX_CLOUDS: - svm_node_tex_clouds(sd, stack, node); + case NODE_TEX_NOISE: + svm_node_tex_noise(kg, sd, stack, node, &offset); break; case NODE_TEX_VORONOI: svm_node_tex_voronoi(kg, sd, stack, node, &offset); @@ -233,20 +223,11 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT case NODE_TEX_MUSGRAVE: svm_node_tex_musgrave(kg, sd, stack, node, &offset); break; - case NODE_TEX_MARBLE: - svm_node_tex_marble(kg, sd, stack, node, &offset); + case NODE_TEX_WAVE: + svm_node_tex_wave(kg, sd, stack, node, &offset); break; case NODE_TEX_MAGIC: - svm_node_tex_magic(sd, stack, node); - break; - case NODE_TEX_STUCCI: - svm_node_tex_stucci(kg, sd, stack, node, &offset); - break; - case NODE_TEX_DISTORTED_NOISE: - svm_node_tex_distorted_noise(kg, sd, stack, node, &offset); - break; - case NODE_TEX_WOOD: - svm_node_tex_wood(kg, sd, stack, node, &offset); + svm_node_tex_magic(kg, sd, stack, node, &offset); break; #endif case NODE_GEOMETRY: @@ -285,8 +266,8 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT case NODE_FRESNEL: svm_node_fresnel(sd, stack, node.y, node.z, node.w); break; - case NODE_BLEND_WEIGHT: - svm_node_blend_weight(sd, stack, node); + case NODE_LAYER_WEIGHT: + svm_node_layer_weight(sd, stack, node); break; case NODE_SET_DISPLACEMENT: svm_node_set_displacement(sd, stack, node.y); diff --git a/intern/cycles/kernel/svm/svm_clouds.h b/intern/cycles/kernel/svm/svm_clouds.h deleted file mode 100644 index b89f1ceb072..00000000000 --- a/intern/cycles/kernel/svm/svm_clouds.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2011, Blender Foundation. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -CCL_NAMESPACE_BEGIN - -/* Clouds */ - -__device_inline void svm_clouds(NodeNoiseBasis basis, int hard, int depth, float size, float3 p, float *fac, float3 *color) -{ - p /= size; - - *fac = noise_turbulence(p, basis, depth, hard); - *color = make_float3(*fac, - noise_turbulence(make_float3(p.y, p.x, p.z), basis, depth, hard), - noise_turbulence(make_float3(p.y, p.z, p.x), basis, depth, hard)); -} - -__device void svm_node_tex_clouds(ShaderData *sd, float *stack, uint4 node) -{ - uint basis, hard, depth; - uint size_offset, co_offset, fac_offset, color_offset; - - decode_node_uchar4(node.y, &basis, &hard, &depth, NULL); - decode_node_uchar4(node.z, &size_offset, &co_offset, &fac_offset, &color_offset); - - float3 co = stack_load_float3(stack, co_offset); - float size = stack_load_float_default(stack, size_offset, node.w); - size = nonzerof(size, 1e-5f); - - float3 color; - float f; - - svm_clouds((NodeNoiseBasis)basis, hard, depth, size, co, &f, &color); - - if(stack_valid(fac_offset)) stack_store_float(stack, fac_offset, f); - if(stack_valid(color_offset)) stack_store_float3(stack, color_offset, color); -} - -CCL_NAMESPACE_END - diff --git a/intern/cycles/kernel/svm/svm_distorted_noise.h b/intern/cycles/kernel/svm/svm_distorted_noise.h deleted file mode 100644 index 7d1556cd185..00000000000 --- a/intern/cycles/kernel/svm/svm_distorted_noise.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2011, Blender Foundation. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -CCL_NAMESPACE_BEGIN - -/* Distorted Noise (variable lacunarity noise) */ - -__device_noinline float svm_distorted_noise(float3 p, float size, NodeNoiseBasis basis, NodeNoiseBasis distortion_basis, float distortion) -{ - float3 r; - float3 offset = make_float3(13.5f, 13.5f, 13.5f); - - p /= size; - - r.x = noise_basis(p + offset, basis) * distortion; - r.y = noise_basis(p, basis) * distortion; - r.z = noise_basis(p - offset, basis) * distortion; - - return noise_basis(p + r, distortion_basis); /* distorted-domain noise */ -} - -__device void svm_node_tex_distorted_noise(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) -{ - uint4 node2 = read_node(kg, offset); - - uint basis, distortion_basis; - uint size_offset, distortion_offset, co_offset, fac_offset; - - decode_node_uchar4(node.y, &basis, &distortion_basis, NULL, NULL); - decode_node_uchar4(node.z, &size_offset, &distortion_offset, &co_offset, &fac_offset); - - float3 co = stack_load_float3(stack, co_offset); - float size = stack_load_float_default(stack, size_offset, node2.x); - float distortion = stack_load_float_default(stack, distortion_offset, node2.y); - size = nonzerof(size, 1e-5f); - - float f = svm_distorted_noise(co, size, (NodeNoiseBasis)basis, - (NodeNoiseBasis)distortion_basis, distortion); - - stack_store_float(stack, fac_offset, f); -} - -CCL_NAMESPACE_END - diff --git a/intern/cycles/kernel/svm/svm_fresnel.h b/intern/cycles/kernel/svm/svm_fresnel.h index 1b9d99506e3..7684eabeecb 100644 --- a/intern/cycles/kernel/svm/svm_fresnel.h +++ b/intern/cycles/kernel/svm/svm_fresnel.h @@ -33,7 +33,7 @@ __device void svm_node_fresnel(ShaderData *sd, float *stack, uint ior_offset, ui /* Blend Weight Node */ -__device void svm_node_blend_weight(ShaderData *sd, float *stack, uint4 node) +__device void svm_node_layer_weight(ShaderData *sd, float *stack, uint4 node) { uint blend_offset = node.y; uint blend_value = node.z; @@ -44,7 +44,7 @@ __device void svm_node_blend_weight(ShaderData *sd, float *stack, uint4 node) float f; - if(type == NODE_BLEND_WEIGHT_FRESNEL) { + if(type == NODE_LAYER_WEIGHT_FRESNEL) { float eta = fmaxf(1.0f - blend, 1e-5f); eta = (sd->flag & SD_BACKFACING)? eta: 1.0f/eta; diff --git a/intern/cycles/kernel/svm/svm_blend.h b/intern/cycles/kernel/svm/svm_gradient.h index 97fa4aff9e7..79298f5f581 100644 --- a/intern/cycles/kernel/svm/svm_blend.h +++ b/intern/cycles/kernel/svm/svm_gradient.h @@ -18,36 +18,31 @@ CCL_NAMESPACE_BEGIN -/* Blend */ +/* Gradient */ -__device float svm_blend(float3 p, NodeBlendType type, NodeBlendAxis axis) +__device float svm_gradient(float3 p, NodeBlendType type) { - float x, y; + float x, y, z; - if(axis == NODE_BLEND_VERTICAL) { - x= p.y; - y= p.x; - } - else { - x= p.x; - y= p.y; - } + x= p.x; + y= p.y; + z= p.z; if(type == NODE_BLEND_LINEAR) { - return (1.0f + x)/2.0f; + return x; } else if(type == NODE_BLEND_QUADRATIC) { - float r = fmaxf((1.0f + x)/2.0f, 0.0f); + float r = fmaxf(x, 0.0f); return r*r; } else if(type == NODE_BLEND_EASING) { - float r = fminf(fmaxf((1.0f + x)/2.0f, 0.0f), 1.0f); + float r = fminf(fmaxf(x, 0.0f), 1.0f); float t = r*r; return (3.0f*t - 2.0f*t*r); } else if(type == NODE_BLEND_DIAGONAL) { - return (2.0f + x + y)/4.0f; + return (x + y)/2.0f; } else if(type == NODE_BLEND_RADIAL) { return atan2(y, x)/(2.0f*M_PI_F) + 0.5f; @@ -64,15 +59,21 @@ __device float svm_blend(float3 p, NodeBlendType type, NodeBlendAxis axis) return 0.0f; } -__device void svm_node_tex_blend(ShaderData *sd, float *stack, uint4 node) +__device void svm_node_tex_gradient(ShaderData *sd, float *stack, uint4 node) { - float3 co = stack_load_float3(stack, node.z); - uint type, axis; + uint type, co_offset, color_offset, fac_offset; + + decode_node_uchar4(node.y, &type, &co_offset, &fac_offset, &color_offset); + + float3 co = stack_load_float3(stack, co_offset); - decode_node_uchar4(node.y, &type, &axis, NULL, NULL); + float f = svm_gradient(co, (NodeBlendType)type); + f = clamp(f, 0.0f, 1.0f); - float f = svm_blend(co, (NodeBlendType)type, (NodeBlendAxis)axis); - stack_store_float(stack, node.w, f); + if(stack_valid(fac_offset)) + stack_store_float(stack, fac_offset, f); + if(stack_valid(color_offset)) + stack_store_float3(stack, color_offset, make_float3(f, f, f)); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/svm_magic.h b/intern/cycles/kernel/svm/svm_magic.h index af847869f6e..65d37937e1e 100644 --- a/intern/cycles/kernel/svm/svm_magic.h +++ b/intern/cycles/kernel/svm/svm_magic.h @@ -20,56 +20,54 @@ CCL_NAMESPACE_BEGIN /* Magic */ -__device_noinline float3 svm_magic(float3 p, int n, float turbulence) +__device_noinline float3 svm_magic(float3 p, int n, float distortion) { - float turb = turbulence/5.0f; - float x = sinf((p.x + p.y + p.z)*5.0f); float y = cosf((-p.x + p.y - p.z)*5.0f); float z = -cosf((-p.x - p.y + p.z)*5.0f); if(n > 0) { - x *= turb; - y *= turb; - z *= turb; + x *= distortion; + y *= distortion; + z *= distortion; y = -cosf(x-y+z); - y *= turb; + y *= distortion; if(n > 1) { x= cosf(x-y-z); - x *= turb; + x *= distortion; if(n > 2) { z= sinf(-x-y-z); - z *= turb; + z *= distortion; if(n > 3) { x= -cosf(-x+y-z); - x *= turb; + x *= distortion; if(n > 4) { y= -sinf(-x+y+z); - y *= turb; + y *= distortion; if(n > 5) { y= -cosf(-x+y+z); - y *= turb; + y *= distortion; if(n > 6) { x= cosf(x+y+z); - x *= turb; + x *= distortion; if(n > 7) { z= sinf(x+y-z); - z *= turb; + z *= distortion; if(n > 8) { x= -cosf(-x-y+z); - x *= turb; + x *= distortion; if(n > 9) { y= -sinf(x-y+z); - y *= turb; + y *= distortion; } } } @@ -81,27 +79,35 @@ __device_noinline float3 svm_magic(float3 p, int n, float turbulence) } } - if(turb != 0.0f) { - turb *= 2.0f; - x /= turb; - y /= turb; - z /= turb; + if(distortion != 0.0f) { + distortion *= 2.0f; + x /= distortion; + y /= distortion; + z /= distortion; } return make_float3(0.5f - x, 0.5f - y, 0.5f - z); } -__device void svm_node_tex_magic(ShaderData *sd, float *stack, uint4 node) +__device void svm_node_tex_magic(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) { - uint depth, turbulence_offset, co_offset, color_offset; + uint depth; + uint scale_offset, distortion_offset, co_offset, fac_offset, color_offset; - decode_node_uchar4(node.y, &depth, &turbulence_offset, &co_offset, &color_offset); + decode_node_uchar4(node.y, &depth, &color_offset, &fac_offset, NULL); + decode_node_uchar4(node.z, &co_offset, &scale_offset, &distortion_offset, NULL); + uint4 node2 = read_node(kg, offset); float3 co = stack_load_float3(stack, co_offset); - float turbulence = stack_load_float_default(stack, turbulence_offset, node.z); + float scale = stack_load_float_default(stack, scale_offset, node2.x); + float distortion = stack_load_float_default(stack, distortion_offset, node2.y); + + float3 color = svm_magic(co*scale, depth, distortion); - float3 color = svm_magic(co, depth, turbulence); - stack_store_float3(stack, color_offset, color); + if(stack_valid(fac_offset)) + stack_store_float(stack, fac_offset, average(color)); + if(stack_valid(color_offset)) + stack_store_float3(stack, color_offset, color); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/svm_marble.h b/intern/cycles/kernel/svm/svm_marble.h deleted file mode 100644 index aa22565e956..00000000000 --- a/intern/cycles/kernel/svm/svm_marble.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2011, Blender Foundation. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -CCL_NAMESPACE_BEGIN - -/* Marble */ - -__device_noinline float svm_marble(float3 p, float size, NodeMarbleType type, NodeWaveType wave, NodeNoiseBasis basis, int hard, float turb, int depth) -{ - float x = p.x; - float y = p.y; - float z = p.z; - - float n = 5.0f * (x + y + z); - - float mi = n + turb * noise_turbulence(p/size, basis, depth, hard); - - mi = noise_wave(wave, mi); - - if(type == NODE_MARBLE_SHARP) - mi = sqrt(mi); - else if(type == NODE_MARBLE_SHARPER) - mi = sqrt(sqrt(mi)); - - return mi; -} - -__device void svm_node_tex_marble(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) -{ - uint4 node2 = read_node(kg, offset); - - uint type, wave, basis, hard; - uint depth; - uint size_offset, turbulence_offset, co_offset, fac_offset; - - decode_node_uchar4(node.y, &type, &wave, &basis, &hard); - decode_node_uchar4(node.z, &depth, NULL, NULL, NULL); - decode_node_uchar4(node.w, &size_offset, &turbulence_offset, &co_offset, &fac_offset); - - float3 co = stack_load_float3(stack, co_offset); - float size = stack_load_float_default(stack, size_offset, node2.x); - float turbulence = stack_load_float_default(stack, turbulence_offset, node2.y); - size = nonzerof(size, 1e-5f); - - float f = svm_marble(co, size, (NodeMarbleType)type, (NodeWaveType)wave, - (NodeNoiseBasis)basis, hard, turbulence, depth); - - stack_store_float(stack, fac_offset, f); -} - -CCL_NAMESPACE_END - diff --git a/intern/cycles/kernel/svm/svm_musgrave.h b/intern/cycles/kernel/svm/svm_musgrave.h index be327f7f262..34cf7868f07 100644 --- a/intern/cycles/kernel/svm/svm_musgrave.h +++ b/intern/cycles/kernel/svm/svm_musgrave.h @@ -36,14 +36,14 @@ __device_noinline float noise_musgrave_fBm(float3 p, NodeNoiseBasis basis, float int i; for(i = 0; i < (int)octaves; i++) { - value += noise_basis(p, basis) * pwr; + value += snoise(p) * pwr; pwr *= pwHL; p *= lacunarity; } rmd = octaves - floor(octaves); if(rmd != 0.0f) - value += rmd * noise_basis(p, basis) * pwr; + value += rmd * snoise(p) * pwr; return value; } @@ -64,14 +64,14 @@ __device_noinline float noise_musgrave_multi_fractal(float3 p, NodeNoiseBasis ba int i; for(i = 0; i < (int)octaves; i++) { - value *= (pwr * noise_basis(p, basis) + 1.0f); + value *= (pwr * snoise(p) + 1.0f); pwr *= pwHL; p *= lacunarity; } rmd = octaves - floor(octaves); if(rmd != 0.0f) - value *= (rmd * pwr * noise_basis(p, basis) + 1.0f); /* correct? */ + value *= (rmd * pwr * snoise(p) + 1.0f); /* correct? */ return value; } @@ -92,11 +92,11 @@ __device_noinline float noise_musgrave_hetero_terrain(float3 p, NodeNoiseBasis b int i; /* first unscaled octave of function; later octaves are scaled */ - value = offset + noise_basis(p, basis); + value = offset + snoise(p); p *= lacunarity; for(i = 1; i < (int)octaves; i++) { - increment = (noise_basis(p, basis) + offset) * pwr * value; + increment = (snoise(p) + offset) * pwr * value; value += increment; pwr *= pwHL; p *= lacunarity; @@ -104,7 +104,7 @@ __device_noinline float noise_musgrave_hetero_terrain(float3 p, NodeNoiseBasis b rmd = octaves - floor(octaves); if(rmd != 0.0f) { - increment = (noise_basis(p, basis) + offset) * pwr * value; + increment = (snoise(p) + offset) * pwr * value; value += rmd * increment; } @@ -126,7 +126,7 @@ __device_noinline float noise_musgrave_hybrid_multi_fractal(float3 p, NodeNoiseB float pwr = pwHL; int i; - result = noise_basis(p, basis) + offset; + result = snoise(p) + offset; weight = gain * result; p *= lacunarity; @@ -134,7 +134,7 @@ __device_noinline float noise_musgrave_hybrid_multi_fractal(float3 p, NodeNoiseB if(weight > 1.0f) weight = 1.0f; - signal = (noise_basis(p, basis) + offset) * pwr; + signal = (snoise(p) + offset) * pwr; pwr *= pwHL; result += weight * signal; weight *= gain * signal; @@ -143,7 +143,7 @@ __device_noinline float noise_musgrave_hybrid_multi_fractal(float3 p, NodeNoiseB rmd = octaves - floor(octaves); if(rmd != 0.0f) - result += rmd * ((noise_basis(p, basis) + offset) * pwr); + result += rmd * ((snoise(p) + offset) * pwr); return result; } @@ -163,7 +163,7 @@ __device_noinline float noise_musgrave_ridged_multi_fractal(float3 p, NodeNoiseB float pwr = pwHL; int i; - signal = offset - fabsf(noise_basis(p, basis)); + signal = offset - fabsf(snoise(p)); signal *= signal; result = signal; weight = 1.0f; @@ -171,7 +171,7 @@ __device_noinline float noise_musgrave_ridged_multi_fractal(float3 p, NodeNoiseB for(i = 1; i < (int)octaves; i++) { p *= lacunarity; weight = clamp(signal * gain, 0.0f, 1.0f); - signal = offset - fabsf(noise_basis(p, basis)); + signal = offset - fabsf(snoise(p)); signal *= signal; signal *= weight; result += signal * pwr; @@ -183,9 +183,10 @@ __device_noinline float noise_musgrave_ridged_multi_fractal(float3 p, NodeNoiseB /* Shader */ -__device float svm_musgrave(NodeMusgraveType type, NodeNoiseBasis basis, float dimension, float lacunarity, float octaves, float offset, float intensity, float gain, float size, float3 p) +__device float svm_musgrave(NodeMusgraveType type, float dimension, float lacunarity, float octaves, float offset, float intensity, float gain, float scale, float3 p) { - p /= size; + NodeNoiseBasis basis = NODE_NOISE_PERLIN; + p *= scale; if(type == NODE_MUSGRAVE_MULTIFRACTAL) return intensity*noise_musgrave_multi_fractal(p, basis, dimension, lacunarity, octaves); @@ -206,31 +207,33 @@ __device void svm_node_tex_musgrave(KernelGlobals *kg, ShaderData *sd, float *st uint4 node2 = read_node(kg, offset); uint4 node3 = read_node(kg, offset); - uint type, basis, co_offset, fac_offset; - uint dimension_offset, lacunarity_offset, octaves_offset, offset_offset; - uint gain_offset, size_offset; + uint type, co_offset, color_offset, fac_offset; + uint dimension_offset, lacunarity_offset, detail_offset, offset_offset; + uint gain_offset, scale_offset; - decode_node_uchar4(node.y, &type, &basis, &co_offset, &fac_offset); - decode_node_uchar4(node.z, &dimension_offset, &lacunarity_offset, &octaves_offset, &offset_offset); - decode_node_uchar4(node.z, &gain_offset, &size_offset, NULL, NULL); + decode_node_uchar4(node.y, &type, &co_offset, &color_offset, &fac_offset); + decode_node_uchar4(node.z, &dimension_offset, &lacunarity_offset, &detail_offset, &offset_offset); + decode_node_uchar4(node.z, &gain_offset, &scale_offset, NULL, NULL); float3 co = stack_load_float3(stack, co_offset); float dimension = stack_load_float_default(stack, dimension_offset, node2.x); float lacunarity = stack_load_float_default(stack, lacunarity_offset, node2.y); - float octaves = stack_load_float_default(stack, octaves_offset, node2.z); + float detail = stack_load_float_default(stack, detail_offset, node2.z); float foffset = stack_load_float_default(stack, offset_offset, node2.w); float gain = stack_load_float_default(stack, gain_offset, node3.x); - float size = stack_load_float_default(stack, size_offset, node3.y); + float scale = stack_load_float_default(stack, scale_offset, node3.y); - dimension = fmaxf(dimension, 0.0f); - octaves = fmaxf(octaves, 0.0f); + dimension = fmaxf(dimension, 1e-5f); + detail = clamp(detail, 0.0f, 16.0f); lacunarity = fmaxf(lacunarity, 1e-5f); - size = nonzerof(size, 1e-5f); - float f = svm_musgrave((NodeMusgraveType)type, (NodeNoiseBasis)basis, - dimension, lacunarity, octaves, foffset, 1.0f, gain, size, co); + float f = svm_musgrave((NodeMusgraveType)type, + dimension, lacunarity, detail, foffset, 1.0f, gain, scale, co); - stack_store_float(stack, fac_offset, f); + if(stack_valid(fac_offset)) + stack_store_float(stack, fac_offset, f); + if(stack_valid(color_offset)) + stack_store_float3(stack, color_offset, make_float3(f, f, f)); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/svm_noisetex.h b/intern/cycles/kernel/svm/svm_noisetex.h index 38b249a80fe..7421597040e 100644 --- a/intern/cycles/kernel/svm/svm_noisetex.h +++ b/intern/cycles/kernel/svm/svm_noisetex.h @@ -18,30 +18,55 @@ CCL_NAMESPACE_BEGIN -__device float svm_noise_texture_value(float3 p) -{ - return cellnoise(p*1e8f); -} +/* Clouds */ -__device float3 svm_noise_texture_color(float3 p) +__device_inline void svm_noise(float3 p, float scale, float detail, float distortion, float *fac, float3 *color) { - return cellnoise_color(p*1e8f); -} + NodeNoiseBasis basis = NODE_NOISE_PERLIN; + int hard = 0; -__device void svm_node_tex_noise_f(ShaderData *sd, float *stack, uint co_offset, uint out_offset) -{ - float3 co = stack_load_float3(stack, co_offset); - float f = svm_noise_texture_value(co); + p *= scale; + + if(distortion != 0.0f) { + float3 r, offset = make_float3(13.5f, 13.5f, 13.5f); + + r.x = noise_basis(p + offset, basis) * distortion; + r.y = noise_basis(p, basis) * distortion; + r.z = noise_basis(p - offset, basis) * distortion; - stack_store_float(stack, out_offset, f); + p += r; + } + + *fac = noise_turbulence(p, basis, detail, hard); + *color = make_float3(*fac, + noise_turbulence(make_float3(p.y, p.x, p.z), basis, detail, hard), + noise_turbulence(make_float3(p.y, p.z, p.x), basis, detail, hard)); } -__device void svm_node_tex_noise_v(ShaderData *sd, float *stack, uint co_offset, uint out_offset) +__device void svm_node_tex_noise(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) { + uint co_offset, scale_offset, detail_offset, distortion_offset, fac_offset, color_offset; + + decode_node_uchar4(node.y, &co_offset, &scale_offset, &detail_offset, &distortion_offset); + + uint4 node2 = read_node(kg, offset); + + float scale = stack_load_float_default(stack, scale_offset, node2.x); + float detail = stack_load_float_default(stack, detail_offset, node2.y); + float distortion = stack_load_float_default(stack, distortion_offset, node2.z); float3 co = stack_load_float3(stack, co_offset); - float3 f = svm_noise_texture_color(co); - stack_store_float3(stack, out_offset, f); + float3 color; + float f; + + svm_noise(co, scale, detail, distortion, &f, &color); + + decode_node_uchar4(node.z, &color_offset, &fac_offset, NULL, NULL); + + if(stack_valid(fac_offset)) + stack_store_float(stack, fac_offset, f); + if(stack_valid(color_offset)) + stack_store_float3(stack, color_offset, color); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/svm_stucci.h b/intern/cycles/kernel/svm/svm_stucci.h deleted file mode 100644 index 89353ab4cd3..00000000000 --- a/intern/cycles/kernel/svm/svm_stucci.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2011, Blender Foundation. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -CCL_NAMESPACE_BEGIN - -/* Stucci */ - -__device_noinline float svm_stucci(NodeStucciType type, NodeNoiseBasis basis, int hard, float turbulence, float size, float3 p) -{ - p /= size; - - float b2 = noise_basis_hard(p, basis, hard); - float ofs = turbulence/200.0f; - - if(type != NODE_STUCCI_PLASTIC) - ofs *= b2*b2; - - float r = noise_basis_hard(make_float3(p.x, p.y, p.z+ofs), basis, hard); - - if(type == NODE_STUCCI_WALL_OUT) - r = 1.0f - r; - - return fmaxf(r, 0.0f); -} - -__device void svm_node_tex_stucci(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) -{ - uint4 node2 = read_node(kg, offset); - - uint type, basis, hard; - uint size_offset, turbulence_offset, co_offset, fac_offset; - - decode_node_uchar4(node.y, &type, &basis, &hard, NULL); - decode_node_uchar4(node.z, &size_offset, &turbulence_offset, &co_offset, &fac_offset); - - float3 co = stack_load_float3(stack, co_offset); - float size = stack_load_float_default(stack, size_offset, node2.x); - float turbulence = stack_load_float_default(stack, turbulence_offset, node2.y); - size = nonzerof(size, 1e-5f); - - float f = svm_stucci((NodeStucciType)type, (NodeNoiseBasis)basis, hard, - turbulence, size, co); - - stack_store_float(stack, fac_offset, f); -} - -CCL_NAMESPACE_END - diff --git a/intern/cycles/kernel/svm/svm_texture.h b/intern/cycles/kernel/svm/svm_texture.h index e273a92c988..82797018d74 100644 --- a/intern/cycles/kernel/svm/svm_texture.h +++ b/intern/cycles/kernel/svm/svm_texture.h @@ -213,14 +213,17 @@ __device float noise_wave(NodeWaveType wave, float a) /* Turbulence */ -__device_noinline float noise_turbulence(float3 p, NodeNoiseBasis basis, int octaves, int hard) +__device_noinline float noise_turbulence(float3 p, NodeNoiseBasis basis, float octaves, int hard) { float fscale = 1.0f; float amp = 1.0f; float sum = 0.0f; - int i; + int i, n; - for(i = 0; i <= octaves; i++) { + octaves = clamp(octaves, 0.0f, 16.0f); + n= (int)octaves; + + for(i = 0; i <= n; i++) { float t = noise_basis(fscale*p, basis); if(hard) @@ -231,9 +234,25 @@ __device_noinline float noise_turbulence(float3 p, NodeNoiseBasis basis, int oct fscale *= 2.0f; } - sum *= ((float)(1 << octaves)/(float)((1 << (octaves+1)) - 1)); + float rmd = octaves - floor(octaves); + + if(rmd != 0.0f) { + float t = noise_basis(fscale*p, basis); + + if(hard) + t = fabsf(2.0f*t - 1.0f); + + float sum2 = sum + t*amp; + + sum *= ((float)(1 << n)/(float)((1 << (n+1)) - 1)); + sum2 *= ((float)(1 << (n+1))/(float)((1 << (n+2)) - 1)); - return sum; + return (1.0f - rmd)*sum + rmd*sum2; + } + else { + sum *= ((float)(1 << n)/(float)((1 << (n+1)) - 1)); + return sum; + } } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index baec3d7ac6e..89fc413c539 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -44,8 +44,6 @@ typedef enum NodeType { NODE_CLOSURE_WEIGHT = 500, NODE_MIX_CLOSURE = 600, NODE_JUMP = 700, - NODE_TEX_NOISE_F = 800, - NODE_TEX_NOISE_V = 900, NODE_TEX_IMAGE = 1000, NODE_TEX_SKY = 1100, NODE_GEOMETRY = 1200, @@ -57,15 +55,12 @@ typedef enum NodeType { NODE_CONVERT = 1900, NODE_FRESNEL = 2000, NODE_EMISSION_WEIGHT = 2100, - NODE_TEX_BLEND = 2200, + NODE_TEX_GRADIENT = 2200, NODE_TEX_VORONOI = 2300, NODE_TEX_MUSGRAVE = 2400, - NODE_TEX_MARBLE = 2500, + NODE_TEX_WAVE = 2500, NODE_TEX_MAGIC = 2600, - NODE_TEX_STUCCI = 2700, - NODE_TEX_DISTORTED_NOISE = 2800, - NODE_TEX_WOOD = 2900, - NODE_TEX_CLOUDS = 3000, + NODE_TEX_NOISE = 3000, NODE_SHADER_JUMP = 3100, NODE_SET_DISPLACEMENT = 3200, NODE_GEOMETRY_BUMP_DX = 3300, @@ -83,7 +78,7 @@ typedef enum NodeType { NODE_ATTR_BUMP_DY = 4500, NODE_TEX_ENVIRONMENT = 4600, NODE_CLOSURE_HOLDOUT = 4700, - NODE_BLEND_WEIGHT = 4800, + NODE_LAYER_WEIGHT = 4800, NODE_CLOSURE_VOLUME = 4900 } NodeType; @@ -211,10 +206,8 @@ typedef enum NodeMusgraveType { } NodeMusgraveType; typedef enum NodeWoodType { - NODE_WOOD_BANDS, - NODE_WOOD_RINGS, - NODE_WOOD_BAND_NOISE, - NODE_WOOD_RING_NOISE + NODE_WAVE_BANDS, + NODE_WAVE_RINGS } NodeWoodType; typedef enum NodeBlendType { @@ -246,14 +239,12 @@ typedef enum NodeStucciType { typedef enum NodeVoronoiColoring { NODE_VORONOI_INTENSITY, - NODE_VORONOI_POSITION, - NODE_VORONOI_POSITION_OUTLINE, - NODE_VORONOI_POSITION_OUTLINE_INTENSITY + NODE_VORONOI_CELLS } NodeVoronoiColoring; typedef enum NodeBlendWeightType { - NODE_BLEND_WEIGHT_FRESNEL, - NODE_BLEND_WEIGHT_FACING + NODE_LAYER_WEIGHT_FRESNEL, + NODE_LAYER_WEIGHT_FACING } NodeBlendWeightType; typedef enum ShaderType { diff --git a/intern/cycles/kernel/svm/svm_voronoi.h b/intern/cycles/kernel/svm/svm_voronoi.h index 36965959cc2..f5ee7851a51 100644 --- a/intern/cycles/kernel/svm/svm_voronoi.h +++ b/intern/cycles/kernel/svm/svm_voronoi.h @@ -20,50 +20,25 @@ CCL_NAMESPACE_BEGIN /* Voronoi */ -__device_noinline float4 svm_voronoi(NodeDistanceMetric distance_metric, NodeVoronoiColoring coloring, - float weight1, float weight2, float weight3, float weight4, - float exponent, float intensity, float size, float3 p) +__device_noinline float4 svm_voronoi(NodeVoronoiColoring coloring, float scale, float3 p) { - float aw1 = fabsf(weight1); - float aw2 = fabsf(weight2); - float aw3 = fabsf(weight3); - float aw4 = fabsf(weight4); - float sc = (aw1 + aw2 + aw3 + aw4); - - if(sc != 0.0f) - sc = intensity/sc; - /* compute distance and point coordinate of 4 nearest neighbours */ float da[4]; float3 pa[4]; - voronoi(p/size, distance_metric, exponent, da, pa); + voronoi(p*scale, NODE_VORONOI_DISTANCE_SQUARED, 1.0f, da, pa); - /* Scalar output */ - float fac = sc * fabsf(weight1*da[0] + weight2*da[1] + weight3*da[2] + weight4*da[3]); + /* output */ + float fac; float3 color; - /* colored output */ if(coloring == NODE_VORONOI_INTENSITY) { + fac = fabsf(da[0]); color = make_float3(fac, fac, fac); } else { - color = aw1*cellnoise_color(pa[0]); - color += aw2*cellnoise_color(pa[1]); - color += aw3*cellnoise_color(pa[2]); - color += aw4*cellnoise_color(pa[3]); - - if(coloring != NODE_VORONOI_POSITION) { - float t1 = min((da[1] - da[0])*10.0f, 1.0f); - - if(coloring == NODE_VORONOI_POSITION_OUTLINE_INTENSITY) - color *= t1*fac; - else if(coloring == NODE_VORONOI_POSITION_OUTLINE) - color *= t1*sc; - } - else { - color *= sc; - } + color = cellnoise_color(pa[0]); + fac= average(color); } return make_float4(color.x, color.y, color.z, fac); @@ -71,31 +46,15 @@ __device_noinline float4 svm_voronoi(NodeDistanceMetric distance_metric, NodeVor __device void svm_node_tex_voronoi(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) { - uint4 node2 = read_node(kg, offset); - uint4 node3 = read_node(kg, offset); + uint coloring = node.y; + uint scale_offset, co_offset, fac_offset, color_offset; - uint distance_metric, coloring, exponent_offset; - uint size_offset, co_offset, fac_offset, color_offset; - uint weight1_offset, weight2_offset, weight3_offset, weight4_offset; - - decode_node_uchar4(node.y, &distance_metric, &coloring, &exponent_offset, NULL); - decode_node_uchar4(node.z, &size_offset, &co_offset, &fac_offset, &color_offset); - decode_node_uchar4(node.w, &weight1_offset, &weight2_offset, &weight3_offset, &weight4_offset); + decode_node_uchar4(node.z, &scale_offset, &co_offset, &fac_offset, &color_offset); float3 co = stack_load_float3(stack, co_offset); - float weight1 = stack_load_float_default(stack, weight1_offset, node2.x); - float weight2 = stack_load_float_default(stack, weight2_offset, node2.y); - float weight3 = stack_load_float_default(stack, weight3_offset, node2.z); - float weight4 = stack_load_float_default(stack, weight4_offset, node2.w); - float exponent = stack_load_float_default(stack, exponent_offset, node3.x); - float size = stack_load_float_default(stack, size_offset, node3.y); - - exponent = fmaxf(exponent, 1e-5f); - size = nonzerof(size, 1e-5f); + float scale = stack_load_float_default(stack, scale_offset, node.w); - float4 result = svm_voronoi((NodeDistanceMetric)distance_metric, - (NodeVoronoiColoring)coloring, - weight1, weight2, weight3, weight4, exponent, 1.0f, size, co); + float4 result = svm_voronoi((NodeVoronoiColoring)coloring, scale, co); float3 color = make_float3(result.x, result.y, result.z); float f = result.w; diff --git a/intern/cycles/kernel/svm/svm_wave.h b/intern/cycles/kernel/svm/svm_wave.h new file mode 100644 index 00000000000..8f2131156c4 --- /dev/null +++ b/intern/cycles/kernel/svm/svm_wave.h @@ -0,0 +1,65 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +CCL_NAMESPACE_BEGIN + +/* Marble */ + +__device_noinline float svm_wave(NodeWoodType type, float3 p, float scale, float detail, float distortion, float dscale) +{ + float w, n; + + p *= scale; + + if(type == NODE_WAVE_BANDS) + n= (p.x + p.x + p.z)*10.0f; + else /* if(type == NODE_WAVE_RINGS) */ + n= len(p)*20.0f; + + if(distortion != 0.0f) + n += distortion * noise_turbulence(p*dscale, NODE_NOISE_PERLIN, detail, 0); + + w = noise_wave(NODE_WAVE_SINE, n); + + return w; +} + +__device void svm_node_tex_wave(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) +{ + uint4 node2 = read_node(kg, offset); + + uint type; + uint co_offset, scale_offset, detail_offset, dscale_offset, distortion_offset, color_offset, fac_offset; + + decode_node_uchar4(node.y, &type, &color_offset, &fac_offset, &dscale_offset); + decode_node_uchar4(node.z, &co_offset, &scale_offset, &detail_offset, &distortion_offset); + + float3 co = stack_load_float3(stack, co_offset); + float scale = stack_load_float_default(stack, scale_offset, node2.x); + float detail = stack_load_float_default(stack, detail_offset, node2.y); + float distortion = stack_load_float_default(stack, distortion_offset, node2.z); + float dscale = stack_load_float_default(stack, dscale_offset, node2.w); + + float f = svm_wave((NodeWoodType)type, co, scale, detail, distortion, dscale); + + if(stack_valid(fac_offset)) stack_store_float(stack, fac_offset, f); + if(stack_valid(color_offset)) stack_store_float3(stack, color_offset, make_float3(f, f, f)); +} + +CCL_NAMESPACE_END + diff --git a/intern/cycles/kernel/svm/svm_wood.h b/intern/cycles/kernel/svm/svm_wood.h deleted file mode 100644 index 0f22e633766..00000000000 --- a/intern/cycles/kernel/svm/svm_wood.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2011, Blender Foundation. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -CCL_NAMESPACE_BEGIN - -/* Wood */ - -__device_noinline float svm_wood(float3 p, float size, NodeWoodType type, NodeWaveType wave, NodeNoiseBasis basis, uint hard, float turb) -{ - float x = p.x; - float y = p.y; - float z = p.z; - - if(type == NODE_WOOD_BANDS) { - return noise_wave(wave, (x + y + z)*10.0f); - } - else if(type == NODE_WOOD_RINGS) { - return noise_wave(wave, sqrt(x*x + y*y + z*z)*20.0f); - } - else if (type == NODE_WOOD_BAND_NOISE) { - float wi = turb*noise_basis_hard(p/size, basis, hard); - return noise_wave(wave, (x + y + z)*10.0f + wi); - } - else if (type == NODE_WOOD_RING_NOISE) { - float wi = turb*noise_basis_hard(p/size, basis, hard); - return noise_wave(wave, sqrt(x*x + y*y + z*z)*20.0f + wi); - } - - return 0.0f; -} - -__device void svm_node_tex_wood(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) -{ - uint4 node2 = read_node(kg, offset); - - uint type, wave, basis, hard; - uint co_offset, size_offset, turbulence_offset, fac_offset; - - decode_node_uchar4(node.y, &type, &wave, &basis, &hard); - decode_node_uchar4(node.z, &co_offset, &size_offset, &turbulence_offset, &fac_offset); - - float3 co = stack_load_float3(stack, co_offset); - float size = stack_load_float_default(stack, size_offset, node2.y); - float turbulence = stack_load_float_default(stack, turbulence_offset, node2.z); - size = nonzerof(size, 1e-5f); - - float f = svm_wood(co, size, (NodeWoodType)type, (NodeWaveType)wave, - (NodeNoiseBasis)basis, hard, turbulence); - - stack_store_float(stack, fac_offset, f); -} - -CCL_NAMESPACE_END - diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 56d5bdf77ba..f934b703103 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -353,45 +353,9 @@ void SkyTextureNode::compile(OSLCompiler& compiler) compiler.add(this, "node_sky_texture"); } -/* Noise Texture */ - -NoiseTextureNode::NoiseTextureNode() -: TextureNode("noise_texture") -{ - add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED); - add_output("Color", SHADER_SOCKET_COLOR); - add_output("Fac", SHADER_SOCKET_FLOAT); -} - -void NoiseTextureNode::compile(SVMCompiler& compiler) -{ - ShaderInput *vector_in = input("Vector"); - ShaderOutput *color_out = output("Color"); - ShaderOutput *fac_out = output("Fac"); - - if(!color_out->links.empty() || !fac_out->links.empty()) - if(!tex_mapping.skip()) - tex_mapping.compile(compiler, vector_in->stack_offset, vector_in->stack_offset); - - if(!color_out->links.empty()) { - compiler.stack_assign(color_out); - compiler.add_node(NODE_TEX_NOISE_V, vector_in->stack_offset, color_out->stack_offset); - } - - if(!fac_out->links.empty()) { - compiler.stack_assign(fac_out); - compiler.add_node(NODE_TEX_NOISE_F, vector_in->stack_offset, fac_out->stack_offset); - } -} - -void NoiseTextureNode::compile(OSLCompiler& compiler) -{ - compiler.add(this, "node_noise_texture"); -} +/* Gradient Texture */ -/* Blend Texture */ - -static ShaderEnum blend_progression_init() +static ShaderEnum gradient_type_init() { ShaderEnum enm; @@ -406,32 +370,22 @@ static ShaderEnum blend_progression_init() return enm; } -static ShaderEnum blend_axis_init() -{ - ShaderEnum enm; - - enm.insert("Horizontal", NODE_BLEND_HORIZONTAL); - enm.insert("Vertical", NODE_BLEND_VERTICAL); - - return enm; -} - -ShaderEnum BlendTextureNode::progression_enum = blend_progression_init(); -ShaderEnum BlendTextureNode::axis_enum = blend_axis_init(); +ShaderEnum GradientTextureNode::type_enum = gradient_type_init(); -BlendTextureNode::BlendTextureNode() -: TextureNode("blend_texture") +GradientTextureNode::GradientTextureNode() +: TextureNode("gradient_texture") { - progression = ustring("Linear"); - axis = ustring("Horizontal"); + type = ustring("Linear"); add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED); + add_output("Color", SHADER_SOCKET_COLOR); add_output("Fac", SHADER_SOCKET_FLOAT); } -void BlendTextureNode::compile(SVMCompiler& compiler) +void GradientTextureNode::compile(SVMCompiler& compiler) { ShaderInput *vector_in = input("Vector"); + ShaderOutput *color_out = output("Color"); ShaderOutput *fac_out = output("Fac"); if(vector_in->link) compiler.stack_assign(vector_in); @@ -439,127 +393,91 @@ void BlendTextureNode::compile(SVMCompiler& compiler) if(!tex_mapping.skip()) tex_mapping.compile(compiler, vector_in->stack_offset, vector_in->stack_offset); - compiler.stack_assign(fac_out); - compiler.add_node(NODE_TEX_BLEND, - compiler.encode_uchar4(progression_enum[progression], axis_enum[axis]), - vector_in->stack_offset, fac_out->stack_offset); -} + if(!fac_out->links.empty()) + compiler.stack_assign(fac_out); + if(!color_out->links.empty()) + compiler.stack_assign(color_out); -void BlendTextureNode::compile(OSLCompiler& compiler) -{ - compiler.parameter("Progression", progression); - compiler.parameter("Axis", axis); - compiler.add(this, "node_blend_texture"); + compiler.add_node(NODE_TEX_GRADIENT, + compiler.encode_uchar4(type_enum[type], vector_in->stack_offset, fac_out->stack_offset, color_out->stack_offset)); } -/* Clouds Texture */ - -static ShaderEnum noise_basis_init() +void GradientTextureNode::compile(OSLCompiler& compiler) { - ShaderEnum enm; - - enm.insert("Perlin", NODE_NOISE_PERLIN); - enm.insert("Voronoi F1", NODE_NOISE_VORONOI_F1); - enm.insert("Voronoi F2", NODE_NOISE_VORONOI_F2); - enm.insert("Voronoi F3", NODE_NOISE_VORONOI_F3); - enm.insert("Voronoi F4", NODE_NOISE_VORONOI_F4); - enm.insert("Voronoi F2-F1", NODE_NOISE_VORONOI_F2_F1); - enm.insert("Voronoi Crackle", NODE_NOISE_VORONOI_CRACKLE); - enm.insert("Cell Noise", NODE_NOISE_CELL_NOISE); - - return enm; + compiler.parameter("Type", type); + compiler.add(this, "node_gradient_texture"); } -ShaderEnum CloudsTextureNode::basis_enum = noise_basis_init(); +/* Noise Texture */ -CloudsTextureNode::CloudsTextureNode() -: TextureNode("clouds_texture") +NoiseTextureNode::NoiseTextureNode() +: TextureNode("noise_texture") { - basis = ustring("Perlin"); - hard = false; - depth = 2; - - add_input("Size", SHADER_SOCKET_FLOAT, 0.25f); add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED); + add_input("Scale", SHADER_SOCKET_FLOAT, 1.0f); + add_input("Detail", SHADER_SOCKET_FLOAT, 2.0f); + add_input("Distortion", SHADER_SOCKET_FLOAT, 0.0f); add_output("Color", SHADER_SOCKET_COLOR); add_output("Fac", SHADER_SOCKET_FLOAT); } -void CloudsTextureNode::compile(SVMCompiler& compiler) +void NoiseTextureNode::compile(SVMCompiler& compiler) { - ShaderInput *size_in = input("Size"); + ShaderInput *distortion_in = input("Distortion"); + ShaderInput *detail_in = input("Detail"); + ShaderInput *scale_in = input("Scale"); ShaderInput *vector_in = input("Vector"); ShaderOutput *color_out = output("Color"); ShaderOutput *fac_out = output("Fac"); if(vector_in->link) compiler.stack_assign(vector_in); - if(size_in->link) compiler.stack_assign(size_in); + if(scale_in->link) compiler.stack_assign(scale_in); + if(detail_in->link) compiler.stack_assign(detail_in); + if(distortion_in->link) compiler.stack_assign(distortion_in); if(!tex_mapping.skip()) tex_mapping.compile(compiler, vector_in->stack_offset, vector_in->stack_offset); - compiler.stack_assign(color_out); - compiler.stack_assign(fac_out); + if(!fac_out->links.empty()) + compiler.stack_assign(fac_out); + if(!color_out->links.empty()) + compiler.stack_assign(color_out); - compiler.add_node(NODE_TEX_CLOUDS, - compiler.encode_uchar4(basis_enum[basis], hard, depth), - compiler.encode_uchar4(size_in->stack_offset, vector_in->stack_offset, fac_out->stack_offset, color_out->stack_offset), - __float_as_int(size_in->value.x)); + compiler.add_node(NODE_TEX_NOISE, + compiler.encode_uchar4(vector_in->stack_offset, scale_in->stack_offset, detail_in->stack_offset, distortion_in->stack_offset), + compiler.encode_uchar4(color_out->stack_offset, fac_out->stack_offset)); + compiler.add_node( + __float_as_int(scale_in->value.x), + __float_as_int(detail_in->value.x), + __float_as_int(distortion_in->value.x)); } -void CloudsTextureNode::compile(OSLCompiler& compiler) +void NoiseTextureNode::compile(OSLCompiler& compiler) { - compiler.parameter("Hard", (hard)? 1: 0); - compiler.parameter("Depth", depth); - compiler.parameter("Basis", basis); - compiler.add(this, "node_clouds_texture"); + compiler.add(this, "node_noise_texture"); } /* Voronoi Texture */ -static ShaderEnum distance_metric_init() -{ - ShaderEnum enm; - - enm.insert("Distance Squared", NODE_VORONOI_DISTANCE_SQUARED); - enm.insert("Actual Distance", NODE_VORONOI_ACTUAL_DISTANCE); - enm.insert("Manhattan", NODE_VORONOI_MANHATTAN); - enm.insert("Chebychev", NODE_VORONOI_CHEBYCHEV); - enm.insert("Minkovsky 1/2", NODE_VORONOI_MINKOVSKY_H); - enm.insert("Minkovsky 4", NODE_VORONOI_MINKOVSKY_4); - enm.insert("Minkovsky", NODE_VORONOI_MINKOVSKY); - - return enm; -} - static ShaderEnum voronoi_coloring_init() { ShaderEnum enm; enm.insert("Intensity", NODE_VORONOI_INTENSITY); - enm.insert("Position", NODE_VORONOI_POSITION); - enm.insert("Position and Outline", NODE_VORONOI_POSITION_OUTLINE); - enm.insert("Position, Outline, and Intensity", NODE_VORONOI_POSITION_OUTLINE_INTENSITY); + enm.insert("Cells", NODE_VORONOI_CELLS); return enm; } -ShaderEnum VoronoiTextureNode::distance_metric_enum = distance_metric_init(); ShaderEnum VoronoiTextureNode::coloring_enum = voronoi_coloring_init(); VoronoiTextureNode::VoronoiTextureNode() : TextureNode("voronoi_texture") { - distance_metric = ustring("Actual Distance"); coloring = ustring("Intensity"); - add_input("Size", SHADER_SOCKET_FLOAT, 0.25f); - add_input("Weight1", SHADER_SOCKET_FLOAT, 1.0f); - add_input("Weight2", SHADER_SOCKET_FLOAT, 0.0f); - add_input("Weight3", SHADER_SOCKET_FLOAT, 0.0f); - add_input("Weight4", SHADER_SOCKET_FLOAT, 0.0f); - add_input("Exponent", SHADER_SOCKET_FLOAT, 2.5f); + add_input("Scale", SHADER_SOCKET_FLOAT, 1.0f); add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED); add_output("Color", SHADER_SOCKET_COLOR); @@ -568,23 +486,13 @@ VoronoiTextureNode::VoronoiTextureNode() void VoronoiTextureNode::compile(SVMCompiler& compiler) { - ShaderInput *weight1_in = input("Weight1"); - ShaderInput *weight2_in = input("Weight2"); - ShaderInput *weight3_in = input("Weight3"); - ShaderInput *weight4_in = input("Weight4"); - ShaderInput *exponent_in = input("Exponent"); - ShaderInput *size_in = input("Size"); + ShaderInput *scale_in = input("Scale"); ShaderInput *vector_in = input("Vector"); ShaderOutput *color_out = output("Color"); ShaderOutput *fac_out = output("Fac"); - if(weight1_in->link) compiler.stack_assign(weight1_in); - if(weight2_in->link) compiler.stack_assign(weight2_in); - if(weight3_in->link) compiler.stack_assign(weight3_in); - if(weight4_in->link) compiler.stack_assign(weight4_in); - if(exponent_in->link) compiler.stack_assign(exponent_in); if(vector_in->link) compiler.stack_assign(vector_in); - if(size_in->link) compiler.stack_assign(size_in); + if(scale_in->link) compiler.stack_assign(scale_in); if(!tex_mapping.skip()) tex_mapping.compile(compiler, vector_in->stack_offset, vector_in->stack_offset); @@ -593,20 +501,13 @@ void VoronoiTextureNode::compile(SVMCompiler& compiler) compiler.stack_assign(fac_out); compiler.add_node(NODE_TEX_VORONOI, - compiler.encode_uchar4(distance_metric_enum[distance_metric], coloring_enum[coloring], exponent_in->stack_offset), - compiler.encode_uchar4(size_in->stack_offset, vector_in->stack_offset, fac_out->stack_offset, color_out->stack_offset), - compiler.encode_uchar4(weight1_in->stack_offset, weight2_in->stack_offset, weight3_in->stack_offset, weight4_in->stack_offset)); - compiler.add_node(__float_as_int(weight1_in->value.x), - __float_as_int(weight2_in->value.x), - __float_as_int(weight3_in->value.x), - __float_as_int(weight4_in->value.x)); - compiler.add_node(__float_as_int(exponent_in->value.x), - __float_as_int(size_in->value.x)); + coloring_enum[coloring], + compiler.encode_uchar4(scale_in->stack_offset, vector_in->stack_offset, fac_out->stack_offset, color_out->stack_offset), + __float_as_int(scale_in->value.x)); } void VoronoiTextureNode::compile(OSLCompiler& compiler) { - compiler.parameter("DistanceMetric", distance_metric); compiler.parameter("Coloring", coloring); compiler.add(this, "node_voronoi_texture"); } @@ -627,141 +528,138 @@ static ShaderEnum musgrave_type_init() } ShaderEnum MusgraveTextureNode::type_enum = musgrave_type_init(); -ShaderEnum MusgraveTextureNode::basis_enum = noise_basis_init(); MusgraveTextureNode::MusgraveTextureNode() : TextureNode("musgrave_texture") { type = ustring("fBM"); - basis = ustring("Perlin"); + add_input("Scale", SHADER_SOCKET_FLOAT, 1.0f); + add_input("Detail", SHADER_SOCKET_FLOAT, 2.0f); + add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED); add_input("Dimension", SHADER_SOCKET_FLOAT, 2.0f); add_input("Lacunarity", SHADER_SOCKET_FLOAT, 1.0f); - add_input("Octaves", SHADER_SOCKET_FLOAT, 2.0f); add_input("Offset", SHADER_SOCKET_FLOAT, 0.0f); add_input("Gain", SHADER_SOCKET_FLOAT, 1.0f); - add_input("Size", SHADER_SOCKET_FLOAT, 0.25f); - add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED); add_output("Fac", SHADER_SOCKET_FLOAT); + add_output("Color", SHADER_SOCKET_COLOR); } void MusgraveTextureNode::compile(SVMCompiler& compiler) { ShaderInput *vector_in = input("Vector"); + ShaderInput *scale_in = input("Scale"); ShaderInput *dimension_in = input("Dimension"); ShaderInput *lacunarity_in = input("Lacunarity"); - ShaderInput *octaves_in = input("Octaves"); + ShaderInput *detail_in = input("Detail"); ShaderInput *offset_in = input("Offset"); ShaderInput *gain_in = input("Gain"); - ShaderInput *size_in = input("Size"); ShaderOutput *fac_out = output("Fac"); + ShaderOutput *color_out = output("Color"); if(vector_in->link) compiler.stack_assign(vector_in); if(dimension_in->link) compiler.stack_assign(dimension_in); if(lacunarity_in->link) compiler.stack_assign(lacunarity_in); - if(octaves_in->link) compiler.stack_assign(octaves_in); + if(detail_in->link) compiler.stack_assign(detail_in); if(offset_in->link) compiler.stack_assign(offset_in); if(gain_in->link) compiler.stack_assign(gain_in); - if(size_in->link) compiler.stack_assign(size_in); + if(scale_in->link) compiler.stack_assign(scale_in); if(!tex_mapping.skip()) tex_mapping.compile(compiler, vector_in->stack_offset, vector_in->stack_offset); - compiler.stack_assign(fac_out); + if(!fac_out->links.empty()) + compiler.stack_assign(fac_out); + if(!color_out->links.empty()) + compiler.stack_assign(color_out); + compiler.add_node(NODE_TEX_MUSGRAVE, - compiler.encode_uchar4(type_enum[type], basis_enum[basis], vector_in->stack_offset, fac_out->stack_offset), - compiler.encode_uchar4(dimension_in->stack_offset, lacunarity_in->stack_offset, octaves_in->stack_offset, offset_in->stack_offset), - compiler.encode_uchar4(gain_in->stack_offset, size_in->stack_offset)); + compiler.encode_uchar4(type_enum[type], vector_in->stack_offset, color_out->stack_offset, fac_out->stack_offset), + compiler.encode_uchar4(dimension_in->stack_offset, lacunarity_in->stack_offset, detail_in->stack_offset, offset_in->stack_offset), + compiler.encode_uchar4(gain_in->stack_offset, scale_in->stack_offset)); compiler.add_node(__float_as_int(dimension_in->value.x), __float_as_int(lacunarity_in->value.x), - __float_as_int(octaves_in->value.x), + __float_as_int(detail_in->value.x), __float_as_int(offset_in->value.x)); compiler.add_node(__float_as_int(gain_in->value.x), - __float_as_int(size_in->value.x)); + __float_as_int(scale_in->value.x)); } void MusgraveTextureNode::compile(OSLCompiler& compiler) { compiler.parameter("Type", type); - compiler.parameter("Basis", basis); compiler.add(this, "node_musgrave_texture"); } -/* Marble Texture */ +/* Wave Texture */ -static ShaderEnum marble_type_init() +static ShaderEnum wave_type_init() { ShaderEnum enm; - enm.insert("Soft", NODE_MARBLE_SOFT); - enm.insert("Sharp", NODE_MARBLE_SHARP); - enm.insert("Sharper", NODE_MARBLE_SHARPER); + enm.insert("Bands", NODE_WAVE_BANDS); + enm.insert("Rings", NODE_WAVE_RINGS); return enm; } -static ShaderEnum noise_wave_init() -{ - ShaderEnum enm; +ShaderEnum WaveTextureNode::type_enum = wave_type_init(); - enm.insert("Sine", NODE_WAVE_SINE); - enm.insert("Saw", NODE_WAVE_SAW); - enm.insert("Tri", NODE_WAVE_TRI); - - return enm; -} - -ShaderEnum MarbleTextureNode::type_enum = marble_type_init(); -ShaderEnum MarbleTextureNode::wave_enum = noise_wave_init(); -ShaderEnum MarbleTextureNode::basis_enum = noise_basis_init(); - -MarbleTextureNode::MarbleTextureNode() +WaveTextureNode::WaveTextureNode() : TextureNode("marble_texture") { - type = ustring("Soft"); - wave = ustring("Sine"); - basis = ustring("Perlin"); - hard = false; - depth = 2; + type = ustring("Bands"); - add_input("Size", SHADER_SOCKET_FLOAT, 0.25f); - add_input("Turbulence", SHADER_SOCKET_FLOAT, 5.0f); + add_input("Scale", SHADER_SOCKET_FLOAT, 1.0f); + add_input("Distortion", SHADER_SOCKET_FLOAT, 0.0f); + add_input("Detail", SHADER_SOCKET_FLOAT, 2.0f); + add_input("Detail Scale", SHADER_SOCKET_FLOAT, 1.0f); add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED); + add_output("Color", SHADER_SOCKET_COLOR); add_output("Fac", SHADER_SOCKET_FLOAT); } -void MarbleTextureNode::compile(SVMCompiler& compiler) +void WaveTextureNode::compile(SVMCompiler& compiler) { - ShaderInput *size_in = input("Size"); - ShaderInput *turbulence_in = input("Turbulence"); + ShaderInput *scale_in = input("Scale"); + ShaderInput *distortion_in = input("Distortion"); + ShaderInput *dscale_in = input("Detail Scale"); + ShaderInput *detail_in = input("Detail"); ShaderInput *vector_in = input("Vector"); ShaderOutput *fac_out = output("Fac"); + ShaderOutput *color_out = output("Color"); - if(size_in->link) compiler.stack_assign(size_in); - if(turbulence_in->link) compiler.stack_assign(turbulence_in); + if(scale_in->link) compiler.stack_assign(scale_in); + if(detail_in->link) compiler.stack_assign(detail_in); + if(distortion_in->link) compiler.stack_assign(distortion_in); + if(dscale_in->link) compiler.stack_assign(dscale_in); if(vector_in->link) compiler.stack_assign(vector_in); if(!tex_mapping.skip()) tex_mapping.compile(compiler, vector_in->stack_offset, vector_in->stack_offset); - compiler.stack_assign(fac_out); - compiler.add_node(NODE_TEX_MARBLE, - compiler.encode_uchar4(type_enum[type], wave_enum[wave], basis_enum[basis], hard), - compiler.encode_uchar4(depth), - compiler.encode_uchar4(size_in->stack_offset, turbulence_in->stack_offset, vector_in->stack_offset, fac_out->stack_offset)); - compiler.add_node(__float_as_int(size_in->value.x), __float_as_int(turbulence_in->value.x)); + if(!fac_out->links.empty()) + compiler.stack_assign(fac_out); + if(!color_out->links.empty()) + compiler.stack_assign(color_out); + + compiler.add_node(NODE_TEX_WAVE, + compiler.encode_uchar4(type_enum[type], color_out->stack_offset, fac_out->stack_offset, dscale_in->stack_offset), + compiler.encode_uchar4(vector_in->stack_offset, scale_in->stack_offset, detail_in->stack_offset, distortion_in->stack_offset)); + + compiler.add_node( + __float_as_int(scale_in->value.x), + __float_as_int(detail_in->value.x), + __float_as_int(distortion_in->value.x), + __float_as_int(dscale_in->value.x)); } -void MarbleTextureNode::compile(OSLCompiler& compiler) +void WaveTextureNode::compile(OSLCompiler& compiler) { compiler.parameter("Type", type); - compiler.parameter("Wave", wave); - compiler.parameter("Basis", basis); - compiler.parameter("Hard", (hard)? 1: 0); - compiler.parameter("Depth", depth); compiler.add(this, "node_marble_texture"); } @@ -773,205 +671,46 @@ MagicTextureNode::MagicTextureNode() { depth = 2; - add_input("Turbulence", SHADER_SOCKET_FLOAT, 5.0f); add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED); + add_input("Scale", SHADER_SOCKET_FLOAT, 5.0f); + add_input("Distortion", SHADER_SOCKET_FLOAT, 1.0f); + add_output("Color", SHADER_SOCKET_COLOR); + add_output("Fac", SHADER_SOCKET_FLOAT); } void MagicTextureNode::compile(SVMCompiler& compiler) { ShaderInput *vector_in = input("Vector"); - ShaderInput *turbulence_in = input("Turbulence"); + ShaderInput *scale_in = input("Scale"); + ShaderInput *distortion_in = input("Distortion"); ShaderOutput *color_out = output("Color"); - - if(vector_in->link) compiler.stack_assign(vector_in); - if(turbulence_in->link) compiler.stack_assign(turbulence_in); - - if(!tex_mapping.skip()) - tex_mapping.compile(compiler, vector_in->stack_offset, vector_in->stack_offset); - - compiler.stack_assign(color_out); - compiler.add_node(NODE_TEX_MAGIC, - compiler.encode_uchar4(depth, turbulence_in->stack_offset, vector_in->stack_offset, color_out->stack_offset), - __float_as_int(turbulence_in->value.x)); -} - -void MagicTextureNode::compile(OSLCompiler& compiler) -{ - compiler.parameter("Depth", depth); - compiler.add(this, "node_magic_texture"); -} - -/* Stucci Texture */ - -static ShaderEnum stucci_type_init() -{ - ShaderEnum enm; - - enm.insert("Plastic", NODE_STUCCI_PLASTIC); - enm.insert("Wall In", NODE_STUCCI_WALL_IN); - enm.insert("Wall Out", NODE_STUCCI_WALL_OUT); - - return enm; -} - -ShaderEnum StucciTextureNode::type_enum = stucci_type_init(); -ShaderEnum StucciTextureNode::basis_enum = noise_basis_init(); - -StucciTextureNode::StucciTextureNode() -: TextureNode("stucci_texture") -{ - type = ustring("Plastic"); - basis = ustring("Perlin"); - hard = false; - - add_input("Size", SHADER_SOCKET_FLOAT, 1.0f); - add_input("Turbulence", SHADER_SOCKET_FLOAT, 1.0f); - add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED); - - add_output("Fac", SHADER_SOCKET_FLOAT); -} - -void StucciTextureNode::compile(SVMCompiler& compiler) -{ - ShaderInput *size_in = input("Size"); - ShaderInput *turbulence_in = input("Turbulence"); - ShaderInput *vector_in = input("Vector"); ShaderOutput *fac_out = output("Fac"); - if(size_in->link) compiler.stack_assign(size_in); - if(turbulence_in->link) compiler.stack_assign(turbulence_in); if(vector_in->link) compiler.stack_assign(vector_in); - - if(!tex_mapping.skip()) - tex_mapping.compile(compiler, vector_in->stack_offset, vector_in->stack_offset); - - compiler.stack_assign(fac_out); - - compiler.add_node(NODE_TEX_STUCCI, - compiler.encode_uchar4(type_enum[type], basis_enum[basis], hard), - compiler.encode_uchar4(size_in->stack_offset, turbulence_in->stack_offset, - vector_in->stack_offset, fac_out->stack_offset)); - compiler.add_node(__float_as_int(size_in->value.x), - __float_as_int(turbulence_in->value.x)); -} - -void StucciTextureNode::compile(OSLCompiler& compiler) -{ - compiler.parameter("Type", type); - compiler.parameter("Basis", basis); - compiler.parameter("Hard", (hard)? 1: 0); - compiler.add(this, "node_stucci_texture"); -} - -/* Distorted Noise Texture */ - -ShaderEnum DistortedNoiseTextureNode::basis_enum = noise_basis_init(); - -DistortedNoiseTextureNode::DistortedNoiseTextureNode() -: TextureNode("distorted_noise_texture") -{ - basis = ustring("Perlin"); - distortion_basis = ustring("Perlin"); - - add_input("Size", SHADER_SOCKET_FLOAT, 0.25f); - add_input("Distortion", SHADER_SOCKET_FLOAT, 1.0f); - add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED); - - add_output("Fac", SHADER_SOCKET_FLOAT); -} - -void DistortedNoiseTextureNode::compile(SVMCompiler& compiler) -{ - ShaderInput *size_in = input("Size"); - ShaderInput *distortion_in = input("Distortion"); - ShaderInput *vector_in = input("Vector"); - ShaderOutput *fac_out = output("Fac"); - - if(size_in->link) compiler.stack_assign(size_in); if(distortion_in->link) compiler.stack_assign(distortion_in); - if(vector_in->link) compiler.stack_assign(vector_in); + if(scale_in->link) compiler.stack_assign(scale_in); if(!tex_mapping.skip()) tex_mapping.compile(compiler, vector_in->stack_offset, vector_in->stack_offset); - compiler.stack_assign(fac_out); + if(!fac_out->links.empty()) + compiler.stack_assign(fac_out); + if(!color_out->links.empty()) + compiler.stack_assign(color_out); - compiler.add_node(NODE_TEX_DISTORTED_NOISE, - compiler.encode_uchar4(basis_enum[basis], basis_enum[distortion_basis]), - compiler.encode_uchar4(size_in->stack_offset, distortion_in->stack_offset, vector_in->stack_offset, fac_out->stack_offset)); - compiler.add_node(__float_as_int(size_in->value.x), + compiler.add_node(NODE_TEX_MAGIC, + compiler.encode_uchar4(depth, color_out->stack_offset, fac_out->stack_offset), + compiler.encode_uchar4(vector_in->stack_offset, scale_in->stack_offset, distortion_in->stack_offset)); + compiler.add_node( + __float_as_int(scale_in->value.x), __float_as_int(distortion_in->value.x)); } -void DistortedNoiseTextureNode::compile(OSLCompiler& compiler) -{ - compiler.parameter("Basis", basis); - compiler.parameter("DistortionBasis", distortion_basis); - compiler.add(this, "node_distorted_noise_texture"); -} - -/* Wood Texture */ - -static ShaderEnum wood_type_init() -{ - ShaderEnum enm; - - enm.insert("Bands", NODE_WOOD_BANDS); - enm.insert("Rings", NODE_WOOD_RINGS); - enm.insert("Band Noise", NODE_WOOD_BAND_NOISE); - enm.insert("Ring Noise", NODE_WOOD_RING_NOISE); - - return enm; -} - -ShaderEnum WoodTextureNode::type_enum = wood_type_init(); -ShaderEnum WoodTextureNode::wave_enum = noise_wave_init(); -ShaderEnum WoodTextureNode::basis_enum = noise_basis_init(); - -WoodTextureNode::WoodTextureNode() -: TextureNode("wood_texture") -{ - type = ustring("Bands"); - wave = ustring("Sine"); - basis = ustring("Perlin"); - hard = false; - - add_input("Size", SHADER_SOCKET_FLOAT, 0.25f); - add_input("Turbulence", SHADER_SOCKET_FLOAT, 5.0f); - add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_GENERATED); - - add_output("Fac", SHADER_SOCKET_FLOAT); -} - -void WoodTextureNode::compile(SVMCompiler& compiler) -{ - ShaderInput *vector_in = input("Vector"); - ShaderInput *size_in = input("Size"); - ShaderInput *turbulence_in = input("Turbulence"); - ShaderOutput *fac_out = output("Fac"); - - if(vector_in->link) compiler.stack_assign(vector_in); - if(size_in->link) compiler.stack_assign(size_in); - if(turbulence_in->link) compiler.stack_assign(turbulence_in); - - if(!tex_mapping.skip()) - tex_mapping.compile(compiler, vector_in->stack_offset, vector_in->stack_offset); - - compiler.stack_assign(fac_out); - compiler.add_node(NODE_TEX_WOOD, - compiler.encode_uchar4(type_enum[type], wave_enum[wave], basis_enum[basis], hard), - compiler.encode_uchar4(vector_in->stack_offset, size_in->stack_offset, turbulence_in->stack_offset, fac_out->stack_offset)); - compiler.add_node(NODE_TEX_WOOD, make_float3(size_in->value.x, turbulence_in->value.x, 0.0f)); -} - -void WoodTextureNode::compile(OSLCompiler& compiler) +void MagicTextureNode::compile(OSLCompiler& compiler) { - compiler.parameter("Type", type); - compiler.parameter("Wave", wave); - compiler.parameter("Basis", basis); - compiler.parameter("Hard", (hard)? 1: 0); - compiler.add(this, "node_wood_texture"); + compiler.parameter("Depth", depth); + compiler.add(this, "node_magic_texture"); } /* Mapping */ @@ -1986,8 +1725,8 @@ void FresnelNode::compile(OSLCompiler& compiler) /* Blend Weight */ -BlendWeightNode::BlendWeightNode() -: ShaderNode("BlendWeight") +LayerWeightNode::LayerWeightNode() +: ShaderNode("LayerWeight") { add_input("Normal", SHADER_SOCKET_NORMAL, ShaderInput::NORMAL, true); add_input("Blend", SHADER_SOCKET_FLOAT, 0.5f); @@ -1996,7 +1735,7 @@ BlendWeightNode::BlendWeightNode() add_output("Facing", SHADER_SOCKET_FLOAT); } -void BlendWeightNode::compile(SVMCompiler& compiler) +void LayerWeightNode::compile(SVMCompiler& compiler) { ShaderInput *blend_in = input("Blend"); @@ -2006,21 +1745,21 @@ void BlendWeightNode::compile(SVMCompiler& compiler) ShaderOutput *fresnel_out = output("Fresnel"); if(!fresnel_out->links.empty()) { compiler.stack_assign(fresnel_out); - compiler.add_node(NODE_BLEND_WEIGHT, blend_in->stack_offset, __float_as_int(blend_in->value.x), - compiler.encode_uchar4(NODE_BLEND_WEIGHT_FRESNEL, fresnel_out->stack_offset)); + compiler.add_node(NODE_LAYER_WEIGHT, blend_in->stack_offset, __float_as_int(blend_in->value.x), + compiler.encode_uchar4(NODE_LAYER_WEIGHT_FRESNEL, fresnel_out->stack_offset)); } ShaderOutput *facing_out = output("Facing"); if(!facing_out->links.empty()) { compiler.stack_assign(facing_out); - compiler.add_node(NODE_BLEND_WEIGHT, blend_in->stack_offset, __float_as_int(blend_in->value.x), - compiler.encode_uchar4(NODE_BLEND_WEIGHT_FACING, facing_out->stack_offset)); + compiler.add_node(NODE_LAYER_WEIGHT, blend_in->stack_offset, __float_as_int(blend_in->value.x), + compiler.encode_uchar4(NODE_LAYER_WEIGHT_FACING, facing_out->stack_offset)); } } -void BlendWeightNode::compile(OSLCompiler& compiler) +void LayerWeightNode::compile(OSLCompiler& compiler) { - compiler.add(this, "node_blend_weight"); + compiler.add(this, "node_layer_height"); } /* Output */ diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index 09b565b5043..d9cbd7ff589 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -97,41 +97,25 @@ public: SHADER_NODE_CLASS(OutputNode) }; -class NoiseTextureNode : public TextureNode { -public: - SHADER_NODE_CLASS(NoiseTextureNode) -}; - -class BlendTextureNode : public TextureNode { +class GradientTextureNode : public TextureNode { public: - SHADER_NODE_CLASS(BlendTextureNode) + SHADER_NODE_CLASS(GradientTextureNode) - ustring progression; - ustring axis; - - static ShaderEnum progression_enum; - static ShaderEnum axis_enum; + ustring type; + static ShaderEnum type_enum; }; -class CloudsTextureNode : public TextureNode { +class NoiseTextureNode : public TextureNode { public: - SHADER_NODE_CLASS(CloudsTextureNode) - - bool hard; - int depth; - ustring basis; - - static ShaderEnum basis_enum; + SHADER_NODE_CLASS(NoiseTextureNode) }; class VoronoiTextureNode : public TextureNode { public: SHADER_NODE_CLASS(VoronoiTextureNode) - ustring distance_metric; ustring coloring; - static ShaderEnum distance_metric_enum; static ShaderEnum coloring_enum; }; @@ -140,25 +124,16 @@ public: SHADER_NODE_CLASS(MusgraveTextureNode) ustring type; - ustring basis; static ShaderEnum type_enum; - static ShaderEnum basis_enum; }; -class MarbleTextureNode : public TextureNode { +class WaveTextureNode : public TextureNode { public: - SHADER_NODE_CLASS(MarbleTextureNode) + SHADER_NODE_CLASS(WaveTextureNode) ustring type; - ustring wave; - ustring basis; - bool hard; - int depth; - static ShaderEnum type_enum; - static ShaderEnum wave_enum; - static ShaderEnum basis_enum; }; class MagicTextureNode : public TextureNode { @@ -168,41 +143,6 @@ public: int depth; }; -class StucciTextureNode : public TextureNode { -public: - SHADER_NODE_CLASS(StucciTextureNode) - - ustring type; - ustring basis; - bool hard; - - static ShaderEnum type_enum; - static ShaderEnum basis_enum; -}; - -class DistortedNoiseTextureNode : public TextureNode { -public: - SHADER_NODE_CLASS(DistortedNoiseTextureNode) - - ustring basis; - ustring distortion_basis; - static ShaderEnum basis_enum; -}; - -class WoodTextureNode : public TextureNode { -public: - SHADER_NODE_CLASS(WoodTextureNode) - - ustring type; - ustring wave; - ustring basis; - bool hard; - - static ShaderEnum type_enum; - static ShaderEnum wave_enum; - static ShaderEnum basis_enum; -}; - class MappingNode : public ShaderNode { public: SHADER_NODE_CLASS(MappingNode) @@ -365,9 +305,9 @@ public: SHADER_NODE_CLASS(FresnelNode) }; -class BlendWeightNode : public ShaderNode { +class LayerWeightNode : public ShaderNode { public: - SHADER_NODE_CLASS(BlendWeightNode) + SHADER_NODE_CLASS(LayerWeightNode) }; class MathNode : public ShaderNode { diff --git a/intern/cycles/util/util_hash.h b/intern/cycles/util/util_hash.h index af7ad7e06a1..16901dab38e 100644 --- a/intern/cycles/util/util_hash.h +++ b/intern/cycles/util/util_hash.h @@ -21,7 +21,7 @@ CCL_NAMESPACE_BEGIN -static unsigned int hash_int_2d(unsigned int kx, unsigned int ky) +static inline unsigned int hash_int_2d(unsigned int kx, unsigned int ky) { #define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k)))) @@ -44,7 +44,7 @@ static unsigned int hash_int_2d(unsigned int kx, unsigned int ky) #undef rot } -static unsigned int hash_int(unsigned int k) +static inline unsigned int hash_int(unsigned int k) { return hash_int_2d(k, 0); } |