-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellTexturing.gdshader
More file actions
46 lines (37 loc) · 1.27 KB
/
ShellTexturing.gdshader
File metadata and controls
46 lines (37 loc) · 1.27 KB
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
shader_type spatial;
uniform float shell_index;
uniform float shell_count;
uniform float frond_count;
uniform vec3 light_pos;
uniform float thickness;
uniform vec3 color;
uniform float height;
float random( vec2 p ) {
// from https://stackoverflow.com/questions/5149544/can-i-generate-a-random-number-inside-a-pixel-shader
vec2 K1 = vec2(
23.14069263277926, // e^pi (Gelfond's constant)
2.665144142690225 // 2^sqrt(2) (Gelfond–Schneider constant)
);
return fract( cos( dot(p,K1) ) * 12345.6789 );
}
void vertex() {
float h = shell_index / shell_count;
h = pow(h, 2);
VERTEX += NORMAL * h * height;
VERTEX.x += (cos(TIME * 1.5 - VERTEX.y) + sin(TIME - VERTEX.y) + 1.0) * pow(h, 2) * 0.05;
}
void fragment() {
vec2 newUV = UV * frond_count;
vec2 seedCoord = floor(newUV);
vec2 localUV = fract(newUV) * 2.0 - 1.0;
float distToCentre = length(localUV);
float h = shell_index / shell_count;
float rand = random(seedCoord);
if ( distToCentre > thickness * (rand - h) && shell_index > 0.0 ) discard;
float ndotl = clamp(dot(NORMAL, light_pos), 0, 1) * 0.5 + 0.5;
ndotl = ndotl * ndotl;
float ambientOcclusion = pow(h, 2.0);
ambientOcclusion += 0.5;
ambientOcclusion = clamp(ambientOcclusion, 0, 1);
ALBEDO = color * ndotl * ambientOcclusion;
}