Beginning WebGL for HTML5 by Brian Danchilla
Author:Brian Danchilla
Language: eng
Format: epub, pdf
ISBN: 9781430239963
Publisher: Apress
Figure 6-4. Mandelbrot set (left); some regions of self-similarity highlighted (right)
In Listing 6-4, we set constants of the number of iterations to test for each point being in the set and the amount to multiply the color of the boundary points based on the iteration number when a number leaves the set. When setting the c-value, the x coordinate has been moved 0.5 in the negative direction just to center the image better. The first z-value, z1, equals c,so we set z initially equal to c. We initialize the pixel color to black and start our loop. The next z-value is calculated from the equations that we have derived in Listing 6-3 and then we test the dot product for being over 4. Recall that the dot product is x2+ y2, which is the magnitude (or length) squared. We know that a magnitude larger than 2 means that the point is outside the set. As 22 = 4, using the squared value is an equivalent but less-expensive calculation because it does not require us to compute a square root. Finally we shade our pixel a value of blue between 0 and 1 based on the current iteration when the pixel becomes unbound in the sequence to the maximum number of iterations. However, it can be hard to see the boundary, so setting the constant LIGHTNESS_FACTOR to a higher value such as 10.0 will help visualize the boundary. Doing so increases the number of white-colored iterations, but this does provide much better contrast.
Note If the fragment shader is not loading externally, try placing it inline. I have experienced errors with the for loop when placed in an external file, but have the program working when inline. The actual reason for this is that the comparision sign “<” needs to be escaped in the shader if it is read in as XML. A couple ways to resolve this issue are shown in the debugging section of Chapter 9.The for loop in GLSL is much more restrictive than in JavaScript or C/C++ and requires a constant as the limit condition.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Whiskies (Collins Gem) by dominic roskrow(45482)
Spell It Out by David Crystal(36193)
Cecilia; Or, Memoirs of an Heiress — Volume 1 by Fanny Burney(32686)
Cecilia; Or, Memoirs of an Heiress — Volume 2 by Fanny Burney(32046)
Cecilia; Or, Memoirs of an Heiress — Volume 3 by Fanny Burney(32029)
Beautiful Disaster by McGuire Jamie(25415)
Trainspotting by Irvine Welsh(21897)
Chic & Unique Celebration Cakes by Zoe Clark(20125)
The Secret History by Donna Tartt(19392)
How High Can a Kangaroo Hop? by Jackie French(18830)
Twilight of the Idols With the Antichrist and Ecce Homo by Friedrich Nietzsche(18726)
All the Missing Girls by Megan Miranda(16488)
Cat's cradle by Kurt Vonnegut(15492)
Ready Player One by Cline Ernest(14834)
For the Love of Europe by Rick Steves(14743)
Fifty Shades Freed by E L James(13321)
4 3 2 1: A Novel by Paul Auster(12561)
Crooked Kingdom: Book 2 (Six of Crows) by Bardugo Leigh(12408)
Grundlagen Kreatives Schreiben (German Edition) by Helfferich Pia(10507)