POV-Ray : Newsgroups : povray.text.scene-files : Source code for "AOI textures for isosurfaces" Server Time
1 Nov 2024 01:23:24 EDT (-0400)
  Source code for "AOI textures for isosurfaces" (Message 1 to 5 of 5)  
From: Tor Olav Kristensen
Subject: Source code for "AOI textures for isosurfaces"
Date: 5 Jun 2003 14:10:01
Message: <web.3edf86e32428076b417814a0@news.povray.org>
Some minutes ago I posted an image to povray.binaries.images.
Here's the source code for that image.

Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2003 by Tor Olav Kristensen
// Email: t o r _ o l a v _ k [ a t ] h o t m a i l . c o m
// http://hjem.sol.no/t-o-k/povray
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.5;

#include "functions.inc" // For f_r() and f_torus
#include "textures.inc"
#include "glass.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Macro to build "Angle Of Incidence" functions

#macro AOI_Function(Fn, p0)

  #local x0 = p0.x;
  #local y0 = p0.y;
  #local z0 = p0.z;
  #local h = 1e-4;
  #local h2 = h*2;

  #local Temp0Fn =
    function(GradX, GradY, GradZ, DirX, DirY, DirZ, Div) {
      abs(GradX*DirX + GradY*DirY + GradZ*DirZ)/Div
    }
  #local Temp1Fn =
    function(GradX, GradY, GradZ, DirX, DirY, DirZ) {
      Temp0Fn(
        GradX, GradY, GradZ,
        DirX, DirY, DirZ,
        f_r(GradX, GradY, GradZ)*f_r(DirX, DirY, DirZ)
      )
    }

  function {
    Temp1Fn(
      (Fn(x + h, y, z) - Fn(x - h, y, z))/h2,
      (Fn(x, y + h, z) - Fn(x, y - h, z))/h2,
      (Fn(x, y, z + h) - Fn(x, y, z - h))/h2,
      x - x0,
      y - y0,
      z - z0
    )
  }

#end // macro AOI_Function

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

#declare pCameraLocation = <0.0, 3.4, -5.1>;
#declare pCameraLookAt = <0.0, -2.6, 0.0>;

camera {
  location pCameraLocation
  look_at pCameraLookAt
  angle 100
}

light_source {
  <-4, 2, -1>*10
  color rgb <1, 1, 1>
}

sky_sphere {
  pigment {
    gradient y
    turbulence 0.1
    color_map {
      [ 0.0 color rgb <1.5, 1.5, 1.5> ]
      [ 0.4 color rgb <0.0, 0.0, 0.5> ]
      [ 0.6 color rgb <0.0, 0.0, 0.5> ]
      [ 1.0 color rgb <1.5, 1.5, 1.5> ]
    }
  }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Isosurface with "Angle Of Incidence" controlled texture

#declare Rmaj = 4;
#declare Rmin = 1;

#declare TorusFn = function { f_torus(x, y, z, Rmaj, Rmin) }

#declare GlassMaterial =
  material {
    texture {
      AOI_Function(TorusFn, pCameraLocation)
      texture_map {
        [ 0 Orange_Glass ]
        [ 1 Vicks_Bottle_Glass ]
      }
    }
    interior { I_Glass }
  }

/*
#declare SimpleMaterial =
  material {
    texture {
      AOI_Function(TorusFn, pCameraLocation)
      texture_map {
        [ 0.0 pigment { color rgbt <1.5, 0.0, 0.0, 0.0> } ]
        [ 1.0 pigment { color rgbt <0.0, 1.5, 0.0, 0.0> } ]
      }
    }
  }
*/

#declare pMin = -<Rmaj + Rmin, Rmin, Rmaj + Rmin>;
#declare pMax =  <Rmaj + Rmin, Rmin, Rmaj + Rmin>;

isosurface {
  function { TorusFn(x, y, z) }
  contained_by { box { pMin, pMax } }
  material { GlassMaterial }
//  material { SimpleMaterial }
}

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


Post a reply to this message

From: Tek
Subject: Re: Source code for "AOI textures for isosurfaces"
Date: 5 Jun 2003 18:55:01
Message: <3edfca45$2@news.povray.org>
Wow, that's a clever trick :)

Is it possible to rig up a function to use several slope maps (one on each axis)
to get the surface normal? That way it could work on non-isosurfaces.

Something like:
(x-x0)*slope_x(x,y,z) + (y-y0)*slope_y(x,y,z) + (z-z0)*slope_z(x,y,z)

Would that work?
I'd try it myself only it's getting kinda late...

--
Tek
http://www.evilsuperbrain.com


"Tor Olav Kristensen" <tor### [at] hotmailcom> wrote in message
news:web.3edf86e32428076b417814a0@news.povray.org...
>
> Some minutes ago I posted an image to povray.binaries.images.
> Here's the source code for that image.
>
> Tor Olav
>
>
> // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
> // Copyright 2003 by Tor Olav Kristensen
> // Email: t o r _ o l a v _ k [ a t ] h o t m a i l . c o m
> // http://hjem.sol.no/t-o-k/povray
> // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
>
> #version 3.5;
>
> #include "functions.inc" // For f_r() and f_torus
> #include "textures.inc"
> #include "glass.inc"
>
> // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
> // Macro to build "Angle Of Incidence" functions
>
> #macro AOI_Function(Fn, p0)
>
>   #local x0 = p0.x;
>   #local y0 = p0.y;
>   #local z0 = p0.z;
>   #local h = 1e-4;
>   #local h2 = h*2;
>
>   #local Temp0Fn =
>     function(GradX, GradY, GradZ, DirX, DirY, DirZ, Div) {
>       abs(GradX*DirX + GradY*DirY + GradZ*DirZ)/Div
>     }
>   #local Temp1Fn =
>     function(GradX, GradY, GradZ, DirX, DirY, DirZ) {
>       Temp0Fn(
>         GradX, GradY, GradZ,
>         DirX, DirY, DirZ,
>         f_r(GradX, GradY, GradZ)*f_r(DirX, DirY, DirZ)
>       )
>     }
>
>   function {
>     Temp1Fn(
>       (Fn(x + h, y, z) - Fn(x - h, y, z))/h2,
>       (Fn(x, y + h, z) - Fn(x, y - h, z))/h2,
>       (Fn(x, y, z + h) - Fn(x, y, z - h))/h2,
>       x - x0,
>       y - y0,
>       z - z0
>     )
>   }
>
> #end // macro AOI_Function
>
> // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
>
> #declare pCameraLocation = <0.0, 3.4, -5.1>;
> #declare pCameraLookAt = <0.0, -2.6, 0.0>;
>
> camera {
>   location pCameraLocation
>   look_at pCameraLookAt
>   angle 100
> }
>
> light_source {
>   <-4, 2, -1>*10
>   color rgb <1, 1, 1>
> }
>
> sky_sphere {
>   pigment {
>     gradient y
>     turbulence 0.1
>     color_map {
>       [ 0.0 color rgb <1.5, 1.5, 1.5> ]
>       [ 0.4 color rgb <0.0, 0.0, 0.5> ]
>       [ 0.6 color rgb <0.0, 0.0, 0.5> ]
>       [ 1.0 color rgb <1.5, 1.5, 1.5> ]
>     }
>   }
> }
>
> // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
> // Isosurface with "Angle Of Incidence" controlled texture
>
> #declare Rmaj = 4;
> #declare Rmin = 1;
>
> #declare TorusFn = function { f_torus(x, y, z, Rmaj, Rmin) }
>
> #declare GlassMaterial =
>   material {
>     texture {
>       AOI_Function(TorusFn, pCameraLocation)
>       texture_map {
>         [ 0 Orange_Glass ]
>         [ 1 Vicks_Bottle_Glass ]
>       }
>     }
>     interior { I_Glass }
>   }
>
> /*
> #declare SimpleMaterial =
>   material {
>     texture {
>       AOI_Function(TorusFn, pCameraLocation)
>       texture_map {
>         [ 0.0 pigment { color rgbt <1.5, 0.0, 0.0, 0.0> } ]
>         [ 1.0 pigment { color rgbt <0.0, 1.5, 0.0, 0.0> } ]
>       }
>     }
>   }
> */
>
> #declare pMin = -<Rmaj + Rmin, Rmin, Rmaj + Rmin>;
> #declare pMax =  <Rmaj + Rmin, Rmin, Rmaj + Rmin>;
>
> isosurface {
>   function { TorusFn(x, y, z) }
>   contained_by { box { pMin, pMax } }
>   material { GlassMaterial }
> //  material { SimpleMaterial }
> }
>
> // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
>
>


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Source code for "AOI textures for isosurfaces"
Date: 5 Jun 2003 21:05:41
Message: <Xns9392209102AE3torolavkhotmailcom@204.213.191.226>
"Tek" <tek### [at] evilsuperbraincom> wrote in news:3edfca45$2@news.povray.org:

> Wow, that's a clever trick :)
> 
> Is it possible to rig up a function to use several slope maps (one on
> each axis) to get the surface normal? That way it could work on
> non-isosurfaces. 
> 
> Something like:
> (x-x0)*slope_x(x,y,z) + (y-y0)*slope_y(x,y,z) + (z-z0)*slope_z(x,y,z)
> 
> Would that work?
> I'd try it myself only it's getting kinda late...


I'm not quite sure if I understand what you mean here.

Are you suggesting to actually use the slope_map pattern modifier
or do you mean to use 3 slope functions (one for each component) ?

Please explain more.


Here's a little explanation in the meantime:

The GradX, GradY and GradZ parameters in the macro represents
the 3 components of a non-normalized normal vector of the
corresponding isosurface object.

This vector: <GradX, GradY, GradZ>/f_r(GradX, GradY, GradZ)
-would be the normalized normal vector of the isosurface.

And this vector: <DirX, DirY, DirZ>/f_r(DirX, DirY, DirZ)
- would be the normalized vector from the camera towards
each point on the isosurface.


The dot product of these two vectors is:

(GradX*DirX + GradY*DirY + GradZ*DirZ)
/f_r(GradX, GradY, GradZ)/f_r(DirX, DirY, DirZ)


As long as the primitive is identical to the isosurface formed by
a given function, then one can use the macro in textures and still
get accurate AOI controlled textures.

To see this you can replace the isosurface object in my code with
this:


torus {
  Rmaj, Rmin
  pigment {
    AOI_Function(TorusFn, pCameraLocation)
    color_map {
      [ 0.0 color rgb <2, 0, 0> ]
      [ 1.0 color rgb <0, 2, 0> ]
    }
  }
}


But the problems starts when one are using CSG.


Tor Olav


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Source code for "AOI textures for isosurfaces"
Date: 5 Jun 2003 21:14:46
Message: <Xns9392221B96B17torolavkhotmailcom@204.213.191.226>
"Tor Olav Kristensen" <tor### [at] hotmailcom> wrote in 
news:web.3edf86e32428076b417814a0@news.povray.org:

...
> // http://hjem.sol.no/t-o-k/povray
...


Ooops - My POV-Ray page is here:

http://home.no/t-o-k/povray


Tor Olav


Post a reply to this message

From: Tek
Subject: Re: Source code for "AOI textures for isosurfaces"
Date: 6 Jun 2003 14:49:14
Message: <3ee0e22a$1@news.povray.org>
"Tor Olav Kristensen" <tor_olav_kCURLYAhotmail.com> wrote:
> I'm not quite sure if I understand what you mean here.
>
> Are you suggesting to actually use the slope_map pattern modifier
> or do you mean to use 3 slope functions (one for each component) ?

I meant 3 slope functions. Sorry I always mistakenly call them slope_maps and
then I get confused when POV gives me errors :)

> Please explain more.

Well, basically your angle of incidence calculation works by computing the
surface normal from the gradient of the isosurface function. Then you dot
product that with the position of the point relative to the camera, giving you
the cos of the angle of incedence.

What I'm suggesting is you could find the surface normal using 3 slope
functions, one for each component. Now, if I'm right, those 3 functions will
give you the x, y, and z values of the surface normal. Then you can form the dot
product of that with the vector from the camera to the point, to again get the
cos of the angle of incedence.

That way you could apply the material to any object without needing the
isosurface function for that object.

I think that should work.

--
Tek
http://www.evilsuperbrain.com


Post a reply to this message

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