VertexBuffer for specific UV behavior Shaders

When you use tessellation you need to add a HeightMap :stuck_out_tongue: also i may have made a spelling error so it may really be HeightMap and not HeigthMap xD

    tessellationMaterial.setInt("TessellationFactor", 64);//(2-64 max) also setting this value higher will make the LOD farter :slight_smile: So you can abuse this to make the Distance for change higher :stuck_out_tongue:  
    tessellationMaterial.setFloat("DisplaceFactor", 0.2f);//(how much displacement will be done with the white color of the HeightMap)

    Texture diffuse = assetManager.loadTexture("Textures/Road/diffuse.png");
    Texture normal = assetManager.loadTexture("Textures/Road/normal.png");
    Texture height = assetManager.loadTexture("Textures/Road/height.png");

    tessellationMaterial.setTexture("DiffuseMap", diffuse);
    tessellationMaterial.setTexture("NormalMap", normal);
    tessellationMaterial.setTexture("NormalDisplacementMap", height);

i had to correct my self, IT’s a NormalDisplacementMap and not HeightMap

I have added the new code you posted, and have linked images to the 3 Textures you have.
The road is still transparent. (i can see the shadow on it though)
I get the feeling im doing something wrong…

Just to be clear, im trying to recreate the road you have, the terrain is not related just so i can be on something to see things.

Oh did you set the tessellation Boolean true? in the Mesh Builder,

    RoadMesh road = new RoadMesh(10, 5, cp, false, true); //The last param as to be true

also If nothing work, try to set the FaceCullMode off

 road.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);

I didn’t really did any Documentation… Sorry, first time i was sharing code with some one. Next time i will be aware of adding comments :stuck_out_tongue:

If it doesn’t work, i will have to look at it by my self. I may have done a mistake and integrating the code doesn’t work as intended.

I changed those 2 things and set the facecullmode to off. I had to switch the collisionshape to a meshcollisionshape for this to work to here.
Now im getting this error, which isn’t in my code (because it happens in simple update):

java.lang.UnsupportedOperationException
	at com.jme3.scene.mesh.WrappedIndexBuffer.<init>(WrappedIndexBuffer.java:73)
	at com.jme3.collision.bih.BIHTree.<init>(BIHTree.java:131)
	at com.jme3.collision.bih.BIHTree.<init>(BIHTree.java:139)
	at com.jme3.scene.Mesh.createCollisionData(Mesh.java:966)
	at com.jme3.scene.Mesh.collideWith(Mesh.java:995)
	at com.jme3.scene.Geometry.collideWith(Geometry.java:450)
	at com.jme3.scene.Node.collideWith(Node.java:611)
	at com.jme3.scene.Node.collideWith(Node.java:611)
	at com.simsilica.lemur.event.PickEventSession.cursorMoved(PickEventSession.java:467)
	at com.simsilica.lemur.event.MouseAppState.dispatchMotion(MouseAppState.java:93)
	at com.simsilica.lemur.event.BasePickState.update(BasePickState.java:169)
	at com.jme3.app.state.AppStateManager.update(AppStateManager.java:287)

It feels like there is a method in RoadMesh class that needs to be overrided.

My debugging found that removing the setMode(Mesh.Mode.Patch) line in RoadMesh removes the error. But this results in a textureless roadmesh again.

Nope you are using a Ray tracing or some method that travers the Mesh which isn’t supported at the moment, I asked about it and @nehon told me he would see about this issue :S. This was talk in a previous topic with an other member but at the moment you would need to stop using any kind of mesh detection you are using, or make the road not be test for collision result, There was an other methods which did the same effect, i can’t recall which lets me look
Edit:

Batching does the samething, anyway you shouldn’t batch the road it was intended to not require any batching, also Physic may do the issue so you should try to remove physics.

If you need physic make the mesh with out collision and make the physic object from the non Tessellated version.(If the physic was the issue) If you need collision with RayTracing you can do an invisible Node and use the one with out Tessellation.
Using Tessellation is just to improve close by graphics and geometry complexity at a lesser cost, you will need a good Displacement Map to get good result, if you want try this Texture

http://www.textures.com/download/substance0043/127911

Use the 3 first, Diffuse, Height and Normal and see for your self :slight_smile:

That is disappointing, because the next step for me was raycasting the terrain to the height of the road (similar to the linked video).
And without really looking into it, lemur does seem like it does some world objects detection for object selection reasons. So adjusting lemur just to get the road to work would be a rather large modification.

Thanks for all the help though. And I will be keeping an eye on this if the Mesh.Mode.Patch gets fixed.

Like i said, you can do a fake road not visible under which receive the ray

I have tried adding a secondary road without tessellation and textures which can be the raycast and collision model.

I think by just having the object the sceen graph every raycast will have to ignore it (other wise it will crash on the above exception). Unless there is there a way to exclude something from the raycast set permanently i would be able to use RoadMesh because something will still try to ray cast it.

Edited back, It work, i remove the wrong thing haha

SO like I said, just don’t attach the Node to the Scene and use it like this

public void update2(float tpf) {
    Camera cam = getCamera();
    Ray ray = new Ray();
    CollisionResults results = new CollisionResults();
    boolean touched = false;
    String s = "";

    Vector3f origin = cam.getWorldCoordinates(getInputManager().getCursorPosition(), 0.0f);
    Vector3f direction = cam.getWorldCoordinates(getInputManager().getCursorPosition(), 0.1f);

    direction.subtractLocal(origin).normalizeLocal();

    ray.setDirection(direction);
    ray.setOrigin(origin);

    fakeRoadNode.collideWith(ray, results); // It wont be compute and you will be able to test

    if (results.size() > 0) {

        for (int i = 0; i < results.size(); i++) {

            s = results.getCollision(i).getGeometry().getParent().getName();
            if (s.equalsIgnoreCase("FakeFloor") && results.getCollision(i).getDistance() < 1680) {

                touched = true;
                moveBasicFondatiom(results.getCollision(i).getGeometry(), results.getCollision(i).getContactPoint());

                break;
            }

        }
    }
}

What happens when i can’t edit the ray cast code to exclude the RoadNode?
That sounds like code coupling i don’t need.

What do you mean? you don’t edit the code, you just use it as it is, look at the code

I have a raycast on the root node for the car wheels because they have to show effects on collisions.
As in: restricting the raycasts to not include the RoadMesh is not possible in my game.

Something like:

public class MyGeometry extends Geometry {
    public int collideWith( CollisionResults cr ) {
        return 0;
    }
}

Oh, my bad.
Looks like this will work. I’ll let you know how it goes.

Sorry for not responding earlier, I found a few other parts of the project needed to happen first.

In summary i not longer ray cast to set the height.
I generate the height of every integer grid point under the road segment and set the height to that instead, its much faster and using a separate thread can be done in real time. (the ray casting method took 30sec to load the first terrain point)

@n3cr0
I think i found a bug in the RoadMesh code. The lines that look like
computePosition.add( v1.add(new Vector3f(FastMath.cos(angle1) * width , 1, FastMath.sin(angle1) * width )));
Need the 1 turned into a 0 otherwise the road texture is offset by 1y.
(RoadTessalation/RoadMesh.java at master ¡ JulienGreen/RoadTessalation ¡ GitHub)

Sorry as i haven’t managed to test the textures yet.
But i will get to it.

1 Like

That correction you made was already corrected long ago. Maybe i just forgot to update the Github with it. also sorry for the slow answer i had other thing to do in life :confused: .

But thx to point out that bug i will look closer into it.