PDA

View Full Version : multitexturing with a lightmap


cade_mccall
08-03-2012, 01:48 AM
Hellooooo,

I've made an ive with a lightmap that looks good in Vizard. Now I want use multitexturing so that I can blend between multiple textures. I'm able to add textures to different units, but when I use texblend to blend in a unit above 1, I lose the lightmap (which is in unit 1). So, is there a way to use texblend without losing the lightmap? If possible, I'd like to use the lightmap instead of baking the light onto each of the textures I'm using since I'm using many of them.

Thanks,
Cornelius

cade_mccall
09-20-2012, 06:03 AM
Was it something I said?

farshizzo
09-20-2012, 10:37 AM
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.

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)

cade_mccall
10-12-2012, 06:42 AM
Thanks! That did the trick.