for a bit of fun, I implemented rendering of the Mandelbrot set in ISL.

The material with shader is as follows:

Code: Select all

```
<material>
<name>mat1</name>
<diffuse>
<albedo>
<shader>
<shader>
<![CDATA[
# x^2 = (a + bi)^2 = aa + 2abi + bbii
# = a^2 + 2abi -b^2
# = a^2-b^2 + 2abi
# Does one iteration (application of f)
# Returns (re(x), im(x), i)
# Where i is the number of iterations before the point escaped.
def f(vec3 x, vec2 c) vec3 :
vec3(
e0(x)*e0(x) - e1(x)*e1(x) + e0(c),
2.0*e0(x)*e1(x) + e1(c),
if((e0(x)*e0(x) + e1(x)*e1(x)) < 2.0, e2(x) + 1.0, e2(x))
)
# The composition of f with itself. Does 2 iterations.
# ISL doesn't support recursion for various reasons,
# so we'll use the following composition technique for bounded 'recursion'.
def f2(vec3 x, vec2 c) vec3:
f(f(x, c), c)
# Does 4 iterations
def f4(vec3 x, vec2 c) vec3:
f2(f2(x, c), c)
# etc..
def f8(vec3 x, vec2 c) vec3:
f4(f4(x, c), c)
def f16(vec3 x, vec2 c) vec3:
f8(f8(x, c), c)
def f32(vec3 x, vec2 c) vec3:
f16(f16(x, c), c)
def f64(vec3 x, vec2 c) vec3:
f32(f32(x, c), c)
def f128(vec3 x, vec2 c) vec3:
f64(f64(x, c), c)
def colour(real i) vec3:
vec3(i * 0.02, i * 0.04, i * 0.08)
def eval(vec3 pos) vec3 :
# We will use the texture coordinates for c.
# Return a colour based on the number of iterations before escape,
# which is in the third vector component of the returned vector, hence the e2()
# We call f128 to do 128 iterations.
colour(e2(f128(vec3(0.0,0.0,0.0), getTexCoords(0))))
]]>
</shader>
</shader>
</albedo>
</diffuse>
</material>
```