Home - Forums - Documentation - Gallery - Bugs

Contents

This will teach you how to use the "stat_dyn_reflect" shader in Crystal Space!

Example

Here you see an example of how the shader works!

Image:tut_reflection.gif

As you see the metal is static, and the reflection is only reflected where there is non-white surface on the mask file.

Image:tut_reflection_mask.jpg

This is the mask file I used.

Setting up the files

The metal you want to add reflections too: metal.jpg. The reflecting texture, which will float, and create the reflecting surface: reflection.jpg. This is the mask that masks what will be reflected and what will not be: reflection_mask.jpg.

If you don't use the shader it will look like this.

Image:tut_non_reflection.jpg

You might think this looks nicer, yes maybe in this static picture, but in the "game", the reflection looks great!!!

The masked reflection shader works like this

It will not create any reflections where the mask texture is 100% white. It will create 100% reflection where the mask texture is 100% black. In between it makes reflections, static according to how bright/dark the mask is.

How to use it

Step 1 - Loading the textures

The first thing you need to do is to add the loading of the textures you are using.

<textures>
    ... (other textures) ...
    <texture name="metal">
        <file>metal.jpg</file>
    </texture>
    <texture name="reflection_mask">
        <file>reflection_mask.jpg</file>
    </texture>
    <cubemap name="reflection">
        <north>reflection.jpg</north>
        <south>reflection.jpg</south>
        <east>reflection.jpg</east>
        <west>reflection.jpg</west>
        <top>reflection.jpg</top>>
        <bottom>reflection.jpg</bottom>
    </cubemap>
</textures>

The reflection is added as a cubemap to prevent the reflection to get all messy, and look bad. Instead of using one texture, it is actually using 6 different textures (I used the same to prevent the memory usage to be too high).

Step 2 - Loading the shader

Then you need to load the shader!

<shaders>
    <shader>
        <file>/shader/stat_dyn_reflect.xml</file>
    </shader>
</shaders>

This is the part you load the shader into the world file, you can add multiple shaders, if you will use another shader as well!

Step 3 - Adding the shader to a specific material

<material name="metal.jpg">
    <texture>metal.jpg</texture>
    <shader type="standard">stat_dyn_reflect</shader>
    <shadervar name="tex reflection" type="texture">reflection</shadervar>
    <shadervar name="tex mask" type="texture">reflection_mask.jpg</shadervar>
</material>

These are the variables that are used in the shader for creating the reflections and the mask, but only for that special material. If you want to use another mask (or reflection) just import another texture as well (named mask2.jpg...etc.) then apply this in the other material you want to use this stat dyn reflect shader!

But you can off course use the same texture as many times as you want!

Final Result

The final source should look a bit like this:

<world>
    <textures>
        <texture name="metal.jpg">
            <file>metal.jpg</file>
        </texture>
        <texture name="mask.jpg">
            <file>mask2.jpg</file>
        </texture>
        <cubemap name="reflection">
            <north>reflection.jpg</north>
            <south>reflection.jpg</south>
            <east>reflection.jpg</east>
            <west>reflection.jpg</west>
            <top>reflection.jpg</top>
            <bottom>reflection.jpg</bottom>
        </cubemap>
    </textures>
    <shaders>
        <shader><file>/shader/stat_dyn_reflect.xml</file></shader>
    </shaders>
    <materials>
        <material name="metal.jpg">
            <texture>metal.jpg</texture>
            <shader type="standard">stat_dyn_reflect</shader>
            <shadervar name="tex reflection" type="texture">reflection</shadervar>
            <shadervar name="tex mask" type="texture">mask.jpg</shadervar>
        </material>
    </materials>
    ...
</world>

Created by: Anders Wisur (Xotic)

| Article | Discussion | View source | History |