POV-Ray : Newsgroups : povray.unofficial.patches : Some ideas about SDL enhancements : Re: Some ideas about SDL enhancements Server Time
5 Jul 2024 15:13:29 EDT (-0400)
  Re: Some ideas about SDL enhancements  
From: ABX
Date: 3 Apr 2003 02:09:14
Message: <a5jn8vs8n8u2929ajl86cmjtbhsamdm4fh@4ax.com>
On Wed, 02 Apr 2003 17:07:06 -0500, Christopher James Huff
<cja### [at] earthlinknet> wrote:
> I doubt it, unless somebody else has worked up a more capable function 
> language. I'm talking about something more like (roughly):
>
> define BasicCamera = camera {...usual camera stuff...}
>
> special_camera {
>   function trace_pixel(x, y) {
>    define pixelColor = BasicCamera.trace_pixel(x, y);
>    return pixelColor + (1 - 
>      pixelColor.alpha)*bkgndPigment(x/image_width, y/image_height);
>    }
> }
> > > pigment function to determine the final pixel color.

(Are you sure you used correct math for this effect? I used weighting.)

That's possible and already tested with my post_process implementation (if you
wish I can send sample image to p.b.i but its content seems obvious). It is
possible with following script.

  #version unofficial megapov 1.1;
  #include "pprocess.inc"

  Use_PP_Color_Output() // this macro turns on caching of color output and
                        // defines internal functions f_output_red,
                        // f_output_green, f_output_blue and f_output_alpha
                        // for further usage

  #declare back_Pig=function{pigment{agate}}; // pigment for background
  #declare f_avg=function(v1,v2,w){(1-w)*v1+w*v2}; // average/weight

  sphere{0 1 translate z*4 pigment{rgb 1}}
  light_source{-99 1}
  camera{}

  global_settings{
    post_process{
      // functions for four channels of output
      function{f_avg(f_output_red(x,y)  ,back_Pig(x,y,0).x,f_output_alpha(x,y))}
      function{f_avg(f_output_green(x,y),back_Pig(x,y,0).y,f_output_alpha(x,y))}
      function{f_avg(f_output_blue(x,y) ,back_Pig(x,y,0).z,f_output_alpha(x,y))}
      function{0}
      save_file "with_background.png"
    }
  }

Please note that there will be two passes, one for rendering and one for
post_process. But it will be also possible to do it in one pass. Instead of
using internal function with output of rendering you could use new camera_view
pigment type. The engine recognizes lack of output usage (it simple checks
whether output internal functions are defined in script). So rendering is
skipped (or rather does not use trace) and post_process loop starts. It is
possible and already tested with following script:

  #version unofficial megapov 1.1;
  #declare back_Pig=function{pigment{agate}}; // pigment for background
  #declare camb_Pig=function{pigment{camera_view{}  // rendering output
                            scale -y translate y}}; // has to be transformed
                                                    // like all image maps
  #declare f_avg=function(v1,v2,w){(1-w)*v1+w*v2}; // average/weight

  sphere{0 1 translate z*4 pigment{rgb 1}}
  light_source{-99 1}

  global_settings{
    post_process{
      // functions for four channels of output

function{f_avg(camb_Pig(x,y,0).x,back_Pig(x,y,0).x,camb_Pig(x,y,0).transmit)}

function{f_avg(camb_Pig(x,y,0).y,back_Pig(x,y,0).y,camb_Pig(x,y,0).transmit)}

function{f_avg(camb_Pig(x,y,0).z,back_Pig(x,y,0).z,camb_Pig(x,y,0).transmit)}
      function{0}
      save_file "with_background.png"
    }
  }

Please note that you have more control in this implementation than in your
script becouse you can define differend behaviour for each channel. In order to
avoid such long syntax for every scene you can simple collect your favourite
post_processes in macros (as it is done for replications of post_processing
effects used in previous MegaPovs) as well as in #declarations. Imagine:

  #macro PP_Clip_Colors(Color_Min,Color_Max)
    #local cminr=Color_Min.red;
    #local cmaxr=Color_Max.red;
    #local cming=Color_Min.green;
    #local cmaxg=Color_Max.green;
    #local cminb=Color_Min.blue;
    #local cmaxb=Color_Max.blue;
    #local cmina=Color_Min.transmit;
    #local cmaxa=Color_Max.transmit;
    function{clip(f_pp_red(u,v,-1)  ,cminr,cmaxr)}
    function{clip(f_pp_green(u,v,-1),cming,cmaxg)}
    function{clip(f_pp_blue(u,v,-1) ,cminb,cmaxb)}
    function{clip(f_pp_alpha(u,v,-1),cmina,cmaxa)}
  #end

  global_settings{
    post_process{ PP_Clip_Colors(rgb.1,rgb.9) }
  }

Moreover instead of refering to output data of rendering, you can refer one of
previous post_process effects. In below script in first effect channels are
reordered, in second effect they are inversed, in third effect they are
transformed:

  #version unofficial megapov 1.1;
  #include "pprocess.inc"
  Use_PP_Effects_Output() // defines internal functions f_pp_red, f_pp_green,  
                          // f_pp_blue and f_pp_alpha for further usage
  global_settings{
    post_process{
      function{f_output_green(x,y))} // green instead of red
      function{f_output_blue(x,y))}  // blue  instead of green
      function{f_output_red(x,y))}   // red   instead of blue
      function{f_output_alpha(x,y))} // transparency not changed
    }
    post_process{
      function{1-f_pp_green(x,y,1))} // inverse green
      function{1-f_pp_blue(x,y,1))}  // inverse blue
      function{1-f_pp_red(x,y,1))}   // inverse red
      function{f_pp_alpha(x,y,1))}   // transparency not changed
      save_file "inversed.png"
    }
    post_process{
      function{f_pp_green(x,1-y,2))} // mirror along y
      function{f_pp_blue(x,1-y,2))}  // mirror along y
      function{f_pp_red(x,1-y,2))}   // mirror along y
      function{f_pp_alpha(x,1-y,2))} // mirror along y
    }
  }

In above example there will be only two passes. One for rendering and one for
second effect. First effect if calculated online. Third effect is not calculated
because has no save_file parameter and is not used in any other effect.

Please note third parameter of f_pp_* functions. If positive it is index to
refer which previous effect should be calculated to get value. Index 0 means
original rendering output. Index negative is relative to current effect (simpler
when long list of effects is used).

I hope you like this new post_processing.

> > In case you mean something like camera_view pigment, then such a thing is
> > already done for future MegaPOV
>
> Again, highly doubtful.

In case you could deliver example script with description of expected image we
could clarify it.

ABX


Post a reply to this message

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