Particles


Author: Pabs - April-May 2000 (based on a project by James Neill - March 1995 (based on a project by Ryan D. Kelly - 1994))
e-mail: pabs3@hotmail.com & JamesNeill@icl.com
URL: http://zip.to/pabs3 & http://home.clara.net/renaissance59/

Notes


Don't know if this will be of use to anyone

For a better description of how this patch works & some implementation details you should really read James' project report or take a look at the source.
James' project report also contains several of his test images - when converted to POV they will not produce the same results
Particles are NOT objects & no they are not implemented as objects- they are fields that affect light (another atmospheric effect like rainbows & media)
As they are NOT objects they cannot have textures, interiors, media, transformations etc but they can be translated at parse time
I don't know if they will work with media & other atmospheric effects in the same scene, but they should.
This is because the atmosphere code does not allow a ray to be affected by atmospheric effects in the order the ray goes through the atmospheric effects
They can be made to act kind of like objects using checkrad num, which effectively creates a particle inside a sphere. Setting num to 0.0 makes them act as infinite fields again.
They are effectively 2D but can be made kind of 3D using incstart & incend
I thought of modifying the sphere parsing code to create particles from spheres but its pointless really
They should interact with photons & radiosity just like media & other atmospheric effects, although I have not tried them.
You can #declare them, re-use them using particle [ s ] { idname } and #undef them
They should work as macro parameters
If people want this I will allow them to be added to csgs (like lights are)
I may some time in the future let objects be containers for them if there is support & or assistance
e-mail any other bug-reports, ideas, suggestions or comments to me (Pabs) not the POV-Team or James Neill (he tells me he is very busy & he didn't write the patch anyways)
Disclaimer: This patch probably has bugs in it so make sure you save & perhaps backup your scene files before rendering + all that stuff about me not being responsible for anything bad that happens to your computer.
Note however that it has not done anything disastrous during my testing & probably won't during yours

Syntax


Note: see the POV-Ray docs for the syntax format, but it is fairly simple
global_settings{ particle [ s ] { incstart [Boolean] | incend [Boolean] } | Boolean }

#default{ DEFAULT_ITEM |
        particle [ s ] [ {
                 [Particle_Identifier] [PARTICLE_STUFF…]
         } | Particle_Identifier]
}

particles
[ { [Particle_Identifier]
         [
" particle_file.prt " [,] " Format_string "]
        [PARTICLE_STUFF]…
} |
        Boolean]


particle [ { [Particle_Identifier] [<Center> [ , ] Size ]
        [PARTICLE_STUFF]…
} |
        Boolean]

PARTICLE_STUFF:
Group Defaults Format specifiers Syntax Explanation SEB - See equations below)
Global Settings off incstart [Boolean] Includes the particle before the ray origin in colouring effects
off incend [Boolean] Includes the particle after the ray intersection in colouring effects
Particle < 0, 0, 0> c center <Center> | Location of the particle SEB
t translate <transvector> | Translates center by a vector
1 z size Size | The size of the particle SEB
0 k check_radius Checkrad | If the particle is this greater than this distance from the ray then its effects are ignored
0 n noise noiselevel | Multiplied by a 3D noise value (same as bozo (I think – calls dbl Noise(vec))) and added to a particle's influence at a point - perhaps this will become a pattern some day instead of Noise SEB
1 e noise_scale scalelevel | Scale the point by this before calculating the 3D noise value SEB
Color 1 d density Density | SEB
1 f falloff Falloff | SEB
off o colour_effects | color_effects [Boolean] | Turn colour effects on SEB
rgb <1,1,1> C colour | color COLOUR | The colour of the particle SEB
rgb <0,0,0> i illum_colour | illum_color COLOUR | The illumination the particle contributes to the ray SEB
Refraction off r refraction [Boolean] | Turn refraction on and off. The key to successful refraction is don't place your particles too close to objects or the whole object may fill your field of view 30-40 POV units is good
< 0.1, 0.0> a angle <2D Refraction_angle> | Setting both to zero may result in stack overflows & slows the scene down heaps. I have no idea why. SEB
off I inverse [Boolean] When calculating the refracted ray takes point on ray from center instead of reverse – refracts away from particle instead SEB

The format for particle_file.prt is specified by the artist in the Format_string– use the format specifier chars in the above table to specify the corresponding parameter of PARTICLE_STUFF. The particle file is just a text file full of numbers – ints/floats with whitespace between them (like printf would output) – make sure there are no other characters like “abc$&%*~][m” etc. or an error will be issued & you will have to restart parsing.
Note – if you specify any character other than these (except for white-space) a warning is issued and the file is parsed as per usual, ignoring the errant characters (they are deleted internally - but not from your source).

Use


Specifying any of the following turns particle rendering on:
global_settings{ particles on }
particles
particle
particles true
particles yes
particles on
particle on
particle 1
particle 2
particle{<1,1,1>, <1,1,1> …} //not sure if these should turn it on or not email me
particles{ "pf.prt" "tc" …}

And likewise the following turn particle rendering off
global_settings{ particles off }
particles no
particles false
particles off
particle 0


There are several things particles can do in a scene: colour a light ray, refract light and sometime in the future cast shadows

Colouring a light ray


When a light ray is returning from its source (infinity / light source / reflection) and it passes a particle the particle alters its colour. The particle can illuminate the ray (add to is intensity) or absorb some or all of its colour / intensity.
An example of this is below
particle{ 0, .1 colour_effects on//the on is not necessary
        colour .5 // lets through half of the light
        illumcol .5 //adds .5 * its colour (.25) to the light
}

//Particles can alter each rgb component separately

particle{ 0, .1 colour_effects on//the on is not necessary
        colour rgb <.5, 1, 1> // lets through half of the red light and all of the other light
        illumcol rgb <0, 0, 0.5> //adds .5 * its blue colour (.5) to the light and nothing else
}

Refracting a light ray


When a ray is back-traced into a scene particles can alter the direction of the ray. Basically a new ray is created that originates from the point closest to the particle on the old ray, and has a direction that is similar to the old one, but is perturbed toward or away from the particle.
The ray can also be perturbed to the side of the particle.
eg
particle{ 0, .1 refraction on//the on is not necessary
        angle <0.1,0> //just refract toward the particle
}

particle{ 0, .1 refraction on//the on is not necessary
        angle <0.1,0.1> //refract toward the particle and clockwise around it
}

particle{ 0, .1 refraction on//the on is not necessary
        angle <0.1,-0.1> inverse//refract away from the particle and clockwise around it
}

particle{ 0, .1 refraction on//the on is not necessary
        angle <-0.1,-0.1> //refract away from the particle and anticlockwise around it
          //negative sign here has same effect as 'inverse'
}

Equations


Degree of effect


f(d) = pd × cropmax(1, ps × (d-pf )) + pn × Noise(pns × point)
Where
        point = point on the ray closest to the particle
        d = distance of point from center of the particle
        pd = particle density
        ps = " size
        pf = " falloff
        pn = " noise
        pns = " " scale
        Noise = the POV-Ray Noise function

Colour


ncx = ( 1 - f(d) ) × ocx +
        f(d) × pcx × ocx × ( 1 - ilx ) +
        f(d) × pcx × ilx
Where terms ending in x are red, green & blue components
        nc = new colour of the ray after passing the particle
        oc = old colour of the ray before passing the particle
        pc = colour of the particle
        il = illumination component

Refraction


Refraction amount rax = pax × ps / d + pn × Noise(pns × point)
        pa = angle component (u & v components)
New ray origin = point on old ray closest to the particle
New ray direction = vnorm( old_ray_dir + rau × vnorm(point - center) + rav × vnorm ( vcross( old_ray_dir, point - center ) )
        rau = refraction amount produced from angle 1
        rav = refraction amount produced from angle 2

Images & Code


Color effects


01.pov
With particle Without particle

Refraction effects


02.pov
With particle Without particle

Both effects, checkrad & different settings


03.pov
With particle Without particle

Example of using a particle file to hold the parameters


04.pov & 04.prt
Note that the extension does not have to be "prt" & that I have not rendered this image so it could be anything - I just included random particles

Some more images


(src not available - I just played around for a while & kept the good ones)
crackle*03.pov sphere & particle particle behind spheresphere & particle

Source changes from MegaPOV 0.5


particle.c & particle.h added

atmosph.c express.c - these just convenience changes, but are needed express.h frame.h parse.c parse.h povray.h render.c tokenize.c vbuffer.c