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

gpu_shader_material_tex_wave.glsl « material « shaders « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 070f42a5e30ee5cd3290d05ab4d3f35405614670 (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
float calc_wave(vec3 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)
{
  /* Prevent precision issues on unit coordinates. */
  p = (p + 0.000001) * 0.999999;

  float n;

  if (wave_type == 0) {   /* type bands */
    if (bands_dir == 0) { /* X axis */
      n = p.x * 20.0;
    }
    else if (bands_dir == 1) { /* Y axis */
      n = p.y * 20.0;
    }
    else if (bands_dir == 2) { /* Z axis */
      n = p.z * 20.0;
    }
    else { /* Diagonal axis */
      n = (p.x + p.y + p.z) * 10.0;
    }
  }
  else { /* type rings */
    vec3 rp = p;
    if (rings_dir == 0) { /* X axis */
      rp *= vec3(0.0, 1.0, 1.0);
    }
    else if (rings_dir == 1) { /* Y axis */
      rp *= vec3(1.0, 0.0, 1.0);
    }
    else if (rings_dir == 2) { /* Z axis */
      rp *= vec3(1.0, 1.0, 0.0);
    }
    /* else: Spherical */

    n = length(rp) * 20.0;
  }

  n += phase;

  if (distortion != 0.0) {
    n += distortion * (fractal_noise(p * detail_scale, detail, detail_roughness) * 2.0 - 1.0);
  }

  if (wave_profile == 0) { /* profile sin */
    return 0.5 + 0.5 * sin(n - M_PI_2);
  }
  else if (wave_profile == 1) { /* profile saw */
    n /= 2.0 * M_PI;
    return n - floor(n);
  }
  else { /* profile tri */
    n /= 2.0 * M_PI;
    return abs(n - floor(n + 0.5)) * 2.0;
  }
}

void node_tex_wave(vec3 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,
                   out vec4 color,
                   out float fac)
{
  float f;
  f = calc_wave(co * scale,
                distortion,
                detail,
                detail_scale,
                detail_roughness,
                phase,
                int(wave_type),
                int(bands_dir),
                int(rings_dir),
                int(wave_profile));

  color = vec4(f, f, f, 1.0);
  fac = f;
}