Tutorial:MapWithPOVRay(Tinnut): Difference between revisions

From Spring
Jump to navigationJump to search
Tinnut (talk | contribs)
No edit summary
Tinnut (talk | contribs)
No edit summary
Line 34: Line 34:


7) Copy the following povray scene code into the above file:
7) Copy the following povray scene code into the above file:
{| class="wikitable" style="font-style:italic; font-size:120%; border:1px dashed red;background-color:white"
|
<pre>
// Setup some parameters that we will use within the script
#declare MAP_WIDTH=8192;
#declare MAP_HEIGHT=8192;
#declare MAP_ELEVATION=600;
global_settings {
  // ambient light level
  ambient_light rgb<1,1,1>
}
// Set a directional light
light_source {
  <100,-100,100> * 20, color rgb 1
  parallel
  point_at <1, 0, 0>
}
// Set the background colour
background {rgb<1,1,1>}
// Define our camera position, and set it to "orthographic" (important :)
camera {
  orthographic
  location <0,0,MAP_ELEVATION + 90>    // position & direction of view
  look_at  <0,0,0>
  right MAP_WIDTH*x            // horizontal size of view
  up MAP_HEIGHT*z              // vertical size of view
}
// ** Define our primary textures **
// lowest texture (512 x 512)
// Found in low lying areas of the heightfield
#declare level1_texture =
texture {
  pigment {
    image_map {
      png "level1.png"
    }
  }
  finish {ambient 1 diffuse 0}
  scale <512/MAP_WIDTH, 512/MAP_WIDTH, 512/MAP_WIDTH>
}
// middle texture (512 x 512)
// Found in the middle areas of the heightfield
#declare level2_texture =
texture {
  pigment {
    image_map {
      png "level2.png"
    }
  }
  finish {ambient 1 diffuse 0}
  scale <512/MAP_WIDTH, 512/MAP_WIDTH, 512/MAP_WIDTH>
}
// highest texture (512 x 512)
// Found in the peaks / hills / mountains of the heightfield
#declare level3_texture =
texture {
  pigment {
    image_map {
      png "level3.png"
    }
  }
  finish {ambient 1 diffuse 0}
  scale <512/MAP_WIDTH, 512/MAP_WIDTH, 512/MAP_WIDTH>
}
// Define a texture that blends from one level's texture to the next, depending on elevation:
#declare levels_elevation_texture=
texture {
  gradient z
 
  texture_map {
    [0.00 level1_texture]  // from 0.0 to 0.1 we have just level1.png
    [0.10 level1_texture]
                          // from 0.1 to 0.2 we blend from level1.png to level2.png
    [0.30 level2_texture]  // from 0.2 to 0.5 we have just level2.png
    [0.40 level2_texture]
                          // from 0.5 to 0.6 we blend from level2.png to level3.png
    [0.60  level3_texture]  // from 0.6 to 1.0 we have just level2.png
    [1.00  level3_texture]
  }
}


// ** Define textures used on areas of slope
// lower slope texture (512 x 512)
#declare slope1_texture =
texture {
  pigment {
    image_map {
      png "slope1.png"
    }
  }
  finish {ambient 1 diffuse 0}
  scale <512/MAP_WIDTH, 512/MAP_WIDTH, 512/MAP_WIDTH>
}
// upper slope texture (512 x 512)
#declare slope2_texture =
texture {
  pigment {
    image_map {
      png "slope2.png"
    }
  }
  finish {ambient 1 diffuse 0}
  scale <512/MAP_WIDTH, 512/MAP_WIDTH, 512/MAP_WIDTH>
}
// Define a texture that blends from one slope's texture to the next, depending on elevation:
#declare slopes_elevation_texture=
texture {
  gradient z
 
  texture_map {
    [0.00 slope1_texture]
    [0.30 slope1_texture]
   
    [0.65  slope2_texture]
    [1.00  slope2_texture]
  }
}
// ** Now define the final texture blending between the height textures and the slope textures:
#declare final_texture =
texture {
  slope {
    <0,0,-1>, 0, 0.5
  }
  texture_map {
    [0.00    levels_elevation_texture]
    [0.06    levels_elevation_texture]
    [0.40    slopes_elevation_texture]
    [1.00    slopes_elevation_texture]
  }
} 
// ***!! Now we declare our heightfield object that uses this texture
height_field {
  png "povmap_height.png"                                 
  smooth              // smooth the heightfield
  no_shadow          // you may want to remove this
  translate <-.5, -.5, -.5>
  rotate <90,0,0>    // rotate it so that the projection of the texture is correct
  scale <1,-1,1>      // invert the y axis
  translate <0.5, 0.5, 0.5>
  texture {
    final_texture
  }
 
  scale <MAP_WIDTH, MAP_HEIGHT, MAP_ELEVATION>    // now scale to the maps height x width
  translate <-MAP_WIDTH/2, -MAP_HEIGHT/2, -MAP_ELEVATION/2>  // and center it for the camera
}
</pre>
|}


8) Double click on your gen_pov_texture.pov file so that it opens up in Povray.
8) Double click on your gen_pov_texture.pov file so that it opens up in Povray.
Line 69: Line 233:


1) Define a function that will return the current metal locations in a pov kind of way:
1) Define a function that will return the current metal locations in a pov kind of way:
<pre>
{| class="wikitable" style="font-style:italic; font-size:120%; border:1px dashed red;background-color:white"
|
<pre><pre>
   #declare getMetal = function {
   #declare getMetal = function {
     pigment {
     pigment {
Line 79: Line 245:
   }
   }
</pre>
</pre>
 
|}
This function, when called for a given coordinate (0 to 1), returns a vector of the three colours for that point.
This function, when called for a given coordinate (0 to 1), returns a vector of the three colours for that point.


2) We now define a texture that we'll use for our metal (this is made up of a number of subcomponent textures):
2) We now define a texture that we'll use for our metal (this is made up of a number of subcomponent textures):
{| class="wikitable" style="font-style:italic; font-size:120%; border:1px dashed red;background-color:white"
|
<pre>
<pre>
// A simple brownish texture
// A simple brownish texture
Line 146: Line 314:
}   
}   
</pre>
</pre>
 
|}
3) Finally, we define a "blob" object that adds a sphere object to the master blob object for each point in the metal map:  
3) Finally, we define a "blob" object that adds a sphere object to the master blob object for each point in the metal map:  
{| class="wikitable" style="font-style:italic; font-size:120%; border:1px dashed red;background-color:white"
{| class="wikitable" style="font-style:italic; font-size:120%; border:1px dashed red;background-color:white"

Revision as of 10:42, 26 February 2008

Howto: Create a map's texture using Povray to generate the texture

!! This is currently a work in progress and make take some time to complete. !!

Intro

This guide will take you through creating a Spring map's texture using the freeware Povray program. It does not cover other aspects of map creation (heighmaps, features, metal, compiling, etc), but there are a few excellent guides within the Wiki that already cover those steps.

Povray is available for both Windows and Linux. I have only tested these steps under Windows, but they should work under Linux.

Initial Steps

1) Download and install Povray: Povray Site

2) Create a working folder for your map, for this example, we'll make C:\PovMap

3) Create a heightmap using whatever program (I like The GIMP). Here is the one we'll use for our map:


4) For our example, we'll be defining three different elevation levels for which there are different terrain textures, these will be (each at 512x512):

4.1) Lowest elevation (low lying areas):

4.2) Middle elevation (main map surface):

4.3) Highest elevation (mountains):

5) Now also for our example, we'll be defining two different textures to be used by sloping areas, one for slopes in the lower elevation areas of the map, and another for slopes in the higher elevations:

5.1) Lower elevations:

5.2) Higher elevations:

6) Create an empty text file in your C:\Povmap folder named gen_pov_texture.pov

7) Copy the following povray scene code into the above file:


// Setup some parameters that we will use within the script
#declare MAP_WIDTH=8192;
#declare MAP_HEIGHT=8192;
#declare MAP_ELEVATION=600;

global_settings { 
  // ambient light level
  ambient_light rgb<1,1,1> 
}

// Set a directional light
light_source {
  <100,-100,100> * 20, color rgb 1
  parallel
  point_at <1, 0, 0>
}

// Set the background colour
background {rgb<1,1,1>}

// Define our camera position, and set it to "orthographic" (important :)
camera {
  orthographic
  location <0,0,MAP_ELEVATION + 90>    // position & direction of view
  look_at  <0,0,0>
  right MAP_WIDTH*x            // horizontal size of view
  up MAP_HEIGHT*z               // vertical size of view
}

// ** Define our primary textures **
 
// lowest texture (512 x 512)
// Found in low lying areas of the heightfield
#declare level1_texture =
texture {
  pigment {
    image_map {
      png "level1.png"
    }
  }
  finish {ambient 1 diffuse 0}
  scale <512/MAP_WIDTH, 512/MAP_WIDTH, 512/MAP_WIDTH>
}

// middle texture (512 x 512)
// Found in the middle areas of the heightfield
#declare level2_texture =
texture {
  pigment {
    image_map {
      png "level2.png"
    }
  }
  finish {ambient 1 diffuse 0}
  scale <512/MAP_WIDTH, 512/MAP_WIDTH, 512/MAP_WIDTH>
}

// highest texture (512 x 512)
// Found in the peaks / hills / mountains of the heightfield
#declare level3_texture =
texture {
  pigment {
    image_map {
      png "level3.png"
    }
  }
  finish {ambient 1 diffuse 0}
  scale <512/MAP_WIDTH, 512/MAP_WIDTH, 512/MAP_WIDTH>
}

// Define a texture that blends from one level's texture to the next, depending on elevation:
#declare levels_elevation_texture=
texture {
  gradient z
  
  texture_map {
    [0.00 level1_texture]  // from 0.0 to 0.1 we have just level1.png
    [0.10 level1_texture]
                           // from 0.1 to 0.2 we blend from level1.png to level2.png
    [0.30 level2_texture]  // from 0.2 to 0.5 we have just level2.png
    [0.40 level2_texture]
                           // from 0.5 to 0.6 we blend from level2.png to level3.png
    [0.60  level3_texture]  // from 0.6 to 1.0 we have just level2.png
    [1.00  level3_texture]
  }
}


// ** Define textures used on areas of slope

// lower slope texture (512 x 512)
#declare slope1_texture =
texture {
  pigment {
    image_map {
      png "slope1.png"
    }
  }
  finish {ambient 1 diffuse 0}
  scale <512/MAP_WIDTH, 512/MAP_WIDTH, 512/MAP_WIDTH>
}

// upper slope texture (512 x 512)
#declare slope2_texture =
texture {
  pigment {
    image_map {
      png "slope2.png"
    }
  }
  finish {ambient 1 diffuse 0}
  scale <512/MAP_WIDTH, 512/MAP_WIDTH, 512/MAP_WIDTH>
}

// Define a texture that blends from one slope's texture to the next, depending on elevation:
#declare slopes_elevation_texture=
texture {
  gradient z
  
  texture_map {
    [0.00 slope1_texture]
    [0.30 slope1_texture]
    
    [0.65  slope2_texture]
    [1.00  slope2_texture]
  }
}

// ** Now define the final texture blending between the height textures and the slope textures:
#declare final_texture = 
texture {
  slope {
    <0,0,-1>, 0, 0.5
  } 
  texture_map {
    [0.00    levels_elevation_texture]
    [0.06    levels_elevation_texture]
    [0.40    slopes_elevation_texture]
    [1.00    slopes_elevation_texture]
  }
}  

// ***!! Now we declare our heightfield object that uses this texture
height_field {
  png "povmap_height.png"                                  
  smooth              // smooth the heightfield
  no_shadow           // you may want to remove this
  translate <-.5, -.5, -.5>
  rotate <90,0,0>     // rotate it so that the projection of the texture is correct
  scale <1,-1,1>      // invert the y axis
  translate <0.5, 0.5, 0.5>
  texture {
    final_texture
  }
  
  scale <MAP_WIDTH, MAP_HEIGHT, MAP_ELEVATION>    // now scale to the maps height x width
  translate <-MAP_WIDTH/2, -MAP_HEIGHT/2, -MAP_ELEVATION/2>   // and center it for the camera
}

8) Double click on your gen_pov_texture.pov file so that it opens up in Povray.

9) Add a new render size (8192 x 8192): 9.1) 9.2)

10) Restart Povray

11) Select your new reder size Click Render

12) Convert to gen_pov_texture.bmp to a png file if you're using the new mapconv (it doesn't seem to like bitmaps)

13) Do all the other map stuff: metal placement bitmap, feature placement bitmap, smd file

14) Compile your map with mapconv

15) Test it :)

Advanced stuff

Check out your help file that came with Povray. There is a LOT that you can do!

Complex Texture Map Combinations

As you can see from the pov code above, a "texture" declaration can be an image (called an "image_map"), but it can also be a definition of a blend between any number of earlier defined textures (called a "texture_map"), which is based on a function. In the above example, it uses the "gradient" function for changes in elevation, and the "slope" function for changes in slope. It is possible to define much more complex sets of textures than those defined above, such as mixing different combination of slope mapings with combinations of elevation mapings.

Procedural Textures

It is also possible to use "procedural textures" instead of image_map textures. These can be quite useful for areas on your map that have a high slope as they can create a better looking texture, including effects such as the layered rock textures. Unfortunately these types of textures can result in larger map sizes, but if you just use them on the high slope areas of your map it should not be too bad.

Some good examples used in terrains can be found at the Geomorph website.

Placing Metal Textures

There are quite a few posible ways to have Povray place metal textures for you. One approach that I have used is:

1) Define a function that will return the current metal locations in a pov kind of way:

<pre>
  #declare getMetal = function {
    pigment {
      image_map {
        png "metallocations.png"
      }
      scale <1,-1,1>
    }
  }

This function, when called for a given coordinate (0 to 1), returns a vector of the three colours for that point.

2) We now define a texture that we'll use for our metal (this is made up of a number of subcomponent textures):

// A simple brownish texture
#declare dirt_Texture=
texture {
  pigment { rgb <0.75,0.55,0.35>*0.7 }
  normal {
    granite 0.5  // for use with normal{} (0...1 or more)
    //scale MAP_WIDTH
  }
  finish {
    ambient 0.5
    diffuse .9
  }
}

// A shiny metalish texture
#declare metal_TextureBase = 
texture { 
  pigment {
    rgb<1,1,1>    
  }
  normal {
      granite 0.9  // for use with normal{} (0...1 or more)
    scale 80/5
  }
  finish {
    ambient 0.6
    brilliance 4
    diffuse 1
    specular 0.90
    roughness 1/80
  }
}

// A combination of the metal_TextureBase, the dirt_Texture and the Transparent_Texture
#declare metal_Texture=
texture {
  bozo              // very smooth, random noise function
  turbulence 0.3  // turbulence often useful

  texture_map {
    [0.0  metal_TextureBase]  //T_Silver_3B
    [0.42  metal_TextureBase]
    [0.47  dirt_Texture]
    [0.50  dirt_Texture]
    [0.55  Transparent_Texture]
    [1.0  Transparent_Texture]
  }
  //scale <16, 16, 16> //even
  scale <7, 32, 16> //stretched 
  rotate z*40  //set it at an angle so it looks betterer ;)
}

#declare blob_Texture=
texture {
  slope { z, 0.0, 0.5 }
  texture_map {
    [0.0  Transparent_Texture]
    [0.6  Transparent_Texture]
    [1.0  metal_Texture]
  }
}  

3) Finally, we define a "blob" object that adds a sphere object to the master blob object for each point in the metal map:

  #declare metalBlob=
  blob {
  #declare geos=0;
  #declare ix=4.0;
  #declare num=0;
  #while (ix < MAP_WIDTH)
    #declare iy=0.0;
    #while (iy < MAP_WIDTH)
      #declare metal=getMetal(ix/MAP_WIDTH, iy/MAP_WIDTH, 0);
      #if (metal.red)
        #declare Pos = trace(primaryHF,<ix-MAP_WIDTH/2, -iy+MAP_WIDTH/2, MAP_ELEVATION*2>,-z);
        sphere {
            //Pos-<0,0,5>, 8*6, 8  
            Pos-<0,0,5>, 8*2, 8  
        }
      #end 
      #declare iy=iy+8;
    #end
    #declare ix=ix+8;
  #end
  
    texture {
      blob_Texture
    }
    scale <1,1,0.5>  
  }  //metalBlob

  object {metalBlob}

This all adds some time to the rendering time, but seems to work well enough (although it could be nicer).