Distorting Shapes

Finally, the include file offers a way to distort the normal vectors of a grid to create a little more chaos to the shapes without affecting the modeling grid itself.

We’ll start with an image with as flat of a plane as we can create using bicubic patches:

#include "bez.inc" 
#include "math.inc"

#declare Bez_Texture = 
   texture { pigment{ red 1 green 1 } 
             finish { phong 1} 
           } // end of texture

#declare ModelGrid = array[6][6]
#declare sampleseed = seed(42);
#for(X, 0, dimension_size(ModelGrid, 1)-1, 1)
  #for(Z, 0, dimension_size(ModelGrid, 2)-1, 1)
    #declare ModelGrid[X][Z] = <Interpolate(X, 0, 5, -2, 2, 1), 
                                0+rand(sampleseed)*0.01, 
                                Interpolate(Z, 0, 5, -2, 2, 1)>;
  #end // for Z
#end // for X

#declare CPGrid = CreateGridControlPoints(ModelGrid, 0)

DrawPatches(CPGrid, Bez_Texture)
_images/bezier-patch-normal-distortion.png

We need to find the normal vectors at each vertice in the modeling grid, adjust those normal vectors, and then apply them back to the control grid based on the modeling grid.

#include "bez.inc" 
#include "math.inc"

#declare Bez_Texture = 
   texture { pigment{ red 1 green 1 } 
             finish { phong 1} 
           } // end of texture

#declare ModelGrid = array[6][6]
#declare sampleseed = seed(42);
#for(X, 0, dimension_size(ModelGrid, 1)-1, 1)
  #for(Z, 0, dimension_size(ModelGrid, 2)-1, 1)
    #declare ModelGrid[X][Z] = <Interpolate(X, 0, 5, -2, 2, 1), 
                                0+rand(sampleseed)*0.01, 
                                Interpolate(Z, 0, 5, -2, 2, 1)>;
  #end // for Z
#end // for X

#declare CPGrid = CreateGridControlPoints(ModelGrid, 0)

DrawPatches(CPGrid, Bez_Texture)

#declare Normals = MakeNormals(ModelGrid);

object{ DrawNormals(ModelGrid, Normals, 0.05) pigment { red 1 } finish { phong 1 } }
_images/bezier-patch-normal-distortion-2.png

Distorting the normals moves them off center in random directions.

#include "bez.inc" 
#include "math.inc"

#declare Bez_Texture = 
   texture { pigment{ red 1 green 1 } 
             finish { phong 1} 
           } // end of texture

#declare ModelGrid = array[6][6]
#declare sampleseed = seed(42);
#for(X, 0, dimension_size(ModelGrid, 1)-1, 1)
  #for(Z, 0, dimension_size(ModelGrid, 2)-1, 1)
    #declare ModelGrid[X][Z] = <Interpolate(X, 0, 5, -2, 2, 1), 
                                0+rand(sampleseed)*0.01, 
                                Interpolate(Z, 0, 5, -2, 2, 1)>;
  #end // for Z
#end // for X

#declare CPGrid = CreateGridControlPoints(ModelGrid, 0)

DrawPatches(CPGrid, Bez_Texture)

#declare Normals = MakeNormals(ModelGrid);

#declare DistortedNormals = DistortNormals(Normals, 15, no);
_images/bezier-patch-normal-distortion-3.png

The final version has a little variation to it now.

#include "bez.inc" 
#include "math.inc"

#declare Bez_Texture = 
   texture { pigment{ red 1 green 1 } 
             finish { phong 1} 
           } // end of texture

#declare ModelGrid = array[6][6]
#declare sampleseed = seed(42);
#for(X, 0, dimension_size(ModelGrid, 1)-1, 1)
  #for(Z, 0, dimension_size(ModelGrid, 2)-1, 1)
    #declare ModelGrid[X][Z] = <Interpolate(X, 0, 5, -2, 2, 1), 
                                0+rand(sampleseed)*0.01, 
                                Interpolate(Z, 0, 5, -2, 2, 1)>;
  #end // for Z
#end // for X

#declare CPGrid = CreateGridControlPoints(ModelGrid, 0)

//DrawPatches(CPGrid, Bez_Texture)

#declare Normals = MakeNormals(ModelGrid);

#declare DistortedNormals = DistortNormals(Normals, 15, no);

//object{ DrawNormals(ModelGrid, DistortedNormals, 0.05) pigment { red 1 } finish { phong 1 } }

#declare DistortedControlGrid = ApplyNormals(CPGrid, DistortedNormals, no);

DrawPatches(DistortedControlGrid, Bez_Texture)
_images/bezier-patch-normal-distortion-4.png