svm_noisetex.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright 2011-2013 Blender Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. CCL_NAMESPACE_BEGIN
  17. /* Noise */
  18. ccl_device void svm_node_tex_noise(
  19. KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset)
  20. {
  21. uint co_offset, scale_offset, detail_offset, distortion_offset, fac_offset, color_offset;
  22. decode_node_uchar4(node.y, &co_offset, &scale_offset, &detail_offset, &distortion_offset);
  23. decode_node_uchar4(node.z, &color_offset, &fac_offset, NULL, NULL);
  24. uint4 node2 = read_node(kg, offset);
  25. float scale = stack_load_float_default(stack, scale_offset, node2.x);
  26. float detail = stack_load_float_default(stack, detail_offset, node2.y);
  27. float distortion = stack_load_float_default(stack, distortion_offset, node2.z);
  28. float3 p = stack_load_float3(stack, co_offset) * scale;
  29. int hard = 0;
  30. if (distortion != 0.0f) {
  31. float3 r, offset = make_float3(13.5f, 13.5f, 13.5f);
  32. r.x = noise(p + offset) * distortion;
  33. r.y = noise(p) * distortion;
  34. r.z = noise(p - offset) * distortion;
  35. p += r;
  36. }
  37. float f = noise_turbulence(p, detail, hard);
  38. if (stack_valid(fac_offset)) {
  39. stack_store_float(stack, fac_offset, f);
  40. }
  41. if (stack_valid(color_offset)) {
  42. float3 color = make_float3(f,
  43. noise_turbulence(make_float3(p.y, p.x, p.z), detail, hard),
  44. noise_turbulence(make_float3(p.y, p.z, p.x), detail, hard));
  45. stack_store_float3(stack, color_offset, color);
  46. }
  47. }
  48. CCL_NAMESPACE_END