Texture Fading

Hey there,



I am currently fading from one texture to another on a Quad, using this code:



    fadeFromTex.setApply(Texture.ApplyMode.Combine);
    fadeFromTex.setCombineFuncRGB(Texture.CombinerFunctionRGB.Interpolate);
    fadeFromTex.setCombineSrc0RGB(Texture.CombinerSource.TextureUnit1);
    fadeFromTex.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
    fadeFromTex.setCombineSrc1RGB(Texture.CombinerSource.CurrentTexture);
    fadeFromTex.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);
    fadeFromTex.setCombineSrc2RGB(Texture.CombinerSource.Constant);
    fadeFromTex.setCombineOp2RGB(Texture.CombinerOperandRGB.SourceAlpha);
    fadeFromTex.setBlendColor(fadeColor);
    fadeToTex.setApply(Texture.ApplyMode.Combine);
    fadeToTex.setCombineFuncRGB(Texture.CombinerFunctionRGB.Modulate);
    fadeToTex.setCombineSrc0RGB(Texture.CombinerSource.Previous);
    fadeToTex.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
    fadeToTex.setCombineSrc1RGB(Texture.CombinerSource.PrimaryColor);
    fadeToTex.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);

    q.copyTextureCoordinates(0, 1, 1);
    q.updateRenderState();



but it results in the following:



The original texture is a textured letter k and i want to fade to the image of a pyramid.
As you can see here, when i fade from a partially transparent texture to another texture, the fade only happens where the original texture is not transparent. I need the other texture to also fade in the transparent parts.

i appreciate any help, so long,
Andy

anyone? please?

Not sure if that's the problem, but you're not setting the alpha combine mode in that code (setCombineFuncAlpha), it's possible that the alpha is taken from the K image which causes the results you have.

this is definitely the problem, thx.



but now i have the problem that i do not know my way around these Functions



if I add these two lines, the whole texture will fade correctly, BUT the transparent parts of the K will be displayed black  :expressionless:


    fadeFromTex.setCombineFuncAlpha(CombinerFunctionAlpha.Modulate);
    fadeToTex.setCombineFuncAlpha(CombinerFunctionAlpha.Interpolate);



Momoko_Fan, you're the goto guy on these things. Please give me the correct values for now  ;) I promise i'll buy the red book soon  :wink:

thanks a lot so far,
Andy

I was going to answer this but forgot…

Anyway, you have to specify alpha=1 for both textures, so just use a texture where all alpha pixels are white (I assume the pyramid) and specify that as a source.



I don't remember the names but hopefully you can guess

setCombineFuncAlpha(CombinerFunctionAlpha.Constant);
setCombineSrc0Alpha(Texture.CombinerSource.Texture0);
setCombineOp0Alpha(Texture.CombinerOperandAlpha.SourceAlpha);

hey there,



thanks so far but i am confused in two ways:  :wink:


  • CombinerFunctionAlpha doesn't have an enum value Constant
  • Set all transparent pixels to white  :?



    in the case above the texture with the letter K has a transparent background and the pyramid has no transparency.



    The problem is that i never know which two textures i am fading and if none of them, one of them or even both have transparent parts in them. Nevertheless i need to fade them correctly with transparency and all.



    Thank you so far Momoko_Fan, please don't give up on me now  :wink:

got it to work!  :smiley:



since the colors fade just fine i thought just do the same thing with alpha:



    fadeFromTex.setApply(Texture.ApplyMode.Combine);
    fadeFromTex.setCombineFuncRGB(Texture.CombinerFunctionRGB.Interpolate);
    fadeFromTex.setCombineSrc0RGB(Texture.CombinerSource.TextureUnit1);
    fadeFromTex.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
    fadeFromTex.setCombineSrc1RGB(Texture.CombinerSource.CurrentTexture);
    fadeFromTex.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);
    fadeFromTex.setCombineSrc2RGB(Texture.CombinerSource.Constant);
    fadeFromTex.setCombineOp2RGB(Texture.CombinerOperandRGB.SourceAlpha);
    // do the same with alpha:
    fadeFromTex.setCombineFuncAlpha(Texture.CombinerFunctionAlpha.Interpolate);
    fadeFromTex.setCombineSrc0Alpha(Texture.CombinerSource.TextureUnit1);
    fadeFromTex.setCombineOp0Alpha(Texture.CombinerOperandAlpha.SourceAlpha);
    fadeFromTex.setCombineSrc1Alpha(Texture.CombinerSource.CurrentTexture);
    fadeFromTex.setCombineOp1Alpha(Texture.CombinerOperandAlpha.SourceAlpha);
    fadeFromTex.setCombineSrc2Alpha(Texture.CombinerSource.Constant);
    fadeFromTex.setCombineOp2Alpha(Texture.CombinerOperandAlpha.SourceAlpha);
    fadeFromTex.setBlendColor(fadeColor);
   
    fadeToTex.setApply(Texture.ApplyMode.Combine);
    fadeToTex.setCombineFuncRGB(Texture.CombinerFunctionRGB.Modulate);
    fadeToTex.setCombineSrc0RGB(Texture.CombinerSource.Previous);
    fadeToTex.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
    fadeToTex.setCombineSrc1RGB(Texture.CombinerSource.PrimaryColor);
    fadeToTex.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);
    // do the same with alpha:
    fadeToTex.setCombineFuncAlpha(Texture.CombinerFunctionAlpha.Modulate);
    fadeToTex.setCombineSrc0Alpha(Texture.CombinerSource.Previous);
    fadeToTex.setCombineOp0Alpha(Texture.CombinerOperandAlpha.SourceAlpha);
    fadeToTex.setCombineSrc1Alpha(Texture.CombinerSource.PrimaryColor);
    fadeToTex.setCombineOp1Alpha(Texture.CombinerOperandAlpha.SourceAlpha);



Thank you Momoko_fan for your help!