• February 27, 2021, 11:07:26 PM

Login with username, password and session length

Author Topic:  Algorithm for Rendering Slope in a Fractal  (Read 3620 times)

0 Members and 1 Guest are viewing this topic.

Offline LionHeart

  • Uploader
  • *
  • Posts: 164
    • ManpWIN Fractal Generator
Algorithm for Rendering Slope in a Fractal
« on: March 08, 2020, 11:53:33 AM »
Dear Friends,

I have been playing with Kalles Fraktaler and I'm impressed with the slope function.



The effect is great



I tried to look at the source code and soon got lost. Is there a simple algorithm if one has the horizontal and vertical location of the pixel and the iteration count? Is anything else required?

Many thanks for any suggestions


Linkback: https://fractalforums.org/programming/11/algorithm-for-rendering-slope-in-a-fractal/3357/
Paul the LionHeart

Offline claude

  • 3f
  • ******
  • Posts: 1784
    • mathr.co.uk
Re: Algorithm for Rendering Slope in a Fractal
« Reply #1 on: March 08, 2020, 01:41:29 PM »
Slopes rendering is originally a screen-space post-processing effect, using differences between neighbouring pixels' smooth iteration counts.  More recently it can use directional distance estimate (normalized by pixel spacing) instead, which I think gerrit proved is equivalent in the limit of infinitely fine pixel grid.

Relevant part of the source code:
https://code.mathr.co.uk/kalles-fraktaler-2/blob/c78c224a4a3ae7f10ed03aa3948f0cd6b740adcb:/fraktal_sft/fraktal_sft.cpp#l933 lines 933 to 998


Offline C0ryMcG

  • Uploader
  • *
  • Posts: 243
Re: Algorithm for Rendering Slope in a Fractal
« Reply #3 on: March 08, 2020, 11:20:43 PM »
I found this to be a very clear and easy-to-follow explination of this technique
https://www.math.univ-toulouse.fr/~cheritat/wiki-draw/index.php/Mandelbrot_set#Normal_map_effect

The process it describes involves keeping track of the Derivative of the iterations, as well as the iterations, and using that to calculate slope angle in the form of a normal map.
It works on an intuitive level, as well.. In calculus, the derivative of a f(x)=? function returns another function which describes the slope of the original function. So the fact that it works in the complex plane as well, resulting in a 2d slope, is very pleasing in its consistency.

Lots of fun things can be done once you have a normal map generated, and of course, it works for any fractal function as long as you can find that function's derivative!

Offline LionHeart

  • Uploader
  • *
  • Posts: 164
    • ManpWIN Fractal Generator
Re: Algorithm for Rendering Slope in a Fractal
« Reply #4 on: March 09, 2020, 05:02:23 AM »
Many thanks Claude, Adam Majewski and C0ryMcG.

You have been most helpful. A few hours of experimenting and...



Now let's see if we can change the palette.



This is fun.

Again, many thanks to you all.

Offline C0ryMcG

  • Uploader
  • *
  • Posts: 243
Re: Algorithm for Rendering Slope in a Fractal
« Reply #5 on: March 09, 2020, 06:20:41 AM »
Very nice! Looks great. next... Reflections? Refractions? Physics based rendering? I look forward to the results!

Offline LionHeart

  • Uploader
  • *
  • Posts: 164
    • ManpWIN Fractal Generator
Re: Algorithm for Rendering Slope in a Fractal
« Reply #6 on: March 09, 2020, 07:13:12 AM »
Hi C0ryMcG

Thanks for the encouragement  :)

Offline LionHeart

  • Uploader
  • *
  • Posts: 164
    • ManpWIN Fractal Generator
Re: Algorithm for Rendering Slope in a Fractal
« Reply #7 on: March 09, 2020, 12:27:17 PM »
Dear Friends,

I have made more progress with slopes and have incorporated higher orders of Mandelbrot and also include the ability to add a palette.



Many thanks again.

Offline LionHeart

  • Uploader
  • *
  • Posts: 164
    • ManpWIN Fractal Generator
Re: Algorithm for Rendering Slope in a Fractal
« Reply #8 on: March 09, 2020, 01:20:28 PM »
Hi C0ryMcG,

Quote
Lots of fun things can be done once you have a normal map generated, and of course, it works for any fractal function as long as you can find that function's derivative!

I had no problem finding the derivatives of polynomial functions. But I can't get functions like sin(z), exp(z) to yield derivatives that give the same pleasing effect. Also how does on find derivatives of abs(z) functions like Burning Ship etc? Have you had success here?

Quote
The process it describes involves keeping track of the Derivative of the iterations, as well as the iterations, and using that to calculate slope angle in the form of a normal map.

So if we want to do post-production once an image is formed, we need to have a table of iteration counts and derivative values. Is that correct?

Is this the sort of thing I should generate when building the original fractal?

Code: [Select]
struct SlopeStruct {
    long iteration;
    double dC;
    } SlopeData[height][width];

Then I could simply index through the pixels and create a new image. Does this strategy make sense?

Thanks.


Offline superheal

  • Strange Attractor
  • ******
  • Posts: 94
Re: Algorithm for Rendering Slope in a Fractal
« Reply #9 on: March 09, 2020, 01:27:43 PM »
Hello Paul,

you can create the same effect without the need of calculating the actual derivative for each different fractal type. If you store the continuous iteration count then you can post-process these data to find the actual slopes. In fractal zoomer, I used the bump mapping algorithm from mandel machine, and for lighting the algorithm from fractview. They basically do kinda the same.

Edit: This is what claude already mentioned!

Offline claude

  • 3f
  • ******
  • Posts: 1784
    • mathr.co.uk
Re: Algorithm for Rendering Slope in a Fractal
« Reply #10 on: March 09, 2020, 02:43:38 PM »
Also how does on find derivatives of abs(z) functions like Burning Ship etc?
You can treat it Burning Ship as a 2D function of real values, then the derivative is a 2x2 matrix (aka Jacobian).

d/dx abs(x) = sign(x), picking 0 arbitrarily for the non-differentiable point at 0.

gerrit showed me how to turn this Jacobian into a distance estimate using matrix vector norms, and I figured out mostly by accident how to make this into directional DE:
https://fractalforums.org/fractal-image-gallery/18/burning-ship-distance-estimation/647/msg16648#msg16648

But sometimes the image-space processing looks better, I think maybe because the DE-based stuff has way too much fine detail so anti-aliasing is a nightmare?  Not sure exactly...

Offline xenodreambuie

  • Fractal Friar
  • *
  • Posts: 111
Re: Algorithm for Rendering Slope in a Fractal
« Reply #11 on: March 09, 2020, 08:11:15 PM »
The easiest way to get slope is forward differencing, taking two samples a small distance in the x and y directions. That way you can use any measure that you might use for colouring, eg distance estimate, potential, angle, mean |z|, or whatever, without needing an analytic derivative. You still get better quality than pixel differences, and it's easy to use with subsampling. The only drawback is that as you near precision limits, you need to increase the delta towards one pixel at the limit.

Offline Adam Majewski

  • Fractal Frogurt
  • ******
  • Posts: 452
Re: Algorithm for Rendering Slope in a Fractal
« Reply #12 on: March 09, 2020, 09:09:26 PM »
I have made more progress with slopes and have incorporated higher orders of Mandelbrot and also include the ability to add a palette.

I see fractint default palette
https://gitlab.com/adammajewski/color_gradient/-/blob/master/README.md#default-fractint-map
https://en.wikibooks.org/wiki/Fractals/fractint

Offline LionHeart

  • Uploader
  • *
  • Posts: 164
    • ManpWIN Fractal Generator
Re: Algorithm for Rendering Slope in a Fractal
« Reply #13 on: March 10, 2020, 02:48:23 AM »
Thanks SuperHeal.

This may work as I already store an array of iteration counts for each pixel. Do you have links to some source code? Thanks.

Thanks Claude.

I sort of got lost in the mathematical notation. It's been too many years. Is there a simple programming algorithm?

Thanks xenodreambuie.

That sounds like a good post rendering process.

Yes Adam,

Much of ManpWIN is based on Winfract architecture. This has the advantage that I got a lot of cool stuff working quickly but the overwhelming use of global variable has made it difficult to turn into "good" C++ code. I'm still struggling with this. It really became an issue when I started to work on multi-threading. So I have a crazy collection of code, mostly still c-like. I've often thought of starting from scratch, but there's just too much code.

Thanks all for your suggestions. Now it is time for me to research the options you have suggested and see what I can get working.

Offline C0ryMcG

  • Uploader
  • *
  • Posts: 243
Re: Algorithm for Rendering Slope in a Fractal
« Reply #14 on: March 10, 2020, 03:45:29 AM »
I hadn't really considered the flexibility of a difference-based approach to slope. And the fact that it works with functions that are hard to deriviate (Derive?) is a nice bonus.
I think I need to re-investigate distance estimation... The method I found relies on the function's derivative. Since a few people have now mentioned distance estimation in the context of NOT relying on derivative, I suspect I've been doing it the hard way.

I'm going to try to find the helpful resource I found for describing how to do 3d vector reflection calculations with a normal map... Because I imagine that's going to be helpful in this thread pretty soon.


clip
Algorithm for Full Exploration of 3D Fractal in Realtime

Started by AranLeer on Fractal Mathematics And New Theories

13 Replies
837 Views
Last post April 26, 2019, 07:34:08 AM
by TGlad
xx
Custom 3D Fractal Formula Rendering on Mac

Started by jmseight on Noob's Corner

5 Replies
345 Views
Last post May 11, 2020, 04:30:34 AM
by kosalos
xx
Travel around 3d fractal world. Realtime rendering.

Started by sanbase on Fractal movie gallery

4 Replies
209 Views
Last post February 18, 2021, 06:12:08 AM
by sanbase
xx
How would quantum computing affect fractal rendering?

Started by greentexas on Programming

1 Replies
723 Views
Last post December 12, 2017, 01:40:20 AM
by eiffie
question
How to Generate a Derivative Slope for Mandelbar (Tricorn)

Started by LionHeart on Programming

12 Replies
353 Views
Last post January 08, 2021, 08:25:36 PM
by LionHeart