Entropy Material Tutorial
From LagoonWiki
This tutorial gives more details about what you can do with materials in Galaga/Entropy/Ogre3D.
Contents |
Basic Materials
Recall the following definition from the Skyplane Tutorial:
material BlueSky
{
technique
{
pass
{
lighting off
depth_write off
fog_override true
texture_unit
{
texture bluesky.png
}
}
}
}
This is actually a script, though it does not include much activity: it turns off a couple of features not discussed here, overrides the fog, and defines the texture image to be used to "paint" whatever polygons are rendered with this material. The following sections show how to define more active materials.
Moving Clouds for your Skyplane
You can make the texture move across the surface of a material. This is a simple way to implement various effects such as moving clouds.
Create a new texture cloudysky.png in galaga/data/materials/textures/, similar to bluesky.png except with some white splotches to represent clouds. For best results, paint with the airbrush or some other tool that will let you paint thicker and thinner patches in the clouds and feather out their edges.
Make a new material script CloudySky.material in galaga/data/materials/scripts/, as follows:
material CloudySky
{
technique
{
pass
{
lighting off
depth_write off
# Use whatever settings you wish for fog_override:
fog_override true
texture_unit
{
texture cloudysky.png
scroll_anim 0.005 -0.005
}
}
}
}
Notice that the # can be used to add comments to a script. For this experiment you can use whatever fog settings you currently have, so long as they leave the sky partly visible.
Notice also the new scroll_anim command added to the texture definition. It has two parameters, which are the speeds the texture will scroll in the two dimensions of your skyplane. (If neither are zero it moves in a diagonal direction.) Large numbers cause the clouds to move faster. A negative number just reverses the direction of the motion on that axis.
Now that the texture file is moved across the sky, it must eventually repeat itself so that the motion can be continued indefinitely. If the edges of your image are not a perfect match you will see an edge creep across the sky whenever the image is repeated. You can eliminate that effect by modifying your image to tile seamlessly. The GIMP will let you do that in a single step with the Filters-->Map-->Make Seamless menu option.
Remember also that a parameter of your sceneManager->setSkyPlane command tells the image how many times to repeat the texture across the sky even when it is not in motion. If you are not trying to render a realistic Earth sky you can deliberately create a sky with a repeating pattern, and make the joins seamless if you do not want them to show.
Try the example, and experiment with various speeds and directions to get the desired effect. You may also want to modify your cloudysky.png now that you see how it is rendered on the skyplane.
Shapeshifting Clouds
A more sophisticated effect can be obtained by using a second texture to modulate the first one. Since clouds are generally amorphous, this example just uses your cloudysky.png twice:
material CloudySky
{
technique
{
pass
{
lighting off
depth_write off
# Use whatever settings you wish for fog_override:
fog_override true
texture_unit
{
texture cloudysky.png
scroll_anim 0.005 -0.005
}
texture_unit
{
texture cloudysky.png
colour_op modulate
scroll_anim 0.0 0.005
}
}
}
}
The example adds a second texture_unit with the same image, tells the engine to use that image to modulate the colors in the first one and to move it in a different direction. The result gives the clouds an illusion of depth, and causes them to change shape as they move.
Try the example, and experiment with different textures and scrolling speeds until you get a nice effect.
Creating Clouds with The GIMP
If you have trouble creating clouds you like, you can create images automatically with The GIMP. Use one of the Filters-->Render-->Clouds menu options to do that. Notice that most of these let you specify parameters to modify the effects, and that for some of the renderers the result depends on whether you start with a blank image or apply the filter to something you have already drawn.
Filters-->Render-->Nature-->Flame also produces patterns that could be used for clouds.
Create a pair of exotic images using these filters, and see how they look if you use them to render the sky in your demo environment.
Advanced Features
This section is optional for the CS381 assignment.
One more example is given below. Additional advanced techniques are described at the ogre3d.org wiki, and at the materials page in the manual (which is at present incomplete, but has enough to tip you off to other features).
The follwing example uses alpha blending to paint the sky with parts of two different images. In particular, it puts a "hole" in the cloudy sky and shows a moving texture through the hole. The Psychedelic.material definition looks like this:
material Psychedelic
{
technique
{
pass
{
lighting off
depth_write off
# Do what you want with the fog:
fog_override true
texture_unit
{
texture cloudysky.png
}
texture_unit
{
texture hole-alpha.png
colour_op alpha_blend
}
texture_unit
{
texture psychedelic.png
colour_op_ex blend_current_alpha src_texture src_current
scroll_anim 0.1 0.1
}
}
}
}
The first uses the image of the clouds for the static part of the sky.
The second texture unit is the pattern that works like a mask to allow only a part of the next texture to show through. For the first attempt I just used a big black dot on a transparent background, to create a clean cut between the two images. However, since the image's alpha channel is used to blend the two images, you can use variable alpha in the image to allow a mix of both to be seen in the same place: the more transparent it is, the more you see the first texture, and the blacker it is, the more it will let the next texture show through. (It only serves as a hard mask when you use fully black or fully transparent.)
The third texture unit defines the texture that is blended in wherever hole-alpha.png is black. You can create something psychedlic with one of The GIMP's Filters-->Render options (e.g. -->Lava, -->Pattern-->Sinus , or -->Clouds-->Plasma). The scroll_anim is used as before to make this texture move, so the result looks like you are seeing something moving behind a hole in the sky.
