home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 1995 January / pcw-0195.iso / polyray / dat / texture / eclpse.pi < prev    next >
Text File  |  1994-12-31  |  8KB  |  246 lines

  1. //
  2. // Experiment in layered textures:  A portion of a planet is being
  3. // eclipsed by its moon.  All effects will be simulated with solid
  4. // texturing.  The final form of the planet has a series of textures
  5. // going from the umbra/penumbra of the eclipse, down to the oceans.
  6. //
  7. // Polyray input file: Alexander Enzmann
  8.  
  9. background black
  10.  
  11. //
  12. //  Place the sun, at the same time figure out what direction it is at
  13. //  so that we can align the planet and moon with it.
  14. //
  15. define sun_position <-40, 0, -200>
  16. light sun_position
  17.  
  18. define sun_vector sun_position/|sun_position|
  19.  
  20. //
  21. // The moon will be a white bumpy sphere.
  22. //
  23. define cratered
  24. texture {
  25.    noise surface {
  26.       color white
  27.       normal 1
  28.       frequency 4
  29.       bump_scale 2
  30.       ambient 0.05
  31.       diffuse 0.8
  32.       specular white, 0.2
  33.       microfacet Reitz 5
  34.       }
  35.    scale <0.05, 0.05, 0.05>
  36.    }
  37.  
  38. define moon_position sun_vector * 7
  39. object {
  40.    sphere moon_position, 0.3
  41.    cratered
  42.    shading_flags 0
  43.    }
  44.  
  45. //
  46. // Set up the camera, we want to point it somewhere between the planet
  47. // and the moon so that we get a good frame of the two.  The 2/3 point
  48. // worked out pretty well
  49. //
  50. viewpoint {
  51.    from <0,0,-10>
  52.    at 2*moon_position / 3
  53.    up <0,1,0>
  54.    angle 30
  55.    resolution 640, 480
  56.    aspect 4/3
  57.    }
  58.  
  59. //
  60. // Build an eclipse texture.  This is similar in many respects to
  61. // a wood texture.  The central core of the eclipse is black, and
  62. // as we move farther from the core, we move into less and less
  63. // shadowed regions.  After a certain distance there is no more
  64. // shadow and the eclipse texture becomes clear.
  65. //
  66. // Note that the eclipse calculations are done with "W".  The use of
  67. // world coordinates is quite deliberate - we dont want the eclipse to
  68. // move if the planet turns.  The only problem is that the eclipse has to
  69. // be on something at the origin (but then the earth is at the center of
  70. // the universe).
  71. //
  72. define eclipse_point W / |W|
  73. define eclipse_dot (W[0] * sun_vector[0] +
  74.                     W[1] * sun_vector[1] +
  75.                     W[2] * sun_vector[2]) / |W|
  76. define eclipse_dist sqrt(1 - eclipse_dot)
  77. //
  78. // Define the coloring for the eclipse
  79. //
  80. // "eclipse_colors" was just for testing on an otherwise uncolored sphere
  81. // we don't want any color at all in the final layered texture.
  82. //
  83. define eclipse_colors
  84. color_map([0,    0.02, black, black]  // Umbra
  85.           [0.02, 0.22, black, white]  // Penunmbra
  86.           [0.22, 4.0,  white, white]) // No shadow
  87. //
  88. // The function for the alpha is what gives us the black core for values
  89. // less than 0.2, a soft shadow for values between 0.02 and 0.22, and no
  90. // shadow above that.
  91.  
  92. define eclipse_alpha (eclipse_dist < 0.02 ? 0
  93.                         : (eclipse_dist < 0.22
  94.                              ? 5 * (eclipse_dist - 0.02)
  95.                              : 1))
  96. define eclipse
  97. texture {
  98.    special surface {
  99.       color black
  100.       ambient 0.1
  101.       diffuse 0.9
  102.       specular 0
  103.       transmission eclipse_alpha, 1.0
  104.       }
  105.    }
  106.  
  107. //
  108. // Swirling clouds texture
  109. //
  110. // This texture is an attempt to add a sort of simulation of the
  111. // Coriolis effect to the clouds over a planet.  Not real, but
  112. // I think the look is better than a simple noise function.
  113. //
  114. // The clouds are swirled by a modulated helix - as we move up
  115. // and down the y axis, we twist back and forth according to
  116. // the value of "y_fn".  Using this alone produces very even
  117. // looking clouds that twist back and forth.  By then adding some
  118. // displacement to this helix, using the dnoise function, we can
  119. // do some local bubbling of the clouds.
  120. //
  121. // The multipliers used in the definition of "sky_fn" were found by
  122. // playing around.  For a different look, turn off the transmission
  123. // component of the texture and start changing the values.  When you
  124. // find one you like, turn on the transmisson again to add in the
  125. // rest of the planet.
  126. //
  127. define y_fn cos(6*y)
  128. define helical_pos <x*cos(y_fn) + z*sin(y_fn), y, -x*sin(y_fn) + z*cos(y_fn)>
  129. define sky_fn sawtooth(3*noise(2*helical_pos+3*(dnoise(P, 2)-<0.5,0.5,0.5>), 4))
  130. define sky_color
  131. color_map([0,   0.2, white,     white]
  132.           [0.2, 0.4, white,     0.7*white]
  133.           [0.4, 0.5, 0.7*white, black]
  134.           [0.5, 1,   black,     black])
  135. //
  136. // The transparency is chosen to coincide with the black portions of
  137. // the color map used in "sky_color".  Below 0.4 we are in the white
  138. // part of the clouds, between 0.4 and 0.5 we are in transition from
  139. // white to clear, and above 0.5 there are no clouds.
  140. //
  141. define sky_alpha (sky_fn < 0.4 ? 0
  142.                     : (sky_fn < 0.5 ? 10 * (sky_fn - 0.4) : 1))
  143. //
  144. // Finally put together the cloud texture.
  145. //
  146. define swirling_clouds
  147. texture {
  148.    special surface {
  149.       color sky_color[sky_fn]
  150.       ambient 0.2
  151.       diffuse 0.6
  152.       specular 0
  153.       transmission sky_alpha, 1.0
  154.       }
  155.    }
  156.  
  157. //
  158. // What would a planet be without polar ice caps?  This is a very
  159. // simple white/clear texture, however note the offset in the color
  160. // map from what would be expected for a 2 unit sphere that we
  161. // wrap this onto.  This offset is to compensate for the extra
  162. // turbulence we added.
  163. //
  164. define ice_caps
  165. texture {
  166.    noise surface {
  167.       ambient  0.1
  168.       diffuse  0.7
  169.  
  170.       octaves 4
  171.       position_fn 1
  172.       turbulence 1.2
  173.  
  174.       color_map(
  175.          [-5,  -0.8, white, 0, white, 0]
  176.          [-0.8, 2, black, 1, black, 1]
  177.          [ 2,   5, white, 0, white, 0])
  178.       }
  179.    rotate <0, 0, 90>
  180.    }
  181.  
  182. //
  183. // The land mass of the planet is a standard noise function applied
  184. // to a sphere.  Since we are using a sawtooth lookup function, we
  185. // know that all the noise values will be between 0 and 1.  The
  186. // color map is designed to simulate the following features of a
  187. // planet: white -> mountain tops; a medium tan for areas near the
  188. // mountains, a Desert color for arid land, a green color for the
  189. // livable areas, and a clear color for where we are going to put
  190. // the ocean.  The ocean is separated from this texture because it
  191. // will be rippled to simulate waves and applying ripple to the
  192. // land would not look good.
  193. //
  194. define Desert (Wheat + Tan) / 2
  195. define land
  196. texture {
  197.    noise surface {
  198.       color white
  199.       octaves 6
  200.       position_scale 0.5
  201.       lookup_fn 1
  202.       turbulence 1.7
  203.       ambient 0.1
  204.       diffuse 0.7
  205.       specular 0.1
  206.       microfacet Cook 5
  207.       color_map(
  208.          [0,    0.003, white, white]
  209.          [0.003, 0.02, 0.8*Tan, 0.8*Tan]
  210.          [0.002, 0.08, 0.8*Tan, Desert]
  211.          [0.08, 0.15, Desert,   Desert]
  212.          [0.15, 0.2,  Desert,   MediumForestGreen]
  213.          [0.2,  0.4,  MediumForestGreen, MediumForestGreen]
  214.          [0.4,  0.5,  MediumForestGreen, 0, black, 1]
  215.          [0.5,  1.0,  black, 1, black, 1])
  216.       }
  217.    translate <50, 50, -100>
  218.    }
  219.  
  220. //
  221. // The bottom most layer is the ocean.  This is a blue color with
  222. // a ripple applied to the normal.  Clearly the ocean isn't going
  223. // to have waves this big, but it looks nice.
  224. //
  225. define ocean
  226. texture {
  227.    noise surface {
  228.       color <0.4, 0.4, 1.0>
  229.       normal 2
  230.       frequency 500
  231.       bump_scale 2
  232.       ambient 0.2
  233.       diffuse 0.5
  234.       reflection 0.3
  235.       specular white, 0.5
  236.       microfacet Cook 5
  237.       }
  238.    scale <10, 1, 10>
  239.    }
  240.  
  241. object {
  242.    sphere <0, 0, 0>, 2
  243.    texture { layered eclipse, swirling_clouds, ice_caps, land, ocean }
  244.    rotate <0, 20, 0>
  245.    }
  246.