Light and Shadows example

v0.8.2

Depth bias is no longer hardcoded in the shader and can now be customized by setting light_and_shadows.depth_bias or in the sun object. What’s this? To reduce the Peter Panning effect (shadows detaching from objects) in shadow mapping, you need to adjust the shadow bias, a value that offsets the shadow depth. Too high a bias causes Peter Panning, while too low a bias leads to shadow acne.

A new Tinyworld example has been added. It uses tilemap, pixelart textures, billboard sprites and different material variants.

15 Likes

Another demo “map editor”: tiny_world 0.1 (HTML5)

Added instanced model billboad shader for the forest props. What is the FPS on your device?

18 Likes

240 FPS RTX 3080 ti

5 Likes

What is the FPS on your device?

60 FPS with Intel Iris Xe integrated graphics. I assume it could go higher if vsync were disabled.

4 Likes

160+ FPS with 1000 objects - RTX 4060 on laptop


6 Likes

A steady 60 FPS with 4GB RAM and integrated Intel HD Graphics 4600 on a corei5 running Linux. Very nice work! Once I got to around 700 objects, it stuttered briefly to 59 FPS, but then reverted back to 60.

How do you create a bounce effect when buildings appear?

it’s just go.animate with EASING_INBOUNCE i think

0.83

  • Added billboard models material. And an example of it.
  • Added flexible adjustment of the number of light sources on the Scene. See the settings of the Sun object.
  • Added pinch zoom and rotate gestures. See the tinyworld example.
  • An example with the Spine models has been moved to its own repository. (Html5 Demo)

Demo: Light and Shadows 0.85

How looks billboard model in the editor viewport:

15 Likes

Another demo based on a tinyworld example : Fog of War

  • Fog of War (fragment shader + lua module)
  • Path finding module (pure lua)
  • Mini map

The sources are in a separate branch.

17 Likes

If anyone gets this error with the arena1.collection on main branch, remove the three decor1.go inside walls game object. I’m not sure if this is Linux only issue.

3 Likes

Thank you! I also had this issue (also on Linux).

1 Like

@Dragosha ,
When I run this project on Linux it does run. However I get these warnings:

WARNING:GAMESYS: Material /examples/tinyworld/materials/model_instanced_nearest.materialc has specified a vertex constant named 'mtx_world', but it does not exist or isn't used in any of the shaders.
WARNING:GAMESYS: Material /examples/tinyworld/materials/shadow_mesh/model3.materialc has specified a vertex constant named 'mtx_world', but it does not exist or isn't used in any of the shaders.

Why do these warnings occur? I think that mtx_world is automatically created, and it is used.
Is it to do with set_camera_world() ?
(comment in the readme file noted:-)

Also in the vp:

// When 'mtx_world' and 'mtx_normal' is specified as attributes,
// instanced rendering is automatically triggered.
#ifndef EDITOR
in highp mat4 mtx_world;
in highp mat4 mtx_normal;
#endif

uniform vs_uniforms
{
    #ifdef EDITOR
    highp mat4 mtx_world;
    #endif
    highp mat4 mtx_view;
    highp mat4 mtx_proj;
    highp mat4 mtx_light;
};

Please can someone explain details (or point me at info source, which probably I should of found myself!) of what is occurring with instanced rendering, and why the difference is required in the editor.

This is an amazing example and it opens up a shed load of questions:-)

This is done because the editor currently does not display smooth a large number of models with instancing enabled (the matrix in highp mat4 mtx_world; at the input to the shader as an attribute enables instancing, and this matrix in the uniform block is the opposite disables instancing ). Therefore, instancing in the shader is disabled in the editor, but in realtime it is enabled.

Just ignore these warnings, they don’t affect anything.

1 Like

Yes, this appears to be a workaround for the fact that the editor currently slows down to a crawl when it attempts to display models that use these matrix attributes. We hope to have this performance degradation fixed really soon, and you should no longer need these #ifdef EDITOR blocks.

5 Likes

0.84

  • Depth Of Field.

  • Fixed an error in the shadow rendering code, previously the frustum matrix was not pass correctly. It should be faster now.

  • Demo updated.

13 Likes

An important note regarding the Depth Of Field effect. By default, sprites do not write information to the depth buffer, so the blur effect will not be calculated correctly for them. If you want to add an effect to a scene with sprites, then you need to enable render.set_depth_mask(true) for sprite predicates. For example (this is a render script):

    render.set_depth_mask(true) -- sprites/tilemap for correct DepthOField effect should write to the depth buffer
    render.draw(predicates.bgtile, draw_options_world)
    render.draw(predicates.atile, draw_options_world)
    render.draw(predicates.tile, draw_options_world)
    render.draw(predicates.particle, draw_options_world)
    render.set_depth_mask(false)
    render.disable_state(graphics.STATE_DEPTH_TEST)

You also need to enable the discarding of semitransparent pixels in the shader to work correctly. By default, it is commented out in the shader here:

if(color.a < 0.1) discard; the value of the alpha channel after which discard should be made should be selected based on the graphics of the project, how smooth the edges of objects should be, dark or light graphics in general, etc. For pixelart, alpha <1.0 = discard is usually used.

11 Likes

0.85

  • Added FXAA (Fast Approximate Anti-Aliasing)

FXAA + Upscaling = :smiling_cat_with_heart_eyes:

To see the difference, watch the videos and screenshots in full size. :joy:

17 Likes

The level editor demo has been updated. It works on a mobile device, but it is recommended to open it on a computer to create your own level.

  • There are several ready-made templates (selectable in the settings menu).
  • FXAA, DoF, and all the same features as in the latest version of Light and Shadows.

Editor shortcuts:

  • Tab - switches between editor and view modes.
  • SPACE - opens the object palette.
  • SHIFT switches to moving the object along the Y-axis.
  • Z, X - moves the object only along the axes.
  • ALT - clones an object or a group of objects.
  • Clicking with R held down - draws a road.
  • After selecting an object on the map, use the mouse wheel (or double-tap on the right side of the touchpad on a MacBook) to quickly change the object from the list. + SHIFT - rotates the object.
  • Selecting with CTRL - selects a group of objects. You can move a group of objects around the level.
  • CTRL + Z - Undo
  • There are many glitches included.

25 Likes

Nothing serious, just updated the billboard shader for sprites. Now they work correctly with any initial size and rotation. Requires a new version of Defold 1.12.3 to work.

10 Likes