POV-Ray : Newsgroups : povray.text.scene-files : Source code for "Using functions to distort images" Server Time
31 Oct 2024 19:54:53 EDT (-0400)
  Source code for "Using functions to distort images" (Message 1 to 2 of 2)  
From: Tor Olav Kristensen
Subject: Source code for "Using functions to distort images"
Date: 21 May 2006 18:48:59
Message: <4470ee5b@news.povray.org>
See my posts to povray.binaries.images 20. May 2006:
"Using functions to distort images"

http://news.povray.org/povray.binaries.images/thread/%3C446f8654%40news.povray.org%3E/
http://tinyurl.com/zpyk6

Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2006 Tor Olav Kristensen
// http://subcube.com
// Using functions to distort image
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.6;

#include "functions.inc"

global_settings {
   ambient_light color rgb <1, 1, 1>
//  assumed_gamma 1.0
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#macro BiColorPigment(Fn, Color1, Color2)

   pigment {
     function { Fn(x, y, z) }
     color_map {
       [ 0 color Color1 ]
       [ 1 color Color2 ]
     }
   }

#end // macro BiColorPigment


#macro FunctionPigment(FnR, FnG, FnB)

   #local PigmentR = BiColorPigment(FnR, color   red 0, color   red 3)
   #local PigmentG = BiColorPigment(FnG, color green 0, color green 3)
   #local PigmentB = BiColorPigment(FnB, color  blue 0, color  blue 3)

   pigment {
     average
     pigment_map {
       [ PigmentR ]
       [ PigmentG ]
       [ PigmentB ]
     }
   }

#end // macro FunctionPigment

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare ImageFn =
   function { pigment { image_map { "Image.png" } } }

#declare FnA = function { ImageFn(x, y, z).red   }
#declare FnB = function { ImageFn(x, y, z).green }
#declare FnC = function { ImageFn(x, y, z).blue  }

#declare A = 1.5; // Amplitude
#declare F = 1.0; // Frequency

// Two (different) noisy functions.
#declare N_FnX = function { A*(f_agate(  0 + F*x, F*y, z) - 0.5) }
#declare N_FnY = function { A*(f_agate(100 + F*x, F*y, z) - 0.5) }

box {
   -<1, 1, 1>/2, <1, 1, 1>/2
   texture {
     FunctionPigment(
       function { FnA(x + N_FnX(x, y, z), y + N_FnY(x, y, z), z) },
       function { FnB(x + N_FnX(x, y, z), y + N_FnY(x, y, z), z) },
       function { FnC(x + N_FnX(x, y, z), y + N_FnY(x, y, z), z) }
     )
     finish { ambient color rgb <1, 1, 1> } // Adjust brightness here
     translate -<1, 1, 0>/2
   }
   scale <4, 3, 1> // Adjust image aspect ratio
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

camera {
   orthographic
   location -3.1*z
   look_at 0*y
}

background { color rgb <1, 1, 1> }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Source code for "Using functions to distort images"
Date: 21 May 2006 19:32:14
Message: <4470f87e@news.povray.org>
Tor Olav Kristensen wrote:
> 
> See my posts to povray.binaries.images 20. May 2006:
> "Using functions to distort images"
> 
>
http://news.povray.org/povray.binaries.images/thread/%3C446f8654%40news.povray.org%3E/

> 
> http://tinyurl.com/zpyk6

Here's a more "macrofied" version of the source code.


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2006 Tor Olav Kristensen
// Use of functions to distort image
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.6;

#include "functions.inc"
#include "colors.inc"

global_settings {
   ambient_light color White
//  assumed_gamma 1.0
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#macro BiColorPigment(Fn, Color1, Color2)

   pigment {
     function { Fn(x, y, z) }
     color_map {
       [ 0 color Color1 ]
       [ 1 color Color2 ]
     }
   }

#end // macro BiColorPigment


#macro FunctionPigment(FnR, FnG, FnB)

   #local PigmentR = BiColorPigment(FnR, color   red 0, color   red 3)
   #local PigmentG = BiColorPigment(FnG, color green 0, color green 3)
   #local PigmentB = BiColorPigment(FnB, color  blue 0, color  blue 3)

   pigment {
     average
     pigment_map {
       [ PigmentR ]
       [ PigmentG ]
       [ PigmentB ]
     }
   }

#end // macro FunctionPigment


// Note that this macro only works with PNG-images
#macro DistortedImagePigment(ImageFileName, D_FnX, D_FnY)

   #local ImageFn =
     function { pigment { image_map { png ImageFileName } } }
   #local FnA = function { ImageFn(x, y, z).red   }
   #local FnB = function { ImageFn(x, y, z).green }
   #local FnC = function { ImageFn(x, y, z).blue  }

   FunctionPigment(
     function { FnA(x + D_FnX(x, y, z), y + D_FnY(x, y, z), z) },
     function { FnB(x + D_FnX(x, y, z), y + D_FnY(x, y, z), z) },
     function { FnC(x + D_FnX(x, y, z), y + D_FnY(x, y, z), z) }
   )

#end // macro DistortedImagePigment

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare A = 1.5; // Amplitude
#declare F = 1.0; // Frequency

// Two (different) noisy functions.
#declare N_FnX = function { A*(f_agate(  0 + F*x, F*y, z) - 0.5) }
#declare N_FnY = function { A*(f_agate(100 + F*x, F*y, z) - 0.5) }

box {
   -<1, 1, 1>/2, <1, 1, 1>/2
   texture {
     DistortedImagePigment("YourImage.png", N_FnX, N_FnY)
     finish { ambient color White*1.0 } // Adjust brightness here
     translate -<1, 1, 0>/2
   }
   scale <4, 3, 1> // Adjust to image aspect ratio here
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

background { color White }

camera {
   orthographic
   location -3.1*z
   look_at 0*y
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.