Texture blending does not work with jme2.0 [Solved]

im porting my environment system to jme2.0 since im about to release it to the community. but i just found out that dynamic texture blending doesnt work with jme2.0. could this be a bug?



heres the code i setup the textures in jme1.0:


   /**
    * Setup day and night blending textures on the given <code>Geometry</code>.
    * @param dayTexture The <code>Texture</code> used for the <code>Geometry</code> during day time.
    * @param nightTexture The <code>Texture</code> used for the <code>Geometry</code> during night time.
    * @param geometry The <code>Geometry</code> to be setup with the textures.
    */
   private void setupTexture(Texture dayTexture, Texture nightTexture, Geometry geometry) {
      TextureState texState = this.environment.getRenderer().createTextureState();
      geometry.setRenderState(texState);
      texState.setTexture(nightTexture, 0);
      texState.setTexture(dayTexture, 1);
      nightTexture.setApply(Texture.AM_COMBINE);
      nightTexture.setCombineFuncRGB(Texture.ACF_INTERPOLATE);
      nightTexture.setCombineSrc0RGB(Texture.ACS_TEXTURE1);
      nightTexture.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
      nightTexture.setCombineSrc1RGB(Texture.ACS_TEXTURE);
      nightTexture.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
      nightTexture.setCombineSrc2RGB(Texture.ACS_CONSTANT);
      nightTexture.setCombineOp2RGB(Texture.ACO_SRC_ALPHA);
      nightTexture.setBlendColor(this.fading);
       dayTexture.setApply(Texture.AM_COMBINE);
       dayTexture.setCombineFuncRGB(Texture.ACF_MODULATE);
       dayTexture.setCombineSrc0RGB(Texture.ACS_PREVIOUS);
       dayTexture.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
       dayTexture.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);
       dayTexture.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
      // Apply the day texture on the geometry with blending.
       geometry.copyTextureCoords(0, 0, 1);
   }



and heres the code with jme2.0:


   /**
    * Setup day and night blending textures on the given <code>Geometry</code>.
    * @param dayTexture The <code>Texture</code> used for the <code>Geometry</code> during day time.
    * @param nightTexture The <code>Texture</code> used for the <code>Geometry</code> during night time.
    * @param geometry The <code>Geometry</code> to be setup with the textures.
    */
   private void setupTexture(Texture dayTexture, Texture nightTexture, Geometry geometry) {
      TextureState texState = this.environment.getRenderer().createTextureState();
      geometry.setRenderState(texState);
      texState.setTexture(nightTexture, 0);
      texState.setTexture(dayTexture, 1);
      nightTexture.setApply(Texture.ApplyMode.Combine);
      nightTexture.setCombineFuncRGB(Texture.CombinerFunctionRGB.Interpolate);
      nightTexture.setCombineSrc0RGB(Texture.CombinerSource.TextureUnit1);
      nightTexture.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
      nightTexture.setCombineSrc1RGB(Texture.CombinerSource.CurrentTexture);
      nightTexture.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);
      nightTexture.setCombineSrc2RGB(Texture.CombinerSource.Constant);
      nightTexture.setCombineOp2RGB(Texture.CombinerOperandRGB.SourceAlpha);
      nightTexture.setBlendColor(this.fading);
       dayTexture.setApply(Texture.ApplyMode.Combine);
       dayTexture.setCombineFuncRGB(Texture.CombinerFunctionRGB.Modulate);
       dayTexture.setCombineSrc0RGB(Texture.CombinerSource.Previous);
       dayTexture.setCombineOp0RGB(Texture.CombinerOperandRGB.SourceColor);
       dayTexture.setCombineSrc1RGB(Texture.CombinerSource.PrimaryColor);
       dayTexture.setCombineOp1RGB(Texture.CombinerOperandRGB.SourceColor);
      // Apply the day texture on the geometry with blending.
       geometry.copyTextureCoordinates(0, 1, 1);
   }

provide a test and I'll be happy to debug

renanse said:

provide a test and I'll be happy to debug


heres the archive file. i setup 2 projects in there, Test1 uses jME1.0 and Test2 uses jME2.0.

please check it out.

http://environmentsystem.googlecode.com/files/TestBlend.zip

Can't wait for the final release  :slight_smile:

I hope some documentation will be present :slight_smile:



anyway, thank you very much for this great porting!

Niggle said:

Can't wait for the final release  :)
I hope some documentation will be present :)

anyway, thank you very much for this great porting!


well all the code r very well documented. and theres a test example provided as well.

i cant release it until this problem is fixed.

thx for the support  :D

Great :slight_smile:



By the way, at the end of the method, the code in JME 1.X is:

geometry.copyTextureCoords(0, 0, 1);



whereas in JME 2.X, it is:

geometry.copyTextureCoordinates(0, 1, 1);



Is the parameter difference normal?

Nah, the difference there is due to the removal of batches and such.



Turned out the problem was because setBlendColor copies the color object, so you changes to the original do not affect the set color.  This is by design, so instead, you can grab the blend color from the texture and make changes to it directly.

renanse said:

Nah, the difference there is due to the removal of batches and such.

Turned out the problem was because setBlendColor copies the color object, so you changes to the original do not affect the set color.  This is by design, so instead, you can grab the blend color from the texture and make changes to it directly.


thx for the help~ i should have looked into the new jme2.0 code more carefully  :D

now i just need to wait for the new textures to come, and settle all the legal issues, then i should be able to release the 1.0 version.

Any news?  :slight_smile: