Home - Forums - Documentation - Gallery - Bugs
(Example)
Line 4: Line 4:
Here you see an example of how the shader works!
Here you see an example of how the shader works!
-
[[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.''

Revision as of 13:28, 12 January 2007

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.


__I assume this will be 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.

{img src=show_image.php?id=33 width=350 height=274} 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.



^__Step 1 - Loading the textures.__^

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

    <textures> 

Here there will be some other textures too.

         <texture name="metal.jpg"> 
              <file> metal.jpg</file> 
         </texture> 


(Add the following for loading the textures for reflections and mask!)

         <texture name="reflection_mask.jpg"> 
              <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> 

(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).

    </textures> 



^__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.__^

    <materials>

Here there will be lots of other materials too!


         <material name="metal.jpg">
              <texture>metal.jpg</texture>

(Add the following for the metal you want to add reflections too!)

                   <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>

(don't copy more)

"*" Older versions of Crystal Space uses shader type="OR compatibility" instead of shader type="standard" !!!

         </material>
    </materials>

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!

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


^__The final source should look a bit like this (after the <lugin> and before the <settings> tag).__^

    <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>


NOTE: Older versions of Crystal Space uses <shader type="OR compatibility">stat_dyn_reflect</shader> instead of <shader type="standard">stat_dyn_reflect</shader>.


GOOD LUCK TO YOU!!!!

Created by: Anders Wisur (Xotic)

| Article | Discussion | View source | History |