Vertice offset from grey scale images, simmilar to height on Terrains

Hey guys

Is it possible to use a greyscale image to offset vertices?

Similar to a heightmap but to apply the “heightmap” texture to a spatial that is not a Terrain.

Is there another way to accomplish this without manually looping through the vertices, getting the pixel values and assigning the offset myself?

Well if you only need the grafical data, but no rays or collision, (like eg for small details or for rendering only) you an pass the texture to a shader, and mianpulate the vertexes with a small vert programm. However on the cpu you cannot know how the mesh looks then.

[Edit] Thanks @EmpirePhoenix

That’s is correct, I only need it for rendering purposes. I don’t need collisions or anything fancy to interact with the surface.

However, I’m not familiar with shaders and so far have been using JMonkey’s building filters to do stuff. I will look into the vertex shaders but I have a feeling I’m into a world of hurt.

It depends, actually it is kinda easy, once you understood them XD (as always).

The shader itself is probably around 5-10 lines total, then combine that with a j3md material definition, where you set tell it to use your vertex shader, and for the frac just use the default from unshader and that it.

I have a feeling I’m into a world of hurt.

I had the same feeling, then I took an evening to learn how to create shaders. I really recommend doing this step ! It makes difficult things very simple. And your request here is actually very simple to do with shaders (10 lines of code maybe).

It's not that difficult really, there's just a few things to know, like how to use normals, and how the vertex and fragment shaders communicate...

This tutorial is amazing and explains it whole :
I also recommend the software RenderMonkey :

There are various different languages for Shaders. jMonkey uses the GLSL language (GLSL ES is for Android).

Wow, 10 lines??? Is it like 10 difficult lines of code? :slight_smile:

Just kidding, I will look into this Vertice Shading thingy. I already got some success with manipulating the Vertices:

VertexBuffer buffer = mesh.getBuffer(Type.Position);

float[] vertexArray = BufferUtils.getFloatArray((FloatBuffer) buffer.getData());

Looping through these, messing with the position and assigning them back to the mesh by:


This mess up the Mesh because I’m screwing up the normals but at least it’s doing something to the mesh. Which is good.

Thanks a lot guys!

way to complex, and crude, I really suggest the shader approach.

10 simple lines of code. You should invest the time it will take to debug that buffer approach to learn Shaders.

Then, instead of wasting your time debugging something crude and complex, you will know something new, useful, and you will have spare time for a walk in the park.

Thanks for the help guys.

I spend a few days looking into the Shaders and I understand a lot more about where they fit in and how they function. Can I write cool shaders to do what I need? Nope!

My biggest problem is that I have no way of debugging or “seeing” into the inner workings of the sharders during runtime. I wrote a basic shader but as soon as I try something interesting, the shader breaks and I have no way of knowing why. This is hampering my progression and understanding into the wonderful work of shaders.

There is also some shader concepts that seems to elude me. I have read a lot of information about shaders but all the websites I went to, seems to make assumptions on what I already know about computer graphics and hardware. They leave a lot of information out with the assumption that you already have some background knowledge. It doesn’t look like I’ll be getting my project going soon :frowning:

research phail!