POV-Ray : Newsgroups : povray.programming : Fog code mods ... Server Time
29 Jul 2024 08:24:04 EDT (-0400)
  Fog code mods ... (Message 1 to 2 of 2)  
From: Michael C  Andrews
Subject: Fog code mods ...
Date: 4 Jun 1998 14:15:39
Message: <3576E44B.17E6@reading.ac.uk>
Hi folks,
        I had one request for the sources to my fog modification (thanks
Alain!) so I'll put them here.

        Bye for now,
                Mike Andrews.

PS: To use the effect put a 'use_colour' or 'use_color' followed by a
float value in the fog definition. A zero (default value) will have no
effect, positive numbers will give dark objects a blue tinge, light
objects a red tinge. Negative numbers will reverse the effect. Colour
saturation decreases with the fog's optical density until the pure fog
colour is shown at 'infinite' depth. The modifications were  only
designed for use with gray fogs, but other colours can give some nice
effects :-)

OK, here's the start of the code snippets. For each piece I will
indicate the file, function and approximate line number.

/* -- File : atmosph.h, Function : global space, appx. line : 75 -- */

struct Fog_Struct
{
  int Type;
/* MA - May 1998 */
  DBL Scatter;
/* MA - End */
  DBL Distance;
  DBL Alt;
  DBL Offset;
  COLOUR Colour;
  VECTOR Up;
  TURB *Turb;
  SNGL Turb_Depth;
  FOG *Next;
};

/* -- File : atmosph.c, Function : do_fog(), appx. line : 900 -- */

static void do_fog(Ray, Intersection, Colour, Light_Ray_Flag)
RAY *Ray;
INTERSECTION *Intersection;
COLOUR Colour;
int Light_Ray_Flag;
{
  DBL att, att_inv, width;
/* MA - May 1998 */
  DBL flt;
/* MA - End */
  COLOUR Col_Fog;
  COLOUR sum_att;  /* total attenuation. */
  COLOUR sum_col;  /* total color.       */
  FOG *Fog;

/* -- File : atmosph.c, Function : do_fog(), appx. line : 950 -- */

      /* Check for minimum transmittance. */

/* MA - May 98 */

      flt = att;

/* 
 * I think this is better than an abrupt cut-off point ... 
 * I'll probably do the same for atmosphere as well.
 */

      att = Col_Fog[TRANSM] + att * (1.0 - Col_Fog[TRANSM]);

/*
 * The following functions are _not_ physically based - 
 * I played around with several different function 
 * sets until I found something that looked nice. 
 * I repeat - THEY ARE PURELY EMPIRICAL!
 * The tanh()'s simply compress all colour deltas 
 * to the (-1, 1) range to stop over saturation of the colour, 
 * although this can be forced by using Fog->Scatter > ~1.5
 */
      Col_Fog[RED]   += Fog->Scatter * sin(0.5 * M_PI * flt) * 
                            tanh(Colour[RED]  - Col_Fog[RED]);
      Col_Fog[GREEN] -= 0.25 * Fog->Scatter * sin(2.0 * M_PI * flt) * 
                            tanh(Colour[GREEN]  - Col_Fog[GREEN]);
      Col_Fog[BLUE]  -= Fog->Scatter * sin(0.5 * M_PI * flt) *
                            tanh(Colour[BLUE] - Col_Fog[BLUE]);

      /* Get attenuation sum due to filtered/unfiltered translucency. */

      flt = Col_Fog[FILTER];
      sum_att[RED]    *= att * ((1.0 - flt) + flt * Col_Fog[RED]);
      sum_att[GREEN]  *= att * ((1.0 - flt) + flt * Col_Fog[GREEN]);
      sum_att[BLUE]   *= att * ((1.0 - flt) + flt * Col_Fog[BLUE]);
      sum_att[FILTER] *= att * ((1.0 - flt) + flt * Col_Fog[FILTER]);
      sum_att[TRANSM] *= att * ((1.0 - flt) + flt * Col_Fog[TRANSM]);

/* MA - May 98 - end */

/* -- File : parstxtr.c, Function : Parse_Fog(), appx. line : 2770 -- */

    CASE (FOG_TYPE_TOKEN)
      Fog->Type = (int)Parse_Float();
      if ((Fog->Type < ORIG_FOG) || (Fog->Type > FOG_TYPES))
      {
        Warn(0.0, "Unknown fog type.");
      }
    END_CASE

/* MCA May 98 */

    CASE2 (USE_COLOR_TOKEN, USE_COLOUR_TOKEN)
      Fog->Scatter = Parse_Float();
    END_CASE

/* MCA May 98  - end */

/* -- End of code. -- */


Post a reply to this message

From: Alain CULOS
Subject: Re: Fog code mods ...
Date: 4 Jun 1998 17:57:02
Message: <3577182E.D321C629@bigfoot.com>
Hey,

that was fast !
Thank you very much for that one Michael. I'll make sure I'll look at it
some time, but I'm so damn busy it may not be before weeks or months.
I hope some day I'll be able to share something in return.

Cheers,
Al.


Michael C. Andrews wrote:

> Hi folks,
>         I had one request for the sources to my fog modification (thanks
> Alain!) so I'll put them here.

--
ANTI SPAM / ANTI ARROSAGE COMMERCIAL :

To answer me, please take out the Z from my address.


Post a reply to this message

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