Defold 1.7.0 has been released

Yeah, we want to show release notes etc as well, but we haven’t gotten to that point.

4 Likes

Another huge release! Congratulations and thank you! :heart: :confetti_ball:

5 Likes

We’ve added a new example for using vertex colors:

For those that use uniforms and (as a result) have many draw calls, can often use the vertex attribute approach to get a single draw call.

6 Likes

image
I have a few questions about this feature:

  1. Is it possible to dynamically change the size of this render target?
  2. Why are the dimensions of the stencil and depth different from the render-target itself?
  3. Where can I connect this render-target except render-script?
1 Like

Yes you can use a rendertarget resource with ∙ render.set_render_target_size(render_target,width,height)

One possibility I can see is when using texture storage for buffer/stencil and wanting to use a lower resolution, optimizing.

You can add them to .render files as resources and texture slots.

2 Likes

Thank you for VertexAttributeColor example! I’m curious, does it possible to do same with GUI elements? no idea how to pass values like go.set(url, "mycolor", vmath.vector4(r, g, b, 1)) to gui node. I’m trying to innovate on this “workaround” case: GUI add tint effect to image.

2 Likes

It is only supported for sprites currently. I’m not sure if we will add it to gui since we want to migrate Gui into the regular gameobject world

7 Likes

Is it possible to read data directly from render target now?

Not yet no, what is the use case? Don’t think I’ve seen a feature request about that :thinking:

One thing I want to be able to do is to easily be able to render scenes and use them in other scenes. So think of units in an RTS like Warcraft 3 where you click a unit and see a 3D portrait in the GUI.

Or Dota Underlords where you have a variety of 3D objects rendering above/within GUI.

1 Like

Yeah, I guess that’s the reason they want to migrate GUI to gameobject world

Usually it’s something that solves using a render target: you render what you need from the needed camera into a render target and then show it in GUI.

RT as resource should help with that.

I think @d954mas has done something like this in his new game.

3 Likes

Yes, i have it. Idea is simple. Draw 3d model in render target. Then use that render target in gui material as texture.

1)Make attlas with model rect.


2)Use this atlas at gui

3)Make a material for that gui.
gui_3drt.fp

varying mediump vec2 var_texcoord0;
varying lowp vec4 var_color;

uniform lowp sampler2D texture_sampler;
uniform lowp sampler2D rt_target;

void main()
{
    lowp vec4 tex0 = texture2D(texture_sampler, var_texcoord0.xy);
    lowp vec4 tex1 = texture2D(rt_target, var_texcoord0.xy);
    //not worked texture_sampler will be discard
    //rt_target now is texture 0. Shoud be texture 1
    //gl_FragColor = tex1;

    //use texture_sampler so texture index not changed.
    gl_FragColor = tex0 * 0.00 + tex1;
}

4)Draw model to render target. Use quad of atlast where that image should be.

function Render:set_3d_rt_atlas(atlas)
	local texture = hash(atlas.texture)
	local texture_info = resource.get_texture_info(texture)
	local w, h = texture_info.width, texture_info.height

	local data_by_id = {}

	for i = 1, #atlas.animations do
		local anim = atlas.animations[i]
		local gem = atlas.geometries[i]
		data_by_id[anim.id] = { animation = anim, geometry = atlas.geometries[i],
								x = gem.uvs[1], y = h - gem.uvs[2], w = anim.width, h = anim.height
		}
	end
	self.gui_3d_rt_atlas = {
		atlas = atlas,
		texture = texture,
		w = w, h = h,
		data_by_id = data_by_id
	}

end

function Render:draw_3d_for_gui()
	if self.gui_3d_rt_atlas then
		local image = self.gui_3d_rt_atlas.data_by_id["player_model"]
		if not self.gui_3d_rt then
			self.gui_3d_rt = create_3d_gui_buffer(self.gui_3d_rt_atlas.w, self.gui_3d_rt_atlas.h)

			self.rt_camera.view = vmath.matrix4_look_at(vmath.vector3(0, 1, 3), vmath.vector3(0, 1, 0), vmath.vector3(0, 1, 0))
			self.rt_camera.projection = vmath.matrix4_perspective(math.rad(60),image.w/image.h,0.01,100)
		end

		render.set_view(self.rt_camera.view)
		render.set_projection(self.rt_camera.projection)

		render.set_render_target(self.gui_3d_rt)
		render.set_viewport(image.x, image.y, image.w, image.h)

		render.enable_state(render.STATE_BLEND)
		render.clear(self.clear_rt)
		render.draw(self.predicates.player_3drt, self.draw_opts_no_frustum)
		render.draw(self.predicates.model_3drt, self.draw_opts_no_frustum)
		render.disable_state(render.STATE_BLEND)

		render.set_viewport(0, 0, self.screen_size.w, self.screen_size.h)
		render.set_view(self.camera_view)
		render.set_view(self.camera_perspective)
		render.set_render_target(render.RENDER_TARGET_DEFAULT)
	end

end

function Render:update()
...
	if self.gui_3d_rt then
		render.enable_state(render.STATE_STENCIL_TEST)
		render.enable_texture("rt_target", self.gui_3d_rt)
	end
	render.draw(self.predicates.gui)
	if self.gui_3d_rt then
		render.disable_texture("rt_target")
		render.disable_state(render.STATE_STENCIL_TEST)
	end
...
end

5)It worked

8 Likes

You can use named samplers now instead of relying to texture unit indices :+1:

5 Likes

Usecases will be more obvious with upcoming compute shaders support, you will need to pass render results to kernel (e.g. render models with textures to render target and pass this color data for raytracing to apply shadows) :thinking:
Actually it can be done reverse way - pass raytracing shadows data to render and combine with textures there… but probably passing normals and positions will speed up the raytraycer - as you need to trace only secondary (reflected) rays… I am not an expert here.

You can also bind storage buffers and write using atomics, I think we’ll have to cross that bridge when we get to it :slight_smile:

This kind of setup would be really useful to be an example project / module. Any 3D modules should include these features in their examples / easy setup for it. Could you share something stand alone?

I make a note about making demo.

But not in near future)

Now i have focus on next game)

4 Likes

I’m really upset that the built-in font was removed, as there was no clear reason (at least for me) to remove it. Now, every older project fails since 1.7.0 if it wasn’t updated, because many of them were using the built-in font and you need to click through all components and replace it with default.font one by one… I would be ok with only adding the new fonts, but what is the reasoning behind removing the old one?

image

Because 1-2 times a week, we faced the question “why is my text is always on top?” We could continue to answer the same question repeatedly, but the recurring nature of this question indicates that there is an issue with that.

The font’s name, ‘/builtins/fonts/system_font.font’, does not clarify its purpose. Even if we retained it, it’s likely that people would still encounter similar issues, perhaps slightly less frequently.

Sometimes we have to make changes that aren’t backward compatible, but these changes should help to clarify and resolve confusion in such areas.

4 Likes