WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   multitexturing with a lightmap (https://forum.worldviz.com/showthread.php?t=4315)

cade_mccall 08-03-2012 01:48 AM

multitexturing with a lightmap
 
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.

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)


cade_mccall 10-12-2012 06:42 AM

Perfect
 
Thanks! That did the trick.


All times are GMT -7. The time now is 08:57 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC