I have an initial texture loaded on my model and then I want to fade / transition gracefully into a second texture and then do another fade / transition into a third texture.
I found this shader code that works to fade from the original model’s texture to a second texture, but I can’t figure out how to fade to the third.
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *
import direct.directbase.DirectStart
import os
t1 = loader.loadTexture('maps/envir-ground.jpg')
ts = TextureStage('2')
s = loader.loadModel('smiley').getChild(0)
s.reparentTo(render)
s.setTexture(ts,t1)
sha = loader.loadShader('fade.sha')
s.setShader(sha)
s.setShaderInput('fade',0)
def applyFade(fade):
print fade
s.setShaderInput('fade',fade)
lerp1 = LerpFunctionInterval(applyFade,duration=3)
Sequence(
lerp1, Wait(1)
).start()
//Cg
void vshader(
in float4 vtx_color: COLOR,
out float4 l_color0 : COLOR0,
in float4 vtx_position : POSITION,
out float4 l_position : POSITION,
in float2 vtx_texcoord0 : TEXCOORD0,
out float2 l_texcoord0 : TEXCOORD0,
in uniform float4x4 mat_modelproj)
{
l_color0 = vtx_color;
l_position = mul(mat_modelproj, vtx_position);
l_texcoord0 = vtx_texcoord0;
}
void fshader(
in float4 l_color0 : COLOR0,
in float2 l_texcoord0: TEXCOORD0,
in uniform sampler2D tex_0: TEXUNIT0,
in uniform sampler2D tex_1: TEXUNIT1,
in uniform float4 k_fade,
out float4 o_color : COLOR)
{
float4 first_color = tex2D(tex_0, l_texcoord0);
float4 second_color = tex2D(tex_1, l_texcoord0);
o_color = lerp(second_color, first_color, k_fade.x);
}
I also need to fire off one transition at a time and then wait an undetermined amount of time before doing the next transition. So doing them all in the nested lerp may not work.
I’m successfully transitioning through a few textures.
Initial model texture > envir-ground > envir-mountain1
When I initiate ground > mountain I get a quick flicker of mountain on top of ground and then it fades correctly from ground > mountain. Can you tell why it is flickering?
On the last fade, I’m trying to go from envir-mountain1 > envir-rock2, but it isn’t working, mountain transitions back to ground. Why can’t I get to this last texture? Thanks!