How to texture RawHeightMap without splatting

Hello I am new at this forum so i apologize if there is topic like this, but i didnt find it.

I am using RawHeightMap and i want to put some texture on it just like on imageBasedHeightMap.



I have this code:


private void complexTerrain() {
        // This grayscale image will be our terrain
              
        RawHeightMap heightMap = new RawHeightMap(Terrain.class
                .getClassLoader().getResource(
                        "jmetest/data/texture/mapa1.raw"),
                128, RawHeightMap.FORMAT_16BITLE, false);
        heightMap.setHeightScale(0.001f);
        Vector3f terrainScale = new Vector3f(1, 0.003f, 1);
        TerrainBlock tb = new TerrainBlock("Terrain", heightMap.getSize(), terrainScale,
              heightMap.getHeightMap(), new Vector3f(0, 0, 0), false);
        tb.setLocalTranslation(new Vector3f(0, -150, 0));
       
        tb.setDetailTexture(1, 16);

        ProceduralTextureGenerator pt = new ProceduralTextureGenerator(heightMap);
        pt.addTexture(new ImageIcon(Terrain.class.getClassLoader().getResource(
          "jmetest/data/texture/grass.jpg")), -128, 0, 128);
        pt.addTexture(new ImageIcon(Terrain.class.getClassLoader().getResource(
          "jmetest/data/texture/dirt.jpg")), 0, 128, 255);
        pt.addTexture(new ImageIcon(Terrain.class.getClassLoader().getResource(
          "jmetest/data/texture/highest.jpg")), 128, 255, 384);

        pt.createTexture(512);

        TextureState ts = display.getRenderer().createTextureState();
        ts.setEnabled(true);
        Texture t1 = TextureManager.loadTexture(
          pt.getImageIcon().getImage(),
          Texture.MM_LINEAR_LINEAR,
          Texture.FM_LINEAR,
          true);
        ts.setTexture(t1, 0);

        Texture t2 = TextureManager.loadTexture(Terrain.class.getClassLoader().
                                              getResource(
          "jmetest/data/texture/Detail.jpg"),
                                              Texture.MM_LINEAR_LINEAR,
                                              Texture.FM_LINEAR);
        ts.setTexture(t2, 1);
        t2.setWrap(Texture.WM_WRAP_S_WRAP_T);

        t1.setApply(Texture.AM_COMBINE);
        t1.setCombineFuncRGB(Texture.ACF_MODULATE);
        t1.setCombineSrc0RGB(Texture.ACS_TEXTURE);
        t1.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
        t1.setCombineSrc1RGB(Texture.ACS_PRIMARY_COLOR);
        t1.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
        t1.setCombineScaleRGB(1.0f);

        t2.setApply(Texture.AM_COMBINE);
        t2.setCombineFuncRGB(Texture.ACF_ADD_SIGNED);
        t2.setCombineSrc0RGB(Texture.ACS_TEXTURE);
        t2.setCombineOp0RGB(Texture.ACO_SRC_COLOR);
        t2.setCombineSrc1RGB(Texture.ACS_PREVIOUS);
        t2.setCombineOp1RGB(Texture.ACO_SRC_COLOR);
        t2.setCombineScaleRGB(1.0f);
        tb.setRenderState(ts);
       
        FogState fs = display.getRenderer().createFogState();
        fs.setDensity(0.5f);
        fs.setEnabled(true);
        fs.setColor(new ColorRGBA(0.5f, 0.5f, 0.5f, 0.5f));
        fs.setEnd(1000);
        fs.setStart(500);
        fs.setDensityFunction(FogState.DF_LINEAR);
        fs.setApplyFunction(FogState.AF_PER_VERTEX);
        tb.setRenderState(fs);
       
        rootNode.attachChild(tb);
    }



And result is this: http://www.stud.fit.vutbr.cz/~xhacaj00/map.jpg
It is grayscale and pretty dark.

And when i set localTranslation to 0,0,0 its position is aprox. 0,200,0... Why?

Thanks for all replies...

PS: sorry for my english... i am from slovak rep..

I can only see blackness in your screen shot… (press 'L' to toggle lights in simpleGame)



As far as the translation goes, TerrainBlocks are centered at the NorthWest corner while TerrainPages are centered at the center (not to be redundant).  To center a TerrainBlock subtract (or maybe its add…) 1/2 of the X and Z size to the location, then add that to a Node.  The new Node will be centered at (0,0,0) and you can just use it to move the TerrainBlock around…



(Or just switch to a TerrainPage ;))

Thank you



L didnt work…:frowning:



this is better quality screenshot http://www.stud.fit.vutbr.cz/~xhacaj00/map.bmp



looks like there are some green spots…

You cannot multitexture a TerrainPage without using splatting. What you would have to do, if I am not mistaken, is create a texture for how you wanted it to look, and load that one texture onto the object. However, that texture would have to be enormous, and no graphics card could load it.

When I use imageBasedHeightMap, then it works…chceck jme.TutorialGuide.helloTerrain.java

How does your RAW heightmap look like? Are you using the whole grayscale range for it?



Remember that the values in the heightmap multiplied by scale are used to calculate the contribution of each texture. So if all the values fall below -128 (the range start value for grass texture), then no textures will contribute to the final texture. Adjust both your RAW image, the scale, and the ranges, so that you get a better result. Try to debug your program, and see what kind of data is loaded into the heightmap. Are you saving the heightmap with proper format? What happens if you apply a ready made (any) texture to the terrain? Does the terrain look like its supposed to look?

It's because you are still a procedural texture generated for an image based height map.

Image based height maps have a much smaller range of height values.

With a raw height map you will need to use bigger ranges. The result you are seeing is just the detail texture, because the procedural color texture probably only affects a tiny part of your map.



I just made up these numbers, but try something like this:



ProceduralTextureGenerator pt = new ProceduralTextureGenerator(heightMap);
        pt.addTexture(new ImageIcon( (ResourceLocatorTool.locateResource(
               ResourceLocatorTool.TYPE_TEXTURE, "grassb.jpg")) ), -4000, 8000, 18000);
        pt.addTexture(new ImageIcon((ResourceLocatorTool.locateResource(
               ResourceLocatorTool.TYPE_TEXTURE, "dirt.jpg")) ), 12000, 16000, 22000);
        pt.addTexture(new ImageIcon((ResourceLocatorTool.locateResource(
               ResourceLocatorTool.TYPE_TEXTURE, "highest.jpg"))), 18000, 25000, 32000);

doh Vear wins  :expressionless:

Alric said:

doh Vear wins  :|


We wont know the result, till he fixes it. I'm just eyeing the RawHeightMap, cause there is some of my code in it. So, if it really is that the solution, and not a bug in RawHeightMap, then you can have the score.  :D

To Alric:

Thank You, playing with this numbers helps me.



I ve got this:

pg.addTexture(new ImageIcon(grassImage),25000, 30000, 40000);
        //  Look like dirt from height 40-120 with the strongest "dirt look" at 80
        pg.addTexture(new ImageIcon(dirtImage),35000, 40000, 50000);
        //  Look like highest (pure white) from height 110-256 with the strongest "white look" at 130
        pg.addTexture(new ImageIcon(grassImage),40000, 50000, 55000);



result is:
http://www.stud.fit.vutbr.cz/~xhacaj00/map2.bmp
raw map is:
http://www.stud.fit.vutbr.cz/~xhacaj00/raw.png

For creating this map i used photoshop and render clouds, save as raw for pc, header 0 :)

But i must guess this numbers... Is there a way to count it? thanks again  :)

EDIT: i think i got it... i must use whole range of grayscale... is there some good program to make raw files with this range?

because my goal is to make a HUGE scene and I must do it by myself because its for my BSc Thesis (so i cant use jme terra or this http://www.jmonkeyengine.com/jmeforum/index.php?action=printpage;topic=8727.0) I have a BIG grayscale image(2000x2000 f.e.) and i want to divide it to small squares and display only few (9) of them. When I transfer in world i display another 9. Similar principle like in link, i wrote. And i dont know how to make this picture, that every tile of it will have whole range(or at least same)  of grayscale... any ideas? thanks a lot

So I have created big picture(500x500) and divided it to 100 small squares(50x50) and I load that squares in sequences… But I have a proble that these suqares don't fit to each other (see screen shot). They just fit aproximately but i need it correctly… please help i am down:(

I try to use RawHeightmap and ImageBasedHeightMap, but same problem with both of them…



http://www.stud.fit.vutbr.cz/~xhacaj00/problem.bmp

You need the border triangles fixed so that those stitch together, so you will probably need to change the whole terrainblock triangle generation.



I would suggest that you choose a terrain engine, which already has all the issues solved.

Thank You!

Stich it together was easy… but i didnt realize that its possible:) thank you