POV-Ray : Newsgroups : povray.advanced-users : Texture transition : Re: Texture transition Server Time
29 Jul 2024 00:36:49 EDT (-0400)
  Re: Texture transition  
From:
Date: 10 Jun 2003 00:57:00
Message: <3ee5651c$1@news.povray.org>
// Hi Andrew,
//
// if your object(s) is/are not infinite in the direction of the
// gradient (y in your case), a simple gradient pattern will suffice.
// If the range (along the direction of the gradient) of the object(s)
// to be textured is completely contained in  Bottom ... Top  and the
// range where blending is desired is  Min ... Max,  then the macro call
//
// Blending_pigment (Direction, Bottom, Top, Min, Max, Color_min, Color_max)
//
// creates a pigment with Color_min for Y<Min, Color_max for Y>Max and
// linearly blending from Color_min to Color_max in the y-range  Min to
// Max  if Direction=y, similar for other directions. This pattern repeats
// above Top and below Bottom. The range Bottom to Top should be slightly
// larger than the dimensions of the object(s) in the given direction to
// give rounding errors no chance.
// Because this pigment is a single gradient pattern with a very simple
// color_map, it should be faster than all other solutions.
//
// The same principle can be used with pigments or textures instead of
// colors; then it will be helpful for waterline texturing and the like.
//
// In case of infinite objects (like planes), it usually is acceptable
// to use very large values for Bottom and Top, the coloring errors
// in such a large distance will almost certainly be invisible.
//
// I'll post the picture created by the following demo code to p.b.i.
//
//    Sputnik
//
// --
// ----------------------------

// fr### [at] computermuseumfh-kielde
// ----------------------------



//===== macro for pigment with blending colors ============================

#macro Blending_pigment (

  Direction,   // direction of blending
  Bottom, Top, // usable y-range
  Min, Max,    // range of colors blending from Color_min to Color_max
  Color_min,   // color for y=Bottom .. Min
  Color_max    // color for y=Max .. Top
  )

  pigment {
    gradient Direction
    color_map {
      [ (Min-Bottom)/(Top-Bottom) Color_min ]
      [ (Max-Bottom)/(Top-Bottom) Color_max ]
      }
    scale Top-Bottom
    translate Bottom*Direction
    }

  #end//macro Blending_pigment


//===== examples ==========================================================

// create a box, Y=-400 to 400, blue to red from -100 to 100
box { <-1200, -400, -300>, <-600, 400, 300>
  texture {
    // give it a pigment covering a little more than its y-range
    // which is blue below y=-100, red above y=100 and
    // linearly blending in the range between
    Blending_pigment ( y, -401,401, -100,100, rgb<0,0,1>,rgb<1,0,0> )
    finish {
      ambient .4
      diffuse .6
      }
    }
  }

// another box, Y=-400 to 600, light blue to orange from -300 to 0
box { <-300, -400, -300>, <300, 600, 300>
  texture {
    Blending_pigment ( y, -401,601, -300,0, rgb<.2,.6,1>,rgb<1,.6,.2> )
    finish {
      ambient .4
      diffuse .6
      }
    }
  }

// bad example: large parts of box are outside Bottom ... Top
box { <600, -400, -300>, <1200, 400, 300>
  texture {
    Blending_pigment ( y, -81,81, -40,40, rgb<0,1,0>,rgb<1,1,0> )
    finish {
      ambient .4
      diffuse .6
      }
    }
  }

// infinite plane, blending in z-direction
plane { y, -400
  texture {
    Blending_pigment ( z, -1E7, 1E7, -1000,1000, rgb<0,1,1>,rgb<1,0,1> )
    finish {
      ambient .4
      diffuse .6
      }
    }
  }


light_source { <-1000, 3500, -2000>, color rgb 1 }

camera { location -6000*z look_at 300*y angle 30
  rotate <12, -20, 0>
  }


// END ==================================================================


Post a reply to this message

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