Vizard 8 » Tutorials & Examples » Example scripts » Shaders » Alpha map
8.0

Alpha map

\examples\shader\tutorial_alphaMap.py

This script uses an alpha map texturing shader. Alpha maps allow you to combine textures.

import viz

viz.setMultiSample(4)
viz.fov(60)
viz.go()

#Add box that we will be applying the shader to
box = viz.addChild( 'box.wrl', pos = [0, 1.8, 2.5] )

#Add all the textures that the tutorial will use
baseTexture = viz.addTexture( 'brick.jpg' )
alphaMap = viz.addTexture( 'grid.jpg' )

#Attach these textures to the box node as texture numbers 0 and 1
box.texture( baseTexture )
box.texture( alphaMap, unit = 1 )

#Create shader object and assosiate it with our alpha mapping frag program
shader = viz.addShader( frag = 'alphaMapper.frag' )

#Create the shader parameter objects
#They tell the shader the texture numbers of the base texture and the alpha map
BaseTextureUniform = viz.addUniformInt( 'BaseTexture', 0 )
AlphaMapTextureUniform = viz.addUniformInt( 'AlphaMapTexture', 1 )

#Make Vizard use the created shader when rendering the box node
box.apply( shader )
#Provide the shader with its parameters
box.apply( BaseTextureUniform )
box.apply( AlphaMapTextureUniform )