Home - Forums - Documentation - Gallery - Bugs
(Example)
Current revision (10:31, 22 August 2008) (edit) (undo)
 
(3 intermediate revisions not shown.)
Line 1: Line 1:
 +
[[Category:Tutorial]]
=This will teach you how to use the "stat_dyn_reflect" shader in Crystal Space!=
=This will teach you how to use the "stat_dyn_reflect" shader in Crystal Space!=
Line 6: Line 7:
[[Image:tut_reflection.gif]]
[[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.''
''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]]
[[Image:tut_reflection_mask.jpg]]
 +
''This is the mask file I used.''
''This is the mask file I used.''
-
--------------------------------------------------------------------------------
+
== Setting up the files ==
-
 
+
-
__I assume this will be the files:__
+
The metal you want to add reflections too: metal.jpg.
The metal you want to add reflections too: metal.jpg.
The reflecting texture, which will float, and create the reflecting surface: reflection.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.
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.
If you don't use the shader it will look like this.
-
{img src=show_image.php?id=33 width=350 height=274}
+
[[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!!!''
+
 +
''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:__
+
== The masked reflection shader works like this ==
It will not create any reflections where the mask texture is 100% white.
It will not create any reflections where the mask texture is 100% white.
Line 32: Line 32:
In between it makes reflections, static according to how bright/dark the mask is.
In between it makes reflections, static according to how bright/dark the mask is.
 +
== How to use it ==
-
 
+
=== Step 1 - Loading the textures ===
-
 
+
-
^__Step 1 - Loading the textures.__^
+
The first thing you need to do is to add the loading of the textures you are using.
The first thing you need to do is to add the loading of the textures you are using.
-
<textures>
+
<source lang="xml">
 +
<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>
 +
</source>
-
''Here there will be some other textures too.''
+
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).
-
&lt;texture name="metal.jpg"&gt;
+
=== Step 2 - Loading the shader ===
-
&lt;file&gt; metal.jpg&lt;/file&gt;
+
-
&lt;/texture&gt;
+
-
 
+
-
 
+
-
 
+
-
(Add the following for loading the textures for reflections and mask!)
+
-
 
+
-
&lt;texture name="reflection_mask.jpg"&gt;
+
-
&lt;file&gt; reflection_mask.jpg&lt;/file&gt;
+
-
&lt;/texture&gt;
+
-
 
+
-
&lt;cubemap name="reflection"&gt;
+
-
&lt;north&gt; reflection.jpg&lt;/north&gt;
+
-
&lt;south&gt; reflection.jpg&lt;/south&gt;
+
-
&lt;east&gt; reflection.jpg&lt;/east&gt;
+
-
&lt;west&gt; reflection.jpg&lt;/west&gt;
+
-
&lt;top&gt;reflection.jpg&lt;/top&gt;&gt;
+
-
&lt;bottom&gt; reflection.jpg&lt;/bottom&gt;
+
-
&lt;/cubemap&gt;
+
-
 
+
-
(don't copy more)
+
-
 
+
-
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 using to be too high).
+
-
 
+
-
&lt;/textures&gt;
+
-
 
+
-
 
+
-
 
+
-
 
+
-
^__Step 2 - Loading the shader.__^
+
Then you need to load the shader!
Then you need to load the shader!
-
&lt;shaders&gt;
+
<source lang="xml">
-
&lt;shader&gt;&lt;file&gt;/shader/stat_dyn_reflect.xml&lt;/file>&lt;/shader&gt;
+
<shaders>
-
&lt;/shaders&gt;
+
<shader>
 +
<file>/shader/stat_dyn_reflect.xml</file>
 +
</shader>
 +
</shaders>
 +
</source>
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!
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 ===
-
^__Step 3 - Adding the shader to a specific material.__^
+
<source lang="xml">
 +
<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>
 +
</source>
-
&lt;materials>
+
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
-
 
+
-
Here there will be lots of other materials too!
+
-
 
+
-
 
+
-
&lt;material name="metal.jpg"&gt;
+
-
&lt;texture>metal.jpg&lt;/texture&gt;
+
-
 
+
-
(Add the following for the metal you want to add reflections too!)
+
-
 
+
-
&lt;shader type="standard"&gt;stat_dyn_reflect&lt;/shader&gt; "*"
+
-
&lt;shadervar name="tex reflection" type="texture"&gt;reflection&lt;/shadervar&gt;
+
-
&lt;shadervar name="tex mask" type="texture"&gt;reflection_mask.jpg&lt;/shadervar&gt;
+
-
 
+
-
(don't copy more)
+
-
 
+
-
"*" Older versions of Crystal Space uses shader type="OR compatibility" instead of shader type="standard" !!!
+
-
 
+
-
&lt;/material&gt;
+
-
&lt;/materials&gt;
+
-
 
+
-
This is 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!
stat dyn reflect shader!
-
But you can off course use the same textures as many times as you want!
+
But you can off course use the same texture as many times as you want!
-
 
+
-
 
+
-
^__The final source should look a bit like this (after the &lt;lugin&gt; and before the &lt;settings&gt; tag).__^
+
-
 
+
-
&lt;textures&gt;
+
-
&lt;texture name="metal.jpg"&gt;
+
-
&lt;file&gt;metal.jpg&lt;/file&gt;
+
-
&lt;/texture&gt;
+
-
&lt;texture name="mask.jpg"&gt;
+
-
&lt;file&gt;mask2.jpg&lt;/file&gt;
+
-
&lt;/texture&gt;
+
-
&lt;cubemap name="reflection"&gt;
+
-
&lt;north&gt;reflection.jpg&lt;/north&gt;
+
-
&lt;south&gt;reflection.jpg&lt;/south&gt;
+
-
&lt;east&gt;reflection.jpg&lt;/east&gt;
+
-
&lt;west&gt;reflection.jpg&lt;/west&gt;
+
-
&lt;top&gt;reflection.jpg&lt;/top&gt;
+
-
&lt;bottom&gt;reflection.jpg&lt;/bottom&gt;
+
-
&lt;/cubemap&gt;
+
-
&lt;/textures&gt;
+
-
 
+
-
&lt;shaders&gt;
+
-
&lt;shader&gt;&lt;file&gt;/shader/stat_dyn_reflect.xml&lt;/file&gt;&lt;/shader&gt;
+
-
&lt;/shaders&gt;
+
-
 
+
-
&lt;materials&gt;
+
-
&lt;material name="metal.jpg"&gt;
+
-
&lt;texture&gt;metal.jpg&lt;/texture&gt;
+
-
&lt;shader type="standard"&gt;stat_dyn_reflect&lt;/shader&gt;
+
-
&lt;shadervar name="tex reflection" type="texture"&gt;reflection&lt;/shadervar&gt;
+
-
&lt;shadervar name="tex mask" type="texture"&gt;mask.jpg&lt;/shadervar&gt;
+
-
&lt;/material&gt;
+
-
&lt;/materials&gt;
+
-
 
+
-
NOTE: Older versions of Crystal Space uses &lt;shader type="OR compatibility"&gt;stat_dyn_reflect&lt;/shader&gt; instead of &lt;shader type="standard"&gt;stat_dyn_reflect&lt;/shader&gt;.
+
=== Final Result ===
-
--------------------------------------------------------------------------------
+
The final source should look a bit like this:
-
GOOD LUCK TO YOU!!!!
+
<source lang="xml">
 +
<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>
 +
</source>
Created by: Anders Wisur (Xotic)
Created by: Anders Wisur (Xotic)

Current revision

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 |