Blender V5.3
gpu_shader_material_tex_wave.bsl.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8
10 float distortion,
11 float detail,
12 float detail_scale,
13 float detail_roughness,
14 float phase,
15 int wave_type,
16 int bands_dir,
17 int rings_dir,
18 int wave_profile)
19{
20 /* Prevent precision issues on unit coordinates. */
21 p = (p + 0.000001f) * 0.999999f;
22
23 float n;
24
25 if (wave_type == 0) { /* type bands */
26 if (bands_dir == 0) { /* X axis */
27 n = p.x * 20.0f;
28 }
29 else if (bands_dir == 1) { /* Y axis */
30 n = p.y * 20.0f;
31 }
32 else if (bands_dir == 2) { /* Z axis */
33 n = p.z * 20.0f;
34 }
35 else { /* Diagonal axis */
36 n = (p.x + p.y + p.z) * 10.0f;
37 }
38 }
39 else { /* type rings */
40 float3 rp = p;
41 if (rings_dir == 0) { /* X axis */
42 rp *= float3(0.0f, 1.0f, 1.0f);
43 }
44 else if (rings_dir == 1) { /* Y axis */
45 rp *= float3(1.0f, 0.0f, 1.0f);
46 }
47 else if (rings_dir == 2) { /* Z axis */
48 rp *= float3(1.0f, 1.0f, 0.0f);
49 }
50 /* else: Spherical */
51
52 n = length(rp) * 20.0f;
53 }
54
55 n += phase;
56
57 if (distortion != 0.0f) {
58 n += distortion *
59 (noise_fbm(p * detail_scale, detail, detail_roughness, 2.0f, 0.0f, 0.0f, true) * 2.0f -
60 1.0f);
61 }
62
63 if (wave_profile == 0) { /* profile sin */
64 return 0.5f + 0.5f * sin(n - M_PI_2);
65 }
66 if (wave_profile == 1) { /* profile saw */
67 n /= 2.0f * M_PI;
68 return n - floor(n);
69 }
70 /* profile tri */
71 n /= 2.0f * M_PI;
72 return abs(n - floor(n + 0.5f)) * 2.0f;
73}
74
75[[node]]
77 float scale,
78 float distortion,
79 float detail,
80 float detail_scale,
81 float detail_roughness,
82 float phase,
83 float wave_type,
84 float bands_dir,
85 float rings_dir,
86 float wave_profile,
87 float4 &color,
88 float &fac)
89{
90 float f;
91 f = calc_wave(co * scale,
92 distortion,
93 detail,
94 detail_scale,
95 detail_roughness,
96 phase,
97 int(wave_type),
98 int(bands_dir),
99 int(rings_dir),
100 int(wave_profile));
101
102 color = float4(f, f, f, 1.0f);
103 fac = f;
104}
#define M_PI_2
#define M_PI
#define sin
#define abs
#define floor
float length(VecOp< float, D >) RET
float noise_fbm(T co, float detail, float roughness, float lacunarity, float, float, bool normalize)
float calc_wave(float3 p, float distortion, float detail, float detail_scale, float detail_roughness, float phase, int wave_type, int bands_dir, int rings_dir, int wave_profile)
void node_tex_wave(float3 co, float scale, float distortion, float detail, float detail_scale, float detail_roughness, float phase, float wave_type, float bands_dir, float rings_dir, float wave_profile, float4 &color, float &fac)
float3x3 scale(float3x3 mat, float2 scale)
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136