Simple shadow mapping example

That artifact is called “shadow acne”, try tweaking the bias value in the shadow shader, or as ivan says dont render it to the shadow map.

Thanks people!

I’ve been able to remove most of the acne by tweaking the bias and also by making sure all the model surfaces have “flat shading” set in Blender (this made a big difference).

How would I remove the road surface from the shadow map? Wouldn’t that also remove the shadow from the car?

You can set a special material for road and create a predicate (in render script) for it.

1 Like

Oh I see. Yeah, that would work, thanks!

Edit: Sorry, I’m still not with you. :thinking: The road surface is the only model that needs to receive shadows, so it can show the shadow of the car.

To be able to receive shadows from the car, doesn’t that mean it also automatically receives shadows from itself?

Mesh will receive shadow from shadow map, if there is no road in shadow map - it will receive shadows only from other meshes, right?
You don’t need road in shadow map, but you need to apply shadow map while rendering road model.

3 Likes

Yes, that makes sense. Really neat. I’m going to test this and report back.

Edit: It works really well! For some reason the shadows were inverted, so the numbers had to be tweaked, but really happy with the result.

Update: @Pkeod Asked if I could share this, and I think that’s a good idea. Maybe someone can help improve it. One thing I haven’t been able to figure out is how to cast the shadow on the walls.

Here is a minimal project with just the car , the track and the shadow stuff:
Shadow test.zip (130.4 KB)

12 Likes

That looks great! Glad to see this example is of use to someone :slight_smile:

3 Likes

Wow! Awesome!

3 Likes

The example above has been updated with a minimal example, in case someone wants to quickly try it out for themselves.

8 Likes

Where? :slight_smile:

Here!

2 Likes

how i can add my custom camera or implement in my render script?

1 Like

I really appreciate for all of your examples :heart: . I actually didn’t realize that I will have drop shadows on this iteration.

10 Likes

One beautiful sunny afternoon I was about to make shadows for my prototype. But something went wrong.

As you can see, everything works on PC.
But on a mobile phone it doesn’t.
I’ve done some research to find out WHY exactly it doesn’t work on a mobile phone.
And at the moment it has reached a dead end.

Here are some screenshots - one for PC, one for mobile. In these, I’ve displayed the contents of the shadow texture on the sprite on the right-hand side of the screen.
In addition, I’ve also displayed the content of the shadow texture also on top of the 3D objects, so that you can see how it’s projected.

What do we see?
That on the PC the shadow texture matches its content.
But on a mobile, it doesn’t.

Naturally, the build shows no errors.
Look at the project itself - you may find the reason. My experience is not enough to solve it myself.
__SHADOW_TEST.zip (8.3 MB)

6 Likes

I’m guessing you’re using an Android phone?
What if you use Android Studio to debug your graphics, perhaps it can reveal something interesting?
Also, do you get anything relevant in the adb logs on the device?

How large is the texture?

Yes, android - Samsung Galaxy Note 10.
Texture size 4K * 4K, R32F format.
The shadow depth texture is rendered correctly. The problem is that it doesn’t read correctly.
There is nothing in the adb logs.

1 Like

I’ve done a number of experiments with float render-target with different formats.
Here’s a screenshot from a mobile phone:

Unfortunately, this is the situation I have at the moment:

  1. My build crashes when using ANY format other than R32F with error: ERROR:GRAPHICS: OpenGLSetTexture(2579): gl error 1280
  2. R32F format works very strangely - there are no errors, but only if it is set to zero sampler (render.enable_texture(0, self.shadow_buffer).

What to do, who is to blame?

6 Likes

Thanks. We need to gather all of this into a GitHub issue and look into it more closely. @jhonny.goransson is currently on vacation and I think it’s best to wait until he is back. @morgerion could you please create a ticket?

6 Likes
7 Likes

So if it renders correctly but samples incorrectly I’d probably start debugging by using highp everywhere in the shaders. I don’t have an android with me so I can’t do anything more than guess right now :frowning: