home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 1995 January
/
pcw-0195.iso
/
polyray
/
dat
/
texture
/
eclpse.pi
< prev
next >
Wrap
Text File
|
1994-12-31
|
8KB
|
246 lines
//
// Experiment in layered textures: A portion of a planet is being
// eclipsed by its moon. All effects will be simulated with solid
// texturing. The final form of the planet has a series of textures
// going from the umbra/penumbra of the eclipse, down to the oceans.
//
// Polyray input file: Alexander Enzmann
background black
//
// Place the sun, at the same time figure out what direction it is at
// so that we can align the planet and moon with it.
//
define sun_position <-40, 0, -200>
light sun_position
define sun_vector sun_position/|sun_position|
//
// The moon will be a white bumpy sphere.
//
define cratered
texture {
noise surface {
color white
normal 1
frequency 4
bump_scale 2
ambient 0.05
diffuse 0.8
specular white, 0.2
microfacet Reitz 5
}
scale <0.05, 0.05, 0.05>
}
define moon_position sun_vector * 7
object {
sphere moon_position, 0.3
cratered
shading_flags 0
}
//
// Set up the camera, we want to point it somewhere between the planet
// and the moon so that we get a good frame of the two. The 2/3 point
// worked out pretty well
//
viewpoint {
from <0,0,-10>
at 2*moon_position / 3
up <0,1,0>
angle 30
resolution 640, 480
aspect 4/3
}
//
// Build an eclipse texture. This is similar in many respects to
// a wood texture. The central core of the eclipse is black, and
// as we move farther from the core, we move into less and less
// shadowed regions. After a certain distance there is no more
// shadow and the eclipse texture becomes clear.
//
// Note that the eclipse calculations are done with "W". The use of
// world coordinates is quite deliberate - we dont want the eclipse to
// move if the planet turns. The only problem is that the eclipse has to
// be on something at the origin (but then the earth is at the center of
// the universe).
//
define eclipse_point W / |W|
define eclipse_dot (W[0] * sun_vector[0] +
W[1] * sun_vector[1] +
W[2] * sun_vector[2]) / |W|
define eclipse_dist sqrt(1 - eclipse_dot)
//
// Define the coloring for the eclipse
//
// "eclipse_colors" was just for testing on an otherwise uncolored sphere
// we don't want any color at all in the final layered texture.
//
define eclipse_colors
color_map([0, 0.02, black, black] // Umbra
[0.02, 0.22, black, white] // Penunmbra
[0.22, 4.0, white, white]) // No shadow
//
// The function for the alpha is what gives us the black core for values
// less than 0.2, a soft shadow for values between 0.02 and 0.22, and no
// shadow above that.
define eclipse_alpha (eclipse_dist < 0.02 ? 0
: (eclipse_dist < 0.22
? 5 * (eclipse_dist - 0.02)
: 1))
define eclipse
texture {
special surface {
color black
ambient 0.1
diffuse 0.9
specular 0
transmission eclipse_alpha, 1.0
}
}
//
// Swirling clouds texture
//
// This texture is an attempt to add a sort of simulation of the
// Coriolis effect to the clouds over a planet. Not real, but
// I think the look is better than a simple noise function.
//
// The clouds are swirled by a modulated helix - as we move up
// and down the y axis, we twist back and forth according to
// the value of "y_fn". Using this alone produces very even
// looking clouds that twist back and forth. By then adding some
// displacement to this helix, using the dnoise function, we can
// do some local bubbling of the clouds.
//
// The multipliers used in the definition of "sky_fn" were found by
// playing around. For a different look, turn off the transmission
// component of the texture and start changing the values. When you
// find one you like, turn on the transmisson again to add in the
// rest of the planet.
//
define y_fn cos(6*y)
define helical_pos <x*cos(y_fn) + z*sin(y_fn), y, -x*sin(y_fn) + z*cos(y_fn)>
define sky_fn sawtooth(3*noise(2*helical_pos+3*(dnoise(P, 2)-<0.5,0.5,0.5>), 4))
define sky_color
color_map([0, 0.2, white, white]
[0.2, 0.4, white, 0.7*white]
[0.4, 0.5, 0.7*white, black]
[0.5, 1, black, black])
//
// The transparency is chosen to coincide with the black portions of
// the color map used in "sky_color". Below 0.4 we are in the white
// part of the clouds, between 0.4 and 0.5 we are in transition from
// white to clear, and above 0.5 there are no clouds.
//
define sky_alpha (sky_fn < 0.4 ? 0
: (sky_fn < 0.5 ? 10 * (sky_fn - 0.4) : 1))
//
// Finally put together the cloud texture.
//
define swirling_clouds
texture {
special surface {
color sky_color[sky_fn]
ambient 0.2
diffuse 0.6
specular 0
transmission sky_alpha, 1.0
}
}
//
// What would a planet be without polar ice caps? This is a very
// simple white/clear texture, however note the offset in the color
// map from what would be expected for a 2 unit sphere that we
// wrap this onto. This offset is to compensate for the extra
// turbulence we added.
//
define ice_caps
texture {
noise surface {
ambient 0.1
diffuse 0.7
octaves 4
position_fn 1
turbulence 1.2
color_map(
[-5, -0.8, white, 0, white, 0]
[-0.8, 2, black, 1, black, 1]
[ 2, 5, white, 0, white, 0])
}
rotate <0, 0, 90>
}
//
// The land mass of the planet is a standard noise function applied
// to a sphere. Since we are using a sawtooth lookup function, we
// know that all the noise values will be between 0 and 1. The
// color map is designed to simulate the following features of a
// planet: white -> mountain tops; a medium tan for areas near the
// mountains, a Desert color for arid land, a green color for the
// livable areas, and a clear color for where we are going to put
// the ocean. The ocean is separated from this texture because it
// will be rippled to simulate waves and applying ripple to the
// land would not look good.
//
define Desert (Wheat + Tan) / 2
define land
texture {
noise surface {
color white
octaves 6
position_scale 0.5
lookup_fn 1
turbulence 1.7
ambient 0.1
diffuse 0.7
specular 0.1
microfacet Cook 5
color_map(
[0, 0.003, white, white]
[0.003, 0.02, 0.8*Tan, 0.8*Tan]
[0.002, 0.08, 0.8*Tan, Desert]
[0.08, 0.15, Desert, Desert]
[0.15, 0.2, Desert, MediumForestGreen]
[0.2, 0.4, MediumForestGreen, MediumForestGreen]
[0.4, 0.5, MediumForestGreen, 0, black, 1]
[0.5, 1.0, black, 1, black, 1])
}
translate <50, 50, -100>
}
//
// The bottom most layer is the ocean. This is a blue color with
// a ripple applied to the normal. Clearly the ocean isn't going
// to have waves this big, but it looks nice.
//
define ocean
texture {
noise surface {
color <0.4, 0.4, 1.0>
normal 2
frequency 500
bump_scale 2
ambient 0.2
diffuse 0.5
reflection 0.3
specular white, 0.5
microfacet Cook 5
}
scale <10, 1, 10>
}
object {
sphere <0, 0, 0>, 2
texture { layered eclipse, swirling_clouds, ice_caps, land, ocean }
rotate <0, 20, 0>
}