reb
Class REB_TrapShapeModPerlinTexture

Object
  extended by common:Generic
      extended by common:TrapShape
          extended by reb:REB_TrapShapeModPerlinTexture

class 
TrapShape:REB_TrapShapeModPerlinTexture

This texture is based upon the code of Damien Jones
Convolution code added 10/10/08


Ultra Fractal Source

Toggle UF Source Code Display

 class REB_TrapShapeModPerlinTexture(common.ulb:TrapShape) {
  ; This texture is based upon the code of Damien Jones <br>
  ; Convolution code added 10/10/08 <br>
  public:
    import "common.ulb"
 
 ; Constructor
    func REB_TrapShapeModPerlinTexture(Generic pparent)
      TrapShape.TrapShape(pparent)
    endfunc
    
   ; Call this for each iteration being trapped.
    float func Iterate(complex pz)
     TrapShape.Iterate(pz)
     int p[514]
     float g3[514, 3]
     int i = 0
     int j = 0
     int k = 0
     int seed = @seed
     float sum2 = 0
     float jc = 0
     float aa = 0
     float jmax = 0
     if @mode == 0
       jmax = 1
     else
       jmax = 5
     endif
 
     while i < 256
       p[i] = i
       j = 0
       while j < 3
         seed = random(seed)
         g3[i, j] = seed % 256
         j = j + 1
       endwhile
       float t0 = g3[i, 0]
       float t1 = g3[i, 1]
       float t2 = g3[i, 2]
       float s = sqrt(t0 * t0 + t1 * t1 + t2 * t2)
       g3[i, 0] = g3[i, 0] / s
       g3[i, 1] = g3[i, 1] / s
       g3[i, 2] = g3[i, 2] / s
       i = i + 1
     endwhile
     i = 0
     while i < 256
       k = p[i]
       j = abs(seed) % 256
       seed = random(seed)
       p[i] = p[j]
       p[j] = k
       i = i + 1
     endwhile
     i = 0
     while i < 256
       p[256 + i] = p[i]
       j = 0
       while j < 3
         g3[256 + i , j] = g3[i, j];
         j = j + 1
       endwhile
       i = i + 1
     endwhile
 
     while jc < jmax
       z = pz*@scale
       if @mode == 1 || @mode == 2
         if jc == 0
           aa = @cbl + @ctl + @cbr + @ctr + @cc;/20
         elseif jc == 1
           z = z + @eps*(-1,-1)
           aa = -@cbl
         elseif jc == 2
           z = z + @eps*(-1,1)
           aa = -@ctl
         elseif jc == 3
           z = z + @eps*(1,-1)
           aa = -@cbr
         elseif jc == 4
           z = z + @eps*(1,1)
          aa = -@ctr
         endif
       else
         aa = 1
       endif
       jc = jc + 1
       int iter = 0
       float sum = 0
       float amplitude = 1.0, r = (0,1) ^ (1/3)
       while iter < @octaves
         float t = real(z) % 4096 + 4096
         int bx0 = floor(t) % 256
         int bx1 = (bx0 + 1) % 256
         float rx0 = t - floor(t)
         float rx1 = rx0 - 1
         t = imag(z) % 4096 + 4096
         int by0 = floor(t) % 256
         int by1 = (by0 + 1) % 256
         float ry0 = t - floor(t)
         float ry1 = ry0 - 1
         t =  4096
         int bz0 = floor(t) % 256
         int bz1 = (bz0 + 1) % 256
         float rz0 = t - floor(t)
         float rz1 = rz0 - 1
         int ii = p[bx0]
         int jj = p[bx1]
         int b00 = p[ii + by0]
         int b10 = p[jj + by0]
         int b01 = p[ii + by1]
         int b11 = p[jj + by1]
         float t = (rx0 * rx0 * (3.0 - 2.0 * rx0))
         float sy = (ry0 * ry0 * (3.0 - 2.0 * ry0))
         float sz = (rz0 * rz0 * (3.0 - 2.0 * rz0))
         float u = (rx0 * g3[b00 + bz0, 0] + ry0 * g3[b00 + bz0, 1] + rz0 * g3[b00 + bz0, 2])
         float v = (rx1 * g3[b10 + bz0, 0] + ry0 * g3[b10 + bz0, 1] + rz0 * g3[b10 + bz0, 2])
         float a = (u + t * (v - u))
         u = (rx0 * g3[b01 + bz0, 0] + ry1 * g3[b01 + bz0, 1] + rz0 * g3[b01 + bz0, 2])
         v = (rx1 * g3[b11 + bz0, 0] + ry1 * g3[b11 + bz0, 1] + rz0 * g3[b11 + bz0, 2])
         float b = (u + t * (v - u))
         float c = (a + sy * (b - a))
         u = (rx0 * g3[b00 + bz1, 0] + ry0 * g3[b00 + bz1, 1] + rz1 * g3[b00 + bz1, 2])
         v = (rx1 * g3[b10 + bz1, 0] + ry0 * g3[b10 + bz1, 1] + rz1 * g3[b10 + bz1, 2])
         a = (u + t * (v - u))
         u = (rx0 * g3[b01 + bz1, 0] + ry1 * g3[b01 + bz1, 1] + rz1 * g3[b01 + bz1, 2])
         v = (rx1 * g3[b11 + bz1, 0] + ry1 * g3[b11 + bz1, 1] + rz1 * g3[b11 + bz1, 2])
         b = (u + t * (v - u))
         float d = (a + sy *(b - a))
         sum = sum + real(@fun(c + sz *(d - c))) * amplitude
         amplitude = amplitude * @persistence
         z = z * r / @nfactorp
         iter = iter + 1
       endwhile
 
       if @mode != 2
         sum2 = sum2 + aa*sum
       else
         sum2 = sum2 + aa*abs(sum)
       endif
       sum = 0
     endwhile
 
     if @mode == 2
       sum2 = 3*abs(sum2)
     endif
 
     if @mode == 1
       sum = sum2/(10*@eps*(abs(@cbl + @ctl + @cbr + @ctr)+1))
     else
       sum = sum2
     endif
 
     z = exp(flip(2 * #pi * sqrt(2) * sum))
     m_lastZ = z
     if @flavort == 1
       m_lastZ = m_lastZ + sum + flip(sum)
       sum = sum + cabs(z)
     endif
     return sum
    endfunc
    
  default:
    title = "Modified Perlin Textures"
   int param v_trapshapemodperlintextures
     caption = "Version (Trap Shape Modified Perlin Textures)"
     default = 102
     hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used."
     visible = @v_trapshapemodperlintextures < 102
   endparam
   param flavort
     caption = "Perlin flavor"
     default = 0
     enum = "0" "1"
   endparam
   param octaves
     caption = "Octaves"
     default = 7
     min = 1
   endparam
   param persistence
     caption = "Persistence"
     default = 0.5
   endparam
   float param nfactorp
     caption = "Noise Factor"
     default = 0.5
   endparam
   func fun
     caption = "Noise Function"
     default = ident()
   endfunc
   param scale
     caption = "Scale"
     default = 10.0
   endparam
   param @seed
     caption = "Random Seed"
     default = 1234567
   endparam
   param mode
     caption = "Mode"
     default = 0
     enum = "Normal" "Convolution" "Absolute Convolution"
   endparam
   param cc
     caption = "Center Extra Weight"
     default = 0.0
     visible = @mode != "Normal"
   endparam
   param cbl
     caption = "Bottom Left Weight"
     default = 1.0
     visible = @mode != "Normal"
   endparam
   param ctl
     caption = "Top Left Weight"
     default = 0.0
     visible = @mode != "Normal"
   endparam
   param cbr
     caption = "Bottom Right Weight"
     default = 0.0
     visible = @mode != "Normal"
   endparam
   param ctr
     caption = "Top Right Weight"
     default = 0.0
     visible = @mode != "Normal"
   endparam
   param eps
     caption = "Epsilon"
     default = 0.006
     visible = @mode != "Normal"
   endparam
  }
 


Constructor Summary
REB_TrapShapeModPerlinTexture()
           
REB_TrapShapeModPerlinTexture(Generic pparent)
          Constructor
 
Method Summary
 float Iterate(complex pz)
          Call this for each iteration being trapped.
 
Methods inherited from class common:TrapShape
GetColorChannel, GetTextureValue, GetTransformedPoint, Init, IterateSilent, SetThreshold
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

REB_TrapShapeModPerlinTexture

public REB_TrapShapeModPerlinTexture(Generic pparent)
Constructor


REB_TrapShapeModPerlinTexture

public REB_TrapShapeModPerlinTexture()
Method Detail

Iterate

public float Iterate(complex pz)
Call this for each iteration being trapped.

Overrides:
Iterate in class TrapShape