Skip to content

Commit 14fbed7

Browse files
committed
Consolidate and rename newton_fractal shader
1 parent e10a752 commit 14fbed7

File tree

4 files changed

+25
-146
lines changed

4 files changed

+25
-146
lines changed

manimlib/shaders/meta_poly_fractal/frag.glsl

Lines changed: 0 additions & 115 deletions
This file was deleted.
Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ uniform vec2 root4;
2727
uniform float n_roots;
2828
uniform float n_steps;
2929
uniform float julia_highlight;
30-
uniform float color_mult;
30+
uniform float saturation_factor;
3131
uniform float black_for_cycles;
32+
uniform float is_parameter_space;
3233

3334
uniform vec2 frame_shape;
3435

@@ -40,6 +41,7 @@ out vec4 frag_color;
4041
#INSERT complex_functions.glsl
4142

4243
const int MAX_DEGREE = 5;
44+
const float CLOSE_ENOUGH = 1e-3;
4345

4446

4547
vec2 poly(vec2 z, vec2[MAX_DEGREE + 1] coefs){
@@ -61,7 +63,7 @@ vec2 dpoly(vec2 z, vec2[MAX_DEGREE + 1] coefs){
6163
vec2 seek_root(vec2 z, vec2[MAX_DEGREE + 1] coefs, int max_steps, out float n_iters){
6264
float last_len;
6365
float curr_len;
64-
float threshold = 1e-3;
66+
float threshold = CLOSE_ENOUGH;
6567

6668
for(int i = 0; i < max_steps; i++){
6769
last_len = curr_len;
@@ -85,6 +87,24 @@ void main() {
8587
vec4[MAX_DEGREE] colors = vec4[MAX_DEGREE](color0, color1, color2, color3, color4);
8688

8789
vec2 z = xyz_coords.xy;
90+
91+
if(is_parameter_space > 0){
92+
// In this case, pixel should correspond to one of the roots
93+
roots[2] = xyz_coords.xy;
94+
vec2 r0 = roots[0];
95+
vec2 r1 = roots[1];
96+
vec2 r2 = roots[2];
97+
98+
// It is assumed that the polynomial is cubid...
99+
coefs[0] = -complex_mult(complex_mult(r0, r1), r2);
100+
coefs[1] = complex_mult(r0, r1) + complex_mult(r0, r2) + complex_mult(r1, r2);
101+
coefs[2] = -(r0 + r1 + r2);
102+
coefs[3] = vec2(1.0, 0.0);
103+
104+
// Seed value is always center of the roots
105+
z = -coefs[2] / 3.0;
106+
}
107+
88108
float n_iters;
89109
vec2 found_root = seek_root(z, coefs, int(n_steps), n_iters);
90110

@@ -98,23 +118,14 @@ void main() {
98118
color = colors[i];
99119
}
100120
}
101-
color *= (1.0 + (color_mult - 1) * (n_iters - 5));
121+
color *= 1.0 + (0.01 * saturation_factor) * (n_iters - 5 * saturation_factor);
102122

103-
if(black_for_cycles > 0.0 && min_dist > 1e-2){
123+
if(black_for_cycles > 0 && min_dist > CLOSE_ENOUGH){
104124
color = vec4(0.0, 0.0, 0.0, 1.0);
105125
}
106126

107-
// if(julia_highlight > 0.0){
108-
// float factor = min_dist / distance(z, found_root);
109-
// factor *= pow(2.0, n_iters);
110-
// float t = smoothstep(0, 5, factor);
111-
// t *= 2.0;
112-
// // color = vec4(0.0) * (1 - t) * (1 - t) + 2 * color * (1 - t) * t + vec4(1.0) * t * t;
113-
// color *= t;
114-
// }
115-
116127
if(julia_highlight > 0.0){
117-
float radius = julia_highlight; // TODO
128+
float radius = julia_highlight;
118129
vec2[4] samples = vec2[4](
119130
z + vec2(radius, 0.0),
120131
z + vec2(-radius, 0.0),
File renamed without changes.

manimlib/shaders/poly_fractal/vert.glsl

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)