We no longer use the hardcoded objectUniform UBO name, instead, we
access the object uniforms through the new getObjectUniforms().
Because it's not possible to return a "Uniform Block" from a function
in GLSL, a large part of this change, is to replace the interface block
by a structure.
Note: getObjectUniforms() is not public, but it is used by gltfio to
access the userData field, which is also not public at the moment.
This boolean parameter is used with materials that need to access
`getInstanceIndex()` (filament's equivalent to `gl_InstanceIndex`).
It is false by default, and getInstanceIndex() is not accessible.
This is intended to be used in concert with
`RenderableManager::Builder::instances()`.
Our `morphNormal` GLSL function treats each normal target as a
displacement from the base normal (similar to the glTF spec) but the
normal that is extracted from the tangent frame is actually an absolute
normal.
In other words, if b is the base normal, we were doing:
b = b + w0 * n0 + w1 * n1 + ...
This is obviously wrong, since the base normal has an overpowering
influence.
The fixed math looks like this:
b = b + w0 * (n0 - b) + w1 * (n1 - b) + ...
Fixes#5584.
The most important change here is that we no longer apply the
backend (e.g. Metal/Vulkan) UV transformation before calling the
user's vertex shader. This is an API change for post-process materials
(but they're not public).
Now the user is responsible for using uvToRenderTargetUV() in their
shaders (either in the fragment or vertex as appropriate).
This makes it easier to handle offsets/transforms with all APIs.
Conceptually, the only thing that is needed is to call
uvToRenderTargetUV() just before making a texture call.
This fixes a couple of issues:
- some image shifting in metal/vk
- flare in metal/vk was upside down
We also simplify the DoF code quite a bit now that we can rely on the
rendertargets begin multiple of 16.
We also "fix" SSAO that was working by accident on metal/vk. The UV
correction was applied 3 times 2 of which were canceling each other.
- rename common_math and common_shadowing from .fs to .glsl
because they were both included in both vertex and fragment
shaders
- add getFragCoord() which always returns coordinates in the
glsl convention. This is useful when used with RNGs to get
consistant results accross backends.
this is because this uniform is not well defined -- it's unclear if
it is set to the viewport or the buffer size.
also, it's not needed, and removes a couple multiplies from the shader.
it made it actually more confusing to have two version of the uv
(normalized and not). Also the unnormalized version was computed from
frameUniforms which is not great in the case of post-processing
(it just happened to work).
With this change we are now generating refraction and reflections
buffer into their own layer of a 2D array -- so they can coexist.
This change doesn't actually enable both at the same time yet.
There are downsides to this approach:
- a 2d array of 2 layers is created even if only one of reflection or
refraction is active. This could be fixed at the cost of more
complexity.
- if reflections are active then refraction must use a RGBA16F texture
instead of RGB_11_11_10, because they share the texture
The existing behavior was surprising for users who draw opaque objects
into a semitransparent views, and this was especially evident with
the labels in `TextureLinearInterpolationTest`.
We now disable blending for MASKED, which is what our existing materials
documentation already says. We also now set the fragment alpha to 1 when
the fragment is not discarded, which prevents the "punch through"
effect. This is consistent with ThreeJS.
Fixes#4576.
We now have a single varyings.glsl containing our varyings for both
the vertex and fragment shader. This file is included with the right
definition of VARYING as `in` or `out`.
inputs.vs is now renamed attributes.vs
We can now specify an "instance count" per renderable during creation.
This instance count applies to all render primitives in the
Renderable.
This will simply draw the renderable "instance count" times. A new
method available to vertex shaders, getInstanceIndex(), allows the
material to discriminate the instances and adjust the position/transform
accordingly.
Typically this is used for particle systems.
The main change here is that for screen-space reflections, the lod
calculation takes the camera distance into account.
We also now correctly take into account that we blur each lod
successively which increases the standard deviation by 10%. This applies
to both refraction and reflection.
This works by first generating a reflection buffer which gets blurred,
then the color pass samples from this buffer according to the roughness
of the surface being rendered.
A lot of the changes here involve utilizing "reserved" variants for
the new "SSR" pass and all the fallout from that.
- Rename projectToPixelMatrix to uvFromViewMatrix, this match our
existing style better.
- slightly more efficient direction transform
- limit roughness to 0.1 instead of 0.01, because in a lot of cases,
the roughness increases with the LOD, for instance if it comes from
a texture (to combat aliasing).
- Make sure to disabled SSR when it's... disabled.
- Fade the reflection when the ray direction is towards de camera,
where it will likely hit a back face
- Simplify the fading code, for near identical results.
Support legacy morphing (morphing with targets supplied via VertexAttributes) for older clients. This gives clients more time to transition over to the new MorphTargetBuffer API.
screen-space reflections are integrated in the indirect light computation
(similarly to screen-space refraction), this is because it can be seen as
the specular term of screen-space GI.
However, because this effect is screen-space, the data it accesses has
the ibl luminance (and exposure) applied.
Besides some minor refactoring, this change just applies the
screen-space reflections *after* the ibl's specular term is exposed.
We can now do screen-space refraction and reflections at the same time.
This change mostly removes the checks that were preventing it from
working.
The real change in the PR is to adjust the reprojection matrix based
on whether the SSR buffer (both for refractions and reflections) comes
from this or the previous frame.
The same can be achieved with VSM + blur=3 however, this is noticeably
slower. Also when using transparent shadows, VSM needs a much larger
blur to iron out the dithering pattern.
Fixes#5048, #5039
it was incorrect to store bone matrices as quaternions because it is
allowed for these matrices to have a skew component.
We now store the 4x4 matrix -- which is the same amount of data as
before, however we compute the cofactor matrix in the vertex shader when
transforming normals.
fixes#4887
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).