More testing

This commit is contained in:
hodasemi 2020-11-26 19:12:46 +01:00
parent 8f86376e99
commit beef18467e
3 changed files with 65 additions and 27 deletions

View file

@ -9,6 +9,8 @@ layout (set = 0, binding = 0) uniform Parameters {
float size;
float time;
float factor;
float width;
float height;
} parameters;
float hue_to_rgb(float p, float q, float t) {
@ -100,39 +102,66 @@ vec3 paint(float nx, float ny) {
// color = vec4(paint(gl_FragCoord.x, gl_FragCoord.y), 1.0);
// }
void main() {
vec2 tc = vec2(in_uv.x) * parameters.time * parameters.factor;
float x0 = (tc.x * 3 - 2);
float y0 = (tc.y * 2 - 1);
float x = 0;
float y = 0;
int iteration = 0;
while ((x * x + y * y <= 4) && (iteration < parameters.max_iter))
{
float xtemp = x * x - y * y + x0;
y = 2 * x * y + y0;
x = xtemp;
iteration += 1;
}
if (iteration == parameters.max_iter)
{
// Hier wird der Farbwert für das Innere der Mandelbrotmenge gesetzt
color = vec4(0, 0, 0, 1);
}
else
{
// Hier kann eine beliebige Farbwahl stattfinden(z.B. mit einer Farbtabelle).
// als Index verwendet man die Variable "iteration", die einen Wert zwischen 1 und parameters.max_iter hat.
x = sin(float(iteration));
color = vec4(x, x, x, 1);
}
vec2 square_imaginary(vec2 number) {
return vec2(
pow(number.x, 2) - pow(number.y, 2),
2 * number.x * number.y
);
}
float iterate_mandelbrot(vec2 coord) {
vec2 z = vec2(0,0);
for(int i = 0; i < parameters.max_iter; i++){
z = square_imaginary(z) + coord;
if ( length(z) > 2 ) {
return i / parameters.max_iter;
}
}
return parameters.max_iter;
}
void main() {
vec2 coord = gl_FragCoord.xy / vec2(parameters.width, parameters.height);
float c = iterate_mandelbrot(coord);
color = vec4(vec3(c, c * 0.3, c * 0.7), 1.0);
// vec2 tc = vec2(in_uv.x) * parameters.time * parameters.factor;
// float x0 = (tc.x * 3 - 2);
// float y0 = (tc.y * 2 - 1);
// float x = 0;
// float y = 0;
// int iteration = 0;
// while ((x * x + y * y <= 4) && (iteration < parameters.max_iter))
// {
// float xtemp = x * x - y * y + x0;
// y = 2 * x * y + y0;
// x = xtemp;
// iteration += 1;
// }
// if (iteration == parameters.max_iter)
// {
// // Hier wird der Farbwert für das Innere der Mandelbrotmenge gesetzt
// color = vec4(0, 0, 0, 1);
// }
// else
// {
// // Hier kann eine beliebige Farbwahl stattfinden(z.B. mit einer Farbtabelle).
// // als Index verwendet man die Variable "iteration", die einen Wert zwischen 1 und parameters.max_iter hat.
// x = sin(float(iteration));
// color = vec4(x, x, x, 1);
// }
}

Binary file not shown.

View file

@ -8,6 +8,8 @@ struct ShaderInfo {
size: f32,
time: f32,
factor: f32,
width: f32,
height: f32,
}
#[derive(Clone)]
@ -158,6 +160,8 @@ impl Fractal {
size: 0.001,
time: 0.0,
factor: 1.0,
width: render_core.width() as f32,
height: render_core.height() as f32,
}])
.set_memory_usage(MemoryUsage::CpuOnly)
.set_usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)
@ -234,8 +238,13 @@ impl TScene for Fractal {
}
fn resize(&self) -> VerboseResult<()> {
println!("resize of FB is still missing");
let mut mapping = self.descriptor_buffer.map_complete()?;
Ok(())
mapping[0].width = self.context.render_core().width() as f32;
mapping[0].height = self.context.render_core().height() as f32;
todo!("resize of FB is still missing");
// Ok(())
}
}