So I have just tried out going from Godot 4.4 to 4.5 and ran into two big issues during the migration. The first was related to a plugin I was using and I’ve since resolved it. The other however, I am at a loss as to how to solve and I’m not even sure it’s a bug given considerable changes were made to how reflections work between 4.4 and 4.5.
Basically, a key issue I was running into at first when trying to get HDR sky backgrounds working is that the sky wasn’t contributing any shadow casting to the world and never would since due to the nature of what I’m making, baking the lighting is not an option.
So, to account for this, I added a DirectionalLight3D to match the sun’s position in the sky and that gave me the shadows I wanted, but now the sun was showing up INSIDE the shadows as a specular effect because I have ReflectionProbes in the scene. The way to work around this was to change the Reflected Light setting inside the Environment resource to Disabled and now I was able to attenuate the ambient light as desired and no longer had the sun showing up in shadows!
But… upon migrating to 4.5, this trick no longer gets rid of the specular sun effect, and after HOURS of trying things I pretty much have to give up and go back to 4.4 now. I cannot find any way to get the sun out of my shadows, I can’t get rid of the directional light casting the shadows otherwise there would be no shadows at all, and I can’t bake the lighting because the world itself is far too dynamic and user-editable.
Does anyone have any ideas what I might be able to try to get that sun from the sky out of my shadows? Or is it possible I have run into a bug introduced with all of the reflection changes made between 4.4 and 4.5?
Unfortunately, the new Specular Occlusion features do not help in this case. They rely on Ambient Occlusion which I cannot bake in due to how dynamic the world is and SSAO doesn’t affect the specular component of the sun in the background at all unless I crank it up so high it just turns every shadow into a black void.
I recommend logging a bug on their GitHub Issues Page then and see what the team says. They will either tell you it’s not a bug and fix it, or they will fix the issue for you.
Actually… hang on a moment… I was reloading my backup in 4.4.1 just now and noticed the problem is still there too…???
…did I really just spend the entire 4.4 branch completely oblivious to this? It would’ve been back in 4.2 or 4.3 when I first came up with my solution to the sun in the shadows issue.
Well… I mean I can’t be the only person who’s run into these kinds of issues, trying to combine an HDR background with a scene only for extra-bright things to bleed into shadowed areas as a specular highlight. Does anyone have any advice on the proper way of getting around this sort of thing, or am I doomed to have the sun in my shadows without baking?
AFAIK the ‘proper’ way to do this is to write a shader that checks by casting a ray from the fragment to the light source then uses that ray to read from the shadow buffer.
So the shadow buffer is aligned perfectly to a shadow camera near plane at the light source - with directional lights this is a very large near plane as the projection is orthogonal.
you just need to check whether distance between the fragment and the light is greater than the distance stored in the shadow buffer.
So then its best to grab an example code that samples the shadow buffer.
AFAIK Godot does not make the shadow buffer accessible.
You could try a view space technique rendering a simplified version of the scene (literally black and white values for whether its a shadow or not, perhaps even low res), to a viewport containing an offscreen buffer, then just get the screen space fragment position and multiply by the specular.
I just ran a test and I’m not getting the same problem. This screen shot is in Godot 4.4 with a default material with roughness set to a low value. The light is just a directional light with directional shadows set to PSSM 4 splits.
If the scene was created in godot 4.3 then maybe some settings were copied over. If you try recreating the scene by importing all the assets again maybe that will fix it.
So, the problem is primarily that the background I’m using here has a pretty intense sun in it at HDR levels, the centre of which is about 40 times brighter than maximum white at standard levels based on some work I was doing with the image between my posting this thread and now. I’m pretty sure in an earlier version of Godot 4 I was able to prevent the sun from being reflected but somewhere along the line those settings didn’t do the same job anymore, but I can’t port my project back to an older version of Godot, nor would I want to given the improvements which have followed.
However, in learning to do HDR image manipulation, I was able to manually dial down the intensity of the sun in the background by clamping to a value higher than standard range but ten times lower than the original image’s sun strength, thus making it only 4x brighter. In combination with the new Specular Occlusion feature (which I found does indeed work with AO disabled, again my background’s sun was way too bright to notice) there’s STILL a sun in my shadows, but it’s so little now I can live with it. :B
I would expect the light from HDR environment textures would also be accumulated in the lighting pass and would therefore be clipped by the shadow section of the shader. So there may be a project setting or something about the mesh - i.e. the direction of the mesh normals for example. I can’t quite find the solution however I’ve definitely noticed this before on other scenes and one of them definitely had the floor as separate object (to lower the polygon count over multiple rooms).
Yes, it does. Removing the shadow mesh from the Mesh resource of the MeshInstance3D nodes makes no difference.
Note too that ALL of the flat surfaces in my screenshots are all using the same Mesh resource. Removing the shadow mesh from one effectively removes it from every surface. I also made sure to check this with the directional light for the scene both enabled and disabled.
Reason i wanted to check that is because I found the same issue with the specular light on the terrain in one of my test maps (the terrain has no shadow mesh in the UI) … the terrain is scaled using the node transform and not the internal transform. I didnt notice the problem on unscaled versions, although im not 100% sure.
Maybe it has settings from 4.3 … also there is an HDRI sky so perhaps that is the problem.
Also it was only self shadowing on the terrain that exhibited the problem - other meshes like buildings seem to block the specular … at least within voxel GI zones
So maybe its an underlying problem that manifests / haunts when things are not scaled right or HDR exposure is beyond a clip range . Undefined lighting behaviour perhaps
Well, I at least have it under control to an acceptable point without giving up having an HDRI for the sky.
What would be nice though, given that I still have to configure lighting nodes on top of having the sky defined, which themselves generate specular light, would be if we could have separate images defined for the Sky Box and Sky Reflections. An HDRI Sky Box with a separate non-HDRI for Sky Reflections would be one way to solve this, but that’s presently not an option and may be too niche of a feature to see implemented in the future.
You are probably right. I think the problem wont get solved unless theres a repeatable use-case, i.e. an example project. Im not quite understanding the essential reason why HDRI’s could cause the problem - other than that perhaps its flagged as a reflection calculation that should be mostly diffuse and ambient environmental lighting contribution (therefore not usually needing shadows). And then theres a huge back log of issues anyway.
The environmental lighting rays are from hemispherical directions and unfortunately accounting for the occlusion would typically involve rendering the entire scene to a cube map relection probe - there might be some overlapping light from the highly emissive pixels.