Multiple Texture Rendering with Terrain

First of all THANK YOU for the great job on JME, the quantity of material included helps more than thousands guides.



Though i am stuck in this -even if well documented- task.

[edit] i checked and tried to copy the relevant parts in the TestMultipleTexRender.java file included in jme



Situation: terrain built with 2 textures (similar to the Flag Rush tutorial) - with a milk model on top of it.

What i want to add: a texture rendered disk on the terrain just below the model.



I tried using a simple Disk textured, but it didn’t fit the terrain (it both cut it on half and went on top of it too much, cause of “hills”).

So i went towards this multitextured rending solution.



Some code i tried to use:



Top of buildTerrain()


   tRenderer = display.createTextureRenderer(512, 512, TextureRenderer.RENDER_TEXTURE_2D);;
   fakeTex = new Texture();
        fakeTex.setWrap(Texture.WM_CLAMP_S_CLAMP_T);
        tRenderer.setupTexture(fakeTex);



followed by the terrain generation.

Terrain texturing:


        TextureState ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        ts.setTexture(fakeTex, 0);
        Texture t1 = TextureManager.loadTexture(pt.getImageIcon().getImage(),
              Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR, true);
        ts.setTexture(t1, 1);
       
        //load a detail texture and set the combine modes for the two terrain textures.
        Texture t2 = TextureManager.loadTexture(
                TestTerrain.class.getClassLoader().getResource(
                "jmetest/data/texture/Detail.jpg"),
                Texture.MM_LINEAR_LINEAR,
                Texture.FM_LINEAR);

        ts.setTexture(t2, 2);
        t2.setWrap(Texture.WM_WRAP_S_WRAP_T);

       //.... some combining parts omitted ....//

        tb.setRenderState(ts);
        //set the detail parameters.
        tb.setDetailTexture(2, 16);
        tb.setRenderQueueMode(Renderer.QUEUE_OPAQUE);



Then the famous disk construction (method buildSelector()):


   Disk selector = new Disk("selectorDisk", 100, 100, 20);
   /* This quaternion stores a 180 degree rolling rotation */
   Quaternion roll180 = new Quaternion();
   roll180.fromAngleAxis( FastMath.PI , new Vector3f(0,1,1) );
   /* The rotation is applied: The object rolls by 180 degrees. */
   selector.setLocalRotation( roll180 );
   
   selector.setModelBound(new BoundingSphere());
   selector.updateModelBound();
   fakeScene = new Node("Fake node");
        fakeScene.setRenderQueueMode(Renderer.QUEUE_SKIP);
        fakeScene.attachChild(selector);
      
/*some alfas*/
   AlphaState as1 = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
        as1.setBlendEnabled(true);
        as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);
        as1.setDstFunction(AlphaState.DB_ONE);
        as1.setTestEnabled(true);
        as1.setTestFunction(AlphaState.TF_GREATER);
        as1.setEnabled(true);

        fakeScene.setRenderState(as1);
       
        ZBufferState buf = display.getRenderer().createZBufferState();
        buf.setEnabled(true);
        buf.setFunction(ZBufferState.CF_LEQUAL);
        fakeScene.setRenderState(buf);
       
        TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
        selectorTex = TextureManager.loadTexture(ClickAndMove.class.getClassLoader()
                  .getResource("texture/selection/heater.jpg"),
                  Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR);
       
        selectorTex.setWrap(Texture.WM_WRAP_S_WRAP_T);
        selectorTex.setTranslation(new Vector3f());
        ts.setTexture(selectorTex);
       
        fakeScene.setRenderState(ts);
       
        fakeScene.updateGeometricState(0.0f, true);
        fakeScene.updateRenderState();



Finally (sorry for the big code :x ) the render() part (i copied it, as most of the multitexturing code):


        lastRend += interpolation;
        if (lastRend > .03f) {
            tRenderer.render(fakeScene, fakeTex);
           lastRend = 0;
        }



The disk's texture is meant to be moving but i didn't implement it yet, cause it doesn't even appear on the terrain!

I'm sure i'm missing a step in here, if anyone can help me out, i would be very glad :)

Thank you in advance,
b4gn0

What you are looking for is called a decal just do a search and you will find a bunch of info.  :smiley:



One thread:



http://www.jmonkeyengine.com/jmeforum/index.php?topic=3519.0

"Decal".

Thank you for improving my knowledge  :wink:



b4gn0