POV-Ray : Newsgroups : povray.binaries.images : Wood grain : Re: Wood grain Server Time
19 Apr 2024 08:28:40 EDT (-0400)
  Re: Wood grain  
From: Chris R
Date: 2 May 2023 08:55:00
Message: <web.6451071f6808bc7793c0941a5cc1b6e@news.povray.org>
"Chris R" <car### [at] comcastnet> wrote:
> "Mike Miller" <mil### [at] gmailcom> wrote:
> > "Chris R" <car### [at] comcastnet> wrote:
> > > Maybe this is an obvious trick to some of the veterans here, but I thought it
> > > was an interesting way to get good color maps for wood, so here it goes.
> > >
> > > I was working on some wood flooring for a scene and found a site called
> > > wood-database.com that has images and information on lots of different types of
> > > wood, including images of lumber made from the types of wood.
> > >
> > > I downloaded an image of the wood I wanted to replicate in my scene, (the lower
> > > left inset in the image below), and imported it into GIMP.  In the Colors/Info
> > > menu there is a "Smooth Palette" option that creates a palette of the colors in
> > > the image, (seen to the right of the inset).  I exported that as a JPEG and then
> > > used some macros I created to pull out the POV-ray colors from the image.  I
> > > have used both interpolation and non-interpolation for different effects.  I
> > > then use those colors, in the order given, to create the color map for the wood
> > > texture.
> > >
> > > Coming up with the wood pigment and warps is still mostly trial and error, but
> > > the sample is actually pretty close.
> > >
> > > The three boards are rendered using variations on the color map.  The center one
> > > is non-translated and unaltered.  The right has been lightened, and the grain
> > > was selected randomly from a normal-sized pine tree.  The left was grayed by
> > > aging, and also randomly selected.
> > >
> > > In this particular example, I only sampled the colors from a single ring of the
> > > wood pattern.  For others, the colors vary across rings, so it works better to
> > > use all of the colors in the color map, but scale the pigment so the ring sizes
> > > stay the same.
> > >
> > > Anyway, I'm finding this is a lot easier than my usual hit or miss method of
> > > creating a wood colormap, and allows for greater variation in the colors, which
> > > enhances realism.
> > >
> > >
> > > -- Chris R.
> >
> >
> > That's excellent Chris. Nice work. I came close to writing a macro to do the
> > same - generate a pov color_map from a given image. Mind sharing the macro? :)
> > Mike.
>
> I am doing some more experiments and cleaning up the code.  I'll get around to
> posting it eventually after I look at some of the suggestions from below as
> well.  The version I have right now just creates a pigment function using an
> image_map from the palette jpeg, and then scans it from <0,0,0> to <1,0,0> in
> steps based on the size of the color map I want to generate.  It then just dumps
> the colors it found using #debug as a color_map {} and I copy and paste from the
> message window into my code.
>
> There's a bunch of things to clean up based on failed experiments.
>
> -- Chris R.

For what it's worth, here's the new macro I defined.  It now actually generates
a color_map so you can include it as part of modeling, but gives the option of
dumping it to #debug so you can copy and paste it and modify it for artistic
purposes.

I updated it to take any pigment as input to represent the color palette, as
well as allowing you to specify a range other than 0.0 to 1.0 for the range to
sample colors from.  This makes it easier to select a subset of the palette.

I'm sure there's a better way to ignore the alpha channel, but this was quick
and dirty so I didn't hunt for one.

#macro Wood_colormap(PalettePigment,MaxEntries,Start,End)
    #ifdef (Wood_colormap_debug) #debug "color_map {\n" #end
    #local _cm  = color_map {
        #local _cur_pt      = Start;
        #local _cur_offset  = 0.0;
        #local _step        = (End-Start)/MaxEntries;
        #local _step_offset = 1/MaxEntries;
        #while (_cur_pt <= End)
            #local _cur_color   = eval_pigment(PalettePigment,<_cur_pt, 0, 0>);
            #local _scolor      = <_cur_color.red, _cur_color.green,
_cur_color.blue>;
            #ifdef (Wood_colormap_debug) #debug concat("   [", str(_cur_offset,
0, 3), ", rgb <", vstr(3, _scolor, ",", 0, 4), ">]\n") #end
            [_cur_offset, rgb _scolor]
            #local _cur_pt      = _cur_pt + _step;
            #local _cur_offset  = _cur_offset + _step_offset;
        #end
    #ifdef (Wood_colormap_debug) #debug "}\n" #end
    }

    _cm
#end

The image uses this color_map directly:

#local _board_cm    = color_map { Wood_colormap(_colors_pigment, 24, 0.0, 0.9) }
#local _board_pigment   = pigment {
    wood
    warp { ... }
    color_map { _board_cm }
}

Here's the #debug output:

color_map {
   [0.000, rgb <0.9473,0.7682,0.5972>]
   [0.042, rgb <0.8815,0.6459,0.4811>]
   [0.083, rgb <0.8542,0.5965,0.4078>]
   [0.125, rgb <0.8364,0.6356,0.4650>]
   [0.167, rgb <0.8929,0.7560,0.5718>]
   [0.208, rgb <0.9048,0.7418,0.5618>]
   [0.250, rgb <0.8388,0.6732,0.4993>]
   [0.292, rgb <0.8236,0.6438,0.4899>]
   [0.333, rgb <0.7335,0.5126,0.3459>]
   [0.375, rgb <0.8308,0.6514,0.4851>]
   [0.417, rgb <0.8309,0.6514,0.5029>]
   [0.458, rgb <0.8574,0.6605,0.4905>]
   [0.500, rgb <0.8372,0.6424,0.4701>]
   [0.542, rgb <0.8276,0.5571,0.3510>]
   [0.583, rgb <0.8125,0.6235,0.4699>]
   [0.625, rgb <0.7305,0.5059,0.3492>]
   [0.667, rgb <0.8252,0.6073,0.4353>]
   [0.708, rgb <0.8156,0.6383,0.4741>]
   [0.750, rgb <0.8228,0.6445,0.4793>]
   [0.792, rgb <0.8308,0.6119,0.4425>]
   [0.833, rgb <0.9098,0.7310,0.5561>]
   [0.875, rgb <0.9140,0.7396,0.5553>]
   [0.917, rgb <0.7859,0.5887,0.4250>]
   [0.958, rgb <0.8085,0.5634,0.3648>]
   [1.000, rgb <0.8583,0.6620,0.5145>]
}


-- Chris R.


Post a reply to this message


Attachments:
Download 'woodgrains.png' (234 KB)

Preview of image 'woodgrains.png'
woodgrains.png


 

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