Compare commits

...

707 Commits

Author SHA1 Message Date
Fernando Raviola
555a1396ca Data verification before server upload (#6518)
Data verification before server upload
2023-05-18 15:29:50 +10:00
Fernando Raviola
57ce236fe4 Improve Session API, send formatted string to server (#6498)
Add fgdbg::Session.h, Pass.h, Resource.h dtos/models
2023-05-18 15:29:50 +10:00
raviola
527428a629 Add fgdbg::Session.h, Pass.h, Resource.h dtos/models 2023-05-18 15:29:50 +10:00
Fernando Raviola
a5913e2c36 Add fgdbg::Session.h, Pass.h, Resource.h dtos/models (#6270)
* Add fgdbg::Session.h, Pass.h, Resource.h dtos/models

* Add session name

* Update Engine to use new API
2023-05-18 15:29:50 +10:00
Fernando Raviola
48a31f484a fgdbg client project structure + simple server connection (#6210)
* fgdbg client project structure + simple server connection

* pr feedback
2023-05-18 15:29:50 +10:00
Fernando Raviola
21cf0f40c4 Add DebugServer for fgdbg with support for Websockets (#6169)
* Add dummy DebugServer for fgdbg with support for Websockets

* PR feedback
2023-05-18 15:29:50 +10:00
raviola
16a351bf15 rename debug.server to debug.matdbg 2023-05-18 15:29:27 +10:00
raviola
c76b6d7bed Use smart pointer 2023-05-18 15:27:57 +10:00
raviola
827f82fa84 PR suggestions 2023-05-18 15:27:57 +10:00
Fernando Raviola
9d7317a4a9 Concat namespaces
Co-authored-by: Mathias Agopian <mathias@google.com>
2023-05-18 15:27:57 +10:00
Fernando Raviola
786008c2ed Add FrameGraph debugger lib: package structure + CmakeLists.txt 2023-05-18 15:27:57 +10: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
Romain Guy
002becdc4f Don't use large runners yet (#6814) 2023-05-17 13:46:55 -07:00
Romain Guy
2ade1778b1 Don't rely on Java8 to invoke sdkmanager (#6809) 2023-05-16 13:01:56 -07:00
Mathias Agopian
f6c8ce1fd1 New API to apply a transform to the large-scale fog.
This works by making the fog an entity which can be used to create
a TransformManager component an participate to the transform hierarchy.

This feature can be used as more advanced way to set the fog's floor,
which now can have an orientation (essentially be a plane).
This is useful for coordinate systems that are not y-up.
2023-05-16 12:42:59 -07:00
Mathias Agopian
8aa1435fbd fogHeight is not needed in the shader 2023-05-16 12:42:59 -07:00
Benjamin Doherty
3e29b6e443 Release Filament 1.36.0 2023-05-15 16:55:11 -07:00
Ben Doherty
1a138aea1a Fix incorrect target passed to glBindFramebuffer (#6807) 2023-05-15 15:27:54 -07:00
Mathias Agopian
d40712937d Fog should be calculated in the user's world coordinates
Fixes #6798
2023-05-12 17:40:25 -07:00
Mathias Agopian
cfe1abec08 fog color from ibl should work with unlit
the skybox is unlit for instance, but for should still get the color
from the ibl. that can't work with ES2 though.
2023-05-12 17:40:06 -07:00
Mathias Agopian
719ed28d7e API to asynchronously force material compilation
Material::compile() can be used to asynchronously ask the backend to
compile a subset of the variants of a Material and be notified when
done. This can be used during initialization to avoid hiccups later.
This will also force caching of those material programs if the 
Platform provides the blob cache API.
2023-05-12 10:46:30 -07:00
Mathias Agopian
aa1773d633 cache programs in gl backend 2023-05-12 10:46:30 -07:00
Mathias Agopian
9b8b882818 Blob cache API in Platform
This is compatible with EGL_blob_cache.
2023-05-12 10:46:30 -07:00
Mathias Agopian
17664d294e A new Builder-based API to create a filament Engine
This doesn't add or remove functionality, but merely changes the API
to create an Engine, to be more consistant with how we construct other
objects in filament.

You can now use Engine::Builder to construct an Engine.
2023-05-12 10:46:30 -07:00
Ben Doherty
2ae4ee85e0 Fix IndexError in zbloat tool (#6802) 2023-05-11 11:43:33 -07:00
Powei Feng
70bb08a93a vulkan: refactor VulkanPlatform implementations (#6797)
Fold all the platform code into a single concrete implementation
named PlatformVulkan.
2023-05-10 12:49:08 -07:00
Mathias Agopian
88f6360321 update remote ui and web samples 2023-05-10 10:19:49 -07:00
Ben Doherty
f7538342df Use a single material for separable gaussian blur (#6791) 2023-05-09 16:50:31 -04:00
Mathias Agopian
8e6d5d11b6 deleteVertexArrays only destroyed the first VAO
fixes #6794
2023-05-09 11:50:23 -07:00
Benjamin Doherty
ac74f09dc8 Fix Android CI release build 2023-05-09 13:22:29 -04:00
Benjamin Doherty
f47265e9c5 Release Filament 1.35.0 2023-05-08 18:04:40 -04:00
dingyi.chen
9243887a3a Fix Sampler External texture build 2023-05-05 16:55:42 -07:00
Mathias Agopian
4efac2c0fa iOS: make sure to save/restore the framebuffer binding
this is needed because filament does state tracking.
2023-05-04 14:42:15 -07:00
Mathias Agopian
f3e1d5592a Extend OpenGLPlatform to support preserving attachments on commit
By default ancillary buffers are discarded on commit (eg. depth buffer),
but in certain situations the platform may want to preserve them. this
new virtual allows a concrete implementation to specify which buffers
need to be preserved.
2023-05-04 14:29:41 -07:00
Mathias Agopian
c67d9ce09b ES2: add support for devices without VAOs 2023-05-03 10:40:29 -07:00
Mathias Agopian
27ee90a56d fix windows build 2023-05-03 00:11:06 -07:00
Mathias Agopian
41ccbdbf17 ES2 support: support picking properly
Note that in ES2 mode, the depth value returned by the picking API
only has 8-bits precision and incurs a bigger performance penalty,
because glReadPixels is synchronous.
2023-05-02 21:23:47 -07:00
Mathias Agopian
17fc3c23ed ES2 support: rec709 out colorspace emulation for ES2
This is only the 2nd step where we implement the
emulation logic and set the appropriate spec-constant and
uniform.
2023-05-02 21:23:47 -07:00
Mathias Agopian
fdb0798f28 ES2 support: rec709 out colorspace emulation for ES2
This is only the first step where we:
- clean-up some code to prepare for 2nd step
- add support for the linear->srgb in the shaders

The linear->srgb conversion is protected by a
specification constant and will be enabled only
if the corresponding EGL extension in not present.

Then, if enabled, the actual conversion is
controlled by a uniform so that it can be
selectively enabled on swapchains that have it
turned on.

In this change, the emulation logic that sets
these gates is not implemented (that's step 2).
2023-05-02 21:23:47 -07:00
Mathias Agopian
b4d842c342 ES2 support: filament and filamat changes
This CL contains two parts:
- changes to matc/filamat
- changes to filament itself

Filamat can now generate ES2 compatible shaders. Only the unlit variant
is supported. Fog and picking are supported as well.
post-processing, skinning, instancing, all lighting and shadowing are not supported.

Filament is updated to not issue commands that are not supported in ES2.

Addtionnally, the hello-triangle sample is updated to work on an ES2 device.
2023-05-02 21:23:47 -07:00
Mathias Agopian
7cddd832aa ES2 support: backend API to specify attributes of a Program
In ES2 attributes must be bound by name, so we need to pass that
information to the backend.

This is needed only for ES2 (feature level 0)
2023-05-02 21:23:47 -07:00
Mathias Agopian
6a10753267 ES2 support: add support for emulated UBOs in the backend
From the backend's point of view, UBOs are emulated with uniforms.
The backend will maintain a data structure that maps an offset into
the UBO to a uniform and will do the appropriate glUniform* calls
at the right time and if needed (e.g. only if the UBO content has
changed).

The mapping from an UBO content to uniforms is passed to Program
upon creation.
2023-05-02 21:23:47 -07:00
Mathias Agopian
38dba5394e ES2 support: basic support in backend
This first round is mostly about making the backend compile with the
ES2 header only and use the ES2 code path when running on an ES2
context. We also add feature level 0, which corresponds to ES2
devices.

We introduce the macro FILAMENT_SILENCE_NOT_SUPPORTED_BY_ES2, which is
exclusively used to compile-out code that cannot compile with ES2
headers. This macro is active when ES2 headers are used.

There is also a new `OpenGLContext::isES2()` method that is returns
whether we're running an ES2 context, either statically (desktop, ios)
or dynamically (mobile).

This PR should add or remove any functionality.
2023-05-02 21:23:47 -07:00
Powei Feng
108cdd4242 vulkan: Fix Adreno crash for debug build (#6752)
- Remove `const` from `const highp mat4` just for mobile+vulkan

Fixes #5294
2023-05-02 13:00:38 -07:00
Powei Feng
228aa6c631 vulkan: fix surface format (#6783) 2023-05-02 12:28:48 -07:00
Powei Feng
8936b3aa66 opengl: fix web readPixels (#6781) 2023-05-02 10:56:05 -07:00
Ben Doherty
6558448eae Add support for supplying instance local transforms (#6762)
Clients can now supply a local transform for each GPU instance.
2023-05-01 18:00:27 -04:00
Romain Guy
88be599c2e Use width instead of heigh 2023-05-01 13:53:25 -07:00
Benjamin Doherty
cf1bbf63fc Bump MATERIAL_VERSION to 35 2023-05-01 13:39:45 -04:00
Benjamin Doherty
4e888d142b Release Filament 1.34.0 2023-05-01 13:34:52 -04:00
Mathias Agopian
a5e6d9ef3d cleanup PlatformEGL a bit. (#6769)
- add a helper Config class to more easily manage EGL's attribute
  pairs.

- consolidate config selection code
2023-04-27 11:39:09 -07:00
Powei Feng
5e58af466c vulkan: fix RenderPass size (#6775) 2023-04-27 10:09:23 -07:00
Mathias Agopian
899c15f023 very basic API for materials to have global variables (#6764)
A material global is a variable seen by all materials. There are 4 such 
variable which are all vec4 and they can be set on a per-view basis.

All materials used during Renderer::render() will see the same value.

These variable can be accessed in the materials by using 
getMaterialGloabal{0|1|2|3}.
2023-04-25 17:20:43 -07:00
Powei Feng
861da7b5c9 Change mac/linux runners to more cores (#6768) 2023-04-25 15:12:49 -07:00
Benjamin Doherty
b62cf698a5 Release Filament 1.33.0 2023-04-25 13:08:56 -04:00
Powei Feng
b928e5c4dc vulkan: Fix Adreno issue with optimized material (#6757)
* vulkan: Fix Adreno issue with optimized material

Turning off the simplification pass seems to remove all of the
artifacts associated with Adreno GPUs.
2023-04-24 15:11:29 -07:00
Powei Feng
b748ea7239 Fix no-opt build option for materials (#6756)
- `-g` option was missing from `build.sh`
- `-Pcom.google.android.filament.matnopt` should be passed to
   the sample apps as well.
- Add logic to respect `-Pcom.google.android.filament.matnopt`
   in `FilamentPlugin.groovy`
2023-04-24 13:05:23 -07:00
Romain Guy
bd9ba1139e Update Kotlin math APIs (#6761)
Fixes bugs and adds new useful APIs.
2023-04-24 05:17:09 -07:00
Romain Guy
5ed25aa327 Apply post-lighting blending before the fog (#6755)
* Apply post-lighting blending before the fog

* Update release notes
2023-04-21 16:51:38 -07:00
Romain Guy
7f51f21512 Fix Android samples 2023-04-21 15:53:59 -07:00
Mathias Agopian
c24cc726e8 Fix Android samples so they handle surface resizes properly 2023-04-21 15:36:02 -07:00
Romain Guy
7b90a8f921 Set the Kotlin JDK version to match AGP's 2023-04-20 23:17:25 -07:00
Romain Guy
9fb96cd200 Upgrade to AGP/Gradle 8.0.0, and other dependency upgrades (#6753)
This upgrade lets us remove several hacks we needed to properly publish
our artifacts on Maven.
2023-04-20 18:02:23 -07:00
Mathias Agopian
f881b59d60 fog: disable fog color from IBL when unlit
When unlit, the IBL specular map is not defined.
2023-04-20 12:45:29 -07:00
Mathias Agopian
ebb07520c0 change picking to use floats (#6747)
floats can have up to 16.7M unique integers which is enough for encoding
an Entity. 
This change will help a later one that adds support for ES2
2023-04-19 13:53:45 -07:00
Benjamin Doherty
29d5ae621a Release Filament 1.32.4 2023-04-19 14:09:32 -04:00
Mathias Agopian
6e275514ad matc: attributes are no longer hardcoded in a file
They're not hardcoded in a database inside MaterialBuilder and are
generated. This will be needed later for ES2 support.

We could actually imagine something more dynamic in the future too.
2023-04-18 15:09:43 -07:00
Benjamin Doherty
08503943f4 Update web docs 2023-04-17 13:29:47 -04:00
Elie Michel
0c547748bf Small typos in Design doc (#6740) 2023-04-17 10:23:16 -07:00
Powei Feng
19ab9f0403 vulkan: refactor image layout transition (#6729)
- Moved most of the layout transition logic into VulkanImageUtil
   so that we'd have a single place to consider if failure arises
 - Add an abstraction on top of vk's layouts so that reasoning
   about our use cases (and corresponding layout is easier).
 - Removed the redundant VulkanDepthLayout
 - Refactor VulkanTexture::transitionLayout so that most of the
   transition paths can be done through this entry point. It also
   enables us to handle tracking the current layout.
 - Add a special case to transition the depth attachment/texture
   if it is both a sampler and an attachment.
 - Add a few debug printing markers across the classe - guarded
   under the existing FILAMENT_VULKAN_VERBOSE define.
2023-04-12 15:49:37 -07:00
Mathias Agopian
c895554a22 don't write floats with a trailing f
this is not supported in ES2
2023-04-12 10:12:19 -07:00
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
Mathias Agopian
de845d2885 make CodeGenParam a parameter of semantic analysis 2023-04-12 10:12:19 -07:00
Mathias Agopian
0e1f57d712 simplify code that resolves precision qualifiers
Some logic specific to uniform was pushed too low in the method 
resolving a precision to a string.
2023-04-12 10:12:19 -07:00
Mathias Agopian
6b3dfbc635 reduce our reliance on unsigned types
This is to facilitate ES2 support, in all places where unsigned types
were not strictly needed, we now use the corresponding signed type.
2023-04-12 10:12:19 -07:00
Mathias Agopian
5e2b4dec99 fix specification constant injection in glsl
- boolean where handled as int
- always cast float to float()
2023-04-11 15:56:06 -07:00
Powei Feng
0cd4a143ab vulkan: fix spec constant bool size 2023-04-11 15:55:37 -07:00
Ben Doherty
c7ad9acc79 Fix float spec constant formatting (#6731) 2023-04-11 15:55:04 -07:00
Benjamin Doherty
afeaf90d0d Fix build when exceptions disabled 2023-04-11 15:36:24 -07:00
Benjamin Doherty
3603aaafa6 Release Filament 1.32.3 2023-04-11 11:17:21 -07:00
Ben Doherty
6cab8d2cd4 Expose specialization constants to materials as constant parameters (#6652) 2023-04-11 11:09:53 -07:00
Ben Doherty
ca2f3d76e6 Metal: work around iPad pipeline error (#6724) 2023-04-10 16:45:38 -07:00
daemyung jang(danny.jang)
a2beaf0582 Support the external image on macOS (#6689)
* Support the external image on macOS

Implement CocoaExternalImage.

* Fix to take an onwership of the external image

* Correct incorrect comments

* Rename a function explicitly

Make a function name to know copying RECTANGLE to TEXTURE2D.

* Do lazy initialization

Create CocoaExternalImage::SharedGl when it's needed.

* Fix a crash when engine is terminated

Destroy the external image shared gl before gl context is destroyed.

* Remove an useless variable
2023-04-10 09:38:26 -07:00
Romain Guy
4a116e6791 Improve size optimizations when compiling material (#6721)
* Improve size optimizations when compiling material

This changes the behavior of the size optimizer in matc (-S), but
only for GLSL and MSL. With this change we gain a ~65% size reduction
on a lit material compiled for OpenGL. To get those gains we generate
extra SPIRV debug information to preserve variable names and better
utilize the line dictionary. Unfortunately this break the SPIRV
optimizer so we skip it and instead rely on a simple DCE pass provided
by glslang. We also enhance the whitespace removal pass of the GLSL
minifier to move lone { and } to the previous line, which avoids
generating an extra index in each shader variant. Each index being
at least as big as the character itself, this is quite wasteful.

When generating SPIRV for Vulkan, we rely on spirv-opt for size
optimizations as before.
2023-04-07 09:34:43 -07:00
Mathias Agopian
040fc64583 Improve how we cache shared shaders
Some shaders can be shared across all materials (e.g. the depth 
shaders). We use the filament default material as the "source" of
the cache, but until now we relied on an a priori knowledge of which
variants were present in the default material.

With this change, we now query once the list of variants (of interest)
in the default material and reuse that list for caching these variants
later.

This is better because the cached variants are now entirely driven by
the default material (which they depend on anyways). This is also faster
because we don't need to query which variant we need each time we create
a material.
2023-04-07 09:33:26 -07:00
Mathias Agopian
e19011d0e0 use the enum instead of ints everywhere for ShaderModel and ShaderStage 2023-04-07 09:33:26 -07:00
Mathias Agopian
8d3b395e86 ProgramBuilder is a relic, rename to Program 2023-04-07 09:33:26 -07:00
Mathias Agopian
2d1d8a6eec add a few asserts 2023-04-07 09:33:06 -07:00
Powei Feng
498a355fb2 vulkan: Fix validation errors (#6717)
- Depth attachment layout has generated a lot of error due to
   it being read-only. But the store-ops for the attachment during
   the renderpass are all write ops. We set the depth attachment
   layout as VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
 - Enable extra blitting step for SSAO because of the above layout
   conundrum.
 - Index buffers did not have a pipeline barriers after loading
   them.
 - Remove `assert_invariant(utils::popcount(sampleCount) == 1);`
   from `reduceSampleCount`. This assert fails when enabling the
   duplicate pass for SSAO.
2023-04-06 17:32:27 -07:00
Powei Feng
944031af14 vulkan: add missing index buffer barrier (#6718) 2023-04-06 15:09:10 -07:00
Mathias Agopian
ee9d427526 hellotriangle can now choose the backend 2023-04-05 16:22:46 -07:00
Benjamin Doherty
9b98ae66ce Release Filament 1.32.2 2023-04-05 12:54:40 -07:00
Mathias Agopian
126ba44719 expose getShadowCascade() only when shadowing and lighting is enabled 2023-04-04 21:31:23 -07:00
Mathias Agopian
503e3ba555 honor matc -t (print shader) options, even when compilation fails early 2023-04-04 21:30:49 -07:00
Mathias Agopian
c264d26edd filter out VSM variant for unlit materials DEPTH shaders
The VSM variant is never needed for unlit materials, it was filtered
out correctly for color shaders but not for the depth shaders.
This removes 4 variants from all unlit materials.

Also improve matinfo variants output.
2023-04-04 16:52:04 -07:00
Romain Guy
185c68c55b Suppress numerous libz warnings (#6709)
* Suppress numerous libz warnings

zlib will fix this issue later (see https://github.com/madler/zlib/issues/633).
For now we will just turn off the warning.

* Fix Windows build
2023-04-04 11:15:39 -07:00
Romain Guy
4624b0d1a1 Update libz and libpng to fix compilation warnings (#6708) 2023-04-04 10:07:18 -07:00
Romain Guy
5fe0a50c99 Update spirv-cross to fix build failures with recent versions of clang (#6707) 2023-04-04 10:06:57 -07:00
Mathias Agopian
a484fe1de3 rename ChunkcContainer::addChild/addSimpleChild to push/emplace (#6704)
'child' didn't make any sense in this API, push/emplace mimics
std::vector, which is closer to what the api actually does.
2023-04-03 14:06:42 -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
bc40ff7f19 fix typos in documentation
Fixes #6294
2023-03-31 15:27:50 -07:00
Mathias Agopian
30979124b5 skinning now works when the model is far from the origin
We are doing skinning computations effectively in world space, so
some of the math must be done in high-precision.
2023-03-31 14:47:54 -07:00
Mathias Agopian
6eb4c5e356 gltf_viewer: debug option to move the origin far away 2023-03-31 14:47:54 -07:00
Ben Doherty
38ede3719f TangentSpaceMesh fixes (#6697) 2023-03-31 12:03:49 -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
Romain Guy
9fc6b0d654 Update LICENSE (#6691) 2023-03-28 17:27:31 -07:00
Romain Guy
d00223332e Update README.md 2023-03-28 15:22:20 -07:00
Mathias Agopian
d3013ae151 better selection of opengl context version on desktop
fixes #6682
2023-03-28 11:59:05 -07:00
Mathias Agopian
b2fc46c320 start froxelization earlier 2023-03-28 10:46:11 -07:00
Romain Guy
53aac259a0 Fix emscripten compilation errors and warnings (#6688)
These errors and warnings only appear with more recent versions of
the emscripten SDK.
2023-03-27 17:33:45 -07:00
Powei Feng
af35b87d5b vulkan: prefer discrete GPU over integrated (#6677) 2023-03-27 08:09:16 -07:00
Mathias Agopian
0171452b02 fix stream unit-test 2023-03-24 17:30:00 -07:00
alexfh
065a33c846 Add a missing #include <exception>
... which is needed to avoid compilation error with recent LLVM libc++ (after https://reviews.llvm.org/D146097). Previously, symbols like std::terminate() were available through other headers (e.g. <functional>, <vector>, etc.).
2023-03-24 17:21:28 -07:00
Mathias Agopian
90601b9471 update remote ui 2023-03-24 17:19:35 -07:00
Romain Guy
327f630ed7 Update web demos 2023-03-24 09:38:42 -07:00
Mathias Agopian
96acc6900d gltf_viewer now respects FILAMENT_DISABLE_MATOPT
debug builds are unchanged, release builds will now optimize shaders and
either build can be overridden with OPTIMIZE_MATERIALS.
2023-03-24 09:23:10 -07:00
Mathias Agopian
91cc36f1ec fix IDE warnings
mostly const decorators.
2023-03-24 09:22:53 -07:00
Mathias Agopian
575e54e5d6 convert floats to their smallest string representation 2023-03-23 15:23:18 -07:00
Mathias Agopian
9a2fd38f33 update libutils to output floats/double without loss 2023-03-23 15:23:18 -07:00
Mathias Agopian
7cba0da0a2 implement cascades visualization as a post-process
this allows us to remove code from the main shaders that is basically
never used, reducing shader size and runtime costs.
2023-03-23 12:11:56 -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
Mathias Agopian
3ccd592eab fix manual instancing
only use the instanced UBO with automatic instancing.

Fixes #6579
2023-03-23 09:30:36 -07:00
Benjamin Doherty
a157546d82 Release Filament 1.32.1 2023-03-21 15:47:47 -07:00
Mathias Agopian
3ec704b91c fix world-space coords of DEVICE vertex domain at infinity
In device vertex domain it is easy to specify infinite world-space
coordinated (e.g. with the skybox), this results in complications
everywhere. We were mitigating this by essentially moving these
coordinates to around 16000 (give or take depending on the near plane),
but that was way too small.
Now we move them around 1e19, which seems to work. It's important with
applications rendering very large scenes to not use too small of a value.
2023-03-21 11:11:17 -07:00
Romain Guy
331af7bf35 Add sun size and halo properties to glTF viewer controls. (#6655)
This change also simplifies libviewer by removing duplicated code.
2023-03-21 10:08:20 -07:00
Mathias Agopian
473aff9093 Fix a bug in matdbg where it could reorder the shaders in the package (#6656)
This happened because the code iterated over the keys of a hashmap,
which obviously were not guaranteed to be in the same order as those
entries where added to the hashmap.

We fix this by adding a "visitor" to the materialchunk, so we can
iterate through it in order and retried the info we need.
2023-03-21 10:00:33 -07:00
Powei Feng
6ff08f2ac1 Update filament rendering test (#6654)
- If the callback isn't called, fail.
- Simplify by disabling post-processing.
2023-03-21 09:50:13 -07:00
Romain Guy
3db7f6675e The sun disc should be computed in high quality only. (#6653)
This will provide a boost to mobile devices by not computing the sun
disc as it was intended.
2023-03-20 16:20:46 -07:00
Powei Feng
e501a15ef2 gltfio: Release cancelled, decoded texture resources (#6620)
When we call TextureProvider::cancelDecoding, we should make sure
that textures that have been decoded, but not yet used (popped)
should be released (i.e. memory freed and the meta data marked
appropriately.)
2023-03-20 10:34:24 -07:00
Powei Feng
4e8974bcd9 vulkan: disable xlib when using swiftshader (#6647) 2023-03-17 16:21:03 -07:00
Andi Smithers
7914372707 Update Materials.md.html (#6646)
Fixed typo in the source documentation : getUserTimeMode(float m) which should be getUserTimeMod(float m)
2023-03-17 12:36:39 -07:00
Ben Doherty
3c794247c3 Update web docs (#6645) 2023-03-17 00:34:39 -07:00
Powei Feng
ae12e3a51c Revert "vulkan: async readPixels (#6605)" (#6644)
This reverts commit 6f25e8ae5a.

Reason for revert: breaks clients that were expecting synchronous readPixels for vulkan
2023-03-16 12:55:19 -07:00
Benjamin Doherty
fdc2ab30c0 Include atomic in VulkanCommands.h 2023-03-15 11:15:04 -07:00
mackong
122541eedc web: fix animation stopped premature (#6630) 2023-03-14 10:52:34 -07:00
Benjamin Doherty
7e54bc8bcd Release Filament 1.32.0 2023-03-14 10:46:08 -07:00
Ben Doherty
e1ebe97eb5 Vulkan: fix stack use-after-free (#6639) 2023-03-14 10:25:01 -07:00
Powei Feng
9fed30af55 gltf-viewer: update API/backend usage description (#6638) 2023-03-13 23:22:30 -07:00
mackong
4fd02d7e75 gltfio: fix crash when custom attributes used 2023-03-13 15:16:36 -07:00
Daniel Rahme
e30a99f692 Fix wrong package name 2023-03-13 15:14:46 -07:00
mackong
b891c52d9b web: fix getWorldTransform typo 2023-03-13 15:14:21 -07:00
Benjamin Doherty
74eb8a77e5 Bump MATERIAL_VERSION to 32 2023-03-13 14:04:40 -07:00
Mathias Agopian
ba59d6d1b7 update webgl samples and remote ui 2023-03-09 15:11:29 -08:00
Ben Doherty
46efeb7fa8 Fix RELEASE_GUIDE numbering 2023-03-09 10:50:06 -08:00
Ben Doherty
673c1104b2 Update RELEASE_GUIDE
Reflect the NEW_RELEASE_NOTES process
2023-03-09 10:48:06 -08:00
Benjamin Doherty
7cca872af5 Release Filament 1.31.7 2023-03-09 10:39:17 -08:00
Mathias Agopian
3cef1991b2 Minor cleanup of GL backend 2023-03-08 12:49:22 -08:00
Mathias Agopian
64493d8636 Fix timer query breakage on webgl 2023-03-08 12:06:59 -08:00
Powei Feng
df78322bdc android: fix sample-material-builder app name (#6624)
fixes #6622
2023-03-08 11:11:56 -08:00
Ben Doherty
f1a967d631 Update web docs and include ktx2 assets (#6616) 2023-03-08 10:55:13 -08:00
Ben Doherty
ec48dfa453 Remove compute shader assertion in GLProgram 2023-03-07 23:31:33 -08:00
Deadlock Yoon
5881a13b20 Metal: fix memory leak in readPixels
The PixelBufferDescriptor was not being deallocated properly, which
resulted in the leak. This patch explicitly deletes the
PixelBufferDescriptor at the end of the callback to prevent the leak
.This is necessary as the move constructor does not automatically
deallocate the existing PixelBufferDescriptor.
2023-03-07 11:02:39 -08:00
Mathias Agopian
efd9e875db fix a discard flags issue
An attachment would be wrongly discarded if used as read-only: because
it didn't have a dependency to it, the discard flag was set.
This is fixed by setting the discard flag only if a resource is written
and has dependencies to it.

Should fix: #5005
2023-03-06 22:39:11 -08:00
Powei Feng
6f25e8ae5a vulkan: async readPixels (#6605)
- Add a TaskHandler class for process events on the backend
   thread
 - Check fence status when handler runs and copy bits to the client
   when the fence is reached.
2023-03-06 18:03:28 -08:00
Mathias Agopian
449519c1b4 cleanup fog
- update comments and some names
2023-03-06 16:28:31 -08:00
Mathias Agopian
e2e5f7cee9 Add way to retrieve the user world-space in materials (#6607)
* Add way to retrieve the user world-space in materials

added `getUserWorldFromWorldMatrix()` and `getUserWorldPosition()` to
retrieve the API-level (user) world position in materials.
Deprecated `getWorldOffset()`

`getWorldOffset` didn't work when an IBL rotation was applied.

* fix large scenes with an ibl rotation

Rotate the IBL around the camera instead of the world so that the camera 
is always at the origin regardless of the rotation.
2023-03-03 21:34:17 -08:00
Powei Feng
9d30233a38 geometry: clean up TangentSpaceMesh (#6595)
- Reordered the 'const var' declarations to 'var const'
 - Use std::vector for data arrays instead of manually managing
   allocations
2023-03-03 15:33:28 -08:00
Ben Doherty
d684fc4096 Compute shading_view will full precision (#6611) 2023-03-03 13:48:36 -08:00
Ben Doherty
5f3f3f1b24 Fix NaN parameters in material_sandbox (#6609) 2023-03-03 12:13:06 -08:00
Romain Guy
6aa2a2b89b Update getopt to musl-1.1's implementation (#6610)
* Update getopt to musl-1.1's implementation

Our former implementation was rather ancient and was using unsupported
features of C.

* Fix Windows
2023-03-03 11:56:32 -08:00
Powei Feng
47135164ee vulkan: fix validation BestPractices-vkCmdBeginRenderPass-ClearValueWithoutLoadOpClear (#6608) 2023-03-03 11:14:05 -08: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
Mathias Agopian
7933b08e85 fix fog instability with strong falloff
The fog calculation could fail when the falloff was strong and the
camera z position was far from the fog height. The problem was
that the computation was spread between the cpu and gpu by splitting
an exp(), but with certain parameters the two exp() would independently
blow-up.  We fix this by doing the exp() only on the gpu side.
2023-03-01 16:48:16 -08:00
Mathias Agopian
a6809b4550 Fix fog's z origin
the fog's z origin was always the camera height instead of being the
ground (or more precisely the value of fogHeight).
2023-03-01 16:48:16 -08:00
Mathias Agopian
8f77308bca fix fog integral computation
1-a/b not the same as (1-a)/b !
2023-03-01 16:48:16 -08:00
Mathias Agopian
65f1e64812 fix fog heigh falloff computation
it was especially wrong when near or at 0.
2023-03-01 16:48:16 -08:00
Mathias Agopian
79942b3bea fog parameters should be calculated in highp 2023-03-01 16:48:16 -08:00
Mathias Agopian
9ee41b9b6a rework again how we manage different versions of GL
try to be more explicit about which configurations are supported,
and use the same pattern everywhere for checking the gl version at
either compile and runtime.
2023-03-01 15:59:04 -08:00
Mathias Agopian
21995e4ac9 clip_control could fail on desktop
This didn't happen in practice, but we would call (null) if the
clip_control extension was available and we were not on GL 4.1.

We "fix" this by not supporting the clip_control extension on desktop.
It doesn't matter because clip_control is core as of 4.5 and is 
present in only 8% of non 4.5 GL implementation, and this doesn't
include any macOS versions.
2023-03-01 15:59:04 -08:00
Mathias Agopian
8dc871c86e remove code for unused extensions 2023-03-01 15:59:04 -08:00
Benjamin Doherty
78785a5bca Release Filament 1.31.6 2023-03-01 11:23:37 -08:00
Mathias Agopian
662b4b5ca3 fix typo that could cause a OOB
fortunately this would only happen when using SSBOs (which are not
used currently).
2023-02-27 13:06:25 -08:00
Mathias Agopian
bee96d1cf1 abstract OpenGL's GLSync
This small abstraction is (will be) needed because GLES 2.0 doesn't
have sync object, however synchronization is sometimes available
externally, in particular with EGL.

This PR doesn't provide other implementations.
2023-02-27 12:40:21 -08:00
Mathias Agopian
122ebe1ccb More improvements to how we handle extensions (#6591)
- make sure to initialize all extension booleans, we treat them
  as feature flags.
- be more explicit about #define'ing gl tokens, so we can more easily
  catch errors later.
- don't blindly use extension tokens that might not be available
  (e.g.: GL_TEXTURE_EXTERNAL_OES or GL_TEXTURE_CUBE_MAP_ARRAY). It
  would probably cause a spurious gl error.
2023-02-24 16:52:43 -08:00
Mathias Agopian
e741e165ae remove unused / no longer used code 2023-02-24 16:50:15 -08:00
Mathias Agopian
d38dc24915 Cleanup how we get GL extensions entry-points
- iOS is treated the same way than Android now. The only difference
  is that iOS only provides prototypes and no typedef, whereas 
  Android only provides typedefs and no prototypes.

- Timer queries is core in GL and an extension on all versions of
  GLES. On iOS it's not available at the header level. An additional
  subtlety is that glGetObjectuiv is core in GLES 3.0, so it conflicts
  with the extension.
  So, now we do things correctly:
  - on desktop we use the core methods
  - on ios we ifdef out everything related to timer queries
  - on gles 2.0 and up we use only the extension entry-points
2023-02-24 11:55:22 -08:00
Powei Feng
d12612f091 Add UV-based tangent space algorithms (#6572)
Added mikktspace as a third party lib
2023-02-24 09:32:02 -08:00
Mathias Agopian
e6d73135c1 fix DEPTH_STENCIL case for fbo attachments
We were not testing for that case properly. This case is taken when 
either:
- depth & stencil textures are the same and not null
- or, only depth is specified but both attachments are requested


Also cleanup the dimension checks in debug builds.
2023-02-23 14:47:17 -08:00
Mathias Agopian
816612cf0a Fix readPixels() for "auto-resolved" MS color buffers
glReadPixel doesn't resolve automatically, but it does with the 
auto-resolve extension, which we're always emulating.
2023-02-23 10:56:08 -08:00
Mathias Agopian
7ca8ba272c don't rely on GL PACK/UNPACK convenience
- some of the convenience are not available in ES2
- it's less efficient
- we can save some PBO space when reading back
  a partial framebuffer.

We also avoid using GL_PACK_ROW_LENGTH which technically is not
a convenience, but in our case we are doing an extra copy anyways, so
we can account for the row-length at that point.
2023-02-23 10:55:46 -08:00
Mathias Agopian
d337a6d019 Scene::prepare is now multithreaded 2023-02-22 16:28:40 -08:00
Mathias Agopian
f79c4c6080 Improve directional shadow performance with large scenes
- We now call visitScene only once for the directional shadowmap instead of
1 + cascade_count times.

- Don't use visitScene for spot shadows

it was only used to compute the near/far planes, but instead we can
use the radius of the light. This could degrade the quality of the
spot shadows, but this can be corrected by setting a correct radius.

caveat: currently the near is hardcoded to 0.01 units. this should be
user-settable.

- Improve performance of visitScene calls

instead of transforming 8 points of an AABB and finding the min/max,
we transform the AABB and use its minz and maxz. This works for affine
transforms.

This change also cleans-up AABB and Box transform APIs, which also
are now inline.
2023-02-22 16:28:40 -08:00
Mathias Agopian
2e7fc6229b Improve StructureOfArray
- StructureOfArray: don't initialize trivial ctors

We mimic the behavior of std::vector<> here, where a resize() won't
initialize the array if the type is trivially_default_constructible.
This can reveal existing bugs, where we depended on the initialization
to 0.

- StructureOfArray: add push_back(std::tuple<>)

This basically allows us to push_back() a struct of the SoA.

- Make PerRenderableData trivially constructible

this improves performance when we have tons of objects in the scene
because PerRenderableData is used in arrays.
2023-02-22 16:28:40 -08:00
Mathias Agopian
fc724575fa Make SYSTRACE_CALL work with SYSTRACE_CONTEXT
SYSTRACE_VALUE now requires a SYSTRACE_CONTEXT.
2023-02-22 16:28:40 -08:00
Mathias Agopian
84716610b8 cleanup: make const everything that can be 2023-02-22 16:28:40 -08:00
Benjamin Doherty
29983772ed Release Filament 1.31.5 2023-02-21 13:16:09 -08:00
ViktorHeisenberger
d100e628c2 Invoke ccache on Win+ninja. There is no support for ENV vars. (#6582) 2023-02-21 09:19:03 -08:00
Mathias Agopian
94f121f37d Add a camera near/far setting in gltf_viewer 2023-02-17 11:16:42 -08:00
Mathias Agopian
d9266ba61c fix a main camera far plane culling
we need to use the culling projection matrix for culling!
2023-02-16 15:40:32 -08:00
Ben Doherty
8389056d2d gltfio: Fix crash when a MIME type has no texture provider (#6569) 2023-02-16 14:21:26 -08:00
Powei Feng
26b8cb238a Add build.sh flag for ASAN/UBSAN (#6566) 2023-02-16 13:19:32 -08:00
Powei Feng
f8d4690cd8 Update linux-continuous.yml to use ubuntu-22.04 (#6559) 2023-02-14 16:47:02 -08:00
Benjamin Doherty
c2e2f80945 Fix RELEASE_NOTES.md 2023-02-14 14:10:40 -08:00
Powei Feng
e9efcdf191 -Werror for libfilament and backend (#6547) 2023-02-14 01:15:25 -08:00
Mathias Agopian
8ea159520d workaround our -ffast-math
We use isnan() to detect that the estimation of directional light
parameters from the IBL has failed, however isnan() always returns
false with -ffast-math, which we're using in release builds.
This works around that. The affected code is non essential, performance
is not a concern here.
2023-02-13 21:51:43 -08:00
Mathias Agopian
337e18051a The default render channel is now 2 instead of 0
This also fixes some potential issues with refraction when using
render channels.
2023-02-13 17:31:34 -08:00
Ben Doherty
3c4e094990 Rework how release notes work (#6557) 2023-02-13 14:54:07 -08:00
Powei Feng
71e6f3d037 Update linux clang to version 10 (#6556) 2023-02-13 14:49:45 -08:00
Benjamin Doherty
d2690bf75a Release Filament 1.31.4 2023-02-13 11:51:06 -08:00
Ben Doherty
44f002a5a1 gltfio: Fix race condition affecting mobile and web (#6548)
When loading a glTF file on platforms without a filesystem, a client
calls `addResourceData` to populate `ResourceLoader`'s cache with data.
For example, a web client might make HTTP fetch requests to fill in
buffer data. This internal cache of data is stored in
`ResourceLoader::Impl::mUriDataCache`.

This works well, except the cache must persist until after it has been
uploaded to the GPU.

There was already a mechanism (see `uploadUserdata`) in place to ensure
that glTF data persisted until after it had been uploaded to the GPU.
However, this mechanism did not extend to client-provided data. Thus, a
race occured between Filament's driver consuming the buffer and it
getting freed.
2023-02-13 10:44:22 -08:00
Powei Feng
f8442c9ec0 vulkan: Remove unused presentQueueFamilyIndex (#6545) 2023-02-10 12:41:00 -08:00
Powei Feng
b3513c7d1f geometry: Add TangentSpaceMesh implementations (#6530)
geometry: Add TangentSpaceMesh implementations

Added:
 - Hughes-Moller
 - Frisvad's method
 - Flat shading
2023-02-10 09:34:49 -08:00
Mathias Agopian
a82e813333 fix libmath streaming operators 2023-02-09 16:11:30 -08:00
Powei Feng
dd246aeee4 vulkan: Assert that graphics-QF is present-QF (#6540) 2023-02-09 13:31:29 -08:00
Ben Doherty
1653d3615b Fix Metal crash due to empty program names (#6537) 2023-02-09 12:11:04 -08:00
Mathias Agopian
4847b00f9e improve SoA a bit
Instead of storing the arrays into an array of void*, we use a 
tuple<> instead. This improves debugging because now the tuple<>
has pointer with the correct types.

It also improves most of the code except `push_back` which now
relies on a hack -- this is the only place where I'm not able to 
resolve the array strictly at compile time, even if in practice it is.
2023-02-08 16:22:00 -08:00
Igor Korobka
d613145c1a Fix JNI after minification is applied
UbershaderProvider.getNativeObject() is accessed from AssetLoader.cpp,
so it must be annotated with @UsedByNative("AssetLoader.cpp") to
avoid runtime crashes when minification is applied.

Fixes #5944
2023-02-08 15:29:55 -08:00
ritik619
a788f66e18 Fixed typographic error 2023-02-08 12:01:50 -08:00
Romain Guy
9ca3a7456c Fix JNI 2023-02-08 09:07:59 -08:00
Mathias Agopian
5cec001058 matdbg: direct SPIRV edit now supported 2023-02-03 13:57:44 -08:00
Mathias Agopian
2fb42f5144 matdbg: refresh spirv properly
we now refresh the spirv code properly after it's rebuilt from the
glsl tab.
2023-02-02 11:10:21 -08:00
Mathias Agopian
02c22a668c matdbg: make sure we use the same spirv parameters everywhere 2023-02-02 11:10:02 -08:00
Mathias Agopian
a7bf90f5be build.sh -d is now split in two options
`-d` now enables matdbg and adds debugging data, but doesn't affect 
 material optimization

`-g` disables material optimizations


A similar change is done with gradle options. The new proprety
`com.google.android.filament.matnopt` is used to disable material
optimizations.

These options mimic `matc` options.
2023-02-01 23:59:00 -08:00
Mathias Agopian
f71e90fae0 deduplicate spirv disassembly code 2023-02-01 21:12:53 -08:00
Mathias Agopian
8afb11128d move UibGenerator and SibGenerator to the shader folder
The shader folder is where we generate the glsl, so this is more
appropriate.
2023-02-01 21:12:53 -08:00
Mathias Agopian
2e0c238cc6 We now require Vulkan 1.1 for the vulkan backend 2023-02-01 21:10:26 -08:00
Benjamin Doherty
03b89b4327 Release Filament 1.31.3 2023-02-01 11:53:41 -08:00
Mathias Agopian
a878d1f39c improve sample_full_pbr
- -m option now works with "directory_*.png" or just "*.png"
- "color" replaced by "albedo" to mach other places in the source tree
- fixed warnings
- clear the background when IBL is not used
2023-02-01 10:04:02 -08:00
Mathias Agopian
4a09e13e9d fix a couple typos and consts.
make it easier to activate matdbg on android builds, by adding, but
commenting out the appropriate property.
2023-02-01 10:03:20 -08:00
Mathias Agopian
0b4d32bf98 matdbg: use GLSL 4.5 on desktop when debugging spirv
GLSL 4.5 is closer to spriv than 4.1 and since this is just to 
"interpret" the spirv, 4.5 is fine.

Set the default precision for GLES though.
2023-02-01 10:03:20 -08:00
Mathias Agopian
b940fc9c48 update remote ui 2023-01-31 20:55:23 -08:00
Koncz Levente
2eb0dd7153 Sample Full PBR fixes (#6490)
* Calculate view vector without using camera eye position

* Fix compilation error (during parsing the material when a height map is passed in)

* Add SUN light to the scene
2023-01-31 12:28:25 -08:00
Mathias Agopian
101c7db9a2 update remote ui 2023-01-31 09:52:37 -08:00
Mathias Agopian
032ace2051 Add output color space to ColorGrading settings 2023-01-31 09:46:22 -08:00
Mathias Agopian
5754b9907d Add support for sRGB swapchains
This change adds a 'SRGB' config flag when creating a SwapChain that
enables linear to sRGB conversion on write.

When using this flag, the linear->srgb conversion in the color grading
post processing should be disabled (or, the whole post-processing
stage should be disabled).

There is also a new query to determine if this flag is supported by
the underlaying platform.

On Metal, this happens automatically when the underlaying layer is sRGB.

This reverts commit 3799e219fc.
2023-01-31 09:29:02 -08:00
Mathias Agopian
ffb8203ae7 Fix typo in ColorSpace operator= 2023-01-30 21:35:51 -08:00
Powei Feng
906da033dd vulkan: Add fallback extent for swap chain sizing (#6495)
vulkan: Add fallback extent for swap chain sizing
2023-01-30 19:29:10 -08:00
daemyung danny jang
1077405bc1 Support Windows32 on bluegl as C backend (#6499) 2023-01-30 15:56:15 -08:00
daemyung danny jang
e37df8fc89 Include a header in alphabetical order (#6507) 2023-01-30 14:58:56 -08:00
Mathias Agopian
3799e219fc Revert "Add support for sRGB swapchains"
This reverts commit eab14da30e.

This broke macOS desktop (and maybe other GL platforms).
2023-01-30 11:20:18 -08:00
Mathias Agopian
eab14da30e Add support for sRGB swapchains
This change adds a 'SRGB' config flag when creating a SwapChain that
enables linear to sRGB conversion on write.

When using this flag, the linear->srgb conversion in the color grading
post processing should be disabled (or, the whole post-processing
stage should be disabled).

There is also a new query to determine if this flag is supported by
the underlaying platform.


On Metal, this happens automatically when the underlaying layer is sRGB.
2023-01-30 10:49:38 -08:00
Mathias Agopian
84e999fe57 cleanup PlatformEGL config selection code
We now structure the code to assume we have EGL_KHR_no_config_context,
which is the common case. This allows use to decouple context creation
from swapchain creation.

We still handle the case where the extension is not present by always
selecting a transparent config.
2023-01-30 10:49:38 -08:00
Mathias Agopian
f22ff6a340 the createSwapChain flag shouldn't be a reference 2023-01-30 10:49:38 -08:00
daemyung danny jang
d9d0b93306 Fix a build error (#6502) 2023-01-30 10:38:36 -08:00
Powei Feng
09248cd451 Destroy FilamentInstance's mRoot in EntityManager (#6500) 2023-01-27 16:05:42 -08:00
Koncz Levente
73880428dc Ortho shading fixes (#6453) 2023-01-27 09:36:56 -08:00
Ben Doherty
2a049d1324 Initialize object_uniforms in depth shader (#6492) 2023-01-26 16:23:14 -08:00
Powei Feng
51cbd74235 Add missing STL includes (#6496) 2023-01-26 16:07:58 -08:00
Powei Feng
45246b6109 geometry: Add TangentSpaceMesh class outline (#6476)
- Defined class with documentation in comments
 - Implemented algorithm selection
 - No actual algorithms written yet

Part of google/filament#6358
2023-01-26 14:39:48 -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
Benjamin Doherty
298e54c32a Release Filament 1.31.2 2023-01-24 14:26:22 -08:00
Ben Doherty
4c82f0259d Add systrace support on Apple platforms (#6480) 2023-01-23 14:11:47 -08: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
Powei Feng
20cbecfd7c vulkan: put getEnabledLayers behind VK_ENABLE_VALIDATION (#6474) 2023-01-18 18:38:53 -08:00
Powei Feng
194defdb1b vulkan: Fix readPixels memory leak (#6473) 2023-01-18 16:35:58 -08:00
Benjamin Doherty
5017cbe67e Release Filament 1.31.1 2023-01-18 14:23:21 -08:00
Ben Doherty
4c4201cb72 Update check-headers script to ignore platform headers (#6472) 2023-01-18 13:53:45 -08:00
Powei Feng
3ee635f8e4 Fix enabledLayers (#6467)
instanceCreateInfo should not take stack-allocated data
2023-01-18 13:50:10 -08:00
Ben Doherty
4c2dabffd6 Vulkan: fix stack-use-after-scope ASAN error in VulkanContext.cpp (#6463) 2023-01-18 12:00:08 -08:00
Mathias Agopian
185c83dae2 Fix a crash on Vulkan with some Adreno drivers
We were using a specialization constant to size an array inside an
UBO interface block, which caused the crash in the Vulkan driver.

However, this specialization constant was only used to workaround a
Chrome bug on WebGL. Additionally, specialized array size inside blocks
are not fully supported in spirv.

This workaround simply replaces the specialization constant by a 
constant on Vulkan.

Fix #6444
2023-01-18 10:36:43 -08:00
Mathias Agopian
15d124b225 disable KHR_debug messages
there were never useful and in fact harmful, because confusing to our
users.
2023-01-18 10:35:48 -08:00
Mathias Agopian
9c474c5b08 remove too verbose log when auto-instancing 2023-01-18 10:35:31 -08:00
Mathias Agopian
f92f283e00 Fix a typo with auto instancing
fixes b/265831206
2023-01-17 16:42:26 -08:00
Mathias Agopian
f6b94614e8 Make all OpenGLPlatform related interfaces public
- Remove DefaultPlatform from public headers
DefaultPlatform is now PlatormFactory and is just an implementation
detail.

- VulkanPlatform is now public
- Improvements to the OpenGLPlatform interface
- Cleanup PlatformEGL and PlatformEGLAndroid

Also:

- reworked how external image worked so that all the implementation
  is contained in the Platform and no dependency to the backend is
  needed.

- MetalPlatform is now entirely private and final

This is because MetalPlatform wasn't an interface. We probably need one
so it could be customized in the future. But as it stands now it's
better to be private.
2023-01-17 16:39:44 -08:00
Ben Doherty
978517b057 Update actions/checkout version (#6454) 2023-01-17 09:59:19 -08:00
Levente Koncz
d911640809 Attempt to fix skybox shader in ORTHO view 2023-01-13 16:29:08 -08:00
Mathias Agopian
473e610430 reenable compute in the GL backend
We do some shenanigans so it works with API < 21 on android.
2023-01-13 16:00:56 -08:00
Mathias Agopian
3b9b725406 fix dynamic lighting with custom projections
Forxelization made many assumptions about the shape of the projection
matrix, the gist of these fixes is to remove those assumptions.

Fix #6390
2023-01-13 11:36:44 -08:00
Mathias Agopian
fa742bc6bf fix typos 2023-01-13 11:36:44 -08:00
Romain Guy
6a02dd0993 Update to Android Studio Electric Eel and AGP 7.4.0 (#6456) 2023-01-13 08:21:03 -08:00
Powei Feng
243d10f864 [vulkan] enumerate: Returning size = 0 is ok (#6450) 2023-01-12 12:56:34 -08:00
Romain Guy
bbe46071f3 Update Android dependencies (#6452) 2023-01-12 10:02:18 -08:00
Ben Doherty
8ded184ea3 Metal: add labels to aid debugging (#6451) 2023-01-12 09:55:43 -08:00
Romain Guy
ce407ba844 Fix typo 2023-01-11 08:48:04 -08:00
Powei Feng
ddb6a7fa93 Update Linux build instructions (#6438) 2023-01-10 16:42:44 -08:00
Benjamin Doherty
72bba47880 Release Filament 1.31.0 2023-01-10 12:50:17 -05:00
Ben Doherty
0c38b1e3f9 Add SPIR-V debugging guide (#6405) 2023-01-09 13:15:41 -08:00
Powei Feng
8de3de235b Refactor VulkanContext/Driver initialization (#6429)
* Refactor VulkanContext/Driver initialization

Move the initialization of VulkanContext fields to the class
itself. This will clean up how the various extension support
flags are deteremined.

Also disable debugUtils extension for Mesa driver (#6192).
2023-01-09 12:51:49 -08:00
Romain Guy
24e1eef56e Fix glTF volumes 2023-01-05 17:38:16 -08:00
Powei Feng
378fb92434 Re-land #1 "[vulkan] Refactor vkEnumerate methods (#6423)" (#6426)
* Re-land #1 "[vulkan] Refactor vkEnumerate methods (#6423)"

This reverts commit 6f7d203adb.
The above commit (6f7d20) is the revert of #6423. Commit
6f7d20 is PR #6425.

"[vulkan] Refactor vkEnumerate methods (#6423)" failed [here] due to
a missing function attribute (VKAPI_ATTR in bluevk) for ARM64
compilers.

[here]: https://github.com/google/filament/actions/runs/3841550984
2023-01-05 11:45:25 -08:00
daemyung danny jang
c7c184d952 Make a small optimization on drop event at filament app (#6424) 2023-01-05 08:38:28 -08:00
Powei Feng
6f7d203adb Revert "[vulkan] Refactor vkEnumerate methods (#6423)" (#6425)
This reverts commit 8d608830d4.

Reason: broke Android build -> https://github.com/google/filament/actions/runs/3841550984
2023-01-04 15:16:23 -08:00
Po
8d608830d4 [vulkan] Refactor vkEnumerate methods (#6423)
* [vulkan] Refactor vkEnumerate methods

Use templates to help clean up the enumeration a bit.
2023-01-04 12:58:18 -08:00
daemyung danny jang
6734dc6f43 Create a path from a string view (#6406) 2023-01-03 09:36:41 -08:00
Po
5343d504c4 [vulkan] Break when desired layer is found (#6403) 2022-12-21 13:29:26 -08:00
Nick Fisher
f8684beba2 expose joint inverse bind matrices via method on FilamentInstance (#6388)
* expose joint inverse bind matrices via method on FilamentInstance

* change const pointer refs, add asserts and update release notes

Co-authored-by: Mathias Agopian <mathias@google.com>
2022-12-20 15:19:19 -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
1f0b988472 Add Filamesh template for Hex Fiend 2022-12-20 10:07:33 -08:00
Romain Guy
60c264a2e7 Add Hex Fiend template for filamesh files 2022-12-20 10:01:56 -08:00
Benjamin Doherty
7724219f1e Fix Windows CI build 2022-12-20 11:01:10 -07:00
Ben Doherty
1d5ce4d1c2 Update spirv-tools to 025ea89 (#6393) 2022-12-19 15:42:42 -08:00
Mathias Agopian
9ff4a311ef fix typos 2022-12-19 15:22:49 -08:00
Benjamin Doherty
2f0bdd9c39 Release Filament 1.30.0 2022-12-19 11:11:45 -08:00
Ben Doherty
e1ba37b910 Fix memory leak in Scene (#6387) 2022-12-16 14:39:01 -08:00
Mathias Agopian
7448e7c3c5 CMakeLists minor cleanup 2022-12-15 15:19:31 -08:00
Mathias Agopian
ee6612ecfa Workaround for a bug in Adreno's shader compiler
At least some adreno compilers don't like returning an element of a
UBO array that is a structure in the vertex shader.
To work this around we have to copy the each of the structure fields.

Fixes #6355
2022-12-14 15:39:18 -08:00
Mathias Agopian
aa5504aad3 auto instancing wasn't applied in Settings. 2022-12-14 00:52:37 -08:00
Mathias Agopian
1523edd519 attempt to fix helmet web sample 2022-12-14 00:11:18 -08:00
Mathias Agopian
190d6faa67 attempt to fix web demos #4 2022-12-13 23:17:44 -08:00
Mathias Agopian
9f97ff4ced 3rd attempt at fixing web demos 2022-12-13 23:08:22 -08:00
Mathias Agopian
989e6c9198 2nd attempt at fixing the web demos 2022-12-13 22:54:29 -08:00
Mathias Agopian
9c19e746a4 attempt to fix webgl demos 2022-12-13 22:38:00 -08:00
Mathias Agopian
0a20be7097 update docs/remote 2022-12-13 22:25:17 -08:00
Mathias Agopian
0d72a0904b getNormalizedViewportCoord() now returns the logical viewport coords
This is a better user-facing API because materials don't need to know
about the physical viewport.
2022-12-13 16:37:49 -08:00
Romain Guy
7f9e7a4566 Update Web demos 2022-12-13 15:04:12 -08:00
Mathias Agopian
48d9f44291 Handle Vulkan and Metal shadow coordinates in the same way
Vulkan and Metal should be handled exactly the same within filament,
when it comes to texture-space and clip-space because filament
always transforms vulkan's clip-space to gl's/metal's).

Our shadow code took different paths, both equivalent though, but it's
confusing.
2022-12-12 15:21:35 -08:00
Mathias Agopian
b5d197dfe3 Fix unused variables in release builds 2022-12-12 12:30:33 -08:00
Mathias Agopian
1d387d04fd add a debug option for Renderer's buffer padding 2022-12-12 11:18:17 -08:00
Mathias Agopian
4215ba6476 code cleanup
fix new code quality warnings enabled by CLion
2022-12-09 11:05:26 -08:00
Mathias Agopian
5b2a92a5c4 fix a typo that caused a wrong allocation size
this only affect the WebGL build's readPixels.
2022-12-09 10:52:24 -08:00
Mathias Agopian
9661cd4c3a fix a race condition with acquired streams
The race coud lead to user after free and crashes.

We now keep a list of acquired streams with pending images on the 
main thread, and use that to update the streams synchronously in
beginFrame. We can then enqueue a command for the driver thread that
will look for that stream in the active list of textures with stream
attached. Race avoided.


The previous code used the later list from both threads.
2022-12-08 16:19:11 -08:00
Balazs Vegh
cc2580230f Add fallback return to uintToColorDebug() (#6364) 2022-12-08 09:00:23 -08:00
Romain Guy
2a69a892b0 Add TS definition for Engine.destroy (#6359)
* Add TS definition for Engine.destroy

* Update release notes
2022-12-07 16:18:45 -08:00
Mathias Agopian
34e5865941 fix TransformManager high precision mode
The residual would be corrupted when using transactions.
2022-12-06 14:18:33 -08:00
Mathias Agopian
07464c967b Add missing Scene::getIndirectLight()
Also add missing getSkybox in js bindings
2022-12-06 11:19:43 -08:00
Koncz Levente
c2fcaf7a6b Add RGTC + BPTC support (#6320)
* Add RGTC support
* Add BPTC support
2022-12-06 11:18:35 -08:00
Mathias Agopian
d8c9391498 fix clear options
When more than one view was used, only the first view was cleared with
the ClearOption. This was actually intended when the views are rendering
into the swapchain (e.g. post process disabled), but that's incorrect 
when the views render into intermediate buffers.

The clear flags are now associated with the actual rendertarget.
2022-12-02 15:24:40 -08:00
Romain Guy
78554d2319 Add new outputColorSpace() API to ColorGrading (#6342)
* Add new outputColorSpace() API to ColorGrading

This allows the application to select the desired output color space.
The default is set to Rec709-sRGB-D65 ("sRGB") but can be changed to
Rec709-Linear-D65.

Currently only the transfer function is taken into account and must
be either sRGB or Linear. Future updates will add support for
different gamuts and white points.

* Update release notes
2022-12-01 17:00:30 -08:00
Mathias Agopian
c2711d643e minor code cleanup 2022-12-01 09:37:10 -08:00
Mathias Agopian
913e3d32ee fix viewtest
- it didn't clear the swapchain
- added support for `-a` option
2022-12-01 09:36:46 -08:00
Mathias Agopian
f0b9c5fff4 Fix a WebGL program link failure
WebGL complained about:

Precisions of uniform block 'ShadowUniforms' member 
'ShadowUniforms.shadows.texelSizeAtOneMeter' differ between VERTEX and 
FRAGMENT shaders.


this field didn't have a precision qualifier, this might be specific to
WebGL or a Chrome bug, unsure. Either we fix it by specifying all
qualifiers.
2022-11-29 23:27:55 -08:00
ThomasGorisse
fe67404fd5 Fix typo in LightManager documentation 2022-11-28 14:56:22 -08:00
ThomasGorisse
555ed96918 Fix confusing typo in Camera documentation 2022-11-28 14:56:22 -08:00
Mathias Agopian
fc74154ffe Fix Android continuous and presubmit builds
Since cmake 3.25 LINUX is automatically set based on CMAKE_SYSTEM_NAME, 
which the android cmake files are setting to "Linux". This created an
inconsistant state in our build system.
2022-11-28 14:07:04 -08:00
Mathias Agopian
74e8ddaf95 Directional shadow improvements
Use a much more precise way to calculate the directional shadow frustum.
With very large scenes, we were losing the precision on the direction
of the light, and in some case even producing NaN in the matrix.

This partially addresses #6293
2022-11-28 10:25:06 -08:00
Benjamin Doherty
f05c7f1141 Fix CI build 2022-11-22 13:49:59 -08:00
ViktorHeisenberger
565d385132 Use Frisvad's method to compute tangent space from normals-only mesh input (#6313)
* Change tangent basis computation for normals-only to Frisvad's method

* Update RELEASE_NOTES.md
2022-11-22 09:30:37 -08:00
Benjamin Doherty
e2384f59a2 Release Filament 1.29.0 2022-11-21 15:44:09 -08:00
Mathias Agopian
f619b62877 Handle shadow borders better
All shadow maps need a 1-px border for different reasons.
The directional shadow needs a "not in shadow" border because it uses
the intersection of receivers and casters in light-space.
Other shadow types need a border because of bilinear access at the 
edges. Until now, the spot/point shadow border was handled with the
sampler's CLAMP.

Instead, now, we always generate a border and in one case we fill it
with "not in shadow" (by not rendering into it), in the other cases we
render the 2px larger shadowmap so we get completely correct bilinear 
filter.

Additionally, for PCF, DPCF and PCSS we use a large filter kernel which
accesses data outside the texture, until now this was handled with CLAMP,
but that failed (2 of the edges were not handled in the same way) when 
the shadowmap was smaller than the texture.
We fix this by clamping manually the texture coordinates.


The real motivation for these changes is to allow the use of a
shadow Atlas later.
2022-11-21 15:38:25 -08:00
Ben Doherty
22e5d15a17 Use GitHub script for release asset upload (#6308) 2022-11-21 10:25:20 -08:00
Mathias Agopian
77fcf4d260 don't store the light direction in the shadowmap structure
We already have it in the Light structure.
2022-11-17 11:07:47 -08:00
Mathias Agopian
46a8b242a8 don't set invalid viewport in gl backend
When width/height is converted to GLSizei, which is signed, it can
become negative, which happened with a "full" viewport.
On some GL implementation, this resulted in a failure.
2022-11-17 11:07:30 -08:00
Romain Guy
901d255026 Update README.md 2022-11-16 11:01:57 -08:00
Mathias Agopian
b3cf555eb2 fixup: better accounting of available shadowmaps 2022-11-16 09:20:59 -08:00
Mathias Agopian
594cce35c7 the 1-px border is only needed for the directional light 2022-11-16 09:20:38 -08:00
Mathias Agopian
8b96af8e3f AtlasAllocator improvements 2022-11-16 09:20:22 -08:00
Mathias Agopian
641a0bda9e spell specialization correctly 2022-11-16 09:20:00 -08:00
Mathias Agopian
b1e438e141 move vsm's MSAA sample count to the view settings
VSM's MSAA is no longer a "per light" setting, it is now global for
the whole view.
2022-11-14 15:29:08 -08:00
Mathias Agopian
a61338ff8b fix scissor override
don't forget to update the scissor state when setting the override.
2022-11-10 16:14:10 -08:00
Mathias Agopian
82da7dc999 minor cleanups 2022-11-10 15:46:24 -08:00
Joel Winarske
9f7bb14bd1 Enable CMake fo subdirectory use (#6287)
-Addresses issue where launch-c/launch-cxx is expected in CMAKE_BINARY_DIR

https://github.com/google/filament/issues/6285

Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
2022-11-10 15:18:21 -08:00
Mathias Agopian
6ec5fd86fa rework how we set the viewport for shadows
The viewport is now entirely handled by ShadowMap, that is, we're no
longer setting a viewport in the renderpass, instead the ShadowMap
uses a post projection transform to achieve the same effect.
This will become useful when store shadow maps in an Atlas.
2022-11-10 15:15:43 -08:00
Mathias Agopian
cf16bbe64b fix atlas allocator
it could return an orphan node, that is some of the parent in its
ancestry have no children.
2022-11-10 11:33:30 -08:00
daemyung jang
3da450a019 Include the windows.h header after packing alignment (#6280) 2022-11-10 11:02:45 -08:00
Ben Doherty
66276710f4 Fix memory corruption in FScene (#6282) 2022-11-10 10:44:58 -08:00
Benjamin Doherty
957380b258 Release Filament 1.28.3 (ignore prev commit) 2022-11-09 16:41:13 -08:00
Benjamin Doherty
fe3f16924d Release Filament 1.29.0 2022-11-09 16:37:39 -08:00
Ben Doherty
ffc3128377 Skip rendering renderables with missing geometry (#6281) 2022-11-09 16:35:02 -08:00
Mathias Agopian
c05e2ec47d improve variant filter
- variant filter didn't filter the VSM variant of depth variants

Fix #6274
2022-11-08 16:48:54 -08:00
Mathias Agopian
9768f49714 unify point and spotlight shadows
point light shadows are not sampled just like spotlight shadows, the
only difference is that we're calculating the face first to access the
corresponding shadowmap data (including the light transform).
2022-11-08 16:35:54 -08:00
Mathias Agopian
6c54cfe88a Shadowmaping code improvements
- the layer is now stored in the shadow ubo
- we now have one shadow ubo per face
- ShadowMap holds UBO index even for cascades
- move some shadow "view" uniforms into the shadow UBO
2022-11-08 15:25:33 -08:00
Mathias Agopian
2dc8d6bcc0 minor cleanups, comment fixes
- update comments
- remove unused or unneeded methods
2022-11-08 15:25:33 -08:00
Balazs Vegh
08dc398452 Fix skipped depth bias set on Metal (#6276) 2022-11-07 11:26:53 -08:00
Benjamin Doherty
cd180c9a44 Update Python requirements.txt to fix CI 2022-11-04 11:35:10 -07:00
daemyung jang
0a7fe52124 Trim a whitespace (#6272) 2022-11-04 08:36:36 -07:00
Mathias Agopian
b71faf47cc fix shadow cascades
breakage was due to an uninitialized variable at the beginning of the
frame, caused by a recent change.

shadows would disappear when cascades were used with 'stable' shadows.
2022-11-03 13:48:09 -07:00
Ben Doherty
67babceb73 Fix backend_test to work with Metal arg buffers (#6135) 2022-11-03 11:04:29 -07:00
Ben Doherty
8e13fc86d5 Expose missing ColorGrading::Builder methods to JS (#6262) 2022-11-03 11:04:06 -07:00
Mathias Agopian
351c8e0972 fix spotlight attenuation
Spotlight attenuation was computed only when shadowing was enabled.
2022-11-03 10:34:39 -07:00
Benjamin Doherty
dc44e20be0 Fix RELEASE_NOTES 2022-11-03 09:57:21 -07:00
daemyung jang
e64b498d6e Update a comment about the range of morph target weight (#6265) 2022-11-03 09:19:01 -07:00
Mathias Agopian
31ab4a13c9 fix recently introduced crash on init
certain material properties can only be set if supported by the 
material.
2022-11-01 13:23:52 -07:00
Benjamin Doherty
e9728dcc8d Fix iOS build 2022-11-01 15:03:44 -04:00
Mathias Agopian
40a3644086 Reduce the size of ShadowMap to 40 bytes from 2KB+
ShadowMap had recently inflated due to its internal use of 
PerViewUniforms, which keeps a shadow copy of the uniform data. This
copy is not needed for ShadowMaps.
2022-11-01 11:58:28 -07:00
Mathias Agopian
41ef71abdf Add MaterialInstance getters for overridable properties (#6243)
In addition to the new getters, this change fixes the duplication of
a MaterialInstance, which didn't carry along the following states:
  - alpha mask threshold
  - specular AA threshold
  - specular AA variance
  - double sidedness

TODO: stencil state, polygon offset and scissor are stil not queryable
2022-11-01 11:22:01 -07:00
daemyung jang
3b40e52c98 Recompute bounding boxes with morph targets (#6246)
* Recompute bounding boxes with morph targets

* Reduce the number of heap allocation while recomputing bounding boxes

Co-authored-by: Romain Guy <romainguy@curious-creature.com>
2022-11-01 11:20:28 -07:00
daemyung jang
de8c7969f3 Return the correct permit type corresponding to the component type (#6255) 2022-11-01 11:03:27 -07:00
Benjamin Doherty
f2c049222b Release Filament 1.28.2 2022-11-01 13:01:13 -04:00
Ben Doherty
be30ac1fcb Fix G3 reported ubsan warning (#6257) 2022-11-01 12:50:27 -04:00
Ben Doherty
c5cc7fe26a Metal: generate argument buffer structures ourselves (#6242) 2022-11-01 12:44:42 -04:00
Ben Doherty
d04b0a5c73 Update Vulkan headers to v1.3.232 (#6256) 2022-11-01 12:38:23 -04:00
Mathias Agopian
72ab2aef0a fix UBO handle leak with ShadowMap
This wasn't a big issue because the "leak" would be cleaned when the
engine is destroyed.
2022-10-31 11:29:46 -07:00
Koncz Levente
1527bb7ad3 Preserve iOS stack traces (#6240) 2022-10-31 13:58:31 -04:00
daemyung jang
8cb26fc9ac Fix a build error on Android
The size of struct could be different on each architecture.
2022-10-30 20:52:56 -07:00
Matt Vera
c21794d0a0 Add Vulkan GGP platform. (#6235)
* Add GGP vulkan platform.

* Add release note for GGP support
2022-10-28 11:53:29 -07:00
daemyung jang
1a6338569a Calculate primitive's AABB correctly (#6232)
AABB of morph target is displacement data so it should be added to
primitive's base AABB.

Co-authored-by: Mathias Agopian <mathias@google.com>
2022-10-28 11:51:02 -07:00
Mathias Agopian
c5ebe1a88a skip primitives with FRONT_AND_BACK face culling 2022-10-28 11:50:21 -07:00
Mathias Agopian
a3f2028ae4 Reduce the size of PerViewUniforms by 24 bytes
This seems a bit pointless because PerViewUniforms has a 2KB field,
however, it adds up now that it's used by ShadowMap.
2022-10-28 11:49:55 -07:00
Mathias Agopian
c393ee4591 Each shadowmap now manages its own UBO
Instead of constantly reusing the View's UBO, each shadowmap now
manages it own. All UBOs for all shadow maps are updated together, 
then later during rendering, we're simply binding the correct UBO.
This change will be needed later so that we can update several
shadow maps in a single texture.

There are two main changes to achieve this:
1. ShadowMap now has PerViewUniforms object
2. For point lights, each face now has a ShadowMap object

One consequence is that ShadowMap is now very large (over 2KB). This
will be addressed later.
2022-10-28 11:49:55 -07:00
Mathias Agopian
83a82ae10e shadowing: store Executor instead of whole RenderPass
We didn't need to store the actual RenderPass for each shadowmap pass,
the executor is enough. This might prevent some mistakes later.
2022-10-28 11:47:12 -07:00
daemyung jang
676694e458 Fix glTF breaking issue (#6239) 2022-10-28 09:56:01 -07:00
Mathias Agopian
2ca218928f utils: get rid of GrowingSlice
it's just not used anywhere. change the implementation of Slice<> to
use two pointers.
2022-10-27 22:48:45 -07:00
Philip Rideout
776ce223fc Fix incorrect Vulkan documentation wrt layouts. 2022-10-26 19:18:32 -07:00
Philip Rideout
0d4d1f55c9 Updates to the Vulkan architecture doc. 2022-10-26 19:18:32 -07:00
Romain Guy
d6dba71ace Update docs 2022-10-26 12:28:56 -07:00
Mathias Agopian
61ee11ae6c fix the doubleSided property documentation (#6228)
* fix the `doubleSided` property documentation

* Update Materials.md.html

Co-authored-by: Romain Guy <romainguy@curious-creature.com>
2022-10-26 12:28:03 -07:00
Mathias Agopian
90f32e7277 A basic POT 2D allocator
This 2D allocator only supports power-of-two, square allocations. It
uses a quadtree to store the allocated regions.

The quadtree implementation currently has a fixed depth (templated).

The allocator does a best-fit match, but currently doesn't implement a
free method.
2022-10-26 11:02:17 -07:00
daemyung jang
b85d9afdb3 Remove an useless whitespace (#6226) 2022-10-26 00:10:33 -07:00
Mathias Agopian
4297d43d9a more improvements to RenderPass
- RenderPass::Executor now only executes the commands, it doesn't 
  create a backend render pass anymore. This is still done in the
  RenderPass::execute() helper.

- scissor and poloyon offset overrides are now set on Executor because
  they are not needed to generate the commands.
2022-10-25 14:38:56 -07:00
Mathias Agopian
cfcf714c21 Get rid of PrimitiveType::NONE 2022-10-25 14:38:08 -07:00
Benjamin Doherty
f7cfc6a65e Release Filament 1.28.1 2022-10-25 13:07:56 -04:00
Benjamin Doherty
4ead3bcebf Force spirv-cross to keep Metal argument buffer equal sized 2022-10-25 12:07:24 -04:00
Balazs Vegh
21e0677039 Check GPU support for depth resolve on Metal (#6220) 2022-10-25 11:55:17 -04:00
Ben Doherty
107b5a4854 Metal: fix microshadowing artifacts (#6221) 2022-10-24 19:12:14 -04:00
Balazs Vegh
9761b65137 Fix Metal unused variable warning (#6217) 2022-10-24 12:41:58 -04:00
Ben Doherty
b1831d2786 Fix, don't use encoder.device (#6212) 2022-10-20 13:05:07 -04:00
Benjamin Doherty
977d369e40 Fix unused variable warnings 2022-10-19 12:44:07 -04:00
Josh Faust
5cf5b25175 Add a function to reset internal GL backend state (#6105)
This allows bug-free integration with external renderers in WebGL

See https://github.com/google/filament/issues/6091
2022-10-19 09:31:11 -07:00
Ben Doherty
e75c3020c8 Initial support for Metal compute shaders / SSBOs (#6189) 2022-10-18 16:21:57 -04:00
k1rnt
aeb0a4008d fix(ci): replace set-output to GITHUB_OUTPUT (#6195) 2022-10-18 13:41:25 -04:00
Benjamin Doherty
2d43ad59ec Revert Android API_LEVEL change
glDispatchCompute requires Android API level 21, however bumping our
required minimum from 19 to 21 caused some clients' builds to fail.
Commenting-out that line for now to proceed with the 1.28.0 upgrade.
2022-10-18 13:34:50 -04:00
daemyung jang
f86ec07c45 Fix ios hello-gltf runtime errors 2022-10-18 10:19:22 -07:00
Ben Doherty
fc012d6d65 Metal: fix use-after-free ASAN error (#6203) 2022-10-17 19:13:36 -04:00
Philip Rideout
6b71232e38 matc / matinfo / filamesh: add vulnerability message 2022-10-17 15:49:35 -07:00
Philip Rideout
e157023fc1 Use mField style for fields in FFilamentInstance 2022-10-17 15:49:19 -07:00
Philip Rideout
6e38db882f Fix installed IBL location for desktop.
Fixes #6193
2022-10-17 12:30:11 -07:00
daemyung jang
09600699cb Update README.md 2022-10-17 09:57:58 -07:00
daemyung jang
6a5e74f031 Update README for meshoptimizer 2022-10-17 09:57:58 -07:00
daemyung jang
795bd1e995 Fix build errors in ios samples 2022-10-17 09:57:58 -07:00
daemyung jang
784416f658 Support glTF EXT_meshopt_compression 2022-10-17 09:57:58 -07:00
daemyung jang
b151afe567 Update meshoptimizer to version 0.18 2022-10-17 09:57:58 -07:00
Mathias Agopian
117ae1d648 RenderPass doesn't store an FEngine anymore 2022-10-14 15:59:03 -07:00
Mathias Agopian
7165d8aa54 fix a directional light shadowing issue
the shadow frustum could be be smaller than expected.
2022-10-14 13:16:14 -07:00
Ben Doherty
6b461b2d89 Metal: fix simulator regression due to arg buffers (#6181) 2022-10-13 14:34:33 -04:00
Benjamin Doherty
affc5be840 Release Filament 1.28.0 2022-10-13 12:35:45 -04:00
Ben Doherty
e3ff5616ef G3 fixes for 1.28.0 (#6174) 2022-10-11 17:02:46 -07:00
Mathias Agopian
d9a401d57e Reduce size of ShadowMap object
- remove mEngine from ShadowMap
- remove storage of ShadowMapInfo in ShadowMap
- ShadowMap::render should be on ShadowMapManager
- remove more attributes from ShadowMap

ShadowMap is now reduced to 32 bytes.
2022-10-10 13:03:36 -07:00
Mathias Agopian
acd5823953 Add support for point light shadows
[experimental]
2022-10-10 13:03:36 -07:00
Mathias Agopian
9b13565750 spotlight shadow map skipped if the scene is empty. 2022-10-10 13:03:36 -07:00
Mathias Agopian
734d8ff85c rename upcast() to downcast()
it was down casting all along!
2022-10-07 17:50:56 -07:00
Mathias Agopian
a02ef1a6c7 Remove the limit to 14 spot shadow maps, now 64.
Spotlight shadow maps are now limited only by h/w limits (UBO size and
2d array maximum layers), which works out to about 146 shadows.

In practice we hardcode the limite to 64, but this can be changed at
compile time. A higher maximum increases memory usage.

There used to be a bitfield per renderable with a bit for each shadow
map indicating if the renderable was "visible" from this light. The
limit to 14 came from that bitfield. All shadow maps used to be culled
first, setting the bitfield appropriately.

Instead, we are now processing spotlight shadows one at a time,
performing culling as we go. For this reason we don't need a bit per
shadow map.
2022-10-07 14:07:51 -07:00
Mathias Agopian
f13bf11d0f simplify command generation
No need to generate a sentinel command in the main loop when a 
command is canceled, this is now done automatically at a higher level.
The main benefit is that we can reject renderables that are not visible
a bit faster.
2022-10-07 14:07:51 -07:00
Ben Doherty
7d0b5fed8f Fix Metal argument buffer encoding (#6150) 2022-10-07 13:53:26 -07:00
Philip Rideout
e1f51f04c1 Vulkan: fix black screen regression
The VulkanProgram constructor was bailing out early and emitting a
warning because it saw that one of the stages wasn't fulfilled.
However it's okay for a pipeline to be missing a compute program.

Fixes regression that started with fabba73b1.
2022-10-04 10:47:16 -07:00
Philip Rideout
f6d74be123 Fix windows build. 2022-10-03 12:35:35 -07:00
Philip Rideout
50a1935b68 Vulkan performance improvements for readPixels. 2022-10-03 09:54:35 -07:00
Mathias Agopian
694ecce150 fix shadowing when the scene is outside the "shadow" view frustum
this case was causing uninitialized variables to be used creating a
false positive "shadows on" in the first cascade.

The main change here is to bail out as soon as we know there is no shadowing.
2022-09-30 16:12:36 -07:00
Mathias Agopian
3e3bd2722f fix lispsm when camera and light direction are aligned
in that case we have to revert to the ortho projection
2022-09-30 16:12:15 -07:00
Mathias Agopian
44fdf83e4c fix multiview mode in gltf_viewer
The "shadow" camera now works again.
2022-09-30 16:12:15 -07:00
Benjamin Doherty
99c4ce67e4 Print warning when Metal reaches memoryless geo limit 2022-09-30 13:59:49 -07:00
Balazs Vegh
71aceec4cf Memoryless storage mode with fallback (Metal) (#6124) 2022-09-30 13:54:54 -07:00
Philip Rideout
98e4cdbd4c gltfio ubershader mode: fix re-loading.
Fixes #6128
2022-09-30 13:54:36 -07:00
Mathias Agopian
86ef0109f4 use the correct gaussian blur shader
we attempted to select a shader which processed the required number of
component, but were always selecting the 4-components version.

this should improve blur performance for VSM.
2022-09-30 13:30:15 -07:00
Mathias Agopian
b4142261c2 trivial typo and ide warnings fixes 2022-09-30 13:30:15 -07:00
Mathias Agopian
359624e8eb Fix gaussian blur kernel computation
This improves significantly VSM shadows with blur,
 but will also improve SSR and the flare.
2022-09-30 13:30:15 -07:00
Mathias Agopian
5bcc11d9e8 fix typo that broke the VSM blur radius setting 2022-09-30 13:30:15 -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
fc484bd319 fix "stable" shadows
We were always adjusting the near/far of the view volume based on the
scene content for shadowing, which defeated the "stable" shadows.

Also changed the default cascade splits from a linear split to a
log2 split, because due to the perspective projection, the log2 split
actually looks linear. Also intuitively, it makes more sense to give
more resolution to the shadows close to the camera.
2022-09-30 12:00:02 -07:00
Mathias Agopian
9c4783142e matc: minor cleanup 2022-09-29 19:34:07 -07:00
Mathias Agopian
4dc03318e8 break circular dependency between Package and Flattener 2022-09-29 19:34:07 -07:00
Philip Rideout
15ba54c4c5 Update README wrt Android Studio Version. 2022-09-29 16:28:50 -07:00
Philip Rideout
342138aecb gltfio: Update Java API. 2022-09-29 16:28:50 -07:00
Philip Rideout
9f53c62e06 gltfio: Update Web API.
Java API changes will come next.
2022-09-29 16:28:50 -07:00
Philip Rideout
2d996033e3 gltfio API change part 2: remove asset-level animator 2022-09-29 16:28:50 -07:00
Philip Rideout
9fa6dc4131 gltfio API change part 1: move all MaterialInstance methods to FilamentInstance 2022-09-29 16:28:50 -07:00
daemyung jang
4930227743 Fix a crash by setting not exist material parameters on ubershader (#6122)
* Fix a crash by setting not exist material parameters on ubershader

* gltfio: add getFeatureMap, remove logic for dummy textures

Co-authored-by: Philip Rideout <philiprideout@gmail.com>
2022-09-29 15:51:35 -07:00
Benjamin Doherty
fbfcce563d Release Filament 1.27.2 2022-09-29 13:11:43 -07:00
Ben Doherty
7f5ad3743b Fixes for 1.27.2 release (#6125) 2022-09-29 13:08:00 -07:00
daemyung jang
981020e72b Get the morph target buffer to the given primitive 2022-09-29 13:01:42 -07:00
Mathias Agopian
7c1a705a07 reduce setSarameter(texture) calls 2022-09-28 22:10:27 -07:00
Mathias Agopian
3d53ae583f switch our min sdk from 19 to 21
this is so that we can support OpenGL ES3.1
2022-09-28 22:08:27 -07:00
Mathias Agopian
dc9f03cbd0 don't attempt to use more texture units than present
to emulate the bindless API in the gl backend we always used the highest
texture unit available. However at feature level 3, we support up to 62
textures, so the that max was bumped to 62 -- however, where we're not
on a feature level 2 device, that texture unit doesn't exist.

Instead we now always use binding 31, which is guaranteed to exist by 
EGL's minspec.
2022-09-28 22:05:05 -07:00
Philip Rideout
de7bca7ef8 gltfio: fix occlusion strength
Fixes #6106
2022-09-28 17:42:29 -07:00
Ben Doherty
f151f56a2e Metal: use argument buffers for SamplerGroups (#6093) 2022-09-28 16:50:11 -07:00
Ben Doherty
fe3d1713a4 Fix generic/Mutex.h not installed on Linux (#6117) 2022-09-28 16:36:38 -07:00
Joel Winarske
2cad3be7a3 Wayland FilamentApp
- move Wayland specific code into getNativeWindow
- make wayland struct static

Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
2022-09-28 16:14:01 -07:00
Thomas Gorisse
5262512eea Fix JNI for TransformManager.getChildren() (#6116) 2022-09-28 11:27:35 -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
daemyung jang
d291ec739b Update cgltf to version 1.13 (#6099) 2022-09-23 11:52:57 -07:00
Mathias Agopian
0dc0bbd4f3 LiSPSM is now a user settable option 2022-09-22 09:35:45 -07:00
Mathias Agopian
984a029ce4 fix (again) the box-frustum intersection
it is not true that the whole box is inside the frustum if we have
8 vertices and some frustum vertices are in the box -- that's even
non-sensical.

We now test for this case by checking that we have all (8) vertices of
the box inside the frustum.

This caused some shadows to be missing.
2022-09-22 09:35:28 -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
Mathias Agopian
cc64704a82 fix buffer overflow filamat
b/247447117
2022-09-20 16:45:45 -07:00
Benjamin Doherty
df2ad99260 Release Filament 1.27.1 2022-09-20 11:04:07 -07:00
Mathias Agopian
fb1f277b9a attempt to fix android build again 2022-09-20 09:11:42 -07:00
Mathias Agopian
0388161464 fix android debug build 2022-09-19 23:03:12 -07:00
Ben Doherty
e989d5603f Add MetalRingBuffer for future argument buffer management (#6087) 2022-09-19 16:18:54 -07:00
Mathias Agopian
defaa0d008 use ES3.1 headers
We now compile with ES3.1 headers but we make sure we can still compile
with ES3.0 headers (still needed for iOS).
2022-09-18 20:37:43 -07:00
Mathias Agopian
e161ba80f2 cleanup: move string_view over string uses 2022-09-16 18:31:48 -07:00
Philip Rideout
034aaff56c gltfio: FilamentInstance owner is now const.
In the future, we will allow instances to be constructed from
immutable assets (this is a Google feature request) so this PR
prepares for that.
2022-09-16 16:32:49 -07:00
Mathias Agopian
b0fb52c5f4 matinfo: fix feature level print output 2022-09-16 16:22:25 -07:00
Philip Rideout
a05f9c172f gltfio: change instancing behavior for punctual lights 2022-09-16 15:32:18 -07:00
Ben Doherty
adde936d18 Update glslang to c0cf8ad87 (master) (#6076) 2022-09-16 12:29:56 -07:00
Philip Rideout
feda999eb3 matinfo and filamesh: misc ASAN fixes 2022-09-15 17:23:54 -07:00
Romain Guy
8dae181c2f Upgrade AGP and dependencies including plugins (#6078)
This moves to a new, maintained Maven publishing plugin.
2022-09-15 16:05:18 -07:00
Philip Rideout
8cdac431a6 Vk getFeatureLevel() should use maxPerStageDescriptorSamplers 2022-09-15 13:51:10 -07:00
Romain Guy
0ecf5118ba Update docs 2022-09-14 20:18:27 -07:00
Philip Rideout
f21638a1e2 gltfio: fix material-free assets 2022-09-14 16:54:27 -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
Mathias Agopian
a8765b1dc0 fix some trivial ide warnings 2022-09-14 16:53:43 -07:00
Philip Rideout
d346b94b8a gltfio: fix regression with recomputeBoundingBoxes() 2022-09-14 16:53:20 -07:00
Philip Rideout
c4abe4f46a gltfio: allow zero-instance assets.
This is a feature request from Google. It allows users to "preload" an
asset, ie you can now create all VertexBuffer objects, Texture objects,
etc, without actually creating any entities or renderable components.

In the past we used TransformManager to help out with computing the big
asset-level bounding box, but now we use `gltf_node_transform_world()`
because entities might not yet exist.

One minor side effect is that `FilamentAsset::getBoundingBox()` now
returns the AABB that was determined at load time, and does not account
for instances. As a result, our `gltf_instances` sample app looks
slightly different but this is expected.
2022-09-14 16:40:47 -07:00
Philip Rideout
ad6a5eb4e1 Vulkan samplers: fit incorrect bitset logic.
In VulkanPipelineCache, `getShaderStageFlags()` and `getUsageFlags()`
are used to track which samplers are used in the VERTEX stage and which
are used in the FRAGMENT stage. The recent change I made was incorrect
because it did not account for samplers that are used in BOTH stages.

This fixes the recent regression where we see validation errors when
running `gltf_viewer` in ubershader mode.
2022-09-14 15:21:26 -07:00
Mathias Agopian
c84834d666 bump max sampler count to 62
This is needed for feature level 2.
2022-09-13 10:49:21 -07:00
Benjamin Doherty
334fe70d6c Release Filament 1.27.0 2022-09-13 10:14:02 -07:00
Philip Rideout
3b4fbaccc9 gltfio: fix regression when textures are "shared"
Some (poorly authored) glTF assets have several `image` elements
that all refer to the same URL or buffer view. When this occurs,
we create only 1 Filament Texture.

These assets regressed after PR 6051, which consolidated the texture
related fields in `FilamentAsset`, but did not include an ownership flag
in the new `TextureInfo` struct.
2022-09-12 16:00:24 -07:00
Mathias Agopian
58401e0b6e Fix FilamentApp multiview mode in gltf_viewer
- fix View::setVisibleLayers to match code. By default only layer 0
  is active, despite the documentation stating otherwise.

- add a helper to enable/disable layers more easily

- don't use layer 0,1,2 for the overdraw function as they were used by
  FilamentApp in "multi view" mode.
2022-09-12 15:55:16 -07:00
Mathias Agopian
3496f3a8ba rename ShaderType to ShaderStage 2022-09-12 15:54:07 -07:00
Mathias Agopian
441708ea12 Make ShaderStage an enum class 2022-09-12 15:54:07 -07:00
Mathias Agopian
ba8abb9031 scissor improvements
- improve scissor documentation, specify coordinate system and
  clipping behavior
- scissor now takes the guard bands into account
- on the backend side the scissor is no longer clipped to the viewport
- clipping to the viewport is now done on the filament side
- don't set scissor when material instance doesn't specify one
  (common case)
2022-09-12 12:45:36 -07:00
Ben Doherty
2718a22f64 Add return case to fix G3 compiler error (#6062) 2022-09-12 12:34:23 -07:00
Philip Rideout
85fb4be37e gltfio: use BitmaskFlags for sRGB
This PR also contains a small change in ResourceLoader::createTextures
that will permit zero-instance assets (an upcoming gltfio feature).
2022-09-12 12:27:01 -07:00
Mathias Agopian
f772c92eed fix typo in spotlight attenuation doc 2022-09-12 12:04:35 -07:00
Philip Rideout
cd58d39eb9 Vk cleanup: incorporate code review feedback. 2022-09-09 13:00:49 -07:00
Philip Rideout
2d730a4618 Vk cleanup: remove dummy samplers. 2022-09-09 13:00:49 -07:00
Philip Rideout
da6d17531c Vk: do not provide descriptors for unused samplers. 2022-09-09 13:00:49 -07:00
Philip Rideout
37b9b182b1 gltfio: prep step for allowing zero-instance assets
AssetLoader now loads assets in two passes:
- Pass 1 creates VertexBuffer objects, MorphTargetBuffer objects, etc.
- Pass 2 creates entities, renderables, etc (only if numInstances > 0)

This feature will help us integrate gltfio with an internal library at
Google.
2022-09-09 09:21:33 -07:00
Romain Guy
eaa86060e2 Fix memory leak (#6056)
This change fixes #6055
2022-09-08 20:57:46 -07:00
Philip Rideout
5e128214fa Vk: When the layout requirement change, the pipeline is "dirty".
Also, there's no such thing as a "bound layout".
2022-09-08 16:40:49 -07:00
Philip Rideout
9a7b967889 Rename mResult to mAsset. 2022-09-07 16:28:30 -07:00
Philip Rideout
5e498e7442 gltfio: big simplification for textures + add sRGB related assert.
The asset previously had three confusing fields related to textures:
mTextures, mTextureSlots, and mTextureBindings.

These are now consolidated into a single field, which simply has one top
level array item per `cgltf_texture`.

The memory footprint is smaller because we no longer bother to store
`TextureSampler` objects, instead we simply defer their construction
until calling setParameter.

Last but not least, we now assert in debug builds if the usages of a
particular texture have inconsistent sRGB flags. In the past,
inconsistent sRGB would be silently ignored.

In other words, we will now assert if you try to use the same texture
for `baseColor` and `normalMap`, whereas in the past we would simply
exhibit non-deterministic behavior in this situation (with respect to
sRGB semantics).
2022-09-07 16:28:30 -07:00
Mathias Agopian
25990ecd37 FilamentApp sets the feature level to highest allowed
There is also a new option to override the default with a lower
feature level. This is used in gltf_viewer only at the moment.
2022-09-07 15:32:58 -07:00
Mathias Agopian
ead5a97871 make AutomationEngine feature level aware
this basically just adds an Engine* parameter too all applySettings
methods
2022-09-07 15:32:58 -07:00
Mathias Agopian
a66495b2e0 fix setting spec constants in gl backend
a failure could happen if a comment contained the word `#extension`
2022-09-07 15:32:58 -07:00
Philip Rideout
f83172f9f9 gltfio MaterialProvider: add new method for getting Material
gltfio can now ask the material provider plugin which `Material` would
be used for a given set of requirements.  Prior to this change, gltfio
could only create a new `MaterialInstance`.

This method is necessary to support an upcoming gltfio feature.
2022-09-07 12:08:55 -07:00
Philip Rideout
80a957c1e3 gltfio: do not clear out the texture slots too early.
This broke asyncGetLoadProgress() and caused WebGL to crash reliably
because ResourceLoader got destroyed too soon.

Bug was introduced with de7dfc2ea6.

I intend to cherry pick this to rc/1.27.0, which is where it was
introduced, so there's no need to update the release notes.
2022-09-07 08:29:07 -07:00
Philip Rideout
e983169b35 gltfio: fix crash when material is unspecified 2022-09-07 08:28:36 -07:00
Mathias Agopian
b21d633c0c check that user materials don't exceed their allowed features (#6030)
* check that user materials don't exceed their allowed features

* backend sampler limits now take feature level into account


- in the backend, the constants are now in an array indexed by the 
  feature level

- samplerBindingMap now asserts only what it can.

- matc (filamat) now logs the user samplers when an error is detected.
2022-09-02 16:37:19 -07:00
Ben Doherty
f538d028d5 In debug builds, verify destroyed textures aren't in sampler groups (#6029) 2022-09-02 14:32:53 -04:00
Ben Doherty
4e15b7abc2 Add overdraw visualization to gltf_viewer (#6018) 2022-09-02 12:33:26 -04:00
Thomas Gorisse
e80ea5eae2 Add JNI for TransformManager.getChildCount(), TransformManager.getChildren() and Scene.hasEntity() (#6007)
* Add JNI for TransformManager.getChildCount(), TransformManager.getChildren() and scene.hasEntity()

* Update RELEASE_NOTES.md

* Fixes

* Change getChildren to take a nullable array

* Remove no params TransformManager.getChildren()

* Update RELEASE_NOTES.md

Co-authored-by: Ben Doherty <benjdoherty15@gmail.com>
Co-authored-by: Ben Doherty <bendoherty@google.com>
2022-09-01 11:22:44 -07:00
Mathias Agopian
6215050086 Fix a "dangling" texture in a SamplerGroup
One of the bloom texture ended-up dangling in the material's
SamplerGroup. That sampler group was never used to draw with, but was
made active which caused problem with the backends.


Also make sure the public API can unset a texture in a MaterialInstance
by passing nullptr for the texture.
2022-09-01 11:21:41 -07:00
Mathias Agopian
1fdb44ff42 graphvizify should only be implemented on debug builds 2022-08-31 17:17:38 -07:00
Ben Doherty
1768a2f8b7 Fix uberarchive not included in PodSpec (#6024) 2022-08-31 18:27:15 -04:00
Ben Doherty
2f26ef0873 Fix OpenGL stencil buffer writes (#6023) 2022-08-31 17:17:16 -04:00
Mathias Agopian
ac61fd7ba4 make a small optimization more explicit, fix typos 2022-08-31 09:11:25 -07:00
Benjamin Doherty
a886166489 Release Filament 1.26.0 2022-08-31 12:03:43 -04: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
Philip Rideout
de7dfc2ea6 gltfio: Better behavior for releaseSourceData() 2022-08-30 16:00:11 -07:00
Philip Rideout
7337a467b9 gltfio cleanup: NodeMap is now a FixedCapacityVector, etc. 2022-08-30 15:57:30 -07:00
Philip Rideout
8118b4a774 gltfio: reset MaterialInstance cache for each instance.
For each "cgltf_material", we now create one "MaterialInstance", even
if a given asset has multiple instances. In the future, we might make
this behavior configurable to make better use of Filament's
auto-instancing feature.

This change is a feature request from Google, but also this behavior is
more consistent with the code comments.

Also some related cleanup:

(1) Use FixedCapacityVector instead of robin_map.

(2) Move the cache to move out of the asset and into the loader,
    because it is only used at load time.
2022-08-30 12:03:52 -07:00
Mathias Agopian
b295743330 Fix filamat internal state tracking
in a few places filamat loses the value of targetApi and targetLanguage
and attempt to guess it from other values, this lead to inconsistencies.

we now keep both targetApi and targetLanguage and use them appropriately.

in particular we don't use the optimization level to "guess" what 
targetLangage we're on.


In the end this resolve a prior unit test failure and allows us to not
have to use "spirv" rules when generating only GLSL.
2022-08-29 22:11:17 -07:00
Mathias Agopian
4f8d7092e0 fix typos and reformat code 2022-08-29 22:11:17 -07:00
Mathias Agopian
2701e57779 fix filamat unit tests
We use TargetLanguage::SPIRV instead of GLSL which affects how the
source GLSL is generated, in particular which version is used.

This change is not a problem for these unit tests, but is probably
exposing another problem -- we will address that separately.
2022-08-29 17:31:51 -07:00
Philip Rideout
f9375d5c33 gltfio: fix spotlight regression.
Spotlights were accidentally disabled in PR #5932.
2022-08-29 15:29:35 -07:00
Mathias Agopian
d04f049fa3 fix (again) frustum-box intersection
We were early-exiting too aggressively in the some case.
2022-08-29 14:55:49 -07:00
Mathias Agopian
8b8e724761 fix a use after free when setting a Program's uniform infos
We were keeping the list if uniform names in Material and passing
pointers to the backend. Unfortunately, HwProgram can outlive
Material because it is legal to destroy a Material once it's not
needed on the client side. e.g. just after rendering something.

This was happening with the IBLPrefilter code, but probably elsewhere
too.

We now just store CStrings in HwProgram.
2022-08-29 13:49:34 -07:00
Philip Rideout
45e8c57f77 gltfio: Innocuous comment fixes / renamings. 2022-08-29 13:06:13 -07:00
Philip Rideout
d01b3301d0 Vulkan: fix a warning, fix use-before-init. 2022-08-29 10:53:48 -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
Philip Rideout
0695c12420 gltfio: Refactor skinning, fix duplicated data.
The immutable inverse bind matrices can be shared among instances, so
they are now stored in Asset, not in Instance.

Also, there are now two "load" phases for skinning data:

(1) storing the inverse bind matrices
(2) building the Entity mappings (for animation efficiency)

Phase 1 is done in `ResourceLoader` because inverse bind matrices can
live in an external bin file.

Phase 2 is done during Instance creation, because that's when entities
are created.
2022-08-29 09:18:17 -07:00
Mathias Agopian
4af533c010 material instanced property must be false by default.
this fix auto-instancing.
2022-08-26 14:43:52 -07:00
Balazs Vegh
6a28d2b81c Implement setThreadName() on Windows (#5999) 2022-08-26 13:29:42 -04:00
Philip Rideout
54769a2ad3 gltfio: Move the API for recomputeBoundingBoxes.
Prior to this change, `recomputeBoundingBoxes` was an opt-in config
parameter in ResourceLoader. It is now a method on FilamentInstance.

The old API did not work for dynamically created instances. Since this
is a relatively obscure feature, we considered removing it completely,
especially since the computation requires the presence of CPU-side
vertex data combined with the transform hierarchy.

Instead of removing the feature, we decided to move it to a better
place. This paves the way for some upcoming improvements, which include
reducing the memory footprint for assets. It also improves overall code
organization and separation of concerns.
2022-08-26 09:48:04 -07:00
Mathias Agopian
87cece8379 use separate enums for uniform and sampler binding points (#5984)
Co-authored-by: Benjamin Doherty <bendoherty@google.com>
2022-08-24 16:36:13 -07:00
Philip Rideout
fe3790cb9c WASM: Set CONFIG_MAX_INSTANCES to a small value + hack the GLSL.
Temporary fix until spec constants arrive.

Second attempt, fixes #5859.
2022-08-24 16:24:25 -07:00
gaborvalasek
39cb238065 Fix MSVC warnings (#5926)
* Fix warning C4146: unary minus operator applied to unsigned type, result still unsigned

* Fix warning C4068: unknown pragma 'nounroll'

* Fix warning C4068: unknown pragma 'unroll'

* Fix warning C4068: unknown pragma 'clang'

* Fix warning C4305: 'initializing': truncation from 'double' to 'float'

* Fix warning C4267: 'argument': conversion from 'size_t' to 'utils::FixedCapacityVector<filament::uberz::WritableArchive::Material,std::allocator<T>,true>::size_type', possible loss of data

* Fix warning C4267: 'argument': conversion from 'size_t' to 'uint32_t', possible loss of data

* Fix warning C4244: 'initializing': conversion from 'A' to 'T', possible loss of data

* Fix warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

* Fix warning C4293: '>>': shift count negative or too big, undefined behavior

* Fix diagnostic warning C4189: 'channels': local variable is initialized but not referenced

* Use [[maybe_unused]] where possible and revert aa79bd6fa8.

* Revert unary minus for non-MSVC compilers

* Add macro for enabling warnings temporarily

* Get rid of UTILS_HAS_CXX17

* Revisit warning related macros

Co-authored-by: Levente Koncz <levente.koncz@shapr3d.com>
2022-08-24 11:41:10 -07:00
Mathias Agopian
2182149b7a fix shadows when there is no receivers in the frustum
this case could cause an assert in debug builds. There was a few bugs:

- when computing the intersection between a box and a frustum, a special
  case test had a typo which would cause extra work in some case. Also,
  we were not detecting correctly when there was no intersection at all.
  This could result in some intersection point being found.

- Finally, we reject the intersection volume when it has only 3 vertices
  because that's not a volume.

Fixes #5933
2022-08-24 11:07:32 -07:00
Ben Doherty
006e0548c1 Adjust Metal buffer bindings in preparation for argument buffers (#5986) 2022-08-24 13:50:45 -04:00
Mathias Agopian
8257fbdbf3 Fix a merge that went bad 2022-08-23 17:16:56 -07:00
Mathias Agopian
f57224952a record sampler informations in the material file
The main goal of this change is to have "ugly" code only in filamat.
In particular, the sampler binding information is now recorded
into the material file and used on the filament side to inform the
backend.

This means that on the filament side we only have generic code with
all the "uglyness" in filamat. In particular SamplerBindingMap and
SibGenerator now only exist in filamat.

Files of greater interest:
Material.cpp, MaterialBuilder.cpp
2022-08-23 17:03:30 -07:00
Philip Rideout
3c982cae64 Revert "WASM: Set CONFIG_MAX_INSTANCES to a small value."
This reverts commit 7aa5d4a375.
2022-08-23 16:42:16 -07:00
Mathias Agopian
3ffe63c02c don't use std::is_pod which is soon to be deprecated
fixes #5980
2022-08-23 15:49:35 -07:00
Philip Rideout
7aa5d4a375 WASM: Set CONFIG_MAX_INSTANCES to a small value.
This is a workaround for the following Chrome issues:

https://crbug.com/1348017 Compiling GLSL is very slow with struct arrays
https://crbug.com/1348363 Lighting looks wrong with D3D11 but not OpenGL

This requires a rebuild of materials for WebGL users.

Fixes #5859.
2022-08-23 11:57:26 -07:00
Philip Rideout
1d06dd630a Add CONFIG for MaxInstanceCount. 2022-08-23 09:32:01 -07:00
Mathias Agopian
f630fb6732 'strict' field is no longer needed in Program::Sampler 2022-08-23 09:08:13 -07:00
Benjamin Doherty
df3ea47a3c Release Filament 1.25.6 2022-08-23 12:05:06 -04:00
Johnathon Selstad
6ceb122ae8 Set Frame Delay according to Monitor Refresh Rate (#5942) 2022-08-23 11:56:17 -04:00
Ben Doherty
ec92a0c458 Fix: Metal scissor calculation (#5896) 2022-08-23 11:54:32 -04:00
Ben Doherty
60294c2514 Add stencil API bindings for Java (#5949) 2022-08-23 11:54:09 -04:00
Ben Doherty
94f72ea137 Add stencil API bindings for web (#5976) 2022-08-23 11:53:27 -04:00
Mathias Agopian
9b7295fd8f remove unused mIsMobile attribute 2022-08-22 22:15:02 -07:00
Mathias Agopian
c93b49e714 It was a mistake to change Program's ctor
partially revert a recent change where Program needs a DriverApi in its
ctor. This was a misguided change. Backend API never take a DriverApi
as parameter.

Checking the feature level, for instance, should happen as a 
precondition, or in the backend as postcondition.
2022-08-22 22:15:02 -07:00
Philip Rideout
a81b9a0f09 CMake: fix wasm build on windows machines
Noticed this while trying to help with #5859.
2022-08-22 11:44:36 -07:00
Mathias Agopian
82d9d2a016 Program.h should be a backend public header 2022-08-22 09:36:12 -07:00
Mathias Agopian
d529a7514a DriverApiForward.h should a backend public header 2022-08-22 09:36:12 -07:00
Mathias Agopian
a5c91a6ed4 Cleanup SamplerGroup includes
SamplerGroup should be moved out of backend but it still lives there
for now because it's used as an implementation detail in metal and vk
backends.
2022-08-22 09:36:12 -07:00
Mathias Agopian
357000a0e7 Make ShaderStageFlags an enum class 2022-08-19 22:08:59 -07:00
Mathias Agopian
80e26ba4af Make BindingPoints an enum class 2022-08-19 22:08:59 -07:00
Mathias Agopian
6310a15650 keep only one entry point for specifying shaders on Program 2022-08-19 22:08:59 -07:00
Mathias Agopian
5909215967 keep only 1 entry point for UniformInterfaceBlock::add
add() now take a list of Uniforms, and is the only entry point.
At least clang generates much less code this way.
2022-08-19 16:23:39 -07:00
Mathias Agopian
f0eb1c59b1 don't hardcode uniform block bindings on filament side
GLES3.0 (and GL4.1) need informations about the uniform block bindings
because they don't allow to do that setup in the shaders. So we store
that information in the material blob and retrieve it on the filament
side in Material. This information is passed to Program so it can
create the bindings.

Prior to this change, this information was set by Material itself, but
this ment we had two places where these bindings were hardcoded.


The bulk of the change is to add a new material chunk which stores an
array of {name, binding}, retrieve it on the Material side and pass it
to Program.
2022-08-19 16:23:39 -07:00
Mathias Agopian
22aa429059 Program now needs a DriverApi
This will be needed soon so Program can check the feature level.
2022-08-19 16:23:39 -07:00
Mathias Agopian
3cc5f38da2 Program cleanup.
- remove Program::Shader, use ShaderType instead.
- unhardcode some array sizes
- remove unused code
2022-08-19 16:23:39 -07:00
Mathias Agopian
83985ba910 get rid of PlatformDummyGL
We can't use a compile time failure (e.g. #error) because another
backend (e.g. vulkan) might be supported.

Fixes #5948
2022-08-19 14:38:31 -07:00
Philip Rideout
263d4bfc1e Remove sampler check from VulkanDriver::draw 2022-08-19 12:25:10 -07:00
Philip Rideout
8c608cdce5 gltfio: add ownership query
Adding this getter lets us remove some duplicated state from an
internal client at Google.
2022-08-19 09:58:15 -07:00
Philip Rideout
ceea495da1 Android: prevent misc obfuscation for gltfio
Fixes #5944
2022-08-19 09:36:09 -07:00
Philip Rideout
a0af0a98cb gltfio: minor code cleanup 2022-08-18 13:46:52 -07:00
Mathias Agopian
9e99cfef61 cleanup SamplerBindingMap usages
- remove unused SamplerBindingMap parameter 
  In fact, the SamplerBindingMap is used, but it is passed inside the
  MaterialInfo structure, so it doesn't need to be passed as parameter.

- Don't create unneeded SamplerBindingMap temporaries
2022-08-18 11:00:25 -07:00
Ben Doherty
b6e6733361 Fix Metal GPU capture (#5939) 2022-08-18 12:25:06 -04:00
Ben Doherty
d3cf84680c Add stencil state APIs to MaterialInstance (#5938) 2022-08-18 12:24:42 -04:00
Philip Rideout
8dc6fde588 gltfio API change: assets are now always 'instanced' etc
This change was motivated by some internal work at Google and has the
benefit of simplifying the gltfio API and implementation. There are 2
major API changes:

(1) Consolidate separate loader entry points for GLB and GLTF.

The distinction between GLB and GLTF can be made from the file content
alone, because GLB has a 4-byte magic string in its header. There is no
need for separate entry points.  Clients do not (and should not) need
to check the file name extension.

(2) Remove the distinction between "instanced" and "non-instanced"
glTF assets.

In the new scheme, all assets have at least 1 instance.

Broadly speaking, in gltfio an "asset" is a collection of Filament
objects like textures and vertex buffers, while an "instance" is a
collection of entities and components (e.g. the transform hierarchy).

This API change makes life easier for clients because they no longer
need to decide a priori if they will ever need to add instances.

This change also moves some public-facing methods from FilamentAsset to
FilamentInstance:

    - getSkinCount, getSkinNameAt
    - getJointCountAt, getJointsAt
    - attachSkin, detachSkin
2022-08-18 08:58:24 -07:00
Johnathon Selstad
1938c8239a Add glslang/OSDependent to ThirdParty folder (#5941) 2022-08-17 17:48:50 -07:00
Mathias Agopian
bf43c61a05 fix incorrect assert when uploading cubemaps
this regression was introduced recently.
2022-08-17 16:18:04 -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
bb5d82fce9 fix MaterialBuilder tests 2022-08-17 11:19:39 -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
7c092a8714 both fragment and vertex shaders need material defines
Fixes #5917
2022-08-17 10:13:28 -07:00
Ben Doherty
53350bbec0 Add View API to enable the stencil buffer (#5886) 2022-08-17 09:25:33 -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
35204faa6b use our custom mutex/condition only on ANDROID
For other linux distributions we use the generic C++ ones. I think this
is probably safer and more friendly to non-linux unixes.


Fixes #2861
2022-08-16 14:55:46 -07:00
Benjamin Doherty
9e87a312ab Release Filament 1.25.5 2022-08-16 10:59:05 -07:00
Ben Doherty
e1911eef3a Fix SamplerGroup update issue (#5928) 2022-08-16 10:46:35 -07:00
Philip Rideout
e0c11cfeed Add CONFIG_MINSPEC_UBO_SIZE and fix comment.
Fixed a comment that said "We store 64 bytes per bone.".  The actual
number is 32.

Developers who know their users have powerful devices may wish to exceed
ES3.0 minspec constraints to allow more bones and / or morph targets.

Fixes #5785.
2022-08-16 10:38:33 -07:00
Philip Rideout
b9efd4fbf0 gltfio Android: Fix double free error.
The custom release callback that I provided was in the wrong place; it
was only being used for a path string, not the actual buffer content.
The cgltf API is a bit awkward in this area.

No need to update RELEASE_NOTES because this will be cherry picked to
the RC branch, which is where the bug introduced.

Fixes #5918.
2022-08-15 16:02:31 -07:00
Mathias Agopian
38ca4ceb52 Fix Texture documentation
Fixes #5904
2022-08-15 12:38:57 -07:00
Philip Rideout
bfe8a8aa18 WASM: Allow clients to enable pthreads.
Filament does not yet fully support threads with WASM, but this is a
baby step in that direction.

To enable experimental pthreads support, enable the WEBGL_PTHREADS CMake
option. This will enable pthreads support in `gltfio` and `utils`, which
is known to work, but not when served with GitHub Pages.

The web server must emit COOP, COEP and CORP headers, so our build
instructions now recommend the use of `emrun` for local testing.

This also changes our demos so that they do not use unpkg, which
does not work when using `emrun`, due to cross-origin restrictions.
2022-08-12 15:43:00 -07:00
Philip Rideout
430f060db2 gltfio: concurrent texture downloading and decoding.
This feature can improve load time when textures are downloaded from the
web on non-filesystem platforms like Android.

More specifically, this allows downloaded texture assets to arrive after
the user calls asyncBeginLoad(), which means that decoding and
downloading can occur concurrently.

Prior to this PR, we already used JobSystem for decoding, but we did not
kick off any jobs until after all assets were downloaded.

Still TBD: add this feature for external vertex data.

Partial fix for #5909.
2022-08-11 15:45:29 -07:00
Philip Rideout
62cffc51bb gltfio: remove a memcpy via custom cgltf_file_options.
Earlier versions of cgltf did not support file reader customization.
This was fixed back in Dec 2019 but at the time I did not notice, so
we never bothered cleaning up our usage.

In the future we would like WebGL + Android builds to permit texture
downloads to occur concurrently with the texture decoder jobs. This PR
is basically a preparatory refactoring, but with the nice side effect of
removing a memcpy.
2022-08-11 11:18:12 -07:00
Philip Rideout
75004e9d3e gltfio: add 'detach' methods to allow ownership transfer
These new methods allow gltfio to be integrated into internal Google
libraries.
2022-08-09 14:28:15 -07:00
Mathias Agopian
efba9a636a Stencil reference value can be separate for front and back 2022-08-05 15:34:37 -07:00
Mathias Agopian
e2161fa3af Fix a small discard issue with the stencil buffer
In GL we need to track if a buffer is written at all so that later we
can decide to honor the discard flags or not (see b514b2e9).
2022-08-05 10:30:53 -07:00
Mathias Agopian
6d6e9f965b Remove mRasterState from OpenGLDriver
it was a duplicate state from the true gl state which could easily cause
problems. It only existed to optimize state updates when nothing changed
but we already have fine-grained tests for this.
2022-08-05 10:30:53 -07:00
Mathias Agopian
9307422e54 We don't need the union in StencilOperations anymore 2022-08-05 10:30:53 -07:00
Mathias Agopian
df5b763d33 Remove mStentilState from OpenGLDriver
It wasn't really needed because it's essentially a copy of the GL state.
2022-08-05 10:30:53 -07:00
Mathias Agopian
90ff85b04d StencilState can now use designated initializers
We just remove the custom default ctor.
2022-08-05 10:30:53 -07:00
Mathias Agopian
c1505f3513 improve GL backend stencil state updates
We separate stencilWrite from stencilFunc, which can lead to less
GL state changing.
2022-08-05 10:30:53 -07:00
Filip Henningsson
1bd4a15d5c Ensure UTILS_DEPRECATED is used in the public API 2022-08-05 10:27:48 -07:00
Ben Doherty
7a2ecf8435 Fix PrimitiveInfo size (#5883)
* Fix PrimitiveInfo size

* Make Command 64 bytes
2022-08-04 09:15:09 -07:00
Ben Doherty
3c7ff0ee19 Add additional state to StencilState (#5879)
Separate out stencil operations for back/front facing primitives and add read/write masks.
2022-08-03 18:55:59 -07:00
Mathias Agopian
d3073a8ebd The "Prepare Shadow Pass" was never executed
It was culled by the frame-graph because it didn't have "read" from 
any of its resource, only writes. However, it does set uniforms, so need
to be called.

fix #5874
2022-08-03 16:54:24 -07:00
Romain Guy
59e9f36e25 Update docs for sampler2D arrays 2022-08-03 16:08:28 -07:00
Mathias Agopian
7e21db1de1 Fix StructureOfArray alignments
StructureOfArray always aligned each array to the same alignment as
malloc (usually 8 bytes), but that was not enough if one of its type 
has stricter alignment requirements. 

StructureOfArray now always honors at least the alignment requirement
of each array.

Also removed dependency on EntityInstance.h

Fixes #5727
2022-08-03 14:40:27 -07:00
Mathias Agopian
1f451777b4 Return support for ASTC formats properly.
`Texture::isTextureFormatSupported` always returned `true` for ASTC, it
now queries the hardware as expected.


Fixes #5872
2022-08-03 11:52:35 -07:00
Ben Doherty
832442d092 Move stencil state out of RasterState (#5873) 2022-08-03 11:21:17 -07:00
Mathias Agopian
7101757bff Camera::getPosition() now returns a double3 2022-08-02 19:48:57 -07:00
Mathias Agopian
3090ed1523 make Camera::lookAt() take doubles instead of floats
this matches all the other Camera APIs
2022-08-02 19:48:57 -07:00
Mathias Agopian
1dd2b32a1f make all public API pre-condition violation fatal
We used to have a mix of fatal and non-fatal assertions for precondtions
errors. From now on, we always throw if exceptions are enabled or 
crash with a log otherwise.
2022-08-02 15:15:16 -07:00
Philip Rideout
f75e37cf83 gltfio: fix warning in release build. 2022-08-02 14:32:27 -07:00
Ben Doherty
3fba6754c5 Fix: OpenGL not clearing stencil buffer (#5870) 2022-08-02 14:19:24 -07:00
Benjamin Doherty
d4e2d7f07f Release Filament 1.25.4 2022-08-02 11:47:15 -07:00
Mathias Agopian
7917f74bc8 Fix derivation of SH trig terms recursion
Fixes #5866
2022-08-02 11:22:36 -07:00
Mathias Agopian
7d086beb3f Fix "angle sum trig identity" typo 2022-08-02 11:22:36 -07:00
Mathias Agopian
37cd7d6944 Fix typo in documentation
Fixes #5848
2022-08-02 11:22:36 -07:00
Mathias Agopian
5b71274fa5 get rid of utils::StaticString
In most places this is simply replaced by `std::string_view`.

We also change a few internal/private headers so they accept 
`std::string_view` instead of `utils::CString`.
2022-08-02 09:51:13 -07:00
Philip Rideout
971df18b3c Vulkan: add documentation for cmd buf manager. 2022-08-01 14:26:22 -07:00
Mathias Agopian
841ea86cea MaterialInstance public API friendly to std::string_view
Internally we use std::string_view and the public API is augmented
with APIs that take a length for strings, which makes them useable
with string_view parameters.

Also fix exception specification for all setParameter methods, which
can throw if exceptions are enabled (or exit the program otherwise).
2022-08-01 14:17:29 -07:00
Philip Rideout
f79e703861 Remove vestiges of old API from Stream. 2022-08-01 11:37:38 -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
Romain Guy
b9b4b7c64d Fix bluegl-gen.py
The comment about MSVC was not properly escaping backslash
sequences, eating some of the comment and generating an
interpreter error on \u.
2022-07-31 13:27:26 -07:00
Ben Doherty
47d58aa484 Metal: implement MSAA stencil buffers (#5834) 2022-07-29 16:22:22 -07:00
Benjamin Doherty
1e87c68435 Fix incorrect shader permutations in MaterialBuilder 2022-07-29 10:55:59 -07:00
MasTraER
54106962fe Fix incorrect precision restoration when computing accurate world translations
When FTransformManager computes accurate world transforms, it adds downcasted leftover to translation part to restore precision.
However, both transltation and leftover are given as float3 - simply adding them resut float3, so addling leftover become meaningless.
one or both should be upcasted first.
2022-07-29 10:54:04 -07:00
Philip Rideout
ec2fee7a4e Fix typo. 2022-07-29 09:19:18 -07:00
Alan Eneev
27aed0a951 Headless EGL: Fallback to a 24-bit depth buffer 2022-07-29 09:17:48 -07:00
Alan Eneev
ec5738c651 Fix PlatformEGLHeadless build and add a build.sh option to build EGL
I have disabled building SDL with headless EGL, because
SDL_config_minimal.h doesn't work with EGL, and I don't know how to
implement a an SDL config that would work with EGL.

I have verified that this works in a separate project, and that it
compiles in this project.

```
$ ./build.sh -e release
$ find ./out/ -name "*EGL*"
./out/cmake-release/filament/backend/CMakeFiles/backend.dir/src/opengl/platforms/PlatformEGL.cpp.o
./out/cmake-release/filament/backend/CMakeFiles/backend.dir/src/opengl/platforms/PlatformEGLHeadless.cpp.o
./out/cmake-release/libs/bluegl/CMakeFiles/bluegl.dir/src/BlueGLLinuxEGL.cpp.o
```
2022-07-29 09:17:07 -07:00
Mathias Agopian
050ffdd585 Fix DoF on WebGL
The issue was that WebGL2.0 doesn't support texture swizzle.


Fixes: #5828
2022-07-28 16:34:07 -07:00
Mathias Agopian
7169c4e386 better test for presence of unpackHalf2x16
This will actually reduce the binary size a bit on mobile.
2022-07-28 15:39:39 -07:00
Mathias Agopian
4b7fa63722 rename ShaderModel enums
GL_ES_30   becomes MOBILE
GL_CORE_41 becomes DESKTOP

ShaderModel controls which flavor of GLSL (GL or ES) is used both when 
reading and outputting materials.

It's also used to set default quality settings and the default precision
of all fragment shaders.

Technically, Vulkan and Metal don't need this distinction, but the GL
backend does.
2022-07-28 15:39:39 -07:00
Philip Rideout
bff0d1dcf4 Add IBL builder to TypeScript, fix #5805 2022-07-28 15:39:06 -07:00
Ben Doherty
1ac469f340 Metal: add initial support for stencil buffers (#5783) 2022-07-28 12:21:32 -07:00
Philip Rideout
3b4c10f952 Update public WebGL viewer to 1.25.3 2022-07-28 12:17:31 -07:00
Philip Rideout
07d2b5ce12 cgltf: enable validation asserts in debug builds 2022-07-28 12:13:06 -07:00
Mathias Agopian
fd2fc23885 updateSamplerGroup() now uses a BufferDescriptor
this is more in line with other APIs of the backend. This change is
complete for the GL backend, but for the metal/vulkan backend we still
use a SamplerGroup as the internal data structure, which is just 
temporary.

Eventually, SamplerGroup should becomes a "filament" only API (not
a backend API).
2022-07-28 10:51:42 -07:00
Mathias Agopian
bf051657ed SamplerGroup now uses a FixedCapacityVector<>
SamplerGroup itself is now a more "traditional" class where copy and
move ctor do what you'd expect. This actually removes a few copy of
the internal data in some cases and uses less memory, at the cost of
doing some heap allocations, but they should be rare and outside of
the main loop.
2022-07-28 10:51:42 -07:00
Mathias Agopian
baecec9a37 take advantage of HwSamplerGroup abstraction in GL backend
we mow do most of the work of validating the sampler parameters and
resolving to an actual GL sampler, when updating a SamplerGroup,
instead of doing this each time a program is made active.

A lot of cpu work is saved when the same samplergroup is reused with
multiple programs.
2022-07-28 10:51:42 -07:00
Mathias Agopian
805e7a10d1 move SamplerGroup out of HwSamplerGroup
this is the start at making HwSamplerGroup more "real". It shouldn't
keep a reference to the filament::SamplerGroup, which is just an object
to pass the data.

for now, we move the SamplerGroup reference into the concrete classes to
keep the same implementation. But now it becomes an "implementation
detail" of the respective backends.
2022-07-28 10:51:42 -07:00
Mathias Agopian
646dfa8b70 SamplerGroup cleanup
- remove the 2 argument version of setSampler
- use a bool instead of bitfield for the dirty state
- try to avoid setting dirty bit if setting same sampler
2022-07-28 10:51:42 -07:00
Philip Rideout
bf8b0d8843 Prevent proguard obfuscation for KTX1Loader. 2022-07-27 10:57:09 -07:00
Mathias Agopian
41b5b997a7 fix all warnings in OpenGLDriver.cpp 2022-07-27 10:50:38 -07:00
Mathias Agopian
881867be71 fix a use-after-move 2022-07-27 10:50:38 -07:00
Philip Rideout
4afd0c5456 Upgrade to emscripten 3.1.15 and remove workaround.
Starting with 3.1.14, embind started to support for `noexcept`
which caused multiple definition errors since we have a workaround
in place that alreadys supplies template instantiations for `noexcept`.

This change should not affect G3 since our JS bindings are not used
in G3.

The upstream fix is here:
https://github.com/emscripten-core/emscripten/pull/17140

Fixes #5789.
2022-07-27 09:10:29 -07:00
Mathias Agopian
ec74cc2d39 Add support for cubemap arrays in the backends
This is not intended to be used yet because we're not currently
checking that cubemap array are actually supported, however, if they
are, they should work.
2022-07-26 15:06:43 -07:00
Mathias Agopian
88b29b9eb7 Make filament and utils public headers -Wall -Wextra warning free
All warnings here where harmless unused parameters.
2022-07-26 11:54:54 -07:00
Mathias Agopian
3974a548d3 fix View::pick() callbacks
the handler parameter would be ignored for some overloads.
2022-07-26 11:54:54 -07:00
Benjamin Doherty
90f508e89d Release Filament 1.25.3 2022-07-26 09:55:54 -07:00
Ben Doherty
d70cee7fec Fix config object related build failures (#5814) 2022-07-26 09:52:19 -07:00
Mathias Agopian
9c542791ef fix max mipmap levels calculation for 3D textures
the depth of the texture wasn't taken into account. In practice this
would restrict the number of mip levels of a 3d texture that would have
a larger dimension in depth.
2022-07-25 11:30:27 -07:00
Mathias Agopian
2d1d6ffb2c fix cubemap uploading
There was a wrong assert in Texture::setImage() as well as a typo when
calling setImage() itself in the sample code.
2022-07-25 11:30:08 -07:00
Romain Guy
9cc7fe97c5 Upgrade Kotlin, AGP, NDK (#5804) 2022-07-22 13:46:13 -07:00
Mathias Agopian
61fb5a588e rework backend texture upload APIs
The main goal is to allow more flexibility, allow cubemap arrays in
the future and better match vk and metal apis.

Main changes:
- remove updateCubeImage
- remove update2DImage
- update3DImage is now the only texture upload backend API

cubemaps are now treated just like a 2D array of 6 layers.

For this reason, Texture::setImage(..., FaceOFfsets) is deprecated.
Additionally, the 2D versions of Texture::setImage() become inline
helpers.

A side effect of this change is that it is now possible to update only
a single face of a cubemap, but also a region of a face (or faces).
2022-07-21 11:12:05 -07:00
Ben Doherty
815d202f6d Use staging buffers to implement Metal buffer updates (#5795)
This PR changes how Metal handles buffer updates. Previously, Metal allocated a full new buffer each time an `updateBufferObject` command was issued; however, it did not copy the previous contents of the buffer over to the new buffer, so partial updates did not work correctly.

Now, Metal allocates a single, private GPU buffer and employs temporary staging buffers whose contents get blitted to the private buffer at each update.

There's still some room for optimizations, and I need to give more thought to how I want to implement `updateBufferObjectUnsynchronized`.
2022-07-18 18:08:00 -07:00
Benjamin Doherty
2b57ec476d Release Filament 1.25.2 2022-07-18 15:13:37 -07:00
Philip Rideout
eb1b700ef7 gltfio: minor fixups to prep for g3 integration. 2022-07-15 08:36:53 -07:00
Mathias Agopian
efc88fbc6f more Engine configuration cleanup
- move all froxel configuration constants out of Engine.h, unlike
  the previous todo/comment, these shouldn't be part of Engine::Config.

- same for irradiance map
2022-07-12 21:25:27 -07:00
hzzengxiaoqi
0ba0591e19 fix adreno driver crash related to morph target change. (#5754)
For some android gpu drivers, some uniform arrays should be initialized to be used in the shader, even if not used.

Co-authored-by: Mathias Agopian <mathias@google.com>
2022-07-12 16:24:19 -07:00
Mathias Agopian
385608648f cleanup comments/documentation and code 2022-07-12 15:58:18 -07:00
Benjamin Doherty
7d170ee391 Fix build 2022-07-12 10:55:34 -07:00
Mathias Agopian
5906d144dd code maintenance/cleanups
- try to help DataReshaper a bit
- fix some typos in comments
- address a few "todos"
- protect mActivePrograms with a lock, as it should
2022-07-12 10:37:40 -07:00
BStringhamVRSK
6a1cc3abe9 Add config object to engine initialization(#5556)
This code adds a config object, "ConfigParams," to Engine creation parameters for setting memory buffer sizes for command buffers and driver handle arena sizes. It will use #define values (FILAMENT_PER_FRAME_COMMANDS_SIZE_IN_MB, etc.) as defaults (and as minimum acceptable values) if the user does not provide values. It attempts to validate the values given to prevent the user from creating a unusable state.
2022-07-11 17:36:45 -07:00
Philip Rideout
6aa11e5ceb gltfio: use openLocalTransformTransaction API. 2022-07-11 16:17:52 -07:00
Benjamin Doherty
ce33fda6ec Release Filament 1.25.1 2022-07-11 15:49:29 -07:00
Mathias Agopian
88768e8003 Fix Conflict with glibc 2.35+ macro.
Fix #5720
2022-07-11 15:25:02 -07:00
Philip Rideout
4f1dd8b304 filamat: dictionaries now store each blob once, not twice.
BlobDictionary and LineDictionary were storing blobs as map keys to
achieve simple compression, but they also stored duplicates of
in a vector for index-based lookup.

Now, the vector is storage and the map has keys that are string_view.
2022-07-11 11:00:04 -07:00
Philip Rideout
42cae27992 filamat: remove more dead codelines. 2022-07-11 11:00:04 -07:00
Mathias Agopian
13f646025b Renderer::getUserTime() now returns seconds as documented
Fixes #5722
2022-07-11 10:53:12 -07:00
Philip Rideout
e7c9197d07 matdbg: rewrite ShaderReplacer to remove bespoke chunk i/o. 2022-07-11 10:09:16 -07:00
Mathias Agopian
7afd5e5963 Camera API and documentation improvements
- getNear() and getCullingFar() now return doubles
- updated documentation
- all setProjection() calls can now throw (when enabled) and will
  do so if preconditions are not met (instead of setting a default
  projection).
- Frustum can now be logged on debug builds
2022-07-11 09:56:41 -07:00
Philip Rideout
d73453863d Fix swallowed errors in MaterialParser.
If `ChunkContainer::parse` failed, then `MaterialParser::parse` was
returning SUCCESS.
2022-07-07 22:34:32 -07:00
Philip Rideout
8b88638232 filamat: remove some unused code. 2022-07-07 22:34:19 -07:00
Ben Doherty
677cdc1239 Add backend test for viewport and scissor (#5767) 2022-07-07 17:22:41 -07:00
MasTraER
a4d3ffe7d4 Metal: add support for scissor (#5644)
This patch enables user scissor in Metal backend; There was no implementation for it.
While the absence of the feature in Metal does not incur serious problem, many rendering glitches were found in apps using ImGui due to it.

Co-authored-by: Benjamin Doherty <bendoherty@google.com>
2022-07-07 13:37:43 -07:00
Philip Rideout
3ada971d8a matdbg: prep for removing bespoke chunk serializer
matdbg should use Flattener / Unflattener rather than imitating them,
this is phase 1.
2022-07-07 11:09:23 -07:00
Philip Rideout
6588cc30ea Use string_view for map lookups.
We can avoid construction of std::string by using std::map with a
special comparator. For some reason, this is not supported with
unordered_map.
2022-07-07 10:07:17 -07:00
Mathias Agopian
09f188659a fix typos in Camera documentation 2022-07-07 09:37:34 -07:00
Benjamin Doherty
ea3553ceb7 Release Filament 1.25.0 2022-07-06 19:07:22 -07:00
Mathias Agopian
a64b1eccdf add API to enable/disable auto-instancing globally.
auto-instancing can have some overhead, so when it is known that the
scene doesn't have identical primitives, it is better to disable it.
(disabled by default).

Also add some missing bindings for `enableAccurateTranslations`.
2022-07-06 15:51:41 -07:00
Mathias Agopian
eda2b7955d Basic automatic instancing. 2022-07-06 15:51:41 -07:00
Mathias Agopian
6bc0e032fc Access the object uniforms relative to gl_InstanceIndex 2022-07-06 15:51:41 -07:00
Ben Doherty
9ce797eee8 Fix destroyEntity documentation (#5760) 2022-07-06 13:17:19 -07:00
Benjamin Doherty
ab2a90374b Release Filament 1.24.0 2022-07-01 12:08:17 -07:00
Ben Doherty
10cf45dd6b Metal: Allow Filament to disregard MTLTexture pixelFormat when importing (#5753) 2022-06-30 16:04:01 -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
Ben Doherty
4096a46547 CocoaPods: include uberz library (#5752) 2022-06-30 14:08:46 -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
ecede1e947 matdbg: fix 4x overallocation for SMOLV blobs 2022-06-30 12:06:53 -07:00
Philip Rideout
130053dfad ImGuiHelper: add support for Y flip. (#5748)
Reflects a change from Betty and should be cherry picked to v1.23.3

Users could customize the ImGuiHelper camera, but they had no control
over the scissor coordinates. This allows them to use vertically flipped
coordinates, which, unfortunately, is required for MediaPipe
integration.
2022-06-30 12:04:39 -07:00
Philip Rideout
e3932f6e65 uberz tool: add --append and --template arguments. (#5730) 2022-06-23 13:01:48 -07:00
Philip Rideout
05792fa5f4 Speed up debug builds. (#5735) 2022-06-23 11:22:48 -07:00
daemyung jang
3469e9f4a8 Check the font path is the file (#5734)
If the font path is the directory then it's undefined behavior.
2022-06-23 09:29:50 -07:00
LaiJF
c839a66958 Fix typo (#5728) 2022-06-22 14:48:05 -07:00
Philip Rideout
31757203eb Vulkan: fix VMA-related warning in GitHub builds. (#5729) 2022-06-22 14:41:48 -07:00
Philip Rideout
3f5ed476a6 Refactor the CMake script for gltfio ubershaders. (#5725) 2022-06-22 11:51:03 -07:00
Ben Doherty
97f8b8aa60 Vulkan: Support VMA_DYNAMIC_VULKAN_FUNCTIONS off (#5726) 2022-06-21 15:18:15 -07:00
Mathias Agopian
16af12b58c vulkan: first instance should be 0 not 1 2022-06-17 13:02:41 -07:00
Philip Rideout
1b11c90f2b Vk minor code cleanup. 2022-06-17 12:20:13 -07:00
Philip Rideout
3b71cb13b1 Quick repair to matdbg for alignment padding. (#5717)
This was too tricky, it highlights that we definitely need refactor this
to share code with the flattener / unflattener pipeline. I'll look at
that next.
2022-06-17 12:09:20 -07:00
Ben Doherty
439bcb59cf OpenGL: take mip level into account when checking attachment sizes (#5709) 2022-06-17 12:04:28 -07:00
Ben Doherty
0e9cbeb340 Metal: correctly compute viewport (#5710) 2022-06-17 12:04:09 -07:00
Rahul Sheth
f48a02949c Add EGL support for OpenGL on Linux (#5674) 2022-06-17 10:05:46 -07:00
Mathias Agopian
4eea8a5c07 fix the use of an uninitialized texture (#5711) 2022-06-17 09:57:25 -07:00
LaiJF
a9a420f0eb Fix typo (#5713) 2022-06-16 20:56:14 -07:00
Ben Doherty
b90cf971d9 Update RELEASE_GUIDE with info on re-running 2022-06-16 13:25:06 -07:00
Philip Rideout
1ac57038d9 smolv blobs are now 8-byte aligned in filamat. (breaks materials) (#5705) 2022-06-16 11:23:52 -07:00
Philip Rideout
fe3be06c2c Vk: remove slow allocations workaround, fix scaniverse models. (#5708)
The vkmemalloc performance workaround we implemented with #4128 for Mali
is no longer necessary. Removing this fixes #5432.
2022-06-16 11:19:59 -07:00
Philip Rideout
1ff57e66aa BlueVKDarwin: Simplify the build and loading process. (#5701)
* BlueVKDarwin: Simplify the build and loading process.

Some of our CMake logic was not necessary because we do not staticly
link against anything for Vulkan.  All entry points are dynamically
loaded.

Some of the load-time code was also needlessly complicated. In fact the
ICD environment variable that we were setting is now deprecated.

I tested this PR with:

- macOS + June LunarG SDK
- Android on a Pixel 6

* Fix up, further simplification.
2022-06-15 16:08:34 -07:00
Philip Rideout
036c1706f5 Vk: set ENUMERATE_PORTABILITY_BIT for MoltenVK. (#5699)
This lets us avoid the following validation error.

    Attempting to create a VkDevice from a VkPhysicalDevice which is
    from a portability driver without the
    VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the
    VkInstanceCreateInfo flags being set...
2022-06-15 16:08:14 -07:00
Philip Rideout
467f0acdb4 Vk: do not raise SIGINT for validation errors. (#5700)
This was occasionally useful for debugging specific problems, but it is
much too intrusive to enable in all debug builds.
2022-06-15 16:07:58 -07:00
Philip Rideout
c910cab7a3 Fix bitrot in sample-page-curl (#5703) 2022-06-15 15:14:18 -07:00
Philip Rideout
74346d0046 Update instructions for Vulkan + macOS. (#5693) 2022-06-15 11:50:33 -07:00
5957 changed files with 449218 additions and 522795 deletions

BIN
.build.sh.un~ Normal file

Binary file not shown.

View File

@@ -13,7 +13,11 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3.3.0
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Run build script
run: |
cd build/android && printf "y" | ./build.sh continuous

View File

@@ -13,7 +13,7 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3.3.0
- name: Run build script
run: |
cd build/ios && printf "y" | ./build.sh continuous

View File

@@ -10,10 +10,10 @@ on:
jobs:
build-linux:
name: build-linux
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3.3.0
- name: Run build script
run: |
cd build/linux && printf "y" | ./build.sh continuous

View File

@@ -13,7 +13,7 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3.3.0
- name: Run build script
run: |
cd build/mac && printf "y" | ./build.sh continuous

View File

@@ -15,10 +15,10 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-18.04]
os: [macos-latest, ubuntu-22.04]
steps:
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3.3.0
- name: Run build script
run: |
WORKFLOW_OS=`echo \`uname\` | sed "s/Darwin/mac/" | tr [:upper:] [:lower:]`
@@ -32,7 +32,7 @@ jobs:
runs-on: windows-2019
steps:
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3.3.0
- name: Run build script
run: |
build\windows\build-github.bat presubmit
@@ -43,7 +43,11 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3.3.0
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Run build script
run: |
cd build/android && printf "y" | ./build.sh presubmit
@@ -53,7 +57,7 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3.3.0
- name: Run build script
run: |
cd build/ios && printf "y" | ./build.sh presubmit
@@ -66,7 +70,7 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3.3.0
- name: Run build script
run: |
cd build/web && printf "y" | ./build.sh presubmit

View File

@@ -31,7 +31,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-18.04]
os: [macos-latest, ubuntu-22.04]
steps:
- name: Decide Git ref
@@ -39,24 +39,29 @@ jobs:
run: |
REF=${RELEASE_TAG:-${GITHUB_REF}}
TAG=${REF##*/}
echo ::set-output name=ref::${REF}
echo ::set-output name=tag::${TAG}
- uses: actions/checkout@v2.0.0
echo "ref=${REF}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3.3.0
with:
ref: ${{ steps.git_ref.outputs.ref }}
- name: Run build script
env:
TAG: ${{ steps.git_ref.outputs.tag }}
run: |
WORKFLOW_OS=`echo \`uname\` | sed "s/Darwin/mac/" | tr [:upper:] [:lower:]`
cd build/$WORKFLOW_OS && printf "y" | ./build.sh release
- name: Upload release assets
run: |
xargs -L 1 sudo pip3 install < build/common/requirements.txt
cd ../..
if [ -f out/filament-release-darwin.tgz ]; then mv out/filament-release-darwin.tgz out/filament-${TAG}-mac.tgz; fi;
if [ -f out/filament-release-linux.tgz ]; then mv out/filament-release-linux.tgz out/filament-${TAG}-linux.tgz; fi;
python3 build/common/upload-assets.py ${TAG} out/*.tgz
- uses: actions/github-script@v6
env:
TAG: ${{ steps.git_ref.outputs.tag }}
GITHUB_API_KEY: ${{ secrets.GITHUB_API_KEY }}
with:
script: |
const upload = require('./build/common/upload-release-assets');
const { TAG } = process.env;
const globber = await glob.create('out/*.tgz');
await upload({ github, context }, await globber.glob(), TAG);
build-web:
name: build-web
@@ -69,22 +74,27 @@ jobs:
run: |
REF=${RELEASE_TAG:-${GITHUB_REF}}
TAG=${REF##*/}
echo ::set-output name=ref::${REF}
echo ::set-output name=tag::${TAG}
- uses: actions/checkout@v2.0.0
echo "ref=${REF}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3.3.0
with:
ref: ${{ steps.git_ref.outputs.ref }}
- name: Run build script
run: |
cd build/web && printf "y" | ./build.sh release
- name: Upload release assets
run: |
xargs -L 1 sudo pip3 install < build/common/requirements.txt
mv out/filament-release-web.tgz out/filament-${TAG}-web.tgz
python3 build/common/upload-assets.py ${TAG} out/*.tgz
env:
TAG: ${{ steps.git_ref.outputs.tag }}
GITHUB_API_KEY: ${{ secrets.GITHUB_API_KEY }}
run: |
cd build/web && printf "y" | ./build.sh release
cd ../..
mv out/filament-release-web.tgz out/filament-${TAG}-web.tgz
- uses: actions/github-script@v6
env:
TAG: ${{ steps.git_ref.outputs.tag }}
with:
script: |
const upload = require('./build/common/upload-release-assets');
const { TAG } = process.env;
const globber = await glob.create('out/*.tgz');
await upload({ github, context }, await globber.glob(), TAG);
build-android:
name: build-android
@@ -97,14 +107,26 @@ jobs:
run: |
REF=${RELEASE_TAG:-${GITHUB_REF}}
TAG=${REF##*/}
echo ::set-output name=ref::${REF}
echo ::set-output name=tag::${TAG}
- uses: actions/checkout@v2.0.0
echo "ref=${REF}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3.3.0
with:
ref: ${{ steps.git_ref.outputs.ref }}
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Run build script
env:
TAG: ${{ steps.git_ref.outputs.tag }}
run: |
cd build/android && printf "y" | ./build.sh release
cd ../..
mv out/filament-android-release.aar out/filament-${TAG}-android.aar
mv out/filamat-android-release.aar out/filamat-${TAG}-android.aar
mv out/filamat-android-lite-release.aar out/filamat-${TAG}-lite-android.aar
mv out/gltfio-android-release.aar out/gltfio-${TAG}-android.aar
mv out/filament-utils-android-release.aar out/filament-utils-${TAG}-android.aar
- name: Sign sample-gltf-viewer
run: |
echo "${APK_KEYSTORE_BASE64}" > filament.jks.base64
@@ -119,18 +141,15 @@ jobs:
TAG: ${{ steps.git_ref.outputs.tag }}
APK_KEYSTORE_BASE64: ${{ secrets.APK_KEYSTORE_BASE64 }}
APK_KEYSTORE_PASS: ${{ secrets.APK_KEYSTORE_PASS }}
- name: Upload release assets
run: |
xargs -L 1 sudo pip3 install < build/common/requirements.txt
mv out/filament-android-release.aar out/filament-${TAG}-android.aar
mv out/filamat-android-release.aar out/filamat-${TAG}-android.aar
mv out/filamat-android-lite-release.aar out/filamat-${TAG}-lite-android.aar
mv out/gltfio-android-release.aar out/gltfio-${TAG}-android.aar
mv out/filament-utils-android-release.aar out/filament-utils-${TAG}-android.aar
python3 build/common/upload-assets.py ${TAG} out/*.aar out/*.apk
- uses: actions/github-script@v6
env:
TAG: ${{ steps.git_ref.outputs.tag }}
GITHUB_API_KEY: ${{ secrets.GITHUB_API_KEY }}
with:
script: |
const upload = require('./build/common/upload-release-assets');
const { TAG } = process.env;
const globber = await glob.create(['out/*.aar', 'out/*.apk'].join('\n'));
await upload({ github, context }, await globber.glob(), TAG);
build-ios:
name: build-ios
@@ -143,22 +162,27 @@ jobs:
run: |
REF=${RELEASE_TAG:-${GITHUB_REF}}
TAG=${REF##*/}
echo ::set-output name=ref::${REF}
echo ::set-output name=tag::${TAG}
- uses: actions/checkout@v2.0.0
echo "ref=${REF}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3.3.0
with:
ref: ${{ steps.git_ref.outputs.ref }}
- name: Run build script
run: |
cd build/ios && printf "y" | ./build.sh release
- name: Upload release assets
run: |
xargs -L 1 sudo pip3 install < build/common/requirements.txt
mv out/filament-release-ios.tgz out/filament-${TAG}-ios.tgz
python3 build/common/upload-assets.py ${TAG} out/*.tgz
env:
TAG: ${{ steps.git_ref.outputs.tag }}
GITHUB_API_KEY: ${{ secrets.GITHUB_API_KEY }}
run: |
cd build/ios && printf "y" | ./build.sh release
cd ../..
mv out/filament-release-ios.tgz out/filament-${TAG}-ios.tgz
- uses: actions/github-script@v6
env:
TAG: ${{ steps.git_ref.outputs.tag }}
with:
script: |
const upload = require('./build/common/upload-release-assets');
const { TAG } = process.env;
const globber = await glob.create('out/*.tgz');
await upload({ github, context }, await globber.glob(), TAG);
build-windows:
name: build-windows
@@ -171,22 +195,26 @@ jobs:
run: |
REF=${RELEASE_TAG:-${GITHUB_REF}}
TAG=${REF##*/}
echo ::set-output name=ref::${REF}
echo ::set-output name=tag::${TAG}
echo "ref=${REF}" >> $GITHUB_OUTPUT
echo "tag=${TAG}" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3.3.0
with:
ref: ${{ steps.git_ref.outputs.ref }}
- name: Run build script
run: |
build\windows\build-github.bat release
shell: cmd
- name: Upload release assets
run: |
pip3 install PyGithub
mv out/filament-windows.tgz out/filament-${TAG}-windows.tgz
python build/common/upload-assets.py ${TAG} out/*.tgz
shell: bash
env:
TAG: ${{ steps.git_ref.outputs.tag }}
GITHUB_API_KEY: ${{ secrets.GITHUB_API_KEY }}
run: |
build\windows\build-github.bat release
cd ..\..
move out\filament-windows.tgz out\filament-%TAG%-windows.tgz
shell: cmd
- uses: actions/github-script@v6
env:
TAG: ${{ steps.git_ref.outputs.tag }}
with:
script: |
const upload = require('./build/common/upload-release-assets');
const { TAG } = process.env;
const globber = await glob.create('out/*.tgz');
await upload({ github, context }, await globber.glob(), TAG);

View File

@@ -24,3 +24,4 @@ jobs:
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ github.event.pull_request.number }}
release-notes-file: 'NEW_RELEASE_NOTES.md'

View File

@@ -13,7 +13,7 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3.3.0
- name: Run build script
run: |
cd build/web && printf "y" | ./build.sh continuous

View File

@@ -13,7 +13,7 @@ jobs:
runs-on: windows-2019
steps:
- uses: actions/checkout@v2.0.0
- uses: actions/checkout@v3.3.0
- name: Run build script
run: |
build\windows\build-github.bat continuous

View File

@@ -13,9 +13,10 @@ section below.
To build Filament for Android you must also install the following:
- Android Studio Arctic Fox or more recent
- Android Studio Flamingo or more recent
- Android SDK
- Android NDK "side-by-side" 23.1 or higher
- Android NDK 25.1 or higher
- Java 17
### Environment variables
@@ -92,6 +93,8 @@ Make sure you've installed the following dependencies:
- `libc++abi-7-dev` (`libcxxabi-static` on Fedora) or higher
- `ninja-build`
- `libxi-dev`
- `libxcomposite-dev` (`libXcomposite-devel` on Fedora)
- `libxxf86vm-dev` (`libXxf86vm-devel` on Fedora)
After dependencies have been installed, we highly recommend using the [easy build](#easy-build)
script.
@@ -144,6 +147,9 @@ make sure the command line tools are setup by running:
$ xcode-select --install
```
If you wish to run the Vulkan backend instead of the default Metal backend, you must install
the LunarG SDK, enable "System Global Components", and reboot your machine.
Then run `cmake` and `ninja` to trigger a build:
```
@@ -349,7 +355,7 @@ same version that our continuous builds use.
```
cd <your chosen parent folder for the emscripten SDK>
curl -L https://github.com/emscripten-core/emsdk/archive/refs/tags/3.1.9.zip > emsdk.zip
curl -L https://github.com/emscripten-core/emsdk/archive/refs/tags/3.1.15.zip > emsdk.zip
unzip emsdk.zip ; mv emsdk-* emsdk ; cd emsdk
python ./emsdk.py install latest
python ./emsdk.py activate latest
@@ -365,13 +371,11 @@ export EMSDK=<your chosen home for the emscripten SDK>
The EMSDK variable is required so that the build script can find the Emscripten SDK. The build
creates a `samples` folder that can be used as the root of a simple static web server. Note that you
cannot open the HTML directly from the filesystem due to CORS. One way to deal with this is to
use Python to create a quick localhost server:
cannot open the HTML directly from the filesystem due to CORS. We recommend using the emrun tool
to create a quick localhost server:
```
cd out/cmake-webgl-release/web/samples
python3 -m http.server # Python 3
python -m SimpleHTTPServer # Python 2.7
emrun out/cmake-webgl-release/web/samples --no_browser --port 8000
```
You can then open http://localhost:8000/suzanne.html in your web browser.

View File

@@ -23,26 +23,30 @@ option(FILAMENT_SUPPORTS_XCB "Include XCB support in Linux builds" ON)
option(FILAMENT_SUPPORTS_XLIB "Include XLIB support in Linux builds" ON)
option(FILAMENT_SUPPORTS_EGL_ON_LINUX "Use EGL for OpenGL in Linux builds" OFF)
option(FILAMENT_SUPPORTS_WAYLAND "Include Wayland support in Linux builds" OFF)
option(FILAMENT_SKIP_SDL2 "Skip dependencies of SDL2, and SDL2" OFF)
option(FILAMENT_LINUX_IS_MOBILE "Treat Linux as Mobile" OFF)
option(FILAMENT_ENABLE_ASAN_UBSAN "Enable Address and Undefined Behavior Sanitizers" OFF)
set(FILAMENT_NDK_VERSION "" CACHE STRING
"Android NDK version or version prefix to be used when building for Android."
)
set(FILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB "2" CACHE STRING
"Per render pass arena size. Must be roughly 1 MB larger than FILAMENT_PER_FRAME_COMMANDS_SIZE_IN_MB, default 2."
set(FILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB "3" CACHE STRING
"Per render pass arena size. Must be roughly 1 MB larger than FILAMENT_PER_FRAME_COMMANDS_SIZE_IN_MB, default 3."
)
set(FILAMENT_PER_FRAME_COMMANDS_SIZE_IN_MB "1" CACHE STRING
"Size of the high-level draw commands buffer. Rule of thumb, 1 MB less than FILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB, default 1."
set(FILAMENT_PER_FRAME_COMMANDS_SIZE_IN_MB "2" CACHE STRING
"Size of the high-level draw commands buffer. Rule of thumb, 1 MB less than FILAMENT_PER_RENDER_PASS_ARENA_SIZE_IN_MB, default 2."
)
set(FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB "1" CACHE STRING
"Size of the command-stream buffer. As a rule of thumb use the same value as FILAMENT_PER_FRRAME_COMMANDS_SIZE_IN_MB, default 1."
set(FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB "2" CACHE STRING
"Size of the command-stream buffer. As a rule of thumb use the same value as FILAMENT_PER_FRRAME_COMMANDS_SIZE_IN_MB, default 2."
)
set(FILAMENT_OPENGL_HANDLE_ARENA_SIZE_IN_MB "4" CACHE STRING
@@ -65,25 +69,30 @@ endif()
# ==================================================================================================
find_program(CCACHE_PROGRAM ccache)
if (CCACHE_PROGRAM)
set(C_LAUNCHER "${CCACHE_PROGRAM}")
set(CXX_LAUNCHER "${CCACHE_PROGRAM}")
configure_file(build/launch-c.in launch-c)
configure_file(build/launch-cxx.in launch-cxx)
execute_process(COMMAND chmod a+rx
"${CMAKE_BINARY_DIR}/launch-c"
"${CMAKE_BINARY_DIR}/launch-cxx"
)
if (CMAKE_GENERATOR STREQUAL "Xcode")
set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/launch-c")
set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/launch-cxx")
set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/launch-c")
set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/launch-cxx")
if (WIN32)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
else()
set(CMAKE_C_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-c")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-cxx")
set(C_LAUNCHER "${CCACHE_PROGRAM}")
set(CXX_LAUNCHER "${CCACHE_PROGRAM}")
configure_file(build/launch-c.in launch-c)
configure_file(build/launch-cxx.in launch-cxx)
execute_process(COMMAND chmod a+rx
"${CMAKE_CURRENT_BINARY_DIR}/launch-c"
"${CMAKE_CURRENT_BINARY_DIR}/launch-cxx"
)
if (CMAKE_GENERATOR STREQUAL "Xcode")
set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_CURRENT_BINARY_DIR}/launch-c")
set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_CURRENT_BINARY_DIR}/launch-cxx")
set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_CURRENT_BINARY_DIR}/launch-c")
set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_CURRENT_BINARY_DIR}/launch-cxx")
else()
set(CMAKE_C_COMPILER_LAUNCHER "${CMAKE_CURRENT_BINARY_DIR}/launch-c")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_CURRENT_BINARY_DIR}/launch-cxx")
endif()
endif()
endif()
@@ -97,22 +106,34 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# ==================================================================================================
if (UNIX AND NOT APPLE AND NOT ANDROID AND NOT WEBGL)
set(LINUX TRUE)
else()
# since cmake 3.25 LINUX is automatically set based on CMAKE_SYSTEM_NAME, which the android
# cmake files are setting to "Linux".
set(LINUX FALSE)
endif()
if (LINUX)
if (FILAMENT_SUPPORTS_WAYLAND)
add_definitions(-DFILAMENT_SUPPORTS_WAYLAND)
set(FILAMENT_SUPPORTS_X11 FALSE)
elseif (FILAMENT_SUPPORTS_EGL_ON_LINUX)
add_definitions(-DFILAMENT_SUPPORTS_EGL_ON_LINUX)
set(FILAMENT_SUPPORTS_X11 FALSE)
else ()
if (FILAMENT_SUPPORTS_XCB)
add_definitions(-DFILAMENT_SUPPORTS_XCB)
endif()
# Default Swiftshader build does not enable the xlib extension
if (FILAMENT_SUPPORTS_XLIB AND FILAMENT_USE_SWIFTSHADER)
set(FILAMENT_SUPPORTS_XLIB OFF)
endif()
if (FILAMENT_SUPPORTS_XLIB)
add_definitions(-DFILAMENT_SUPPORTS_XLIB)
endif()
if (FILAMENT_SUPPORTS_XCB OR FILAMENT_SUPORTS_XLIB)
if (FILAMENT_SUPPORTS_XCB OR FILAMENT_SUPPORTS_XLIB)
add_definitions(-DFILAMENT_SUPPORTS_X11)
set(FILAMENT_SUPPORTS_X11 TRUE)
endif()
@@ -275,6 +296,10 @@ if (FILAMENT_USE_EXTERNAL_GLES3)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_EXTERNAL_GLES3")
endif()
if (FILAMENT_SUPPORTS_EGL_ON_LINUX)
set(EGL TRUE)
endif()
if (FILAMENT_USE_SWIFTSHADER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFILAMENT_USE_SWIFTSHADER")
endif()
@@ -328,19 +353,23 @@ endif()
# ==================================================================================================
# Release compiler flags
# ==================================================================================================
if (NOT MSVC)
if (NOT MSVC AND NOT IOS)
# Omitting stack frame pointers prevents the generation of readable stack traces in crash reports on iOS
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer")
# These aren't compatible with -fembed-bitcode (and seem to have no effect on Apple platforms anyway)
if (NOT IOS)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffunction-sections -fdata-sections")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffunction-sections -fdata-sections")
endif()
# On Android RELEASE builds, we disable exceptions and RTTI to save some space (about 75 KiB
# saved by -fno-exception and 10 KiB saved by -fno-rtti).
if (ANDROID OR IOS OR WEBGL)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-exceptions -fno-rtti")
if (ANDROID OR WEBGL)
# Omitting unwind info prevents the generation of readable stack traces in crash reports on iOS
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-unwind-tables -fno-asynchronous-unwind-tables")
endif()
endif()
# With WebGL, we disable RTTI even for debug builds because we pass emscripten::val back and forth
@@ -350,13 +379,17 @@ if (WEBGL)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-rtti")
endif()
if (WEBGL_PTHREADS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
# ==================================================================================================
# Debug compiler flags
# ==================================================================================================
# ASAN is deactivated for now because:
# -fsanitize=undefined causes extremely long link times
# -fsanitize=address causes a crash with assimp, which we can't explain for now
#set(EXTRA_SANITIZE_OPTIONS "-fsanitize=undefined -fsanitize=address")
if (FILAMENT_ENABLE_ASAN_UBSAN)
set(EXTRA_SANITIZE_OPTIONS "-fsanitize=address -fsanitize=undefined")
endif()
if (NOT MSVC AND NOT WEBGL)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fstack-protector")
endif()
@@ -392,8 +425,8 @@ endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GC_SECTIONS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GC_SECTIONS} ${B_SYMBOLIC_FUNCTIONS}")
if (WEBGL)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s USE_WEBGL2=1")
if (WEBGL_PTHREADS)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pthread")
endif()
# ==================================================================================================
@@ -446,6 +479,13 @@ else()
option(FILAMENT_ENABLE_MATDBG "Enable the material debugger" OFF)
endif()
# By default, link in fgdbg for Desktop + Debug
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND IS_HOST_PLATFORM)
option(FILAMENT_ENABLE_FGDBG "Enable the framegraph debugger" ON)
else()
option(FILAMENT_ENABLE_FGDBG "Enable the framegraph debugger" OFF)
endif()
# Only optimize materials in Release mode (so error message lines match the source code)
if (CMAKE_BUILD_TYPE MATCHES Release)
option(FILAMENT_DISABLE_MATOPT "Disable material optimizations" OFF)
@@ -476,9 +516,14 @@ if (FILAMENT_SUPPORTS_METAL)
set(MATC_API_FLAGS ${MATC_API_FLAGS} -a metal)
endif()
# Disable optimizations and enable debug info (preserves names in SPIR-V)
# Enable debug info (preserves names in SPIR-V)
if (FILAMENT_ENABLE_MATDBG)
set(MATC_OPT_FLAGS ${MATC_OPT_FLAGS} -d)
endif()
# Disable optimizations
if (FILAMENT_DISABLE_MATOPT)
set(MATC_OPT_FLAGS -gd)
set(MATC_OPT_FLAGS ${MATC_OPT_FLAGS} -g)
endif()
set(MATC_BASE_FLAGS ${MATC_API_FLAGS} -p ${MATC_TARGET} ${MATC_OPT_FLAGS})
@@ -533,7 +578,7 @@ function(list_licenses OUTPUT MODULES)
endif()
endforeach()
configure_file(${FILAMENT}/build/licenses.inc.in ${OUTPUT})
endfunction(list_licenses)
endfunction()
set(COMBINE_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/build/linux/combine-static-libs.sh")
if (WIN32)
@@ -584,15 +629,6 @@ if (FILAMENT_USE_SWIFTSHADER)
find_library(SWIFTSHADER_VK NAMES vk_swiftshader HINTS "$ENV{SWIFTSHADER_LD_LIBRARY_PATH}")
message(STATUS "Found SwiftShader VK library in: ${SWIFTSHADER_VK}.")
add_definitions(-DFILAMENT_VKLIBRARY_PATH=\"${SWIFTSHADER_VK}\")
elseif (FILAMENT_SUPPORTS_VULKAN)
if (APPLE OR FILAMENT_LINUX_IS_MOBILE)
find_library(Vulkan_LIBRARY NAMES vulkan HINTS "$ENV{VULKAN_SDK}/lib" "$ENV{VULKAN_SDK}/macOS/lib")
if (Vulkan_LIBRARY)
set(Vulkan_FOUND ON)
message(STATUS "Found Vulkan library in SDK: ${Vulkan_LIBRARY}.")
add_definitions(-DFILAMENT_VKLIBRARY_PATH=\"${Vulkan_LIBRARY}\")
endif()
endif()
endif()
# ==================================================================================================
@@ -662,7 +698,8 @@ add_subdirectory(${EXTERNAL}/imgui/tnt)
add_subdirectory(${EXTERNAL}/robin-map/tnt)
add_subdirectory(${EXTERNAL}/smol-v/tnt)
add_subdirectory(${EXTERNAL}/benchmark/tnt)
add_subdirectory(${EXTERNAL}/meshoptimizer)
add_subdirectory(${EXTERNAL}/meshoptimizer/tnt)
add_subdirectory(${EXTERNAL}/mikktspace)
add_subdirectory(${EXTERNAL}/cgltf/tnt)
add_subdirectory(${EXTERNAL}/draco/tnt)
add_subdirectory(${EXTERNAL}/jsmn/tnt)
@@ -681,6 +718,10 @@ if (FILAMENT_BUILD_FILAMAT OR IS_HOST_PLATFORM)
if (FILAMENT_ENABLE_MATDBG OR IS_HOST_PLATFORM)
add_subdirectory(${LIBRARIES}/matdbg)
endif()
if (FILAMENT_ENABLE_FGDBG OR IS_HOST_PLATFORM)
add_subdirectory(${LIBRARIES}/fgdbg)
endif()
endif()
if (FILAMENT_SUPPORTS_VULKAN)
@@ -699,7 +740,9 @@ if (IS_HOST_PLATFORM)
if (FILAMENT_SUPPORTS_OPENGL)
add_subdirectory(${LIBRARIES}/bluegl)
endif()
add_subdirectory(${LIBRARIES}/filamentapp)
if (NOT FILAMENT_SKIP_SDL2)
add_subdirectory(${LIBRARIES}/filamentapp)
endif()
add_subdirectory(${LIBRARIES}/imageio)
add_subdirectory(${FILAMENT}/samples)

View File

@@ -164,8 +164,7 @@ private:
### Strings
- Never use `std::string` in the Filament core renderer. Prefer `utils::CString` or
`utils::StaticString`.
- Never use `std::string` in the Filament core renderer. Prefer `utils::CString` or `std::string_view`.
- When using `std::string` in tools, always include the `std::` qualifier to disambiguate it
from other string types.

View File

@@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Copyright 2023 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

12
NEW_RELEASE_NOTES.md Normal file
View File

@@ -0,0 +1,12 @@
# Filament Release Notes log
**If you are merging a PR into main**: please add the release note below, under the *Release notes
for next branch cut* header.
**If you are cherry-picking a commit into an rc/ branch**: add the release note under the
appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md).
## Release notes for next branch cut
- engine: a new feature to set a transform on the global-scale fog [⚠️ **Recompile materials**]
- engine: large-scale fog can now be opted-out on a per-renderable basis

View File

@@ -31,7 +31,7 @@ repositories {
}
dependencies {
implementation 'com.google.android.filament:filament-android:1.23.2'
implementation 'com.google.android.filament:filament-android:1.36.0'
}
```
@@ -41,7 +41,6 @@ Here are all the libraries available in the group `com.google.android.filament`:
| ------------- | ------------- |
| [![filament-android](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-android/badge.svg?subject=filament-android)](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-android) | The Filament rendering engine itself. |
| [![gltfio-android](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/gltfio-android/badge.svg?subject=gltfio-android)](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/gltfio-android) | A glTF 2.0 loader for Filament, depends on `filament-android`. |
| [![gltfio-android-lite](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/gltfio-android-lite/badge.svg?subject=gltfio-android-lite)](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/gltfio-android-lite) | Trimmed version of `gltfio` that does not support some glTF extensions. |
| [![filament-utils-android](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-utils-android/badge.svg?subject=filament-utils-android)](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filament-utils-android) | KTX loading, Kotlin math, and camera utilities, depends on `gltfio-android`. |
| [![filamat-android](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filamat-android/badge.svg?subject=filamat-android)](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filamat-android) | A runtime material builder/compiler. This library is large but contains a full shader compiler/validator/optimizer and supports both OpenGL and Vulkan. |
| [![filamat-android-lite](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filamat-android-lite/badge.svg?subject=filamat-android-lite)](https://maven-badges.herokuapp.com/maven-central/com.google.android.filament/filamat-android-lite) | A much smaller alternative to `filamat-android` that can only generate OpenGL shaders. It does not provide validation or optimizations. |
@@ -51,7 +50,7 @@ Here are all the libraries available in the group `com.google.android.filament`:
iOS projects can use CocoaPods to install the latest release:
```
pod 'Filament', '~> 1.23.2'
pod 'Filament', '~> 1.36.0'
```
### Snapshots
@@ -117,9 +116,9 @@ steps:
- Image-based lighting
- Physically-based camera (shutter speed, sensitivity and aperture)
- Physical light units
- Point lights, spot lights and directional light
- Point lights, spot lights, and directional light
- Specular anti-aliasing
- Spot and directional light shadows
- Point, spot, and directional light shadows
- Cascaded shadows
- EVSM, PCSS, DPCF, or PCF shadows
- Transparent shadows
@@ -179,6 +178,7 @@ steps:
- [x] KHR_mesh_quantization
- [x] KHR_texture_basisu
- [x] KHR_texture_transform
- [x] EXT_meshopt_compression
## Rendering with Filament
@@ -312,6 +312,7 @@ and tools.
- `bluegl`: OpenGL bindings for macOS, Linux and Windows
- `bluevk`: Vulkan bindings for macOS, Linux, Windows and Android
- `camutils`: Camera manipulation utilities
- `fgdbg`: Frame Graph inspector and debugger (debug builds only)
- `filabridge`: Library shared by the Filament engine and host tools
- `filaflat`: Serialization/deserialization library used for materials
- `filagui`: Helper library for [Dear ImGui](https://github.com/ocornut/imgui)

View File

@@ -13,22 +13,7 @@ Before starting, ensure that each of these branches is up-to-date with origin:
It should have the version corresponding to its name, $RELEASE.
## 1. Update RELEASE_NOTES.md on the rc branch.
Checkout the rc/$RELEASE branch. In RELEASE_NOTES.md, locate the header corresponding to $RELEASE
and write release notes. To see which commits make up the release, run:
```
build/common/release.sh -c rc/$RELEASE
```
Commit the changes to rc/$RELEASE with the title:
```
Update RELEASE_NOTES for $RELEASE
```
## 2. Bump versions on main to $RELEASE.
## 1. Bump versions on main to $RELEASE.
Checkout main and run the following command to bump Filament's version to $RELEASE:
@@ -44,49 +29,19 @@ Release Filament $RELEASE
Do not push to origin yet.
## 3. Cherry-pick RELEASE_NOTES change from rc branch to main.
## 2. Update RELEASE_NOTES.md on main.
```
git cherry-pick rc/$RELEASE
```
Create a new header in RELEASE_NOTES.md for $NEXT_RELEASE. Copy the release notes in
NEW_RELEASE_NOTES.md to RELEASE_NOTES.md under the new header. Clear NEW_RELEASE_NOTES.md.
Update the headers. The "main branch" header becomes a header for $NEXT_RELEASE, and a new "main
branch" header is added.
For example, this:
```
## main branch
- foo
- bar
## v1.9.3
- baz
- bat
```
becomes:
```
## main branch
## v1.9.4
- foo
- bar
## v1.9.3
- baz
- bat
```
Ammend these changes to the cherry-picked change.
Amend these changes to the "Release Filament $RELEASE" commit.
```
git add -u
git commit --amend --no-edit
```
## 4. Run release script.
## 3. Run release script.
```
build/common/release.sh rc/$RELEASE rc/$NEXT_RELEASE
@@ -95,18 +50,18 @@ build/common/release.sh rc/$RELEASE rc/$NEXT_RELEASE
This script will merge rc/$RELEASE into release, delete the rc branch, and create a new rc
branch called rc/$NEXT_RELEASE. Verify that everything looks okay locally.
## 5. Push the release branch.
## 4. Push the release branch.
```
git push origin release
```
## 6. Create the GitHub release.
## 5. Create the GitHub release.
Use the GitHub UI to create a GitHub release corresponding to $RELEASE version.
Make sure the target is set to the release branch.
## 7. Delete the old rc branch (optional).
## 6. Delete the old rc branch (optional).
This step is optional. The old rc branch may be left alive for a few weeks for posterity.
@@ -114,7 +69,7 @@ This step is optional. The old rc branch may be left alive for a few weeks for p
git push origin --delete rc/$RELEASE
```
## 8. Bump the version on the new rc branch to $NEXT_RELEASE.
## 7. Bump the version on the new rc branch to $NEXT_RELEASE.
```
git checkout rc/$NEXT_RELEASE
@@ -127,14 +82,45 @@ Commit the changes to rc/$NEXT_RELEASE with the title:
Bump version to $NEXT_RELEASE
```
## 9. Push main.
## 8. Push main.
```
git push origin main
```
## 10. Push the new rc branch.
## 9. Push the new rc branch.
```
git push origin -u rc/$NEXT_RELEASE
```
## 10. Rebuild the GitHub release (if failed).
Sometimes the GitHub release job will fail. In this case, you can manually re-run the release job.
### Remove any assets uploaded to the release (if needed).
For example, if rebuilding the Mac release, ensure that the `filament-<version>-mac.tgz` artifact
is removed from the release assets.
### Update the release branch (if needed).
If you need to add one or more new commits to the release, perform the following:
First, push the new commit(s) to the `release` branch.
Then, with the release branch checked out with the new commit(s), run
```
git tag -f -a <release tagname>
git push origin -f <release tagname>
```
This will update and force push the tag.
### Re-run the GitHub release workflow
Navigate to [Filament's release
workflow](https://github.com/google/filament/actions/workflows/release.yml). Hit the _Run workflow_
dropdown. Modify _Platform to build_ and _Release tag to build_, then hit _Run workflow_. This will
initiate a new release run.

View File

@@ -3,10 +3,239 @@
This file contains one line summaries of commits that are worthy of mentioning in release notes.
A new header is inserted each time a *tag* is created.
## main branch
**Do not edit this file unless you are performing a release or cherry-picking into an rc/ branch.**
Instead, if you are authoring a PR for the main branch, add your release note to
[NEW_RELEASE_NOTES.md](./NEW_RELEASE_NOTES.md).
## v1.23.3
## v1.37.0
- backend: added `Platform` blob cache APIs, typically used to cache programs [⚠️ **Recompile materials**]
## v1.36.0
- engine: a local transform can now be supplied for each GPU instance [⚠️ **Recompile materials**]
- everything: Add limited support for OpenGL ES 2.0 devices. [⚠️ **Recompile Materials**]
- platform: New virtual on `OpenGLPlatform` to preserve ancillary buffers
## v1.35.0
- materials: Materials can now access up to 4 global `vec4` visible by all materials [⚠️ **Recompile Materials**]
## v1.34.0
- materials: picking is done in float (prepare for ES2) [⚠️ **New Material Version**]
- materials: postLightingBlending is now applied before the fog [⚠️ **Recompile materials**]
- vulkan: fix adreno optimized material artifacts [⚠️ **Recompile Materials**]
## v1.33.0
- materials: prepare ES2 support [⚠️ **New Material Version**]
## v1.32.4
- engine: Add support for _constant parameters_, which are constants that can be specialized after material compilation.
- materials: improved size reduction of OpenGL/Metal shaders by ~65% when compiling materials with
size optimizations (`matc -S`) [⚠️ **Recompile Materials**]
- engine: fix potential crash on Metal devices with A8X GPU (iPad Air 2) [⚠️ **Recompile Materials**]
- opengl: support the external image on macOS
## v1.32.3
- fog: added an option to disable the fog after a certain distance [⚠️ **Recompile Materials**].
- fog: fog color now takes exposure and IBL intensity into account [⚠️ **Recompile Materials**].
- materials: implement cascades debugging as a post-process [⚠️ **Recompile Materials**].
- materials: use 9 digits or less for floats [⚠️ **Recompile Materials**].
- gltfio: fix skinning when objects are far from the origin
- materials: remove 4 unneeded variants from `unlit` materials [⚠️ **Recompile Materials**].
## v1.32.2
- lighting: the sun disc was computed in low/medium quality instead of high quality. This will
provide performance improvements to mobile devices [⚠️ **Recompile Materials**]
## v1.32.1
## v1.32.0
- fog: fixed fog height falloff and computation precision on mobile [⚠️ **Recompile Materials**]
- materials: new alphaToCoverage property can be used to control alpha to coverage behavior
- materials: added `getUserWorldFromWorldMatrix()` and `getUserWorldPosition()` to retrieve the
API-level (user) world position in materials. Deprecated `getWorldOffset()`. [⚠️ **Recompile
Materials**]
- engine: fix precision issue with `shading_view` in large scenes
- vulkan: readPixels is now async (#6560)
## v1.31.7
## v1.31.6
- engine: the default render channel is now 2 instead of 0
- gltfio: Fix crash when a MIME type has no texture provider
## v1.31.5
- gltfio: fix potential early freeing of data provided with `ResourceLoader::addResourceData`.
## v1.31.4
- engine: fix broken picking [⚠️ **Recompile Materials to get the fix**]
- engine: added support for sRGB swapchains. See `SwapChain.h`
- bluegl: support Windows32
## v1.31.3
- vulkan: fix memory leak in readPixels
- engine: added support for draw-commands channels (stronger ordering of commands/renderables)
## v1.31.2
## v1.31.1
- gltfio: expose joint inverse bind matrices via method on FilamentInstance
- filamesh: add error when uv coords size does not match num of vertices. (#6351)
## v1.31.0
- java: fix confusing typo in Camera documentation
- engine: the output color space can be set on `ColorGrading`. This API currently has limitations,
please refer to the documentation for more details
- Support for RGTC and BPTC texture compression
- engine: fix TransformManager high precision mode when using transactions
- web: added TypeScript definition for `Engine.destroy`
- materials: `getNormalizedViewportCoord()` now returns the logical (i.e. user) viewport
normalized position and keeps z reversed [⚠️ **Recompile Materials**]
- backend: workaround Adreno shader compiler bug (#6355) [⚠️ **Recompile Materials**]
- geometry: change computing tangent basis from normal vector to use Frisvad's method
## v1.30.0
- engine: optimize per-shadow UBO [⚠️ **Recompile Materials**]
- engine: fix potential memory corruption with larger scenes
- engine: VSM's MSAA setting is now per-view instead of per-light [⚠️ **API Change**]
## v1.29.0
- gltfio: calculate primitive's AABB correctly.
- gltfio: recompute bounding boxes with morph targets
- engine: add missing getters on `MaterialInstance`
- WebGL: add missing `ColorGrading` JS bindings
- engine: improvements/cleanup of Shadow mapping code [⚠️ **Recompile Materials**]
## v1.28.3
- backend: add support for GGP platform
- engine: primitives with `CullingMode::FRONT_AND_BACK` are now skipped.
## v1.28.2
- gltfio: support EXT_meshopt_compression
- release packaging: fixed location of default IBL file
## v1.28.1
- gltfio: fix reloading crash in ubershader mode
- Vulkan: improve performance in the readPixels path
- engine: raise the spot shadows limit to 64, from 14.
- engine: add experimental support for point light shadows.
- gltfio: fix ubershader issues with assignment of dummy textures
- gltfio: material instances and variants are now accessed via `FilamentInstance` [⚠️ **API Change**]
- gltfio: the animator can now only be accessed via `FilamentInstance` [⚠️ **API Change**]
- engine: fix "stable" shadows and make the default cascade splits logarithmic.
- engine: Add new quality options to EVSM shadows + rendering fixes
## v1.28.0
- engine: LiSPSM is now a user settable option
- engine: get the morph target buffer to the given primitive
- Java: Fix TransformManager.getChildren()
- Metal: newer devices are no longer limited to 16 samplers per Material.
- gltfio: fix interpretation of occlusion strength
- engine: minsdk is now 21 instead of 19. This allows the use of OpenGL ES 3.1
- Vulkan: fix black screen regression
## v1.27.2
- gltfio: punctual lights are now duplicated when adding new asset instances
- gltfio: FilamentInstance getAsset method now returns an immutable asset
- gltfio: allow zero-instance assets
- gltfio: fix regression with meshes that have no material
- gltfio: fix regression with recomputeBoundingBoxes()
- filamesh / matinfo: fix minor ASAN issues
- engine: Added `Engine::resetBackendState()`, available only in WebGL builds
## v1.27.1
- Java: add methods for TransformManager.getChildCount(), TransformManager.getChildren() and Scene.hasEntity()
- engine: Fix stencil buffer writes with OpenGL backend.
- gltfio: add new virtual method to MaterialProvider that all plugins must implement
- gltfio: add an assert for inconsistent sRGB flags among usages of a particular texture
- engine: improve scissor documentation
- backend: scissor is no longer clipped to the viewport (done on filament side)
- samples: add debug overdraw visualization to gltf_viewer
## v1.27.0
- WebGL: reduce max instance count to work around Chrome issues [⚠️ **Recompile Materials**]
- engine: rework material/shader sampler binding code [⚠️ **Recompile Materials**]
- gltfio: move the API for `recomputeBoundingBoxes` [⚠️ **API Change**]
- engine: add support for specialization constants [⚠️ **Recompile Materials**]
- gltfio: fix spotlight regression
- gltfio: clear the MaterialInstance cache when creating new instances
## v1.26.0
- engine: new feature level APIs, see `Engine::getSupportedFeatureLevel()`
- engine: add new stencil API to `View` and stencil state APIs to `MaterialInstance` [**NEW API**].
- engine: Fix guard bands and TAA with `vertexDomain:Device` [⚠️ **Recompile Materials**]
- engine: `clipSpaceTransform` is now only available with `vertexDomain:Device` [⚠️ **API Change**]
- gltfio: add unified `AssetLoader::createAsset()` method [⚠️ **API Change**]
- gltfio: all assets are now "instanced" [⚠️ **API Change**]
## v1.25.6
- engine: Add `CONFIG_MINSPEC_UBO_SIZE` as a nicer way to allow exceeding the ES3.0 minspec.
- gltfio: minor efficiency improvement for Android and WebGL builds.
- gltfio: add support for concurrent texture downloading and decoding.
## v1.25.5
- WebGL: upgraded the JS bindings to work with emsdk 3.1.15
- WebGL: added missing IBL builder to TypeScript annotations
- engine: Fix incorrect precision restoration when computing accurate world translations
- engine: make `MaterialInstance` public API friendly to `std::string_view` parameters
- gltfio: add 'detach' methods to allow ownership transfer of entities and components
## v1.25.4
- backend: streamline texture upload APIs [⚠️ **API Change**]
## v1.25.3
- engine: Fix Adreno gpu crash introduced by gpu morph target change
- engine: Add optional memory configuration parameters to Engine initialization
## v1.25.2
- engine: `Camera::getNear()` and `Camera::getCullingFar()` now return `doubles`
- Metal: implement scissor support.
- engine: `Renderer::getUserTime()` now returns seconds as documented (#5722) [⚠️ **API Fix**]
## v1.25.1
- engine: add support for automatic instancing. Must be enabled with `Engine::setAutomaticInstancingEnabled(bool)`
## v1.25.0
- Vulkan: smol-v blobs are now 8-byte aligned within the filamat archive. [⚠️ **Recompile Materials**]
- backend: added support for EGL on linux (headless)
- uberz tool: add --append and --template arguments.
- matc tool: add --template argument.
## v1.24.0
- ImGuiHelper: add support for Y flip.
- Metal: ignore `MTLTexture` formatting when importing external textures.
- materials: add a new `instanced` material parameter that is now mandatory in order to call `getInstanceIndex()`
- gltfio: UbershaderProvider now takes the ubershader archive in its constructor [⚠️ **API Change**]
- gltfio: Fix morphing with sparse accessors.

View File

@@ -12,7 +12,10 @@
// When set, support for Vulkan will be excluded.
//
// com.google.android.filament.matdbg
// When set, enables matdbg, disables shader optimizations
// When set, enables matdbg
//
// com.google.android.filament.matnopt
// When set, disable shader optimizations.
//
// com.google.android.filament.skip-samples
// Exclude samples from the project. Useful to speed up compilation.
@@ -29,15 +32,12 @@
// Publishing to Maven Central:
// - Build and upload artifacts with ./gradlew publish
// - Close and release staging repo on Nexus with ./gradlew closeAndReleaseRepository
// - Close and release staging repo on Nexus with ./gradlew closeAndReleaseStagingRepository
//
// The following is needed in ~/gradle/gradle.properties:
//
// SONATYPE_NEXUS_USERNAME=nexus_user
// SONATYPE_NEXUS_PASSWORD=nexus_password
//
// nexusUsername=nexus_user
// nexusPassword=nexus_password
// sonatypeUsername=nexus_user
// sonatypePassword=nexus_password
//
// signing.keyId=pgp_key_id
// signing.password=pgp_key_password
@@ -47,7 +47,7 @@
buildscript {
def path = providers
.gradleProperty("com.google.android.filament.dist-dir")
.forUseAtConfigurationTime().get()
.get()
def directory = objects.fileProperty().fileValue(new File(path)).getAsFile().get()
def filamentPath = directory.absolutePath
@@ -59,18 +59,19 @@ buildscript {
// Warning: changing this property does not work well with incremental builds.
def excludeVulkan = providers
.gradleProperty("com.google.android.filament.exclude-vulkan")
.forUseAtConfigurationTime()
.isPresent()
def matdbg = providers
.gradleProperty("com.google.android.filament.matdbg")
.forUseAtConfigurationTime()
.isPresent()
def matnopt = providers
.gradleProperty("com.google.android.filament.matnopt")
.isPresent()
def abis = ["arm64-v8a", "armeabi-v7a", "x86_64", "x86"]
def newAbis = providers
.gradleProperty("com.google.android.filament.abis")
.forUseAtConfigurationTime()
.get()
.split(',')
if (!newAbis.contains("all")) {
@@ -78,19 +79,22 @@ buildscript {
}
ext.versions = [
'jdk': 17,
'minSdk': 19,
'targetSdk': 31,
'compileSdk': 31,
'kotlin': '1.6.21',
'kotlin_coroutines': '1.6.1',
'buildTools': '32.0.0',
'ndk': '24.0.8215888'
'targetSdk': 33,
'compileSdk': 33,
'kotlin': '1.8.20',
'kotlin_coroutines': '1.6.4',
'buildTools': '33.0.2',
'ndk': '25.1.8937393',
'androidx_core': '1.10.0',
'androidx_annotations': '1.3.0'
]
ext.deps = [
'androidx': [
'annotations': "androidx.annotation:annotation:1.3.0",
'core': "androidx.core:core:1.7.0",
'annotations': "androidx.annotation:annotation:${versions.androidx_annotations}",
'core': "androidx.core:core:${versions.androidx_core}",
],
'kotlin': "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}",
'coroutines': [
@@ -100,8 +104,7 @@ buildscript {
]
dependencies {
// NOTE: See TODO in gradle.properties once we move to Gradle 7.4
classpath 'com.android.tools.build:gradle:7.2.0'
classpath 'com.android.tools.build:gradle:8.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
}
@@ -113,7 +116,7 @@ buildscript {
"-DFILAMENT_DIST_DIR=${filamentPath}".toString(),
"-DFILAMENT_SUPPORTS_VULKAN=${excludeVulkan ? 'OFF' : 'ON'}".toString(),
"-DFILAMENT_ENABLE_MATDBG=${matdbg ? 'ON' : 'OFF'}".toString(),
"-DFILAMENT_DISABLE_MATOPT=${matdbg ? 'ON' : 'OFF'}".toString()
"-DFILAMENT_DISABLE_MATOPT=${matnopt ? 'ON' : 'OFF'}".toString()
]
ext.cppFlags = [
@@ -124,6 +127,7 @@ buildscript {
"-fno-asynchronous-unwind-tables",
"-fno-rtti",
"-ffast-math",
"-fno-finite-math-only",
"-ffp-contract=fast",
"-fvisibility-inlines-hidden",
"-fvisibility=hidden",
@@ -148,14 +152,18 @@ buildscript {
}
plugins {
id 'io.codearte.nexus-staging' version '0.30.0'
id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
}
// Nexus Staging configuration
// See https://github.com/Codearte/gradle-nexus-staging-plugin/
nexusStaging {
// See https://github.com/gradle-nexus/publish-plugin
// Publish to https://oss.sonatype.org/ (not s01)
nexusPublishing {
packageGroup = 'com.google.android'
stagingProfileId = '9a75a224a4f17b'
repositories {
sonatype {
stagingProfileId = '9a75a224a4f17b'
}
}
}
subprojects {
@@ -187,6 +195,7 @@ subprojects {
}
ndk {
//noinspection ChromeOsAbiSupport
abiFilters(*rootProject.ext.abis)
}
@@ -207,8 +216,8 @@ subprojects {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility versions.jdk
targetCompatibility versions.jdk
}
}
}

View File

@@ -142,6 +142,14 @@ abstract class MaterialCompiler extends TaskWithBinary {
if (!exclude_vulkan) {
matcArgs += ['-a', 'vulkan']
}
def mat_no_opt = providers
.gradleProperty("com.google.android.filament.matnopt")
.forUseAtConfigurationTime().present
if (mat_no_opt) {
matcArgs += ['-g']
}
matcArgs += ['-a', 'opengl', '-p', 'mobile', '-o', getOutputFile(file), file]
exec.exec {

View File

@@ -17,6 +17,17 @@ android {
}
}
}
publishing {
singleVariant("fullRelease") {
withSourcesJar()
withJavadocJar()
}
singleVariant("liteRelease") {
withSourcesJar()
withJavadocJar()
}
}
}
dependencies {

View File

@@ -126,8 +126,8 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderUniform
JNIEnv* env, jclass, jlong nativeBuilder, jint uniformType, jint precision, jstring name_) {
auto builder = (MaterialBuilder*) nativeBuilder;
const char* name = env->GetStringUTFChars(name_, nullptr);
builder->parameter((MaterialBuilder::UniformType) uniformType,
(MaterialBuilder::ParameterPrecision) precision, name);
builder->parameter(name, (MaterialBuilder::UniformType) uniformType,
(MaterialBuilder::ParameterPrecision) precision);
env->ReleaseStringUTFChars(name_, name);
}
@@ -137,8 +137,8 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderUniform
jstring name_) {
auto builder = (MaterialBuilder*) nativeBuilder;
const char* name = env->GetStringUTFChars(name_, nullptr);
builder->parameter((MaterialBuilder::UniformType) uniformType, (size_t) size,
(MaterialBuilder::ParameterPrecision) precision, name);
builder->parameter(name, (size_t) size, (MaterialBuilder::UniformType) uniformType,
(MaterialBuilder::ParameterPrecision) precision);
env->ReleaseStringUTFChars(name_, name);
}
@@ -148,9 +148,8 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderSampler
jint precision, jstring name_) {
auto builder = (MaterialBuilder*) nativeBuilder;
const char* name = env->GetStringUTFChars(name_, nullptr);
builder->parameter((MaterialBuilder::SamplerType) samplerType,
(MaterialBuilder::SamplerFormat) format, (MaterialBuilder::ParameterPrecision) precision,
name);
builder->parameter(name, (MaterialBuilder::SamplerType) samplerType,
(MaterialBuilder::SamplerFormat) format, (MaterialBuilder::ParameterPrecision) precision);
env->ReleaseStringUTFChars(name_, name);
}
@@ -251,6 +250,13 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderMaskThr
builder->maskThreshold(maskThreshold);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderAlphaToCoverage(JNIEnv*,
jclass, jlong nativeBuilder, jboolean enable) {
auto builder = (MaterialBuilder*) nativeBuilder;
builder->alphaToCoverage(enable);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderShadowMultiplier(
JNIEnv*, jclass, jlong nativeBuilder, jboolean shadowMultiplier) {

View File

@@ -360,6 +360,12 @@ public class MaterialBuilder {
return this;
}
@NonNull
public MaterialBuilder alphaToCoverage(boolean enable) {
nMaterialBuilderAlphaToCoverage(mNativeObject, enable);
return this;
}
@NonNull
public MaterialBuilder shadowMultiplier(boolean shadowMultiplier) {
nMaterialBuilderShadowMultiplier(mNativeObject, shadowMultiplier);
@@ -584,6 +590,7 @@ public class MaterialBuilder {
private static native void nMaterialBuilderDepthCulling(long nativeBuilder, boolean enable);
private static native void nMaterialBuilderDoubleSided(long nativeBuilder, boolean doubleSided);
private static native void nMaterialBuilderMaskThreshold(long nativeBuilder, float mode);
private static native void nMaterialBuilderAlphaToCoverage(long nativeBuilder, boolean enable);
private static native void nMaterialBuilderShadowMultiplier(long mNativeObject,
boolean shadowMultiplier);

View File

@@ -1,5 +1,12 @@
android {
namespace 'com.google.android.filament'
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}
dependencies {

View File

@@ -84,13 +84,13 @@ Java_com_google_android_filament_Camera_nLookAt(JNIEnv*, jclass, jlong nativeCam
camera->lookAt({eye_x, eye_y, eye_z}, {center_x, center_y, center_z}, {up_x, up_y, up_z});
}
extern "C" JNIEXPORT jfloat JNICALL
extern "C" JNIEXPORT jdouble JNICALL
Java_com_google_android_filament_Camera_nGetNear(JNIEnv*, jclass, jlong nativeCamera) {
Camera *camera = (Camera *) nativeCamera;
return camera->getNear();
}
extern "C" JNIEXPORT jfloat JNICALL
extern "C" JNIEXPORT jdouble JNICALL
Java_com_google_android_filament_Camera_nGetCullingFar(JNIEnv*, jclass,
jlong nativeCamera) {
Camera *camera = (Camera *) nativeCamera;

View File

@@ -316,3 +316,36 @@ Java_com_google_android_filament_Engine_nGetEntityManager(JNIEnv*, jclass, jlong
Engine* engine = (Engine*) nativeEngine;
return (jlong) &engine->getEntityManager();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Engine_nSetAutomaticInstancingEnabled(JNIEnv*, jclass, jlong nativeEngine, jboolean enable) {
Engine* engine = (Engine*) nativeEngine;
engine->setAutomaticInstancingEnabled(enable);
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nIsAutomaticInstancingEnabled(JNIEnv*, jclass, jlong nativeEngine) {
Engine* engine = (Engine*) nativeEngine;
return (jboolean)engine->isAutomaticInstancingEnabled();
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Engine_nGetSupportedFeatureLevel(JNIEnv *, jclass,
jlong nativeEngine) {
Engine* engine = (Engine*) nativeEngine;
return (jint)engine->getSupportedFeatureLevel();
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Engine_nSetActiveFeatureLevel(JNIEnv *, jclass,
jlong nativeEngine, jint ordinal) {
Engine* engine = (Engine*) nativeEngine;
return (jint)engine->setActiveFeatureLevel((Engine::FeatureLevel)ordinal);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Engine_nGetActiveFeatureLevel(JNIEnv *, jclass,
jlong nativeEngine) {
Engine* engine = (Engine*) nativeEngine;
return (jint)engine->getActiveFeatureLevel();
}

View File

@@ -76,10 +76,10 @@ extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderShadowOptions(JNIEnv* env, jclass,
jlong nativeBuilder, jint mapSize, jint cascades, jfloatArray splitPositions,
jfloat constantBias, jfloat normalBias, jfloat shadowFar, jfloat shadowNearHint,
jfloat shadowFarHint, jboolean stable,
jfloat shadowFarHint, jboolean stable, jboolean lispsm,
jfloat polygonOffsetConstant, jfloat polygonOffsetSlope,
jboolean screenSpaceContactShadows, jint stepCount,
jfloat maxShadowDistance, jint vsmMsaaSamples, jfloat blurWidth, jfloat shadowBulbRadius) {
jfloat maxShadowDistance, jboolean elvsm, jfloat blurWidth, jfloat shadowBulbRadius) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
LightManager::ShadowOptions shadowOptions {
.mapSize = (uint32_t)mapSize,
@@ -90,13 +90,14 @@ Java_com_google_android_filament_LightManager_nBuilderShadowOptions(JNIEnv* env,
.shadowNearHint = shadowNearHint,
.shadowFarHint = shadowFarHint,
.stable = (bool)stable,
.lispsm = (bool)lispsm,
.polygonOffsetConstant = polygonOffsetConstant,
.polygonOffsetSlope = polygonOffsetConstant,
.screenSpaceContactShadows = (bool)screenSpaceContactShadows,
.stepCount = uint8_t(stepCount),
.maxShadowDistance = maxShadowDistance,
.vsm = {
.msaaSamples = (uint8_t) vsmMsaaSamples,
.elvsm = (bool)elvsm,
.blurWidth = blurWidth
},
.shadowBulbRadius = shadowBulbRadius

View File

@@ -153,6 +153,14 @@ Java_com_google_android_filament_Material_nIsDoubleSided(JNIEnv*, jclass,
return (jboolean) material->isDoubleSided();
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Material_nIsAlphaToCoverageEnabled(JNIEnv*, jclass,
jlong nativeMaterial) {
Material* material = (Material*) nativeMaterial;
return (jboolean) material->isAlphaToCoverageEnabled();
}
extern "C"
JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_Material_nGetMaskThreshold(JNIEnv*, jclass,

View File

@@ -341,6 +341,14 @@ Java_com_google_android_filament_MaterialInstance_nSetDepthWrite(JNIEnv*,
instance->setDepthWrite(enable);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetStencilWrite(JNIEnv*, jclass,
jlong nativeMaterialInstance, jboolean enable) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
instance->setStencilWrite(enable);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetDepthCulling(JNIEnv*,
@@ -349,6 +357,70 @@ Java_com_google_android_filament_MaterialInstance_nSetDepthCulling(JNIEnv*,
instance->setDepthCulling(enable);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetStencilCompareFunction(JNIEnv*, jclass,
jlong nativeMaterialInstance, jlong function, jlong face) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
instance->setStencilCompareFunction(
static_cast<MaterialInstance::StencilCompareFunc>(function),
static_cast<MaterialInstance::StencilFace>(face));
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetStencilOpStencilFail(JNIEnv*, jclass,
jlong nativeMaterialInstance, jlong op, jlong face) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
instance->setStencilOpStencilFail(
static_cast<MaterialInstance::StencilOperation>(op),
static_cast<MaterialInstance::StencilFace>(face));
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetStencilOpDepthFail(JNIEnv*, jclass,
jlong nativeMaterialInstance, jlong op, jlong face) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
instance->setStencilOpDepthFail(
static_cast<MaterialInstance::StencilOperation>(op),
static_cast<MaterialInstance::StencilFace>(face));
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetStencilOpDepthStencilPass(JNIEnv*, jclass,
jlong nativeMaterialInstance, jlong op, jlong face) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
instance->setStencilOpDepthStencilPass(
static_cast<MaterialInstance::StencilOperation>(op),
static_cast<MaterialInstance::StencilFace>(face));
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetStencilReferenceValue(JNIEnv*, jclass,
jlong nativeMaterialInstance, jint value, jlong face) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
instance->setStencilReferenceValue(value, static_cast<MaterialInstance::StencilFace>(face));
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetStencilReadMask(JNIEnv*, jclass,
jlong nativeMaterialInstance, jint readMask, jlong face) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
instance->setStencilReadMask(readMask, static_cast<MaterialInstance::StencilFace>(face));
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetStencilWriteMask(JNIEnv*, jclass,
jlong nativeMaterialInstance, jint writeMask, jlong face) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
instance->setStencilWriteMask(writeMask, static_cast<MaterialInstance::StencilFace>(face));
}
extern "C"
JNIEXPORT jstring JNICALL
Java_com_google_android_filament_MaterialInstance_nGetName(JNIEnv* env, jclass,
@@ -380,3 +452,75 @@ Java_com_google_android_filament_MaterialInstance_nDuplicate(JNIEnv* env, jclass
}
return (jlong)mi;
}
extern "C"
JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_MaterialInstance_nGetMaskThreshold(JNIEnv* env, jclass clazz,
jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
return instance->getMaskThreshold();
}
extern "C"
JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_MaterialInstance_nGetSpecularAntiAliasingVariance(JNIEnv* env,
jclass clazz, jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
return instance->getSpecularAntiAliasingVariance();
}
extern "C"
JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_MaterialInstance_nGetSpecularAntiAliasingThreshold(JNIEnv* env,
jclass clazz, jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
return instance->getSpecularAntiAliasingThreshold();
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_MaterialInstance_nIsDoubleSided(JNIEnv* env, jclass clazz,
jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
return instance->isDoubleSided();
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_MaterialInstance_nGetCullingMode(JNIEnv* env, jclass clazz,
jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
return (jint)instance->getCullingMode();
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_MaterialInstance_nIsColorWriteEnabled(JNIEnv* env, jclass clazz,
jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
return instance->isColorWriteEnabled();
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_MaterialInstance_nIsDepthWriteEnabled(JNIEnv* env, jclass clazz,
jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
return instance->isDepthWriteEnabled();
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_MaterialInstance_nIsStencilWriteEnabled(JNIEnv* env, jclass clazz,
jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
return instance->isStencilWriteEnabled();
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_MaterialInstance_nIsDepthCullingEnabled(JNIEnv* env, jclass clazz,
jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
return instance->isDepthCullingEnabled();
}

View File

@@ -150,6 +150,13 @@ Java_com_google_android_filament_RenderableManager_nBuilderPriority(JNIEnv*, jcl
builder->priority((uint8_t) priority);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderChannel(JNIEnv*, jclass,
jlong nativeBuilder, jint channel) {
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
builder->channel((uint8_t) channel);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderCulling(JNIEnv*, jclass,
jlong nativeBuilder, jboolean enabled) {
@@ -194,12 +201,19 @@ Java_com_google_android_filament_RenderableManager_nBuilderSkinning(JNIEnv*, jcl
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nEnableSkinningBuffers(JNIEnv*, jclass,
Java_com_google_android_filament_RenderableManager_nBuilderEnableSkinningBuffers(JNIEnv*, jclass,
jlong nativeBuilder, jboolean enabled) {
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
builder->enableSkinningBuffers(enabled);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderFog(JNIEnv*, jclass,
jlong nativeBuilder, jboolean enabled) {
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
builder->fog(enabled);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderSkinningBones(JNIEnv* env, jclass,
jlong nativeBuilder, jint boneCount, jobject bones, jint remaining) {
@@ -339,6 +353,13 @@ Java_com_google_android_filament_RenderableManager_nSetPriority(JNIEnv*, jclass,
rm->setPriority((RenderableManager::Instance) i, (uint8_t) priority);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetChannel(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jint channel) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
rm->setChannel((RenderableManager::Instance) i, (uint8_t) channel);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetCulling(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jboolean enabled) {
@@ -346,6 +367,20 @@ Java_com_google_android_filament_RenderableManager_nSetCulling(JNIEnv*, jclass,
rm->setCulling((RenderableManager::Instance) i, enabled);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetFogEnabled(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jboolean enabled) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
rm->setFogEnabled((RenderableManager::Instance) i, enabled);
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_RenderableManager_nGetFogEnabled(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
return (jboolean)rm->getFogEnabled((RenderableManager::Instance) i);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetCastShadows(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jboolean enabled) {

View File

@@ -83,3 +83,11 @@ Java_com_google_android_filament_Scene_nGetLightCount(JNIEnv *env, jclass type,
Scene* scene = (Scene*) nativeScene;
return (jint) scene->getLightCount();
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Scene_nHasEntity(JNIEnv *env, jclass type, jlong nativeScene,
jint entityId) {
Scene* scene = (Scene*) nativeScene;
Entity entity = Entity::import(entityId);
return (jboolean) scene->hasEntity(entity);
}

View File

@@ -16,6 +16,7 @@
#include <jni.h>
#include <filament/Engine.h>
#include <filament/SwapChain.h>
#include "common/CallbackUtils.h"
@@ -32,3 +33,9 @@ Java_com_google_android_filament_SwapChain_nSetFrameCompletedCallback(JNIEnv* en
JniCallback::postToJavaAndDestroy(callback);
}, callback);
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_SwapChain_nIsSRGBSwapChainSupported(JNIEnv *, jclass, jlong nativeEngine) {
Engine* engine = (Engine*) nativeEngine;
return (bool)SwapChain::isSRGBSwapChainSupported(*engine);
}

View File

@@ -188,69 +188,6 @@ Java_com_google_android_filament_Texture_nGetInternalFormat(JNIEnv*, jclass,
return (jint) texture->getFormat();
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Texture_nSetImage(JNIEnv* env, jclass, jlong nativeTexture,
jlong nativeEngine, jint level, jint xoffset, jint yoffset, jint width, jint height,
jobject storage, jint remaining,
jint left, jint top, jint type, jint alignment,
jint stride, jint format,
jobject handler, jobject runnable) {
Texture* texture = (Texture*) nativeTexture;
Engine* engine = (Engine*) nativeEngine;
size_t sizeInBytes = getTextureDataSize(texture, (size_t) level, (Texture::Format) format,
(Texture::Type) type, (size_t) stride, (size_t) height, (size_t) alignment);
AutoBuffer nioBuffer(env, storage, 0);
if (sizeInBytes > (size_t(remaining) << nioBuffer.getShift())) {
// BufferOverflowException
return -1;
}
void *buffer = nioBuffer.getData();
auto *callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
Texture::PixelBufferDescriptor desc(buffer, sizeInBytes, (backend::PixelDataFormat) format,
(backend::PixelDataType) type, (uint8_t) alignment, (uint32_t) left, (uint32_t) top,
(uint32_t) stride,
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
texture->setImage(*engine, (size_t) level, (uint32_t) xoffset, (uint32_t) yoffset,
(uint32_t) width, (uint32_t) height, std::move(desc));
return 0;
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Texture_nSetImageCompressed(JNIEnv *env, jclass,
jlong nativeTexture, jlong nativeEngine, jint level, jint xoffset, jint yoffset,
jint width, jint height, jobject storage, jint remaining,
jint, jint, jint, jint, jint compressedSizeInBytes, jint compressedFormat,
jobject handler, jobject runnable) {
Texture *texture = (Texture *) nativeTexture;
Engine *engine = (Engine *) nativeEngine;
size_t sizeInBytes = (size_t) compressedSizeInBytes;
AutoBuffer nioBuffer(env, storage, 0);
if (sizeInBytes > (size_t(remaining) << nioBuffer.getShift())) {
// BufferOverflowException
return -1;
}
void *buffer = nioBuffer.getData();
auto *callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
Texture::PixelBufferDescriptor desc(buffer, sizeInBytes,
(backend::CompressedPixelDataType) compressedFormat, (uint32_t) compressedSizeInBytes,
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
texture->setImage(*engine, (size_t) level, (uint32_t) xoffset, (uint32_t) yoffset,
(uint32_t) width, (uint32_t) height, std::move(desc));
return 0;
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Texture_nSetImage3D(JNIEnv* env, jclass, jlong nativeTexture,
jlong nativeEngine, jint level,
@@ -353,7 +290,10 @@ Java_com_google_android_filament_Texture_nSetImageCubemap(JNIEnv *env, jclass,
(uint32_t) stride,
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
texture->setImage(*engine, (size_t) level, std::move(desc), faceOffsets);
#pragma clang diagnostic pop
return 0;
}
@@ -388,7 +328,10 @@ Java_com_google_android_filament_Texture_nSetImageCubemapCompressed(JNIEnv *env,
(backend::CompressedPixelDataType) compressedFormat, (uint32_t) compressedSizeInBytes,
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
texture->setImage(*engine, (size_t) level, std::move(desc), faceOffsets);
#pragma clang diagnostic pop
return 0;
}

View File

@@ -110,6 +110,26 @@ Java_com_google_android_filament_TransformManager_nGetParent(JNIEnv*, jclass,
return tm->getParent((TransformManager::Instance) i).getId();
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_TransformManager_nGetChildCount(JNIEnv*, jclass,
jlong nativeTransformManager, jint i) {
TransformManager* tm = (TransformManager*) nativeTransformManager;
return tm->getChildCount((TransformManager::Instance) i);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_TransformManager_nGetChildren(JNIEnv* env,
jclass, jlong nativeTransformManager, jint i,
jintArray outEntities_, jint count) {
TransformManager* tm = (TransformManager*) nativeTransformManager;
jint* entities = env->GetIntArrayElements(outEntities_, nullptr);
// This is very very gross, we just pretend Entity is just like an jint
// (which it is), but still.
tm->getChildren((TransformManager::Instance) i,
reinterpret_cast<Entity *>(entities), (size_t) count);
env->ReleaseIntArrayElements(outEntities_, entities, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_TransformManager_nSetTransform(JNIEnv* env,
jclass, jlong nativeTransformManager, jint i,

View File

@@ -149,12 +149,13 @@ Java_com_google_android_filament_View_nSetShadowType(JNIEnv*, jclass, jlong nati
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetVsmShadowOptions(JNIEnv*, jclass, jlong nativeView,
jint anisotropy, jboolean mipmapping, jfloat minVarianceScale,
jint anisotropy, jboolean mipmapping, jboolean highPrecision, jfloat minVarianceScale,
jfloat lightBleedReduction) {
View* view = (View*) nativeView;
View::VsmShadowOptions options;
options.anisotropy = (uint8_t)anisotropy;
options.mipmapping = (bool)mipmapping;
options.highPrecision = (bool)highPrecision;
options.minVarianceScale = minVarianceScale;
options.lightBleedReduction = lightBleedReduction;
view->setVsmShadowOptions(options);
@@ -314,12 +315,13 @@ Java_com_google_android_filament_View_nSetBloomOptions(JNIEnv*, jclass,
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetFogOptions(JNIEnv *, jclass , jlong nativeView,
jfloat distance, jfloat maximumOpacity, jfloat height, jfloat heightFalloff, jfloat r,
jfloat g, jfloat b, jfloat density, jfloat inScatteringStart,
jfloat distance, jfloat maximumOpacity, jfloat height, jfloat heightFalloff, jfloat cutOffDistance,
jfloat r, jfloat g, jfloat b, jfloat density, jfloat inScatteringStart,
jfloat inScatteringSize, jboolean fogColorFromIbl, jboolean enabled) {
View* view = (View*) nativeView;
View::FogOptions options = {
.distance = distance,
.cutOffDistance = cutOffDistance,
.maximumOpacity = maximumOpacity,
.height = height,
.heightFalloff = heightFalloff,
@@ -462,6 +464,21 @@ Java_com_google_android_filament_View_nPick(JNIEnv* env, jclass,
}, callback->getHandler());
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetStencilBufferEnabled(JNIEnv *, jclass, jlong nativeView,
jboolean enabled) {
View* view = (View*) nativeView;
view->setStencilBufferEnabled(enabled);
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_View_nIsStencilBufferEnabled(JNIEnv *, jclass, jlong nativeView) {
View* view = (View*) nativeView;
return view->isStencilBufferEnabled();
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetGuardBandOptions(JNIEnv *, jclass,
@@ -469,3 +486,30 @@ Java_com_google_android_filament_View_nSetGuardBandOptions(JNIEnv *, jclass,
View* view = (View*) nativeView;
view->setGuardBandOptions({ .enabled = (bool)enabled });
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetMaterialGlobal(JNIEnv * , jclass, jlong nativeView,
jint index, jfloat x, jfloat y, jfloat z, jfloat w) {
View *view = (View *) nativeView;
view->setMaterialGlobal((uint32_t)index, { x, y, z, w });
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nGetMaterialGlobal(JNIEnv *env, jclass clazz,
jlong nativeView, jint index, jfloatArray out_) {
jfloat* out = env->GetFloatArrayElements(out_, nullptr);
View *view = (View *) nativeView;
auto result = view->getMaterialGlobal(index);
std::copy_n(result.v, 4, out);
env->ReleaseFloatArrayElements(out_, out, 0);
}
extern "C"
JNIEXPORT int JNICALL
Java_com_google_android_filament_View_nGetFogEntity(JNIEnv *env, jclass clazz,
jlong nativeView) {
View *view = (View *) nativeView;
return (jint)view->getFogEntity().getId();
}

View File

@@ -365,7 +365,7 @@ public class Camera {
* By default, this is an identity matrix.
* </p>
*
* @param scaling diagonal of the scaling matrix to be applied after the projection matrix.
* @param inScaling diagonal of the scaling matrix to be applied after the projection matrix.
*
* @see Camera#setProjection
* @see Camera#setLensProjection
@@ -400,7 +400,7 @@ public class Camera {
}
/**
* Sets the camera's view matrix.
* Sets the camera's model matrix.
* <p>
* Helper method to set the camera's entity transform component.
* Remember that the Camera "looks" towards its -z axis.
@@ -409,32 +409,32 @@ public class Camera {
*
* <pre>
* engine.getTransformManager().setTransform(
* engine.getTransformManager().getInstance(camera->getEntity()), viewMatrix);
* engine.getTransformManager().getInstance(camera->getEntity()), modelMatrix);
* </pre>
*
* @param viewMatrix The camera position and orientation provided as a <b>rigid transform</b> matrix.
* @param modelMatrix The camera position and orientation provided as a <b>rigid transform</b> matrix.
*/
public void setModelMatrix(@NonNull @Size(min = 16) float[] viewMatrix) {
Asserts.assertMat4fIn(viewMatrix);
nSetModelMatrix(getNativeObject(), viewMatrix);
public void setModelMatrix(@NonNull @Size(min = 16) float[] modelMatrix) {
Asserts.assertMat4fIn(modelMatrix);
nSetModelMatrix(getNativeObject(), modelMatrix);
}
/**
* Sets the camera's view matrix.
* Sets the camera's model matrix.
* <p>
* Helper method to set the camera's entity transform component.
* Remember that the Camera "looks" towards its -z axis.
* <p>
*
* @param viewMatrix The camera position and orientation provided as a <b>rigid transform</b> matrix.
* @param modelMatrix The camera position and orientation provided as a <b>rigid transform</b> matrix.
*/
public void setModelMatrix(@NonNull @Size(min = 16) double[] viewMatrix) {
Asserts.assertMat4In(viewMatrix);
nSetModelMatrixFp64(getNativeObject(), viewMatrix);
public void setModelMatrix(@NonNull @Size(min = 16) double[] modelMatrix) {
Asserts.assertMat4In(modelMatrix);
nSetModelMatrixFp64(getNativeObject(), modelMatrix);
}
/**
* Sets the camera's view matrix.
* Sets the camera's model matrix.
*
* @param eyeX x-axis position of the camera in world space
* @param eyeY y-axis position of the camera in world space
@@ -456,7 +456,7 @@ public class Camera {
* @return Distance to the near plane
*/
public float getNear() {
return nGetNear(getNativeObject());
return (float)nGetNear(getNativeObject());
}
/**
@@ -464,7 +464,7 @@ public class Camera {
* @return Distance to the far plane
*/
public float getCullingFar() {
return nGetCullingFar(getNativeObject());
return (float)nGetCullingFar(getNativeObject());
}
/**
@@ -549,10 +549,10 @@ public class Camera {
/**
* Retrieves the camera's view matrix. The view matrix is the inverse of the model matrix.
*
* @param out A 16-float array where the model view will be stored, or null in which
* @param out A 16-float array where the view matrix will be stored, or null in which
* case a new array is allocated.
*
* @return A 16-float array containing the camera's view as a column-major matrix.
* @return A 16-float array containing the camera's column-major view matrix.
*/
@NonNull @Size(min = 16)
public float[] getViewMatrix(@Nullable @Size(min = 16) float[] out) {
@@ -567,7 +567,7 @@ public class Camera {
* @param out A 16-double array where the model view will be stored, or null in which
* case a new array is allocated.
*
* @return A 16-double array containing the camera's view as a column-major matrix.
* @return A 16-double array containing the camera's column-major view matrix.
*/
@NonNull @Size(min = 16)
public double[] getViewMatrix(@Nullable @Size(min = 16) double[] out) {
@@ -787,8 +787,8 @@ public class Camera {
private static native void nSetModelMatrix(long nativeCamera, float[] in);
private static native void nSetModelMatrixFp64(long nativeCamera, double[] in);
private static native void nLookAt(long nativeCamera, double eyeX, double eyeY, double eyeZ, double centerX, double centerY, double centerZ, double upX, double upY, double upZ);
private static native float nGetNear(long nativeCamera);
private static native float nGetCullingFar(long nativeCamera);
private static native double nGetNear(long nativeCamera);
private static native double nGetCullingFar(long nativeCamera);
private static native void nGetProjectionMatrix(long nativeCamera, double[] out);
private static native void nGetCullingProjectionMatrix(long nativeCamera, double[] out);
private static native void nGetScaling(long nativeCamera, double[] out);

View File

@@ -118,6 +118,7 @@ public class ColorGrading {
*
* @deprecated Use {@link ColorGrading.Builder#toneMapper(ToneMapper)}
*/
@Deprecated
public enum ToneMapping {
/** Linear tone mapping (i.e. no tone mapping). */
LINEAR,
@@ -231,6 +232,7 @@ public class ColorGrading {
*
* @deprecated Use {@link #toneMapper(ToneMapper)}
*/
@Deprecated
public Builder toneMapping(ToneMapping toneMapping) {
nBuilderToneMapping(mNativeBuilder, toneMapping.ordinal());
return this;

View File

@@ -47,7 +47,7 @@ import com.google.android.filament.proguard.UsedByReflection;
* <pre>
* import com.google.android.filament.*
*
* Engin engine = Engine.create();
* Engine engine = Engine.create();
* SwapChain swapChain = engine.createSwapChain(nativeWindow);
* Renderer renderer = engine.createRenderer();
* Scene scene = engine.createScene();
@@ -107,6 +107,7 @@ import com.google.android.filament.proguard.UsedByReflection;
*/
public class Engine {
private static final Backend[] sBackendValues = Backend.values();
private static final FeatureLevel[] sFeatureLevelValues = FeatureLevel.values();
private long mNativeObject;
@@ -141,6 +142,18 @@ public class Engine {
NOOP,
}
/**
* Defines the backend's feature levels.
*/
public enum FeatureLevel {
/** Reserved, don't use */
FEATURE_LEVEL_0,
/** OpenGL ES 3.0 features (default) */
FEATURE_LEVEL_1,
/** OpenGL ES 3.1 features + 31 textures units + cubemap arrays */
FEATURE_LEVEL_2
};
private Engine(long nativeEngine) {
mNativeObject = nativeEngine;
mTransformManager = new TransformManager(nGetTransformManager(nativeEngine));
@@ -258,6 +271,88 @@ public class Engine {
return sBackendValues[(int) nGetBackend(getNativeObject())];
}
/**
* Helper to enable accurate translations.
* If you need this Engine to handle a very large world space, one way to achieve this
* automatically is to enable accurate translations in the TransformManager. This helper
* provides a convenient way of doing that.
* This is typically called once just after creating the Engine.
*/
public void enableAccurateTranslations() {
getTransformManager().setAccurateTranslationsEnabled(true);
}
/**
* Query the feature level supported by the selected backend.
*
* A specific feature level needs to be set before the corresponding features can be used.
*
* @return FeatureLevel supported the selected backend.
* @see #setActiveFeatureLevel
*/
@NonNull
public FeatureLevel getSupportedFeatureLevel() {
return sFeatureLevelValues[(int) nGetSupportedFeatureLevel(getNativeObject())];
}
/**
* Activate all features of a given feature level. By default FeatureLevel::FEATURE_LEVEL_1 is
* active. The selected feature level must not be higher than the value returned by
* getActiveFeatureLevel() and it's not possible lower the active feature level.
*
* @param featureLevel the feature level to activate. If featureLevel is lower than
* getActiveFeatureLevel(), the current (higher) feature level is kept.
* If featureLevel is higher than getSupportedFeatureLevel(), an exception
* is thrown, or the program is terminated if exceptions are disabled.
*
* @return the active feature level.
*
* @see #getSupportedFeatureLevel
* @see #getActiveFeatureLevel
*/
@NonNull
public FeatureLevel setActiveFeatureLevel(@NonNull FeatureLevel featureLevel) {
return sFeatureLevelValues[(int) nSetActiveFeatureLevel(getNativeObject(), featureLevel.ordinal())];
}
/**
* Returns the currently active feature level.
* @return currently active feature level
* @see #getSupportedFeatureLevel
* @see #setActiveFeatureLevel
*/
@NonNull
public FeatureLevel getActiveFeatureLevel() {
return sFeatureLevelValues[(int) nGetActiveFeatureLevel(getNativeObject())];
}
/**
* Enables or disables automatic instancing of render primitives. Instancing of render primitive
* can greatly reduce CPU overhead but requires the instanced primitives to be identical
* (i.e. use the same geometry) and use the same MaterialInstance. If it is known that the
* scene doesn't contain any identical primitives, automatic instancing can have some
* overhead and it is then best to disable it.
*
* Disabled by default.
*
* @param enable true to enable, false to disable automatic instancing.
*
* @see RenderableManager
* @see MaterialInstance
*/
public void setAutomaticInstancingEnabled(boolean enable) {
nSetAutomaticInstancingEnabled(getNativeObject(), enable);
}
/**
* @return true if automatic instancing is enabled, false otherwise.
* @see #setAutomaticInstancingEnabled
*/
public boolean isAutomaticInstancingEnabled() {
return nIsAutomaticInstancingEnabled(getNativeObject());
}
// SwapChain
/**
@@ -593,8 +688,11 @@ public class Engine {
}
/**
* Destroys an <code>entity</code> and all its components.
* Destroys all Filament-known components from this <code>entity</code>.
* <p>
* This method destroys Filament components only, not the <code>entity</code> itself. To destroy
* the <code>entity</code> use <code>EntityManager#destroy</code>.
*
* It is recommended to destroy components individually before destroying their
* <code>entity</code>, this gives more control as to when the destruction really happens.
* Otherwise, orphaned components are garbage collected, which can happen at a later time.
@@ -717,4 +815,9 @@ public class Engine {
private static native long nGetRenderableManager(long nativeEngine);
private static native long nGetJobSystem(long nativeEngine);
private static native long nGetEntityManager(long nativeEngine);
private static native void nSetAutomaticInstancingEnabled(long nativeEngine, boolean enable);
private static native boolean nIsAutomaticInstancingEnabled(long nativeEngine);
private static native int nGetSupportedFeatureLevel(long nativeEngine);
private static native int nSetActiveFeatureLevel(long nativeEngine, int ordinal);
private static native int nGetActiveFeatureLevel(long nativeEngine);
}

View File

@@ -240,7 +240,7 @@ public class LightManager {
*/
@NonNull
@Size(min = 3)
public float[] cascadeSplitPositions = { 0.25f, 0.50f, 0.75f };
public float[] cascadeSplitPositions = { 0.125f, 0.25f, 0.50f };
/** Constant bias in world units (e.g. meters) by which shadows are moved away from the
* light. 1mm by default.
@@ -280,9 +280,25 @@ public class LightManager {
* Controls whether the shadow map should be optimized for resolution or stability.
* When set to true, all resolution enhancing features that can affect stability are
* disabling, resulting in significantly lower resolution shadows, albeit stable ones.
*
* Setting this flag to true always disables LiSPSM (see below).
*/
public boolean stable = false;
/**
* LiSPSM, or light-space perspective shadow-mapping is a technique allowing to better
* optimize the use of the shadow-map texture. When enabled the effective resolution of
* shadows is greatly improved and yields result similar to using cascades without the
* extra cost. LiSPSM comes with some drawbacks however, in particular it is incompatible
* with blurring because it effectively affects the blur kernel size.
*
* Blurring is only an issue when using ShadowType.VSM with a large blur or with
* ShadowType.PCSS however.
*
* If these blurring artifacts become problematic, this flag can be used to disable LiSPSM.
*/
public boolean lispsm = false;
/**
* Constant bias in depth-resolution units by which shadows are moved away from the
* light. The default value of 0.5 is used to round depth values up.
@@ -334,17 +350,12 @@ public class LightManager {
*/
/**
* The number of MSAA samples to use when rendering VSM shadow maps.
* Must be a power-of-two and greater than or equal to 1. A value of 1 effectively turns
* off MSAA.
* Higher values may not be available depending on the underlying hardware.
*
* <p>
* <strong>Warning: This API is still experimental and subject to change.</strong>
* </p>
* When elvsm is set to true, "Exponential Layered VSM without Layers" are used. It is
* an improvement to the default EVSM which suffers important light leaks. Enabling
* ELVSM for a single shadowmap doubles the memory usage of all shadow maps.
* ELVSM is mostly useful when large blurs are used.
*/
@IntRange(from = 1)
public int vsmMsaaSamples = 1;
public boolean elvsm = false;
/**
* Blur width for the VSM blur. Zero do disable.
@@ -470,11 +481,6 @@ public class LightManager {
/**
* Whether this Light casts shadows (disabled by default)
*
* <p>
* <b>warning:</b>
* {@link Type#POINT} lights cannot cast shadows.
* </p>
*
* @param enable Enables or disables casting shadows from this Light.
*
* @return This Builder, for chaining calls.
@@ -496,11 +502,11 @@ public class LightManager {
nBuilderShadowOptions(mNativeBuilder,
options.mapSize, options.shadowCascades, options.cascadeSplitPositions,
options.constantBias, options.normalBias, options.shadowFar, options.shadowNearHint,
options.shadowFarHint, options.stable,
options.shadowFarHint, options.stable, options.lispsm,
options.polygonOffsetConstant, options.polygonOffsetSlope,
options.screenSpaceContactShadows,
options.stepCount, options.maxShadowDistance, options.vsmMsaaSamples,
options.blurWidth, options.shadowBulbRadius);
options.stepCount, options.maxShadowDistance,
options.elvsm, options.blurWidth, options.shadowBulbRadius);
return this;
}
@@ -998,8 +1004,6 @@ public class LightManager {
* lightbulbs.
*
* @param efficiency Efficiency in percent. This depends on the type of lightbulb used.
*
* @return This Builder, for chaining calls.
*/
public void setIntensity(@EntityInstance int i, float watts, float efficiency) {
nSetIntensity(mNativeObject, i , watts, efficiency);
@@ -1158,7 +1162,14 @@ public class LightManager {
private static native void nDestroyBuilder(long nativeBuilder);
private static native boolean nBuilderBuild(long nativeBuilder, long nativeEngine, int entity);
private static native void nBuilderCastShadows(long nativeBuilder, boolean enable);
private static native void nBuilderShadowOptions(long nativeBuilder, int mapSize, int cascades, float[] splitPositions, float constantBias, float normalBias, float shadowFar, float shadowNearHint, float shadowFarhint, boolean stable, float polygonOffsetConstant, float polygonOffsetSlope, boolean screenSpaceContactShadows, int stepCount, float maxShadowDistance, int vsmMsaaSamples, float blurWidth, float shadowBulbRadius);
private static native void nBuilderShadowOptions(long nativeBuilder, int mapSize,
int cascades, float[] splitPositions,
float constantBias, float normalBias,
float shadowFar, float shadowNearHint, float shadowFarhint,
boolean stable, boolean lispsm,
float polygonOffsetConstant, float polygonOffsetSlope,
boolean screenSpaceContactShadows, int stepCount, float maxShadowDistance,
boolean elvsm, float blurWidth, float shadowBulbRadius);
private static native void nBuilderCastLight(long nativeBuilder, boolean enabled);
private static native void nBuilderPosition(long nativeBuilder, float x, float y, float z);
private static native void nBuilderDirection(long nativeBuilder, float x, float y, float z);

View File

@@ -36,6 +36,7 @@ import java.util.Set;
*
* @see <a href="https://google.github.io/filament/Materials.html">Filament Materials Guide</a>
*/
@UsedByNative("AssetLoader.cpp")
public class Material {
static final class EnumCache {
private EnumCache() { }
@@ -502,6 +503,17 @@ public class Material {
return nIsDoubleSided(getNativeObject());
}
/**
* Indicates whether instances of this material will use alpha to coverage.
*
* @see
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/rasterization:alphatocoverage">
* Rasterization: alphaToCoverage</a>
*/
public boolean isAlphaToCoverageEnabled() {
return nIsAlphaToCoverageEnabled(getNativeObject());
}
/**
* Returns the alpha mask threshold used when the blending mode is set to masked.
*
@@ -914,6 +926,7 @@ public class Material {
private static native boolean nIsDepthWriteEnabled(long nativeMaterial);
private static native boolean nIsDepthCullingEnabled(long nativeMaterial);
private static native boolean nIsDoubleSided(long nativeMaterial);
private static native boolean nIsAlphaToCoverageEnabled(long nativeMaterial);
private static native float nGetMaskThreshold(long nativeMaterial);
private static native float nGetSpecularAntiAliasingVariance(long nativeMaterial);
private static native float nGetSpecularAntiAliasingThreshold(long nativeMaterial);

View File

@@ -20,7 +20,11 @@ import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Size;
import com.google.android.filament.proguard.UsedByNative;
@UsedByNative("AssetLoader.cpp")
public class MaterialInstance {
private static final Material.CullingMode[] sCullingModeValues = Material.CullingMode.values();
private Material mMaterial;
private String mName;
private long mNativeObject;
@@ -49,6 +53,54 @@ public class MaterialInstance {
MAT4
}
/**
* Operations that control how the stencil buffer is updated.
*/
public enum StencilOperation {
/**
* Keeps the current value.
*/
KEEP,
/**
* Sets the value to 0.
*/
ZERO,
/**
* Sets the value to the stencil reference value.
*/
REPLACE,
/**
* Increments the current value. Clamps to the maximum representable unsigned value.
*/
INCR_CLAMP,
/**
* Increments the current value. Wraps value to zero when incrementing the maximum
* representable unsigned value.
*/
INCR_WRAP,
/**
* Decrements the current value. Clamps to 0.
*/
DECR_CLAMP,
/**
* Decrements the current value. Wraps value to the maximum representable unsigned value
* when decrementing a value of zero.
*/
DECR_WRAP,
/**
* Bitwise inverts the current value.
*/
INVERT,
}
public enum StencilFace {
FRONT,
BACK,
FRONT_AND_BACK
}
// Converts the StencilFace enum ordinal to Filament's equivalent bit field.
static final int[] sStencilFaceMapping = {0x1, 0x2, 0x3};
public MaterialInstance(Engine engine, long nativeMaterialInstance) {
mNativeObject = nativeMaterialInstance;
mNativeMaterial = nGetMaterial(mNativeObject);
@@ -351,19 +403,40 @@ public class MaterialInstance {
}
/**
* Set up a custom scissor rectangle; by default this encompasses the View.
* Set-up a custom scissor rectangle; by default it is disabled.
*
* @param left left coordinate of the scissor box
* @param bottom bottom coordinate of the scissor box
* <p>
* The scissor rectangle gets clipped by the View's viewport, in other words, the scissor
* cannot affect fragments outside of the View's Viewport.
* </p>
*
* <p>
* Currently the scissor is not compatible with dynamic resolution and should always be
* disabled when dynamic resolution is used.
* </p>
*
* @param left left coordinate of the scissor box relative to the viewport
* @param bottom bottom coordinate of the scissor box relative to the viewport
* @param width width of the scissor box
* @param height height of the scissor box
*
* @see #unsetScissor
* @see View#setViewport
* @see View#setDynamicResolutionOptions
*/
public void setScissor(@IntRange(from = 0) int left, @IntRange(from = 0) int bottom,
@IntRange(from = 0) int width, @IntRange(from = 0) int height) {
nSetScissor(getNativeObject(), left, bottom, width, height);
}
/** Returns the scissor rectangle to its default setting, which encompasses the View. */
/**
* Returns the scissor rectangle to its default disabled setting.
* <p>
* Currently the scissor is not compatible with dynamic resolution and should always be
* disabled when dynamic resolution is used.
* </p>
* @see View#setDynamicResolutionOptions
*/
public void unsetScissor() {
nUnsetScissor(getNativeObject());
}
@@ -401,6 +474,14 @@ public class MaterialInstance {
nSetMaskThreshold(getNativeObject(), threshold);
}
/**
* Gets the minimum alpha value a fragment must have to not be discarded when the blend
* mode is MASKED
*/
public float getMaskThreshold() {
return nGetMaskThreshold(getNativeObject());
}
/**
* Sets the screen space variance of the filter kernel used when applying specular
* anti-aliasing. The default value is set to 0.15. The specified value should be between
@@ -414,6 +495,14 @@ public class MaterialInstance {
nSetSpecularAntiAliasingVariance(getNativeObject(), variance);
}
/**
* Gets the screen space variance of the filter kernel used when applying specular
* anti-aliasing.
*/
public float getSpecularAntiAliasingVariance() {
return nGetSpecularAntiAliasingVariance(getNativeObject());
}
/**
* Sets the clamping threshold used to suppress estimation errors when applying specular
* anti-aliasing. The default value is set to 0.2. The specified value should be between 0
@@ -427,6 +516,14 @@ public class MaterialInstance {
nSetSpecularAntiAliasingThreshold(getNativeObject(), threshold);
}
/**
* Gets the clamping threshold used to suppress estimation errors when applying specular
* anti-aliasing.
*/
public float getSpecularAntiAliasingThreshold() {
return nGetSpecularAntiAliasingThreshold(getNativeObject());
}
/**
* Enables or disables double-sided lighting if the parent Material has double-sided capability,
* otherwise prints a warning. If double-sided lighting is enabled, backface culling is
@@ -440,6 +537,14 @@ public class MaterialInstance {
nSetDoubleSided(getNativeObject(), doubleSided);
}
/**
* Returns whether double-sided lighting is enabled when the parent Material has double-sided
* capability.
*/
public boolean isDoubleSided() {
return nIsDoubleSided(getNativeObject());
}
/**
* Overrides the default triangle culling state that was set on the material.
*
@@ -447,10 +552,18 @@ public class MaterialInstance {
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/rasterization:culling">
* Rasterization: culling</a>
*/
public void setCullingMode(Material.CullingMode mode) {
public void setCullingMode(@NonNull Material.CullingMode mode) {
nSetCullingMode(getNativeObject(), mode.ordinal());
}
/**
* Returns the face culling mode.
*/
@NonNull
public Material.CullingMode getCullingMode() {
return sCullingModeValues[nGetCullingMode(getNativeObject())];
}
/**
* Overrides the default color-buffer write state that was set on the material.
*
@@ -462,6 +575,13 @@ public class MaterialInstance {
nSetColorWrite(getNativeObject(), enable);
}
/**
* Returns whether color write is enabled.
*/
public boolean isColorWriteEnabled() {
return nIsColorWriteEnabled(getNativeObject());
}
/**
* Overrides the default depth-buffer write state that was set on the material.
*
@@ -473,6 +593,27 @@ public class MaterialInstance {
nSetDepthWrite(getNativeObject(), enable);
}
/**
* Returns whether depth write is enabled.
*/
public boolean isDepthWriteEnabled() {
return nIsDepthWriteEnabled(getNativeObject());
}
/**
* Enables or Disable stencil writes
*/
public void setStencilWrite(boolean enable) {
nSetStencilWrite(getNativeObject(), enable);
}
/**
* Returns whether stencil write is enabled.
*/
public boolean isStencilWriteEnabled() {
return nIsStencilWriteEnabled(getNativeObject());
}
/**
* Overrides the default depth testing state that was set on the material.
*
@@ -484,6 +625,215 @@ public class MaterialInstance {
nSetDepthCulling(getNativeObject(), enable);
}
/**
* Returns whether depth culling is enabled.
*/
public boolean isDepthCullingEnabled() {
return nIsDepthCullingEnabled(getNativeObject());
}
/**
* Sets the stencil comparison function (default is {@link TextureSampler.CompareFunction#ALWAYS}).
*
* <p>
* It's possible to set separate stencil comparison functions; one for front-facing polygons,
* and one for back-facing polygons. The face parameter determines the comparison function(s)
* updated by this call.
* </p>
*
* @param func the stencil comparison function
* @param face the faces to update the comparison function for
*/
public void setStencilCompareFunction(TextureSampler.CompareFunction func, StencilFace face) {
nSetStencilCompareFunction(getNativeObject(), func.ordinal(),
sStencilFaceMapping[face.ordinal()]);
}
/**
* Sets the stencil comparison function for both front and back-facing polygons.
* @see #setStencilCompareFunction(TextureSampler.CompareFunction, StencilFace)
*/
public void setStencilCompareFunction(TextureSampler.CompareFunction func) {
setStencilCompareFunction(func, StencilFace.FRONT_AND_BACK);
}
/**
* Sets the stencil fail operation (default is {@link StencilOperation#KEEP}).
*
* <p>
* The stencil fail operation is performed to update values in the stencil buffer when the
* stencil test fails.
* </p>
*
* <p>
* It's possible to set separate stencil fail operations; one for front-facing polygons, and one
* for back-facing polygons. The face parameter determines the stencil fail operation(s) updated
* by this call.
* </p>
*
* @param op the stencil fail operation
* @param face the faces to update the stencil fail operation for
*/
public void setStencilOpStencilFail(StencilOperation op, StencilFace face) {
nSetStencilOpStencilFail(getNativeObject(), op.ordinal(),
sStencilFaceMapping[face.ordinal()]);
}
/**
* Sets the stencil fail operation for both front and back-facing polygons.
* @see #setStencilOpStencilFail(StencilOperation, StencilFace)
*/
public void setStencilOpStencilFail(StencilOperation op) {
setStencilOpStencilFail(op, StencilFace.FRONT_AND_BACK);
}
/**
* Sets the depth fail operation (default is {@link StencilOperation#KEEP}).
*
* <p>
* The depth fail operation is performed to update values in the stencil buffer when the depth
* test fails.
* </p>
*
* <p>
* It's possible to set separate depth fail operations; one for front-facing polygons, and one
* for back-facing polygons. The face parameter determines the depth fail operation(s) updated
* by this call.
* </p>
*
* @param op the depth fail operation
* @param face the faces to update the depth fail operation for
*/
public void setStencilOpDepthFail(StencilOperation op, StencilFace face) {
nSetStencilOpDepthFail(getNativeObject(), op.ordinal(),
sStencilFaceMapping[face.ordinal()]);
}
/**
* Sets the depth fail operation for both front and back-facing polygons.
* @see #setStencilOpDepthFail(StencilOperation, StencilFace)
*/
public void setStencilOpDepthFail(StencilOperation op) {
setStencilOpDepthFail(op, StencilFace.FRONT_AND_BACK);
}
/**
* Sets the depth-stencil pass operation (default is {@link StencilOperation#KEEP}).
*
* <p>
* The depth-stencil pass operation is performed to update values in the stencil buffer when
* both the stencil test and depth test pass.
* </p>
*
* <p>
* It's possible to set separate depth-stencil pass operations; one for front-facing polygons,
* and one for back-facing polygons. The face parameter determines the depth-stencil pass
* operation(s) updated by this call.
* </p>
*
* @param op the depth-stencil pass operation
* @param face the faces to update the depth-stencil operation for
*/
public void setStencilOpDepthStencilPass(StencilOperation op, StencilFace face) {
nSetStencilOpDepthStencilPass(getNativeObject(), op.ordinal(),
sStencilFaceMapping[face.ordinal()]);
}
/**
* Sets the depth-stencil pass operation for both front and back-facing polygons.
* @see #setStencilOpDepthStencilPass(StencilOperation, StencilFace)
*/
public void setStencilOpDepthStencilPass(StencilOperation op) {
setStencilOpDepthStencilPass(op, StencilFace.FRONT_AND_BACK);
}
/**
* Sets the stencil reference value (default is 0).
*
* <p>
* The stencil reference value is the left-hand side for stencil comparison tests. It's also
* used as the replacement stencil value when {@link StencilOperation} is
* {@link StencilOperation#REPLACE}.
* </p>
*
* <p>
* It's possible to set separate stencil reference values; one for front-facing polygons, and
* one for back-facing polygons. The face parameter determines the reference value(s) updated by
* this call.
* </p>
*
* @param value the stencil reference value (only the least significant 8 bits are used)
* @param face the faces to update the reference value for
*/
public void setStencilReferenceValue(@IntRange(from = 0, to = 255) int value, StencilFace face) {
nSetStencilReferenceValue(getNativeObject(), value, sStencilFaceMapping[face.ordinal()]);
}
/**
* Sets the stencil reference value for both front and back-facing polygons.
* @see #setStencilReferenceValue(int, StencilFace)
*/
public void setStencilReferenceValue(@IntRange(from = 0, to = 255) int value) {
setStencilReferenceValue(value, StencilFace.FRONT_AND_BACK);
}
/**
* Sets the stencil read mask (default is 0xFF).
*
* <p>
* The stencil read mask masks the bits of the values participating in the stencil comparison
* test- both the value read from the stencil buffer and the reference value.
* </p>
*
* <p>
* It's possible to set separate stencil read masks; one for front-facing polygons, and one for
* back-facing polygons. The face parameter determines the stencil read mask(s) updated by this
* call.
* </p>
*
* @param readMask the read mask (only the least significant 8 bits are used)
* @param face the faces to update the read mask for
*/
public void setStencilReadMask(@IntRange(from = 0, to = 255) int readMask, StencilFace face) {
nSetStencilReadMask(getNativeObject(), readMask, sStencilFaceMapping[face.ordinal()]);
}
/**
* Sets the stencil read mask for both front and back-facing polygons.
* @see #setStencilReadMask(int, StencilFace)
*/
public void setStencilReadMask(@IntRange(from = 0, to = 255) int readMask) {
setStencilReadMask(readMask, StencilFace.FRONT_AND_BACK);
}
/**
* Sets the stencil write mask (default is 0xFF).
*
* <p>
* The stencil write mask masks the bits in the stencil buffer updated by stencil operations.
* </p>
*
* <p>
* It's possible to set separate stencil write masks; one for front-facing polygons, and one for
* back-facing polygons. The face parameter determines the stencil write mask(s) updated by this
* call.
* </p>
*
* @param writeMask the write mask (only the least significant 8 bits are used)
* @param face the faces to update the read mask for
*/
public void setStencilWriteMask(@IntRange(from = 0, to = 255) int writeMask, StencilFace face) {
nSetStencilWriteMask(getNativeObject(), writeMask, sStencilFaceMapping[face.ordinal()]);
}
/**
* Sets the stencil write mask for both front and back-facing polygons.
* @see #setStencilWriteMask(int, StencilFace)
*/
public void setStencilWriteMask(int writeMask) {
setStencilWriteMask(writeMask, StencilFace.FRONT_AND_BACK);
}
public long getNativeObject() {
if (mNativeObject == 0) {
throw new IllegalStateException("Calling method on destroyed MaterialInstance");
@@ -556,10 +906,37 @@ public class MaterialInstance {
private static native void nSetCullingMode(long nativeMaterialInstance, long mode);
private static native void nSetColorWrite(long nativeMaterialInstance, boolean enable);
private static native void nSetDepthWrite(long nativeMaterialInstance, boolean enable);
private static native void nSetStencilWrite(long nativeMaterialInstance, boolean enable);
private static native void nSetDepthCulling(long nativeMaterialInstance, boolean enable);
private static native void nSetStencilCompareFunction(long nativeMaterialInstance,
long function, long face);
private static native void nSetStencilOpStencilFail(long nativeMaterialInstance, long op,
long face);
private static native void nSetStencilOpDepthFail(long nativeMaterialInstance, long op,
long face);
private static native void nSetStencilOpDepthStencilPass(long nativeMaterialInstance, long op,
long face);
private static native void nSetStencilReferenceValue(long nativeMaterialInstance, int value,
long face);
private static native void nSetStencilReadMask(long nativeMaterialInstance, int readMask,
long face);
private static native void nSetStencilWriteMask(long nativeMaterialInstance, int writeMask,
long face);
private static native String nGetName(long nativeMaterialInstance);
private static native long nGetMaterial(long nativeMaterialInstance);
private static native long nDuplicate(long otherNativeMaterialInstance, String name);
private static native float nGetMaskThreshold(long nativeMaterialInstance);
private static native float nGetSpecularAntiAliasingVariance(long nativeMaterialInstance);
private static native float nGetSpecularAntiAliasingThreshold(long nativeMaterialInstance);
private static native boolean nIsDoubleSided(long nativeMaterialInstance);
private static native int nGetCullingMode(long nativeMaterialInstance);
private static native boolean nIsColorWriteEnabled(long nativeMaterialInstance);
private static native boolean nIsDepthWriteEnabled(long nativeMaterialInstance);
private static native boolean nIsStencilWriteEnabled(long nativeMaterialInstance);
private static native boolean nIsDepthCullingEnabled(long nativeMaterialInstance);
}

View File

@@ -257,23 +257,79 @@ public class RenderableManager {
* Provides coarse-grained control over draw order.
*
* <p>In general Filament reserves the right to re-order renderables to allow for efficient
* rendering. However clients can control ordering at a coarse level using <em>priority</em>.</p>
* rendering. However clients can control ordering at a coarse level using \em priority.
* The priority is applied separately for opaque and translucent objects, that is, opaque
* objects are always drawn before translucent objects regardless of the priority.</p>
*
* <p>For example, this could be used to draw a semitransparent HUD, if a client wishes to
* avoid using a separate View for the HUD. Note that priority is completely orthogonal to
* {@link Builder#layerMask}, which merely controls visibility.</p>
* <p>The Skybox always using the lowest priority, so it's drawn last, which may improve
* performance.</p>
*
* <p>The priority is clamped to the range [0..7], defaults to 4; 7 is lowest priority
* (rendered last).</p>
*
* @see Builder#blendOrder
*/
/**
* Provides coarse-grained control over draw order.
*
* <p>In general Filament reserves the right to re-order renderables to allow for efficient
* rendering. However clients can control ordering at a coarse level using priority.
* The priority is applied separately for opaque and translucent objects, that is, opaque
* objects are always drawn before translucent objects regardless of the priority.</p>
*
* <p>For example, this could be used to draw a semitransparent HUD, if a client wishes to
* avoid using a separate View for the HUD. Note that priority is completely orthogonal to
* {@link Builder#layerMask}, which merely controls visibility.</p>
* <p>The Skybox always using the lowest priority, so it's drawn last, which may improve
* performance.</p>
*
* @param priority clamped to the range [0..7], defaults to 4; 7 is lowest priority
* (rendered last).
*
* @return Builder reference for chaining calls.
*
* @see Builder#channel
* @see Builder#blendOrder
* @see #setPriority
* @see #setBlendOrderAt
*/
@NonNull
public Builder priority(@IntRange(from = 0, to = 7) int priority) {
nBuilderPriority(mNativeBuilder, priority);
return this;
}
/**
* Set the channel this renderable is associated to. There can be 4 channels.
*
* <p>All renderables in a given channel are rendered together, regardless of anything else.
* They are sorted as usual within a channel.</p>
* <p>Channels work similarly to priorities, except that they enforce the strongest
* ordering.</p>
*
* <p>Channels 0 and 1 may not have render primitives using a material with `refractionType`
* set to `screenspace`.</p>
*
* @param channel clamped to the range [0..3], defaults to 2.
*
* @return Builder reference for chaining calls.
*
* @see Builder::blendOrder()
* @see Builder::priority()
* @see RenderableManager::setBlendOrderAt()
*/
@NonNull
public Builder channel(@IntRange(from = 0, to = 3) int channel) {
nBuilderChannel(mNativeBuilder, channel);
return this;
}
/**
* Controls frustum culling, true by default.
*
@@ -300,16 +356,16 @@ public class RenderableManager {
/**
* Specifies the number of draw instance of this renderable. The default is 1 instance and
* the maximum number of instances allowed is 65535. 0 is invalid.
* the maximum number of instances allowed is 32767. 0 is invalid.
* All instances are culled using the same bounding box, so care must be taken to make
* sure all instances render inside the specified bounding box.
* The material can use getInstanceIndex() in the vertex shader to get the instance index and
* possibly adjust the position or transform.
*
* @param instanceCount the number of instances silently clamped between 1 and 65535.
* @param instanceCount the number of instances silently clamped between 1 and 32767.
*/
@NonNull
public Builder instances(@IntRange(from = 1, to = 65535) int instanceCount) {
public Builder instances(@IntRange(from = 1, to = 32767) int instanceCount) {
nBuilderInstances(mNativeBuilder, instanceCount);
return this;
}
@@ -361,7 +417,19 @@ public class RenderableManager {
*/
@NonNull
public Builder enableSkinningBuffers(boolean enabled) {
nEnableSkinningBuffers(mNativeBuilder, enabled);
nBuilderEnableSkinningBuffers(mNativeBuilder, enabled);
return this;
}
/**
* Controls if this renderable is affected by the large-scale fog.
* @param enabled If true, enables large-scale fog on this object. Disables it otherwise.
* True by default.
* @return this <code>Builder</code> object for chaining calls
*/
@NonNull
public Builder fog(boolean enabled) {
nBuilderFog(mNativeBuilder, enabled);
return this;
}
@@ -655,6 +723,15 @@ public class RenderableManager {
nSetPriority(mNativeObject, i, priority);
}
/**
* Changes the channel of a renderable
*
* @see Builder#channel
*/
public void setChannel(@EntityInstance int i, @IntRange(from = 0, to = 3) int channel) {
nSetChannel(mNativeObject, i, channel);
}
/**
* Changes whether or not frustum culling is on.
*
@@ -664,6 +741,23 @@ public class RenderableManager {
nSetCulling(mNativeObject, i, enabled);
}
/**
* Changes whether or not the large-scale fog is applied to this renderable
* @see Builder#fog
*/
public void setFogEnabled(@EntityInstance int i, boolean enabled) {
nSetFogEnabled(mNativeObject, i, enabled);
}
/**
* Returns whether large-scale fog is enabled for this renderable.
* @return True if fog is enabled for this renderable.
* @see Builder#fog
*/
public boolean getFogEnabled(@EntityInstance int i) {
return nGetFogEnabled(mNativeObject, i);
}
/**
* Enables or disables a light channel.
* Light channel 0 is enabled by default.
@@ -876,6 +970,7 @@ public class RenderableManager {
private static native void nBuilderBoundingBox(long nativeBuilder, float cx, float cy, float cz, float ex, float ey, float ez);
private static native void nBuilderLayerMask(long nativeBuilder, int select, int value);
private static native void nBuilderPriority(long nativeBuilder, int priority);
private static native void nBuilderChannel(long nativeBuilder, int channel);
private static native void nBuilderCulling(long nativeBuilder, boolean enabled);
private static native void nBuilderCastShadows(long nativeBuilder, boolean enabled);
private static native void nBuilderReceiveShadows(long nativeBuilder, boolean enabled);
@@ -885,7 +980,8 @@ public class RenderableManager {
private static native void nBuilderSkinningBuffer(long nativeBuilder, long nativeSkinningBuffer, int boneCount, int offset);
private static native void nBuilderMorphing(long nativeBuilder, int targetCount);
private static native void nBuilderSetMorphTargetBufferAt(long nativeBuilder, int level, int primitiveIndex, long nativeMorphTargetBuffer, int offset, int count);
private static native void nEnableSkinningBuffers(long nativeBuilder, boolean enabled);
private static native void nBuilderEnableSkinningBuffers(long nativeBuilder, boolean enabled);
private static native void nBuilderFog(long nativeBuilder, boolean enabled);
private static native void nBuilderLightChannel(long nativeRenderableManager, int channel, boolean enable);
private static native void nBuilderInstances(long nativeRenderableManager, int instances);
@@ -898,7 +994,10 @@ public class RenderableManager {
private static native void nSetAxisAlignedBoundingBox(long nativeRenderableManager, int i, float cx, float cy, float cz, float ex, float ey, float ez);
private static native void nSetLayerMask(long nativeRenderableManager, int i, int select, int value);
private static native void nSetPriority(long nativeRenderableManager, int i, int priority);
private static native void nSetChannel(long nativeRenderableManager, int i, int channel);
private static native void nSetCulling(long nativeRenderableManager, int i, boolean enabled);
private static native void nSetFogEnabled(long nativeRenderableManager, int i, boolean enabled);
private static native boolean nGetFogEnabled(long nativeRenderableManager, int i);
private static native void nSetLightChannel(long nativeRenderableManager, int i, int channel, boolean enable);
private static native boolean nGetLightChannel(long nativeRenderableManager, int i, int channel);
private static native void nSetCastShadows(long nativeRenderableManager, int i, boolean enabled);

View File

@@ -124,7 +124,24 @@ public class Renderer {
*/
public static class ClearOptions {
/**
* Color to use to clear the SwapChain
* Color (sRGB linear) to use to clear the RenderTarget (typically the SwapChain).
*
* The RenderTarget is cleared using this color, which won't be tone-mapped since
* tone-mapping is part of View rendering (this is not).
*
* When a View is rendered, there are 3 scenarios to consider:
* - Pixels rendered by the View replace the clear color (or blend with it in
* `BlendMode.TRANSLUCENT` mode).
*
* - With blending mode set to `BlendMode.TRANSLUCENT`, Pixels untouched by the View
* are considered fulling transparent and let the clear color show through.
*
* - With blending mode set to `BlendMode.OPAQUE`, Pixels untouched by the View
* are set to the clear color. However, because it is now used in the context of a View,
* it will go through the post-processing stage, which includes tone-mapping.
*
* For consistency, it is recommended to always use a Skybox to clear an opaque View's
* background, or to use black or fully-transparent (i.e. {0,0,0,0}) as the clear color.
*/
@NonNull
public float[] clearColor = { 0.0f, 0.0f, 0.0f, 0.0f };

View File

@@ -163,6 +163,15 @@ public class Scene {
return nGetLightCount(getNativeObject());
}
/**
* Returns true if the given entity is in the Scene.
*
* @return Whether the given entity is in the Scene.
*/
public boolean hasEntity(@Entity int entity) {
return nHasEntity(getNativeObject(), entity);
}
public long getNativeObject() {
if (mNativeObject == 0) {
throw new IllegalStateException("Calling method on destroyed Scene");
@@ -182,4 +191,5 @@ public class Scene {
private static native void nRemoveEntities(long nativeScene, int[] entities);
private static native int nGetRenderableCount(long nativeScene);
private static native int nGetLightCount(long nativeScene);
private static native boolean nHasEntity(long nativeScene, int entity);
}

View File

@@ -29,7 +29,6 @@ import java.nio.ReadOnlyBufferException;
* Stream supports three different configurations:
*
* <dl>
* <dt>TEXTURE_ID</dt> <dd>takes an OpenGL texture ID and incurs a copy</dd>
* <dt>ACQUIRED</dt> <dd>connects to an Android AHardwareBuffer</dd>
* <dt>NATIVE</dt> <dd>connects to an Android SurfaceTexture</dd>
* </dl>
@@ -66,12 +65,6 @@ import java.nio.ReadOnlyBufferException;
* </ul>
*
* <p>
* The <b>TEXTURE_ID</b> configuration achieves synchronization automatically. In this mode,
* Filament performs a copy on the main thread during beginFrame by blitting the external image into
* an internal round-robin queue of images. This copy has a run-time cost.
* </p>
*
* <p>
* For <b>ACQUIRED</b> streams, there is no need to perform the copy because Filament explictly
* acquires the stream, then releases it later via a callback function. This configuration is
* especially useful when the Vulkan backend is enabled.
@@ -118,8 +111,7 @@ public class Stream {
* By default, Stream objects are {@link StreamType#ACQUIRED ACQUIRED} and must have external images pushed to them via
* {@link #setAcquiredImage}.
*
* To create a {@link StreamType#NATIVE NATIVE} stream, call one of the <pre>stream</pre> methods
* on the builder.
* To create a {@link StreamType#NATIVE NATIVE} stream, call the <pre>stream</pre> method on the builder.
*/
public static class Builder {
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // Keep to finalize native resources
@@ -211,7 +203,7 @@ public class Stream {
}
/**
* Indicates whether this <code>Stream</code> is NATIVE, TEXTURE_ID, or ACQUIRED.
* Indicates whether this <code>Stream</code> is NATIVE or ACQUIRED.
*/
public StreamType getStreamType() {
return sStreamTypeValues[nGetStreamType(getNativeObject())];
@@ -230,7 +222,7 @@ public class Stream {
* also where the callback is invoked. This method can only be used for streams that were
* constructed without calling the {@link Builder.stream} method.
*
* See {@link Stream} for more information about NATIVE, TEXTURE_ID, and ACQUIRED configurations.
* See {@link Stream} for more information about NATIVE and ACQUIRED configurations.
*
* @param hwbuffer {@link android.hardware.HardwareBuffer HardwareBuffer} (requires API level 26)
* @param handler {@link java.util.concurrent.Executor Executor} or {@link android.os.Handler Handler}.

View File

@@ -91,11 +91,34 @@ public class SwapChain {
*/
public static final long CONFIG_ENABLE_XCB = 0x4;
/**
* Indicates that the SwapChain must automatically perform linear to sRGB encoding.
*
* This flag is ignored if isSRGBSwapChainSupported() is false.
*
* When using this flag, post-processing should be disabled.
*
* @see SwapChain#isSRGBSwapChainSupported
* @see View#setPostProcessingEnabled
*/
public static final long CONFIG_SRGB_COLORSPACE = 0x10;
SwapChain(long nativeSwapChain, Object surface) {
mNativeObject = nativeSwapChain;
mSurface = surface;
}
/**
* Return whether createSwapChain supports the SWAP_CHAIN_CONFIG_SRGB_COLORSPACE flag.
* The default implementation returns false.
*
* @param engine A reference to the filament Engine
* @return true if SWAP_CHAIN_CONFIG_SRGB_COLORSPACE is supported, false otherwise.
*/
public static boolean isSRGBSwapChainSupported(@NonNull Engine engine) {
return nIsSRGBSwapChainSupported(engine.getNativeObject());
}
/**
* @return the native <code>Object</code> this <code>SwapChain</code> was created from or null
* for a headless SwapChain.
@@ -141,4 +164,5 @@ public class SwapChain {
}
private static native void nSetFrameCompletedCallback(long nativeSwapChain, Object handler, Runnable callback);
private static native boolean nIsSRGBSwapChainSupported(long nativeEngine);
}

View File

@@ -250,7 +250,19 @@ public class Texture {
SRGB8_ALPHA8_ASTC_10x8,
SRGB8_ALPHA8_ASTC_10x10,
SRGB8_ALPHA8_ASTC_12x10,
SRGB8_ALPHA8_ASTC_12x12
SRGB8_ALPHA8_ASTC_12x12,
// RGTC formats available with a GLES extension
RED_RGTC1, // BC4 unsigned
SIGNED_RED_RGTC1, // BC4 signed
RED_GREEN_RGTC2, // BC5 unsigned
SIGNED_RED_GREEN_RGTC2, // BC5 signed
// BPTC formats available with a GLES extension
RGB_BPTC_SIGNED_FLOAT, // BC6H signed
RGB_BPTC_UNSIGNED_FLOAT,// BC6H unsigned
RGBA_BPTC_UNORM, // BC7
SRGB_ALPHA_BPTC_UNORM // BC7 sRGB
}
/**
@@ -296,7 +308,19 @@ public class Texture {
SRGB8_ALPHA8_ASTC_10x8,
SRGB8_ALPHA8_ASTC_10x10,
SRGB8_ALPHA8_ASTC_12x10,
SRGB8_ALPHA8_ASTC_12x12
SRGB8_ALPHA8_ASTC_12x12,
// RGTC formats available with a GLES extension
RED_RGTC1, // BC4 unsigned
SIGNED_RED_RGTC1, // BC4 signed
RED_GREEN_RGTC2, // BC5 unsigned
SIGNED_RED_GREEN_RGTC2, // BC5 signed
// BPTC formats available with a GLES extension
RGB_BPTC_SIGNED_FLOAT, // BC6H signed
RGB_BPTC_UNSIGNED_FLOAT,// BC6H unsigned
RGBA_BPTC_UNORM, // BC7
SRGB_ALPHA_BPTC_UNORM // BC7 sRGB
}
/**
@@ -884,7 +908,7 @@ public class Texture {
// TODO: add a setImage() version that takes an android Bitmap
/**
* <code>setImage</code> is used to modify the whole content of the texure from a CPU-buffer.
* <code>setImage</code> is used to modify the whole content of the texture from a CPU-buffer.
*
* <p>This <code>Texture</code> instance must use {@link Sampler#SAMPLER_2D SAMPLER_2D} or
* {@link Sampler#SAMPLER_EXTERNAL SAMPLER_EXTERNAL}. If the later is specified
@@ -912,7 +936,7 @@ public class Texture {
public void setImage(@NonNull Engine engine,
@IntRange(from = 0) int level,
@NonNull PixelBufferDescriptor buffer) {
setImage(engine, level, 0, 0, getWidth(level), getHeight(level), buffer);
setImage(engine, level, 0, 0, 0, getWidth(level), getHeight(level), 1, buffer);
}
@@ -947,33 +971,15 @@ public class Texture {
@IntRange(from = 0) int xoffset, @IntRange(from = 0) int yoffset,
@IntRange(from = 0) int width, @IntRange(from = 0) int height,
@NonNull PixelBufferDescriptor buffer) {
int result;
if (buffer.type == COMPRESSED) {
result = nSetImageCompressed(getNativeObject(), engine.getNativeObject(), level,
xoffset, yoffset, width, height,
buffer.storage, buffer.storage.remaining(),
buffer.left, buffer.top, buffer.type.ordinal(), buffer.alignment,
buffer.compressedSizeInBytes, buffer.compressedFormat.ordinal(),
buffer.handler, buffer.callback);
} else {
result = nSetImage(getNativeObject(), engine.getNativeObject(), level,
xoffset, yoffset, width, height,
buffer.storage, buffer.storage.remaining(),
buffer.left, buffer.top, buffer.type.ordinal(), buffer.alignment,
buffer.stride, buffer.format.ordinal(),
buffer.handler, buffer.callback);
}
if (result < 0) {
throw new BufferOverflowException();
}
setImage(engine, level, xoffset, yoffset, 0, width, height, 1, buffer);
}
/**
* <code>setImage</code> is used to modify a sub-region of the 3D texture or 2D texture array
* from a CPU-buffer.
* <code>setImage</code> is used to modify a sub-region of a 3D texture, 2D texture array or
* cubemap from a CPU-buffer. Cubemaps are treated like a 2D array of six layers.
*
* <p>This <code>Texture</code> instance must use {@link Sampler#SAMPLER_2D_ARRAY SAMPLER_2D_ARRAY} or
* {@link Sampler#SAMPLER_3D SAMPLER_3D}.</p>
* <p>This <code>Texture</code> instance must use {@link Sampler#SAMPLER_2D_ARRAY SAMPLER_2D_ARRAY},
* {@link Sampler#SAMPLER_3D SAMPLER_3D} or {@link Sampler#SAMPLER_CUBEMAP SAMPLER_CUBEMAP}.</p>
*
* @param engine {@link Engine} this texture is associated to. Must be the
* instance passed to {@link Builder#build Builder.build()}.
@@ -1046,7 +1052,9 @@ public class Texture {
*
* @see Builder#sampler
* @see PixelBufferDescriptor
* @deprecated use {@link #setImage(Engine, int, int, int, int, int, int, int, PixelBufferDescriptor)}
*/
@Deprecated
public void setImage(@NonNull Engine engine, @IntRange(from = 0) int level,
@NonNull PixelBufferDescriptor buffer,
@NonNull @Size(min = 6) int[] faceOffsetsInBytes) {
@@ -1258,18 +1266,6 @@ public class Texture {
private static native int nGetTarget(long nativeTexture);
private static native int nGetInternalFormat(long nativeTexture);
private static native int nSetImage(long nativeTexture, long nativeEngine,
int level, int xoffset, int yoffset, int width, int height,
Buffer storage, int remaining, int left, int top, int type, int alignment,
int stride, int format,
Object handler, Runnable callback);
private static native int nSetImageCompressed(long nativeTexture, long nativeEngine,
int level, int xoffset, int yoffset, int width, int height,
Buffer storage, int remaining, int left, int top, int type, int alignment,
int compressedSizeInBytes, int compressedFormat,
Object handler, Runnable callback);
private static native int nSetImage3D(long nativeTexture, long nativeEngine,
int level, int xoffset, int yoffset, int zoffset, int width, int height, int depth,
Buffer storage, int remaining, int left, int top, int type, int alignment,

View File

@@ -276,7 +276,7 @@ public class TextureSampler {
}
/**
* Sets the wrapping mode in the t (depth) direction.
* Sets the wrapping mode in the r (depth) direction.
* @param mode wrapping mode
*/
public void setWrapModeR(WrapMode mode) {

View File

@@ -16,6 +16,7 @@
package com.google.android.filament;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
@@ -199,6 +200,36 @@ import androidx.annotation.Size;
return nGetParent(mNativeObject, i);
}
/**
* Returns the number of children of an {@link EntityInstance}.
*
* @param i the {@link EntityInstance} of the transform component to query.
* @return The number of children of the queried component.
*/
public int getChildCount(@EntityInstance int i) {
return nGetChildCount(mNativeObject, i);
}
/**
* Gets a list of children for a transform component.
*
* @param i the {@link EntityInstance} of the transform component to get the children
* from.
* @param outEntities array to receive the result sized to the maximum number of children to
* retrieve. If <code>null</code> is given, a new suitable array sized to
* {@link #getChildCount(int)} is allocated.
* @return Array of retrieved children {@link Entity}.
*/
public @Entity @NonNull int[] getChildren(@EntityInstance int i, @Nullable int[] outEntities) {
if (outEntities == null) {
outEntities = new int[getChildCount(i)];
}
if (outEntities.length > 0) {
nGetChildren(mNativeObject, i, outEntities, outEntities.length);
}
return outEntities;
}
/**
* Sets a local transform of a transform component.
* <p>This operation can be slow if the hierarchy of transform is too deep, and this
@@ -360,6 +391,8 @@ import androidx.annotation.Size;
private static native void nDestroy(long nativeTransformManager, int entity);
private static native void nSetParent(long nativeTransformManager, int i, int newParent);
private static native int nGetParent(long nativeTransformManager, int i);
private static native int nGetChildCount(long nativeTransformManager, int i);
private static native void nGetChildren(long nativeEntityManager, int i, int[] outEntities, int count);
private static native void nSetTransform(long nativeTransformManager, int i, float[] localTransform);
private static native void nSetTransformFp64(long nativeTransformManager, int i, double[] localTransform);
private static native void nGetTransform(long nativeTransformManager, int i, float[] outLocalTransform);

View File

@@ -793,7 +793,7 @@ public class View {
public void setVsmShadowOptions(@NonNull VsmShadowOptions options) {
mVsmShadowOptions = options;
nSetVsmShadowOptions(getNativeObject(), options.anisotropy, options.mipmapping,
options.minVarianceScale, options.lightBleedReduction);
options.highPrecision, options.minVarianceScale, options.lightBleedReduction);
}
/**
@@ -962,7 +962,8 @@ public class View {
assertFloat3In(options.color);
mFogOptions = options;
nSetFogOptions(getNativeObject(), options.distance, options.maximumOpacity, options.height,
options.heightFalloff, options.color[0], options.color[1], options.color[2],
options.heightFalloff, options.cutOffDistance,
options.color[0], options.color[1], options.color[2],
options.density, options.inScatteringStart, options.inScatteringSize,
options.fogColorFromIbl,
options.enabled);
@@ -1011,6 +1012,45 @@ public class View {
return mDepthOfFieldOptions;
}
/**
* Enables use of the stencil buffer.
*
* <p>
* The stencil buffer is an 8-bit, per-fragment unsigned integer stored alongside the depth
* buffer. The stencil buffer is cleared at the beginning of a frame and discarded after the
* color pass.
* </p>
*
* <p>
* Each fragment's stencil value is set during rasterization by specifying stencil operations on
* a {@link Material}. The stencil buffer can be used as a mask for later rendering by setting a
* {@link Material}'s stencil comparison function and reference value. Fragments that don't pass
* the stencil test are then discarded.
* </p>
*
* <p>
* Post-processing must be enabled in order to use the stencil buffer.
* </p>
*
* <p>
* A renderable's priority (see {@link RenderableManager#setPriority(int, int)}) is useful to
* control the order in which primitives are drawn.
* </p>
*
* @param enabled True to enable the stencil buffer, false disables it (default)
*/
public void setStencilBufferEnabled(boolean enabled) {
nSetStencilBufferEnabled(getNativeObject(), enabled);
}
/**
* @return true if the stencil buffer is enabled.
* @see View#setStencilBufferEnabled(boolean)
*/
public boolean isStencilBufferEnabled() {
return nIsStencilBufferEnabled(getNativeObject());
}
/**
* A class containing the result of a picking query
*/
@@ -1077,6 +1117,51 @@ public class View {
float mFragCoordsZ;
}
/**
* Set the value of material global variables. There are up-to four such variable each of
* type float4. These variables can be read in a user Material with
* `getMaterialGlobal{0|1|2|3}()`. All variable start with a default value of { 0, 0, 0, 1 }
*
* @param index index of the variable to set between 0 and 3.
* @param value new value for the variable.
* @see #getMaterialGlobal
*/
public void setMaterialGlobal(int index, @NonNull @Size(min = 4) float[] value) {
Asserts.assertFloat4In(value);
nSetMaterialGlobal(getNativeObject(), index, value[0], value[1], value[2], value[3]);
}
/**
* Get the value of the material global variables.
* All variable start with a default value of { 0, 0, 0, 1 }
*
* @param index index of the variable to set between 0 and 3.
* @param out A 4-float array where the value will be stored, or null in which case the array is
* allocated.
* @return A 4-float array containing the current value of the variable.
* @see #setMaterialGlobal
*/
@NonNull @Size(min = 4)
public float[] getMaterialGlobal(int index, @Nullable @Size(min = 4) float[] out) {
out = Asserts.assertFloat4(out);
nGetMaterialGlobal(getNativeObject(), index, out);
return out;
}
/**
* Get an Entity representing the large scale fog object.
* This entity is always inherited by the View's Scene.
*
* It is for example possible to create a TransformManager component with this
* Entity and apply a transformation globally on the fog.
*
* @return an Entity representing the large scale fog object.
*/
@Entity
public int getFogEntity() {
return nGetFogEntity(getNativeObject());
}
public long getNativeObject() {
if (mNativeObject == 0) {
throw new IllegalStateException("Calling method on destroyed View");
@@ -1105,7 +1190,7 @@ public class View {
private static native void nSetRenderQuality(long nativeView, int hdrColorBufferQuality);
private static native void nSetDynamicLightingOptions(long nativeView, float zLightNear, float zLightFar);
private static native void nSetShadowType(long nativeView, int type);
private static native void nSetVsmShadowOptions(long nativeView, int anisotropy, boolean mipmapping, float minVarianceScale, float lightBleedReduction);
private static native void nSetVsmShadowOptions(long nativeView, int anisotropy, boolean mipmapping, boolean highPrecision, float minVarianceScale, float lightBleedReduction);
private static native void nSetSoftShadowOptions(long nativeView, float penumbraScale, float penumbraRatioScale);
private static native void nSetColorGrading(long nativeView, long nativeColorGrading);
private static native void nSetPostProcessingEnabled(long nativeView, boolean enabled);
@@ -1118,7 +1203,7 @@ public class View {
private static native void nSetSSCTOptions(long nativeView, float ssctLightConeRad, float ssctStartTraceDistance, float ssctContactDistanceMax, float ssctIntensity, float v, float v1, float v2, float ssctDepthBias, float ssctDepthSlopeBias, int ssctSampleCount, int ssctRayCount, boolean ssctEnabled);
private static native void nSetBloomOptions(long nativeView, long dirtNativeObject, float dirtStrength, float strength, int resolution, float anamorphism, int levels, int blendMode, boolean threshold, boolean enabled, float highlight,
boolean lensFlare, boolean starburst, float chromaticAberration, int ghostCount, float ghostSpacing, float ghostThreshold, float haloThickness, float haloRadius, float haloThreshold);
private static native void nSetFogOptions(long nativeView, float distance, float maximumOpacity, float height, float heightFalloff, float v, float v1, float v2, float density, float inScatteringStart, float inScatteringSize, boolean fogColorFromIbl, boolean enabled);
private static native void nSetFogOptions(long nativeView, float distance, float maximumOpacity, float height, float heightFalloff, float cutOffDistance, float v, float v1, float v2, float density, float inScatteringStart, float inScatteringSize, boolean fogColorFromIbl, boolean enabled);
private static native void nSetBlendMode(long nativeView, int blendMode);
private static native void nSetDepthOfFieldOptions(long nativeView, float cocScale, float maxApertureDiameter, boolean enabled, int filter,
boolean nativeResolution, int foregroundRingCount, int backgroundRingCount, int fastGatherRingCount, int maxForegroundCOC, int maxBackgroundCOC);
@@ -1131,6 +1216,12 @@ public class View {
private static native void nSetGuardBandOptions(long nativeView, boolean enabled);
private static native boolean nIsScreenSpaceRefractionEnabled(long nativeView);
private static native void nPick(long nativeView, int x, int y, Object handler, InternalOnPickCallback internalCallback);
private static native void nSetStencilBufferEnabled(long nativeView, boolean enabled);
private static native boolean nIsStencilBufferEnabled(long nativeView);
private static native void nSetMaterialGlobal(long nativeView, int index, float x, float y, float z, float w);
private static native void nGetMaterialGlobal(long nativeView, int index, float[] out);
private static native int nGetFogEntity(long nativeView);
/**
* List of available ambient occlusion techniques.
@@ -1351,48 +1442,87 @@ public class View {
}
/**
* Options to control fog in the scene
* Options to control large-scale fog in the scene
*/
public static class FogOptions {
/**
* distance in world units from the camera where the fog starts ( >= 0.0 )
* Distance in world units [m] from the camera to where the fog starts ( >= 0.0 )
*/
public float distance = 0.0f;
/**
* Distance in world units [m] after which the fog calculation is disabled.
* This can be used to exclude the skybox, which is desirable if it already contains clouds or
* fog. The default value is +infinity which applies the fog to everything.
*
* Note: The SkyBox is typically at a distance of 1e19 in world space (depending on the near
* plane distance and projection used though).
*/
public float cutOffDistance = Float.POSITIVE_INFINITY;
/**
* fog's maximum opacity between 0 and 1
*/
public float maximumOpacity = 1.0f;
/**
* fog's floor in world units
* Fog's floor in world units [m]. This sets the "sea level".
*/
public float height = 0.0f;
/**
* how fast fog dissipates with altitude
* How fast the fog dissipates with altitude. heightFalloff has a unit of [1/m].
* It can be expressed as 1/H, where H is the altitude change in world units [m] that causes a
* factor 2.78 (e) change in fog density.
*
* A falloff of 0 means the fog density is constant everywhere and may result is slightly
* faster computations.
*/
public float heightFalloff = 1.0f;
/**
* fog's color (linear), see fogColorFromIbl
* Fog's color is used for ambient light in-scattering, a good value is
* to use the average of the ambient light, possibly tinted towards blue
* for outdoors environments. Color component's values should be between 0 and 1, values
* above one are allowed but could create a non energy-conservative fog (this is dependant
* on the IBL's intensity as well).
*
* We assume that our fog has no absorption and therefore all the light it scatters out
* becomes ambient light in-scattering and has lost all directionality, i.e.: scattering is
* isotropic. This somewhat simulates Rayleigh scattering.
*
* This value is used as a tint instead, when fogColorFromIbl is enabled.
*
* @see fogColorFromIbl
*/
@NonNull @Size(min = 3)
public float[] color = {0.5f, 0.5f, 0.5f};
public float[] color = {1.0f, 1.0f, 1.0f};
/**
* fog's density at altitude given by 'height'
* Extinction factor in [1/m] at altitude 'height'. The extinction factor controls how much
* light is absorbed and out-scattered per unit of distance. Each unit of extinction reduces
* the incoming light to 37% of its original value.
*
* Note: The extinction factor is related to the fog density, it's usually some constant K times
* the density at sea level (more specifically at fog height). The constant K depends on
* the composition of the fog/atmosphere.
*
* For historical reason this parameter is called `density`.
*/
public float density = 0.1f;
/**
* distance in world units from the camera where in-scattering starts
* Distance in world units [m] from the camera where the Sun in-scattering starts.
*/
public float inScatteringStart = 0.0f;
/**
* size of in-scattering (>0 to activate). Good values are >> 1 (e.g. ~10 - 100).
* Very inaccurately simulates the Sun's in-scattering. That is, the light from the sun that
* is scattered (by the fog) towards the camera.
* Size of the Sun in-scattering (>0 to activate). Good values are >> 1 (e.g. ~10 - 100).
* Smaller values result is a larger scattering size.
*/
public float inScatteringSize = -1.0f;
/**
* Fog color will be modulated by the IBL color in the view direction.
* The fog color will be sampled from the IBL in the view direction and tinted by `color`.
* Depending on the scene this can produce very convincing results.
* This simulate a more anisotropic phase-function.
*/
public boolean fogColorFromIbl = false;
/**
* enable or disable fog
* Enable or disable large-scale fog
*/
public boolean enabled = false;
}
@@ -1776,6 +1906,20 @@ public class View {
* Whether to generate mipmaps for all VSM shadow maps.
*/
public boolean mipmapping = false;
/**
* The number of MSAA samples to use when rendering VSM shadow maps.
* Must be a power-of-two and greater than or equal to 1. A value of 1 effectively turns
* off MSAA.
* Higher values may not be available depending on the underlying hardware.
*/
public int msaaSamples = 1;
/**
* Whether to use a 32-bits or 16-bits texture format for VSM shadow maps. 32-bits
* precision is rarely needed, but it does reduces light leaks as well as "fading"
* of the shadows in some situations. Setting highPrecision to true for a single
* shadow map will double the memory usage of all shadow maps.
*/
public boolean highPrecision = false;
/**
* VSM minimum variance scale, must be positive.
*/

View File

@@ -0,0 +1,42 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.filament.android;
import com.google.android.filament.Engine;
import com.google.android.filament.Fence;
public class FilamentHelper {
/**
* Wait for all pending frames to be processed before returning. This is to
* avoid a race between the surface being resized before pending frames are
* rendered into it. This is typically called from {@link UiHelper.RendererCallback#onResized},
* {@link android.view.SurfaceHolder.Callback#surfaceChanged} or
* {@link android.view.TextureView.SurfaceTextureListener#onSurfaceTextureSizeChanged}.
*
* @param engine Filament engine to synchronize
*
* @see UiHelper.RendererCallback#onResized
* @see android.view.SurfaceHolder.Callback#surfaceChanged
* @see android.view.TextureView.SurfaceTextureListener#onSurfaceTextureSizeChanged
*/
static public void synchronizePendingFrames(Engine engine) {
Fence fence = engine.createFence();
fence.wait(Fence.Mode.FLUSH, Fence.WAIT_FOR_EVER);
engine.destroyFence(fence);
}
}

View File

@@ -84,6 +84,14 @@ import com.google.android.filament.SwapChain;
* // The native surface has changed size. This is always called at least once
* // after the surface is created (after onNativeWindowChanged() is invoked).
* public void onResized(int width, int height) {
*
* // Wait for all pending frames to be processed before returning. This is to
* // avoid a race between the surface being resized before pending frames are
* // rendered into it.
* Fence fence = mEngine.createFence();
* fence.wait(Fence.Mode.FLUSH, Fence.WAIT_FOR_EVER);
* mEngine.destroyFence(fence);
*
* // Compute camera projection and set the viewport on the view
* }
* });
@@ -175,7 +183,7 @@ public class UiHelper {
}
private static class SurfaceViewHandler implements RenderSurface {
private SurfaceView mSurfaceView;
private final SurfaceView mSurfaceView;
SurfaceViewHandler(SurfaceView surface) {
mSurfaceView = surface;
@@ -192,7 +200,7 @@ public class UiHelper {
}
private static class SurfaceHolderHandler implements RenderSurface {
private SurfaceHolder mSurfaceHolder;
private final SurfaceHolder mSurfaceHolder;
SurfaceHolderHandler(SurfaceHolder surface) {
mSurfaceHolder = surface;
@@ -209,7 +217,7 @@ public class UiHelper {
}
private class TextureViewHandler implements RenderSurface {
private TextureView mTextureView;
private final TextureView mTextureView;
private Surface mSurface;
TextureViewHandler(TextureView surface) { mTextureView = surface; }

View File

@@ -1,4 +1,7 @@
apply plugin: 'kotlin-android'
kotlin {
jvmToolchain(versions.jdk)
}
android {
namespace 'com.google.android.filament.utils'
@@ -21,16 +24,11 @@ android {
excludes += ['lib/*/libfilament-jni.so', 'lib/*/libgltfio-jni.so']
}
}
}
configurations.all { config ->
// Hack to preserve the version of the dependencies
if (!config.name.endsWith('Publication')) {
resolutionStrategy {
dependencySubstitution {
substitute(module("com.google.android.filament:gltfio-android:${VERSION_NAME}")).with(project(":gltfio-android"))
substitute(module("com.google.android.filament:gltfio-android-lite:${VERSION_NAME}")).with(project(":gltfio-android"))
}
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}
@@ -43,7 +41,7 @@ dependencies {
implementation deps.coroutines.android
api project(':filament-android')
api module("com.google.android.filament:gltfio-android:${VERSION_NAME}")
api project(':gltfio-android')
}
apply from: rootProject.file('gradle/gradle-mvn-push.gradle')

View File

@@ -70,7 +70,8 @@ Java_com_google_android_filament_utils_AutomationEngine_nStartBatchMode(JNIEnv*
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_utils_AutomationEngine_nTick(JNIEnv* env, jclass klass,
jlong nativeAutomation, jlong view, jlongArray materials, jlong renderer, jfloat deltaTime) {
jlong nativeAutomation, jlong nativeEngine,
jlong view, jlongArray materials, jlong renderer, jfloat deltaTime) {
using MaterialPointer = MaterialInstance*;
jsize materialCount = 0;
jlong* longMaterials = nullptr;
@@ -90,7 +91,8 @@ Java_com_google_android_filament_utils_AutomationEngine_nTick(JNIEnv* env, jclas
.materials = ptrMaterials,
.materialCount = (size_t) materialCount,
};
automation->tick(content, deltaTime);
Engine* engine = (Engine*)nativeEngine;
automation->tick(engine, content, deltaTime);
if (longMaterials) {
env->ReleaseLongArrayElements(materials, longMaterials, 0);
delete[] ptrMaterials;
@@ -99,7 +101,8 @@ Java_com_google_android_filament_utils_AutomationEngine_nTick(JNIEnv* env, jclas
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_utils_AutomationEngine_nApplySettings(JNIEnv* env, jclass klass,
jlong nativeAutomation, jstring json, jlong view, jlongArray materials, jlong nativeIbl,
jlong nativeAutomation, jlong nativeEngine,
jstring json, jlong view, jlongArray materials, jlong nativeIbl,
jint sunlightEntity, jintArray assetLights, jlong nativeLm, jlong scene, jlong renderer) {
using MaterialPointer = MaterialInstance*;
@@ -140,8 +143,8 @@ Java_com_google_android_filament_utils_AutomationEngine_nApplySettings(JNIEnv* e
.assetLights = (Entity*) intLights,
.assetLightCount = (size_t) lightCount,
};
automation->applySettings(nativeJson, jsonLength, content);
Engine* engine = (Engine*)nativeEngine;
automation->applySettings(engine, nativeJson, jsonLength, content);
env->ReleaseStringUTFChars(json, nativeJson);
if (longMaterials) {
env->ReleaseLongArrayElements(materials, longMaterials, 0);
@@ -163,22 +166,28 @@ Java_com_google_android_filament_utils_AutomationEngine_nGetViewerOptions(JNIEnv
const jfieldID cameraAperture = env->GetFieldID(klass, "cameraAperture", "F");
const jfieldID cameraSpeed = env->GetFieldID(klass, "cameraSpeed", "F");
const jfieldID cameraISO = env->GetFieldID(klass, "cameraISO", "F");
const jfieldID cameraNear = env->GetFieldID(klass, "cameraNear", "F");
const jfieldID cameraFar = env->GetFieldID(klass, "cameraFar", "F");
const jfieldID groundShadowStrength = env->GetFieldID(klass, "groundShadowStrength", "F");
const jfieldID groundPlaneEnabled = env->GetFieldID(klass, "groundPlaneEnabled", "Z");
const jfieldID skyboxEnabled = env->GetFieldID(klass, "skyboxEnabled", "Z");
const jfieldID cameraFocalLength = env->GetFieldID(klass, "cameraFocalLength", "F");
const jfieldID cameraFocusDistance = env->GetFieldID(klass, "cameraFocusDistance", "F");
const jfieldID autoScaleEnabled = env->GetFieldID(klass, "autoScaleEnabled", "Z");
const jfieldID autoInstancingEnabled = env->GetFieldID(klass, "autoInstancingEnabled", "Z");
env->SetFloatField(result, cameraAperture, options.cameraAperture);
env->SetFloatField(result, cameraSpeed, options.cameraSpeed);
env->SetFloatField(result, cameraISO, options.cameraISO);
env->SetFloatField(result, cameraNear, options.cameraNear);
env->SetFloatField(result, cameraFar, options.cameraFar);
env->SetFloatField(result, groundShadowStrength, options.groundShadowStrength);
env->SetBooleanField(result, groundPlaneEnabled, options.groundPlaneEnabled);
env->SetBooleanField(result, skyboxEnabled, options.skyboxEnabled);
env->SetFloatField(result, cameraFocalLength, options.cameraFocalLength);
env->SetFloatField(result, cameraFocusDistance, options.cameraFocusDistance);
env->SetBooleanField(result, autoScaleEnabled, options.autoScaleEnabled);
env->SetBooleanField(result, autoInstancingEnabled, options.autoInstancingEnabled);
}
extern "C" JNIEXPORT jlong JNICALL

View File

@@ -97,12 +97,15 @@ public class AutomationEngine {
public float cameraAperture = 16.0f;
public float cameraSpeed = 125.0f;
public float cameraISO = 100.0f;
public float cameraNear = 0.1f;
public float cameraFar = 100.0f;
public float groundShadowStrength = 0.75f;
public boolean groundPlaneEnabled = false;
public boolean skyboxEnabled = true;
public float cameraFocalLength = 28.0f;
public float cameraFocusDistance = 0.0f;
public boolean autoScaleEnabled = true;
public boolean autoInstancingEnabled = false;
}
/**
@@ -155,10 +158,11 @@ public class AutomationEngine {
* This is when settings get applied, screenshots are (optionally) exported, and the internal
* test counter is potentially incremented.
*
* @param engine The filament Engine of interest.
* @param content Contains the Filament View, Materials, and Renderer that get modified.
* @param deltaTime The amount of time that has passed since the previous tick in seconds.
*/
public void tick(@NonNull ViewerContent content, float deltaTime) {
public void tick(@NonNull Engine engine, @NonNull ViewerContent content, float deltaTime) {
if (content.view == null || content.renderer == null) {
throw new IllegalStateException("Must provide a View and Renderer");
}
@@ -171,7 +175,7 @@ public class AutomationEngine {
}
long nativeView = content.view.getNativeObject();
long nativeRenderer = content.renderer.getNativeObject();
nTick(mNativeObject, nativeView, nativeMaterialInstances, nativeRenderer, deltaTime);
nTick(mNativeObject, engine.getNativeObject(), nativeView, nativeMaterialInstances, nativeRenderer, deltaTime);
}
/**
@@ -183,10 +187,12 @@ public class AutomationEngine {
* This updates the stashed Settings object, then pushes those settings to the given
* Filament objects. Clients can optionally call getColorGrading() after calling this method.
*
* @param engine Filament Engine to use.
* @param settingsJson Contains the JSON string with a set of changes that need to be pushed.
* @param content Contains a set of Filament objects that you want to mutate.
*/
public void applySettings(@NonNull String settingsJson, @NonNull ViewerContent content) {
public void applySettings(@NonNull Engine engine, @NonNull String settingsJson,
@NonNull ViewerContent content) {
if (content.view == null || content.renderer == null) {
throw new IllegalStateException("Must provide a View and Renderer");
}
@@ -205,7 +211,8 @@ public class AutomationEngine {
long nativeLm = content.lightManager.getNativeObject();
long nativeScene = content.scene.getNativeObject();
long nativeRenderer = content.renderer.getNativeObject();
nApplySettings(mNativeObject, settingsJson, nativeView, nativeMaterialInstances,
nApplySettings(mNativeObject, engine.getNativeObject(),
settingsJson, nativeView, nativeMaterialInstances,
nativeIbl, content.sunlight, content.assetLights, nativeLm, nativeScene,
nativeRenderer);
}
@@ -266,9 +273,10 @@ public class AutomationEngine {
int minFrameCount, boolean verbose);
private static native void nStartRunning(long nativeObject);
private static native void nStartBatchMode(long nativeObject);
private static native void nTick(long nativeObject, long view, long[] materials, long renderer,
float deltaTime);
private static native void nApplySettings(long nativeObject, String jsonSettings, long view,
private static native void nTick(long nativeObject, long nativeEngine,
long view, long[] materials, long renderer, float deltaTime);
private static native void nApplySettings(long nativeObject, long nativeEngine,
String jsonSettings, long view,
long[] materials, long ibl, int sunlight, int[] assetLights, long lightManager,
long scene, long renderer);
private static native void nGetViewerOptions(long nativeObject, Object result);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
@file:Suppress("unused")
@file:Suppress("NOTHING_TO_INLINE", "unused")
package com.google.android.filament.utils
@@ -24,8 +24,16 @@ enum class MatrixColumn {
X, Y, Z, W
}
enum class RotationsOrder {
XYZ, XZY, YXZ, YZX, ZXY, ZYX
enum class RotationsOrder(
val yaw: VectorComponent,
val pitch: VectorComponent,
val roll: VectorComponent) {
XYZ(VectorComponent.X, VectorComponent.Y, VectorComponent.Z),
XZY(VectorComponent.X, VectorComponent.Z, VectorComponent.Y),
YXZ(VectorComponent.Y, VectorComponent.X, VectorComponent.Z),
YZX(VectorComponent.Y, VectorComponent.Z, VectorComponent.X),
ZXY(VectorComponent.Z, VectorComponent.X, VectorComponent.Y),
ZYX(VectorComponent.Z, VectorComponent.Y, VectorComponent.X);
}
data class Mat2(
@@ -77,6 +85,12 @@ data class Mat2(
operator fun minus(v: Float) = Mat2(x - v, y - v)
operator fun times(v: Float) = Mat2(x * v, y * v)
operator fun div(v: Float) = Mat2(x / v, y / v)
inline fun compareTo(v: Float, delta: Float = 0.0f) = Mat2(
x.compareTo(v, delta),
y.compareTo(v, delta)
)
inline fun equals(v: Float, delta: Float = 0.0f) = x.equals(v, delta) && y.equals(v, delta)
operator fun times(m: Mat2) = Mat2(
Float2(
@@ -89,12 +103,18 @@ data class Mat2(
)
)
inline fun compareTo(m: Mat2, delta: Float = 0.0f) = Mat2(
x.compareTo(m.x, delta),
y.compareTo(m.y, delta)
)
inline fun equals(m: Mat2, delta: Float = 0.0f) = x.equals(m.x, delta) && y.equals(m.y, delta)
operator fun times(v: Float2) = Float2(
x.x * v.x + y.x * v.y,
x.y * v.x + y.y * v.y,
)
fun toFloatArray() = floatArrayOf(
x.x, y.x,
x.y, y.y
@@ -106,7 +126,6 @@ data class Mat2(
|${x.y} ${y.y}|
""".trimIndent()
}
}
data class Mat3(
@@ -162,6 +181,14 @@ data class Mat3(
operator fun minus(v: Float) = Mat3(x - v, y - v, z - v)
operator fun times(v: Float) = Mat3(x * v, y * v, z * v)
operator fun div(v: Float) = Mat3(x / v, y / v, z / v)
inline fun compareTo(v: Float, delta: Float = 0.0f) = Mat3(
x.compareTo(v, delta),
y.compareTo(v, delta),
z.compareTo(v, delta)
)
inline fun equals(v: Float, delta: Float = 0.0f) =
x.equals(v, delta) && y.equals(v, delta) && z.equals(v, delta)
operator fun times(m: Mat3) = Mat3(
Float3(
@@ -181,6 +208,15 @@ data class Mat3(
)
)
inline fun compareTo(m: Mat3, delta: Float = 0.0f) = Mat3(
x.compareTo(m.x, delta),
y.compareTo(m.y, delta),
z.compareTo(m.z, delta)
)
inline fun equals(m: Mat3, delta: Float = 0.0f) =
x.equals(m.x, delta) && y.equals(m.y, delta) && z.equals(m.z, delta)
operator fun times(v: Float3) = Float3(
x.x * v.x + y.x * v.y + z.x * v.z,
x.y * v.x + y.y * v.y + z.y * v.z,
@@ -212,6 +248,7 @@ data class Mat4(
constructor(m: Mat4) : this(m.x.copy(), m.y.copy(), m.z.copy(), m.w.copy())
companion object {
fun of(vararg a: Float): Mat4 {
require(a.size >= 16)
return Mat4(
@@ -302,6 +339,15 @@ data class Mat4(
operator fun minus(v: Float) = Mat4(x - v, y - v, z - v, w - v)
operator fun times(v: Float) = Mat4(x * v, y * v, z * v, w * v)
operator fun div(v: Float) = Mat4(x / v, y / v, z / v, w / v)
inline fun compareTo(v: Float, delta: Float = 0.0f) = Mat4(
x.compareTo(v, delta),
y.compareTo(v, delta),
z.compareTo(v, delta),
w.compareTo(v, delta)
)
inline fun equals(v: Float, delta: Float = 0.0f) =
x.equals(v, delta) && y.equals(v, delta) && z.equals(v, delta) && w.equals(v, delta)
operator fun times(m: Mat4) = Mat4(
Float4(
@@ -330,6 +376,16 @@ data class Mat4(
)
)
inline fun compareTo(m: Mat4, delta: Float = 0.0f) = Mat4(
x.compareTo(m.x, delta),
y.compareTo(m.y, delta),
z.compareTo(m.z, delta),
w.compareTo(m.w, delta)
)
inline fun equals(m: Mat4, delta: Float = 0.0f) =
x.equals(m.x, delta) && y.equals(m.y, delta) && z.equals(m.z, delta) && w.equals(m.w, delta)
operator fun times(v: Float4) = Float4(
x.x * v.x + y.x * v.y + z.x * v.z+ w.x * v.w,
x.y * v.x + y.y * v.y + z.y * v.z+ w.y * v.w,
@@ -337,6 +393,26 @@ data class Mat4(
x.w * v.x + y.w * v.y + z.w * v.z+ w.w * v.w
)
/**
* Get the Euler angles in degrees from this rotation Matrix
*
* Don't forget to extract the rotation with [rotation] if this is a transposed matrix
*
* @param order The order in which to apply rotations.
* Default is [RotationsOrder.ZYX] which means that the object will first be rotated around its Z
* axis, then its Y axis and finally its X axis.
*
* @see eulerAngles
*/
fun toEulerAngles(order: RotationsOrder = RotationsOrder.ZYX) = eulerAngles(this, order)
/**
* Get the [Quaternion] from this rotation Matrix
*
* Don't forget to extract the rotation with [rotation] if this is a transposed matrix
*
* @see quaternion
*/
fun toQuaternion() = quaternion(this)
fun toFloatArray() = floatArrayOf(
@@ -356,6 +432,78 @@ data class Mat4(
}
}
inline fun equal(a: Mat2, b: Float, delta: Float = 0.0f) = Bool2(
a.x.equals(b, delta),
a.y.equals(b, delta)
)
inline fun equal(a: Mat2, b: Mat2, delta: Float = 0.0f) = Bool2(
a.x.equals(b.x, delta),
a.y.equals(b.y, delta)
)
inline fun notEqual(a: Mat2, b: Float, delta: Float = 0.0f) = Bool2(
!a.x.equals(b, delta),
!a.y.equals(b, delta)
)
inline fun notEqual(a: Mat2, b: Mat2, delta: Float = 0.0f) = Bool2(
!a.x.equals(b.x, delta),
!a.y.equals(b.y, delta)
)
inline fun equal(a: Mat3, b: Float, delta: Float = 0.0f) = Bool3(
a.x.equals(b, delta),
a.y.equals(b, delta),
a.z.equals(b, delta)
)
inline fun equal(a: Mat3, b: Mat3, delta: Float = 0.0f) = Bool3(
a.x.equals(b.x, delta),
a.y.equals(b.y, delta),
a.z.equals(b.z, delta)
)
inline fun notEqual(a: Mat3, b: Float, delta: Float = 0.0f) = Bool3(
!a.x.equals(b, delta),
!a.y.equals(b, delta),
!a.z.equals(b, delta)
)
inline fun notEqual(a: Mat3, b: Mat3, delta: Float = 0.0f) = Bool3(
!a.x.equals(b.x, delta),
!a.y.equals(b.y, delta),
!a.z.equals(b.z, delta)
)
inline fun equal(a: Mat4, b: Float, delta: Float = 0.0f) = Bool4(
a.x.equals(b, delta),
a.y.equals(b, delta),
a.z.equals(b, delta),
a.w.equals(b, delta)
)
inline fun equal(a: Mat4, b: Mat4, delta: Float = 0.0f) = Bool4(
a.x.equals(b.x, delta),
a.y.equals(b.y, delta),
a.z.equals(b.z, delta),
a.w.equals(b.w, delta)
)
inline fun notEqual(a: Mat4, b: Float, delta: Float = 0.0f) = Bool4(
!a.x.equals(b, delta),
!a.y.equals(b, delta),
!a.z.equals(b, delta),
!a.w.equals(b, delta)
)
inline fun notEqual(a: Mat4, b: Mat4, delta: Float = 0.0f) = Bool4(
!a.x.equals(b.x, delta),
!a.y.equals(b.y, delta),
!a.z.equals(b.z, delta),
!a.w.equals(b.w, delta)
)
fun transpose(m: Mat2) = Mat2(
Float2(m.x.x, m.y.x),
Float2(m.x.y, m.y.y)
@@ -494,14 +642,7 @@ fun rotation(m: Mat4) = Mat4(normalize(m.right), normalize(m.up), normalize(m.fo
*/
fun rotation(d: Float3, order: RotationsOrder = RotationsOrder.ZYX): Mat4 {
val r = transform(d, ::radians)
return when(order) {
RotationsOrder.XZY -> rotation(r.x, r.z, r.y)
RotationsOrder.XYZ -> rotation(r.x, r.y, r.z)
RotationsOrder.YXZ -> rotation(r.y, r.x, r.z)
RotationsOrder.YZX -> rotation(r.y, r.z, r.x)
RotationsOrder.ZYX -> rotation(r.z, r.y, r.x)
RotationsOrder.ZXY -> rotation(r.z, r.x, r.y)
}
return rotation(r[order.yaw], r[order.pitch], r[order.roll], order)
}
/**
@@ -599,13 +740,93 @@ fun rotation(quaternion: Quaternion): Mat4 {
Float4(
2.0f * (n.x * n.z + n.y * n.w),
2.0f * (n.y * n.z - n.x * n.w),
1.0f - 2.0f * (n.x * n.x + n.y * n.y),
1.0f - 2.0f * (n.x * n.x + n.y * n.y)
)
)
}
/**
* Extract Quaternion rotation from a Matrix
* Get the Euler angles in degrees from a rotation Matrix
*
* @param m The rotation matrix.
* Don't forget to extract the rotation with [rotation] if it's transposed
* @param order The order in which to apply rotations.
* Default is [RotationsOrder.ZYX] which means that the object will first be rotated around its Z
* axis, then its Y axis and finally its X axis.
*/
fun eulerAngles(m: Mat4, order: RotationsOrder = RotationsOrder.ZYX): Float3 {
// We need to more simplify this with RotationsOrder VectorComponents mapped to MatrixColumn
return transform(Float3().apply {
when (order) {
RotationsOrder.XYZ -> {
this[order.pitch] = asin(clamp(m.z.x, -1.0f, 1.0f))
if (abs(m.z.x) < 0.9999999f) {
this[order.yaw] = atan2(-m.z.y, m.z.z)
this[order.roll] = atan2(-m.y.x, m.x.x)
} else {
this[order.yaw] = atan2(m.y.z, m.y.y)
this[order.roll] = 0.0f
}
}
RotationsOrder.XZY -> {
this[order.pitch] = asin(-clamp(m.y.x, -1.0f, 1.0f))
if (abs(m.y.x) < 0.9999999f) {
this[order.yaw] = atan2(m.y.z, m.y.y)
this[order.roll] = atan2(m.z.x, m.x.x)
} else {
this[order.yaw] = atan2(-m.z.y, m.z.z)
this[order.roll] = 0.0f
}
}
RotationsOrder.YXZ -> {
this[order.pitch] = asin(-clamp(m.z.y, -1.0f, 1.0f))
if (abs(m.z.y) < 0.9999999f) {
this[order.yaw] = atan2(m.z.x, m.z.z)
this[order.roll] = atan2(m.x.y, m.y.y)
} else {
this[order.yaw] = atan2(-m.x.z, m.x.x)
this[order.roll] = 0.0f
}
}
RotationsOrder.YZX -> {
this[order.pitch] = asin(clamp(m.x.y, -1.0f, 1.0f))
if (abs(m.x.y) < 0.9999999f) {
this[order.roll] = atan2(-m.z.y, m.y.y)
this[order.yaw] = atan2(-m.x.z, m.x.x)
} else {
this[order.roll] = 0.0f
this[order.yaw] = atan2(m.z.x, m.z.z)
}
}
RotationsOrder.ZXY -> {
this[order.pitch] = asin(clamp(m.y.z, -1.0f, 1.0f))
if (abs(m.y.z) < 0.9999999f) {
this[order.roll] = atan2(-m.x.z, m.z.z)
this[order.yaw] = atan2(-m.y.x, m.y.y)
} else {
this[order.roll] = 0.0f
this[order.yaw] = atan2(m.x.y, m.x.x)
}
}
RotationsOrder.ZYX -> {
this[order.pitch] = asin(-clamp(m.x.z, -1.0f, 1.0f))
if (abs(m.x.z) < 0.9999999f) {
this[order.roll] = atan2(m.y.z, m.z.z)
this[order.yaw] = atan2(m.x.y, m.x.x)
} else {
this[order.roll] = 0.0f
this[order.yaw] = atan2(-m.y.x, m.y.y)
}
}
}
}, ::degrees)
}
/**
* Get the [Quaternion] from a rotation Matrix
*
* @param m The rotation matrix.
* Don't forget to extract the rotation with [rotation] if it's transposed
*/
fun quaternion(m: Mat4): Quaternion {
val trace = m.x.x + m.y.y + m.z.z
@@ -673,9 +894,14 @@ fun perspective(fov: Float, ratio: Float, near: Float, far: Float): Mat4 {
}
fun ortho(l: Float, r: Float, b: Float, t: Float, n: Float, f: Float) = Mat4(
Float4(x = 2.0f / (r - 1.0f)),
Float4(y = 2.0f / (t - b)),
Float4(z = -2.0f / (f - n)),
Float4(-(r + l) / (r - l), -(t + b) / (t - b), -(f + n) / (f - n), 1.0f)
Float4(x = 2.0f / (r - l)),
Float4(y = 2.0f / (t - b)),
Float4(z = -2.0f / (f - n)),
Float4(
-(r + l) / (r - l),
-(t + b) / (t - b),
-(f + n) / (f - n),
1.0f
)
)

View File

@@ -27,8 +27,8 @@ import com.google.android.filament.gltfio.*
import kotlinx.coroutines.*
import java.nio.Buffer
private const val kNearPlane = 0.05 // 5 cm
private const val kFarPlane = 1000.0 // 1 km
private const val kNearPlane = 0.05f // 5 cm
private const val kFarPlane = 1000.0f // 1 km
private const val kAperture = 16f
private const val kShutterSpeed = 1f / 125f
private const val kSensitivity = 100f
@@ -73,8 +73,6 @@ class ModelViewer(
get() = resourceLoader.asyncGetLoadProgress()
var normalizeSkinningWeights = true
var recomputeBoundingBoxes = false
var ignoreBindTransform = false
var cameraFocalLength = 28f
set(value) {
@@ -82,6 +80,18 @@ class ModelViewer(
updateCameraProjection()
}
var cameraNear = kNearPlane
set(value) {
field = value
updateCameraProjection()
}
var cameraFar = kFarPlane
set(value) {
field = value
updateCameraProjection()
}
val scene: Scene
val view: View
val camera: Camera
@@ -116,7 +126,7 @@ class ModelViewer(
materialProvider = UbershaderProvider(engine)
assetLoader = AssetLoader(engine, materialProvider, EntityManager.get())
resourceLoader = ResourceLoader(engine, normalizeSkinningWeights, recomputeBoundingBoxes, ignoreBindTransform)
resourceLoader = ResourceLoader(engine, normalizeSkinningWeights)
// Always add a direct light source since it is required for shadowing.
// We highly recommend adding an indirect light as well.
@@ -178,10 +188,10 @@ class ModelViewer(
*/
fun loadModelGlb(buffer: Buffer) {
destroyModel()
asset = assetLoader.createAssetFromBinary(buffer)
asset = assetLoader.createAsset(buffer)
asset?.let { asset ->
resourceLoader.asyncBeginLoad(asset)
animator = asset.animator
animator = asset.getInstance().animator
asset.releaseSourceData()
}
}
@@ -193,7 +203,7 @@ class ModelViewer(
*/
fun loadModelGltf(buffer: Buffer, callback: (String) -> Buffer?) {
destroyModel()
asset = assetLoader.createAssetFromJson(buffer)
asset = assetLoader.createAsset(buffer)
asset?.let { asset ->
for (uri in asset.resourceUris) {
val resourceBuffer = callback(uri)
@@ -204,7 +214,7 @@ class ModelViewer(
resourceLoader.addResourceData(uri, resourceBuffer)
}
resourceLoader.asyncBeginLoad(asset)
animator = asset.animator
animator = asset.getInstance().animator
asset.releaseSourceData()
}
}
@@ -216,7 +226,7 @@ class ModelViewer(
*/
fun loadModelGltfAsync(buffer: Buffer, callback: (String) -> Buffer) {
destroyModel()
asset = assetLoader.createAssetFromJson(buffer)
asset = assetLoader.createAsset(buffer)
fetchResourcesJob = CoroutineScope(Dispatchers.IO).launch {
fetchResources(asset!!, callback)
}
@@ -312,8 +322,8 @@ class ModelViewer(
private fun addDetachListener(view: android.view.View) {
view.addOnAttachStateChangeListener(object : android.view.View.OnAttachStateChangeListener {
override fun onViewAttachedToWindow(v: android.view.View?) {}
override fun onViewDetachedFromWindow(v: android.view.View?) {
override fun onViewAttachedToWindow(v: android.view.View) {}
override fun onViewDetachedFromWindow(v: android.view.View) {
uiHelper.detach()
destroyModel()
@@ -361,7 +371,7 @@ class ModelViewer(
resourceLoader.addResourceData(uri, buffer)
}
resourceLoader.asyncBeginLoad(asset)
animator = asset.animator
animator = asset.getInstance().animator
asset.releaseSourceData()
}
}
@@ -370,7 +380,8 @@ class ModelViewer(
val width = view.viewport.width
val height = view.viewport.height
val aspect = width.toDouble() / height.toDouble()
camera.setLensProjection(cameraFocalLength.toDouble(), aspect, kNearPlane, kFarPlane)
camera.setLensProjection(cameraFocalLength.toDouble(), aspect,
cameraNear.toDouble(), cameraFar.toDouble())
}
inner class SurfaceCallback : UiHelper.RendererCallback {
@@ -394,9 +405,19 @@ class ModelViewer(
view.viewport = Viewport(0, 0, width, height)
cameraManipulator.setViewport(width, height)
updateCameraProjection()
synchronizePendingFrames(engine)
}
}
private fun synchronizePendingFrames(engine: Engine) {
// Wait for all pending frames to be processed before returning. This is to
// avoid a race between the surface being resized before pending frames are
// rendered into it.
val fence = engine.createFence()
fence.wait(Fence.Mode.FLUSH, Fence.WAIT_FOR_EVER)
engine.destroyFence(fence)
}
companion object {
private val kDefaultObjectPosition = Float3(0.0f, 0.0f, -4.0f)
}

View File

@@ -33,9 +33,9 @@ data class Quaternion(
var x: Float = 0.0f,
var y: Float = 0.0f,
var z: Float = 0.0f,
var w: Float = 0.0f) {
var w: Float = 1.0f) {
constructor(v: Float3, w: Float = 0.0f) : this(v.x, v.y, v.z, w)
constructor(v: Float3, w: Float = 1.0f) : this(v.x, v.y, v.z, w)
constructor(v: Float4) : this(v.x, v.y, v.z, v.w)
constructor(q: Quaternion) : this(q.x, q.y, q.z, q.w)
@@ -52,42 +52,84 @@ data class Quaternion(
}
/**
* Construct a Quaternion from Euler angles using YPR around ZYX respectively
* Construct a Quaternion from Euler angles using YPR around a specified order
*
* The Euler angles are applied in ZYX order.
* i.e: a vector is first rotated about X (roll) then Y (pitch) and then Z (yaw).
* Uses intrinsic Tait-Bryan angles. This means that rotations are performed with respect to
* the local coordinate system.
* That is, for order 'XYZ', the rotation is first around the X axis (which is the same as
* the world-X axis), then around local-Y (which may now be different from the world
* Y-axis), then local-Z (which may be different from the world Z-axis)
*
* @param d Per axis Euler angles in degrees
* Yaw, pitch, roll (YPR) are taken accordingly to the rotations order input.
* @param order The order in which to apply rotations.
* Default is [RotationsOrder.ZYX] which means that the object will first be rotated around
* its Z axis, then its Y axis and finally its X axis.
*/
fun fromEuler(d: Float3): Quaternion {
fun fromEuler(d: Float3, order: RotationsOrder = RotationsOrder.ZYX): Quaternion {
val r = transform(d, ::radians)
return fromEulerZYX(r.z, r.y, r.x)
return fromEuler(r[order.yaw], r[order.pitch], r[order.roll], order)
}
/**
* Construct a Quaternion from Euler angles using YPR around ZYX respectively
* Construct a Quaternion from Euler yaw, pitch, roll around a specified order.
*
* The Euler angles are applied in ZYX order.
* i.e: a vector is first rotated about X (roll) then Y (pitch) and then Z (yaw).
*
* @param roll about X axis in radians
* @param pitch about Y axis in radians
* @param yaw about Z axis in radians
* @param roll about 1st rotation axis in radians. Z in case of ZYX order
* @param pitch about 2nd rotation axis in radians. Y in case of ZYX order
* @param yaw about 3rd rotation axis in radians. X in case of ZYX order
* @param order The order in which to apply rotations.
* Default is [RotationsOrder.ZYX] which means that the object will first be rotated around its Z
* axis, then its Y axis and finally its X axis.
*/
fun fromEulerZYX(yaw: Float = 0.0f, pitch: Float = 0.0f, roll: Float = 0.0f): Quaternion {
val cy = cos(yaw * 0.5f)
val sy = sin(yaw * 0.5f)
val cp = cos(pitch * 0.5f)
val sp = sin(pitch * 0.5f)
val cr = cos(roll * 0.5f)
val sr = sin(roll * 0.5f)
return Quaternion(
sr * cp * cy - cr * sp * sy,
cr * sp * cy + sr * cp * sy,
cr * cp * sy - sr * sp * cy,
cr * cp * cy + sr * sp * sy
)
fun fromEuler(
yaw: Float = 0.0f,
pitch: Float = 0.0f,
roll: Float = 0.0f,
order: RotationsOrder = RotationsOrder.ZYX
): Quaternion {
val c1 = cos(yaw * 0.5f)
val s1 = sin(yaw * 0.5f)
val c2 = cos(pitch * 0.5f)
val s2 = sin(pitch * 0.5f)
val c3 = cos(roll * 0.5f)
val s3 = sin(roll * 0.5f)
return when (order) {
RotationsOrder.XZY -> Quaternion(
s1 * c2 * c3 - c1 * s2 * s3,
c1 * c2 * s3 - s1 * s2 * c3,
s1 * c2 * s3 + c1 * s2 * c3,
s1 * s2 * s3 + c1 * c2 * c3)
RotationsOrder.XYZ -> Quaternion(
s1 * c2 * c3 + s2 * s3 * c1,
s2 * c1 * c3 - s1 * s3 * c2,
s1 * s2 * c3 + s3 * c1 * c2,
c1 * c2 * c3 - s1 * s2 * s3
)
RotationsOrder.YXZ -> Quaternion(
s1 * c2 * s3 + c1 * s2 * c3,
s1 * c2 * c3 - c1 * s2 * s3,
c1 * c2 * s3 - s1 * s2 * c3,
s1 * s2 * s3 + c1 * c2 * c3
)
RotationsOrder.YZX -> Quaternion(
s1 * s2 * c3 + c1 * c2 * s3,
s1 * c2 * c3 + c1 * s2 * s3,
c1 * s2 * c3 - s1 * c2 * s3,
c1 * c2 * c3 - s1 * s2 * s3
)
RotationsOrder.ZYX -> Quaternion(
c1 * c2 * s3 - s1 * s2 * c3,
s1 * c2 * s3 + c1 * s2 * c3,
s1 * c2 * c3 - c1 * s2 * s3,
s1 * s2 * s3 + c1 * c2 * c3
)
RotationsOrder.ZXY -> Quaternion(
c1 * s2 * c3 - s1 * c2 * s3,
s1 * s2 * c3 + c1 * c2 * s3,
s1 * c2 * c3 + c1 * s2 * s3,
c1 * c2 * c3 - s1 * s2 * s3
)
}
}
}
@@ -222,16 +264,44 @@ data class Quaternion(
inline operator fun minus(v: Float) = Quaternion(x - v, y - v, z - v, w - v)
inline operator fun times(v: Float) = Quaternion(x * v, y * v, z * v, w * v)
inline operator fun div(v: Float) = Quaternion(x / v, y / v, z / v, w / v)
inline fun compareTo(v: Float, delta: Float = 0.0f) = Float4(
x.compareTo(v, delta),
y.compareTo(v, delta),
z.compareTo(v, delta),
w.compareTo(v, delta)
)
inline fun equals(v: Float, delta: Float = 0.0f) = Bool4(
x.equals(v, delta),
y.equals(v, delta),
z.equals(v, delta),
w.equals(v, delta)
)
inline operator fun times(v: Float3) = (this * Quaternion(v, 0.0f) * inverse(this)).xyz
inline operator fun plus(q: Quaternion) = Quaternion(x + q.x, y + q.y, z + q.z, w + q.w)
inline operator fun minus(q: Quaternion) = Quaternion(x - q.x, y - q.y, z - q.z, w - q.w)
inline operator fun times(q: Quaternion) = Quaternion(
w * q.x + x * q.w + y * q.z - z * q.y,
w * q.y - x * q.z + y * q.w + z * q.x,
w * q.z + x * q.y - y * q.x + z * q.w,
w * q.w - x * q.x - y * q.y - z * q.z)
w * q.x + x * q.w + y * q.z - z * q.y,
w * q.y - x * q.z + y * q.w + z * q.x,
w * q.z + x * q.y - y * q.x + z * q.w,
w * q.w - x * q.x - y * q.y - z * q.z
)
inline fun compareTo(v: Float4, delta: Float = 0.0f) = Float4(
x.compareTo(v.x, delta),
y.compareTo(v.y, delta),
z.compareTo(v.z, delta),
w.compareTo(v.w, delta)
)
inline fun equals(v: Float4, delta: Float = 0.0f) = Bool4(
x.equals(v.x, delta),
y.equals(v.y, delta),
z.equals(v.z, delta),
w.equals(v.w, delta)
)
inline fun transform(block: (Float) -> Float): Quaternion {
x = block(x)
@@ -253,6 +323,103 @@ inline operator fun Float.minus(q: Quaternion) = Quaternion(this - q.x, this - q
inline operator fun Float.times(q: Quaternion) = Quaternion(this * q.x, this * q.y, this * q.z, this * q.w)
inline operator fun Float.div(q: Quaternion) = Quaternion(this / q.x, this / q.y, this / q.z, this / q.w)
inline fun lessThan(a: Quaternion, b: Float) = Bool4(
a.x < b,
a.y < b,
a.z < b,
a.w < b
)
inline fun lessThan(a: Quaternion, b: Quaternion) = Bool4(
a.x < b.x,
a.y < b.y,
a.z < b.z,
a.w < b.w
)
inline fun lessThanEqual(a: Quaternion, b: Float) = Bool4(
a.x <= b,
a.y <= b,
a.z <= b,
a.w <= b
)
inline fun lessThanEqual(a: Quaternion, b: Quaternion) = Bool4(
a.x <= b.x,
a.y <= b.y,
a.z <= b.z,
a.w <= b.w
)
inline fun greaterThan(a: Quaternion, b: Float) = Bool4(
a.x > b,
a.y > b,
a.z > b,
a.w > b
)
inline fun greaterThan(a: Quaternion, b: Quaternion) = Bool4(
a.x > b.y,
a.y > b.y,
a.z > b.z,
a.w > b.w
)
inline fun greaterThanEqual(a: Quaternion, b: Float) = Bool4(
a.x >= b,
a.y >= b,
a.z >= b,
a.w >= b
)
inline fun greaterThanEqual(a: Quaternion, b: Quaternion) = Bool4(
a.x >= b.x,
a.y >= b.y,
a.z >= b.z,
a.w >= b.w
)
inline fun equal(a: Quaternion, b: Float, delta: Float = 0.0f) = Bool4(
a.x.equals(b, delta),
a.y.equals(b, delta),
a.z.equals(b, delta),
a.w.equals(b, delta)
)
inline fun equal(a: Quaternion, b: Quaternion, delta: Float = 0.0f) = Bool4(
a.x.equals(b.x, delta),
a.y.equals(b.y, delta),
a.z.equals(b.z, delta),
a.w.equals(b.w, delta)
)
inline fun notEqual(a: Quaternion, b: Float, delta: Float = 0.0f) = Bool4(
!a.x.equals(b, delta),
!a.y.equals(b, delta),
!a.z.equals(b, delta),
!a.w.equals(b, delta)
)
inline fun notEqual(a: Quaternion, b: Quaternion, delta: Float = 0.0f) = Bool4(
!a.x.equals(b.x, delta),
!a.y.equals(b.y, delta),
!a.z.equals(b.z, delta),
!a.w.equals(b.w, delta)
)
inline infix fun Quaternion.lt(b: Float) = Bool4(x < b, y < b, z < b, w < b)
inline infix fun Quaternion.lt(b: Float4) = Bool4(x < b.x, y < b.y, z < b.z, w < b.w)
inline infix fun Quaternion.lte(b: Float) = Bool4(x <= b, y <= b, z <= b, w <= b)
inline infix fun Quaternion.lte(b: Float4) = Bool4(x <= b.x, y <= b.y, z <= b.z, w <= b.w)
inline infix fun Quaternion.gt(b: Float) = Bool4(x > b, y > b, z > b, w > b)
inline infix fun Quaternion.gt(b: Float4) = Bool4(x > b.x, y > b.y, z > b.z, w > b.w)
inline infix fun Quaternion.gte(b: Float) = Bool4(x >= b, y >= b, z >= b, w >= b)
inline infix fun Quaternion.gte(b: Float4) = Bool4(x >= b.x, y >= b.y, z >= b.z, w >= b.w)
inline infix fun Quaternion.eq(b: Float) = Bool4(x == b, y == b, z == b, w == b)
inline infix fun Quaternion.eq(b: Float4) = Bool4(x == b.x, y == b.y, z == b.z, w == b.w)
inline infix fun Quaternion.neq(b: Float) = Bool4(x != b, y != b, z != b, w != b)
inline infix fun Quaternion.neq(b: Float4) = Bool4(x != b.x, y != b.y, z != b.z, w != b.w)
inline fun abs(q: Quaternion) = Quaternion(abs(q.x), abs(q.y), abs(q.z), abs(q.w))
inline fun length(q: Quaternion) = sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w)
inline fun length2(q: Quaternion) = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w
@@ -278,6 +445,10 @@ fun cross(a: Quaternion, b: Quaternion): Quaternion {
return Quaternion(m.x, m.y, m.z, 0.0f)
}
fun angle(a: Quaternion, b: Quaternion): Float {
return 2.0f * acos(abs(clamp(dot(a, b), -1.0f, 1.0f)))
}
/**
* Spherical linear interpolation between two given orientations
*
@@ -287,36 +458,38 @@ fun cross(a: Quaternion, b: Quaternion): Quaternion {
* @param a The beginning value
* @param b The ending value
* @param t The ratio between the two floats
* @param valueEps Prevent blowing up when slerping between two quaternions that are very near each
* other. Linear interpolation (lerp) is returned in this case.
* @param dotThreshold If the quaternion dot product is greater than this value
* (i.e. the quaternions are very close to each other), then the quaternions are
* linearly interpolated instead of spherically interpolated.
*
* @return Interpolated value between the two floats
*/
fun slerp(a: Quaternion, b: Quaternion, t: Float, valueEps: Float = 0.0000000001f): Quaternion {
fun slerp(a: Quaternion, b: Quaternion, t: Float, dotThreshold: Float = 0.9995f): Quaternion {
// could also be computed as: pow(q * inverse(p), t) * p;
val d = dot(a, b)
val absd = abs(d)
var dot = dot(a, b)
var b1 = b
// If the dot product is negative, then the interpolation won't follow the shortest angular path
// between the two quaterions. In this case, invert the end quaternion to produce an equivalent
// rotation that will give us the path we want.
if (dot < 0.0f) {
dot = -dot
b1 = -b
}
// Prevent blowing up when slerping between two quaternions that are very near each other.
if ((1.0f - absd) < valueEps) {
return normalize(lerp(if (d < 0.0f) -a else a, b, t))
return if (dot < dotThreshold) {
val angle = acos(dot)
val s = sin(angle)
a * sin((1.0f - t) * angle) / s + b1 * sin(t * angle) / s
} else {
// If the angle is too small, use linear interpolation
nlerp(a, b1, t)
}
val npq = sqrt(dot(a, a) * dot(b, b)) // ||p|| * ||q||
val acos = acos(clamp(absd / npq, -1.0f, 1.0f))
val acos0 = acos * (1.0f - t)
val acos1 = acos * t
val sina = sin(acos)
if (sina < valueEps) {
return normalize(lerp(a, b, t))
}
val isina = 1.0f / sina
val s0 = sin(acos0) * isina
val s1 = sin(acos1) * isina
// ensure we're taking the "short" side
return normalize(s0 * a + (if (d < 0.0f) -s1 else (s1)) * b)
}
fun lerp(a: Quaternion, b: Quaternion, t: Float): Quaternion {
return ((1 - t) * a) + (t * b)
return ((1.0f - t) * a) + (t * b)
}
fun nlerp(a: Quaternion, b: Quaternion, t: Float): Quaternion {
@@ -324,19 +497,12 @@ fun nlerp(a: Quaternion, b: Quaternion, t: Float): Quaternion {
}
/**
* Convert a Quaternion to Euler angles using YPR around ZYX respectively
* Convert a Quaternion to Euler angles
*
* The Euler angles are applied in ZYX order
* @param order The order in which to apply rotations.
* Default is [RotationsOrder.ZYX] which means that the object will first be rotated around its Z
* axis, then its Y axis and finally its X axis.
*/
fun eulerAngles(q: Quaternion): Float3 {
val nq = normalize(q)
return Float3(
// roll (x-axis rotation)
degrees(atan2(2.0f * (nq.y * nq.z + nq.w * nq.x),
nq.w * nq.w - nq.x * nq.x - nq.y * nq.y + nq.z * nq.z)),
// pitch (y-axis rotation)
degrees(asin(-2.0f * (nq.x * nq.z - nq.w * nq.y))),
// yaw (z-axis rotation)
degrees(atan2(2.0f * (nq.x * nq.y + nq.w * nq.z),
nq.w * nq.w + nq.x * nq.x - nq.y * nq.y - nq.z * nq.z)))
fun eulerAngles(q: Quaternion, order: RotationsOrder = RotationsOrder.ZYX): Float3 {
return eulerAngles(rotation(q), order)
}

View File

@@ -28,12 +28,21 @@ const val INV_PI = 1.0f / FPI
const val INV_TWO_PI = INV_PI * 0.5f
const val INV_FOUR_PI = INV_PI * 0.25f
inline fun clamp(x: Float, min: Float, max: Float)= if (x < min) min else (if (x > max) max else x)
val HALF_ONE = Half(0x3c00.toUShort())
val HALF_TWO = Half(0x4000.toUShort())
inline fun clamp(x: Float, min: Float, max: Float) = if (x < min) min else (if (x > max) max else x)
inline fun clamp(x: Half, min: Half, max: Half) = if (x < min) min else (if (x > max) max else x)
inline fun saturate(x: Float) = clamp(x, 0.0f, 1.0f)
inline fun saturate(x: Half) = clamp(x, Half.POSITIVE_ZERO, HALF_ONE)
inline fun mix(a: Float, b: Float, x: Float) = a * (1.0f - x) + b * x
inline fun mix(a: Half, b: Half, x: Half) = a * (HALF_ONE - x) + b * x
inline fun degrees(v: Float) = v * (180.0f * INV_PI)
inline fun radians(v: Float) = v * (FPI / 180.0f)
@@ -42,4 +51,6 @@ inline fun fract(v: Float) = v % 1
inline fun sqr(v: Float) = v * v
inline fun sqr(v: Half) = v * v
inline fun pow(x: Float, y: Float) = (x.toDouble().pow(y.toDouble())).toFloat()

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.google.android.filament.textured
package com.google.android.filament.utils
import android.content.res.Resources
import android.graphics.Bitmap

View File

@@ -22,6 +22,8 @@ import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
import kotlin.math.sqrt
import kotlin.math.acos
import kotlin.math.absoluteValue
enum class VectorComponent {
X, Y, Z, W,
@@ -124,11 +126,23 @@ data class Float2(var x: Float = 0.0f, var y: Float = 0.0f) {
inline operator fun minus(v: Float) = Float2(x - v, y - v)
inline operator fun times(v: Float) = Float2(x * v, y * v)
inline operator fun div(v: Float) = Float2(x / v, y / v)
inline fun compareTo(v: Float, delta: Float = 0.0f) = Float2(
x.compareTo(v, delta),
y.compareTo(v, delta)
)
inline fun equals(v: Float, delta: Float = 0.0f) = x.equals(v, delta) && y.equals(v, delta)
inline operator fun plus(v: Float2) = Float2(x + v.x, y + v.y)
inline operator fun minus(v: Float2) = Float2(x - v.x, y - v.y)
inline operator fun times(v: Float2) = Float2(x * v.x, y * v.y)
inline operator fun div(v: Float2) = Float2(x / v.x, y / v.y)
inline fun compareTo(v: Float2, delta: Float = 0.0f) = Float2(
x.compareTo(v.x, delta),
y.compareTo(v.y, delta)
)
inline fun equals(v: Float2, delta: Float = 0.0f) = x.equals(v.x, delta) && y.equals(v.y, delta)
inline fun transform(block: (Float) -> Float): Float2 {
x = block(x)
@@ -291,6 +305,14 @@ data class Float3(var x: Float = 0.0f, var y: Float = 0.0f, var z: Float = 0.0f)
inline operator fun minus(v: Float) = Float3(x - v, y - v, z - v)
inline operator fun times(v: Float) = Float3(x * v, y * v, z * v)
inline operator fun div(v: Float) = Float3(x / v, y / v, z / v)
inline fun compareTo(v: Float, delta: Float = 0.0f) = Float3(
x.compareTo(v, delta),
y.compareTo(v, delta),
z.compareTo(v, delta)
)
inline fun equals(v: Float, delta: Float = 0.0f) =
x.equals(v, delta) && y.equals(v, delta) && z.equals(v, delta)
inline operator fun plus(v: Float2) = Float3(x + v.x, y + v.y, z)
inline operator fun minus(v: Float2) = Float3(x - v.x, y - v.y, z)
@@ -301,6 +323,14 @@ data class Float3(var x: Float = 0.0f, var y: Float = 0.0f, var z: Float = 0.0f)
inline operator fun minus(v: Float3) = Float3(x - v.x, y - v.y, z - v.z)
inline operator fun times(v: Float3) = Float3(x * v.x, y * v.y, z * v.z)
inline operator fun div(v: Float3) = Float3(x / v.x, y / v.y, z / v.z)
inline fun compareTo(v: Float3, delta: Float = 0.0f) = Float3(
x.compareTo(v.x, delta),
y.compareTo(v.y, delta),
z.compareTo(v.z, delta)
)
inline fun equals(v: Float3, delta: Float = 0.0f) =
x.equals(v.x, delta) && y.equals(v.y, delta) && z.equals(v.z, delta)
inline fun transform(block: (Float) -> Float): Float3 {
x = block(x)
@@ -534,6 +564,15 @@ data class Float4(
inline operator fun minus(v: Float) = Float4(x - v, y - v, z - v, w - v)
inline operator fun times(v: Float) = Float4(x * v, y * v, z * v, w * v)
inline operator fun div(v: Float) = Float4(x / v, y / v, z / v, w / v)
inline fun compareTo(v: Float, delta: Float = 0.0f) = Float4(
x.compareTo(v, delta),
y.compareTo(v, delta),
z.compareTo(v, delta),
w.compareTo(v, delta)
)
inline fun equals(v: Float, delta: Float = 0.0f) =
x.equals(v, delta) && y.equals(v, delta) && z.equals(v, delta) && w.equals(v, delta)
inline operator fun plus(v: Float2) = Float4(x + v.x, y + v.y, z, w)
inline operator fun minus(v: Float2) = Float4(x - v.x, y - v.y, z, w)
@@ -549,6 +588,15 @@ data class Float4(
inline operator fun minus(v: Float4) = Float4(x - v.x, y - v.y, z - v.z, w - v.w)
inline operator fun times(v: Float4) = Float4(x * v.x, y * v.y, z * v.z, w * v.w)
inline operator fun div(v: Float4) = Float4(x / v.x, y / v.y, z / v.z, w / v.w)
inline fun compareTo(v: Float4, delta: Float = 0.0f) = Float4(
x.compareTo(v.x, delta),
y.compareTo(v.y, delta),
z.compareTo(v.z, delta),
w.compareTo(v.w, delta)
)
inline fun equals(v: Float4, delta: Float = 0.0f) =
x.equals(v.x, delta) && y.equals(v.y, delta) && z.equals(v.z, delta) && w.equals(v.w, delta)
inline fun transform(block: (Float) -> Float): Float4 {
x = block(x)
@@ -566,6 +614,12 @@ inline operator fun Float.minus(v: Float2) = Float2(this - v.x, this - v.y)
inline operator fun Float.times(v: Float2) = Float2(this * v.x, this * v.y)
inline operator fun Float.div(v: Float2) = Float2(this / v.x, this / v.y)
inline fun Float.compareTo(v: Float, delta: Float): Float = when {
equals(v, delta) -> 0.0f
else -> compareTo(v).toFloat()
}
inline fun Float.equals(v: Float, delta: Float) = (this - v).absoluteValue < delta
inline fun abs(v: Float2) = Float2(abs(v.x), abs(v.y))
inline fun length(v: Float2) = sqrt(v.x * v.x + v.y * v.y)
inline fun length2(v: Float2) = v.x * v.x + v.y * v.y
@@ -583,6 +637,11 @@ fun refract(i: Float2, n: Float2, eta: Float): Float2 {
return if (k < 0.0f) Float2(0.0f) else eta * i - (eta * d + sqrt(k)) * n
}
inline fun angle(a: Float2, b: Float2): Float {
val l = length(a) * length(b)
return if (l == 0.0f) 0.0f else acos(clamp(dot(a, b) / l, -1.0f, 1.0f))
}
inline fun clamp(v: Float2, min: Float, max: Float): Float2 {
return Float2(
clamp(v.x, min, max),
@@ -626,10 +685,25 @@ inline fun greaterThan(a: Float2, b: Float) = Bool2(a.x > b, a.y > b)
inline fun greaterThan(a: Float2, b: Float2) = Bool2(a.x > b.y, a.y > b.y)
inline fun greaterThanEqual(a: Float2, b: Float) = Bool2(a.x >= b, a.y >= b)
inline fun greaterThanEqual(a: Float2, b: Float2) = Bool2(a.x >= b.x, a.y >= b.y)
inline fun equal(a: Float2, b: Float) = Bool2(a.x == b, a.y == b)
inline fun equal(a: Float2, b: Float2) = Bool2(a.x == b.x, a.y == b.y)
inline fun notEqual(a: Float2, b: Float) = Bool2(a.x != b, a.y != b)
inline fun notEqual(a: Float2, b: Float2) = Bool2(a.x != b.x, a.y != b.y)
inline fun equal(a: Float2, b: Float, delta: Float = 0.0f) = Bool2(
a.x.equals(b, delta),
a.y.equals(b, delta)
)
inline fun equal(a: Float2, b: Float2, delta: Float = 0.0f) = Bool2(
a.x.equals(b.x, delta),
a.y.equals(b.y, delta)
)
inline fun notEqual(a: Float2, b: Float, delta: Float = 0.0f) = Bool2(
!a.x.equals(b, delta),
!a.y.equals(b, delta)
)
inline fun notEqual(a: Float2, b: Float2, delta: Float = 0.0f) = Bool2(
!a.x.equals(b.x, delta),
!a.y.equals(b.y, delta)
)
inline infix fun Float2.lt(b: Float) = Bool2(x < b, y < b)
inline infix fun Float2.lt(b: Float2) = Bool2(x < b.x, y < b.y)
@@ -675,6 +749,11 @@ fun refract(i: Float3, n: Float3, eta: Float): Float3 {
return if (k < 0.0f) Float3(0.0f) else eta * i - (eta * d + sqrt(k)) * n
}
inline fun angle(a: Float3, b: Float3): Float {
val l = length(a) * length(b)
return if (l == 0.0f) 0.0f else acos(clamp(dot(a, b) / l, -1.0f, 1.0f))
}
inline fun clamp(v: Float3, min: Float, max: Float): Float3 {
return Float3(
clamp(v.x, min, max),
@@ -722,10 +801,29 @@ inline fun greaterThan(a: Float3, b: Float) = Bool3(a.x > b, a.y > b, a.z > b)
inline fun greaterThan(a: Float3, b: Float3) = Bool3(a.x > b.y, a.y > b.y, a.z > b.z)
inline fun greaterThanEqual(a: Float3, b: Float) = Bool3(a.x >= b, a.y >= b, a.z >= b)
inline fun greaterThanEqual(a: Float3, b: Float3) = Bool3(a.x >= b.x, a.y >= b.y, a.z >= b.z)
inline fun equal(a: Float3, b: Float) = Bool3(a.x == b, a.y == b, a.z == b)
inline fun equal(a: Float3, b: Float3) = Bool3(a.x == b.x, a.y == b.y, a.z == b.z)
inline fun notEqual(a: Float3, b: Float) = Bool3(a.x != b, a.y != b, a.z != b)
inline fun notEqual(a: Float3, b: Float3) = Bool3(a.x != b.x, a.y != b.y, a.z != b.z)
inline fun equal(a: Float3, b: Float, delta: Float = 0.0f) = Bool3(
a.x.equals(b, delta),
a.y.equals(b, delta),
a.z.equals(b, delta)
)
inline fun equal(a: Float3, b: Float3, delta: Float = 0.0f) = Bool3(
a.x.equals(b.x, delta),
a.y.equals(b.y, delta),
a.z.equals(b.z, delta)
)
inline fun notEqual(a: Float3, b: Float, delta: Float = 0.0f) = Bool3(
!a.x.equals(b, delta),
!a.y.equals(b, delta),
!a.z.equals(b, delta)
)
inline fun notEqual(a: Float3, b: Float3, delta: Float = 0.0f) = Bool3(
!a.x.equals(b.x, delta),
!a.y.equals(b.y, delta),
!a.z.equals(b.z, delta)
)
inline infix fun Float3.lt(b: Float) = Bool3(x < b, y < b, z < b)
inline infix fun Float3.lt(b: Float3) = Bool3(x < b.x, y < b.y, z < b.z)
@@ -807,17 +905,44 @@ inline fun transform(v: Float4, block: (Float) -> Float) = v.copy().transform(bl
inline fun lessThan(a: Float4, b: Float) = Bool4(a.x < b, a.y < b, a.z < b, a.w < b)
inline fun lessThan(a: Float4, b: Float4) = Bool4(a.x < b.x, a.y < b.y, a.z < b.z, a.w < b.w)
inline fun lessThanEqual(a: Float4, b: Float) = Bool4(a.x <= b, a.y <= b, a.z <= b, a.w <= b)
inline fun lessThanEqual(a: Float4, b: Float4) = Bool4(a.x <= b.x, a.y <= b.y, a.z <= b.z, a.w <= b.w)
inline fun lessThanEqual(a: Float4, b: Float4) =
Bool4(a.x <= b.x, a.y <= b.y, a.z <= b.z, a.w <= b.w)
inline fun greaterThan(a: Float4, b: Float) = Bool4(a.x > b, a.y > b, a.z > b, a.w > b)
inline fun greaterThan(a: Float4, b: Float4) = Bool4(a.x > b.y, a.y > b.y, a.z > b.z, a.w > b.w)
inline fun greaterThanEqual(a: Float4, b: Float) = Bool4(a.x >= b, a.y >= b, a.z >= b, a.w >= b)
inline fun greaterThanEqual(a: Float4, b: Float4) = Bool4(a.x >= b.x, a.y >= b.y, a.z >= b.z, a.w >= b.w)
inline fun equal(a: Float4, b: Float) = Bool4(a.x == b, a.y == b, a.z == b, a.w == b)
inline fun equal(a: Float4, b: Float4) = Bool4(a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w)
inline fun notEqual(a: Float4, b: Float) = Bool4(a.x != b, a.y != b, a.z != b, a.w != b)
inline fun notEqual(a: Float4, b: Float4) = Bool4(a.x != b.x, a.y != b.y, a.z != b.z, a.w != b.w)
inline fun greaterThanEqual(a: Float4, b: Float4) =
Bool4(a.x >= b.x, a.y >= b.y, a.z >= b.z, a.w >= b.w)
inline infix fun Float4.lt(b: Float) = Bool4(x < b, y < b, z < b, a < b)
inline fun equal(a: Float4, b: Float, delta: Float = 0.0f) = Bool4(
a.x.equals(b, delta),
a.y.equals(b, delta),
a.z.equals(b, delta),
a.w.equals(b, delta)
)
inline fun equal(a: Float4, b: Float4, delta: Float = 0.0f) = Bool4(
a.x.equals(b.x, delta),
a.y.equals(b.y, delta),
a.z.equals(b.z, delta),
a.w.equals(b.w, delta)
)
inline fun notEqual(a: Float4, b: Float, delta: Float = 0.0f) = Bool4(
!a.x.equals(b, delta),
!a.y.equals(b, delta),
!a.z.equals(b, delta),
!a.w.equals(b, delta)
)
inline fun notEqual(a: Float4, b: Float4, delta: Float = 0.0f) = Bool4(
!a.x.equals(b.x, delta),
!a.y.equals(b.y, delta),
!a.z.equals(b.z, delta),
!a.w.equals(b.w, delta)
)
inline infix fun Float4.lt(b: Float) = Bool4(x < b, y < b, z < b, w < b)
inline infix fun Float4.lt(b: Float4) = Bool4(x < b.x, y < b.y, z < b.z, w < b.w)
inline infix fun Float4.lte(b: Float) = Bool4(x <= b, y <= b, z <= b, w <= b)
inline infix fun Float4.lte(b: Float4) = Bool4(x <= b.x, y <= b.y, z <= b.z, w <= b.w)
@@ -1277,3 +1402,753 @@ data class Bool4(
set(index4, v)
}
}
data class Half2(var x: Half = Half.POSITIVE_ZERO, var y: Half = Half.POSITIVE_ZERO) {
constructor(v: Half) : this(v, v)
constructor(v: Half2) : this(v.x, v.y)
inline var r: Half
get() = x
set(value) {
x = value
}
inline var g: Half
get() = y
set(value) {
y = value
}
inline var s: Half
get() = x
set(value) {
x = value
}
inline var t: Half
get() = y
set(value) {
y = value
}
inline var xy: Half2
get() = Half2(x, y)
set(value) {
x = value.x
y = value.y
}
inline var rg: Half2
get() = Half2(x, y)
set(value) {
x = value.x
y = value.y
}
inline var st: Half2
get() = Half2(x, y)
set(value) {
x = value.x
y = value.y
}
operator fun get(index: VectorComponent) = when (index) {
VectorComponent.X, VectorComponent.R, VectorComponent.S -> x
VectorComponent.Y, VectorComponent.G, VectorComponent.T -> y
else -> throw IllegalArgumentException("index must be X, Y, R, G, S or T")
}
operator fun get(index1: VectorComponent, index2: VectorComponent): Half2 {
return Half2(get(index1), get(index2))
}
operator fun get(index: Int) = when (index) {
0 -> x
1 -> y
else -> throw IllegalArgumentException("index must be in 0..1")
}
operator fun get(index1: Int, index2: Int) = Half2(get(index1), get(index2))
inline operator fun invoke(index: Int) = get(index - 1)
operator fun set(index: Int, v: Half) = when (index) {
0 -> x = v
1 -> y = v
else -> throw IllegalArgumentException("index must be in 0..1")
}
operator fun set(index1: Int, index2: Int, v: Half) {
set(index1, v)
set(index2, v)
}
operator fun set(index: VectorComponent, v: Half) = when (index) {
VectorComponent.X, VectorComponent.R, VectorComponent.S -> x = v
VectorComponent.Y, VectorComponent.G, VectorComponent.T -> y = v
else -> throw IllegalArgumentException("index must be X, Y, R, G, S or T")
}
operator fun set(index1: VectorComponent, index2: VectorComponent, v: Half) {
set(index1, v)
set(index2, v)
}
operator fun unaryMinus() = Half2(-x, -y)
operator fun inc() = Half2(x++, y++)
operator fun dec() = Half2(x--, y--)
inline operator fun plus(v: Half) = Half2(x + v, y + v)
inline operator fun minus(v: Half) = Half2(x - v, y - v)
inline operator fun times(v: Half) = Half2(x * v, y * v)
inline operator fun div(v: Half) = Half2(x / v, y / v)
inline operator fun plus(v: Half2) = Half2(x + v.x, y + v.y)
inline operator fun minus(v: Half2) = Half2(x - v.x, y - v.y)
inline operator fun times(v: Half2) = Half2(x * v.x, y * v.y)
inline operator fun div(v: Half2) = Half2(x / v.x, y / v.y)
inline fun transform(block: (Half) -> Half): Half2 {
x = block(x)
y = block(y)
return this
}
fun toFloatArray() = floatArrayOf(x.toFloat(), y.toFloat())
}
data class Half3(
var x: Half = Half.POSITIVE_ZERO,
var y: Half = Half.POSITIVE_ZERO,
var z: Half = Half.POSITIVE_ZERO
) {
constructor(v: Half) : this(v, v, v)
constructor(v: Half2, z: Half = Half.POSITIVE_ZERO) : this(v.x, v.y, z)
constructor(v: Half3) : this(v.x, v.y, v.z)
inline var r: Half
get() = x
set(value) {
x = value
}
inline var g: Half
get() = y
set(value) {
y = value
}
inline var b: Half
get() = z
set(value) {
z = value
}
inline var s: Half
get() = x
set(value) {
x = value
}
inline var t: Half
get() = y
set(value) {
y = value
}
inline var p: Half
get() = z
set(value) {
z = value
}
inline var xy: Half2
get() = Half2(x, y)
set(value) {
x = value.x
y = value.y
}
inline var rg: Half2
get() = Half2(x, y)
set(value) {
x = value.x
y = value.y
}
inline var st: Half2
get() = Half2(x, y)
set(value) {
x = value.x
y = value.y
}
inline var rgb: Half3
get() = Half3(x, y, z)
set(value) {
x = value.x
y = value.y
z = value.z
}
inline var xyz: Half3
get() = Half3(x, y, z)
set(value) {
x = value.x
y = value.y
z = value.z
}
inline var stp: Half3
get() = Half3(x, y, z)
set(value) {
x = value.x
y = value.y
z = value.z
}
operator fun get(index: VectorComponent) = when (index) {
VectorComponent.X, VectorComponent.R, VectorComponent.S -> x
VectorComponent.Y, VectorComponent.G, VectorComponent.T -> y
VectorComponent.Z, VectorComponent.B, VectorComponent.P -> z
else -> throw IllegalArgumentException("index must be X, Y, Z, R, G, B, S, T or P")
}
operator fun get(index1: VectorComponent, index2: VectorComponent): Half2 {
return Half2(get(index1), get(index2))
}
operator fun get(
index1: VectorComponent, index2: VectorComponent, index3: VectorComponent): Half3 {
return Half3(get(index1), get(index2), get(index3))
}
operator fun get(index: Int) = when (index) {
0 -> x
1 -> y
2 -> z
else -> throw IllegalArgumentException("index must be in 0..2")
}
operator fun get(index1: Int, index2: Int) = Half2(get(index1), get(index2))
operator fun get(index1: Int, index2: Int, index3: Int): Half3 {
return Half3(get(index1), get(index2), get(index3))
}
inline operator fun invoke(index: Int) = get(index - 1)
operator fun set(index: Int, v: Half) = when (index) {
0 -> x = v
1 -> y = v
2 -> z = v
else -> throw IllegalArgumentException("index must be in 0..2")
}
operator fun set(index1: Int, index2: Int, v: Half) {
set(index1, v)
set(index2, v)
}
operator fun set(index1: Int, index2: Int, index3: Int, v: Half) {
set(index1, v)
set(index2, v)
set(index3, v)
}
operator fun set(index: VectorComponent, v: Half) = when (index) {
VectorComponent.X, VectorComponent.R, VectorComponent.S -> x = v
VectorComponent.Y, VectorComponent.G, VectorComponent.T -> y = v
VectorComponent.Z, VectorComponent.B, VectorComponent.P -> z = v
else -> throw IllegalArgumentException("index must be X, Y, Z, R, G, B, S, T or P")
}
operator fun set(index1: VectorComponent, index2: VectorComponent, v: Half) {
set(index1, v)
set(index2, v)
}
operator fun set(
index1: VectorComponent, index2: VectorComponent, index3: VectorComponent, v: Half) {
set(index1, v)
set(index2, v)
set(index3, v)
}
operator fun unaryMinus() = Half3(-x, -y, -z)
operator fun inc() = Half3(x++, y++, z++)
operator fun dec() = Half3(x--, y--, z--)
inline operator fun plus(v: Half) = Half3(x + v, y + v, z + v)
inline operator fun minus(v: Half) = Half3(x - v, y - v, z - v)
inline operator fun times(v: Half) = Half3(x * v, y * v, z * v)
inline operator fun div(v: Half) = Half3(x / v, y / v, z / v)
inline operator fun plus(v: Half2) = Half3(x + v.x, y + v.y, z)
inline operator fun minus(v: Half2) = Half3(x - v.x, y - v.y, z)
inline operator fun times(v: Half2) = Half3(x * v.x, y * v.y, z)
inline operator fun div(v: Half2) = Half3(x / v.x, y / v.y, z)
inline operator fun plus(v: Half3) = Half3(x + v.x, y + v.y, z + v.z)
inline operator fun minus(v: Half3) = Half3(x - v.x, y - v.y, z - v.z)
inline operator fun times(v: Half3) = Half3(x * v.x, y * v.y, z * v.z)
inline operator fun div(v: Half3) = Half3(x / v.x, y / v.y, z / v.z)
inline fun transform(block: (Half) -> Half): Half3 {
x = block(x)
y = block(y)
z = block(z)
return this
}
fun toFloatArray() = floatArrayOf(x.toFloat(), y.toFloat(), z.toFloat())
}
data class Half4(
var x: Half = Half.POSITIVE_ZERO,
var y: Half = Half.POSITIVE_ZERO,
var z: Half = Half.POSITIVE_ZERO,
var w: Half = Half.POSITIVE_ZERO
) {
constructor(v: Half) : this(v, v, v, v)
constructor(v: Half2, z: Half = Half.POSITIVE_ZERO, w: Half = Half.POSITIVE_ZERO) : this(v.x, v.y, z, w)
constructor(v: Half3, w: Half = Half.POSITIVE_ZERO) : this(v.x, v.y, v.z, w)
constructor(v: Half4) : this(v.x, v.y, v.z, v.w)
inline var r: Half
get() = x
set(value) {
x = value
}
inline var g: Half
get() = y
set(value) {
y = value
}
inline var b: Half
get() = z
set(value) {
z = value
}
inline var a: Half
get() = w
set(value) {
w = value
}
inline var s: Half
get() = x
set(value) {
x = value
}
inline var t: Half
get() = y
set(value) {
y = value
}
inline var p: Half
get() = z
set(value) {
z = value
}
inline var q: Half
get() = w
set(value) {
w = value
}
inline var xy: Half2
get() = Half2(x, y)
set(value) {
x = value.x
y = value.y
}
inline var rg: Half2
get() = Half2(x, y)
set(value) {
x = value.x
y = value.y
}
inline var st: Half2
get() = Half2(x, y)
set(value) {
x = value.x
y = value.y
}
inline var rgb: Half3
get() = Half3(x, y, z)
set(value) {
x = value.x
y = value.y
z = value.z
}
inline var xyz: Half3
get() = Half3(x, y, z)
set(value) {
x = value.x
y = value.y
z = value.z
}
inline var stp: Half3
get() = Half3(x, y, z)
set(value) {
x = value.x
y = value.y
z = value.z
}
inline var rgba: Half4
get() = Half4(x, y, z, w)
set(value) {
x = value.x
y = value.y
z = value.z
w = value.w
}
inline var xyzw: Half4
get() = Half4(x, y, z, w)
set(value) {
x = value.x
y = value.y
z = value.z
w = value.w
}
inline var stpq: Half4
get() = Half4(x, y, z, w)
set(value) {
x = value.x
y = value.y
z = value.z
w = value.w
}
operator fun get(index: VectorComponent) = when (index) {
VectorComponent.X, VectorComponent.R, VectorComponent.S -> x
VectorComponent.Y, VectorComponent.G, VectorComponent.T -> y
VectorComponent.Z, VectorComponent.B, VectorComponent.P -> z
VectorComponent.W, VectorComponent.A, VectorComponent.Q -> w
}
operator fun get(index1: VectorComponent, index2: VectorComponent): Half2 {
return Half2(get(index1), get(index2))
}
operator fun get(
index1: VectorComponent,
index2: VectorComponent,
index3: VectorComponent): Half3 {
return Half3(get(index1), get(index2), get(index3))
}
operator fun get(
index1: VectorComponent,
index2: VectorComponent,
index3: VectorComponent,
index4: VectorComponent): Half4 {
return Half4(get(index1), get(index2), get(index3), get(index4))
}
operator fun get(index: Int) = when (index) {
0 -> x
1 -> y
2 -> z
3 -> w
else -> throw IllegalArgumentException("index must be in 0..3")
}
operator fun get(index1: Int, index2: Int) = Half2(get(index1), get(index2))
operator fun get(index1: Int, index2: Int, index3: Int): Half3 {
return Half3(get(index1), get(index2), get(index3))
}
operator fun get(index1: Int, index2: Int, index3: Int, index4: Int): Half4 {
return Half4(get(index1), get(index2), get(index3), get(index4))
}
inline operator fun invoke(index: Int) = get(index - 1)
operator fun set(index: Int, v: Half) = when (index) {
0 -> x = v
1 -> y = v
2 -> z = v
3 -> w = v
else -> throw IllegalArgumentException("index must be in 0..3")
}
operator fun set(index1: Int, index2: Int, v: Half) {
set(index1, v)
set(index2, v)
}
operator fun set(index1: Int, index2: Int, index3: Int, v: Half) {
set(index1, v)
set(index2, v)
set(index3, v)
}
operator fun set(index1: Int, index2: Int, index3: Int, index4: Int, v: Half) {
set(index1, v)
set(index2, v)
set(index3, v)
set(index4, v)
}
operator fun set(index: VectorComponent, v: Half) = when (index) {
VectorComponent.X, VectorComponent.R, VectorComponent.S -> x = v
VectorComponent.Y, VectorComponent.G, VectorComponent.T -> y = v
VectorComponent.Z, VectorComponent.B, VectorComponent.P -> z = v
VectorComponent.W, VectorComponent.A, VectorComponent.Q -> w = v
}
operator fun set(index1: VectorComponent, index2: VectorComponent, v: Half) {
set(index1, v)
set(index2, v)
}
operator fun set(
index1: VectorComponent, index2: VectorComponent, index3: VectorComponent, v: Half) {
set(index1, v)
set(index2, v)
set(index3, v)
}
operator fun set(
index1: VectorComponent, index2: VectorComponent,
index3: VectorComponent, index4: VectorComponent, v: Half) {
set(index1, v)
set(index2, v)
set(index3, v)
set(index4, v)
}
operator fun unaryMinus() = Half4(-x, -y, -z, -w)
operator fun inc() = Half4(x++, y++, z++, w++)
operator fun dec() = Half4(x--, y--, z--, w--)
inline operator fun plus(v: Half) = Half4(x + v, y + v, z + v, w + v)
inline operator fun minus(v: Half) = Half4(x - v, y - v, z - v, w - v)
inline operator fun times(v: Half) = Half4(x * v, y * v, z * v, w * v)
inline operator fun div(v: Half) = Half4(x / v, y / v, z / v, w / v)
inline operator fun plus(v: Half2) = Half4(x + v.x, y + v.y, z, w)
inline operator fun minus(v: Half2) = Half4(x - v.x, y - v.y, z, w)
inline operator fun times(v: Half2) = Half4(x * v.x, y * v.y, z, w)
inline operator fun div(v: Half2) = Half4(x / v.x, y / v.y, z, w)
inline operator fun plus(v: Half3) = Half4(x + v.x, y + v.y, z + v.z, w)
inline operator fun minus(v: Half3) = Half4(x - v.x, y - v.y, z - v.z, w)
inline operator fun times(v: Half3) = Half4(x * v.x, y * v.y, z * v.z, w)
inline operator fun div(v: Half3) = Half4(x / v.x, y / v.y, z / v.z, w)
inline operator fun plus(v: Half4) = Half4(x + v.x, y + v.y, z + v.z, w + v.w)
inline operator fun minus(v: Half4) = Half4(x - v.x, y - v.y, z - v.z, w - v.w)
inline operator fun times(v: Half4) = Half4(x * v.x, y * v.y, z * v.z, w * v.w)
inline operator fun div(v: Half4) = Half4(x / v.x, y / v.y, z / v.z, w / v.w)
inline fun transform(block: (Half) -> Half): Half4 {
x = block(x)
y = block(y)
z = block(z)
w = block(w)
return this
}
fun toFloatArray() = floatArrayOf(x.toFloat(), y.toFloat(), z.toFloat(), w.toFloat())
}
inline fun min(v: Half2) = min(v.x, v.y)
inline fun min(a: Half2, b: Half2) = Half2(min(a.x, b.x), min(a.y, b.y))
inline fun max(v: Half2) = max(v.x, v.y)
inline fun max(a: Half2, b: Half2) = Half2(max(a.x, b.x), max(a.y, b.y))
inline fun transform(v: Half2, block: (Half) -> Half) = v.copy().transform(block)
inline fun lessThan(a: Half2, b: Half) = Bool2(a.x < b, a.y < b)
inline fun lessThan(a: Half2, b: Half2) = Bool2(a.x < b.x, a.y < b.y)
inline fun lessThanEqual(a: Half2, b: Half) = Bool2(a.x <= b, a.y <= b)
inline fun lessThanEqual(a: Half2, b: Half2) = Bool2(a.x <= b.x, a.y <= b.y)
inline fun greaterThan(a: Half2, b: Half) = Bool2(a.x > b, a.y > b)
inline fun greaterThan(a: Half2, b: Half2) = Bool2(a.x > b.y, a.y > b.y)
inline fun greaterThanEqual(a: Half2, b: Half) = Bool2(a.x >= b, a.y >= b)
inline fun greaterThanEqual(a: Half2, b: Half2) = Bool2(a.x >= b.x, a.y >= b.y)
inline fun equal(a: Half2, b: Half) = Bool2(a.x == b, a.y == b)
inline fun equal(a: Half2, b: Half2) = Bool2(a.x == b.x, a.y == b.y)
inline fun notEqual(a: Half2, b: Half) = Bool2(a.x != b, a.y != b)
inline fun notEqual(a: Half2, b: Half2) = Bool2(a.x != b.x, a.y != b.y)
inline infix fun Half2.lt(b: Half) = Bool2(x < b, y < b)
inline infix fun Half2.lt(b: Half2) = Bool2(x < b.x, y < b.y)
inline infix fun Half2.lte(b: Half) = Bool2(x <= b, y <= b)
inline infix fun Half2.lte(b: Half2) = Bool2(x <= b.x, y <= b.y)
inline infix fun Half2.gt(b: Half) = Bool2(x > b, y > b)
inline infix fun Half2.gt(b: Half2) = Bool2(x > b.x, y > b.y)
inline infix fun Half2.gte(b: Half) = Bool2(x >= b, y >= b)
inline infix fun Half2.gte(b: Half2) = Bool2(x >= b.x, y >= b.y)
inline infix fun Half2.eq(b: Half) = Bool2(x == b, y == b)
inline infix fun Half2.eq(b: Half2) = Bool2(x == b.x, y == b.y)
inline infix fun Half2.neq(b: Half) = Bool2(x != b, y != b)
inline infix fun Half2.neq(b: Half2) = Bool2(x != b.x, y != b.y)
inline operator fun Half.plus(v: Half3) = Half3(this + v.x, this + v.y, this + v.z)
inline operator fun Half.minus(v: Half3) = Half3(this - v.x, this - v.y, this - v.z)
inline operator fun Half.times(v: Half3) = Half3(this * v.x, this * v.y, this * v.z)
inline operator fun Half.div(v: Half3) = Half3(this / v.x, this / v.y, this / v.z)
inline fun abs(v: Half3) = Half3(abs(v.x), abs(v.y), abs(v.z))
inline fun length(v: Half3) = sqrt(v.x * v.x + v.y * v.y + v.z * v.z)
inline fun length2(v: Half3) = v.x * v.x + v.y * v.y + v.z * v.z
inline fun distance(a: Half3, b: Half3) = length(a - b)
inline fun dot(a: Half3, b: Half3) = a.x * b.x + a.y * b.y + a.z * b.z
inline fun cross(a: Half3, b: Half3): Half3 {
return Half3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x)
}
inline infix fun Half3.x(v: Half3): Half3 {
return Half3(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x)
}
fun normalize(v: Half3): Half3 {
val l = HALF_ONE / length(v)
return Half3(v.x * l, v.y * l, v.z * l)
}
inline fun reflect(i: Half3, n: Half3) = i - HALF_TWO * dot(n, i) * n
fun refract(i: Half3, n: Half3, eta: Half): Half3 {
val d = dot(n, i)
val k = HALF_ONE - eta * eta * (HALF_ONE - sqr(d))
return if (k < Half.POSITIVE_ZERO) Half3() else eta * i - (eta * d + sqrt(k)) * n
}
inline fun clamp(v: Half3, min: Half, max: Half): Half3 {
return Half3(
clamp(v.x, min, max),
clamp(v.y, min, max),
clamp(v.z, min, max)
)
}
inline fun clamp(v: Half3, min: Half3, max: Half3): Half3 {
return Half3(
clamp(v.x, min.x, max.x),
clamp(v.y, min.y, max.y),
clamp(v.z, min.z, max.z)
)
}
inline fun mix(a: Half3, b: Half3, x: Half): Half3 {
return Half3(
mix(a.x, b.x, x),
mix(a.y, b.y, x),
mix(a.z, b.z, x)
)
}
inline fun mix(a: Half3, b: Half3, x: Half3): Half3 {
return Half3(
mix(a.x, b.x, x.x),
mix(a.y, b.y, x.y),
mix(a.z, b.z, x.z)
)
}
inline fun min(v: Half3) = min(v.x, min(v.y, v.z))
inline fun min(a: Half3, b: Half3) = Half3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z))
inline fun max(v: Half3) = max(v.x, max(v.y, v.z))
inline fun max(a: Half3, b: Half3) = Half3(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z))
inline fun transform(v: Half3, block: (Half) -> Half) = v.copy().transform(block)
inline fun lessThan(a: Half3, b: Half) = Bool3(a.x < b, a.y < b, a.z < b)
inline fun lessThan(a: Half3, b: Half3) = Bool3(a.x < b.x, a.y < b.y, a.z < b.z)
inline fun lessThanEqual(a: Half3, b: Half) = Bool3(a.x <= b, a.y <= b, a.z <= b)
inline fun lessThanEqual(a: Half3, b: Half3) = Bool3(a.x <= b.x, a.y <= b.y, a.z <= b.z)
inline fun greaterThan(a: Half3, b: Half) = Bool3(a.x > b, a.y > b, a.z > b)
inline fun greaterThan(a: Half3, b: Half3) = Bool3(a.x > b.y, a.y > b.y, a.z > b.z)
inline fun greaterThanEqual(a: Half3, b: Half) = Bool3(a.x >= b, a.y >= b, a.z >= b)
inline fun greaterThanEqual(a: Half3, b: Half3) = Bool3(a.x >= b.x, a.y >= b.y, a.z >= b.z)
inline fun equal(a: Half3, b: Half) = Bool3(a.x == b, a.y == b, a.z == b)
inline fun equal(a: Half3, b: Half3) = Bool3(a.x == b.x, a.y == b.y, a.z == b.z)
inline fun notEqual(a: Half3, b: Half) = Bool3(a.x != b, a.y != b, a.z != b)
inline fun notEqual(a: Half3, b: Half3) = Bool3(a.x != b.x, a.y != b.y, a.z != b.z)
inline infix fun Half3.lt(b: Half) = Bool3(x < b, y < b, z < b)
inline infix fun Half3.lt(b: Half3) = Bool3(x < b.x, y < b.y, z < b.z)
inline infix fun Half3.lte(b: Half) = Bool3(x <= b, y <= b, z <= b)
inline infix fun Half3.lte(b: Half3) = Bool3(x <= b.x, y <= b.y, z <= b.z)
inline infix fun Half3.gt(b: Half) = Bool3(x > b, y > b, z > b)
inline infix fun Half3.gt(b: Half3) = Bool3(x > b.x, y > b.y, z > b.z)
inline infix fun Half3.gte(b: Half) = Bool3(x >= b, y >= b, z >= b)
inline infix fun Half3.gte(b: Half3) = Bool3(x >= b.x, y >= b.y, z >= b.z)
inline infix fun Half3.eq(b: Half) = Bool3(x == b, y == b, z == b)
inline infix fun Half3.eq(b: Half3) = Bool3(x == b.x, y == b.y, z == b.z)
inline infix fun Half3.neq(b: Half) = Bool3(x != b, y != b, z != b)
inline infix fun Half3.neq(b: Half3) = Bool3(x != b.x, y != b.y, z != b.z)
inline operator fun Half.plus(v: Half4) = Half4(this + v.x, this + v.y, this + v.z, this + v.w)
inline operator fun Half.minus(v: Half4) = Half4(this - v.x, this - v.y, this - v.z, this - v.w)
inline operator fun Half.times(v: Half4) = Half4(this * v.x, this * v.y, this * v.z, this * v.w)
inline operator fun Half.div(v: Half4) = Half4(this / v.x, this / v.y, this / v.z, this / v.w)
inline fun abs(v: Half4) = Half4(abs(v.x), abs(v.y), abs(v.z), abs(v.w))
inline fun length(v: Half4) = sqrt(v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w)
inline fun length2(v: Half4) = v.x * v.x + v.y * v.y + v.z * v.z + v.w * v.w
inline fun distance(a: Half4, b: Half4) = length(a - b)
inline fun dot(a: Half4, b: Half4) = a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w
fun normalize(v: Half4): Half4 {
val l = HALF_ONE / length(v)
return Half4(v.x * l, v.y * l, v.z * l, v.w * l)
}
inline fun clamp(v: Half4, min: Half, max: Half): Half4 {
return Half4(
clamp(v.x, min, max),
clamp(v.y, min, max),
clamp(v.z, min, max),
clamp(v.w, min, max)
)
}
inline fun clamp(v: Half4, min: Half4, max: Half4): Half4 {
return Half4(
clamp(v.x, min.x, max.x),
clamp(v.y, min.y, max.y),
clamp(v.z, min.z, max.z),
clamp(v.w, min.z, max.w)
)
}
inline fun mix(a: Half4, b: Half4, x: Half): Half4 {
return Half4(
mix(a.x, b.x, x),
mix(a.y, b.y, x),
mix(a.z, b.z, x),
mix(a.w, b.w, x)
)
}
inline fun mix(a: Half4, b: Half4, x: Half4): Half4 {
return Half4(
mix(a.x, b.x, x.x),
mix(a.y, b.y, x.y),
mix(a.z, b.z, x.z),
mix(a.w, b.w, x.w))
}
inline fun min(v: Half4) = min(v.x, min(v.y, min(v.z, v.w)))
inline fun min(a: Half4, b: Half4): Half4 {
return Half4(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z), min(a.w, b.w))
}
inline fun max(v: Half4) = max(v.x, max(v.y, max(v.z, v.w)))
inline fun max(a: Half4, b: Half4): Half4 {
return Half4(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z), max(a.w, b.w))
}
inline fun transform(v: Half4, block: (Half) -> Half) = v.copy().transform(block)
inline fun lessThan(a: Half4, b: Half) = Bool4(a.x < b, a.y < b, a.z < b, a.w < b)
inline fun lessThan(a: Half4, b: Half4) = Bool4(a.x < b.x, a.y < b.y, a.z < b.z, a.w < b.w)
inline fun lessThanEqual(a: Half4, b: Half) = Bool4(a.x <= b, a.y <= b, a.z <= b, a.w <= b)
inline fun lessThanEqual(a: Half4, b: Half4) = Bool4(a.x <= b.x, a.y <= b.y, a.z <= b.z, a.w <= b.w)
inline fun greaterThan(a: Half4, b: Half) = Bool4(a.x > b, a.y > b, a.z > b, a.w > b)
inline fun greaterThan(a: Half4, b: Half4) = Bool4(a.x > b.y, a.y > b.y, a.z > b.z, a.w > b.w)
inline fun greaterThanEqual(a: Half4, b: Half) = Bool4(a.x >= b, a.y >= b, a.z >= b, a.w >= b)
inline fun greaterThanEqual(a: Half4, b: Half4) = Bool4(a.x >= b.x, a.y >= b.y, a.z >= b.z, a.w >= b.w)
inline fun equal(a: Half4, b: Half) = Bool4(a.x == b, a.y == b, a.z == b, a.w == b)
inline fun equal(a: Half4, b: Half4) = Bool4(a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w)
inline fun notEqual(a: Half4, b: Half) = Bool4(a.x != b, a.y != b, a.z != b, a.w != b)
inline fun notEqual(a: Half4, b: Half4) = Bool4(a.x != b.x, a.y != b.y, a.z != b.z, a.w != b.w)
inline infix fun Half4.lt(b: Half) = Bool4(x < b, y < b, z < b, a < b)
inline infix fun Half4.lt(b: Half4) = Bool4(x < b.x, y < b.y, z < b.z, w < b.w)
inline infix fun Half4.lte(b: Half) = Bool4(x <= b, y <= b, z <= b, w <= b)
inline infix fun Half4.lte(b: Half4) = Bool4(x <= b.x, y <= b.y, z <= b.z, w <= b.w)
inline infix fun Half4.gt(b: Half) = Bool4(x > b, y > b, z > b, w > b)
inline infix fun Half4.gt(b: Half4) = Bool4(x > b.x, y > b.y, z > b.z, w > b.w)
inline infix fun Half4.gte(b: Half) = Bool4(x >= b, y >= b, z >= b, w >= b)
inline infix fun Half4.gte(b: Half4) = Bool4(x >= b.x, y >= b.y, z >= b.z, w >= b.w)
inline infix fun Half4.eq(b: Half) = Bool4(x == b, y == b, z == b, w == b)
inline infix fun Half4.eq(b: Half4) = Bool4(x == b.x, y == b.y, z == b.z, w == b.w)
inline infix fun Half4.neq(b: Half) = Bool4(x != b, y != b, z != b, w != b)
inline infix fun Half4.neq(b: Half4) = Bool4(x != b.x, y != b.y, z != b.z, w != b.w)

View File

@@ -11,6 +11,10 @@ add_library(dracodec STATIC IMPORTED)
set_target_properties(dracodec PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libdracodec.a)
add_library(meshoptimizer STATIC IMPORTED)
set_target_properties(meshoptimizer PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libmeshoptimizer.a)
add_library(ktxreader STATIC IMPORTED)
set_target_properties(ktxreader PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libktxreader.a)
@@ -76,7 +80,7 @@ set(GLTFIO_SRCS
${GLTFIO_DIR}/src/UbershaderProvider.cpp
${GLTFIO_DIR}/src/Wireframe.cpp
${GLTFIO_DIR}/src/Wireframe.h
${GLTFIO_DIR}/src/upcast.h
${GLTFIO_DIR}/src/downcast.h
src/main/cpp/Animator.cpp
src/main/cpp/AssetLoader.cpp
@@ -99,6 +103,7 @@ set(GLTFIO_INCLUDE_DIRS
../../libs/gltfio/include
../../third_party/basisu/zstd
../../third_party/cgltf
../../third_party/meshoptimizer/src
../../third_party/robin-map
../../third_party/hat-trie
../../third_party/stb
@@ -111,7 +116,7 @@ target_include_directories(gltfio-jni PRIVATE ${GLTFIO_INCLUDE_DIRS})
set_target_properties(gltfio-jni PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libgltfio-jni.symbols)
set_target_properties(gltfio-jni PROPERTIES LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libgltfio-jni.map)
target_link_libraries(gltfio-jni filament-jni utils uberzlib log stb ktxreader basis_transcoder zstd uberarchive)
target_link_libraries(gltfio-jni dracodec)
target_link_libraries(gltfio-jni dracodec meshoptimizer)
target_compile_definitions(gltfio-jni PUBLIC GLTFIO_DRACO_SUPPORTED=1)
target_include_directories(gltfio-jni PRIVATE ${DRACO_DIR}/src)
target_include_directories(gltfio-jni PRIVATE ${DRACO_DIR}/tnt)

View File

@@ -16,6 +16,13 @@ android {
excludes += ['lib/*/libfilament-jni.so']
}
}
publishing {
singleVariant("fullRelease") {
withSourcesJar()
withJavadocJar()
}
}
}
dependencies {

View File

@@ -14,5 +14,4 @@
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.filament.gltfio" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />

View File

@@ -42,6 +42,7 @@ class JavaMaterialProvider : public MaterialProvider {
jmethodID mMaterialKeyConstructor;
jmethodID mCreateMaterialInstance;
jmethodID mGetMaterial;
jmethodID mGetMaterials;
jmethodID mNeedsDummyData;
jmethodID mDestroyMaterials;
@@ -72,6 +73,10 @@ public:
"(L" JAVA_MATERIAL_KEY ";[ILjava/lang/String;Ljava/lang/String;)Lcom/google/android/filament/MaterialInstance;");
assert_invariant(mCreateMaterialInstance);
mGetMaterial = env->GetMethodID(providerClass, "getMaterial",
"(L" JAVA_MATERIAL_KEY ";[ILjava/lang/String;)Lcom/google/android/filament/Material;");
assert_invariant(mGetMaterial);
mGetMaterials = env->GetMethodID(providerClass, "getMaterials",
"()[Lcom/google/android/filament/Material;");
assert_invariant(mGetMaterials);
@@ -103,7 +108,7 @@ public:
jstring stringExtras = extras ? mEnv->NewStringUTF(extras) : nullptr;
// Allocate space for the output argument.
jintArray uvMapArray = mEnv->NewIntArray(8);
jintArray uvMapArray = mEnv->NewIntArray(uvmap->size());
// Call the Java-based material provider.
jobject materialInstance = mEnv->CallObjectMethod(mJavaProvider, mCreateMaterialInstance,
@@ -139,6 +144,49 @@ public:
return (MaterialInstance*) mEnv->CallLongMethod(materialInstance, mMaterialInstanceGetNativeObject);
}
Material* getMaterial(MaterialKey* config, UvMap* uvmap, const char* label) override {
// Create a Java object for the material key and copy the native fields into it.
jobject javaKey = mEnv->NewObject(mMaterialKeyClass, mMaterialKeyConstructor);
auto& helper = MaterialKeyHelper::get();
helper.copy(mEnv, javaKey, *config);
// Convert the optional label into a Java string.
jstring stringLabel = label ? mEnv->NewStringUTF(label) : nullptr;
// Allocate space for the output argument.
jintArray uvMapArray = mEnv->NewIntArray(uvmap->size());
// Call the Java-based material provider.
jobject material = mEnv->CallObjectMethod(mJavaProvider, mGetMaterial,
javaKey, uvMapArray, stringLabel);
// Copy the UvMap results from the JVM array into the native array.
if (uvmap) {
jint* elements = mEnv->GetIntArrayElements(uvMapArray, nullptr);
for (size_t i = 0; i < uvmap->size(); i++) {
(*uvmap)[i] = (UvSet) elements[i];
}
mEnv->ReleaseIntArrayElements(uvMapArray, elements, JNI_ABORT);
}
// The config parameter is an in-out parameter so we need to copy the results from Java.
helper.copy(mEnv, *config, javaKey);
mEnv->DeleteLocalRef(javaKey);
mEnv->DeleteLocalRef(uvMapArray);
if (stringLabel) {
mEnv->DeleteLocalRef(stringLabel);
}
if (material == nullptr) {
return nullptr;
}
return (Material*) mEnv->CallLongMethod(material, mMaterialGetNativeObject);
}
const Material* const* getMaterials() const noexcept override {
jobjectArray javaMaterials = (jobjectArray) mEnv->CallObjectMethod(mJavaProvider, mGetMaterials);
@@ -207,20 +255,11 @@ Java_com_google_android_filament_gltfio_AssetLoader_nDestroyAssetLoader(JNIEnv*,
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_gltfio_AssetLoader_nCreateAssetFromBinary(JNIEnv* env, jclass,
Java_com_google_android_filament_gltfio_AssetLoader_nCreateAsset(JNIEnv* env, jclass,
jlong nativeLoader, jobject javaBuffer, jint remaining) {
AssetLoader* loader = (AssetLoader*) nativeLoader;
AutoBuffer buffer(env, javaBuffer, remaining);
return (jlong) loader->createAssetFromBinary((const uint8_t *) buffer.getData(),
buffer.getSize());
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_gltfio_AssetLoader_nCreateAssetFromJson(JNIEnv* env, jclass,
jlong nativeLoader, jobject javaBuffer, jint remaining) {
AssetLoader* loader = (AssetLoader*) nativeLoader;
AutoBuffer buffer(env, javaBuffer, remaining);
return (jlong) loader->createAssetFromJson((const uint8_t *) buffer.getData(),
return (jlong) loader->createAsset((const uint8_t *) buffer.getData(),
buffer.getSize());
}

View File

@@ -172,27 +172,6 @@ Java_com_google_android_filament_gltfio_FilamentAsset_nGetCameraEntityCount(JNIE
return asset->getCameraEntityCount();
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nGetMaterialInstanceCount(JNIEnv*, jclass,
jlong nativeAsset) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
return asset->getMaterialInstanceCount();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nGetMaterialInstances(JNIEnv* env, jclass,
jlong nativeAsset, jlongArray result) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
jsize available = env->GetArrayLength(result);
jsize count = std::min(available, (jsize) asset->getMaterialInstanceCount());
jlong* dst = env->GetLongArrayElements(result, nullptr);
const MaterialInstance * const* src = asset->getMaterialInstances();
for (jsize i = 0; i < count; i++) {
dst[i] = (jlong) src[i];
}
env->ReleaseLongArrayElements(result, dst, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nGetBoundingBox(JNIEnv* env, jclass,
jlong nativeAsset, jfloatArray result) {
@@ -228,49 +207,11 @@ Java_com_google_android_filament_gltfio_FilamentAsset_nGetExtras(JNIEnv* env, jc
return val ? env->NewStringUTF(val) : nullptr;
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nGetSkinCount(JNIEnv* , jclass,
jlong nativeAsset) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
return (jint) asset->getSkinCount();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nGetSkinNames(JNIEnv* env, jclass,
jlong nativeAsset, jobjectArray result) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
jsize available = env->GetArrayLength(result);
for (int i = 0; i < available; ++i) {
const char* name = asset->getSkinNameAt(i);
if (name) {
env->SetObjectArrayElement(result, (jsize) i, env->NewStringUTF(name));
}
}
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nGetJointCountAt(JNIEnv* , jclass,
jlong nativeAsset, jint skinIndex) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
return (jint) asset->getJointCountAt(skinIndex);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nGetJointsAt(JNIEnv* env, jclass,
jlong nativeAsset, jint skinIndex, jintArray result) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
jsize available = env->GetArrayLength(result);
Entity* entities = (Entity*) env->GetIntArrayElements(result, nullptr);
std::copy_n(asset->getJointsAt(skinIndex),
std::min(available, (jsize) asset->getJointCountAt(skinIndex)), entities);
env->ReleaseIntArrayElements(result, (jint*) entities, 0);
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nGetAnimator(JNIEnv* , jclass,
Java_com_google_android_filament_gltfio_FilamentAsset_nGetInstance(JNIEnv* , jclass,
jlong nativeAsset) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
return (jlong) asset->getAnimator();
return (jlong) asset->getInstance();
}
extern "C" JNIEXPORT jint JNICALL
@@ -310,49 +251,9 @@ Java_com_google_android_filament_gltfio_FilamentAsset_nGetMorphTargetNames(JNIEn
}
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nGetMaterialVariantCount(JNIEnv*, jclass,
jlong nativeAsset) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
return (jint) asset->getMaterialVariantCount();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nGetMaterialVariantNames(JNIEnv* env, jclass,
jlong nativeAsset, jobjectArray result) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
for (int i = 0; i < asset->getMaterialVariantCount(); ++i) {
const char* name = asset->getMaterialVariantName(i);
env->SetObjectArrayElement(result, (jsize) i, env->NewStringUTF(name));
}
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nApplyMaterialVariant(JNIEnv* env, jclass,
jlong nativeAsset, jint variantIndex) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
asset->applyMaterialVariant(variantIndex);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nReleaseSourceData(JNIEnv* env, jclass,
jlong nativeAsset) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
asset->releaseSourceData();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nAttachSkin(JNIEnv* env, jclass,
jlong nativeAsset, jint skinIndex, jint targetEntity) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
Entity target = Entity::import(targetEntity);
asset->attachSkin(skinIndex, target);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentAsset_nDetachSkin(JNIEnv* env, jclass,
jlong nativeAsset, jint skinIndex, jint targetEntity) {
FilamentAsset* asset = (FilamentAsset*) nativeAsset;
Entity target = Entity::import(targetEntity);
asset->detachSkin(skinIndex, target);
}

View File

@@ -20,6 +20,7 @@
#include <algorithm>
using namespace filament;
using namespace filament::gltfio;
using namespace utils;
@@ -61,3 +62,95 @@ Java_com_google_android_filament_gltfio_FilamentInstance_nApplyMaterialVariant(J
FilamentInstance* instance = (FilamentInstance*) nativeInstance;
instance->applyMaterialVariant(variantIndex);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_gltfio_FilamentInstance_nGetMaterialVariantCount(JNIEnv*, jclass,
jlong nativeInstance) {
FilamentInstance* instance = (FilamentInstance*) nativeInstance;
return (jint) instance->getMaterialVariantCount();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentInstance_nGetMaterialVariantNames(JNIEnv* env, jclass,
jlong nativeInstance, jobjectArray result) {
FilamentInstance* instance = (FilamentInstance*) nativeInstance;
for (int i = 0; i < instance->getMaterialVariantCount(); ++i) {
const char* name = instance->getMaterialVariantName(i);
env->SetObjectArrayElement(result, (jsize) i, env->NewStringUTF(name));
}
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_gltfio_FilamentInstance_nGetMaterialInstanceCount(JNIEnv*, jclass,
jlong nativeInstance) {
FilamentInstance* instance = (FilamentInstance*) nativeInstance;
return instance->getMaterialInstanceCount();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentInstance_nGetMaterialInstances(JNIEnv* env, jclass,
jlong nativeInstance, jlongArray result) {
FilamentInstance* instance = (FilamentInstance*) nativeInstance;
jsize available = env->GetArrayLength(result);
jsize count = std::min(available, (jsize) instance->getMaterialInstanceCount());
jlong* dst = env->GetLongArrayElements(result, nullptr);
const MaterialInstance * const* src = instance->getMaterialInstances();
for (jsize i = 0; i < count; i++) {
dst[i] = (jlong) src[i];
}
env->ReleaseLongArrayElements(result, dst, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentInstance_nAttachSkin(JNIEnv* env, jclass,
jlong nativeInstance, jint skinIndex, jint targetEntity) {
FilamentInstance* instance = (FilamentInstance*) nativeInstance;
Entity target = Entity::import(targetEntity);
instance->attachSkin(skinIndex, target);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentInstance_nDetachSkin(JNIEnv* env, jclass,
jlong nativeInstance, jint skinIndex, jint targetEntity) {
FilamentInstance* instance = (FilamentInstance*) nativeInstance;
Entity target = Entity::import(targetEntity);
instance->detachSkin(skinIndex, target);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_gltfio_FilamentInstance_nGetSkinCount(JNIEnv* , jclass,
jlong nativeInstance) {
FilamentInstance* instance = (FilamentInstance*) nativeInstance;
return (jint) instance->getSkinCount();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentInstance_nGetSkinNames(JNIEnv* env, jclass,
jlong nativeInstance, jobjectArray result) {
FilamentInstance* instance = (FilamentInstance*) nativeInstance;
jsize available = env->GetArrayLength(result);
for (int i = 0; i < available; ++i) {
const char* name = instance->getSkinNameAt(i);
if (name) {
env->SetObjectArrayElement(result, (jsize) i, env->NewStringUTF(name));
}
}
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_gltfio_FilamentInstance_nGetJointCountAt(JNIEnv* , jclass,
jlong nativeInstance, jint skinIndex) {
FilamentInstance* instance = (FilamentInstance*) nativeInstance;
return (jint) instance->getJointCountAt(skinIndex);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_gltfio_FilamentInstance_nGetJointsAt(JNIEnv* env, jclass,
jlong nativeInstance, jint skinIndex, jintArray result) {
FilamentInstance* instance = (FilamentInstance*) nativeInstance;
jsize available = env->GetArrayLength(result);
Entity* entities = (Entity*) env->GetIntArrayElements(result, nullptr);
std::copy_n(instance->getJointsAt(skinIndex),
std::min(available, (jsize) instance->getJointCountAt(skinIndex)), entities);
env->ReleaseIntArrayElements(result, (jint*) entities, 0);
}

View File

@@ -36,11 +36,9 @@ static void destroy(void*, size_t, void *userData) {
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_gltfio_ResourceLoader_nCreateResourceLoader(JNIEnv*, jclass,
jlong nativeEngine, jboolean normalizeSkinningWeights, jboolean recomputeBoundingBoxes,
jboolean ignoreBindTransform) {
jlong nativeEngine, jboolean normalizeSkinningWeights) {
Engine* engine = (Engine*) nativeEngine;
return (jlong) new ResourceLoader({ engine, {}, (bool) normalizeSkinningWeights,
(bool) recomputeBoundingBoxes, (bool) ignoreBindTransform});
return (jlong) new ResourceLoader({ engine, {}, (bool) normalizeSkinningWeights});
}
extern "C" JNIEXPORT void JNICALL

View File

@@ -49,16 +49,19 @@ Java_com_google_android_filament_gltfio_UbershaderProvider_nDestroyMaterials(JNI
extern "C" JNIEXPORT long JNICALL
Java_com_google_android_filament_gltfio_UbershaderProvider_nCreateMaterialInstance(JNIEnv* env, jclass,
jlong nativeProvider, jobject materialKey, jintArray uvmap, jstring label) {
jlong nativeProvider, jobject materialKey, jintArray uvmap, jstring label, jstring extras) {
MaterialKey nativeKey = {};
auto& helper = MaterialKeyHelper::get();
helper.copy(env, nativeKey, materialKey);
const char* nativeLabel = label ? env->GetStringUTFChars(label, nullptr) : nullptr;
const char* nativeExtras = extras ? env->GetStringUTFChars(extras, nullptr) : nullptr;
UvMap nativeUvMap = {};
auto provider = (MaterialProvider*) nativeProvider;
MaterialInstance* instance = provider->createMaterialInstance(&nativeKey, &nativeUvMap, nativeLabel);
MaterialInstance* instance = provider->createMaterialInstance(&nativeKey, &nativeUvMap,
nativeLabel, nativeExtras);
// Copy the UvMap results from the native array into the JVM array.
jint* elements = env->GetIntArrayElements(uvmap, nullptr);
@@ -77,9 +80,47 @@ Java_com_google_android_filament_gltfio_UbershaderProvider_nCreateMaterialInstan
env->ReleaseStringUTFChars(label, nativeLabel);
}
if (extras) {
env->ReleaseStringUTFChars(extras, nativeExtras);
}
return (long) instance;
}
extern "C" JNIEXPORT long JNICALL
Java_com_google_android_filament_gltfio_UbershaderProvider_nGetMaterial(JNIEnv* env, jclass,
jlong nativeProvider, jobject materialKey, jintArray uvmap, jstring label) {
MaterialKey nativeKey = {};
auto& helper = MaterialKeyHelper::get();
helper.copy(env, nativeKey, materialKey);
const char* nativeLabel = label ? env->GetStringUTFChars(label, nullptr) : nullptr;
UvMap nativeUvMap = {};
auto provider = (MaterialProvider*) nativeProvider;
Material* material = provider->getMaterial(&nativeKey, &nativeUvMap, nativeLabel);
// Copy the UvMap results from the native array into the JVM array.
jint* elements = env->GetIntArrayElements(uvmap, nullptr);
if (elements) {
const size_t javaSize = env->GetArrayLength(uvmap);
for (int i = 0, n = std::min(javaSize, nativeUvMap.size()); i < n; ++i) {
elements[i] = nativeUvMap[i];
}
env->ReleaseIntArrayElements(uvmap, elements, 0);
}
// The config parameter is an in-out parameter so we need to copy the results back to Java.
helper.copy(env, materialKey, nativeKey);
if (label) {
env->ReleaseStringUTFChars(label, nativeLabel);
}
return (long) material;
}
extern "C" JNIEXPORT int JNICALL
Java_com_google_android_filament_gltfio_UbershaderProvider_nGetMaterialCount(JNIEnv*, jclass,
jlong nativeProvider) {

View File

@@ -26,8 +26,8 @@ import java.nio.Buffer;
/**
* Consumes a blob of glTF 2.0 content (either JSON or GLB) and produces a {@link FilamentAsset}
* object, which is a bundle of Filament entities, material instances, textures, vertex buffers,
* and index buffers.
* object, which is a bundle of Filament textures, vertex buffers, index buffers, etc. An asset is
* composed of 1 or more FilamentInstance objects which contain entities and components.
*
* <p>AssetLoader does not fetch external buffer data or create textures on its own. Clients can use
* the provided {@link ResourceLoader} class for this, which obtains the URI list from the asset.
@@ -51,7 +51,7 @@ import java.nio.Buffer;
* filamentAsset = assets.open("models/lucy.gltf").use { input -&gt;
* val bytes = ByteArray(input.available())
* input.read(bytes)
* assetLoader.createAssetFromJson(ByteBuffer.wrap(bytes))!!
* assetLoader.createAsset(ByteBuffer.wrap(bytes))!!
* }
*
* val resourceLoader = ResourceLoader(engine)
@@ -115,20 +115,11 @@ public class AssetLoader {
}
/**
* Creates a {@link FilamentAsset} from the contents of a GLB file.
* Creates a {@link FilamentAsset} from the contents of a GLB or GLTF file.
*/
@Nullable
public FilamentAsset createAssetFromBinary(@NonNull Buffer buffer) {
long nativeAsset = nCreateAssetFromBinary(mNativeObject, buffer, buffer.remaining());
return nativeAsset != 0 ? new FilamentAsset(mEngine, nativeAsset) : null;
}
/**
* Creates a {@link FilamentAsset} from the contents of a GLTF file.
*/
@Nullable
public FilamentAsset createAssetFromJson(@NonNull Buffer buffer) {
long nativeAsset = nCreateAssetFromJson(mNativeObject, buffer, buffer.remaining());
public FilamentAsset createAsset(@NonNull Buffer buffer) {
long nativeAsset = nCreateAsset(mNativeObject, buffer, buffer.remaining());
return nativeAsset != 0 ? new FilamentAsset(mEngine, nativeAsset) : null;
}
@@ -158,7 +149,7 @@ public class AssetLoader {
}
/**
* Adds a new instance to an instanced asset.
* Adds a new instance to the asset.
*
* Use this with caution. It is more efficient to pre-allocate a max number of instances, and
* gradually add them to the scene as needed. Instances can also be "recycled" by removing and
@@ -169,8 +160,6 @@ public class AssetLoader {
* create/destroy churn, as noted above.
*
* This cannot be called after FilamentAsset#releaseSourceData().
* This cannot be called on a non-instanced asset.
* Animation is not supported in new instances.
* See also AssetLoader#createInstancedAsset().
*/
@Nullable
@@ -202,8 +191,7 @@ public class AssetLoader {
private static native long nCreateAssetLoader(long nativeEngine, Object provider,
long nativeEntities);
private static native void nDestroyAssetLoader(long nativeLoader);
private static native long nCreateAssetFromBinary(long nativeLoader, Buffer buffer, int remaining);
private static native long nCreateAssetFromJson(long nativeLoader, Buffer buffer, int remaining);
private static native long nCreateAsset(long nativeLoader, Buffer buffer, int remaining);
private static native long nCreateInstancedAsset(long nativeLoader, Buffer buffer, int remaining,
long[] nativeInstances);
private static native long nCreateInstance(long nativeLoader, long nativeAsset);

View File

@@ -23,7 +23,6 @@ import androidx.annotation.Nullable;
import com.google.android.filament.Box;
import com.google.android.filament.Engine;
import com.google.android.filament.Entity;
import com.google.android.filament.MaterialInstance;
/**
* Owns a bundle of Filament objects that have been created by <code>AssetLoader</code>.
@@ -35,25 +34,32 @@ import com.google.android.filament.MaterialInstance;
* <code>NameComponentManager</code>, <code>RenderableManager</code>, and others.</p>
*
* <p>In addition to the aforementioned entities, an asset has strong ownership over a list of
* <code>VertexBuffer</code>, <code>IndexBuffer</code>, <code>MaterialInstance</code>, and
* <code>Texture</code>.</p>
* <code>VertexBuffer</code>, <code>IndexBuffer</code>, and <code>Texture</code>.</p>
*
* <p>Clients can use {@link ResourceLoader} to create textures, compute tangent quaternions, and
* upload data into vertex buffers and index buffers.</p>
*
* @see ResourceLoader
* @see Animator
* @see FilamentInstance
* @see AssetLoader
*/
public class FilamentAsset {
private long mNativeObject;
private Animator mAnimator;
private FilamentInstance mPrimaryInstance;
private Engine mEngine;
FilamentAsset(Engine engine, long nativeObject) {
mEngine = engine;
mNativeObject = nativeObject;
mAnimator = null;
}
public FilamentInstance getInstance() {
if (mPrimaryInstance != null) {
return mPrimaryInstance;
}
long nativeInstance = nGetInstance(getNativeObject());
mPrimaryInstance = new FilamentInstance(this, nativeInstance);
return mPrimaryInstance;
}
long getNativeObject() {
@@ -169,19 +175,11 @@ public class FilamentAsset {
return result;
}
public @NonNull MaterialInstance[] getMaterialInstances() {
final int count = nGetMaterialInstanceCount(mNativeObject);
MaterialInstance[] result = new MaterialInstance[count];
long[] natives = new long[count];
nGetMaterialInstances(mNativeObject, natives);
for (int i = 0; i < count; i++) {
result[i] = new MaterialInstance(mEngine, natives[i]);
}
return result;
}
/**
* Gets the bounding box computed from the supplied min / max values in glTF accessors.
*
* This does not return a bounding box over all FilamentInstance, it's just a straightforward
* AAAB that can be determined at load time from the asset data.
*/
public @NonNull Box getBoundingBox() {
float[] box = new float[6];
@@ -206,77 +204,6 @@ public class FilamentAsset {
return nGetExtras(mNativeObject, entity);
}
/**
* Retrieves the <code>Animator</code> interface for this asset.
*
* <p>When calling this for the first time, this must be called after
* {@link ResourceLoader#loadResources} or {@link ResourceLoader#asyncBeginLoad}. When the asset
* is destroyed, its animator becomes invalid.</p>
*/
public @NonNull Animator getAnimator() {
if (mAnimator != null) {
return mAnimator;
}
long nativeAnimator = nGetAnimator(getNativeObject());
if (nativeAnimator == 0) {
throw new IllegalStateException("Unable to create animator");
}
mAnimator = new Animator(nativeAnimator);
return mAnimator;
}
/**
* Gets the skin count of this asset.
*/
public int getSkinCount() {
return nGetSkinCount(getNativeObject());
}
/**
* Gets the skin name at skin index in this asset.
*/
public @NonNull String[] getSkinNames() {
String[] result = new String[getSkinCount()];
nGetSkinNames(getNativeObject(), result);
return result;
}
/**
* Attaches the given skin to the given node, which must have an associated mesh with
* BONE_INDICES and BONE_WEIGHTS attributes.
*
* This is a no-op if the given skin index or target is invalid.
*/
public void attachSkin(@IntRange(from = 0) int skinIndex, @Entity int target) {
nAttachSkin(getNativeObject(), skinIndex, target);
}
/**
* Attaches the given skin to the given node, which must have an associated mesh with
* BONE_INDICES and BONE_WEIGHTS attributes.
*
* This is a no-op if the given skin index or target is invalid.
*/
public void detachSkin(@IntRange(from = 0) int skinIndex, @Entity int target) {
nDetachSkin(getNativeObject(), skinIndex, target);
}
/**
* Gets the joint count at skin index in this asset.
*/
public int getJointCountAt(@IntRange(from = 0) int skinIndex) {
return nGetJointCountAt(getNativeObject(), skinIndex);
}
/**
* Gets joints at skin index in this asset.
*/
public @NonNull @Entity int[] getJointsAt(@IntRange(from = 0) int skinIndex) {
int[] result = new int[getJointCountAt(skinIndex)];
nGetJointsAt(getNativeObject(), skinIndex, result);
return result;
}
/**
* Gets the names of all morph targets in the given entity.
*/
@@ -295,31 +222,6 @@ public class FilamentAsset {
return uris;
}
/**
* Returns the names of all material variants.
*/
public @NonNull String[] getMaterialVariantNames() {
String[] names = new String[nGetMaterialVariantCount(mNativeObject)];
nGetMaterialVariantNames(mNativeObject, names);
return names;
}
/**
* Applies the given material variant to all primitives that it affects.
*
* This is efficient because it merely swaps around persistent MaterialInstances. If you change
* a material parameter while a certain variant is active, the updated value will be remembered
* after you re-apply that variant.
*
* If the asset is instanced, this affects all instances in the same way.
* To set the variant on an individual instance, use FilamentInstance#applyMaterialVariant.
*
* Ignored if variantIndex is out of bounds.
*/
public void applyMaterialVariant(@IntRange(from = 0) int variantIndex) {
nApplyMaterialVariant(getNativeObject(), variantIndex);
}
/**
* Reclaims CPU-side memory for URI strings, binding lists, and raw animation data.
*
@@ -331,8 +233,10 @@ public class FilamentAsset {
nReleaseSourceData(mNativeObject);
}
public Engine getEngine() { return mEngine; }
void clearNativeObject() {
if (mAnimator != null) mAnimator.clearNativeObject();
mPrimaryInstance = null;
mNativeObject = 0;
}
@@ -356,28 +260,17 @@ public class FilamentAsset {
private static native int nGetCameraEntityCount(long nativeAsset);
private static native void nGetCameraEntities(long nativeAsset, int[] result);
private static native int nGetMaterialInstanceCount(long nativeAsset);
private static native void nGetMaterialInstances(long nativeAsset, long[] nativeResults);
private static native int nGetMaterialVariantCount(long nativeAsset);
private static native void nGetMaterialVariantNames(long nativeAsset, String[] result);
private static native int nGetMorphTargetCount(long nativeAsset, int entity);
private static native void nGetMorphTargetNames(long nativeAsset, int entity, String[] result);
private static native void nAttachSkin(long nativeAsset, int skinIndex, int entity);
private static native void nDetachSkin(long nativeAsset, int skinIndex, int entity);
private static native void nGetBoundingBox(long nativeAsset, float[] box);
private static native String nGetName(long nativeAsset, int entity);
private static native String nGetExtras(long nativeAsset, int entity);
private static native long nGetAnimator(long nativeAsset);
private static native void nApplyMaterialVariant(long nativeAsset, int variantIndex);
private static native int nGetSkinCount(long nativeAsset);
private static native void nGetSkinNames(long nativeAsset, String[] result);
private static native int nGetJointCountAt(long nativeAsset, int skinIndex);
private static native void nGetJointsAt(long nativeAsset, int skinIndex, int[] result);
private static native long nGetInstance(long nativeAsset);
private static native int nGetResourceUriCount(long nativeAsset);
private static native void nGetResourceUris(long nativeAsset, String[] result);
private static native void nReleaseSourceData(long nativeAsset);
}

View File

@@ -19,7 +19,9 @@ package com.google.android.filament.gltfio;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import com.google.android.filament.Engine;
import com.google.android.filament.Entity;
import com.google.android.filament.MaterialInstance;
/**
* Provides access to a hierarchy of entities that have been instanced from a glTF asset.
@@ -85,6 +87,58 @@ public class FilamentInstance {
return mAnimator;
}
/**
* Gets the skin count of this instance.
*/
public int getSkinCount() {
return nGetSkinCount(getNativeObject());
}
/**
* Gets the skin name at skin index in this instance.
*/
public @NonNull String[] getSkinNames() {
String[] result = new String[getSkinCount()];
nGetSkinNames(getNativeObject(), result);
return result;
}
/**
* Attaches the given skin to the given node, which must have an associated mesh with
* BONE_INDICES and BONE_WEIGHTS attributes.
*
* This is a no-op if the given skin index or target is invalid.
*/
public void attachSkin(@IntRange(from = 0) int skinIndex, @Entity int target) {
nAttachSkin(getNativeObject(), skinIndex, target);
}
/**
* Attaches the given skin to the given node, which must have an associated mesh with
* BONE_INDICES and BONE_WEIGHTS attributes.
*
* This is a no-op if the given skin index or target is invalid.
*/
public void detachSkin(@IntRange(from = 0) int skinIndex, @Entity int target) {
nDetachSkin(getNativeObject(), skinIndex, target);
}
/**
* Gets the joint count at skin index in this instance.
*/
public int getJointCountAt(@IntRange(from = 0) int skinIndex) {
return nGetJointCountAt(getNativeObject(), skinIndex);
}
/**
* Gets joints at skin index in this instance.
*/
public @NonNull @Entity int[] getJointsAt(@IntRange(from = 0) int skinIndex) {
int[] result = new int[getJointCountAt(skinIndex)];
nGetJointsAt(getNativeObject(), skinIndex, result);
return result;
}
/**
* Applies the given material variant to all primitives in this instance.
*
@@ -94,9 +148,43 @@ public class FilamentInstance {
nApplyMaterialVariant(mNativeObject, variantIndex);
}
private static native int nGetRoot(long nativeAsset);
private static native int nGetEntityCount(long nativeAsset);
private static native void nGetEntities(long nativeAsset, int[] result);
private static native long nGetAnimator(long nativeAsset);
private static native void nApplyMaterialVariant(long nativeAsset, int variantIndex);
public @NonNull MaterialInstance[] getMaterialInstances() {
final int count = nGetMaterialInstanceCount(mNativeObject);
MaterialInstance[] result = new MaterialInstance[count];
long[] natives = new long[count];
nGetMaterialInstances(mNativeObject, natives);
Engine engine = mAsset.getEngine();
for (int i = 0; i < count; i++) {
result[i] = new MaterialInstance(engine, natives[i]);
}
return result;
}
/**
* Returns the names of all material variants.
*/
public @NonNull String[] getMaterialVariantNames() {
String[] names = new String[nGetMaterialVariantCount(mNativeObject)];
nGetMaterialVariantNames(mNativeObject, names);
return names;
}
private static native int nGetRoot(long nativeInstance);
private static native int nGetEntityCount(long nativeInstance);
private static native void nGetEntities(long nativeInstance, int[] result);
private static native long nGetAnimator(long nativeInstance);
private static native int nGetMaterialInstanceCount(long nativeAsset);
private static native void nGetMaterialInstances(long nativeAsset, long[] nativeResults);
private static native void nApplyMaterialVariant(long nativeInstance, int variantIndex);
private static native int nGetMaterialVariantCount(long nativeAsset);
private static native void nGetMaterialVariantNames(long nativeAsset, String[] result);
private static native void nGetJointsAt(long nativeInstance, int skinIndex, int[] result);
private static native int nGetSkinCount(long nativeInstance);
private static native void nGetSkinNames(long nativeInstance, String[] result);
private static native int nGetJointCountAt(long nativeInstance, int skinIndex);
private static native void nAttachSkin(long nativeInstance, int skinIndex, int entity);
private static native void nDetachSkin(long nativeInstance, int skinIndex, int entity);
}

View File

@@ -24,47 +24,85 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
public interface MaterialProvider {
import com.google.android.filament.proguard.UsedByNative;
@UsedByNative("AssetLoader.cpp")
public interface MaterialProvider {
/**
* MaterialKey specifies the requirements for a requested glTF material.
* The provider creates Filament materials that fulfill these requirements.
*/
@UsedByNative("MaterialKey.cpp")
public static class MaterialKey {
@UsedByNative("MaterialKey.cpp")
public boolean doubleSided;
@UsedByNative("MaterialKey.cpp")
public boolean unlit;
@UsedByNative("MaterialKey.cpp")
public boolean hasVertexColors;
@UsedByNative("MaterialKey.cpp")
public boolean hasBaseColorTexture;
@UsedByNative("MaterialKey.cpp")
public boolean hasNormalTexture;
@UsedByNative("MaterialKey.cpp")
public boolean hasOcclusionTexture;
@UsedByNative("MaterialKey.cpp")
public boolean hasEmissiveTexture;
@UsedByNative("MaterialKey.cpp")
public boolean useSpecularGlossiness;
@UsedByNative("MaterialKey.cpp")
public int alphaMode; // 0 = OPAQUE, 1 = MASK, 2 = BLEND
@UsedByNative("MaterialKey.cpp")
public boolean enableDiagnostics;
@UsedByNative("MaterialKey.cpp")
public boolean hasMetallicRoughnessTexture; // piggybacks with specularRoughness
@UsedByNative("MaterialKey.cpp")
public int metallicRoughnessUV; // piggybacks with specularRoughness
@UsedByNative("MaterialKey.cpp")
public int baseColorUV;
@UsedByNative("MaterialKey.cpp")
public boolean hasClearCoatTexture;
@UsedByNative("MaterialKey.cpp")
public int clearCoatUV;
@UsedByNative("MaterialKey.cpp")
public boolean hasClearCoatRoughnessTexture;
@UsedByNative("MaterialKey.cpp")
public int clearCoatRoughnessUV;
@UsedByNative("MaterialKey.cpp")
public boolean hasClearCoatNormalTexture;
@UsedByNative("MaterialKey.cpp")
public int clearCoatNormalUV;
@UsedByNative("MaterialKey.cpp")
public boolean hasClearCoat;
@UsedByNative("MaterialKey.cpp")
public boolean hasTransmission;
@UsedByNative("MaterialKey.cpp")
public boolean hasTextureTransforms;
@UsedByNative("MaterialKey.cpp")
public int emissiveUV;
@UsedByNative("MaterialKey.cpp")
public int aoUV;
@UsedByNative("MaterialKey.cpp")
public int normalUV;
@UsedByNative("MaterialKey.cpp")
public boolean hasTransmissionTexture;
@UsedByNative("MaterialKey.cpp")
public int transmissionUV;
@UsedByNative("MaterialKey.cpp")
public boolean hasSheenColorTexture;
@UsedByNative("MaterialKey.cpp")
public int sheenColorUV;
@UsedByNative("MaterialKey.cpp")
public boolean hasSheenRoughnessTexture;
@UsedByNative("MaterialKey.cpp")
public int sheenRoughnessUV;
@UsedByNative("MaterialKey.cpp")
public boolean hasVolumeThicknessTexture;
@UsedByNative("MaterialKey.cpp")
public int volumeThicknessUV;
@UsedByNative("MaterialKey.cpp")
public boolean hasSheen;
@UsedByNative("MaterialKey.cpp")
public boolean hasIOR;
public MaterialKey() {}
@@ -104,6 +142,12 @@ public interface MaterialProvider {
public @Nullable MaterialInstance createMaterialInstance(MaterialKey config,
@NonNull @Size(min = 8) int[] uvmap, @Nullable String label, @Nullable String extras);
/**
* Creates or fetches a compiled Filament material corresponding to the given config.
*/
public @Nullable Material getMaterial(MaterialKey config, @NonNull @Size(min = 8) int[] uvmap,
@Nullable String label);
/**
* Creates and returns an array containing all cached materials.
*/

View File

@@ -47,7 +47,7 @@ public class ResourceLoader {
*/
public ResourceLoader(@NonNull Engine engine) {
long nativeEngine = engine.getNativeObject();
mNativeObject = nCreateResourceLoader(nativeEngine, false, false, false);
mNativeObject = nCreateResourceLoader(nativeEngine, false);
mNativeStbProvider = nCreateStbProvider(nativeEngine);
mNativeKtx2Provider = nCreateKtx2Provider(nativeEngine);
nAddTextureProvider(mNativeObject, "image/jpeg", mNativeStbProvider);
@@ -60,16 +60,12 @@ public class ResourceLoader {
*
* @param engine the engine that gets passed to all builder methods
* @param normalizeSkinningWeights scale non-conformant skinning weights so they sum to 1
* @param recomputeBoundingBoxes use computed bounding boxes rather than the ones in the asset
* @param ignoreBindTransform ignore skinned primitives bind transform when compute bounding boxes
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
public ResourceLoader(@NonNull Engine engine, boolean normalizeSkinningWeights,
boolean recomputeBoundingBoxes, boolean ignoreBindTransform) {
public ResourceLoader(@NonNull Engine engine, boolean normalizeSkinningWeights) {
long nativeEngine = engine.getNativeObject();
mNativeObject = nCreateResourceLoader(nativeEngine, normalizeSkinningWeights,
recomputeBoundingBoxes, ignoreBindTransform);
mNativeObject = nCreateResourceLoader(nativeEngine, normalizeSkinningWeights);
mNativeStbProvider = nCreateStbProvider(nativeEngine);
mNativeKtx2Provider = nCreateKtx2Provider(nativeEngine);
nAddTextureProvider(mNativeObject, "image/jpeg", mNativeStbProvider);
@@ -181,7 +177,7 @@ public class ResourceLoader {
}
private static native long nCreateResourceLoader(long nativeEngine,
boolean normalizeSkinningWeights, boolean recomputeBoundingBoxes, boolean ignoreBindTransform);
boolean normalizeSkinningWeights);
private static native void nDestroyResourceLoader(long nativeLoader);
private static native void nAddResourceData(long nativeLoader, String url, Buffer buffer,
int remaining);

View File

@@ -20,6 +20,7 @@ import com.google.android.filament.Engine;
import com.google.android.filament.MaterialInstance;
import com.google.android.filament.Material;
import com.google.android.filament.VertexBuffer;
import com.google.android.filament.proguard.UsedByNative;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -57,10 +58,16 @@ public class UbershaderProvider implements MaterialProvider {
public @Nullable MaterialInstance createMaterialInstance(MaterialKey config,
@NonNull @Size(min = 8) int[] uvmap, @Nullable String label, @Nullable String extras) {
long nativeMaterialInstance = nCreateMaterialInstance(mNativeObject, config, uvmap, label);
long nativeMaterialInstance = nCreateMaterialInstance(mNativeObject, config, uvmap, label, extras);
return nativeMaterialInstance == 0 ? null : new MaterialInstance(null, nativeMaterialInstance);
}
public @Nullable Material getMaterial(MaterialKey config, @NonNull @Size(min = 8) int[] uvmap,
@Nullable String label) {
long nativeMaterial = nGetMaterial(mNativeObject, config, uvmap, label);
return nativeMaterial == 0 ? null : new Material(nativeMaterial);
}
public @NonNull Material[] getMaterials() {
final int count = nGetMaterialCount(mNativeObject);
Material[] result = new Material[count];
@@ -88,6 +95,7 @@ public class UbershaderProvider implements MaterialProvider {
nDestroyMaterials(mNativeObject);
}
@UsedByNative("AssetLoader.cpp")
public long getNativeObject() {
return mNativeObject;
}
@@ -96,6 +104,8 @@ public class UbershaderProvider implements MaterialProvider {
private static native void nDestroyUbershaderProvider(long nativeProvider);
private static native void nDestroyMaterials(long nativeProvider);
private static native long nCreateMaterialInstance(long nativeProvider,
MaterialKey config, int[] uvmap, String label, String extras);
private static native long nGetMaterial(long nativeProvider,
MaterialKey config, int[] uvmap, String label);
private static native int nGetMaterialCount(long nativeProvider);
private static native void nGetMaterials(long nativeProvider, long[] result);

View File

@@ -1,5 +1,5 @@
GROUP=com.google.android.filament
VERSION_NAME=1.23.2
VERSION_NAME=1.36.0
POM_DESCRIPTION=Real-time physically based rendering engine for Android.
@@ -18,11 +18,12 @@ POM_DEVELOPER_NAME=Filament Team
org.gradle.jvmargs=-Xmx1536m
android.useAndroidX=true
org.gradle.unsafe.configuration-cache=true
# TODO: Remove this when we switch to Gradle 7.4
org.gradle.unsafe.configuration-cache.max-problems=3
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
com.google.android.filament.tools-dir=../../../out/release/filament
com.google.android.filament.dist-dir=../out/android-release/filament
com.google.android.filament.abis=all
#com.google.android.filament.matdbg
#com.google.android.filament.matnopt

View File

@@ -86,63 +86,10 @@ afterEvaluate { project ->
}
}
if (project.getPlugins().hasPlugin('com.android.application') ||
project.getPlugins().hasPlugin('com.android.library')) {
task androidJavadocs(type: Javadoc) {
source = android.sourceSets.main.java.source
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
excludes = ['**/*.kt']
}
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
classifier = 'javadoc'
from androidJavadocs.destinationDir
}
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.source
}
}
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}
if (JavaVersion.current().isJava9Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addBooleanOption('html5', true)
}
}
}
artifacts {
if (project.getPlugins().hasPlugin('com.android.application') ||
project.getPlugins().hasPlugin('com.android.library')) {
archives androidSourcesJar
archives androidJavadocsJar
}
}
android.libraryVariants.all { variant ->
tasks.androidJavadocs.doFirst {
classpath += files(variant.javaCompileProvider.get().classpath.files.join(File.pathSeparator))
}
}
publishing.publications.all { publication ->
publication.groupId = GROUP
publication.version = VERSION_NAME
publication.artifact androidSourcesJar
publication.artifact androidJavadocsJar
configurePom(publication.pom)
}

View File

@@ -1,6 +1,6 @@
#Wed Nov 17 10:40:18 PST 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -14,3 +14,17 @@
-keepclassmembers class * {
@com.google.android.filament.proguard.UsedBy* *;
}
# These classes is loaded via env->FindClass() from Utils.cpp
# They are in the utils namespace and therefore not covered by previous rules.
-keep class com.google.android.filament.utils.KTX1Loader
-keep class com.google.android.filament.utils.HDRLoader
# These native JNI methods are loaded via env->RegisterNatives() from Utils.cpp
-keepclassmembers class com.google.android.filament.utils.KTX1Loader {
native <methods>;
}
-keepclassmembers class com.google.android.filament.utils.HDRLoader {
native <methods>;
}

View File

@@ -112,9 +112,9 @@ the Android SDK.
## Android Studio
You must use Android Studio 3.6 RC 1 or higher. To open the project, point Studio to the `android`
folder. After opening the project and syncing to gradle, select the sample of your choice using the
drop-down widget in the toolbar.
You must use the latest stable release of Android Studio. To open the project, point Studio to the
`android` folder. After opening the project and syncing to gradle, select the sample of your choice
using the drop-down widget in the toolbar.
## Compiling

View File

@@ -40,6 +40,11 @@ android {
dependenciesInfo {
includeInApk = false
}
compileOptions {
sourceCompatibility versions.jdk
targetCompatibility versions.jdk
}
}
dependencies {

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.filament.gltf">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />

View File

@@ -353,9 +353,11 @@ class MainActivity : Activity() {
fun loadSettings(message: RemoteServer.ReceivedMessage) {
val json = StandardCharsets.UTF_8.decode(message.buffer).toString()
viewerContent.assetLights = modelViewer.asset?.lightEntities
automation.applySettings(json, viewerContent)
automation.applySettings(modelViewer.engine, json, viewerContent)
modelViewer.view.colorGrading = automation.getColorGrading(modelViewer.engine)
modelViewer.cameraFocalLength = automation.viewerOptions.cameraFocalLength
modelViewer.cameraNear = automation.viewerOptions.cameraNear
modelViewer.cameraFar = automation.viewerOptions.cameraFar
updateRootTransform()
}
@@ -417,7 +419,7 @@ class MainActivity : Activity() {
// Just for testing purposes, this releases the current model and reloads the default model.
inner class DoubleTapListener : GestureDetector.SimpleOnGestureListener() {
override fun onDoubleTap(e: MotionEvent?): Boolean {
override fun onDoubleTap(e: MotionEvent): Boolean {
modelViewer.destroyModel()
createDefaultRenderables()
return super.onDoubleTap(e)

View File

@@ -6,6 +6,10 @@ plugins {
project.ext.isSample = true
kotlin {
jvmToolchain(versions.jdk)
}
filamentTools {
materialInputDir = project.layout.projectDirectory.dir("src/main/materials")
materialOutputDir = project.layout.projectDirectory.dir("src/main/assets/materials")
@@ -36,6 +40,11 @@ android {
aaptOptions {
noCompress 'filamat', 'ktx'
}
compileOptions {
sourceCompatibility versions.jdk
targetCompatibility versions.jdk
}
}
dependencies {

View File

@@ -16,8 +16,7 @@
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.filament.hellocam">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.CAMERA" />

View File

@@ -30,6 +30,7 @@ import com.google.android.filament.*
import com.google.android.filament.RenderableManager.*
import com.google.android.filament.VertexBuffer.*
import com.google.android.filament.android.DisplayHelper
import com.google.android.filament.android.FilamentHelper
import com.google.android.filament.android.UiHelper
import java.nio.ByteBuffer
@@ -401,6 +402,8 @@ class MainActivity : Activity(), ActivityCompat.OnRequestPermissionsResultCallba
camera.setProjection(45.0, aspect, 0.1, 20.0, Camera.Fov.VERTICAL)
view.viewport = Viewport(0, 0, width, height)
FilamentHelper.synchronizePendingFrames(engine)
}
}

View File

@@ -6,6 +6,10 @@ plugins {
project.ext.isSample = true
kotlin {
jvmToolchain(versions.jdk)
}
filamentTools {
materialInputDir = project.layout.projectDirectory.dir("src/main/materials")
materialOutputDir = project.layout.projectDirectory.dir("src/main/assets/materials")
@@ -36,6 +40,11 @@ android {
aaptOptions {
noCompress 'filamat', 'ktx'
}
compileOptions {
sourceCompatibility versions.jdk
targetCompatibility versions.jdk
}
}
dependencies {

View File

@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.filament.hellotriangle">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"

View File

@@ -29,6 +29,7 @@ import com.google.android.filament.RenderableManager.PrimitiveType
import com.google.android.filament.VertexBuffer.AttributeType
import com.google.android.filament.VertexBuffer.VertexAttribute
import com.google.android.filament.android.DisplayHelper
import com.google.android.filament.android.FilamentHelper
import com.google.android.filament.android.UiHelper
import java.nio.ByteBuffer
import java.nio.ByteOrder
@@ -119,8 +120,13 @@ class MainActivity : Activity() {
private fun setupView() {
scene.skybox = Skybox.Builder().color(0.035f, 0.035f, 0.035f, 1.0f).build(engine)
// NOTE: Try to disable post-processing (tone-mapping, etc.) to see the difference
// view.isPostProcessingEnabled = false
if (engine.activeFeatureLevel == Engine.FeatureLevel.FEATURE_LEVEL_0) {
// post-processing is not supported at feature level 0
view.isPostProcessingEnabled = false
} else {
// NOTE: Try to disable post-processing (tone-mapping, etc.) to see the difference
// view.isPostProcessingEnabled = false
}
// Tell the view which camera we want to use
view.camera = camera
@@ -154,7 +160,11 @@ class MainActivity : Activity() {
}
private fun loadMaterial() {
readUncompressedAsset("materials/baked_color.filamat").let {
var name = "materials/baked_color.filamat"
if (engine.activeFeatureLevel == Engine.FeatureLevel.FEATURE_LEVEL_0) {
name = "materials/baked_color_es2.filamat"
}
readUncompressedAsset(name).let {
material = Material.Builder().payload(it, it.remaining()).build(engine)
}
}
@@ -304,7 +314,17 @@ class MainActivity : Activity() {
inner class SurfaceCallback : UiHelper.RendererCallback {
override fun onNativeWindowChanged(surface: Surface) {
swapChain?.let { engine.destroySwapChain(it) }
swapChain = engine.createSwapChain(surface, uiHelper.swapChainFlags)
// at feature level 0, we don't have post-processing, so we need to set
// the colorspace to sRGB (FIXME: it's not supported everywhere!)
var flags = uiHelper.swapChainFlags
if (engine.activeFeatureLevel == Engine.FeatureLevel.FEATURE_LEVEL_0) {
if (SwapChain.isSRGBSwapChainSupported(engine)) {
flags = flags or SwapChain.CONFIG_SRGB_COLORSPACE
}
}
swapChain = engine.createSwapChain(surface, flags)
displayHelper.attach(renderer, surfaceView.display);
}
@@ -327,6 +347,8 @@ class MainActivity : Activity() {
-aspect * zoom, aspect * zoom, -zoom, zoom, 0.0, 10.0)
view.viewport = Viewport(0, 0, width, height)
FilamentHelper.synchronizePendingFrames(engine)
}
}

View File

@@ -17,7 +17,7 @@ material {
],
// This material disables all lighting
shadingModel : unlit,
shadingModel : unlit
}
fragment {

View File

@@ -0,0 +1,33 @@
// Simple unlit material that uses the colors associated with each vertex.
//
// This source material must be compiled to a binary material using the matc tool.
// The command used to compile this material is:
// matc -p mobile -a opengl -o app/src/main/assets/baked_color.filamat app/src/materials/baked_color.mat
//
// See build.gradle for an example of how to compile materials automatically
// Please refer to the documentation for more information about matc and the materials system.
material {
name : baked_color,
// Lists the required vertex attributes
// Here we only need a color (RGBA)
requires : [
color
],
// This material disables all lighting
shadingModel : unlit,
featureLevel : 0
}
fragment {
void material(inout MaterialInputs material) {
// You must always call the prepareMaterial() function
prepareMaterial(material);
// We set the material's color to the color interpolated from
// the model's vertices
material.baseColor = getColor();
}
}

View File

@@ -6,6 +6,10 @@ plugins {
project.ext.isSample = true
kotlin {
jvmToolchain(versions.jdk)
}
filamentTools {
materialInputDir = project.layout.projectDirectory.dir("src/main/materials")
materialOutputDir = project.layout.projectDirectory.dir("src/main/assets/materials")
@@ -42,6 +46,11 @@ android {
aaptOptions {
noCompress 'filamat', 'ktx'
}
compileOptions {
sourceCompatibility versions.jdk
targetCompatibility versions.jdk
}
}
dependencies {

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.filament.ibl">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />

View File

@@ -26,6 +26,7 @@ import android.view.animation.LinearInterpolator
import com.google.android.filament.*
import com.google.android.filament.android.DisplayHelper
import com.google.android.filament.android.FilamentHelper
import com.google.android.filament.android.UiHelper
import java.nio.ByteBuffer
@@ -303,6 +304,8 @@ class MainActivity : Activity() {
camera.setProjection(45.0, aspect, 0.1, 20.0, Camera.Fov.VERTICAL)
view.viewport = Viewport(0, 0, width, height)
FilamentHelper.synchronizePendingFrames(engine)
}
}

View File

@@ -6,6 +6,10 @@ plugins {
project.ext.isSample = true
kotlin {
jvmToolchain(versions.jdk)
}
filamentTools {
materialInputDir = project.layout.projectDirectory.dir("src/main/materials")
materialOutputDir = project.layout.projectDirectory.dir("src/main/assets/materials")
@@ -35,6 +39,11 @@ android {
aaptOptions {
noCompress 'filamat', 'ktx'
}
compileOptions {
sourceCompatibility versions.jdk
targetCompatibility versions.jdk
}
}
dependencies {

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.filament.litcube">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"

View File

@@ -29,6 +29,7 @@ import com.google.android.filament.*
import com.google.android.filament.RenderableManager.*
import com.google.android.filament.VertexBuffer.*
import com.google.android.filament.android.DisplayHelper
import com.google.android.filament.android.FilamentHelper
import com.google.android.filament.android.UiHelper
import java.nio.ByteBuffer
@@ -413,6 +414,8 @@ class MainActivity : Activity() {
camera.setProjection(45.0, aspect, 0.1, 20.0, Camera.Fov.VERTICAL)
view.viewport = Viewport(0, 0, width, height)
FilamentHelper.synchronizePendingFrames(engine)
}
}

View File

@@ -3,6 +3,10 @@ apply plugin: 'kotlin-android'
project.ext.isSample = true
kotlin {
jvmToolchain(versions.jdk)
}
android {
namespace 'com.google.android.filament.livewallpaper'
@@ -18,6 +22,11 @@ android {
dependenciesInfo {
includeInApk = false
}
compileOptions {
sourceCompatibility versions.jdk
targetCompatibility versions.jdk
}
}
dependencies {

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.filament.livewallpaper">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-feature android:name="android.software.live_wallpaper" />

Some files were not shown because too many files have changed in this diff Show More