Mesh Component

After playing with this for a bit, I have a bit of feedback:

  1. This solved this issue of creating geometry at runtime, but that geometry is still not clickable. For that to happen, we’d need to be able to create collision shapes at runtime. The buffer API sounds like a great use-case for that as well.
  2. I couldn’t get Material World Space to work. It looks like it completely disregards the world transform and everything gets rendered at (0, 0) in world space.
  3. Not a big deal, but it seems like I couldn’t get a bunch of meshes with the same material, uniforms and transform (but different buffers) to batch.
6 Likes

For 3 to work, I think the material vertex space needs to be world instead of local. Then the vertex position needs to be setup differently. Would still be nice for us to be shown the ideal way of doing this.

Yes, but I couldn’t get Material World Space to work. I selected the right streams for position and normal in the mesh component in the editor, and switched the vertex space to World Space in the material. And it seems like it completely discards the world transform on anything that I render, as if it’s sending the data in the buffer without transforming it.

And anyway, even in this state, I still get one render call per mesh.

1 Like

Re 2) When you use World Space, all vertices are transformed on the CPU, thus the world matrix for that mesh essentially becomes the identity matrix. It sounds like what you expected, but didn’t get, so I’ll take a look and try to create an example for you.

Re 3) The batching mechanism triggered only when using World Space. When using “Local Space”, each draw call uses a separate (unique) world transform, and thus cannot be batched. For that to happen, we’d have to implement instancing, which we currently haven’t had in the road map.
I added #4818 for instancing, and #4819 for physics custom meshes using the buffer format.

6 Likes

Yay, and now the links actually make sense to the community as well!

6 Likes

I remember noting that at one point the Release Notes switched over to point towards a private github repo, which means that the older links that didn’t work previously will now work for everyone!

This means that people can even go back to older release notes if they are interesting in how something was fixed :grin: (Looked quickly and it seem to be anything after and including 1.2.163

5 Likes

I have an idea for a new Defold library: functions for transforming 2d primitives into each other. Like circle -> square, square -> triangle and so on
Just if somebody has time to play with math

3 Likes

Hi, awesome feature!
I’m trying to play with your example for studing purposes:

I’ve a bit modified a shader to render textures with alpha channel.
Now I try to fix a mistake with semi-transparent quad (dice shadow), when his Z-coord is behind Z of the ground this quad renders wrong. I get an advice to modify render script with new predicate for transparent materials.

Sources: mesh.zip (313.3 KB)

Questions:

Thanks!

11 Likes

An atlas actually becomes a single texture. The problem is then to figure out the uv coordinates of the original images inside this texture.

I haven’t seen that error output before. Thanks for reporting!

3 Likes

If we could generate or use our own atlases…

I guess we can but if we use raw images then we don’t get the benefits of texture profiles.

1 Like

Updated sources: mesh2.zip (322.0 KB)

Now correct rendering of transparent textures, except a situation of cross of them

3 Likes

Today’ results :slight_smile:

Question:
How to enable ADD blending for mesh or models?

17 Likes

Whoa!!! Truly amazing !!!

3 Likes

You’ll want to add an extra material and render predicate for that most likely. But I do not remember right now what requires to be set. Maybe @d954mas knows? I am not sure if we can set anything which modifies GL_FUNC_ADD currently? You can use a render target for the light step to draw additively more easily.

The godrays are missing some double sided meshes?

The problem you are seeing with your sprite shadows I believe is because of depth culling? So you need to draw those sprites last, disable drawing to depth, but still test depth? It’s been a while since I worked with that.

The shadows appear to have fighting happening in the video where the shadows share the same y position. A possible way to do this is always add a little extra small amount of position like 0.0001 depending on its id.

Some of this is covered here https://learnopengl.com/Advanced-OpenGL/Blending

5 Likes

They’re just sprite components with ADD blending for now, while I research how this effect meet to meshes.

Inside an editor it looks like that:

Thanks for some advice!

12 Likes

And finally, HTML5 demo:
https://dragosha.com/dice/

14 Likes

This looks super exciting! Great work!

4 Likes

@Dragosha it looks great!

Also I’m always amazed at how well Defold runs on html5, even on my super old iPhone6!

6 Likes

Added:

  • simple dice gameplay
  • click to quad detection (coloring)
  • mesh wave fx

15 Likes

:open_mouth: Well this is a pretty amazing feature, I didn’t get a chance to really try it out until now. My mind kind of boggles at all the possibilities this opens up.

A question: When does the “vertices” buffer get copied? I mean, when you do: ‘resource.get_buffer’, is that just a copy, or not? Or does it copy the buffer when you do ‘resource.set_buffer’?

I’ve noticed that:

local buf1 = resource.get_buffer(self.bufferResourceAddress)
local buf2 = resource.get_buffer(self.bufferResourceAddress)
print(buf1 == buf2)

…always gives false. Is that just because == doesn’t work for the buffer type, or are they actually different things?

This is my current experiment:
defold_mesh_line_drawing
So, on every click, I make a new buffer with space for 2 more points and copy the contents of the old one.

My function code
local function makeNewBuffer(self, vertCount)
	local newBuffer = buffer.create(
		vertCount,
		{
			{ name = POSITION, type = buffer.VALUE_TYPE_FLOAT32, count = 3 },
			{ name = COLOR, type = buffer.VALUE_TYPE_FLOAT32, count = 4 },
		}
	)
	buffer.copy_buffer(newBuffer, 0, self.buffer, 0, self.vertCt)
	resource.set_buffer(self.bufferResourceAddress, newBuffer)
	-- self.buffer = newBuffer -- This does NOT work.
	self.buffer = resource.get_buffer(self.bufferResourceAddress) -- Must do this.
	self.verts = buffer.get_stream(self.buffer, POSITION)
	self.colors = buffer.get_stream(self.buffer, COLOR)
	self.vertCt = vertCount
end

It took me a while to figure out that I needed to do ‘resource.get_buffer’ immediately after ‘resource.set_buffer’. I couldn’t just use the buffer that I created. :confused:


Question 2: Will it ever be possible to create and destroy elements from a buffer?

[Edit] Question 2.5: Would it be possible to make a native extension to do this? (as a complete NE noob)

2 Likes