javiergcim / MakeUpUltraFast

High performance Minecraft shader (Java). For a graphical enhancement. Intended for low-spec computers.
GNU Lesser General Public License v3.0
105 stars 38 forks source link

Shadows are not cast by far away terrain #34

Closed ghost closed 2 years ago

ghost commented 2 years ago

Minecraft version: 1.19-Optifine_HD_U_H8 Shader version: MakeUp-UltraFast-8.6

Render distance: 16 Shadow distance: Medium Shadow quality: High

I noticed that shadows sometimes pop in and out as I move around, even though the objects that cast them are still within my render distance. This happens on all shadow quality and distance settings. Maybe the shadow clipping plane is too close to the player?

https://user-images.githubusercontent.com/39716203/180067028-2825f2dc-ea15-4b9d-9e52-0e3b6355e998.mp4

javiergcim commented 2 years ago

Why don't you increase the shadow distance in the options? Shadow quality does not affect distance, only the relative resolution of the shadow map.

The "problem" is not in the distance at which the shadow is drawn (the shadow can be drawn at any distance). The problem is how far away the objects that cast the shadow are from you.

I see you use volumetric light. The depth based godrays option is placed there to avoid the problem that occurs with very distant objects (because the volumetric light is calculated from the shadow map, and does not work well with short shadow distances).

I understand the problem of the shadows, but they are technical limitations that have to be accepted to obtain a fast shader. In the case that you present me, it cannot be "blurred", as happens when the sun is at the zenith.

The shadow distance is short because it is an excessively expensive effect, and is actually one of the reasons the shader is fast. You can increase the shadow distance in the options, but never too far, because that would be prohibitively expensive.

But I do consider your report for longer shadow distances in future versions.

ghost commented 2 years ago

Even on high shadow distance, the shadows still pop in and out at exactly the same place. In all of the 3d software I have used, shadow distance affects how far from the player shadows themselves can be seen, not how far the shadow casters can be. In those software, getting closer to a surface results in more accurate shadows on that surface. However, in this case, shadows are made worse by getting closer to them. The only reason I can think of for this behavior is that the clipping plane of the camera that produces the shadow map is closer to the player than some of the chunks that should be casting shadows (unless this shader uses a completely different way of rendering shadows than I am used to).

ghost commented 2 years ago

Using the debug mode, I see that the shadows are rendered differently than I am used to. It seems that on high shadow distance, the shadow map only renders a 5-chunk radius around the player. Most shadow maps I have seen use an orthographic projection from infinitely far away (by having no clipping plane), which would indeed not have this problem. I don't see why a camera at the player's render distance (with its zoom, not it's physical distance, dictated by the shadow distance) would be significantly worse for performance than the current 5-chunk distance.

javiergcim commented 2 years ago

If you see a shadow radius of 5 chunks, then you are using the shortest possible shadow in MakeUp. The default is 7 chunks, and the largest is 17 chunks. Check your settings.

I highly doubt infinite shadows exist. In a controlled environment, they may be equivalent to that, but in a dynamic environment like Minecraft, that's impossible.

Remember that you do not stop seeing the shadow because the surface where it is projected is far away (the shadow can be drawn at any distance), it is the object that generates the shadow that is far from you.

Also remember that the reason a large shadow makes such an impact on performance is because the entire scene is drawn twice: once in the shadow from the point of view of the light source, and once in the scene itself.

The shadow map only includes objects that are in a spherical volume around you, of a certain radius. The flaws of this solution are most noticeable at dawn or dusk, because there are many objects far away from you that can cast a shadow that you could see.

The problem with large radius is this: if you consider x elements, you probably have to consider x^3 (x cubed) elements when you double the radius of the shadow (because it's a volume). That is, the number of elements to consider/draw grows very fast.

As you can see for yourself, increasing the radius of the shadow impacts performance more than increasing the resolution of the shadow. The radius of the volume cubes the problem, the size of the shadow map only squares it.

You can see the shadow map if you go into the advanced options and activate the DEBUG mode.