New Illumination โ€” clustered forward shading lighting + shadows

Mix of defold-illumination and defold-light-and-shadows
This example contains ready-to-use forward shading lighting mixed with realtime shadow from one source (the sun)

:video_game: Play HTML5 demo with :flashlight: on the E key.

Pros:

  1. Worked in mobile( defold-illumination not worked in my mobile looks like shader precision problem)
  2. Frustum culling for light sources(from scene3d)
  3. Clustered forward shading
  4. Dynamic shadow matrix(update the shadow matrix whenever the camera moves so that it ideally describes the cameraโ€™s frustum)

Cons:

  1. Remove normal and specular map. I do not use it in my games. So if you need them you can add them by yourself(look in illumination sources)
  2. Web build contains some precision issues(need find and fix them):frowning:
17 Likes

583 light sources. About 20fps in firefox(without screen capture)

9 Likes

@jhonny.goransson
For light data i create texture in runtime resource.create_texture.
Then i changed data.png texture using resource.set_texture every frame.

I think i can use texture handler of created texture. But this texture handler have empty texture.
Looks like texture resource not updated when i change buffer.
But if i set this texture resource to another texture in resource.set_texture this another texture is updated.

1)So if i create texture in resource.create_texture. If i update buffer texture not changed? So how can i update this texture?

2)If i use resource.set_texture for data.png. Not i create new texture that will be used? So now i have 2 textures. One i created in resource.create_texture and second in data.png because i set texture?

I understand i need to call resource.set_texture if i change buffer)

I think i donโ€™t need to create texture but only use set_texure to data.png

Thanks)

1 Like

Need help with shadow)
Any ideas how to fix shadow jittering ?
Shadow map is 2048x2048
@jhonny.goransson

1 Like

I donโ€™t know how itโ€™s implemented :thinking: could it be a one frame lag from camera component?

I set all data for shadows in render script. So it use same as render view,projection.

I think it something with precision. If i set shadow projection size to lower values shadows worked better.
But i have no idea what to do with precision. Mb i need some filtering or something like that?

I see that some shadow shaders add random to uv, but i donโ€™t understand how it worked, and it not fixed jittering in my case(

Does it happen on desktop platforms or only web/mobile?

all platforms

I think i find problem. Looks like recalculating shadow area every frame can cause this problem((

1 Like

Fixed shadows. :partying_face:
Avoid recreate light matrix every frame:)
Now i create a bigger light_projection so i donโ€™t need to recalculate light matrix if user make small movement.
It is still possible to see shadow shimmering but now it is much harder)
Old


New

9 Likes

Refactor how lights cluster calculated in c++.
Now math worked a little bit slower but clusters border for lights more accurate and worked correct on all angles of view.

Because clusters more accurate in result it worked faster that previous version :partying_face:

7 Likes

In order to get this (master(d0d16a4)) to build (on Linux) I changed some ints to reals and one real to int. This was to fix errors. dmLogWarning in extension.cpp which has %f in it, which I guess I could of changed to %d maybe.
I still get: ERROR:xMath: Registered xmath Extension

However it does run.

Swapped to:

#define LIGHT_RADIUS_MAX 64 // store in r value of pixel. Mb store as rgba value for better precision?

#define LIGHT_MIN_POSITION_X -511.0
#define LIGHT_MAX_POSITION_X 512.0
#define LIGHT_MIN_POSITION_Y -511.0
#define LIGHT_MAX_POSITION_Y 512.0
#define LIGHT_MIN_POSITION_Z -511.0
#define LIGHT_MAX_POSITION_Z 512.0

(edit: in illumination/native/include/lights.h)

4 Likes

Thanks i will fix dmLog)


Fixed. Should worked in all platforms.

Now positions and radius is limited in some borders. In new year i will refactor that. I think it will be better to store decimal part in RGB and fraction part in A channels.

#define LIGHT_RADIUS_MAX 64.0 // store in r value of pixel. Mb store as rgba value for better precision?

#define LIGHT_MIN_POSITION_X -511
#define LIGHT_MAX_POSITION_X 512
#define LIGHT_MIN_POSITION_Y -511
#define LIGHT_MAX_POSITION_Y 512
#define LIGHT_MIN_POSITION_Z -511
#define LIGHT_MAX_POSITION_Z 512
6 Likes

Version 1.0.0 is ready :partying_face: :partying_face:
I think it is time to try it in real game:)

It worked in all platforms. Also worked in web and mobile web.

Fixed how lights position and radius encoded.

Position component[-131072.0f,131071.0f]
RGB - integer position 6bits per channel
A - fractional part

Radius[0,63]
One channel for integer part
One channel for fractional part

13 Likes