* Use locale-independent string->float conversion
strtof and friends are locale aware and won't parse decimal numbers
with a period ("12.6" for instance) in locales that use another
character for the decimal period ("," in French for instance).
This change introduces a new function called strtof_c that forces
the use of a specific locale (called "C") to make sure we always
parse floats in the desired "C" format ("12.6").
With C++17 we should be able to use std::from_chars but this API
is not implemented in clang for floats at the moment.
* Fix Linux
A recent refactor was causing the following error when the vertex domain
was set to `device`:
```
ERROR: main.vs:23: 'material' : undeclared identifier
ERROR: main.vs:23: 'materialVertex' : no matching overloaded function found
```
We're currently only using the positive layer of EVSM which works
work small blurs and anti-aliasing. This just rearranges the code to
make it easy to test the full formulation.
This is possible because, in fact, we know if we're dealing with a
spot or directional light when we invoke shadow(). So a conditional
inside it is resolved at compile time.
This will allow more flexibility in the future. Also now the shadow()
function only needs the shadow index and cascade -- which is more
future proof (e.g. if we want to handle more than one directional
shadow or spot lights with cascades).
this effectively undoes a recent change, where we had a method for
spot lights and one for the directional light. instead, we can
calculate the bias at the correct Z on the caller side -- which is
needed only for spotlights.
The faulty commit was:
commit 23dab0a013
Author: Mathias Agopian <mathias@google.com>
Date: Fri Oct 29 12:03:14 2021 -0700
Fix very narrow spotlight lighting and other minor issues
Shadow Receiver Plane Depth Bias is only needed when using large PCF
filters, which we are no longer doing. Large filter kernels are now
supported through VSM sampling.
This changes how we select the "optimized depth vertex shader", but
this shouldn't change the current behavior.
We now select the "optimized depth vertex shader" if and only if the
user code is empty. In that case, we can safely assume we can remove
all the code that's not necessary for the depth, since it is all
controlled by filament.
- remove PCF "low" quality, we only use "HARD" now, when using PCF.
Higher quality levels are achieved by using VSM.
- added a version of PCF that doesn't use a shadowSampler for future
use.
The normal bias is now computed correctly, this requires to compute
the z in lightspace in the shader.
Note that this would not work as well if we used LISPSM, but we'll
cross that bridge when we get there.
- constant bias and normal bias default values in java didn't match
C++ or the documentation
- stable shadows were enabled by default in java
- polygon offset biases were missing from the java API
- document and don't apply polygon offset to VSM
- remove unused code
We now cull the shadow casters before computing the near/far plane
for spotlights -- we can do that because we know the light's frustum.
So only these casters that contribute to the shadow are accounted for
when calculating the near/far plane.
This PR also include more cleanup and simplifications.
Near/far plane is now computed dynamically, this significantly
improves the shadowmap depth resolution.
Quite a bit of refactoring was necessary to get all the right data
in the right place, in particular SceneInfo is now passed around for
both directional and spot shadows.
The froxel code was failing when a spotlight cone was too narrow. This
is fixed here by never using a cone smaller than 0.5 degrees during
forxelization.
Additionally we now silently clamp the cone angles to 0.5 degrees at
the API level because, the falloff was also failing due to floating
point precision in the shader.
Finally, we clamp the inner cone upper value to the outer cone's
instead of the other way around. i.e. the outer cone defines the
spotlight while the inner cone just controls the falloff.
When calculating the linear depth for VSM, we were using the whole
range between 0 and the far plane, the near plane wasn't taken into
account.
This can be a problem is the light is very far, but it's near plane is
closer to the camera/scene, in this case the depth precision wasn't
used optimally.
Note that we don't hit this problem currently, because the directional
light is constructed such that its origin is at the near plane, and the
spotlights have a fixed near plane (which is a problem and will be
fixed at a later time).
The bug that prevented them to work has been worked around, but we
don't know when or how. The original bug still exists as demonstrated
by our standalone test apk.
For now, we reenable MSAA VSM on Adreno.