Bump Map Alpha Splatting

From Rigs of Rods Wiki

Jump to:navigation, search

Contents

Introduction

Top: Normal, Bottom: Bump Mapped
Example of a standard Alpha Splatting Material

If you're feeling pretty comfortable creating terrains and want to try something new and experimental, then this is for you. If you are just starting out creating terrains, then I suggest you start here: Basic Terrain Tutorial because this tutorial is experimental. Simply put, this is a new terrain material that was made by adapting the material from the program "Artifex Terra 3D" (all credit for the original material goes to them) to Rigs of Rods. It is designed to be put on a terrain that is already up and running in RoR (this is not a "how to create a terrain" tutorial). IF you have problems, PM Nipash on the forums. It combines two key things:

Alpha Splatting

You're probably familiar with this one. This technique splats different textures across the terrain based off of a splatting map. It is great for adding tons of detail to your terrain with little or no performance drop if the textures are optimized correctly. This is used in the great tutorial by Dega: Alpha Splatting If you haven't followed that tutorial already, I suggest you do so before following this one because things will be easier later on if you do.

Bump Mapping

This uses a special "shader" that simulates bumpiness on a surface even though it is flat. A good explanation can be found here: Wikipedia This is very good for terrains because it means that you can make your terrain appear to be more detailed and bumpy with not much more of a performance drop. In this material, the textures that are being alpha splatted are also bump mapped, which means you get the best of both worlds.

Example

Old Alpha Splatting Material
New Bump Map Alpha Splatting Material





















Getting Started

To start with you need to have made a terrain in your favorite program. Then, you need to work on getting these images one way or another:

1 Main Texture

A big picture from above the terrain that looks kind-of like an aerial photograph. Here is an example: Randommap This is usually pretty straightforward to get as it is the texture of your terrain.

1-3 RGB Splatting Maps

This is slightly more complicated, but you are probably familiar with it if you've followed Dega's tutorial: Alpha Splatting If not, then you should before following this tutorial. Anyway, an example of a splatting map would be this: Splatting Map It defines where certain textures are put, in this case one goes where red is, one for green, and one for blue. Now you might be wondering why some places in the example are black. That is because red, green and blue only account for 3 different textures. This isn't enough, so there are 2 more RGB splat maps in addition to the original giving a total of 9 textures. You have to have some spaces in the maps black because they are used by the others. Additionally, if you don't need 9 textures (like maybe just 5), then just get the amount of maps you need for the textures you need (for 5 you would need 2 maps).

1-9 Textures

These are the textures used by the splatting map. They can be whatever you want from rock to sand to grass. They correspond to different colors on the splatting map, so name them accordingly so you don't forget (like map1_red.png). If you don't know where to get these textures, CGtextures would be a good place to start: CG textures

1-9 Bump Maps

These are the bump maps for the textures. Here is an example: Bump Map There is one for each texture to achieve the affect in the pot picture above. You need to generate them with a separate utility, as they are quite complicated to work out. Some examples would be Crazybump: [1] Xnormal: [2] or GIMP Bumpmap Utility: [3]

Conversion

Unfortunately the material is a bit picky when it comes to what format your images are in. That is why you should download the microsoft directx sdk which has a special converter that converts normal images into .dds images. You need to open your images in the .dds viewer (found inside the Directx SDK program folder) and convert then save them by using items in the drop down menus:

Main Texture: 1024x1024, DXT3, do not generate mip maps
RGB Splatting Maps: 1024x1024, do not convert into different image format, do not generate mip maps
Textures: 512x512, DXT3, generate mip maps
Bump Maps: 512x512, do not convert into different image format, generate mip maps

Download and Set-Up

Finally, we can start with the actual material. Here is the download:

File:Upload.zip

Then, if you are using alpha splatting on your terrain, delete it's files from your terrain .zip as they might conflict with the new ones. Then, extract the files from Upload.zip into your terrain .zip. You should also have all your images and textures in the correct format in your terrain .zip as well.

Set up the .material File

First we need to open up ETterrain.material and scroll to the bottom where you should see this:

material Material : ETTerrainMaterial
{
	set_texture_alias RGBMap1		texture.dds
	set_texture_alias RGBMap2		texture.dds
 	set_texture_alias RGBMap3		texture.dds
	
	set_texture_alias RMap1_DIF        texture.dds
	set_texture_alias RMap1_NRM	texture.dds
	set_texture_alias GMap1_DIF        texture.dds
	set_texture_alias GMap1_NRM	texture.dds
	set_texture_alias BMap1_DIF         texture.dds
	set_texture_alias BMap1_NRM	texture.dds
	set_texture_alias RMap2_DIF         texture.dds
	set_texture_alias RMap2_NRM	texture.dds
	set_texture_alias GMap2_DIF        texture.dds
	set_texture_alias GMap2_NRM	texture.dds
	set_texture_alias BMap2_DIF         texture.dds
	set_texture_alias BMap2_NRM	texture.dds
	set_texture_alias RMap3_DIF        texture.dds
	set_texture_alias RMap3_NRM	texture.dds
	set_texture_alias GMap3_DIF        texture.dds
	set_texture_alias GMap3_NRM	texture.dds
	set_texture_alias BMap3_DIF        texture.dds
	set_texture_alias BMap3_NRM	texture.dds
	
	set_texture_alias Color		       texture.dds
}

First, you should replace Material with whatever name you want the material to be. It must be unique though or else it will conflict. Then, type in the name of your RGB Splat Maps in place of texture.dds where it says set_texture_alias RGBMap1-3. Then, you need to put in your textures and textures' bump maps just down from there in place of texture.dds where is says set_texture_alias RGBMap1-3_NRM or DIF for example. But, where you type in your textures has everything to do with it. Say you want rock.dds to be put on the red on RGB Splat Map 2. You would type rock.dds in place of texture.dds next to set_texture_alias RMap2_DIF. If you wanted the bump map for your dirt texture (dirt_bump.dds for example) to be put where the green is on RGB Splatting Map 3. Then you would type dirt_bump.dds in place of texture.dds next to set_texture_alias BMap3_NRM. After that, type in the name of your Main Texture in place of texture.dds next to set_texture_alias Color. Also, if there are some unused spaces (like if you used less than 9 textures) then just don't change them.

Set up the .cfg File

Then, we need to tell your terrain to use the material. To do this we need to open up the .cfg of your terrain and scroll down to the bottom. You should see this:

# The name of the material you will define to shade the terrain
CustomMaterialName=TestTerrainMaterial

You need to change TestTerrainMaterial to whatever name you gave your material in ETterrain.material.

Run

This should get the shader working. So if you run RoR and the shader works..... great! If it doesn't, back to the log to see what's wrong. With enough troubleshooting and maybe a post to the forum it will get working eventually.

Fine Tuning

This material also has some cool things to adjust in it:

LOD Morphing Rountine

LOD's make the terrain less detailed farther away and more detailed up close to achieve higher performance. You can see this in RoR when you go into free camera mode and the terrain sort-of "jumps" as you approach it. However, this jumping behaviour is noticeable so that is why this material smoothly morph's the LOD's between detail levels. For it to do this, we need to turn it on. So open up your terrains.cfg and change no:

    # Use vertex program to morph LODs, if available
     VertexProgramMorph=no

to yes. There are several different techniques to choose from. So, open ETterrain.material and scroll down to just above where we edited in the first place:

      pass
	  {
			// colour map
			scene_blend modulate	
		     
		    vertex_program_ref ET/Programs/VSLodMorph3
			{
			} 					
			
			texture_unit 
			{			
				texture_alias Color
			}					
			      
		}   
		        
      
   }
}

You change the LOD morphing technique by changing vertex_program_ref ET/Programs/VSLodMorph3 to 1, 2 or 3. 3 takes a less detailed terrain and makes it more detailed by smoothly subtracting bits from the terrain. 2 takes a less detailed terrain and makes it more detailed by smoothly adding bits to the terrain. 1 makes your terrain look like it's on LSD - don't use it.

Color Blending

In the normal Alpha Splatting material, you change how bright or dark your terrain is by changing a number. However, this material does not have that so you have to brighten or darken your main texture in a separate program to make your terrain brighter or darker. You can also adjust the contrast and other properties with this method.

Textures Scaling

You can adjust the scale of your textures in this material. To do this open ETterrain.material and go to here:

pass Lighting
      {
         scene_blend add
         iteration once_per_light
         
         		 
         vertex_program_ref ET/Programs/VSDynLightingNM
         {
         }
         
         fragment_program_ref ET/Programs/PSDynLightingNM
         {
			param_named splatScaleX float 192
           param_named splatScaleZ float 192
         }
         
		 texture_unit
         {
        // first coverage map, dynamically managed
               texture_alias RGBMap1
            }

and here:

vertex_program_ref ET/Programs/VSDynLightingNM
         {
         }
         
         fragment_program_ref ET/Programs/PSDynLightingNM
         {
         }          
         
         vertex_program_ref ET/Programs/VSLodMorph2
         {
         }

         fragment_program_ref ET/Programs/PSSplat2
         {
           param_named splatScaleX float 192
           param_named splatScaleZ float 192
         }

         texture_unit
         {
        // first coverage map, dynamically managed
               texture_alias RGBMap1
            }
         texture_unit
         {
         // second coverage map, dynamically managed
               texture_alias RGBMap2
         }
		 texture_unit

You change the scaling of your textures by changing the numbers 192 higher or lower.

Conclusion

If all is successful then you should have a terrain that has bump mapping on the alpha splatting textures, has color blending with the main texture, changes it's lighting based off of time of day and smoothly morphs lods. Any comments or suggestions on this tutorial should be put in this topic: http://www.rigsofrods.com/threads/82581-New-terrain-material-tutorial



About Rigs of Rods

    Rigs of Rods is a unique soft body physics simulator.


Some Tools


Partners

SourceForge.net

Follow us

Twitter youtube Facebook RSS Feed


impressum