This is a bit of a hack but it helps a lot -- for some reason the
background layer often has a sharp transition to the in-focus plane and
because we're calculating the DoF at 1/4 resolution these transitions
are quite visible. We work around this by fading out the transition over
a 1 CoC unit, specifically between a CoC of 2 to 1 pixel. Below 1 pixel,
we currently clamp to 0.
The sidecar buffer for multisampled_render_to_texture emulation was
stored with the texture, instead of the rendertarget, this prevented
a single texture to be used as an attachment of multiple render targets
with different sample counts.
There was an inconsistency in the gles backend where non-sampleable,
non-MS textures failed (assert) if they were used with a render target
with MS (i.e. "magic resolve" case).
We fix this by taking the same code path for textures and renderbuffers,
the only difference being the calls to glFrameBufferRenderbuffer
instead of glFramebufferTexture2D.
resources structures where not cleared when destroyed, and some code
relies in the handles being set or not to decide if a texture should
be used. in this case, the texture would be set in the shader after
it was destroyed, because its handle wasn't cleared.
- inScatteringSize actually cannot be set to zero because it produces
a 0^0 in the shader. So with this change, in-scattering must be
strictly > 0 to enable.
- inScatteringSize on the java side had an incorrect default value of
zero (which of course, now doesn't matter anymore).
- also clamp the fog altitude to 1mm which simplifies the shader quite
a bit for the same result.
Fixes#3069
.blurScale was in fact a scale factor applied to the circle of
confusion (which makes it indeed a "blur scale", but let's use
a more precise language here).
Update comments to show how to use .cocScale to control the DoF
effect independently from the camera aperture, which can be useful for
artistic reasons.
- simulate a standard deviation of 8 by skipping every other pixel
when blurring the AO buffer at LOW or MEDIuM quality. This creates
a faint checker pattern, but does look much better than the low
frequency noise that is introduced otherwise.
- tweak AO parameters to give a more uniform and smooth AO effect by
default. This also makes AO even more consistant between quality
modes.
- add a simple dithering stage to AO blur to help eliminate banding
artifacts at higher sample counts.
e.g. `F_PI` is also available as `d::PI` and `f::PI` as `double` or
`float` respectively.
Most of our uses of those constants are `float` and it was error prone
and cumbersome to have to cast to that each time we used them.
The `F_` constants are intended to mimic `math.h`, however these new
constants are not, and all the "n over" constants are named
`N_OVER_` instead of `N_`, which helps avoiding the confusion that e.g.:
`F_2_PI` is actually `2/pi` and not `2*pi`.
Also added `F_TAU` which is 2 * PI.
all parameters of the bilateral blur can now be set from the CPU,
instead of being hardcoded -- this probably prevent the shader compiler
from unrolling the filter, but it's also probably not a big deal.
additionally, we now use a kernel size of 23 (12 samples) when the
SSAO quality is set to HIGH or more.
ssaogen is no longer needed
Higher quality levels used to darken the ssao a lot, now they all have
a consistant look.
Add quality control to material sandbox.
Slightly simplify shader code.
We add noise do the radius of the samples on the spiral
(instead of adding noise only to the angle), this reduces a visible
"echo", especially at higher radii.
- don't use frameUniform.time as the temporal noise seed because
this has a cycle to it. It's not very visible on dithering but
obvious when used for other things.
- don't use fract(time) since time was already in [0,1] -- though it's
moot now.
- instead of time pass a random number in [0,1] generated on the CPU
each frame.
This will also allow to control temporal noise more easily if
needed in the future (e.g. for accessibility or rendering tests)
- fix a recent typo that affected SSAO quality
- add a upsampling quality checkbox in material_sandbox
- make use of textureLodOffset instead of texelFetch, so that
we emulate more closely textureGather
- don't hardcode bilateral filter edge-distance in the shader
(still hardcoded on the cpu side)
this broke recently with the reverse-z, the froxel calculation relies
on the depth, which is now inverted.
we actually fix our getNormalizedViewportCorrd() public API, which the
froxel code uses.
Because initializing the backend can be relatively slow, creating an
Engine can block the main thread, is this is a problem, this new API
can be used instead; while a bit more complex, it allow the engine to
be initialized asynchronously.
This significantly improve the depth-buffer resolution utilization
through the near-infinity range on Metal and Vulkan.
On OpenGL, this benefit is only seen when glClipControl is available.
The user-facing clip plane is unchanged [-1,1], the conversion
happens in filament's vertex shaders.
The bulk of this change consists in:
- invert the clip space's z in the vertex shader
- clear the depth buffer with 0
- invert all depth function comparisons
- fix all screen-space effects, e.g. ssao, DoF
- fix shadows and shadow biases
- use floating-point depth
- add a driver API to query which clip-space is used
- add glClipControl support to the gl backend
the depth buffer wasn't resolved in this case. We fix this by always
creating a depth buffer resolve pass -- which is a lot more robust.
this pass automatically culled if the depth is not used (i.e. TAA or
DoF are off). The pass is a no-op if resolving is not needed.
- don't apply SSAO to blended objects
these are not drawn into the structure buffer, so they don't
participate in SSAO.
- remove unused code that was needed for the depth prepass, which
simplifies handling of blended objects.
- always treat alpha-masked objects as opaque.
This also adds a -t flag to the easy build script for convenience.
SwiftShader on Vulkan can now be used as follows.
git clone https://github.com/google/swiftshader.git
cd swiftshader/build
cmake .. && make -j && export SWIFTSHADER_LD_LIBRARY_PATH=`pwd`
cd ../filament
./build.sh -t debug && ./out/cmake-debug/samples/gltf_viewer -a vulkan
Note that third_party/swiftshader does not need to exist since we
already have Vulkan headers. I will remove it in a subsequent PR.