Shader concept help

I have a question. Hope I make it clear.
I have a grid of 9x9 that I want to draw texture file into. So I will have 81 squares drawing textures that has transparency in the texture.

That is easy enough.

But the texture is an atlas of also a grid of 9x9. That is no issue, I have it working and I set the texture position and it passes in text coord to the shader to draw the correct square.

That is all simple.
Next complication is these squares need to be made up of 6 different textures on top of each other and to end up making a final texture. The texture has transparencies that the end results shows a combination of all possible 6 textures (can range from 1 - 6 textures).

What is the best way to approach this. I don’t think creating a grid of 9 x 9 with (6 nodes to each grid) make any since.
I’ve also, thought of creating an array of 6 text positions and passing it to my shader and it calculates the text coord and combines up to all 6 together to create a final color output.

I wanted to check to see if there is something inside of JME or other people ideas that make this easy.

I don’t want to end up with almost 500 nodes of quads to draw this small area.

Thanks,
Kevin

So I would do it like this: First I would apply Texture Array, not Texture.
Index 0…80 = 9x9 base areas. Even if it was unique in chronological order for you, I would disassemble it.
Index 81…86 = serve different textures.


In the texture array shader I would double the loading of the texture and fetch it once for Index9x9 and once for Index6.

Multiply the color. Finished in the very rough.

Or I would just put two meshes on top of each other with a distance of 0.01f.

This made me pause…

Was your 9x9 grid already 81 separate geometries?

Because that wasn’t necessary. One geometry would have been fine.

What is it that you are actually trying to do? How many different unique images are there?

Is there only 6 possible images that can appear on a quad for a given ‘layer’, or?

Without even writing a custom shader, you could have a custom mesh, standard material, atlas texture coordinates for the entire 9x9 quad mesh and then just make six of them. It doesn’t really need to be any more complicated than that… all done with clever meshes and an atlas texture.

But I admit that without context, it’s hard to say.

No just 1 geometry.

Trying to build layers of different images to create one final image to display, all 9x9 grids have this kind of need to it. It lays one texture on top of another and because of the transparent nature of the picture, it ends up creating a final picture.

There is just one image.maptiles
Here is a copy of the image.

I’m converting my game from my own engine into JME3. I would take 1 node with 1 geometry with 1 texture. I use atlas texture technique. I would pass in the Texture Position to use of the 9x9 grid and calculate the textcoord off that to draw just that area. But being my own game engine. I would just loop on that drawing and end up calling draw up to 6 times on that one node and update the texture position each time to end up with the correct image to the screen.

I hope that helps.

Here is a screen shot of my game in my own engine showing the map that it ends up making.


It is the lower right hand corner, arrow shows your position and facing and the gray areas are areas you have been to. and walls and doors are the layers I talked about. The grey area is the background (can be different colors depending on the ground) and the doors and walls for each side is drawn on top from that texture to end up with final result as shown.

If it were me, I’d use 6 geometries, one for each layer. Each of those geometries would be a 9x9 mesh with the appropriate atlas texture coordinates.

You could do it one geometry but it would require a custom shader where as 6 geometries is simple enough it could use the standard JME shaders.

The 6 Geometry approach would have 6 draw calls in total but I think the meshes could share position buffers… only the texture coordinate buffers would need to be different.

It seems you kind of already know what you are doing so there may be some hidden requirement that makes what I said more difficult than it would seem?

It is not just 6 geom. We are talking 6 geom per grid of 9x9. 9x9x6 = 486 geom for the grid. then x2 triangles and x4 time vertices.

I just didn’t want to have almost 1/2k of geom and over 1000 vertices to draw a 9x9 grid.

Also, didn’t mention. that is just the small mini map in the game. You have a full map that shows the full chunk of 64x64 squares. so it would end up, to me, being a tone of triangles and vertices.

64x64x6 = 24576 nodes x2 triangles 24576, x 4 vertices 98304. TO me for a simple function, that is a huge amount of stuff.

I was just wondering if some one had a simple solution.

So far, I think taking the unshaded shader and pass in array of texture points, and inside the shader calculate the textcoord, and just pass that to then add the colors together.
Can do it with one node and on draw call.

THanks, for tossing it around.

We are still talking past each other.

9x9 grid = 1 mesh with 81 x 2 triangle in it. one Geometry no nodes.

Just one geometry.

Mesh mesh = new Mesh();
// create a custom mesh with 9x9 quads in it
Geometry geom = new Geometry(mesh);
geom.setMaterial(... unshaded material);

One draw call for all 81 quads… or one draw call for all 24,576 quads for the larger map.

Then do that 6 times. And each of those 6 times can share the same position and index buffers… they only need a different texture buffer. But you aren’t going to get around having some kind of data for the texture coordinates.

…you say “array of texture points” but you are limited to the size of that array as a material parameter and it buys you nothing over a vertex buffer for texture coordinates, really.

But given that you want to support large maps, too… it’s probably better to just paint a texture. Then it’s only 4 vertexes.

That is a very interesting concept also. I’ll look into doing it this way.

JME has batching, from what I read about it. It sounds like this might work. turn the 9x9 into one mesh and then use the atlas feature to adjust the texture.
Then I just do do that 6 times for all the different textures.

Custom meshes are not particularly hard to make, especially in this case. And knowing how to do it will open up all kinds of possibilities in the future. In the case of your quads you don’t even need anything fancy like normals, etc…

I suspect if you looked at the source code to Quad.java then it might click how you could just extend those buffers to include multiple quads in your own code. Very straight forward with only a little knowledge about how index buffers work, etc… which you may already know from previous experience.

1 Like