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

gpu_shader_material_math.glsl « material « shaders « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4fac770e8fe50acf5ad5ae6ee59c9122a4faeb2c (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
void math_add(float a, float b, out float result)
{
  result = a + b;
}

void math_subtract(float a, float b, out float result)
{
  result = a - b;
}

void math_multiply(float a, float b, out float result)
{
  result = a * b;
}

void math_divide(float a, float b, out float result)
{
  result = safe_divide(a, b);
}

void math_power(float a, float b, out float result)
{
  if (a >= 0.0) {
    result = compatible_pow(a, b);
  }
  else {
    float fraction = mod(abs(b), 1.0);
    if (fraction > 0.999 || fraction < 0.001) {
      result = compatible_pow(a, floor(b + 0.5));
    }
    else {
      result = 0.0;
    }
  }
}

void math_logarithm(float a, float b, out float result)
{
  result = (a > 0.0 && b > 0.0) ? log2(a) / log2(b) : 0.0;
}

void math_sqrt(float a, float b, out float result)
{
  result = (a > 0.0) ? sqrt(a) : 0.0;
}

void math_absolute(float a, float b, out float result)
{
  result = abs(a);
}

void math_minimum(float a, float b, out float result)
{
  result = min(a, b);
}

void math_maximum(float a, float b, out float result)
{
  result = max(a, b);
}

void math_less_than(float a, float b, out float result)
{
  result = (a < b) ? 1.0 : 0.0;
}

void math_greater_than(float a, float b, out float result)
{
  result = (a > b) ? 1.0 : 0.0;
}

void math_round(float a, float b, out float result)
{
  result = floor(a + 0.5);
}

void math_floor(float a, float b, out float result)
{
  result = floor(a);
}

void math_ceil(float a, float b, out float result)
{
  result = ceil(a);
}

void math_fraction(float a, float b, out float result)
{
  result = a - floor(a);
}

void math_modulo(float a, float b, out float result)
{
  result = c_mod(a, b);
}

void math_sine(float a, float b, out float result)
{
  result = sin(a);
}

void math_cosine(float a, float b, out float result)
{
  result = cos(a);
}

void math_tangent(float a, float b, out float result)
{
  result = tan(a);
}

void math_arcsine(float a, float b, out float result)
{
  result = (a <= 1.0 && a >= -1.0) ? asin(a) : 0.0;
}

void math_arccosine(float a, float b, out float result)
{
  result = (a <= 1.0 && a >= -1.0) ? acos(a) : 0.0;
}

void math_arctangent(float a, float b, out float result)
{
  result = atan(a);
}

void math_arctan2(float a, float b, out float result)
{
  result = atan(a, b);
}