Vizard 8 » Tutorials & Examples » Appearance & texturing » Multitexturing » Tutorial: Blending the textures
8.1

Tutorial: Blending the textures

Now, apply the two textures to the logo:

logo.texture(tex1)
logo.texture(tex2,'',1)

The first line applies the first texture to the logo. When you apply a texture to an object, by default it is applied to the first texture layer. Now we need to apply the second texture to the second texture layer of the object. The second line does this for us. The second argument is the subchild we want to apply the texture to. In this case we want to apply the texture to the entire object, so we leave the subchild blank. The last argument tells vizard to apply the texture to the second texture layer. The reason we specify the number 1 is that the texture layer numbers start from 0 and up.

 

Now that the two textures are applied to the object, we need to specify how they will be combined. For this example we will use a shader effect. A shader effect is a small piece of code that you can apply to an object which can control how to combine the color and texture of the object. The following code will add a shader efect and apply it to the logo:

blend = viz.addEffect('multitexblend.fp')
vizfx.apply(logo)
logo.apply(blend)

If you are familiar with OpenGL fragment programs then you can open the 'multitexblend.fp' file and edit it yourself to create a custom effect. This specific shader effect has one parameter 'BlendAmount', which controls how much to blend between the two textures. A value of 0 blends 100% of texture 1 with 0 % of texture 2. A value of 1 blends 0% of texture 1 with 100% of texture 2. A value of 0.4 blends 60% of texture 1 with 40% of texture 2. Let's initialize the shader effect so that it blends 100% of texture 1.

blend.setProperty('BlendAmount', 0.0)

The first argument of the setProperty function is the property name. The second argument is the property value, which is 0 in order to blend 100% of texture 1.

Loading multiple textures

Blending the textures

Real-time adjustments