Teaser for a few small render features

Hi! Since we are working on improving our 3D support this year, I thought I’d share some small features we are adding quite soon to the engine:

Render constant arrays

Github issue: https://github.com/defold/defold/issues/6529

We already support settings constant array values via go.set like this:

go.set(url, "example", vmath.vector4( 1, 1, 1, 1 ), { index=5 } )

But currently our render constant buffers does not have any support for this, we always set the first constant in the array regardless of the other values. Adding that support for the render constants is not only good for feature parity between render and go, but it will be easier to work with in the cases where you only have this data in the “render” world and don’t want to keep passing this back and forth. The API for doing so will look like this:

-- in render script
self.my_constants           = render.constant_buffer()
self.my_constants.colors    = {}
self.my_constants.colors[1] = vmath.vector4(1, 0, 0, 1)
self.my_constants.colors[2] = vmath.vector4(1337, 0, 0, 0)
self.my_constants.colors[3] = vmath.vector4(0, 0, 0, 1337)

render.draw(self.my_pred, { constants = my_constants })
-- in shader
uniform lowp vec4 colors[3];

Constant matrix type

Github issue: https://github.com/defold/defold/issues/3614

Currently we only support user types of vec4, although we do have matrix types for certain built-in constants such as view matrix, projection matrix and so on. For more complex features such as shadow mapping you have to pass in custom matrices, e.g projection matrix from the light that rendered the depth map by passing in four vec4s and recreate the matrix in the shader. It works, but it’s not optimal. So instead we are adding a new constant type ‘CONSTANT_TYPE_USER_MATRIX4’ field that you can use to map a vmath.matrix to shader uniforms via materials. In code, the API will look something like this:

-- in render script
self.my_constants                 = render.constant_buffer()
self.my_constants.matrix_constant = vmath.matrix4()

-- in go world
go.set("#sprite", "matrix_constant", vmath.matrix4())

-- in shader
uniform lowp mat4 matrix_constant;

Anisotropic filtering

Github issue: https://github.com/defold/defold/issues/6155

Currently we can only set bilinear or trilinear filtering for texture samplers in the materials, but for 3D games you typically want to be able to set a level of anisotropic filtering on samplers to avoid blurred filtering in certain scenarios, ie. viewing geometry at extreme angles from the camera:


(image from wikipedia)

This will be available by a new material “max anisotrophy” option passed into the renderer that enables this feature on the hardware level.

When will these features be available?
Soon! The first designs have been approved and the code is mostly done and working, we just need to add unit tests, vulkan support and some editor settings :slight_smile:

26 Likes

Great news!!!
It’s good to see the engine evolving in this direction.
A few months ago I had my doubts whether I could implement one of my projects with massive 3D on Defold, but now those doubts are less and less.

3 Likes

Yeah our plan is to keep improving it, at least that’s my passion right now since more people are doing 3D. Mesh culling is planned as well, which should help your game I think. Also, all of these features are based on community requests so keep posting tickets and we’ll do what we can to enable

6 Likes