Commit Graph

364 Commits

Author SHA1 Message Date
Benjamin Doherty
4ead3bcebf Force spirv-cross to keep Metal argument buffer equal sized 2022-10-25 12:07:24 -04:00
Ben Doherty
107b5a4854 Metal: fix microshadowing artifacts (#6221) 2022-10-24 19:12:14 -04:00
Mathias Agopian
acd5823953 Add support for point light shadows
[experimental]
2022-10-10 13:03:36 -07:00
Mathias Agopian
5aa414dd24 support for ELVSM and 32 bits xVSM
This basically adds two settings:
- highPrecision at the View level, which controls the bit depth
  of the vsm shadow texture used. This affects all shadowmaps.
- elvsm per shadowmap, which enables Exponential Layered VSM.

the main change in the shaders is that we now always output the 
"negative" EVSM, even when it's not enabled. If no shadowmap uses
ELVSM, then the texture is stil an RG texture and the calculation is
lost (with some luck culled by the shader compiler), either way it's
not a lot of math and it's done only once per shadow texel.

During the color pass, on the other hand, we compute the "negative"
EVSM only if enabled.
2022-09-30 12:04:27 -07:00
Mathias Agopian
1e51b03971 fix VSM 2nd moment calculation
the linear approximation only works with a linear depth, it fails
with our warped depth.
2022-09-30 12:04:27 -07:00
Mathias Agopian
fabba73b1e Initial support for compute
* minimal backend support for compute
- added api to dispatch a compute shader
- added api to create and bind a ssbo
- added api to read back a buffer
Only implemented in the gl backend

* Add a backend compute test suite
* basic support for compute shaders in matc
this is still very much work-in-progress.
We're not supporting images nor ssbo for now.

* rename UniformInterfaceBlock to BufferInterfaceBlock
* augment BufferInterfaceBlock to support ssbo features
- add support for std430
- add support for ssbo
- add support for variable-size array
- add support for memory qualifiers

* reformat MaterialBuilder
* material format: move subpasses outside of parameters
subpasses now are their own json property instead of being a
"parameter".

* refactor parameter() methods to match Buffer/SamplerInterfaceBlock
We're just shuffling the arguments.

* add support for buffers in .mat files
* filamat now generates buffer blocks (ssbo)
* take feature level into consideration when optimizing shaders
* don't store the 'uniform binding' chunk for level 2 materials
this includes some refactoring/cleanups of MaterialParser

* matinfo: fixes for compute
- separate subpasses from parameters
- don't attempt to print material properties
2022-09-27 15:52:40 -07:00
Mathias Agopian
2073a9f3e5 cleanup Froxelizer comments
also fix typos, formatting.
2022-08-30 20:31:47 -07:00
Mathias Agopian
be12049a87 The default arena sizes in the makefile didn't match the code
Also added some ascii art to explain better how the various arenas are
used.
2022-08-30 16:48:30 -07:00
Mathias Agopian
a7a55c7617 Specification constants support (#6001)
* Add support for specialization constants

* remove WebGL instancing count hack

use a specification constant instead

* update release notes
2022-08-29 09:38:23 -07:00
Johnathon Selstad
1e3ddd612e Organize Subprojects into Folders in the IDE (#5934)
* Begin Sorting SubProjects into Folders

* Add more subprojects to folders

* Add even more subprojects to folders

* Add further subprojects to folders

* Move the last two projects

* Move Resources to a Resources subfolder

* Remove spaces to be stylistically coherent

* Revert Improper CMake Modifications

* Revert erroneous line removals

* Only specify sdl2's folder on WIN32

* Add the shader subprojects to a Generated folder

* Move shaders to Filament/Shaders
2022-08-17 12:42:21 -07:00
Mathias Agopian
c6502054e9 Fix guard bands and TAA with VERTEX_DOMAIN_DEVICE
With VERTEX_DOMAIN_DEVICE the vertex shader doesn't apply the 
projection (since the vertices are already in clip space), however,
both TAA and guard bands need to jitter/offset the clip space, and
it is done at the projection level.

We now store the clip space offset separately so that it can be applied
to VERTEX_DOMAIN_DEVICE vertices.

We also introduce a new material parameter, vertexDomainDeviceJittered,
a boolean that controls whether clip space offset (above) is applied.
This is because a VERTEX_DOMAIN_DEVICE material that uses the built-in
projection matrices generally ends-up with the jitter already applied,
this is the case with the Skybox for instance.

Fixes #5917
2022-08-16 15:32:33 -07:00
Mathias Agopian
6f9d69e410 skip clear coat if material.clearCoat is null
This allows a material to have clear coat turned on/off dynamically
without paying too much of a price.
2022-08-01 10:22:03 -07:00
Mathias Agopian
e0eaaf4fb9 skip SSAO texture read if SSAO is disabled 2022-08-01 09:49:47 -07:00
Mathias Agopian
6bc0e032fc Access the object uniforms relative to gl_InstanceIndex 2022-07-06 15:51:41 -07:00
Mathias Agopian
ad731aebcb fix getInstanceIndex()
it would be initialized after user material code was called.
2022-06-14 12:01:23 -07:00
Mathias Agopian
803ce07701 Always access object uniforms via getObjectUniforms()
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.
2022-06-10 09:13:18 -07:00
Mathias Agopian
9f8af21ad7 fix typo 2022-06-08 17:26:04 -07:00
Mathias Agopian
61e117beaa Added a new instanced material parameter
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()`.
2022-06-08 17:10:38 -07:00
Philip Rideout
fcbc6d43a1 Fix morphed normals.
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.
2022-05-24 15:03:30 -07:00
Mathias Agopian
60a6d4a348 pack PerRenderableUib a bit more so it occupy 128 bytes
We pack PerRenderableUib so that we could (in the future) store two
renderable datum per slot (each slot is required to be 256 bytes).
2022-05-24 10:16:16 -07:00
daemyung jang
c8cc74e384 Fix not calculating the normal while morphing in the legacy path 2022-05-23 16:00:57 -07:00
Mathias Agopian
2709533fb1 Fix texture coordinate calculations in post-process materials
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.
2022-05-12 13:42:13 -07:00
Mathias Agopian
ce7dd7a1fb reorganize again our main UBO
- try to sort data by usage.
- clarify what post-process materials have access to (not enforced yet)
2022-04-28 10:13:20 -07:00
Mathias Agopian
4ef0b72773 rearrange the per-view UBO (breaks materials)
- 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.
2022-04-27 15:27:47 -07:00
Mathias Agopian
4f137ccf89 don't rely on frameUniform.resolution for froxelization
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.
2022-04-27 09:38:33 -07:00
Mathias Agopian
3cdf24f515 remove getUV() from post-process materials
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).
2022-04-26 11:30:35 -07:00
Mathias Agopian
e188a7875e enable both screen-space refraction and reflection
Both "SSR" can now be used on the same material. This is made possible
by using a 2D array to store both buffers.
2022-04-01 16:22:10 -07:00
Mathias Agopian
edb5fddd03 one more step towards reflection+refraction support
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
2022-04-01 14:37:40 -07:00
Mathias Agopian
8b79f3683e skip work when morphtarget weight is zero
fixes #5344
2022-03-22 22:21:41 -07:00
Mathias Agopian
a40ee77326 minor cleanups 2022-03-21 10:46:55 -07:00
Mathias Agopian
85135e60c7 Switch SSR texture to 2D array
At this point there is no benefit from doing this, but we'll need this
in a later PR.
2022-03-21 10:46:55 -07:00
Philip Rideout
6da46b3b62 Repair A2C for opaque views, add field to FrameUniforms. 2022-03-17 10:01:27 -07:00
Philip Rideout
e8d8080928 New behavior for BlendingMode::MASKED.
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.
2022-03-17 10:01:27 -07:00
Mathias Agopian
3eb2a20c7f fix point light lighting with ortho projection
The froxel parameter for the Z slice were not correct.

Fixes #5318
2022-03-15 21:19:25 -07:00
Mathias Agopian
e9718fa346 cleanup attributes/varyings generation
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
2022-03-10 16:20:18 -08:00
Mathias Agopian
1d6aeb5de1 Add basic support for instanced renderables
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.
2022-02-15 13:11:23 -08:00
Mathias Agopian
df6a100fcb Improve how we compute the lod from the roughness
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.
2022-02-13 22:53:47 -08:00
Mathias Agopian
3f6188edff Enable rough reflections
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.
2022-02-13 22:53:47 -08:00
Mathias Agopian
cde055e5bf Minor cleanups
- 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).
2022-02-03 14:54:03 -08:00
Ben Doherty
d9cbe60ca6 Fix NaN values encountered with SSR and Metal (#5156) 2022-02-03 13:24:43 -08:00
Mathias Agopian
7b03cb9b76 A few screen space reflections improvements
- 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.
2022-02-02 09:36:20 -08:00
Mathias Agopian
73e339b05d be more consistant with defines names in shaders
all defines coming from material parameters are named `MATERIAL_HAS_...` 
and all defines coming from the variant are named `VARIANT_HAS_...`
2022-01-31 22:53:48 -08:00
daemyung jang
5a3853a442 Optimize memory of MorphTargetBuffer (#5046)
* Optimize memory of MorphTargetBuffer

Co-authored-by: Mathias Agopian <mathias@google.com>
2022-01-27 21:19:13 -08:00
Mathias Agopian
70e14a1757 try to workaround optimizer/compiler bugs
Fixes #5088
2022-01-27 19:24:11 -08:00
Ben Doherty
4c4a93d9b5 Support legacy morphing (#5129)
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.
2022-01-27 16:16:53 -08:00
Mathias Agopian
4060b558c7 Minor optimizations and documentation cleanup
- Document that both positions and tangents must be provided.
- Don't memset buffer before filling it
- Don't read 4 identical weights in shader
2022-01-25 17:16:43 -08:00
Mathias Agopian
3de427b74f Fix integration of screen-space reflections with lighting
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.
2022-01-19 17:10:10 -08:00
Mathias Agopian
15899af7cf randomly jitter the ray with screen-space reflections
this helps a lot when stride is > 1
2022-01-19 17:09:54 -08:00
Mathias Agopian
5417d0953b Allow screen space refraction and reflection together
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.
2022-01-19 13:30:12 -08:00
Mathias Agopian
8d1402d37b Bring back the 3x3 filter for PCF shadows
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
2022-01-14 15:08:46 -08:00