View Single Post
  #3  
Old 09-20-2012, 10:37 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Yeah Cornelius, if that's your real name

You can write a simple shader that mixes multiple textures together and combines it with the lightmap. Here is an example that uses the gallery model included with Vizard. It allows you to blend between a wood and slate texture and then adds the existing lightmap onto it. You might have to tweak the texture unit numbers when using this with your model.

Code:
import viz
viz.go()

NAME = 'wood_flloor'

slate = viz.addTexture('images/tile_slate.jpg',wrap=viz.REPEAT)

model = viz.add('gallery.osgb')
model.texture(slate,node=NAME,unit=2)

frag = """
uniform sampler2D map1;
uniform sampler2D map2;
uniform sampler2D lightmap;
uniform float blend;
void main()
{
	vec4 clr1 = texture2D(map1,gl_TexCoord[0].st);
	vec4 clr2 = texture2D(map2,gl_TexCoord[0].st);
	vec4 light = texture2D(lightmap,gl_TexCoord[1].st);
	gl_FragColor = mix(clr1,clr2,blend) * light;
}
"""
shader = viz.addShader(frag=frag)
shader.attach(viz.addUniformInt('map1',0))
shader.attach(viz.addUniformInt('lightmap',1))
shader.attach(viz.addUniformInt('map2',2))
blend = viz.addUniformFloat('blend',0.0)
shader.attach(blend)
model.apply(shader,node=NAME)

slider = viz.addSlider(pos=(0.5,0.1,0))
slider.set(0)

import vizact
vizact.onslider(slider,blend.set)
Reply With Quote