492 Commits

Author SHA1 Message Date
Ben Doherty
fa987f225d Add missing output precision to custom surface output (#9923) 2026-04-22 13:21:10 -04:00
Ben Doherty
533294de9a Add support for custom outputs for unlit surface materials (#9912) 2026-04-20 11:46:21 -04:00
Mathias Agopian
8ec732dadc FL0 materials are always compile via spirv-cross 2026-04-13 20:53:35 -07:00
Mathias Agopian
57faae4645 postfx materials now support sRGB emulation in FL0 (#9866)
FIXES=[498317018]
2026-04-02 09:08:50 -07:00
Mathias Agopian
6416cf1eaa remove sampleDepth(), inline the code instead. (#9806)
This hides less what actually happens, and allows us to save
a few calls to saturate().
2026-03-20 16:56:55 -07:00
Mathias Agopian
6f0d47f275 EVSM improvements (#9758)
- refactoring/clecanup to make some changes easier
- VSM mipmap generation was mistakenly disable when blur radius was 0
- analytic variance was disabled because the math only worked for VSM. Fixed the math.
- better handling of large blurs when using fp32
- implement EVSM equivalent of receiver plane normal bias
- use correct EVSM clearing color
- mipmapping with point lights works much better (no seams)
- min variance is computed automatically
- custom high precision mipmaping shader for VSM
2026-03-02 16:46:07 -08:00
Mathias Agopian
81c71fbbb9 Improve shadow normal bias calculation (#9734)
The previous code used the max of the texel's width or height footprint
in world space to compute the offset; this could both overestimate or
underestimate the bias causing some peter panning or acne.

The new code replaces a sqrt with a dot, but is otherwise similar.
2026-02-25 12:16:13 -08:00
Patrick Ribas
a90019baa2 Remove nonlinear fog from FL0 (#9658)
* Remove fog and lighting uniforms from FL0

---------

Co-authored-by: Mathias Agopian <mathias@google.com>
2026-02-05 12:51:37 -08:00
Mathias Agopian
2f36ab71c9 wip: fog for opaques in applied as a post-process effect (#9645)
Instead of computing the fog "inline", in the forward pass, we can
instead compute it as post-process pass that is applied with a
simple fullscreen quad blending.  On tilers, the operation entirely
stays in the tile, on desktop GPU it is a blending operation.

This works only for opaque materials.

The benefit is that fog will become immune to overdraw, and the forward
pass shader will be simplified, hopefully leading to less register
pressure. Overall performance should be improved.

Another benefit is that it will allow us to free the "fog" texture
slot from all opaque materials.

Transparent materials are unchanged.

This feature is currently DISABLED, and still work in progress; but it
should be mostly functional.

To test it:

```
env material.enable_fog_as_postprocess=true ./out/samples/gltf_viewer
```

This change refactor the fog code, but shouldn't have any impact on the
current behavior.
2026-01-30 12:57:25 -08:00
Patrick Ribas
4abf7cdaba Move eye matrix array to FL1 (#9656) 2026-01-29 08:54:14 -08:00
Patrick Ribas
5c15d56cf5 Remove PerRenderableData::reserved from FL0 (#9657) 2026-01-28 23:32:42 -08:00
Doris Wu
21fd32266a Add support for custom morphing (#9550)
BUGS=[443321184]
2026-01-21 17:11:35 +08:00
Mathias Agopian
496a50bc89 make getWorldFromModelMatrix() accessible in fragment shader (#9584)
this requires to specify `apiLevel: 2` in the material.

FIXES=[474353927]
2026-01-12 09:32:23 -08:00
Mathias Agopian
ad2c291d4a dispersion in XYZ space (#9572)
- spectral reconstructions with 4 samples
- unroll the whole dispersion computation to improve performance
  (batch texture fetches and reuse common values)
- tool to generate the matrices for spectral integration
2026-01-06 16:58:56 -08:00
Mathias Agopian
5661365248 improved the dispersion computation (#9544)
- Split the function so that the 3-components loop is more apparent.
- Factored out the parts of the computation that don't depend on the
index of refraction, so they're only computed once.
- Moved the lod-from-roughness computation out of the loop as well. 
  It does depend on the IOR, but so little that it's not worth it.

The most important result of this change is that the code is now in
good shape if we wanted to change the implementation of dispersion for
these cases (for e.g.) :
- do the computation in the XYZ space
- use more than 3 wavelengths samples
- or use a stochastic approach, trading banding for noise

RDIFF_BRANCH=ma/better-dispersion
2026-01-05 20:27:34 -08:00
Nemi
f701c1e1b5 Implement KHR_materials_dispersion (#9471)
This change adds support for the KHR_materials_dispersion glTF extension, which introduces a dispersion property for refractive materials.

The dispersion property controls the angular separation of colors transmitting through a refractive object, allowing for more realistic rendering of materials like glass and diamonds.

  Changes include:
   - Added a dispersion property to the material definition.
   - Updated the shaders to incorporate the dispersion effect in the refraction calculations.
   - Added a new test case for dispersion.
   - Updated the material documentation to include the new dispersion property.
2025-12-12 13:55:25 -08:00
Sungun Park
2d556bdca2 Workaround for screen space reflections artifacts fix (#9444)
This is a workaround for Samsung Galaxy S24 device failing to link this change.
ea608d409e
2025-11-19 19:03:00 +00:00
Powei Feng
778cbe09d1 build: allow building tools separately (#9384)
Building tools separately is necessary for the existing
cross-complation usecase.  We generalize this by introducing
two cmake vars that enable exporting and importing
prebuilt tools.

The intended usecase is to enable ASAN-built filament without
having to run ASAN-built matc (which is prohibitively slow).

build.sh has been modified to add a `-y` flag forprebuilding
tools.
2025-10-31 22:23:15 +00:00
Mathias Agopian
ea608d409e fix artifacts with screen space reflections (#9380)
on mobile h/w, strong highlights generated by the lighting stages can
turn into +inf and eventually to NaN if more math is performed on them.
Some h/w will kill a while tile or even primitive when that happens,
resulting in strong visual artifacts.

We fix this by clamping to MEDIUMP_FLT_MAX.
2025-10-29 17:00:49 -07:00
Mathias Agopian
4ad619439a use RG32UI for picking instead of RG32F (#8917)
The reason for this is that according to the GLES 3.0 spec, RG32UI is 
guaranteed to be supported for writing, unlike RG32F.

We also use RGBA_INTEGER / UINT for readPixels() which is also a
guaranteed format.

Attempt to Fix #8762
2025-09-23 16:20:57 -07:00
Sungun Park
b31a42a1d0 Improve getEyeFromViewMatrix() (#9184)
Make the size of PerViewUib 2KiB again.

Add overloading functions for getEyeFromViewMatrix() and
getClipFromWorldMatrix().

BUGS=[441127971]
2025-09-04 18:58:14 +00:00
Sungun Park
b0f8e1be7a Add getEyeFromViewMatrix() for vertex shader (#9175)
This new method, intended for the vertex shader, returns a matrix that
transforms vertices from view space (also known as head space) to the
current eye space.

BUGS=[441127971]
2025-09-03 18:05:34 +00:00
Mathias Agopian
cea178a40c froxel vizualization can now be turned on/off per view
Before this change once the froxel vizualizaition was enabled via
the Engine debug framework, it applied to all views. This adds a
debug API on View to control whether the view will display this
vizualization.
2025-08-22 15:55:46 -07:00
Mathias Agopian
3650556de4 make sure PixelParams::thickness is initialized
If screen-space refraction was used enabled but the thickness
parameter wasn't explicitly set in the material, it would end-up
being uninitialized. Now it's initialized to 0.5 by default,
which is the value used for subsurface.

Also removed some calculations dependent on thickness being set, as
they assumed a thickness of 0.
2025-08-21 20:25:01 -07:00
Mathias Agopian
bbf0754183 add a material parameter to control shadow far attenuation
FIXES=[436680157]
2025-08-13 20:22:45 -07:00
Mathias Agopian
d3828cdd1c fix the 3-parameters fresnel calculation
it would automatically degrade to the 2-parameters version in 
LOW_QUALITY mode, but some other code relied on the proper calculation,
in particular when specularFactor was used.


FIXES=[436866605]
2025-08-08 14:18:15 -07:00
Mathias Agopian
b92af357f7 add a material option to use linear fog calculations (#9030)
The new `linearFog` material property, when set to `true` enables a
simplified fog calculation. The fog equation becomes linear which is
unrealistic, but more efficient to compute. In some situations with
a shallow fog range, it doesn't make a huge difference visually.

In this mode, height falloff and in-scattering are ignored.

The linear equation slope is calculated from the regular parameters to
match the slope of the real equation at a camera height. If 
`heightFalloff` is disabled, set to 0, the `density` parameter 
exactly corresponds to the slope of the equation in [1/m] units.
2025-08-07 01:33:36 -07:00
Ben Doherty
1f8248ba99 Metal: re-enable fastmath (#8911) 2025-07-23 13:46:43 -07:00
Juan Caldas
1b46ddd8b6 Webgpu: Check for Shadows (#8807)
BUGS=[397432947]
2025-06-03 11:57:34 +00:00
bridgewaterrobbie
67ed5141bf Avoid using paramater name type which is reserved in WGSL and thus can't be compiled for WebGPU 2025-05-20 14:09:23 -04:00
bridgewaterrobbie
d748dc590e Use WebGPU platform explicitly in shaders rather than rely on the mostly similar cases to Vulkan, with the exception of flipping the Y axis where they are different 2025-05-15 18:02:29 -04:00
Mathias Agopian
8f58743405 support up to five custom varyings
Five custom variables (varyings) are now available on the condition that
the `color` attribute is not requested.

FIXES=[404930099]
2025-03-24 09:38:31 -07:00
Mathias Agopian
6b91f30389 Materials can now specify a shadow attenuation factor (#8540)
* Materials can now specify a shadow strength factor

Materials have a new property: shadowStrength that can be used to
attenuate all shadows received by this material. e.g.:

```
void material(inout MaterialInputs material) {
  prepareMaterial(material);
  material. shadowStrength = 0.1;
}
```

FIXES=[391663042]

Co-authored-by: Powei Feng <powei@google.com>

---------

Co-authored-by: Powei Feng <powei@google.com>
2025-03-20 14:03:52 -07:00
hyde zhou
e414b99c09 fix vmax(const vec4 v) (#8474)
* fix vmax(const vec4 v)

* fix vmin
2025-02-26 17:04:26 -08:00
Sungun Park
ec2f5b8078 Promote getEyeIndex() as a common helper (#8418)
Now the helper function `getEyeIndex` becomes available for all shader
stages including post-processing. It used to be only accessible from
surface vertex shaders.
2025-02-06 22:41:30 +00:00
Rafael Dominguez
62cd8f1d35 Update multiview shader code generator for Vulkan
When targeting Vulkan with multiview, the shader
code generator was using the OpenGL extension
and built-in variables, which are not supported on
Vulkan.

Changed it to use GL_EXT_multiview instead of
GL_OVR_multiview2 when the target API is Vulkan.
2025-01-31 16:50:02 -08:00
Sungun Park
87bdf96449 Refactor: Rename shader snippets w/ new naming convention (see README.md) (#8402)
This commit renames all shader snippet files to conform to the newly
introduced naming convention outlined in README.md.

The new naming convention uses a `prefix_name.suffix` format to clearly
indicate the purpose and target shader stage of each snippet. This
improves the overall organization and readability of the shader code,
making it easier to understand how each snippet contributes to the
shader generation process.

No functional changes were made to the shader code itself or source
code. This is purely a refactoring for clarity and maintainability.
2025-01-31 00:02:53 +00:00
Mathias Agopian
377a1106aa Add a way to set the shadow sampling quality
FIXES=[379754325]
2024-12-17 16:07:40 -08:00
Mathias Agopian
ba6bee10f7 matc: remove access to public functions that should be undefined
When tangents are not supplied in a material, all "normals" related
public methods become undefined; remove access to them so we get 
compile time errors instead of garbage values in the shader.
2024-12-11 12:49:05 -08:00
Mathias Agopian
7f7d4d89ea fix some missing highp qualifiers
BUGS=[377751005]
2024-11-08 14:37:34 -08:00
Powei Feng
2cade209b5 Add Descriptor Sets to Filament (#8165)
We add the concept of the descriptor set as a way to describe
shader resources into Filament. This is a comprehensive change
across Filament.

Info on descriptor sets is available here:
https://docs.vulkan.org/spec/latest/chapters/descriptorsets.html

Co-authored-by: Benjamin Doherty <bendoherty@google.com>
Co-authored-by: Mathias Agopian <mathias@google.com>
Co-authored-by: Sungun Park <sungunpark@google.com>
2024-09-27 23:20:20 -07:00
Ben Doherty
8ba20eb03c Metal: fix static texture target on more devices (#8022) 2024-08-08 13:04:42 -07:00
Mathias Agopian
324dcd3c86 early exit in fog to improve performance 2024-07-31 10:10:48 -07:00
toddZ_CG
e4a0bb8fa0 Add support for KHR_materials_Specular (#7564)
Co-authored-by: Todd Zhang <toddzx@amazon.com>
Co-authored-by: Romain Guy <romain.guy@gmail.com>
Co-authored-by: Mathias Agopian <mathias@google.com>
2024-06-21 17:06:17 +00:00
Mathias Agopian
213eb6af9e Lit Materials can now specify the quality of SH computations
The number of SH bands used for the indirect light irradiance
computations can be set to 1, 2 or 3 (default) in Material::Builder.

For e.g. in lower-end devices w/ non HDR content, it might be
beneficial to set this value to 2.

BUGS=[341971013]
2024-06-20 10:25:04 -07:00
Mathias Agopian
bea02427ed keep the normal transforms in float during skinning
FIXES=[342459864]
2024-06-04 13:37:47 -07:00
Powei Feng
8cfdab0c28 Fix stereo variant defines in common_getters (#7879)
This caused a breakage in shader validation at runtime. Repro:
  - Remove ./out
  - ./build.sh release gltf_viewer
  - run gltf_viewer
2024-05-21 17:34:05 +00:00
Mathias Agopian
18ccf0cd8d change the morphing API so it uses only one buffer per renderable
The current API allowed to have a buffer for each primitive in a
renderable. We instead restrict the API so that there is a single 
MorphTargetBuffer for the whole renderable, shared by all primitives.
The buffer can be shared thanks to the "offset" parameter on
setMorphTargetBufferAt().

Also
- fix FMorphTargetBuffer::updateDataAt()
- add support for the "offset" parameter of setMorphTargetBufferAt()
2024-05-16 14:11:07 -07:00
Sungun Park
6ac36d1aab Fix a shader error (#7828)
gl_ViewID_OVR is of uint type. Explicitly convert it to int to fix the
error.
2024-05-06 21:03:04 +00:00
Ben Doherty
af92a1f21b Add getEyeIndex vertex API (#7822) 2024-05-03 14:22:24 -07:00