Commit Graph

366 Commits

Author SHA1 Message Date
Mathias Agopian
968c2c40fa Cleanup shader generation
- refactor the code so that all defines are generated in the same place
- generate common_type after all defines are generated
- protect (with defines) structures and UBOs that are not needed, based
  on the variant
2023-04-12 10:12:19 -07:00
Ben Doherty
6cab8d2cd4 Expose specialization constants to materials as constant parameters (#6652) 2023-04-11 11:09:53 -07:00
Mathias Agopian
e48690bdf9 matc: new feature-level options
The feature-level option sets the maximum feature level allowed for
the material. matc will fail if the specified material has a higher
feature level than the value set with the feature-level option. The
default is 3 (max).

This can be used to ensure that materials don't use features above
a specified level.
2023-04-03 14:05:38 -07:00
Mathias Agopian
4503ad1e34 fix -ffast-math and -fno-finite-math-only
- remove -ffast-math in place where it didn't seem too useful
- added -fno-finite-math-only everywhere we use -ffast-math so that
  isinf/isnan work.
2023-03-30 16:15:42 -07:00
Mathias Agopian
d8eb48c9de Improvements to fog
- FogOption::color is now correctly multiplied by the exposure and
  environment intensity.
- New option to exclude the skybox from the fog
- better documentation and naming
2023-03-23 09:31:01 -07:00
Romain Guy
5a75fb9b53 Add new alphaToCoverage material property (#6606)
* Add new alphaToCoverage material property

The alphaToCoverage property lets you enable or disable alpha to coverage
in a material. More importantly it lets you overrides the behavior of
blending: masked which automatically enables alphaToCoverage.

* Update release notes
2023-03-02 12:40:55 -08:00
Ben Doherty
d3956adca8 matdbg: take desktop/mobile into account for SPIR-V to GLSL translation (#6488) 2023-01-26 11:30:51 -08:00
Po
c88277a898 [filamesh] Add option to skip secondary UV coords (#6398)
Also added error and exit for when there's a mismatch in the
number of vertices vs. the number of UV coords (either primary or
secondary).
2022-12-20 14:14:31 -08:00
Romain Guy
60c264a2e7 Add Hex Fiend template for filamesh files 2022-12-20 10:01:56 -08:00
Philip Rideout
6b71232e38 matc / matinfo / filamesh: add vulnerability message 2022-10-17 15:49:35 -07:00
Mathias Agopian
9c4783142e matc: minor cleanup 2022-09-29 19:34:07 -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
1cbc1f30a6 filamesh: handle empty meshes
empty meshes would cause a OOB read.

b/246719043
2022-09-20 16:45:45 -07:00
Mathias Agopian
08fb39a1e4 Fix buffer overflow in matc
b/247441389
2022-09-20 16:45:45 -07:00
Mathias Agopian
d8a71ce195 minor cleanup and IDE warning suppression 2022-09-20 16:45:45 -07:00
Mathias Agopian
13986c12bc fix out of bounds access in matc
b/247442731
2022-09-20 16:45:45 -07:00
Philip Rideout
feda999eb3 matinfo and filamesh: misc ASAN fixes 2022-09-15 17:23:54 -07:00
Mathias Agopian
8dc16494a7 introduce "feature level 3"
This is because most android devices only support 16 texture in the
shaders (94.4%), so we can't realistically have feature level 2 demand
that.

Instead feature level 2 enables compute/ES3.1 features.
2022-09-14 16:53:43 -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
b2ec57776d new feature level API for backends (#5784)
* new feature level API for backends

backend can now return a "feature level", each level corresponds to a
"bundle" of features.
Level1: ES3.0 capabilities
Level2: ES3.1 capabilities + 31 textures + cubemap arrays

Currently metal always returns level 1, GL and Vulkan return level 2
if 31 textures or more are supported.

* Add public APIs for feature levels

* Add infrastructure to check feature levels in materials

* validate material feature level on use

The validation is done when creating a renderable. If the engine doesn't
support the material's feature level, an exception is thrown (or assert
if exceptions are not enabled).

* material documentation

* activate ESSL 3.10 for feature level 2

also generate #defines to identify available feature levels

* support for cubemap arrays in the public API


if feature level 2 is supported, cubemap arrays can be used from the
public API.

* add release notes
2022-08-17 10:14:26 -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
Philip Rideout
0ac9ecb823 "ShaderBuilder" does not need to exist, remove it.
We were mostly using this as a byte buffer, not a builder.
This PR removes ~200 LoC and 3 files.
2022-06-30 15:37:35 -07:00
Philip Rideout
a4ac9bf088 matc: add --template option.
This makes it easier to generate ubershaders without the fancy CMake
machinery available in its `configure_file` command.
2022-06-30 14:08:04 -07:00
Philip Rideout
e3932f6e65 uberz tool: add --append and --template arguments. (#5730) 2022-06-23 13:01:48 -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
5860e7fdce Add support for ubershader archives.
An ubershader archive is a bundle of filamat packages with some metadata
that conveys which glTF features each material supports.

This PR does three things:

1. Adds a new command line tool called `uberz` that consumes a list
   of filamat files and metadata text files and produces a single
   ubershader archive.

2. Adds a new library (also called `uberz`) that is used by `gltfio`
   to read ubershader archives, and used by the above command line
   tool to write ubershader archives.

3. Enhances `UbershaderLoader` so that it no longers uses a hardcoded
   set of materials, and instead takes an ubershader archive.

Ubershader archives have a simple binary layout that can be memcpy'd
directly into a C struct. The metadata is specified using a text file
with key-value pairs. These two file formats have formal desriptions in
the README in `libs/uberz`.

In a subsequent PR, we will remove the `gltfio_resources` target and
change the signature of `createUbershaderLoader` so that it takes
an archive.
2022-06-06 13:13:22 -07:00
daemyung jang
5a8bf42ddb Delete redundant semicolons 2022-05-24 09:46:46 -07:00
Philip Rideout
c82ae6a3a7 beamsplitter: add recursive descent parser
This removes usage of regexps from the parsing phase and splits the
program into three sub-packages: parser, database, and emitters.

The parser now generates an AST according to the formal grammar
described in the README:

https://github.com/google/filament/blob/pr/beamsplitter_rewrite2/tools/beamsplitter/README.md#grammar

This allows for nice readable error messages. More importantly, it
permits the C++ syntax to be less restrictive and paves the way for
possible expansion of the tool beyond `Options.h`.

I looked at the C++ AST generated by clang but it is huge and unwieldy.
For our purposes this simplified AST is much easier to work with.

The new lexer is inspired by the following Rob Pike talk.
- https://www.youtube.com/watch?v=HxaD_trXwRE

Beamsplitter does not use the state machine described in the above
prezo, but it does use a Go channel for separating the parser from the
lexer. In our case, the lexer is actually a recursive descent parser
with simple lookahead functionality. This made it easy for the "real"
parser to create an ergonomic coarse-grained AST.

This is a big change but it is a no-op in terms of the generated code.
2022-05-23 09:36:29 -07:00
Philip Rideout
a96d5932a8 beamsplitter: finalize codegen for View.java
Note that JNI c++ functions are not generated.  The setter / getter
methods are also manually maintained.
2022-05-18 13:40:44 -07:00
Philip Rideout
16369255e2 beamsplitter: progress with Java codegen. (#5564) 2022-05-17 13:59:52 -07:00
Philip Rideout
d6588bd382 beamsplitter: decouple parser from emitters (#5561)
This moves parser into a subpackage to shield it from the various
emitters (this folder structure is similar to what Rob Pike used for his
text templating library). This also adds a WIP Java code generator,
currently disabled.
2022-05-16 09:48:32 -07:00
Philip Rideout
c67e5b6047 beamsplitter: refactorings and enhancements. (#5550)
We now store block-level comments and check for template errors.
Previously if a template had a syntax error, it would silently quit.
2022-05-12 20:12:31 -07:00
Philip Rideout
1d223498cb beamsplitter: rename the tool, enhance the README. (#5549) 2022-05-12 17:07:40 -07:00
Philip Rideout
cbcaae6537 codegen: improve parsing of struct field types (#5548) 2022-05-12 13:54:28 -07:00
Philip Rideout
b8705198c0 codegen: improve handling of enums (#5546) 2022-05-12 13:53:31 -07:00
Philip Rideout
bef3c85ebf codegen: do not hardcode the View namespace. (#5547) 2022-05-12 13:52:54 -07:00
Philip Rideout
e3854f5c58 Use codegen for TypeScript definitions. (#5542)
This is a bit fancy because it modifies a file rather than generating
one from scratch.
2022-05-12 08:48:03 -07:00
Philip Rideout
78f2065b6f Use generated code for JSON serialization of Options. (#5541) 2022-05-11 10:47:03 -07:00
Philip Rideout
63cfb817d7 Use generated code for all "Options" JS bindings. (#5536)
TypeScript bindings and Java are still TBD.
2022-05-11 08:02:35 -07:00
Philip Rideout
a572a10ef7 Add codegen golang program. (#5534)
This adds a code generator, implemented in Go.

This PR also prepares `Options.h` (the ground truth) by simplifying its
syntax just a bit. The ground truth file must have very simple C++
syntax, which is described in the README:

https://github.com/google/filament/blob/pr/codegen2/tools/codegen-options/README.md

This process revealed a small bug: `Filter.MEDIAN` was bound to the
incorrect value in Java.

The generated code is not yet used, stay tuned.
2022-05-10 14:40:51 -07:00
Philip Rideout
db3186a65f Remove etc2comp and astcenc from the repo. 2022-05-02 11:29:19 -07:00
Philip Rideout
9aeec3a759 Add Ktx2Reader and BasisEncoder and use them in samples.
mipgen can now emit basis-encoded KTX2 files. Both the desktop and
web "suzanne" samples use this as a test for compressed textures.

This PR does not add KTX2 support to glTF, but it's on the way.

`BasisEncoder` has a builder style API that calls the basis encoder to
create KTX2 files. This hides some low-level BasisU features that we are
not using, like file I/O and mipmap generation.

`Ktx2Reader` is an easy-to-use API for creating Filament textures from
KTX2 files. Its API primarily consists of these two methods:

    bool requestFormat(Texture::InternalFormat format);
    Filament::Texture* load(const uint8_t* data, size_t size);

The first method is used to build an ordered list of formats that are
supported by your hardware. The second method consumes the contents of a
basis-encoded KTX2 file and attempts to produce a Filament texture with
a preferred format.

IMPORTANT: Our tools still let you use KTX1 for non-compressed images
because it is useful for HDR, but you can no longer use KTX1 for
block-compressed data.

Partial fix for #4771.
2022-04-15 10:48:48 -07:00
Philip Rideout
df03fdf3d7 mipgen: fixups / clarification regarding sRGB.
The `g_linearized` variable was being used for two purposes: to denote
the linearity of the source format AND the linearity of the destination
format. This was confusing and is now split is `sourceIsLinear` and
`destIsLinear`.

This change has no effect on the the look of the suzanne demo.
2022-04-11 14:28:34 -07:00
Philip Rideout
b60518caa5 Add libs/ktxreader, rename some things to prep for KTX2.
Changes:

- Remove the strange header-only variant of libs/image
- Rename KtxBundle => Ktx1Bundle
- Move image/KtxUtility => ktxreader/Ktx1Reader
- Add unit test for Ktx1Reader and test stub for KTX2.

Notes:

- Ktx1Bundle does not depend on Filament and is used by cmgen
  and mipgen to generate KTX files.

- Ktx1Reader has a dependency on Filament and should therefore live in
  a separate library, which it now does.
2022-04-06 10:56:37 -07:00
Philip Rideout
101a59138c Update the zbloat tool
The tool now works with Python 3 and handles binaries that have multiple
embedded material archives.
2022-03-21 16:13:49 -07:00
Ben Doherty
f801763e6b Add SSR variant filter to matc (#5256) 2022-02-24 10:35:30 -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
cc0486b3cc Rework material Variant filters
Variants are no longer just a bit mask, but rather a combination of
some bits, depending on the variant. Because of that the variant filer
must be updated.

Basically we now make a distinction between the "variants" as a public
material API and the actual `Variant` data type.

This change does the impedance match between the two.
2022-02-13 22:53:47 -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
ba9e7fa17f Improve (again) comments in Variants.h
- Improved formating
- Added more compile-time sanity checks
- Renamed Variant bits to 3 letters
2022-01-21 14:24:24 -08:00