John's Star Field Page

   When I need a starry background in POV-Ray, I use an assortment of randomly-placed triangles. There are other approaches, but I prefer this because when I'm raytracing I like to use objects that model the simulated objects as closely as possible. Stars, from the sightseeing viewpoint, are just ultra-bright objects that are just close enough to appear as points of light.
   The trick is to place the stars so that at least one pixel but no more than four pixels overlap the star's silhouette on the computer screen. This will give a point of light, especially when anti-aliasing is used.

    Use the following code:

#local sB=sqrt(3)/min(image_height,image_width)/sCamZ;
#local pA=< 0,          sB*2/3,1>*100000;
#local pB=< sB/sqrt(3),-sB/3,  1>*100000;
#local pC=<-sB/sqrt(3),-sB/3,  1>*100000;

#local S0=seed(4);
#local cC=16;
#local sC=.5/cC;#while(sC<=1)
mesh {
#local iI=0; #while (iI<1600/cC*sCamZ*sCamZ)
  #local vAng=<rand(S0),rand(S0),rand(S0)>*360;
  #if (vdot(vrotate(z,vAng),vCamD)>sCamZ/vlength(<sCamR/2,sCamU/2,sCamZ>) | AllStars)  
    triangle { vrotate(pA,vAng), vrotate(pB,vAng), vrotate(pC,vAng) }
  #end
#local iI=iI+1; #end
  no_shadow
pigment { rgb <max(0,-(sC-1)*2),min(sC*4,-(sC-1)*4),max(0,(sC-.25)*4)>*.2+.8 }
finish { ambient 1 diffuse 0 }

//  scale Beyond
  translate pCamL
}
#local sC=sC+1/cC;#end

A number of parameters are used here that you'll need to define first:

  • AllStars: If true, forces all stars to be made. When false prevents creation of off-camera stars
  • Beyond: This is commented out because you may not need it. If any of the stars appear in front of other objects in your scene, take out the slashes and set Beyond to some value that puts the stars beyond all of the other scene objects.
  • cC: This sets the number of shades of color the stars will have. Stars will range in color from reddish to bluish.
  • pCamL: The location setting of your camera.
  • sCamR: The length of the right parameter of the camera. If you didn't specify a right vector in the camera, use a value of 4/3 here.
  • sCamU: The length of the up parameter of the camera. If you didn't specify this parameter in the camera statement, use 1 here.
  • sCamZ: The length of the direction vector in your camera. If you specify the angle in your camera, then set this value equal to cot(radians(angle)/2)*4/3. If you didn't specify either direction or angle, use 1 here.
  • vCamD: The normalized value of the direction vector in your camera


    Back to John's Freeloading Home Page
    Hosted by www.Geocities.ws

    1