Welcome to mirror list, hosted at ThFree Co, Russian Federation.

node_noise_texture.osl « shaders « kernel « cycles « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4b100dc21ad347815b6cbb94419961c5f09bb4ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright 2011-2013 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 "stdosl.h"
#include "vector2.h"
#include "vector4.h"
#include "node_texture.h"

#define vector3 point

/* To compute the color output of the noise, we either swizzle the
 * components, add a random offset {75, 125, 150}, or do both.
 */
float noise(float p, float detail, float distortion, output color Color)
{
  if (distortion != 0.0) {
    p += safe_noise(p + 13.5) * distortion;
  }

  float value = noise_turbulence(p, detail);
  Color = color(value, noise_turbulence(p + 75.0, detail), noise_turbulence(p + 125.0, detail));
  return value;
}

float noise(vector2 p, float detail, float distortion, output color Color)
{
  if (distortion != 0.0) {
    vector2 r;
    r.x = safe_noise(p + vector2(13.5, 13.5)) * distortion;
    r.y = safe_noise(p) * distortion;
    p += r;
  }

  float value = noise_turbulence(p, detail);
  Color = color(value,
                noise_turbulence(p + vector2(150.0, 125.0), detail),
                noise_turbulence(p + vector2(75.0, 125.0), detail));
  return value;
}

float noise(vector3 p, float detail, float distortion, output color Color)
{
  if (distortion != 0.0) {
    vector3 r, offset = vector3(13.5);
    r[0] = safe_noise(p + offset) * distortion;
    r[1] = safe_noise(p) * distortion;
    r[2] = safe_noise(p - offset) * distortion;
    p += r;
  }

  float value = noise_turbulence(p, detail);
  Color = color(value,
                noise_turbulence(vector3(p[1], p[0], p[2]), detail),
                noise_turbulence(vector3(p[1], p[2], p[0]), detail));
  return value;
}

float noise(vector4 p, float detail, float distortion, output color Color)
{
  if (distortion != 0.0) {
    vector4 r, offset = vector4(13.5, 13.5, 13.5, 13.5);
    r.x = safe_noise(p + offset) * distortion;
    r.y = safe_noise(p) * distortion;
    r.z = safe_noise(p - offset) * distortion;
    r.w = safe_noise(vector4(p.w, p.y, p.z, p.x) + offset) * distortion;
    p += r;
  }

  float value = noise_turbulence(p, detail);
  Color = color(value,
                noise_turbulence(vector4(p.y, p.w, p.z, p.x), detail),
                noise_turbulence(vector4(p.y, p.z, p.w, p.x), detail));
  return value;
}

shader node_noise_texture(int use_mapping = 0,
                          matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                          string dimensions = "3D",
                          vector3 Vector = vector3(0, 0, 0),
                          float W = 0.0,
                          float Scale = 5.0,
                          float Detail = 2.0,
                          float Distortion = 0.0,
                          output float Value = 0.0,
                          output color Color = 0.0)
{
  vector3 p = Vector;
  if (use_mapping)
    p = transform(mapping, p);
  p *= Scale;
  float w = W * Scale;

  if (dimensions == "1D")
    Value = noise(w, Detail, Distortion, Color);
  else if (dimensions == "2D")
    Value = noise(vector2(p[0], p[1]), Detail, Distortion, Color);
  else if (dimensions == "3D")
    Value = noise(p, Detail, Distortion, Color);
  else if (dimensions == "4D")
    Value = noise(vector4(p[0], p[1], p[2], w), Detail, Distortion, Color);
  else
    error("Unknown dimension!");
}