Commit Graph

26 Commits

Author SHA1 Message Date
Mathias Agopian
bd67c9c67e Implement missing getters in RenderableManager (#9673)
FIXES=[479883232]
2026-02-03 13:15:18 -08:00
Mathias Agopian
26ceaebac6 add RenderManager::getInstanceCount()
FIXES=[442916683]
2025-09-05 09:51:06 -07:00
Mathias Agopian
1747ae8f5a validate MaterialInstance references when destroyed (#8366)
* validate MaterialInstance references when destroyed

With this change we now enforce two things:
- All MaterialInstance of a Material must be destroyed when
  destroying said Material. This has always been a documented 
  requirement of the public API, but wasn't enforced (only
  a warning was printed).
  This new assertion is unconditional.

- A MaterialInstance, when destroyed is no longer in use by any
  Renderable.

So before destroying a MaterialInstance, the user of API needs to 
ensure that either all Renderable using that MaterialInstance in one
of their Render Primitives are  destroyed, or, that these Renderable
using that MaterialInstance are reset to another one or to null.

There is a new RenderableManager::clearMaterialInstanceAt() that can
be used to clear a MaterialInstance on a Render Primitive.
  
Additionally, a Render Primitive with a null MaterialInstance is now
silently skipped during rendering, instead of a null-dereference.

Finally, that second assert is protected by a new feature flag: 
"features.engine.debug.assert_material_instance_in_use". This flag is
enabled on DEBUG builds and disabled on RELEASE builds by default.
The flag can be changed at any time using `Engine::setFeatureFlag()`.

BUGS=[333907416]

* Update filament/src/components/RenderableManager.cpp

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

---------

Co-authored-by: Powei Feng <powei@google.com>
2025-01-17 14:15:15 -08:00
Mathias Agopian
f7a5111106 switch to new morphing API
- remove deprecated morphing APIs
- repair gltfio, samples and tests

The new API doesn't allow a MorphTargetBuffer per RenderPrimitive,
instead the MorphTargetBuffer is specified per Renderable.

gltfio separates RenderPrimitives from Renderables, in particular all
RenderPrimitives are created before their Renderable; this was
problematic for this change because all primitives must share
a single MorphTargetBuffer living in the Renderable.

To fix this, we're no longer initializing the morphing paramters
at RenderPrimitive creation, instead we store a reference to the
BufferSlot in the Primtive structure, so that later, when the Renderable
is created we can finally retrieve the BufferSlot and initialize its
morphing paramters, which are not available. The "morphing parameters"
are now expanded to contain the MorphTargetBuffer as before (except now
it's always the same for all the primitives of a Rendrable), as well
as the offset within the buffer and the vertex count.
2024-06-28 12:14:57 -07: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
Mathias Agopian
93b15dac87 The type of geometry of a renderable can now be specified
- dynamic (default) no restriction apply
- static bounds: bounds and world transform can't be changed
- static: additionaly morphing/skinning and vertex/index buffers are
  immutable.

This will allow some optimizations in the future. Currently, we just
store the type but don't do anything with it.
2024-03-19 11:12:25 -07:00
Mathias Agopian
da17b6f867 New RenderableManager API to opt-out of fog
Fog can now be opted-out on a per renderable basis. When fog is disabled
on a renderable it removes the requirement that this renderable's 
materials have the FOG variant.
2023-05-17 15:58:56 -07:00
Mathias Agopian
d0c043c7ff implement draw command channels
There can be up to 4 channels drawing commands can be associated to. 
Channels work like "priorities" except it's the strongest command ordering 
key, in particular it takes precedence over the object's blending mode.
2023-01-23 13:47:41 -08:00
Mathias Agopian
cc7d88c033 remove RenderManager::setGeometryAt() that only sets offset/count
This is an API breakage, but the "full" setGeometryAt() can usually be 
used instead.
2022-06-01 12:46:45 -07:00
Mathias Agopian
cc51d478f8 extend blendOrder functionality
blendOrder was used to control the draw order of blended render
primitive within a Renderable. We now have an option to make the
blend order global, in this case those primitives with a global blend
order are always sorted solely using the blend order value (i.e. the 
distance from the camera is not take into account).
2022-05-31 09:30:36 -07:00
daemyung jang
001a3e3dc8 Set the morph target buffer by builder (#5179) 2022-02-16 09:20:38 -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
daemyung jang
354c39be6b Get the morph target count from the renderable (#5077)
* Get the morph target count from the renderable
* Set the morph target count by Builder
* Update morph target weights partially
* Remove noexcept at functions could throw exceptions
* Update Java bindings at RenderableManager
* Add missing comments
* Update morph target weights from offset

Co-authored-by: Mathias Agopian <mathias@google.com>
2022-01-26 10:27:25 -08:00
daemyung jang
1952f0a1f7 Change morphing APIs to support LOD (#5080)
* Change morphing APIs to support LOD
* Add Java and Web bindings for morphing
* Omit and fix JS bindings
* Fix styles in MorphTargetBuffer.java
2022-01-25 21:57:11 -08:00
daemyung jang
6805940bbf Compute morphing on GPU (#4999) 2022-01-12 11:06:47 -08:00
Mathias Agopian
8a81486f5d Implement light channels
Currently there are 8 light channels, both renderables and lights can
be associated to one or several light channel, lighting occurs when
at least one channel is active on both the light and the renderable.

Fixes #4275
2021-07-30 18:54:32 -07:00
Mathias Agopian
3e5471d32a Implement sharing of bones for skinning
The API now allows to create a standalone SkinningBuffer containing
Bones for skinning. This SkinningBuffer can even be very large and
contain bone data for several renderables.

New APIs on RenderableManager allow to switch to skinning buffer mode
and to set the SkinningBuffer (and window into it) to use.


Fixes #3238
2021-07-15 16:29:26 -07:00
Romain Guy
9b1a0e2f58 Remove of static JNI fields (#2400)
Static JNI lookups were causing issues with multiple libraries.
We now do the lookups when we need them as they are effectively
just hashmap lookups and we do them only in places where the
work we need to perform will be much larger than a simple hash
map lookup anyway.

This chane also manually registers filament-utils JNI bindings
to get rid of unnecessary symboles. We should do the same for
other Filament libraries (the symbols are pretty long and
we now have many of them).
2020-04-16 09:00:54 -07:00
Ben Doherty
df2caf4f62 Expose setCulling to public RenderableManager API (#2331) 2020-04-02 17:07:19 -07:00
Mathias Agopian
d54ceff7a3 Add support for screen-space contact shadows (#2245)
* Add support for screen-space contact shadows

This CL adds support and always enables it.
toggles and setting in the next CL (same PR).

* Plumb settings for screen-space contact shadows

screen-space contact shadows is handled like a shadow option,
parameters (including on/off) are set in the LightManager, using
the existing ShadowOptions API.

Additionally there is a per-renderable toggle.

Both toggles are off by default.

* Allow contact shadows when shadowing is auto-disabled


Shadowing can be auto-disabled when for instance there are no
shadow casters in the scene. We still allow contact shadows in
that case.

This would allow for instance, to make the vegetation on a terrain
not shadow-casting, and still get some shadowing there by using
contact shadows instead.

* apply micro-shadowing after contact shadows

also, don't compute contact shadows when we know we're fully shadowed.
2020-03-16 22:39:24 -07:00
Mathias Agopian
3105a8330e remove unneeded includes in public headers
Replace with forward declarations if needed and includes in .cpp that
now need them.
The idea here is to have our headers have the least amount of impact as
possible on our clients (e.g. compilation time).
2020-01-24 12:13:48 -08:00
Philip Rideout
90c17ccbad Filament now supports GPU vertex morphing.
This works by aliasing CUSTOM0 - CUSTOM7 to morphing attributes, and by
extending our existing skinning variant.

This PR was tested against some upcoming changes to gltfio.

Issue #1149, #1417
2019-07-26 17:53:46 -04:00
Philip Rideout
7fcd3e1a4f Java clients can now get material instances from renderables.
Discussed this feature with Mathias, we decided to create
MaterialInstance Java wrappers on the fly, and create Material Java
wrappers lazily. This is simple and avoids caching the wrapper objects,
which might otherwise lead to complexity and bugs.

Note that gltfio creates material instances behind the scenes, so this
feature is particularly useful for gltfio clients.
2019-06-25 19:47:49 -07:00
Philip Rideout
94b4f92bc5 Android: move JNI C++ utils into a common folder.
No need for a proper library, this is just a common location to simplify
JNI bindings in other projects like filamat and gltfio.

There is no need to move the one Java source file (`NioUtils.java`)
since downstream libraries will have a dependency on Filament, and
FindClass should work fine.
2019-06-17 08:47:27 -07:00
prideout
5ee359cf40 Move math namespace to fix #746. 2019-02-07 09:23:07 -08:00
Romain Guy
b3d758f3b3 Initial commit 2018-08-03 10:38:22 -07:00