PDA

View Full Version : Fading a PNG texture with alpha


tokola
06-27-2015, 11:11 AM
I am trying to add a png file on a separate texture unit and fade it in and out. For some reason Vizard does not recognize the transparent part of PNG as having alpha 0 (100% transparent), but rather as completely black. Using texblend has also no impact on this area, neither does setting the appearance to different values.

What's the problem? And can you actually fade in/out a texture, keeping the underlying one (unit=0) totally opaque?

tokola
06-30-2015, 03:39 PM
Any update on this?
I am also trying to apply a texture on another node that has a material pre-assigned in 3DS. No matter what image I use as a texture, only the color of the texture is applied and the actual texture is totally ignored. I am using again the "appearance" property with TEXREPLACE, but has no effect besides getting rid of the pre-exiting material.

I include my attempt. It shouldn't be that hard, but it doesn't work as the multi-texture example in the documentation with the Worldviz logo. What am I missing here?

Thanks.

Jeff
07-01-2015, 05:51 PM
For the first question, you could use a shader to multiply a blend value with the transparent texture and add that to the base texture. Here's an example:

import viz
viz.go()

viz.addChild('piazza.osgb')

quad = viz.addTexQuad(pos=[0,1.8,5])
texture = viz.addTexture('images/tile_grass.jpg')
texture2 = viz.addTexture('crosshair.png')
quad.texture(texture)
quad.texture(texture2,unit=1)

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

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

import vizact
vizact.onslider(slider,blend.set)

Please create a new thread for the second question for further assistance. The model does not seems to have texture coordinates.

tokola
07-06-2015, 02:50 PM
Thanks Jeff. This was actually the solution I've been looking for but haven't worked with shaders before.

As for the second question, it's true indeed that there are no text coords; I admit I forgot about this, as it's been quite a while since I did some modelling. Can you tell me if I have the option to add them in Vizard (or Inspector) and how, or I need only use 3ds? I am actually trying to make this object look rusty (avoiding 3ds, if possible). I'd rather try to resolve this some more, before I repost in another thread, if this is an easy fix.

Thanks!