-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTest_lmstudio.html
More file actions
148 lines (123 loc) · 4.28 KB
/
Copy pathTest_lmstudio.html
File metadata and controls
148 lines (123 loc) · 4.28 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
## 1. Recursive Ripple Rain Drops
Using nested Voronoi calls to simulate ripples spawning ripples:
```glsl
// Based on iq's Voronoi and recursive ripple ideas
vec2 hash2(vec2 p) {
return fract(sin(vec2(
dot(p, vec2(127.1, 311.7)),
dot(p, vec2(269.5, 183.3))
)) * 43758.5453);
}
float ripple(vec2 p, float t) {
float minDist = 1.0;
vec2 cell = floor(p);
vec2 offs = vec2(0.0);
// First pass: find nearest impact point
for (int j = -1; j <= 1; j++) {
for (int i = -1; i <= 1; i++) {
vec2 neighbor = vec2(float(i), float(j));
vec2 point = hash2(cell + neighbor);
point = 0.5 + 0.5 * sin(t + 6.2831 * point);
vec2 diff = neighbor + point - fract(p);
float dist = length(diff);
minDist = min(minDist, dist);
}
}
return minDist;
}
// Recursive ripple ring generation
float recursiveRipple(vec2 p, float t) {
float r = 0.0;
float scale = 1.0;
// Simulates recursion by layering scaled ripples
// Each layer is a "child" of the previous
for (int i = 0; i < 4; i++) {
float ring = abs(ripple(p * scale, t) - fract(t * 0.3));
ring = smoothstep(0.02, 0.0, ring);
r += ring * scale;
scale *= 1.5; // Each recursion step scales UV
}
return r;
}
```
---
## 2. Ray-Marched Rain with Recursive Reflections
Simulates rain droplets as tiny reflective spheres, with recursive ray bounces:
```glsl
// SDF for a single rain drop
float sdDrop(vec3 p, float radius) {
p.y -= radius;
float k = 0.5; // drop shape
float h = clamp(0.5 - 0.5*(p.y - 0.0)/radius, 0.0, 1.0);
p.y -= radius * h * h * k;
return length(p) - radius;
}
// Ray march with recursive reflections
vec3 traceRain(vec3 ro, vec3 rd) {
vec3 col = vec3(0.0);
vec3 refl = vec3(1.0);
for (int bounce = 0; bounce < 4; bounce++) { // recursion depth = 4
float t = 0.0;
vec3 p;
// March toward nearest rain drop
for (int i = 0; i < 64; i++) {
p = ro + rd * t;
float d = sdDrop(p, 0.02); // single drop SDF
// Repeat drops in a grid (infinite rain field)
vec3 cell = floor(p / 0.1);
d = sdDrop(mod(p, 0.1) - 0.05, 0.02);
if (d < 0.001) {
// Hit! Calculate reflection
vec3 normal = normalize(p - (mod(p, 0.1) - 0.05));
rd = reflect(rd, normal);
ro = p + normal * 0.002;
refl *= 0.8; // dampen each recursion level
col += refl * vec3(0.6, 0.7, 0.9); // raindrop tint
break;
}
t += d;
}
}
return col;
}
```
---
## 3. Recursive Worley Noise Rain Surface
Rain hitting a surface disturbs it recursively — each disturbance spawns smaller
disturbances:
```glsl
// Recursive Worley for layered rain-surface noise
float worley(vec2 p) {
vec2 cell = floor(p);
float minDist = 1.0;
for (int j = -1; j <= 1; j++) {
for (int i = -1; i <= 1; i++) {
vec2 neighbor = cell + vec2(float(i), float(j));
// Pseudo-random offset (no state needed = shader-safe)
vec2 seed = sin(vec2(dot(neighbor, vec2(127.1, 311.7)),
dot(neighbor, vec2(269.5, 183.3))));
vec2 point = 0.5 + 0.5 * sin(seed * 6.2831);
float dist = length(neighbor + point - p);
minDist = min(minDist, dist);
}
}
return minDist;
}
// Fractal/recursive rain disturbance
float rainSurface(vec2 uv, float time) {
float height = 0.0;
float amp = 1.0;
float freq = 1.0;
float lacunarity = 2.2; // how much freq increases each "recursion"
float persistence = 0.4; // how much amp decreases
for (int i = 0; i < 6; i++) { // 6 recursion levels
vec2 movedUV = uv * freq;
movedUV.y -= time * freq * 0.3; // falling rain
float w = worley(movedUV);
height += w * amp;
freq *= lacunarity;
amp *= persistence;
}
return height;
}
```