r/GraphicsProgramming • • Dec 31 '19

Question Is it possible to render two objects in one vertex and fragment shader?

I'm trying to make another layer of cloud in Minecraft Bedrock (mobile) through GLSL shaders. Is it possible?

Edit: I'm not a pro at programming GLSL, I've only learned the basics from The Book of Shaders, please don't downvote me.

5 Upvotes

12 comments sorted by

10

u/specialpatrol Dec 31 '19

You can render any number of objects using the same vertex shader, but you can't duplicate objects in the vertex shader.

3

u/Eldeston Dec 31 '19

oh...I see, thanks

3

u/aymen_kh Dec 31 '19

i have no idea about minecraft, but yeah you can do that, ray tracing itself can be coded in a single shader

1

u/Eldeston Dec 31 '19

Is there a tutorial that can teach me how to render two objects?

8

u/hammerkop Dec 31 '19

Are you perhaps looking for instancing? You render as many copies of the same object as you want and use gl_InstanceID in the shader to position then or per instance attribute buffers. Look at glDrawArraysInstanced

4

u/Goku1920 Dec 31 '19

I kind of understand your question so my answer is yes, you can render two objects in one draw call using one vertex and shader call.

This is usually done by packing the vertices info for all the meshes you want to draw into one VBO. You will have to index it properly and provide proper transformation matrices for those meshes and that's about it.

But in your case where you have terrain and clouds they are two different materials (hopefully you want the clouds to just be a collection of cubes kind of like terrain but with different texture) you will have to provide proper texture indices. Look into how to create a texture atlas.

Hopefully I have understood your question and answer it correctly. Feel free to reach out if not or if you have any other questions.

2

u/DethRaid Dec 31 '19

On mobile Minecraft you can not do that

However, you can duplicate geometry on Win10 Minecraft (or Java Edition) through geometry shaders. Geometry shaders let you emit an arbitrary number of primitives for each input primitive. You could emit the regular clouds, then emit a second cloud layer higher up. You can even apply a different transformation to the second cloud layer so that e.g. they move in a slightly different direction or they have a different speed

-2

u/Eldeston Dec 31 '19

The effect I'm trying to get is this.

6

u/kikkurs Dec 31 '19

I'm seeing god rays and you mention two objects and another layer of cloud. What exactly do you want to do?

Do you just want to have another layers of clouds? Normally you'd do that from the draw call. If you want to have a misty effect, then maybe a postprocess will suffice, but that also involves some setup on the end of the draw calls. You definitely won't be able to convert only some existing shader code to create more clouds (maybe with some extreme creativity).

-12

u/Eldeston Dec 31 '19

Dude, I just want to know if it's possible to render two objects, not god rays. If you look close to the image, there are layers of clouds.

5

u/kikkurs Dec 31 '19

No need to downvote, I didn't see another layer of clouds because it's actually not that obvious.

Now that you point it out, sure, but the rest of my reply still holds: You need to touch draw call code to get that working. The reason why is that the original clouds are drawn as meshes, you need to draw more clouds as meshes, so that's more draw calls. Even if you want to use instancing (which is probably the simplest way), you need to change the original draw call(s) that draws the clouds.

1

u/Eldeston Dec 31 '19

Sorry, I didn't know your intentions..