Logo by jodyvl - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Check out the originating "3d Mandelbulb" thread here
 
*
Welcome, Guest. Please login or register. April 23, 2024, 12:31:50 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Shading techniques for rendering 3D fractals  (Read 5480 times)
0 Members and 2 Guests are viewing this topic.
Buddhi
Fractal Iambus
***
Posts: 895



WWW
« on: September 28, 2009, 10:00:28 PM »

Hi

I would like to start discussion about shading techniques for 3D fractals. At start I will share my experience in this topic. I rendered the same view of 3D Mandelbrot fractal (Twenbee's formula) in several shading techniques.
My method of rendering bases on high resolution slices (big 3D array) containing information about number of iteration for each voxel (3D pixel). I know that this is not most efficient method but 3D arrays deliver information about whole fractal and enable rendering with complex shading. Another benefit is possibility to render transparent fog where opacity is proportional to number of iterations.
I have developed following shading methods:
- hard shadows
- angle of incidence of light based on estimated normal vectors
- environment mapping based on estimated normal vectors
- global illumination

Hard shadows


http://www.fractalforums.com/gallery/?sa=view;id=927

This is the simplest method for shading 3D fractals.  From each visible voxel you have to send virtual ray towards light source. If ray meets some obstacle you have to set light intensity for rendered point as zero or decrease light intensity proportional to opacity of encountered voxel (number of fractal iterations).

Angle of incidence of light


http://www.fractalforums.com/gallery/?sa=view;id=928

Calculating angle of incidence of light requires information about angle of normal vector for surface near rendered voxel. It is very difficult to calculate accurate normal vector for 3D array of voxels when fractal is rendered using iteration count. Iteration count function unfortunately is not solid. There is Distance Estimation method which provides solid function of distance to fractal border but it is possible to use this method only for hypercomplex fractals. David Makin developed method for calculating distance function but I tried with this with no result  sad (I don't understand enough David's algorithm).
The simplest method of getting normal vector is calculate something like gradient of potential function where potential equals to iteration count or estimated distance.
\mbox{grad } f = [\frac{df}{dx}, \frac{df}{dy}, \frac{df}{dz}]
This is very simple to calculate. For normal vector calculation you have only subtract values of adjacent pixel in every direction (x,y and z). For example:
delta x = f(x+0.5,y,z) - f(x-0.5,y,z)
delta y = f(x,y+0.5,z) - f(x,y-0.5,z)
delta z = f(x,y,z+0.5) - f(x,y,z-0.5)
(I can use 0.5 offset value because I'm using 3D interpolation)

Next you have to normalize this vector by dividing each component by length of above vector.
length = sqrt(dx^2 + dy^2 + dx^2
N = [\frac{delta x}{length}, \frac{delta y}{length}, \frac{delta z}{length}]

Dot product of normal vector and light direction vector will be intensity of light.

light intensity = N.x * light.x + N.y*light.y + N.z*light.z

This simple method is working but looks not so good in zoom


You can achieve best result when you calculate average gradient for some small area near calculated point. I usually use 3x3x3 voxels area.
Bellow is an example render with this approach. On this image fractal surface is smooth but unfortunately lost some details.


http://www.fractalforums.com/gallery/?sa=view;id=930

To be continued...
Logged

Buddhi
Fractal Iambus
***
Posts: 895



WWW
« Reply #1 on: September 29, 2009, 07:45:04 PM »

Environment mapping


http://www.fractalforums.com/gallery/?sa=view;id=931

This technique in technical details is very similar to calculating angle of incidence of light but end effect is completely another. This shading method simulates reflections of environment (virtual sky) surrounding fractal. For this method there is needed some additional bitmap with reflection map (for example photo of sky).
You also have to calculate normal vector.  Horizontal and vertical (x and y) components will be used as coordinates of pixel on reflection bitmap. Of course x and y values has to be multiplied by proper factor to adjust to bitmap size. Colour of actual rendered pixel will be equal to pointed pixel by normal vector.

Global illumination


http://www.fractalforums.com/gallery/?sa=view;id=932

I think this is the most impressive technique for 3D fractal rendering but unfortunately the slowest. This method simulates ambient light and the final effect is similar to radiosity method (radiosity additionally includes light diffusion and is even slower).
Rendering algorithm is similar to calculation of shadows but you have to calculate not one ray but tens or hundreds. The best effect is when rays are sent in spherical directions. When you calculate all beams the final intensity of light will be average brightness from all rays.
Rendering time is very long because program has to calculate many rays. If average beam length is about 500 voxels and there is about 200 beams program has to scan about 100 thousands voxels for each rendered pixel. For optimisation I used not constant steps for scaning each ray. I wrote something like this (pseudo code):

Code:
for ray_number=0 to max_ray_number
   calculation of dx,dy,dz    ;(spherical directions calculated using sin and cos functions)
   for i=1 to 30
      r2=i*i          ;(step is proportional to square of index)
      x = dx*r2
      y = dy*r2
      z = dz*r2 
      GetIntensityOfVoxel(xx+x, yy+y, zz+z)
      ....
      ....
   next
   .....
next

If I use high accuracy for small distance form centre and lower accuracy for higher distances calculations are much more faster and final effect is nearly the same like when I use constant step.

Complex shading


http://www.fractalforums.com/gallery/?sa=view;id=933

If you have to much free time for rendering you can use all shading techniques together. Rendering is very very slow but result of shading is very realistic. For calculation of resultant brightness of pixel I use following formula:

brightness = normal * (1.0 - ambient)*hard_shadows + ambient) + global_illumination + reflection

where:
  normal - brightness corresponded to angle of incidence of light
  hard_shadows - brightness calculated using hard shadows algorithm
  ambient - constant ambient light value
  global_illumination - brightness calculated using global illumination algorithm
  reflection - brightness from environment mapping
Logged

Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Blend shading Images Showcase (Rate My Fractal) Dinkydau 7 1144 Last post April 18, 2012, 10:03:57 PM
by klixon
Inside rendering of brots and other fractals Tutorials « 1 2 » Alef 15 4568 Last post March 16, 2015, 01:39:51 PM
by LMarkoya
Rendering 3D fractals without distance estimators 3D Fractal Generation « 1 2 ... 7 8 » Syntopia 117 26533 Last post January 16, 2014, 05:11:18 PM
by hobold
Smooth Shading Mandelbrot plugin Fractal eXtreme panzerboy 6 10918 Last post February 20, 2013, 04:26:37 PM
by panzerboy
Phase Angle Shading Images Showcase (Rate My Fractal) wes 0 2850 Last post March 14, 2017, 03:47:02 AM
by wes

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.28 seconds with 24 queries. (Pretty URLs adds 0.006s, 2q)