Compare commits

..
4086 Commits
Author SHA1 Message Date
Benjamin Doherty 9e960b7d45 Merge branch 'rc/1.27.0' into release 2022-09-13 10:14:24 -07:00
Ben Doherty 0c54d4a6a1 Add return case to fix G3 compiler error (#6062) 2022-09-12 12:34:56 -07:00
Philip Rideout 526e846a81 gltfio: fix crash when material is unspecified 2022-09-06 22:13:19 -04:00
Philip Rideout 8bcfa373d4 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-06 22:09:25 -04:00
Ben Doherty db9a0f2c1f Fix uberarchive not included in PodSpec (#6024) 2022-09-01 12:18:20 -04:00
Benjamin Doherty 646b1e2193 Bump version to 1.27.0 2022-08-31 12:04:55 -04:00
Benjamin Doherty 41bd30f81d Merge branch 'rc/1.26.0' into release 2022-08-31 12:04:08 -04: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 bd626aea27 material instanced property must be false by default.
this fix auto-instancing.
2022-08-26 18:28:56 -04: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 AgopianandBenjamin Doherty 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
gaborvalasekandLevente Koncz 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 8a03f75485 Bump version to 1.26.0 2022-08-23 12:07:33 -04:00
Benjamin Doherty dc9594fbdf Merge branch 'rc/1.25.6' into release 2022-08-23 12:05:44 -04:00
Benjamin Doherty df3ea47a3c Release Filament 1.25.6 2022-08-23 12:05:06 -04:00
Benjamin Doherty fad0b533c0 Update RELEASE_NOTES for 1.25.6 2022-08-23 12:03:28 -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 4d773e9453 Bump version to 1.25.6 2022-08-16 11:03:07 -07:00
Benjamin Doherty e0c610b013 Merge branch 'rc/1.25.5' into release 2022-08-16 11:01:04 -07:00
Benjamin Doherty 9e87a312ab Release Filament 1.25.5 2022-08-16 10:59:05 -07:00
Benjamin Doherty 0da4f36c33 Bump version to 1.25.5 2022-08-16 10:54:00 -07:00
Ben Doherty 11d17e1db3 Fix SamplerGroup update issue (#5928) 2022-08-16 10:47:18 -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 b8c318d923 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:28 -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 e563cc6f5e gltfio: add 'detach' methods to allow ownership transfer
These new methods allow gltfio to be integrated into internal Google
libraries.
2022-08-09 14:37:44 -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 cb8914ab96 Merge branch 'rc/1.25.4' into release 2022-08-02 11:47:52 -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
Alan Eneev 2fecda7bdc Headless EGL: Fallback to a 24-bit depth buffer 2022-07-29 10:10:46 -07:00
Alan Eneev 543d8efb25 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 10:10:40 -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 396b1079a7 Bump version to 1.25.4 2022-07-26 09:57:34 -07:00
Benjamin Doherty eedcd9f8cb Merge branch 'rc/1.25.3' into release 2022-07-26 09:56:22 -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
Ben Doherty ab252b210c Fix config object related build failures (#5814) 2022-07-26 09:51:55 -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 1071b8ea90 Bump version to 1.25.3 2022-07-18 15:15:03 -07:00
Benjamin Doherty a9c5bbf185 Merge branch 'rc/1.25.2' into release 2022-07-18 15:14:02 -07:00
Benjamin Doherty 2b57ec476d Release Filament 1.25.2 2022-07-18 15:13:37 -07:00
Philip Rideout 8dd4bff7a7 gltfio: minor fixups to prep for g3 integration. 2022-07-18 15:11:36 -07:00
Philip Rideout 77c54446af gltfio: use openLocalTransformTransaction API. 2022-07-18 15:11:30 -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
hzzengxiaoqiandMathias Agopian 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 4a0bc0af57 Bump version to 1.25.2 2022-07-11 15:51:55 -07:00
Benjamin Doherty a171e75e70 Merge branch 'rc/1.25.1' into release 2022-07-11 15:50:10 -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
MasTraERandBenjamin Doherty 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 f5ffa092fe Bump version to 1.25.1 2022-07-06 19:09:34 -07:00
Benjamin Doherty 8de5fdd551 Merge branch 'rc/1.25.0' into release 2022-07-06 19:07:42 -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 ecca3abe98 Bump version to 1.25.0 2022-07-01 12:09:29 -07:00
Benjamin Doherty 8570e35224 Merge branch 'rc/1.24.0' into release 2022-07-01 12:08:48 -07:00
Benjamin Doherty ab2a90374b Release Filament 1.24.0 2022-07-01 12:08:17 -07:00
Benjamin Doherty 84df9f9a03 Update version to 1.24.0 2022-07-01 12:03:38 -07:00
Benjamin Doherty 5f93fb9613 Update RELEASE_NOTES for 1.24.0 2022-06-30 16:37:03 -07:00
Benjamin Doherty 75f77fdbdd Metal: Allow Filament to disregard MTLTexture pixelFormat when importing 2022-06-30 16:04:28 -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
Ben Doherty 7825d582c2 CocoaPods: include uberz library (#5752) 2022-06-30 14:07:55 -07:00
Ben Doherty 5deb0ba933 CocoaPods: include uberz library (#5752) 2022-06-30 14:04:02 -07:00
Philip Rideout ecede1e947 matdbg: fix 4x overallocation for SMOLV blobs 2022-06-30 12:06:53 -07:00
Philip Rideout 18e917aaf2 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:05: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
Benjamin Doherty a165f3890a Vulkan: Support VMA_DYNAMIC_VULKAN_FUNCTIONS off 2022-06-21 15:09:26 -07:00
Philip Rideout f88b6d9c97 Do not trigger UB with string_view. 2022-06-20 21:11:52 -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
Mathias Agopian db8ecd9952 configure render primitive pool so it works with msvc
a 64 bytes pool seems to work with both clang and msvc, unfortunately,
c++ doesn't let us know the allocator object size at compile time
for map containers, so we have to guess.
2022-06-16 13:13:33 -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
Benjamin Doherty b5ec06c2d2 Fix build breakage 2022-06-15 17:05:53 -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
Benjamin Doherty dfbac8385e Merge branch 'rc/1.23.2' into release 2022-06-15 11:49:06 -07:00
Benjamin Doherty eceb72f609 Release Filament 1.23.2 2022-06-15 11:48:40 -07:00
Ben Doherty aad782a15f NoopDriver: return unique handles (#5697) 2022-06-15 11:28:41 -07:00
Ben Doherty eaab737b2c NoopDriver: return unique handles (#5697) 2022-06-15 11:28:08 -07:00
Philip Rideout 378600dc79 Update BlueVK and use Python 3. (#5698)
This will allow us to fix the validation error related to
VK_KHR_portability_enumeration.

Also, macOS comes with Python 3 nowadays so we're upgrading the script
from Python 2.
2022-06-15 10:59:00 -07:00
Philip Rideout d4cc63f120 Fix warning. 2022-06-14 17:04:14 -07:00
Philip Rideout b99fd143f2 Vulkan: fix ReadPixels with 2-component formats. (#5692)
This fixes the OOB seen with picking.
2022-06-14 16:39:50 -07:00
Philip Rideout 8c74430466 Upgrade vkmemalloc from 2.3.0 to 3.0.1 (#5691) 2022-06-14 14:38:55 -07:00
Philip Rideout fc9608a392 Vulkan: check for OUT_OF_DEVICE_MEMORY. (#5690)
Related to #5432.
2022-06-14 12:15:39 -07:00
Mathias Agopian ad731aebcb fix getInstanceIndex()
it would be initialized after user material code was called.
2022-06-14 12:01:23 -07:00
Philip Rideout 15406825aa Update cgltf, remove a morphing constraint. (#5688)
Fixes #5670.
2022-06-14 10:53:45 -07:00
Mathias Agopian 1e17afbefa small optimization that helps avoid bindUniformBufferRange calls
a lot of primitive may use the same UBO slot, if they happen to be
in a sequence, we don't need to rebind the UBO.
2022-06-14 10:24:41 -07:00
Ben Doherty 83334f7567 Always use homogeneous attachment sizes (#5679) 2022-06-14 10:05:23 -07:00
LaiJF 7275957947 Fix typo 2022-06-14 09:35:18 -07:00
Benjamin Doherty 45991cda0a Update RELEASE_NOTES for 1.23.2 2022-06-13 15:27:03 -07:00
Philip Rideout 74765f05bc OpenGL: add WebGL support for ReadPixels. (#5675) 2022-06-13 14:38:15 -07:00
Mathias Agopian bae32a1a5f backend: remove STREAM buffers and add Unsynchronized buffer update API
Unsynchronized update just means that the buffer is updated regardless
if what the gpu is doing, the synchronization is the responsibility of
the caller.

Also added resetBufferObject(), which essentially destroys and reallocate
a buffer for the same handle.
2022-06-13 12:00:32 -07:00
Mathias Agopian 347642985f fix unit tests 2022-06-11 10:09:11 -07:00
Mathias Agopian 6ebaad28b3 cleanup and fixes regarding skinning UBO (#5676)
- rename PerRenderableUibBones to PerRenderableBonesUib to be more
  consistant with other interface block naming.

- make sure the C++ struct and the UBO definition match. 
  PerRenderableBonesUib is a UBO with one bones[256] field, but the
  C++ struct has a single bone and treated the UBO as an array.
  This makes things less confusing.
  We can now use sizeof(PerRenderableBonesUib) in many places which
  better expresse what we are doing.

- Fix an off-by-one assert when setting a skinning buffer to a renderable

- Asserts that no more than 256 bones are associated to a renderable

- improve documentation and fix some typos
2022-06-10 15:03:41 -07:00
Philip Rideout 9508bf2a0c Expose picking to JavaScript, use it in helmet demo. (#5678) 2022-06-10 13:46:39 -07:00
Philip Rideout 68c6253b3f gltf_viewer: exercise picking functionality. 2022-06-10 13:45:28 -07:00
Mathias Agopian 803ce07701 Always access object uniforms via getObjectUniforms()
We no longer use the hardcoded objectUniform UBO name, instead, we 
access the object uniforms through the new getObjectUniforms().

Because it's not possible to return a "Uniform Block" from a function
in GLSL, a large part of this change, is to replace the interface block
by a structure.


Note: getObjectUniforms() is not public, but it is used by gltfio to
access the userData field, which is also not public at the moment.
2022-06-10 09:13:18 -07:00
Mathias Agopian 95d3b19ced Allow UniformInterfaceBlock to have arrays of size 1 2022-06-10 09:13:18 -07:00
Mathias Agopian cc97a62587 DEPTH commands are now instancing friendly
DEPTH commands are now sorted just like COLOR commands, that is,
they use a 10 bits z-bucket and the material id in the sorting key.
This allows instance-able primitives to be sorted next to each other.
2022-06-10 09:13:18 -07:00
Philip Rideout 434144eef2 Fix morphing with sparse accessors.
We were not leveraging `cgltf_accessor_unpack_floats` in a few spots,
this was a mistake.

Fixes #5651.
2022-06-09 16:46:17 -07:00
Philip Rideout 09a016bb6f Remove an 'API Change' warning from one item. 2022-06-09 14:33:49 -07:00
Philip Rideout adf894a5bc iOS: add --quiet when running cmgen. 2022-06-09 14:31:24 -07:00
Philip Rideout 5e4025bd4c UbershaderProvider now takes a custom archive in its constructor.
We still use resgen for convience, but the archive is now passed in
from the client application.

This will allow us to shrink the gltfio Android library (stay tuned).
2022-06-09 14:31:24 -07:00
Mathias Agopian 9f8af21ad7 fix typo 2022-06-08 17:26:04 -07:00
Mathias Agopian 61e117beaa Added a new instanced material parameter
This boolean parameter is used with materials that need to access 
`getInstanceIndex()` (filament's equivalent to `gl_InstanceIndex`).
It is false by default, and getInstanceIndex() is not accessible.
This is intended to be used in concert with
`RenderableManager::Builder::instances()`.
2022-06-08 17:10:38 -07:00
Philip Rideout ec86fe4e33 Do not trigger UB with string_view. 2022-06-08 12:40:42 -07:00
Philip Rideout 3c29ec5c8e Repair debug builds. 2022-06-08 09:28:58 -07:00
LaiJF de32fc83a4 fix typo 2022-06-08 09:19:38 -07:00
Philip Rideout 51e8a83234 Remove uberz <=> filament dependency, move ArchiveCache. 2022-06-08 08:56:49 -07:00
Philip Rideout b8163b7949 Fixup to "gltfio: remove poorly maintained lite flavor" 2022-06-07 08:44:57 -07:00
Philip Rideout 30dbd3ac4f Rename gltfio to filament::gltfio. 2022-06-06 16:25:02 -07:00
Philip Rideout 0ae83a6c97 gltfio: Rename all plugin classes to have "provider" suffix.
UbershaderLoader  => UbershaderProvider
    MaterialGenerator => JitShaderProvider
2022-06-06 16:25:02 -07:00
Mathias Agopian 5ee54aa4ef Revert "Workaround: partially revert "don't issue a flush..." (#5557)"
This reverts commit c049a1 and reenables commit b2cdf9:

    "don't issue a flush systematically after framegraph's execute"
2022-06-06 16:24:31 -07:00
Mathias Agopian 56e7ae1d56 disable timer queries on some version of Mali-Gxx drivers 2022-06-06 16:24:31 -07:00
Mathias Agopian 39332a92ed configure render primitive pool so it works with msvc
a 64 bytes pool seems to work with both clang and msvc, unfortunately,
c++ doesn't let us know the allocator object size at compile time
for map containers, so we have to guess.
2022-06-06 16:20:22 -07:00
Benjamin Doherty 31607d355d Bump version to 1.23.2 2022-06-06 15:18:57 -07:00
Benjamin Doherty a67d50b9e2 Merge branch 'rc/1.23.1' into release 2022-06-06 15:16:53 -07:00
Benjamin Doherty 6a82f8090e Release Filament 1.23.1 2022-06-06 15:16:20 -07:00
Benjamin Doherty 8d42f53c80 Update RELEASE_NOTES for 1.23.1 2022-06-06 15:14:59 -07:00
Benjamin Doherty 5e21a55bce Revert "iOS: implement headleass swapchain (#5486)"
This reverts commit 0e5ba60cb6.

This causes issues in G3, still need to investigate the root cause.
2022-06-06 13:17:04 -07:00
Philip Rideout 5860e7fdce Add support for ubershader archives.
An ubershader archive is a bundle of filamat packages with some metadata
that conveys which glTF features each material supports.

This PR does three things:

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

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

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

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

In a subsequent PR, we will remove the `gltfio_resources` target and
change the signature of `createUbershaderLoader` so that it takes
an archive.
2022-06-06 13:13:22 -07:00
Philip Rideout 22c3ba2466 gltfio: remove poorly maintained lite flavor 2022-06-06 13:13:22 -07:00
LaiJF 4e260ba3dc Fix typo (#5648) 2022-06-06 12:07:13 -07:00
Ben Doherty 49674c39e8 Metal: fix invalid MSL generated due to missing optimization pass (#5640) 2022-06-03 16:22:06 -07:00
Ben Doherty 23174d56f5 Remove merge conflict line from RELEASE_NOTES 2022-06-03 15:23:50 -07:00
Mathias Agopian 5ff3e85d10 reserve 128 entries in ResourceAllocator
this improves performance quite a bit by reducing heap allocations.
2022-06-03 14:55:22 -07:00
Mathias Agopian 2242ddfbec Add a basic stopwatch class
this can be used for basic timing.
2022-06-03 14:55:22 -07:00
Mathias Agopian 69ec5f9720 Fix WGL requested context attributes
Fixes #5611
2022-06-03 14:54:54 -07:00
Mathias Agopian 6162782bee PrimitiveFactory: fix typo and reserve 256 entries 2022-06-03 14:54:37 -07:00
Ben Doherty 599b2ef377 GitHub Actions: verify RELEASE_NOTES is updated for each PR (#5633) 2022-06-03 12:11:26 -07:00
Mathias Agopian 7aa3b1a6ee merge identical backend RenderPrimitives together
This is done in RenderPrimitiveFactory using a bidirectional associative
container.

This is a necessary step toward auto instancing.
2022-06-03 11:43:00 -07:00
Mathias Agopian 718e7ab064 remove a bunch of <functional> includes
This forces us to use an explicit hash class in a few place, but it
is cleaner.

remove utils::lower_bound and utils::upper_bound, which were not used.
2022-06-03 08:35:57 -07:00
Mathias Agopian 991fa0cf7d disable user scissor while rendering the shadowmaps
fixes #5607
2022-06-03 08:33:40 -07:00
Philip Rideout e81d053f35 gltfio: fix morphing for non-packed floats. 2022-06-03 07:54:42 -07:00
Josh Faust 211cf2b64c Remove NSOpenGLPFANoRecovery requirement when creating the NSOpenGLContext (#5626) 2022-06-01 15:40:54 -07:00
Philip Rideout 5837adf45f Remove stale comment and update the debugging doc. 2022-06-01 15:02:55 -07:00
Benjamin Doherty 85930ea2e8 Bump version to 1.23.1 2022-06-01 14:58:29 -07:00
Benjamin Doherty 9bb6ce5f1d Release Filament 1.23.0 2022-06-01 14:56:11 -07:00
Benjamin Doherty 4b3cde8b39 Merge branch 'rc/1.23.0' into release 2022-06-01 14:55:20 -07:00
Benjamin Doherty eedfa85355 Update RELEASE_NOTES for 1.23.0 2022-06-01 14:54:50 -07:00
Benjamin Doherty bb54c6c807 Release Filament 1.23.0 2022-06-01 14:53:48 -07:00
Benjamin Doherty c23f905858 Update RELEASE_NOTES for 1.23.0 2022-06-01 14:53:23 -07:00
Romain Guy ab9dbb22cc Remover prebuilt MoltenVK (#5623) 2022-06-01 14:49:50 -07:00
Ben Doherty 2a84fe052c Metal: fix blitting when render target is smaller than texture (#5616) 2022-06-01 14:47:57 -07:00
Philip Rideout 140ebbf10d Repair Android and iOS builds. 2022-06-01 13:09:47 -07:00
Philip Rideout 00ecba67b5 Clean up BasisU CMake targets, add zstd target.
We were re-building various C++ files in three different targets
(basis_encoder, basis_transcoder, basisu executable), it's probably
better just to set up proper dependencies between the libraries.  Note
that I'm not sure if this actually improves build times.

More importantly, this creates a CMake target for the zstd library
because we want to use zstd in other places.
2022-06-01 13:09:47 -07:00
Mathias Agopian beb8fd9893 HwRenderPrimitive is now immutable 2022-06-01 12:46:45 -07:00
Mathias Agopian cc7d88c033 remove RenderManager::setGeometryAt() that only sets offset/count
This is an API breakage, but the "full" setGeometryAt() can usually be 
used instead.
2022-06-01 12:46:45 -07:00
Romain Guy f85103af9d Remove unnecessary binaries (#5621) 2022-06-01 12:38:22 -07:00
Philip Rideout 6471efb3a5 Fix warnings. 2022-06-01 09:18:34 -07:00
Philip Rideout f2e36c35a4 gltfio ubershader mode: set sheen to OPAQUE.
This makes ubershader mode more consistent with jit mode.

SheenChair and ToyCar in the samples repo both have opaque cloth.
2022-05-31 15:19:57 -07:00
Mathias Agopian 2eaacd7cb8 fix overallocation by about 17MB
In practice on most systems this would only consume address space,
since most of those pages won't be accessed.

fixes #5608
2022-05-31 14:50:35 -07:00
Benjamin Doherty 8c7be0a1d0 Revert "iOS: implement headleass swapchain (#5486)"
This reverts commit 0e5ba60cb6.

This causes issues in G3, still need to investigate the root cause.
2022-05-31 11:29:38 -07:00
Mathias Agopian cc51d478f8 extend blendOrder functionality
blendOrder was used to control the draw order of blended render
primitive within a Renderable. We now have an option to make the
blend order global, in this case those primitives with a global blend
order are always sorted solely using the blend order value (i.e. the 
distance from the camera is not take into account).
2022-05-31 09:30:36 -07:00
LaiJF a844dc96eb Fix typo 2022-05-31 09:12:36 -07:00
LaiJF e92a684b26 #endif comment match the macro name (#5609) 2022-05-30 21:21:54 -07:00
Philip Rideout a5648de486 Repair macOS build breakage, hopefully.
Not only did I forget to patch the spirv-heades CMake file, I also
messed up the patch file while trying to manually update it.  This
should fix it.
2022-05-26 13:00:46 -07:00
Philip Rideout 88dc25229b Update spirv-tools to get new code folding optimization.
This change includes a fix for an issue we filed against spirv-tools:
https://github.com/KhronosGroup/SPIRV-Tools/issues/4371

So, it should reduce the number of extraneous matrix copies in finalized
GLSL code.

I did quick size total of all filamat files (*) before and after this
update, it went from 11.3 MB to 11.1 MB.

(*) All backends are enabled, includes built-in Filament shaders and
gltfio ubershaders.
2022-05-26 11:40:38 -07:00
daemyung jang ddd93874cc Use the proper variable name to enhance the redability (#5602) 2022-05-25 18:12:51 -07:00
Philip Rideout 609c0482be gltfio: allow dynamic attach / detach for bones (#5601)
Sceneform allowed users to attach and detach bones, so this seems like
a useful feature.

Fixes #3075
2022-05-25 16:03:44 -07:00
Dom Corvasce 92acdff6cb Add JS bindings for Texture class methods (#5598)
* Add JS bindings for Texture class methods

This change introduces bindings for the following methods:
- getWidth
- getHeight
- getDepth
- getLevels

Closes 4492

* Mark level arguments as optional

* Revert docs defs

* Revert docs/webgl/filament.js
2022-05-25 13:01:28 -07:00
Mathias Agopian 292fd7d41f don't allocate more than 16KiB in the command stream
if we have more than 16K of UBO data, we now use a "out of band" buffer
on the heap instead of the command stream, which has limited space.

to minimize the heap allocation we use a simple pool allocator that
recycles a few heap buffers (per Scene).
2022-05-25 12:07:59 -07:00
Mathias Agopian 1af76638cf rework per renderable ubo update
We now store the per renderable ubo data in the scene SoA before sending
to the gpu. This is needed to prepare future work on instancing.
2022-05-25 12:07:59 -07:00
dependabot[bot] bf875554e1 Bump pyjwt from 2.3.0 to 2.4.0 in /build/common (#5596)
Bumps [pyjwt](https://github.com/jpadilla/pyjwt) from 2.3.0 to 2.4.0.
- [Release notes](https://github.com/jpadilla/pyjwt/releases)
- [Changelog](https://github.com/jpadilla/pyjwt/blob/master/CHANGELOG.rst)
- [Commits](https://github.com/jpadilla/pyjwt/compare/2.3.0...2.4.0)

---
updated-dependencies:
- dependency-name: pyjwt
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-05-25 12:07:09 -07:00
Philip Rideout 2b91799ee0 More skinning cleanup + minor fix.
This contains a fix for a hypothetical bug with models that have bones
that do not belong to any gltf scene.
2022-05-25 11:32:31 -07:00
Philip Rideout 2947229d40 gltfio: Streamline the AABB + skinning computation.
This optimizes and cleans up some code from a 3P contributor.

When computing a bounding box, there was no need for an inner loop
through the entire skins array.

Tested using the torus model in #4973 and the `-r` flag in gltf_viewer.
2022-05-25 10:44:31 -07:00
Benjamin Doherty 878497b3d5 Bump version to 1.23.0 2022-05-24 15:19:51 -07:00
Benjamin Doherty a155561769 Merge branch 'rc/1.22.2' into release 2022-05-24 15:17:55 -07:00
Benjamin Doherty 648314d730 Release Filament 1.22.2 2022-05-24 15:17:19 -07:00
Philip Rideout fc3c3376b7 Morphing API docstring fixups.
I think the most important thing here is that we now let users know that
"offset" is not a byte count.  This also fixes some small typos, e.g.
"weights" was used in the docstring instead of "positions".

To avoid making API changes, this does not fix a few weird things I
noticed in the Java API. For example, there is a redundant "count"
argument in methods that take an array.  Also some methods do not
provide an "offset" argument, which is not consistent with C++.
2022-05-24 15:03:45 -07:00
Philip Rideout fcbc6d43a1 Fix morphed normals.
Our `morphNormal` GLSL function treats each normal target as a
displacement from the base normal (similar to the glTF spec) but the
normal that is extracted from the tangent frame is actually an absolute
normal.

In other words, if b is the base normal, we were doing:

    b = b + w0 * n0 + w1 * n1 + ...

This is obviously wrong, since the base normal has an overpowering
influence.

The fixed math looks like this:

    b = b + w0 * (n0 - b) + w1 * (n1 - b) + ...

Fixes #5584.
2022-05-24 15:03:30 -07:00
Philip Rideout a01fa21209 gltfio: introduce cross-fade animation API
Fixes #4754
2022-05-24 13:22:21 -07:00
Benjamin Doherty 8b86a0ed2e Revert "iOS: implement headleass swapchain (#5486)"
This reverts commit 0e5ba60cb6.

This causes issues in G3, still need to investigate the root cause.
2022-05-24 20:13:10 +00:00
Mathias Agopian 60a6d4a348 pack PerRenderableUib a bit more so it occupy 128 bytes
We pack PerRenderableUib so that we could (in the future) store two
renderable datum per slot (each slot is required to be 256 bytes).
2022-05-24 10:16:16 -07:00
Mathias Agopian 6c740f060e move skinning info into PrimitiveInfo
By design we shouldn't access the scene SOA when executing the 
high level commands.

This change increases the size of a command to 64 bytes and 
PrimitiveInfo to 48 bytes (both with some small padding left).
2022-05-24 10:16:16 -07:00
daemyung jang 5a8bf42ddb Delete redundant semicolons 2022-05-24 09:46:46 -07:00
daemyung jang c8cc74e384 Fix not calculating the normal while morphing in the legacy path 2022-05-23 16:00:57 -07:00
Benjamin Doherty 26f9a9b122 Update RELEASE_NOTES for 1.22.2 2022-05-23 12:40:47 -07:00
Philip Rideout c82ae6a3a7 beamsplitter: add recursive descent parser
This removes usage of regexps from the parsing phase and splits the
program into three sub-packages: parser, database, and emitters.

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

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

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

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

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

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

This is a big change but it is a no-op in terms of the generated code.
2022-05-23 09:36:29 -07:00
daemyung jang fbc43d24fe Delete a redundant semicolon 2022-05-21 16:40:14 -07:00
Philip Rideout c0f8f3bdfe beamsplitter update 2022-05-21 11:57:18 -07:00
Ben Doherty 3461ec863b gltfio: Clear texture caches before loading resources (#5580)
* gltfio: Clear texture caches before loading resources

* iOS gltf-viewer: add double-tap to reload model for debugging

* iOS samples: add instructions on ASan / UBSan debugging
2022-05-20 11:41:24 -07:00
Ben Doherty 035f162ebc iOS: small improvements to sample projects (#5579)
- Ensure C++17 is used to compile sample projects
- Upgrade to the latest Xcodegen and re-generate projects
- Add a bundle ID disambiguator so users don't need create unique bundle Ids when opening sample projects
- Add a simple generate-samples.sh script
2022-05-19 15:50:51 -07:00
Ben Doherty 6754885795 imageio: Remove unnecessary dependency (#5574) 2022-05-19 11:16:53 -07:00
Ben Doherty 42e4e5e3ae Only build basisu tool on host platforms (#5575) 2022-05-19 11:16:37 -07:00
Ben Doherty 71a0f46b73 Add ktxreader and viewer libs to CocoaPods (#5573) 2022-05-18 16:25:17 -07:00
Ben Doherty 6e5f6978fb Add ktxreader and viewer libs to CocoaPods (#5573) 2022-05-18 16:24:51 -07:00
Ben Doherty 0d31d7b2de Add ktxreader and viewer libs to CocoaPods (#5573) 2022-05-18 16:13:26 -07:00
Philip Rideout 5f52afdc08 View.java now uses generated code.
The API is the same but there are some minor differences, which include:

- Ordering of fields in AmbientOcclusionOptions
- More @NonNull annotations that we forgot
- Javadoc formatting is different
2022-05-18 13:40:44 -07:00
Philip Rideout 54706ad65e Reorder items in View.java to prep for beamsplitter. 2022-05-18 13:40:44 -07:00
Philip Rideout a96d5932a8 beamsplitter: finalize codegen for View.java
Note that JNI c++ functions are not generated.  The setter / getter
methods are also manually maintained.
2022-05-18 13:40:44 -07:00
Mathias Agopian 41c5615201 fix trailing zero when setting shader sources
the shader source blob's size included the null terminating character,
which ended up being passed to the opengl/metal API.
2022-05-18 11:52:30 -07:00
Romain Guy 719427764c Fix image_viewer (#5571)
Many EXR files may contain negative values, we don't want to output
those to our color buffer.
2022-05-17 19:59:41 -07:00
Benjamin Doherty dd862b7e0a Bump version to 1.22.2 2022-05-17 18:03:38 -07:00
Benjamin Doherty 52065f2cbd Merge branch 'rc/1.22.1' into release 2022-05-17 18:01:37 -07:00
Benjamin Doherty 887fb82cf2 Update RELEASE_GUIDE 2022-05-17 17:59:40 -07:00
Benjamin Doherty 0c78e91aed Release Filament 1.22.1 2022-05-17 17:59:32 -07:00
Ben Doherty 62a234a8f9 Add package name back to AndroidManifest.xml to fix G3 (#5569) 2022-05-17 17:53:16 -07:00
Benjamin Doherty 77c02d5831 Update RELEASE_NOTES for 1.22.1 2022-05-17 17:51:37 -07:00
Ben Doherty f7e4c8d16d Add package name back to AndroidManifest.xml to fix G3 (#5569) 2022-05-17 17:51:21 -07:00
Philip Rideout 29086cee14 Java minor API change: blendingMode => blendMode. (#5567) 2022-05-17 16:46:59 -07:00
Philip Rideout 16369255e2 beamsplitter: progress with Java codegen. (#5564) 2022-05-17 13:59:52 -07:00
Philip Rideout b3e9940625 Java minor API change: ssctStartTraceDistance => ssctShadowDistance (#5566)
This makes Java match better with C++ and helps prepare for
autogenerated Java bindings.
2022-05-17 12:24:34 -07:00
Philip Rideout c04f3e4f00 Web glTF Viewer: Use pinned version, update release procedure. (#5565) 2022-05-17 11:55:53 -07:00
Philip Rideout 13f7c71bf2 Update latest web viewer. 2022-05-17 09:46:31 -07:00
Philip Rideout b7410474ff Workaround: partially revert "don't issue a flush..."
This is a temporary workaround for a memory corruption issue observed on
some devices from a specific vendor. We will try to make this workaround
more targeted in a subequent change.

Partial revert for b2cdf9f2b4.
2022-05-16 10:39:55 -07:00
Philip Rideout eae55c1be8 matdbg: fix several issues uncovered by ASAN (#5558)
There were two places where we were doing unaligned reads: one when
computing the hash for the material identifier, and one when parsing
the chunk in ShaderReplacer.

We also had a potential overflow since civetweb does not add a trailing
null to incoming WebSockets messages.
2022-05-16 10:17:12 -07:00
Philip Rideout d6588bd382 beamsplitter: decouple parser from emitters (#5561)
This moves parser into a subpackage to shield it from the various
emitters (this folder structure is similar to what Rob Pike used for his
text templating library). This also adds a WIP Java code generator,
currently disabled.
2022-05-16 09:48:32 -07:00
Mathias Agopian 3343f2459d fix FSR upscaling offset on metal/vulkan
The FSR API documentation is a bit misleading, it expects offsets
with different origin depending on the backend API.
2022-05-16 09:38:04 -07:00
Mathias Agopian 78679338d7 cleanup blitting passes
We now have 3 public APIS:

- opaqueBlit() which is used for basic blitting and scaling and
  supports sub-resources.

- blit() which is used for blitting + composition
  - can optionally perform basic scaling
  - doesn't support sub-resources

- upscale() which is used for high quality upscaling
  - can do composition (blending)
  - doesn't support sub-resources
2022-05-16 09:38:04 -07:00
Philip Rideout c049a1bfff Workaround: partially revert "don't issue a flush..." (#5557)
This is a temporary workaround for a memory corruption issue observed on
some devices from a specific vendor. We will try to make this workaround
more targeted in a subequent change.

Partial revert for b2cdf9f2b4.
2022-05-13 12:15:12 -07:00
Philip Rideout f311453aed gltfio: use ifstream::binary for external resources (#5555)
Fix #5553
2022-05-13 09:04:27 -07:00
Philip Rideout c67e5b6047 beamsplitter: refactorings and enhancements. (#5550)
We now store block-level comments and check for template errors.
Previously if a template had a syntax error, it would silently quit.
2022-05-12 20:12:31 -07:00
Ben Doherty 7ed315e8ab Complete the OGL backend's stencil support and add test case (#5457) 2022-05-12 19:35:12 -07:00
Philip Rideout 1d223498cb beamsplitter: rename the tool, enhance the README. (#5549) 2022-05-12 17:07:40 -07:00
Philip Rideout cbcaae6537 codegen: improve parsing of struct field types (#5548) 2022-05-12 13:54:28 -07:00
Philip Rideout b8705198c0 codegen: improve handling of enums (#5546) 2022-05-12 13:53:31 -07:00
Philip Rideout bef3c85ebf codegen: do not hardcode the View namespace. (#5547) 2022-05-12 13:52:54 -07:00
Mathias Agopian 2709533fb1 Fix texture coordinate calculations in post-process materials
The most important change here is that we no longer apply the
backend (e.g. Metal/Vulkan) UV transformation before calling the
user's vertex shader. This is an API change for post-process materials
(but they're not public).
Now the user is responsible for using uvToRenderTargetUV() in their
shaders (either in the fragment or vertex as appropriate).

This makes it easier to handle offsets/transforms with all APIs.

Conceptually, the only thing that is needed is to call 
uvToRenderTargetUV() just before making a texture call.


This fixes a couple of issues:
- some image shifting in metal/vk
- flare in metal/vk was upside down

We also simplify the DoF code quite a bit now that we can rely on the
rendertargets begin multiple of 16.

We also "fix" SSAO that was working by accident on  metal/vk. The UV
correction was applied 3 times 2 of which were canceling each other.
2022-05-12 13:42:13 -07:00
Philip Rideout e3854f5c58 Use codegen for TypeScript definitions. (#5542)
This is a bit fancy because it modifies a file rather than generating
one from scratch.
2022-05-12 08:48:03 -07:00
Pei Jia edb9ca71e5 included header files are now in alphabetic order 2022-05-11 15:04:53 -07:00
Pei Jia ad9ce72f61 header files added, for compatibility of clang c++17. Don't forget to add -std=c++17. 2022-05-11 15:04:53 -07:00
Philip Rideout 78f2065b6f Use generated code for JSON serialization of Options. (#5541) 2022-05-11 10:47:03 -07:00
Mathias Agopian a18013c8f4 fix a memory leak in Invocable 2022-05-11 10:22:04 -07:00
daemyung jang b7787b9a1a Fix a memory leak (#5539)
Delete the resource loader when the application is terminated.
2022-05-11 09:27:27 -07:00
Philip Rideout 63cfb817d7 Use generated code for all "Options" JS bindings. (#5536)
TypeScript bindings and Java are still TBD.
2022-05-11 08:02:35 -07:00
Philip Rideout a572a10ef7 Add codegen golang program. (#5534)
This adds a code generator, implemented in Go.

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

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

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

The generated code is not yet used, stay tuned.
2022-05-10 14:40:51 -07:00
Romain Guy e2255e45d8 Update C++ flags 2022-05-10 14:32:58 -07:00
MinWoo Kim 0e5ba60cb6 iOS: implement headleass swapchain (#5486) 2022-05-10 14:19:52 -07:00
Romain Guy f78d131015 Updates docs 2022-05-10 08:31:58 -07:00
Benjamin Doherty 384cc4ebf6 Bump version to 1.22.1 2022-05-09 13:09:39 -07:00
Benjamin Doherty bf63baad53 Release Filament 1.22.0 2022-05-09 13:08:55 -07:00
Benjamin Doherty 7c0643f122 Merge branch 'rc/1.22.0' into release 2022-05-09 13:07:07 -07:00
Benjamin Doherty 58abae3067 Release Filament 1.22.0 2022-05-09 13:07:02 -07:00
Benjamin Doherty 4742693869 Update RELEASE_NOTES for 1.22.0 2022-05-09 13:04:55 -07:00
Romain Guy f229aaa7c4 Upgrade Android tools (#5533)
* Upgrade Android tools

NDK 24
AGP/Gradle 7.2
Kotlin 1.6.21
Coroutines 1.6.1

* Force Java 8 to run sdkmanager
2022-05-09 12:12:14 -07:00
Philip Rideout bf34ee6e22 gltfio: add multi-scene support. (#5524)
* Add multi-scene support to gltf_viewer.

To test this, I generated a multi-scene asset as follows.

```
gltf-transform merge Avocado/glTF/Avocado.gltf \
    BarramundiFish/glTF/BarramundiFish.gltf \
    ~/Desktop/Merged.gltf
```

* Specify c++17 in pbxproj files.
2022-05-09 11:55:32 -07:00
Philip Rideout a68a478bf3 Introduce gltfio::NodeManager, remove some robin_map. (#5522)
* Introduce gltfio::NodeManager, remove some robin_map.

* Incorporate code review feedback.
2022-05-06 16:14:56 -07:00
Mathias Agopian 626beee345 Implement an optional guard band for screen-space effects
When the guard band is enabled, the effective rendering area is
increased by a certain amount (currently 16 pixels on each side) so
that screen-space effects (e.g. SSAO, SSR, DoF) behave better around
the edges of the screen. Of course, this comes at a performance and
memory cost.

Currently the guard band is not configurable other than being optional.

Added c++, java and js bindings.
2022-05-06 16:08:32 -07:00
Philip Rideout f40ef6209b Repair 32 bit build. 2022-05-06 13:15:52 -07:00
Philip Rideout c4c8399247 Fix Vulkan y offset in blit + add backend tests.
This also removes clipping of the blit rectangle that occurred in the VK
backend that is no longer necessary. There's also no need to assert
since validation will catch out-of-bounds blitting.

Reverts the clipping in acdb8addfd.
2022-05-06 09:19:23 -07:00
Mathias Agopian 7baffe34ac fix a crash in assetloader
use std::partition instead of std::sort to partition the entities 
such as the renderables are first.
2022-05-06 09:00:54 -07:00
Mathias Agopian 434dce2b9f fix extra unnecessary blit
we were not reseting the active region after passes that "resolve" the
guard bands, causing an extra blit to cause that resolving.
2022-05-05 12:57:15 -07:00
Mathias Agopian a76e74fb09 Add presentation time to Renderer
Also deprecate some fields of DisplayInfo this shouldn't be a problem
because they were not actually used.


This change should allow an external-to-filament code to manage 
frame pacing (e.g. something like swappy).
2022-05-05 11:11:41 -07:00
Philip Rideout f39815393a Fix crash regression with gltf_viewer and gltf_instances. 2022-05-05 09:42:08 -07:00
Philip Rideout 9031babd92 Various glTF-related cleanup and enhancements.
- For completion, FilamentAsset now has getRenderableEntities(). This is
  similar to sister methods getLightEntities() and getCameraEntities()
  except there is no need to store a separate array.

- The web helmet demo does not need to enable shadows, they are already
  enabled.

- The ViewerGui populateAsset() method was doing two things that are
  now decoupled for clarity: setAsset() and populateAsset().

- The updateRootTransform() method is now called only when the autoscale
  checkbox is toggled, instead of every frame.

- The getFooEntities() methods in Java now skip doing work for empty
  lists. Actually these should not return arrays at all, but let's fix
  that later, since it will break backwards compatibility.
2022-05-04 13:53:28 -07:00
Mathias Agopian c608f6ad79 mostly include cleanups 2022-05-04 12:09:55 -07:00
Ben Doherty efec4e1adc Metal: add RelaxedtoHalfPass for improved ALU performance (#5504) 2022-05-04 11:13:28 -07:00
Mathias Agopian ebd5f150c1 fix a potential threading/memory corruption
We can't call prepareProgram() from any thread, since it is calling
into the backend. When we had more than a certain number of commands,
we would use the jobsystem to generate them and so prepareProgram()
could end up being called from a jobsystem thread.

This is fixed by looping through all the commands once they're generated
and calling prepareProgram() then.
2022-05-03 15:16:11 -07:00
Philip Rideout 156dcb54e8 gltf_viewer: fix accidental removal of camera selector. 2022-05-03 14:33:43 -07:00
Mathias Agopian 88ef76989c Cleanup Renderer.cpp
The main changes are:

- ColorPass() and RefractionPass() are now static and moved into a 
  new RendererUtils file. These methods don't need FRenderer and are 
  more like a big "script".

- Cleaned-up includes

- Reformatted/reordered methods
2022-05-03 14:27:48 -07:00
Philip Rideout fc284af684 Rename SimpleViewer to ViewerGui.
The SimpleViewer C++ class was not viewer component like `ModelViewer`
and `<filament-viewer>`. It was actually just the UI builder used
in the `gltf_viewer` desktop app and the remote Android interface.
2022-05-03 08:10:53 -07:00
Philip Rideout 3a8685cd15 Upgrade emsdk to 3.1.9 2022-05-03 08:10:26 -07:00
Philip Rideout f035655f5b Add support for KHR_texture_basisu.
This adds a new implementation of the TextureProvider interface called
Ktx2Provider.

Tested using the KTX2 variant of the StainedGlassLamp model in the
Khronos samples repo.

Tested on WebGL 2.0 (Chrome v100), Android (Pixel 6 Pro), and Desktop
(Metal, OpenGL, and Vulkan via MoltenVK).
2022-05-02 13:15:56 -07:00
Ben Doherty f498e08d1e Update hello-pbr to work in all orientations (#5488) 2022-05-02 14:41:32 -04:00
Philip Rideout db3186a65f Remove etc2comp and astcenc from the repo. 2022-05-02 11:29:19 -07:00
Philip Rideout 248815a3e0 Fix regression with <filament-viewer>. 2022-05-02 11:09:26 -07:00
Benjamin Doherty 6c39e474ea Bump version to 1.22.0 2022-05-02 13:19:43 -04:00
Benjamin Doherty 5c8977c906 Merge branch 'rc/1.21.3' into release 2022-05-02 13:18:06 -04:00
Benjamin Doherty ebb62b5d55 Release Filament 1.21.3 2022-05-02 13:17:33 -04:00
Benjamin Doherty 6b3cc2e2f3 Update RELEASE_NOTES for 1.21.3 2022-05-02 13:12:51 -04:00
Philip Rideout b9a5ad205a Fix unit test failures.
Basis does not support DXT3 so in the past this unit test passed only
due to the enum translation bug that was recently fixed.
2022-05-02 09:48:36 -07:00
Philip Rideout 100986d8d9 Fix WebGL debug build (assert with 3-channel images) 2022-04-29 16:30:14 -07:00
Philip Rideout b7c9a36d57 Ktx2Reader: Fix error in enum translation table.
This caused DXT5 content to be interpreted as DXT3 by the GPU,
which seemed to manifest as visual artifacts in the alpha channel.
2022-04-29 16:29:53 -07:00
Philip Rideout d76551ab28 Add async interface to Ktx2Reader. 2022-04-29 14:20:57 -07:00
Mathias Agopian 92bc0752d1 repair VSM gaussian blur
When there was more than one shadowmap we would hit an assert. This 
bug was introduced recently and was due to incorrect use of the 
framegraph.
2022-04-29 12:46:37 -07:00
Mathias Agopian 657c251463 Ensure we always have 4 "safe" mip levels
A "safe" mip-level is one that has exactly half the dimensions of
the current level. In other words, we guarantee that we can halve the
dimensions 4 times without loss (i.e. odd dimension).

This is achieved by effectively padding the viewport (i.e. making the
viewport's dimensions multiple of 16). The post-processing passes
eventually take care of cropping the extra padding so the final
image is unchanged.

This is a more generic solution to dynamic resolution padding, helps
with memory allocations and helps all the algorithms that depend on
mipmaping (e.g. DoF, SSAO, Bloom).


One important improvement brought by this change is that all "final"
post-processing effects are now able to handle a sub-region of the
source, including: color-gradding, fxaa and upscaling.
2022-04-29 12:05:08 -07:00
Philip Rideout b6b8fee483 WebGL: fix isTextureFormatSupported for ETC2 formats.
It was assumed that ETC2 is supported on all ES3 devices, but WebGL on
desktop machines does not support ETC2.

Note that WebGL has its own special extension strings for compressed
textures.
2022-04-29 12:04:59 -07:00
Mathias Agopian be5b60f895 cleaner handling of shadow related uniforms
Some uniforms are needed during shadow map generation, other
during shadow sampling (color pass). We didn't have a clear separation
between them and ended up setting the UBOs that were needed only for
sampling multiple times during generation.
2022-04-29 12:04:47 -07:00
Mathias Agopian 681d31758f move the ShadowUib out of View into ShadowMapManager 2022-04-29 12:04:47 -07:00
Ben Doherty 76b2edd6ea Move toCompressedFilamentEnum to Ktx1Reader header (#5493) 2022-04-29 14:50:24 -04:00
Ben Doherty 80dc2f5c9d Move toCompressedFilamentEnum to Ktx1Reader header (#5493) 2022-04-29 14:49:54 -04:00
Mathias Agopian ce7dd7a1fb reorganize again our main UBO
- try to sort data by usage.
- clarify what post-process materials have access to (not enforced yet)
2022-04-28 10:13:20 -07:00
Mathias Agopian 85617c96a2 shrink post-process materials a bit
post-process materials don't need common_shadowing nor common_shading.

also don't rely on MIN_ROUGHNESS in .mat files, because it's not public.
2022-04-28 10:13:20 -07:00
Mathias Agopian 58760adb6a fix typo introduced in previous PR. fixes froxels. 2022-04-27 17:28:16 -07:00
Mathias Agopian 4ef0b72773 rearrange the per-view UBO (breaks materials)
- rename common_math and common_shadowing from .fs to .glsl
  because they were both included in both vertex and fragment
  shaders

- add getFragCoord() which always returns coordinates in the
  glsl convention. This is useful when used with RNGs to get
  consistant results accross backends.
2022-04-27 15:27:47 -07:00
Mathias Agopian 45631c3b81 update binding points from 8 to 12. 2022-04-27 15:27:03 -07:00
Mathias Agopian 6f6dde2579 Optimize custom rendertargets use in Renderer
we just store the "sampleable" attachments as a bitmask in 
RenderTarget instead of computing it each time.
2022-04-27 15:26:45 -07:00
Mathias Agopian e0acbe42cf update material version 2022-04-27 10:14:38 -07:00
Mathias Agopian 4f137ccf89 don't rely on frameUniform.resolution for froxelization
this is because this uniform is not well defined -- it's unclear if
it is set to the viewport or the buffer size.

also, it's not needed, and removes a couple multiplies from the shader.
2022-04-27 09:38:33 -07:00
Mathias Agopian 04010e7dd9 when matdbg is used don't terminate the program on errors 2022-04-27 08:20:00 -07:00
Mathias Agopian f4f9f331c0 CameraInfo cleanups
- add getUserViewMatrix() on CameraInfo, the "user" view matrix is the 
view matrix before we apply the world origin transform, it is needed in
 a few places, so we make it a  method so that in the future we could 
precompute it if we wanted to.

- remove worldOffset which is just the last column of worldOrigin
2022-04-26 11:32:41 -07:00
Mathias Agopian dada291f6b rename mScaling to mScalingCS 2022-04-26 11:32:41 -07:00
Mathias Agopian 18f2f8b6d4 remove unused parameters and state 2022-04-26 11:32:41 -07:00
Mathias Agopian d4117ac968 use interleavedGradientNoise() instead of custom implementaion
interleavedGradientNoise() is available in common_math, so use that
instead of our custom gradient noise RNG.
2022-04-26 11:32:41 -07:00
Mathias Agopian eccbc8c242 simplify FXAA setup
We now do all the setup math on the CPU side, but we also remove some
unnecessary computations based on assumptions that are no longer true.
2022-04-26 11:32:41 -07:00
Mathias Agopian 3cdf24f515 remove getUV() from post-process materials
it made it actually more confusing to have two version of the uv
(normalized and not). Also the unnormalized version was computed from
frameUniforms which is not great in the case of post-processing
(it just happened to work).
2022-04-26 11:30:35 -07:00
Mathias Agopian d91faf9df8 avoid unnecessary parameter copies 2022-04-26 11:28:36 -07:00
Brian Stringham d950efa6ea Changed ALL_SHADER_STATE_FLAGS initializer to support c++17, which is required for C++/CLI support. (#5465) 2022-04-26 08:59:44 -07:00
Benjamin Doherty 8ebb37d011 Bump version to 1.21.3 2022-04-25 16:58:19 -04:00
Benjamin Doherty 3366db83ef Merge branch 'rc/1.21.2' into release 2022-04-25 16:57:25 -04:00
Benjamin Doherty 861d69ea7c Release Filament 1.21.2 2022-04-25 16:57:00 -04:00
Benjamin Doherty 5415254aac Update RELEASE_NOTES for 1.21.2 2022-04-25 16:50:53 -04:00
LaiJF b2cc904fab Fix typo 2022-04-25 09:06:12 -07:00
Mathias Agopian 3f87b520bb ShadowMap::render() doesn't need CameraInfo anymore 2022-04-22 12:35:00 -07:00
LaiJF 135a362176 Fix typo (#5455) 2022-04-22 10:46:04 -04:00
Philip Rideout 391ebc3702 gltfio: fix progress indicator when error occurs.
The progress bar in `gltf_viewer` should not appear to hang if any
of an asset's textures fail to load.
2022-04-21 17:41:32 -07:00
Philip Rideout b4d1443720 Repair iOS build. I think. 2022-04-21 15:36:37 -07:00
Philip Rideout c06737aca2 TextureProvider fixup in ResourceLoader JNI. 2022-04-21 13:44:44 -07:00
Philip Rideout f847232296 gltfio: introduce TextureProvider API.
This allows clients to provide their own asynchronous texture decoders
for various mime-typed images. This is a plug-in component for gltfio,
in some ways similar to MaterialProvider.

There are two motivations for this: to decouple gltfio from STB and
to make it easier to integrate support for BasisU textures.

This also has the side effect of simplifying ResourceLoader, since the
texture decoding jobs have been moved out.

As part of this work, I made the "stb" CMake target into a traditional
static library. Previously we had several files called `Image.cpp`
whose sole purpose was to enable STB_IMAGE_IMPLEMENTATION.
2022-04-21 13:25:40 -07:00
LaiJF 89f06b8923 Fix typo (#5454) 2022-04-21 09:52:04 -06:00
Philip Rideout 90a2b1f3c9 Remove WebGL workaround for bloom.
Bloom now works fine (tested with Chrome 100 on a x86 MacBook) without
this workaround for overly aggressive feedback loop detection.
2022-04-20 12:07:49 -07:00
Ben Doherty 059f51338d Audit backends and test cases for correct Y orientation. (#5440) 2022-04-20 11:01:31 -06:00
LaiJF d3cea5121e Fix typo 2022-04-20 09:58:46 -07:00
LaiJF c37301d2dc Fix typo. 2022-04-19 20:27:52 -07:00
Mathias Agopian aa16778fbd don't leak Engine if the driver fail to initialize
If there is an error during the driver initialization, Engine::create() 
returns nullptr, but the FEngine was allocated and would then never
be destroyed.

mTerminated was useless because by construction it would always have
the expected value.
2022-04-19 11:49:07 -07:00
Mathias Agopian ee499ad2ca don't use a unique_ptr to hold the DFG
we can simply make it a member of FEngine.
2022-04-19 11:49:07 -07:00
Mathias Agopian 958dd5bb27 a lot of our workaround don't apply when using ANGLE 2022-04-18 20:19:09 -07:00
Mathias Agopian f988b75999 fix the 2 passes version of FSR
This version is used only on qualcomm devices. It's now forbidden to
create a program inside a renderpass. Unfortunately there was still
one codepath doing so.
2022-04-18 20:18:45 -07:00
Philip Rideout e3ccb4bb3c gltfio Animator: add resetBoneMatrices().
See #5436.
2022-04-18 15:07:35 -07:00
Philip Rideout 3f0dc6f7e6 Minor Ktx2Reader refactoring. 2022-04-18 15:02:08 -07:00
Mathias Agopian c212dd5bc7 remove the CameraInfo state from FView
this state only exists during Renderer::render(), having it outside
of view is more flexible as it give us an opportunity to adjust
camera parameter globally before drawing.

Also greatly reduced the size of RenderPass (which is a Value object).
2022-04-18 12:04:18 -07:00
LaiJF 1eceab0040 Fix typo. 2022-04-18 10:46:31 -07:00
Philip Rideout ab9d1e5956 Fix unit test. 2022-04-15 12:22:12 -07:00
Philip Rideout c906290416 Add to release notes. 2022-04-15 10:54:27 -07:00
Philip Rideout d52a24b6e9 Incorporate feedback from code review. 2022-04-15 10:48:48 -07:00
Philip Rideout 9aeec3a759 Add Ktx2Reader and BasisEncoder and use them in samples.
mipgen can now emit basis-encoded KTX2 files. Both the desktop and
web "suzanne" samples use this as a test for compressed textures.

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

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

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

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

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

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

Partial fix for #4771.
2022-04-15 10:48:48 -07:00
Mathias Agopian 550fcfe2e3 fix typos 2022-04-15 09:18:06 -07:00
Mathias Agopian b2cdf9f2b4 don't issue a flush systematically after framegraph's execute
This is only a good place for a flush *if* we're going to draw another
view (so the GPU can start working). Otherwise, it can be costly
on some drivers and unnecessary since swapbuffers will do the same.
2022-04-15 09:12:39 -07:00
Mathias Agopian 19a3fe3dce allow radius parameter for upsample bloom stage
The original article we used for our bloom (siggraph'14) called for
a radius parameter for the upsample stage. We're always using 1.0 right
now, but it is useful to keep this possibility for experimentations.
2022-04-14 14:04:32 -07:00
Mathias Agopian 754abbf78e bloom pass cleanups 2022-04-14 14:04:32 -07:00
Mathias Agopian 9b855e9a03 fix bloom downsample
a bug was introduced in 8/2020 where the downsampling filter was wrong,
due to a mistake using textureLodOffset, which obviously uses offsets
in source texel -- we were assuming destination.
2022-04-14 14:04:32 -07:00
Mathias Agopian 2534fdf92d propagate the matdbg flag to graddle 2022-04-14 14:04:15 -07:00
Mathias Agopian dab02e915e Remove deprecated Stream APIs 2022-04-14 12:51:03 -07:00
Mathias Agopian 68da1a25eb disable ANGLE optimization that hurts filament 2022-04-14 08:52:56 -07:00
Romain Guy c67b363576 Fix compilation warnings 2022-04-13 15:15:16 -07:00
Philip Rideout 5c0e7d8211 sample-gltf-viewer: fix regression with zip files.
Path resolution was broken with #5285, which only worked when the glTF
happened to be at root level. This new fix has been tested against:

- My Sponza zip file that hass all files in a "sponza" folder.
- My Bistro zip file, which has resources in a child folder relative to
  the gltf file
- A self-created flat zip using IridescentDishWithOlives, with
  everything at root level.

Side note: Bistro still fails on a Pixel 6 Pro Mali but for an unrelated
reason: (null deref in backend::TimerQueryNative::queryResultAvailable)
2022-04-13 12:18:47 -07:00
Benjamin Doherty caacc61602 Bump version to 1.21.2 2022-04-13 10:21:09 -06:00
Benjamin Doherty e902df19b2 Merge branch 'rc/1.21.1' into release 2022-04-13 10:15:50 -06:00
Benjamin Doherty 3d57c60840 Release Filament 1.21.1 2022-04-13 10:14:44 -06:00
Mathias Agopian 8ab2725a79 string improvements
- don't use __PRETTY_FUNCTION__ and try to parse it, __func__ is
standardized and in most case returns what we want (the function name).

- add native support for string_view in our ostream.

- uninline string support from ostream
2022-04-13 08:53:33 -07:00
Mathias Agopian ff27f8109c Use DEBUG_MARKER() only on (and on all) driver APIs 2022-04-13 08:53:14 -07:00
Benjamin Doherty 40b372dda7 Update RELEASE_NOTES for 1.21.1 2022-04-12 14:36:26 -06:00
Philip Rideout 8e09d8bd71 Fix sRGB correctness in Ktx1Reader.
When creating a KTX file (e.g. with mipgen), you can of course choose
whether or not you want to use an sRGB format.

At load time, your app has an expectation about whether a particular
texture has an sRGB format. e.g. the glTF convention is that albedo
textures should be sRGB, while roughness textures are linear.

Before this commit, our KTX loader would look at the app's expectation,
then silently re-interpret the bits in the glTF texture in order to
match this expectation. This seems very wrong.

Instead, if the expectated format does not match the format in the KTX
file, we now print a warning.

Fixes #2422, which will also be obsoleted by our upcoming KTX2 support.
2022-04-12 11:52:36 -07:00
LaiJF d6df4cd03a Fix typo. 2022-04-12 10:57:46 -07:00
Philip Rideout df03fdf3d7 mipgen: fixups / clarification regarding sRGB.
The `g_linearized` variable was being used for two purposes: to denote
the linearity of the source format AND the linearity of the destination
format. This was confusing and is now split is `sourceIsLinear` and
`destIsLinear`.

This change has no effect on the the look of the suzanne demo.
2022-04-11 14:28:34 -07:00
Mathias Agopian 6c59945395 fix typo preventing desktop GL builds to work 2022-04-11 09:51:38 -07:00
Philip Rideout d16cc50561 Shrink BasisU transcoder.
We do not support these formats and they add bloat to the basis tables.
In a release x86 build, this reduces the transcoder size from 774 KiB to
475 KiB.
2022-04-08 15:03:30 -07:00
Ben Doherty fd330a98aa Releases: specify Python dependencies in requirements.txt file (#5402) 2022-04-08 14:35:51 -07:00
LaiJF e667484a94 Fix typo. (#5413) 2022-04-08 14:23:46 -07:00
LaiJF 71e5e6c6c0 Fix typo. (#5407) 2022-04-08 14:22:29 -07:00
LaiJF c1df902593 Fix typo. (#5414) 2022-04-08 14:14:47 -07:00
Mathias Agopian 3c3320a2ba we need to be able to query the version before creating OpenGLDriver. 2022-04-07 20:30:11 -07:00
Mathias Agopian 35753bc6c2 CommandStream shouldn't be copyable.
This actually avoids a copy of Dispatcher (which is pretty large)
when constructing Engine.
2022-04-07 14:07:20 -07:00
Mathias Agopian 5f7967d09c Improve HandleAllocator
Allocation and destruction of handles generates a fair amount of code
because they are synchronized and the spinlock is inlined.

So we fix this by generating the 3 (de)allocation methods we really
need, we only need 3 because we're using 3 pools. These are now 
out-of-line, which reduces size and reduces pressure on the i-cache.
Performance is not affected much because in the end it's just a
static branch (and in most case the return is elided).
2022-04-07 14:07:20 -07:00
Mathias Agopian 404b6e8af3 Improve CommandStream Dispatcher
The main change here is that instead of allocating a Dispatcher on the
heap and storing a pointer to it in the CommandStream, we now have
a Dispatcher directly inside the CommandStream.

This avoids a heap allocation and a dereference when executing a command.
2022-04-07 14:07:20 -07:00
Mathias Agopian 898c20e584 OpenGLContext cleanups
the main change here is to make OpenGLContext friendly with ES2
2022-04-07 14:07:20 -07:00
Mathias Agopian f278b76b04 gl backend version management cleanup 2022-04-07 14:07:20 -07:00
Ben Doherty 6353f17635 Releases: specify Python dependencies in requirements.txt file (#5402) 2022-04-07 11:23:03 -07:00
daemyung jang 9cae34babf Add Java binding to get skins in FilamentAsset 2022-04-07 08:53:27 -07:00
Philip Rideout c37cc61b30 Update WebGL demos again. 2022-04-06 11:03:18 -07:00
Philip Rideout 9aced8e9b8 WebGL: fix intermittent 'detached ArrayBuffer' errors.
Partial fix for #5404.
2022-04-06 10:58:30 -07:00
Philip Rideout dde060bf4d Repair iOS build. 2022-04-06 10:56:37 -07:00
Philip Rideout b60518caa5 Add libs/ktxreader, rename some things to prep for KTX2.
Changes:

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

Notes:

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

- Ktx1Reader has a dependency on Filament and should therefore live in
  a separate library, which it now does.
2022-04-06 10:56:37 -07:00
Philip Rideout 69000ef1f2 Fix online demo.
The `demo_*` web samples were using unpkg to refer to the Filament build
rather than using the local copy, which was inconsistent with the other
web samples.

We now use the local copy of Filament for everything except the
drag-and-drop viewer, which always uses the latest version of Filament.
2022-04-06 09:14:25 -07:00
Philip Rideout 39d6106ef2 Add BasisU to third_party. 2022-04-06 09:02:18 -07:00
Ben Doherty 96a1cbe69f Attempt to fix GitHub release asset upload (#5398) 2022-04-05 13:01:20 -07:00
Ben Doherty 90c23a7d5d Correctly prepare color grading as subpass programs (#5384) 2022-04-04 13:24:01 -07:00
Benjamin Doherty 5710304114 Bump version to 1.21.1 2022-04-04 13:03:39 -07:00
Benjamin Doherty 0f684820bc Merge branch 'rc/1.21.0' into release 2022-04-04 13:01:35 -07:00
Benjamin Doherty 09fe495384 Release Filament 1.21.0 2022-04-04 13:00:48 -07:00
Benjamin Doherty e1d2d6ade6 Update RELEASE_NOTES for 1.21.0 2022-04-04 12:58:54 -07:00
Mathias Agopian e0b6f2ca71 Change version number to 1.21.0 2022-04-04 12:41:38 -07:00
Pavel Korolev 8457d6092d Use index offset provided by ImGui when rendering UI 2022-04-04 10:49:43 -07:00
Mathias Agopian 72c16e07ed remove Viewport::scale()
because a float->integer conversion is needed, it's better to let the
caller decide what they want.
2022-04-02 20:37:00 -07:00
Mathias Agopian 12b96cba04 minor cleanup: rename internal class attributes 2022-04-02 20:37:00 -07:00
Mathias Agopian e4d943e942 update release nodes and bump material version 2022-04-02 20:36:40 -07:00
Ben Doherty 7fa66325f3 Fix Metal validation error when reading from default SwapChain (#5392) 2022-04-01 16:37:46 -07:00
Mathias Agopian e188a7875e enable both screen-space refraction and reflection
Both "SSR" can now be used on the same material. This is made possible
by using a 2D array to store both buffers.
2022-04-01 16:22:10 -07:00
Mathias Agopian ac9822b8c8 Fix a framegraph dependency bug when writing to subresources
The dependency graph was set incorrectly when writing to a subresource
of a subresource.
2022-04-01 16:22:10 -07:00
Mathias Agopian edb5fddd03 one more step towards reflection+refraction support
With this change we are now generating refraction and reflections
buffer into their own layer of a 2D array -- so they can coexist.

This change doesn't actually enable both at the same time yet.

There are downsides to this approach:
- a 2d array of 2 layers is created even if only one of reflection or
  refraction is active. This could be fixed at the cost of more
  complexity.
- if reflections are active then refraction must use a RGBA16F texture
  instead of RGB_11_11_10, because they share the texture
2022-04-01 14:37:40 -07:00
Mathias Agopian 35f4a97e32 new framegraph API do add a pass without an execute stage 2022-04-01 14:37:40 -07:00
Mathias Agopian 487b10fdda repair and optimize matdbg
we add a checkProgramEdits() method that must be called periodically
on all materials. This is currently done at the beginning of a frame.
2022-03-31 16:52:26 -07:00
Mathias Agopian 271cda88aa Move vulkan backend implementation into the filament::backend namespace 2022-03-31 11:53:54 -07:00
Mathias Agopian 25b73ddcfa Move opengl backend implementation into the filament::backend namespace 2022-03-31 11:53:54 -07:00
Mathias Agopian 35b8146a87 move metal backend out of the metal namespace
this is to be consistent with other backends, which are all in
filament::backend.

had to rename metal::PipelineState to MetalPipelineState.
2022-03-31 11:53:54 -07:00
Mathias Agopian 091e5a33ac move Noop backend into filament::backend namespace 2022-03-31 11:53:54 -07:00
Ben Doherty ffe4b7390d Correctly prepare color grading as subpass programs (#5384) 2022-03-30 16:25:27 -07:00
Mathias Agopian 604d3e34a4 avoid an extra copy during the screen-space reflection pass
unlike for refraction, the reflection buffer is distinct from "the"
color buffer, this allows an optimization (compared to ssr) when we
generate the mipmap chain -- we can allocate the mipmaped texture
and render the SSR pass directly into its level 0. This achieved
use the framegraph's forward resource feature.
2022-03-30 15:32:52 -07:00
Mathias Agopian e116dd4aec Improve framegraph forward resource API
This add a couple methods to allow the creation and forwarding in a
single call.
2022-03-30 15:32:52 -07:00
Mathias Agopian d53614fb0a fix a framegraph crash when forwarding a subresource
the crash would happen when forwarding a subresource of a subresource,
because in this case the parent's handle would be reset to the null
handle.
2022-03-30 15:32:30 -07:00
Mathias Agopian c91e5df117 Add comment about how we calculate the viewport when upscaling 2022-03-30 08:58:50 -07:00
Philip Rideout 96574816b3 Fix 12x overallocation of memory in MorphTargetBuffer.
I noticed this while helping someone at Google understand our new API.
2022-03-30 08:24:40 -07:00
Mathias Agopian b43a609ebc rename framegraph fg2/ folder to fg/ 2022-03-29 14:38:36 -07:00
Benjamin Doherty 2a35ee279b Bump version to 1.20.6 2022-03-28 18:47:38 -07:00
Benjamin Doherty 5abf780360 Merge branch 'rc/1.20.5' into release 2022-03-28 18:45:34 -07:00
Benjamin Doherty 2c490ec799 Release Filament 1.20.5 2022-03-28 18:44:56 -07:00
Benjamin Doherty 181f158ea9 Update RELEASE_NOTES for 1.20.5 2022-03-28 18:42:41 -07:00
Mathias Agopian fbb08d338a repair the flare pass on WebGL 2022-03-28 17:01:07 -07:00
Mathias Agopian 8e1718458a remove all references to the "Blackboard" from PostPorcessManager
This makes the code simpler to follow.
2022-03-28 16:23:52 -07:00
Philip Rideout 6bcd709320 gltfio: add support for KHR_materials_emissive_strength 2022-03-28 12:57:08 -07:00
Mathias Agopian 1a6e3ec88e batch all program linking at begin renderpass time
With this change, shaders are compiled at program creation, programs
are linked at the start of the next render pass and queries are
deferred until first use.

This should improve overall performance on some drivers.
2022-03-26 13:36:35 -07:00
Mathias Agopian f5f50eca06 programs must now be created outside of renderpasses
from now on, the backends can assume that programs are created outside
of begin/endRenderpass.
2022-03-26 13:35:48 -07:00
Mathias Agopian 886fb7fb94 fix build 2022-03-26 13:35:18 -07:00
Philip Rideout a82b3bedb2 gltfio: material variants can now be applied to FilamentInstance. 2022-03-25 16:47:59 -07:00
Mathias Agopian d879bbc80a Simplify OpenGLProgram sampler bindings
This reduces the size of OpenGLProgram from 64 to 32 bytes and
improves the code that sets new samplers.

The main simplification is that we're not trying to "pack" the 
texture units used in the program. For e.g. we could be using
units 0,3,4, where before it would be 0,1,2.
This allows us to do less tracking.

Another optimization is that we're discarding entirely a SamplerGroup 
if the program doesn't use any of its samplers. This helps remove
a test in updateSampler which in turn remove somem tracking data.
2022-03-25 15:35:53 -07:00
Mathias Agopian bf437b7933 defer gl program link + query to first use (draw)
in an upcoming PR we'll move linking back a bit earlier to allow
more batching.
2022-03-25 13:47:31 -07:00
Mathias Agopian 49dff3c439 log shader source code in debug build on error 2022-03-25 09:40:11 -07:00
Mathias Agopian 0d6c017cfb cleanup OpenGLProgram
This is the first step before we defer a lot of the glGet* calls.
2022-03-25 09:40:11 -07:00
Philip Rideout ba042db3f4 gltfio Java: add getMorphTargetNames for consistency with other methods.
Tested by hacking ModelViewer.
2022-03-24 19:23:14 -07:00
Philip Rideout faeba6ad95 gltfio: add support for KHR_materials_variants
Tested the Java API by hacking ModelViewer.
Tested the JavaScript API by adding to filament-viewer-test.
2022-03-24 19:23:14 -07:00
Philip Rideout 163e28ca7a Update public web demos (fixes helmet demo) 2022-03-24 16:10:14 -07:00
Philip Rideout 3dbc168d76 Use newer package for LitElement. 2022-03-24 16:04:43 -07:00
Ben Doherty fe49946852 Metal: support blitting from 2D texture arrays (#5357) 2022-03-24 11:38:51 -07:00
Mathias Agopian 6310ea46e3 fix dummy ssr history texture target type 2022-03-23 20:47:20 -07:00
ef8e3e5224 Fix typo. (#5355)
* Fix typo.

* Update filament/src/RenderPass.cpp

Co-authored-by: Romain Guy <romain.guy@gmail.com>

Co-authored-by: Mathias Agopian <pixelflinger@gmail.com>
Co-authored-by: Romain Guy <romain.guy@gmail.com>
2022-03-23 11:29:07 -07:00
Mathias Agopian 26cc722f74 remove SPVRemaper lib, fold it into glslang directly
This avoids a duplication of doc.cpp, the largest compilation unit
(about 650KiB).
2022-03-23 11:27:30 -07:00
Philip Rideout 043fdf7a51 Remove lite flavor from android-utils.
We noticed that the lite flavor isn't actually smaller, plus we need to
rework our Android library hierarchy anyway, so for now let's remove
this.
2022-03-23 11:18:25 -07:00
Mathias Agopian c01105b49a Fix shadow frustum computation wrt projection matrix
Instead of recomputing the Frustum from its 8 vertices, we compute it
from the projection matrix directly. This ensures this works with any
projection matrix.  Building a Frustum object from 8 vertices required
these vertices to be given in a certain order which wasn't correct if
the projection was flipped for instance.

Removed the API to construct a Frustum from vertices.

fixes b/225975881
2022-03-23 09:41:14 -07:00
Philip Rideout f56f5a300c Temporary workaround for WebGL builds on macOS.
Better fix is to replace etc2comp and astcenc with basis.
2022-03-22 22:21:57 -07:00
Mathias Agopian 8b79f3683e skip work when morphtarget weight is zero
fixes #5344
2022-03-22 22:21:41 -07:00
Benjamin Doherty 319bd123ce Fix, use zero texture array when SSR is of 2022-03-22 22:21:14 -07:00
Benjamin Doherty e23243a65b Fix build breakage on Windows 2022-03-22 20:43:50 -07:00
Mathias Agopian c4261a8c10 hide ostream implementation details into ostream.cpp
Fixes #5343
2022-03-22 16:14:13 -07:00
Mathias Agopian 009b58537e move BuilderBase to libutils and rename to PrivateImplementation 2022-03-22 16:14:13 -07:00
Mathias Agopian e51709a4e8 Size optimizations in UniformInterfaceBlock 2022-03-22 15:28:40 -07:00
Mathias Agopian 78813ed9b7 get rid of ShaderStageFlags.h
move its content to DriverEnums.h, we do this because it is used
in libfilabridge, which has an unspoken rule that it only includes
DriverEnums.h.

filabridge also only has a header dependency, so it can't call any
method, not even operator<<.

Also cleanups and simplifications.
2022-03-22 15:28:40 -07:00
Mathias Agopian 2e649a9f16 size optimizations and cleanups of SamplerInterfaceBlock 2022-03-22 15:28:40 -07:00
Mathias Agopian d36783cd1d cleanup a bit metal codegen for samplers
the main change here is that we actually go through all "binding points"
instead of hardcoding the ones we currently use.
2022-03-22 15:28:40 -07:00
Philip Rideout 101a59138c Update the zbloat tool
The tool now works with Python 3 and handles binaries that have multiple
embedded material archives.
2022-03-21 16:13:49 -07:00
Benjamin Doherty f4087fc81d Bump version to 1.20.5 2022-03-21 14:45:34 -07:00
Benjamin Doherty 3809259f47 Release Filament 1.20.4 2022-03-21 14:45:00 -07:00
Benjamin Doherty 82793f9b82 Merge branch 'rc/1.20.4' into release 2022-03-21 14:43:15 -07:00
Benjamin Doherty 537576e84a Update RELEASE_NOTES for 1.20.4 2022-03-21 14:42:35 -07:00
Benjamin Doherty 375d1f55e3 Release Filament 1.20.4 2022-03-21 14:38:14 -07:00
Benjamin Doherty 597218963f Update RELEASE_NOTES for 1.20.4 2022-03-21 14:37:17 -07:00
Mathias Agopian e103b28b41 The backend CANNOT depend on filabridge
This would mean that the backend is not independent of our material
system. Thankfully we didn't have too many dependencies that leaked
there.
2022-03-21 13:55:15 -07:00
Mathias Agopian 8e7d0c0df9 Fix a bug in Invocable that prevented function signatures that returned references from working 2022-03-21 13:55:15 -07:00
Mathias Agopian d8845e5fcc greatly simplify SamplerBinderMap
The main simplification is that we don't need an actual map to retrieve
the global offset of a sampler, it can be easily calculated as:
  global_offset = offset_of_the_block + local_offset
2022-03-21 10:54:00 -07:00
Mathias Agopian b2ed544ee8 More cleanups in PostProcessManager 2022-03-21 10:46:55 -07:00
Mathias Agopian a40ee77326 minor cleanups 2022-03-21 10:46:55 -07:00
Mathias Agopian 85135e60c7 Switch SSR texture to 2D array
At this point there is no benefit from doing this, but we'll need this
in a later PR.
2022-03-21 10:46:55 -07:00
Mathias Agopian bee9f160fa gaussian passes now handle 2d arrays better
Instead of passing the level and layer explicitly to gaussianBlurPass,
we rely on the information already contained in the handle. i.e. we
honor the "subresource" part of the handle (if it has one).
In other words, it's now possible to pass a subresource (e.g. a layer)
to generateGaussianMipmap or gaussianBlurPass and things should work as
expected.
2022-03-21 10:46:55 -07:00
Mathias Agopian 64c67258b0 fix FrameGraph dependency issue
The problem here would happen when forwarding a subresource (i.e. 
replacing an existing resource by a subresource) and the existing
resource had been written to. In this situation, the subresource's 
parent needs to depend on the subresource (i.e. as if it was written to
by it). This would normally happen during write() but in this situation,
the write had already happened.
2022-03-21 10:46:39 -07:00
Mathias Agopian 49e0f484e9 fix a framegraph dependency issue
the dependency graph would be incorrectly severed in the situation where
a subresource was written to and later its parent was read from.
In this situation, the parent node is in fact a new version of the 
original parent node, so we need a "read" dependency of the orginal to
the copy (otherwise the orginal node is not a dependent of anyone
and gets culled).
2022-03-21 10:46:39 -07:00
Philip Rideout 0d29b3ddc8 WebGL endFrame: restore additional default state. 2022-03-21 09:43:45 -07:00
Philip Rideout e0e3b42623 WebGL: reset VAO and texture bindings when frame ends. 2022-03-21 09:43:33 -07:00
Mathias Agopian dbc78ff0aa Fix screen-space reflections when post-processing and MSAA are off
when we're rendering directly into the swapchain, we can't have a 
history buffer, so in that case we need an intermediate buffer.
2022-03-21 09:10:51 -07:00
Romain Guy ebca955682 Clear warnings 2022-03-19 12:58:18 -07:00
daemyung jang d8ea26e305 Update MAX_MORPH_TARGETS to 256 2022-03-18 15:42:02 -07:00
Philip Rideout 37aafdd912 WebGL endFrame: restore additional default state. 2022-03-18 14:23:08 -07:00
Mathias Agopian edf78afa8e fix warnings from updating macos toolchain 2022-03-17 15:45:09 -07:00
Mathias Agopian 1df4218deb fix python3 detection in cmake 2022-03-17 15:45:09 -07:00
Ben Doherty 1c5715824f Avoid linking clashes with BlueGL and OpenGL (#5323)
Some clients need to link against both Filament and OpenGL. This can lead to symbol clashes under certain circumstances. As a fix, prefix all of our `bluegl` symbols with `bluegl_`. Previously we made this naming change for Windows, but now we'll do it on all platforms for simplicity.
2022-03-17 11:41:38 -07:00
Philip Rideout 6da46b3b62 Repair A2C for opaque views, add field to FrameUniforms. 2022-03-17 10:01:27 -07:00
Philip Rideout e8d8080928 New behavior for BlendingMode::MASKED.
The existing behavior was surprising for users who draw opaque objects
into a semitransparent views, and this was especially evident with
the labels in `TextureLinearInterpolationTest`.

We now disable blending for MASKED, which is what our existing materials
documentation already says. We also now set the fragment alpha to 1 when
the fragment is not discarded, which prevents the "punch through"
effect. This is consistent with ThreeJS.

Fixes #4576.
2022-03-17 10:01:27 -07:00
Philip Rideout e7934314ad WebGL: reset VAO and texture bindings when frame ends. 2022-03-17 10:00:51 -07:00
daemyung jang c79fcf6d8d Fix a typo (#5324) 2022-03-16 08:42:30 -07:00
Mathias Agopian 3eb2a20c7f fix point light lighting with ortho projection
The froxel parameter for the Z slice were not correct.

Fixes #5318
2022-03-15 21:19:25 -07:00
daemyung jang da99fe63be Make public gltfio's math 2022-03-15 09:11:12 -07:00
daemyung jang d9067af3a3 Retrieve skins from FilamentAsset 2022-03-15 09:10:52 -07:00
LaiJF f10bedf186 Fix typo. (#5319) 2022-03-14 19:30:57 -07:00
Mathias Agopian 19b0ad2605 fix a race in jobsystem (2nd attempt)
We were decrementing activeJobCount after removing the job from the
queue, which could cause other threads in the pool to preempt us before
the decrement, causing them to spin forever trying to get a non-existant
job, until the decrement actually happened.

Now we always decrement first and fix-up the count if we couldn't get
a job from the queues. The race is inverted, and doesn't cause threads
to spin a long time.


fixes b/201100123
2022-03-14 16:40:02 -07:00
Philip Rideout 6e7af103d3 Vulkan: misc SwapChain-related cleanup.
This removes some special handling of the default render target lifetime
that is no longer needed, and renames "surface" to "swapChain" where it
is appropriate to do so.
2022-03-14 16:23:31 -07:00
Philip Rideout 8a91723dcf Vulkan cleanup: remove some state from the VulkanDriver class. 2022-03-14 16:23:31 -07:00
Benjamin Doherty 0995ca6614 Bump version to 1.20.4 2022-03-14 14:19:36 -07:00
Benjamin Doherty 3d741fc8d4 Merge branch 'rc/1.20.3' into release 2022-03-14 14:17:54 -07:00
Benjamin Doherty 47e30c337e Release Filament 1.20.3 2022-03-14 14:17:25 -07:00
Philip Rideout fb627d8b66 gltfio: decouple MaterialProvider lifetime from AssetLoader.
This is a gltfio API change (!)

Jave clients now need to call destroy on MaterialProvider.

Previously, the Java AssetLoader took over ownership of a native
material provider upon construction, but this was neither documented
nor consistent with the C++ layer. (This is historical; in the past we
did not expose MaterialProvider to Java.)

One motivation for this (aside from API consistency) is that users may
wish to preserve the material cache from one run to another.

Fixes #5132.
2022-03-14 08:56:33 -07:00
Alexander Biggs 1cb59685c5 Fix precondition for morph weights. (#5308)
Was checking for `MAX - 1` instead of `MAX`.
2022-03-10 16:46:33 -08:00
Mathias Agopian 2b395f1d89 minor ResourceList cleanup 2022-03-10 16:20:36 -08:00
Mathias Agopian e9718fa346 cleanup attributes/varyings generation
We now have a single varyings.glsl containing our varyings for both
the vertex and fragment shader. This file is included with the right
definition of VARYING as `in` or `out`.

inputs.vs is now renamed attributes.vs
2022-03-10 16:20:18 -08:00
Philip Rideout 81fc2c1d23 Always apply bone matrices, even for non-animated models.
This changes the WebGL and desktop glTF viewers so that they always
call `updateBoneMatrices`, even when there are 0 animations. Note
that our Android sample was already doing this correctly.

When combined with #5301, this fixes #5299, although users would need to
use the `recomputeBoundingBoxes` feature in gltfio (`-r` in the desktop
viewer) for this model to be scaled to fill the viewport, since its
embedded bounds are quite large.
2022-03-10 13:41:35 -08:00
Benjamin Doherty c20772b458 Update RELEASE_NOTES for 1.20.3 2022-03-10 12:56:56 -08:00
Philip Rideout dc60f57a9a gltfio: simplify API, make animator always available.
In the past there was an API gotcha because users had to "get" the
animator before releasing the glTF source data. This could have been
surprising because it was a getter method, not a factory method.

This was due to overeager optimization on my part, I wanted to avoid
animator overhead for non-animated models, when in fact it has very
little overhead.

Moreover, the animator is conceivably useful even when there are no
pre-supplied animations (e.g. for applying skins), so let's just create
it unconditionally.

Motivated by #5299.
2022-03-10 11:36:46 -08:00
Mathias Agopian 5c4f12fa00 create only a single "default render target"
we didn't need one per Renderer, and doing so created complexity in the
backends.

fixes #5291
2022-03-10 11:29:17 -08:00
Romain Guy 00ffd9ca74 Update README.md 2022-03-10 11:02:06 -08:00
daemyung jang 166f859c72 Retrieve morph target count from the primitive (#5297)
Morph weights can be zero even if the primitive has morph targets.
2022-03-10 10:56:50 -08:00
daemyung jangandMathias Agopian 1969186fe1 Compute the rotation between two vectors (#5288)
Co-authored-by: Mathias Agopian <pixelflinger@gmail.com>
2022-03-10 10:42:44 -08:00
Philip Rideout e1e7854d97 BlueVK: remove flaky operator<< for flags, update GitHub paths.
Two changes:

1) Khronos has moved from "master" to "main".

2) BlueVK was attempting to generate reasonable "operator<<" support for
bit flags but this was buggy due to type aliases. Since we weren't using
it anyway, I simply removed this functionality from BlueVK.
2022-03-08 16:58:21 -08:00
Philip Rideout 9d5220e28e Regenerate BlueVK for Vulkan 1.3. 2022-03-08 16:57:56 -08:00
Philip Rideout fc0b41d587 VulkanTexture: remove VkAspect state, derive it on the fly.
This fixes a validation warning, since not all depth textures are
necessarily used as depth attachments.
2022-03-08 14:24:44 -08:00
Benjamin Doherty 4a6b659098 Bump version to 1.20.3 2022-03-07 14:12:28 -08:00
Benjamin Doherty 2b93f08ca5 Merge branch 'rc/1.20.2' into release 2022-03-07 14:10:07 -08:00
Benjamin Doherty e4cb861817 Release Filament 1.20.2 2022-03-07 14:09:43 -08:00
Benjamin Doherty fca62b8fff Update RELEASE_NOTES for 1.20.2 2022-03-07 14:08:41 -08:00
Mathias Agopian 640f080ea6 fix TargetBufferInfo uses an union for the face (uint8_t) and layer (uint16_t)
Instead of having 2 fields we're following the vulkan convention of
having only the layer field.

The layer/face convention is still maintained in the public APIs.

fixes #5273
2022-03-04 17:00:37 -08:00
Philip Rideout eed4b3b839 Add comments about validation to Vulkan backend. 2022-03-04 14:10:14 -08:00
Philip Rideout f48dafe87e Update remote page to fix invalid generic tone mapper key. 2022-03-04 09:47:53 -08:00
Philip Rideout daff8fea9f Android Viewer: fix URI bug when dropping some zips.
Dragging a zip file into the Remote Viewer page would fail if it
contained a glTF with `./` prefixes in the `images` section. The best
fix is to use Java's proper URI object rather than trying to parse the
string.
2022-03-04 09:15:37 -08:00
Philip Rideout 51b4a38e20 DriverAPI: add isAutoDepthResolveSupported query. 2022-03-03 14:59:20 -08:00
Philip Rideout 2171e372ce Vulkan: assert if Filament asks to resolve depth in the render pass. 2022-03-03 14:59:20 -08:00
Philip Rideout 1a30709121 Fix Android warnings in Vulkan backend. 2022-03-03 10:37:53 -08:00
Philip Rideout 2ed9b11f50 Bring back initialization of DummyMorphTarget.
This fixes "uninitialized texture" warnings from the Vulkan backend
when viewing Littlest Tokyo in a debug build.
2022-03-02 16:15:57 -08:00
Benjamin Doherty dee6d9de2c Bump version to 1.20.2 2022-03-02 15:51:38 -08:00
Benjamin Doherty 574e3e7521 Merge branch 'rc/1.20.1' into release 2022-03-02 15:47:21 -08:00
Benjamin Doherty 1797ff5d90 Release Filament 1.20.1 2022-03-02 15:46:41 -08:00
Philip Rideout 8c46e6de9b matdbg: repair invalid JSON and display of active variants.
The JSON response to /api/active became malformed after #4465 because
raw hex strings need to be enclosed by quotes.

This commit changes the variant format in the /api/materials response
to be consistent with one used for /api/active. By using integers
instead of strings, we're avoiding the need to parse integers at run
time.

The JSON error did not appear in the Chrome console because it was being
silenced as a hack to appease "matinfo --web-server". I fix this by
removing the hack and simply emitting a valid response when there's
no live backend.

Also fixed the display of materials, which were always being marked
as active even when they had no active variants.
2022-03-02 15:01:25 -08:00
Philip Rideout 613adfa342 VulkanPipelineCache: fix use-after-free when growing pool.
We held a reference to a cache item after potentially clearing it due to
pool growth. I was able to trigger an error only after enabling ASAN and
loading a large model.  Many thanks to @jeanlemotan for catching this.
2022-03-02 14:59:10 -08:00
Philip Rideout 684b0622eb Vulkan: fix logic that determines when to grow descriptor pool.
When we added per-layout arenas for each of the 3 descriptor types, we
did not account for them when determining how much of the Vk Pool is in
use. Therefore the "growth" (really a re-creation) of the Vk Pool wasn't
always occurring when necessary, causing descriptor set allocation to
fail with large models.
2022-03-02 12:39:33 -08:00
Philip Rideout 426f345f19 Minor updates to how we include vk_mem_alloc.
In the current version of the library, it looks like the DYNAMIC config
macro has been replaced with a STATIC config macro.

Also disabled the "unused-private-field" warning since this is a 3rd
party library and its not our fault.
2022-03-02 12:37:14 -08:00
Ben Doherty f80df6e061 Make VulkanContext compatible with vk_mem_alloc dev 2022-03-02 12:10:45 -08:00
Ben Doherty 29fdf82ac5 Make VulkanContext compatible with vk_mem_alloc dev 2022-03-02 12:10:20 -08:00
Ben Doherty e2177e8b36 Apply some clang-tidy fixes (#5281) 2022-03-02 11:49:45 -08:00
Benjamin Doherty c8cf2a54e8 Update RELEASE_NOTES for 1.20.1 2022-03-02 11:47:51 -08:00
Ben Doherty bfd32e67d4 Apply some clang-tidy fixes (#5281) 2022-03-02 11:43:51 -08:00
chubei-oppen 37353cca55 android-utils: Copy bug fixes from upstream (#5279) 2022-03-01 17:32:40 -10:00
chubei-oppen c72817fc25 Bugfix: Mat4 from Quaternion was transposed (#5277) 2022-03-01 10:08:27 -08:00
Mathias Agopian 81c1d3ed1a more code size reduction
The main change here is from ResourceList which ended-up generating
a lot of code due to inlining. This class is only used for tracking
user resources and is not in the performance path.

This saves another ~5K or so of code.
2022-03-01 10:03:31 -08:00
Mathias Agopian 0e1234c57d move the component manager thunks into their own cpp 2022-03-01 10:03:31 -08:00
Mathias Agopian 50fa816a6e fight more unnecessary inlining 2022-03-01 10:03:31 -08:00
Philip Rideout 07f4211dd3 Vulkan: cleanup as per code review. 2022-03-01 08:04:42 -08:00
Philip Rideout 44a433398f Vulkan: shrink DescriptorKey. 2022-03-01 08:04:42 -08:00
Philip Rideout 6821cb60b5 Vulkan: shrink PipelineKey from 608 bytes to 304 bytes. 2022-03-01 08:04:42 -08:00
Philip Rideout b8788bc390 Minor refactoring in VulkanSwapChain. 2022-03-01 08:04:42 -08:00
Philip Rideout 94c59d9d97 libutils: fix inconsistent hash in StaticString
This caused a unit test failure because a StaticString constructed
from "make" had a different hash than one constructed from a literal,
even though the two strings were lexigraphically equivalent.
2022-02-28 15:42:06 -08:00
daemyung jang 5201b5a1ba Decouple the morphing from the render primitive (#5216)
Having MorphTargetBuffer in FRenderPrimitive is a concept of glTF. Filament doesn't have to follow this concept. Actually the responsibility of FRenderPrimitive is to define vertex input stream because FRenderPrimitive maps to HwRenderPrimitive in Filament. If we store MorphTargetBuffer into FRenderPrimitive then it exceeds the responsibility of FRenderPrimitive. Because MorphTargetBuffer doesn't have any information on how to set up vertex input stream. So handling morphing like skinning will be better.
2022-02-28 11:36:52 -08:00
Philip Rideout 215ef460ef Update Vulkan Memory Allocator to v2.3.0 2022-02-28 11:18:34 -08:00
Philip Rideout 90be8ebfa2 Metal: fix bad upload size in blitDepthPlane.
This was caught by ASAN.
2022-02-28 10:33:42 -08:00
Mathias Agopian f62d58bd45 don't inline the command dispatcher ctor
We were basically getting two copies.
2022-02-25 13:19:31 -08:00
Mathias Agopian 9e5da2d75f more size optimizations 2022-02-25 13:19:31 -08:00
Mathias Agopian e12f079ac1 don't prevent unrolling of libmath == operator
We were not unrolling the == loop because the generated code with
unrolling was very branchy; but that's not a good call either because
the loop has the same number of unpredicted branches.
Theoretically the compiler should be able to emit a branchless == but
it doesn't. At least we give it a chance.
2022-02-25 13:19:31 -08:00
Philip Rideout 3c0f18753f GLTFIO_LITE does not need volume texture. 2022-02-25 09:28:17 -08:00
Mathias Agopian a0e4d3df32 fix android build 2022-02-24 22:43:53 -08:00
Mathias Agopian 4f590e3326 uninline some non performance critical setters 2022-02-24 20:59:21 -08:00
Mathias Agopian 6fdfe606e6 move all public trampolines into their own cpp file
This should prevent code duplication due to agressive inlining.
2022-02-24 20:59:21 -08:00
Mathias Agopian 1baab6c3ae move all 'F' classes into src/details 2022-02-24 20:59:21 -08:00
Mathias Agopian 61e67a2766 clenaup 2022-02-24 20:59:21 -08:00
Philip Rideout 8277015785 Vulkan: Fix regression with IridescentDishWithOlives.
When we introduced texture-based morphing, our custom depth resolver
needed to be updated to set up samplers correctly. This fixes a
validation error about shader stage access.
2022-02-24 15:03:23 -08:00
Philip Rideout 97952e0ddc gltfio ubershader: provide dummy texture for volume thickness.
Fixes logcat spam seen with IridescentDishWithOlives.
2022-02-24 15:02:30 -08:00
Benjamin Doherty 95915367fa Bump version to 1.20.1 2022-02-24 13:59:17 -08:00
Benjamin Doherty b769cfda62 Merge branch 'rc/1.20.0' into release 2022-02-24 13:57:10 -08:00
Benjamin Doherty b80d73f3cf Release Filament 1.20.0 2022-02-24 13:55:33 -08:00
Benjamin Doherty 40ac88dfed Bump MATERIAL_VERSION to 20 2022-02-24 13:53:43 -08:00
Benjamin Doherty 6d96082f07 Bump version to 1.20.0 2022-02-24 13:53:43 -08:00
Benjamin Doherty 21f913db1c Update RELEASE_NOTES for 1.20.0 2022-02-24 13:53:42 -08:00
Philip Rideout a1bf6a427d Enhancement for FILAMENT_VULKAN_VERBOSE. 2022-02-24 11:18:48 -08:00
Philip Rideout 67144bec73 Fix build when FILAMENT_VULKAN_VERBOSE is enabled. 2022-02-24 11:11:15 -08:00
Ben Doherty 699a578966 Add SSR variant filter to matc (#5256) 2022-02-24 10:36:06 -08:00
Ben Doherty f801763e6b Add SSR variant filter to matc (#5256) 2022-02-24 10:35:30 -08:00
Philip Rideout 542dd331d7 Vulkan: Add asserts that check render target size. 2022-02-24 09:26:32 -08:00
chubei-oppen 4ac3454dc6 Bugfix: The first image passed to Stream::SetAcquiredImage is ignored and leaked 2022-02-24 09:25:14 -08:00
chubei-oppen 23b578ef89 Bugfix: lookAt z axis negated 2022-02-24 09:24:57 -08:00
daemyung jang b6c26ab4e4 Guarantee Texture's minimum width and height must be 1 2022-02-24 09:23:07 -08:00
Philip Rideout 4fbcfc3168 Engine: fill dummy textures with zeroes or ones. 2022-02-24 09:04:17 -08:00
Philip Rideout 9d0aab4d21 Vulkan: be graceful when apps use uninitialized textures.
This makes it so that we emit a nice error message instead of triggering
a hairy validation error due to UNDEFINED image layout.
2022-02-24 09:02:08 -08:00
Philip Rideout babbfa1394 Vulkan: remove layout checks from SwapChain.
These asserts will come back in the next Filament release, which has
much cleaner layout tracking.
2022-02-23 13:48:13 -08:00
Philip Rideout 73f0d58e10 Vulkan: fix backend tests (especially ReadPixels Y flip). 2022-02-23 11:18:29 -08:00
Philip Rideout 6420bc6dd8 Vulkan: fix backend tests (especially ReadPixels Y flip). 2022-02-23 10:16:53 -08:00
Mathias Agopian 9fa41d06d6 FrameGraphHandle can be trivial for function calls 2022-02-23 09:52:17 -08:00
Mathias Agopian 805227d6fc improve PostProcessMaterial 2022-02-23 09:52:17 -08:00
Mathias Agopian 67d4632868 user c-array instead of vector<> in hot loop 2022-02-23 09:52:17 -08:00
Mathias Agopian 7efe967add don't inline ctor/dtor that have vector<> 2022-02-23 09:52:17 -08:00
Mathias Agopian a8cdfc6b23 Make sure Handle<> is trivial for function calls
This allows small-struct calling convention with most ABIs.
2022-02-23 09:52:17 -08:00
Mathias Agopian 7964ebf3c5 Some method really don’t need to be inlined 2022-02-23 09:52:17 -08:00
Ben Doherty 49b8e5e5d2 Adding missing algorithm include (#5237) 2022-02-22 18:06:53 -08:00
Philip Rideout 54e6b6b24a Vulkan: fix issue with MSAA sidecar dimensions.
Every sidecar texture should have the same dimensions as its parent
texture.

Prior to this change, the sidecar texture would have the dimensions of
the RenderTarget wrapper rather than the parent texture. This was wrong
because the RenderTarget might be slightly smaller than the texture.
This caused an issue when the same texture was attached to two render
targets with different sizes, because there's only 1 cached sidecar per
texture.
2022-02-22 17:35:08 -08:00
Philip Rideout 0fe6cfb224 Vulkan: fix lifetime issue with sidecar depth.
We were passing the wrong texture object to VulkanDisposer::acquire().
MSAA depth sidecar textures are not managed by VulkanDisposer, but their
parent textures are.

Fixes #5217.
2022-02-22 17:34:31 -08:00
Philip Rideout 0ee540df9c Vulkan: fix hack, allow SSAO to read from all mips.
When we overhauled image layout transitions, we moved as many
transitions as possible into the render pass. However the transition
that we perform for "depth read only" layout needs to be applied to
multiple miplevels, so we cannot use the render pass for that.
2022-02-22 17:34:18 -08:00
Philip Rideout 249f0a80d8 gltfio: be graceful when model has > 4 weights per vert.
We now handle "too many bone weights" in the same way that we handle
"too many UV sets".  i.e. emit an error message and do not panic.

This change allows us to render the model in #5234 quite reasonably.

Fixes #5234.
2022-02-22 17:34:02 -08:00
Philip Rideout 9cb4b74bbd Fix web apps that have multiple Filament viewers.
This fixes the emscripten binding errors that we've been seeing
with the <filament-viewer> test page, which prevented us from
including web in the last few Filament releases.

The binding errors were caused by double-initializing the emscripten
module.

I fixed this by allowing clients (e.g. FilamentViewer) to call
Filament.init() more than once. We now accumulate a list of "on ready"
callbacks that get triggered after the emscripten module becomes ready.

As far as I can tell, multiple canvases were actually always broken, and
the viewer test page worked in the past only because we got lucky.
2022-02-22 16:12:13 -08:00
Philip Rideout b3368a3fb2 Vulkan: make validation messages slightly easier to read. 2022-02-22 09:10:05 -08:00
Philip Rideout 327576274f Fix web apps that have multiple Filament viewers.
This fixes the emscripten binding errors that we've been seeing
with the <filament-viewer> test page, which prevented us from
including web in the last few Filament releases.

The binding errors were caused by double-initializing the emscripten
module.

I fixed this by allowing clients (e.g. FilamentViewer) to call
Filament.init() more than once. We now accumulate a list of "on ready"
callbacks that get triggered after the emscripten module becomes ready.

As far as I can tell, multiple canvases were actually always broken, and
the viewer test page worked in the past only because we got lucky.
2022-02-22 08:42:36 -08:00
Mathias Agopian 0e7004a7f8 Automatically set read-only depth in the framefraph 2022-02-18 14:42:35 -08:00
Philip Rideout ca8549549c Fix build break. 2022-02-18 14:41:59 -08:00
Philip Rideout fa6d9a4b01 Upgrade emsripten to 3.1.5 2022-02-18 14:36:20 -08:00
Mathias Agopian 3693e4909b Workaround feedback loops limitation in GLES 2022-02-18 13:51:01 -08:00
Mathias Agopian 697a8370cb There was still a case where skinning wasn’t correctly default initialized
Fixes: #5185
2022-02-18 13:49:12 -08:00
Philip Rideout 155a362d60 Fix warning. 2022-02-18 13:37:28 -08:00
Philip Rideout fed95d70b0 Vulkan: ensure that desired present mode is actually supported. 2022-02-18 11:20:52 -08:00
Philip Rideout cd126138e0 Clean up readOnlyDepthStencil as per code review. 2022-02-18 10:00:06 -08:00
Philip Rideout 7e7398aa92 Assert valid usage of readOnlyDepthStencil in debug builds. 2022-02-18 10:00:06 -08:00
Philip Rideout ede7c579f9 Add new backend hint to RenderPassParams.
Previously, the Vulkan backend made an educated guess about the depth
write state during the start of the render pass. The logic for this
did not make any sense, so now we're replacing it with an explicit
hint that PostProcessManager sets up. In a sense this gives backends
a sneak peek into the raster state.
2022-02-18 10:00:06 -08:00
Philip Rideout 67aa6f1913 Update old comments about max color attachment count. 2022-02-17 12:55:31 -08:00
Philip Rideout 80eba1de10 VulkanRenderTarget: remove duplicated state tracking.
Now that VulkanRenderTarget is always backed by textures, it no longer
needs to track state that is already tracked by VulkanTexture.
2022-02-17 08:31:02 -08:00
Philip Rideout 5e05a23e94 Vulkan: Remove duplicated layout tracking. 2022-02-16 16:21:07 -08:00
Philip Rideout 8c8061a637 Vulkan: simplify management of "default" render target. 2022-02-16 16:21:07 -08:00
Philip Rideout 9ef3c59698 Vulkan: clean up the SSAO image layout workaround. 2022-02-16 16:21:07 -08:00
Mathias Agopian 5f7c6c2fbf update material version
This this needed by recent SSR changes.
2022-02-16 11:20:28 -08:00
Mathias Agopian 991360da97 Missing public modifier in Texture.java
Fixes #5210
2022-02-16 10:24:20 -08:00
Mathias Agopian 50d9fb2b5b Fix typo in documentation
Fixes #5150
2022-02-16 10:23:59 -08:00
daemyung jang 001a3e3dc8 Set the morph target buffer by builder (#5179) 2022-02-16 09:20:38 -08:00
Romain Guy b6eca61786 Update Gradle (#5208)
* Update Gradle

* Add comment
2022-02-15 17:01:17 -08:00
Philip Rideout cc75eb3aa2 Vulkan: add comments explaining layout strategy. 2022-02-15 15:47:17 -08:00
Philip Rideout f5fda88cf6 Vulkan: clean up ReadPixels and Blit paths.
VulkanSwapChain is now always backed by VulkanTexture, so these
code paths can be simplified.
2022-02-15 15:47:17 -08:00
Philip Rideout e99f13b14d Fix some RangeMap behavior and improve its unit test.
The existing unit test had an incorrect expectation in what happens
after splicing an existing range. Fixing the unit test revealed an
actual bug in the RangeMap implementation. It should never modify the
lower bound of an existing interval, because that invalidates the
iterator. It should also never retain a pointer or reference to a range
when the range is potentially removed by subsequent codelines.
2022-02-15 15:46:34 -08:00
Romain Guy 08e809bf75 Update Android tooling (#5204)
* Update Android tooling

* Don't update AGP
2022-02-15 13:22:30 -08:00
Mathias Agopian 1d6aeb5de1 Add basic support for instanced renderables
We can now specify an "instance count" per renderable during creation. 
This instance count applies to all render primitives in the 
Renderable.

This will simply draw the renderable "instance count" times. A new
method available to vertex shaders, getInstanceIndex(), allows the
material to discriminate the instances and adjust the position/transform
accordingly.

Typically this is used for particle systems.
2022-02-15 13:11:23 -08:00
Mathias Agopian d13ccd1c26 instancing support for the backends
We just add an instance count to the backend draw command.
2022-02-15 13:11:23 -08:00
Ben Doherty f2c8456971 Attempt to fix Windows CI builds (#5205) 2022-02-15 11:12:19 -08:00
Ben Doherty 54482e6451 Attempt to fix Windows CI builds (#5205) 2022-02-15 11:11:28 -08:00
Romain Guy 9491b36a25 It's ok compiler, it's ok 2022-02-15 08:17:10 -08:00
Mathias Agopian d387e14d4c cleanup TAA
The new SSR code allows to clean-up TAA code a bit.
TAA should now be more standalone/abstracted.
2022-02-14 16:43:24 -08:00
daemyung jang 5c41b332ad Add Java binding to get morph target names 2022-02-14 16:40:32 -08:00
Benjamin Doherty e571600c30 Bump version to 1.19.1 2022-02-14 13:48:59 -08:00
Benjamin Doherty e84c94d3eb Merge branch 'rc/1.19.0' into release 2022-02-14 13:46:45 -08:00
Benjamin Doherty fd69c7ed75 Release Filament 1.19.0 2022-02-14 13:46:06 -08:00
Benjamin Doherty e791d4818f Update RELEASE_NOTES for 1.19.0 2022-02-14 13:45:28 -08:00
Philip Rideout 3ff8d6dc22 Incorporate code review feedback. 2022-02-14 13:00:12 -08:00
Philip Rideout af6fd21e11 Crucial refactoring of VulkanFboCache and VulkanSwapChain.
Two big changes to simplify and fix layout transitions:

(1) The RenderPassKey struct has been reduced from 88 bytes to 56 bytes
by using custom enum types and bitmasks. It also now has separate fields
for "final" and "initial" image layouts.

(2) VulkanSwapChain now leverages VulkanTexture, which enables it to
share tracking functionality, avoid duplicated state, and have less code
overall.

In a future PR we will clean up the ReadPixels and Blit paths, and also
remove some hacks that appease Vulkan when SSAO is enabled.
2022-02-14 13:00:12 -08:00
Mathias Agopian 5bd5c50c8d Remove unit test that is not very useful. 2022-02-14 12:03:07 -08:00
Elie Michel 2c8d296044 Make sure one use the right combination of version
To avoid `Material version mismatch`
2022-02-14 10:55:55 -08:00
Mathias Agopian df6a100fcb Improve how we compute the lod from the roughness
The main change here is that for screen-space reflections, the lod
calculation takes the camera distance into account.

We also now correctly take into account that we blur each lod
successively which increases the standard deviation by 10%. This applies
to both refraction and reflection.
2022-02-13 22:53:47 -08:00
Mathias Agopian 3f6188edff Enable rough reflections
This works by first generating a reflection buffer which gets blurred,
then the color pass samples from this buffer according to the roughness
of the surface being rendered.

A lot of the changes here involve utilizing "reserved" variants for
the new "SSR" pass and all the fallout from that.
2022-02-13 22:53:47 -08:00
Mathias Agopian cc0486b3cc Rework material Variant filters
Variants are no longer just a bit mask, but rather a combination of
some bits, depending on the variant. Because of that the variant filer
must be updated.

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

This change does the impedance match between the two.
2022-02-13 22:53:47 -08:00
Mathias Agopian 8314bafc0e reformat Variant.h
indentation was wrong
2022-02-13 22:53:47 -08:00
daemyung jang 764c695e4e Fix typos 2022-02-12 19:30:19 -08:00
Philip Rideout 808ca42992 Vulkan: fix segfault during shutdown. 2022-02-11 16:45:23 -08:00
Philip Rideout 4a8428318b Refactor VulkanSwapChain to prep for image layout cleanup. 2022-02-11 14:50:51 -08:00
Philip Rideout c93059783b VulkanDriver: fix VkImageView mismatch in render pass logic. 2022-02-11 14:50:51 -08:00
Mathias Agopian d21f092645 make sure skinning bones are correctly initialized
Fixes: #5185
2022-02-10 20:34:53 -08:00
daemyung jang 9844803b26 Add function overloading for setMorphTargetBufferAt (#5169) 2022-02-10 15:55:41 -08:00
Philip Rideout cdadb43e50 WebGL: another fix for BufferDescriptor bindings.
The previous code would convert each element of the source data
into 8 bit-per-element, but we wnat to preserve the original format
that the user provides.

The new solution is to use `slice()` which is a robust way to clone
all the data in a typed array.

This fixes the new regression with Triangle that Ben caught.
2022-02-09 15:44:26 -08:00
Philip Rideout 2e0ace5026 WebGL: another fix for BufferDescriptor bindings.
The previous code would convert each element of the source data
into 8 bit-per-element, but we wnat to preserve the original format
that the user provides.

The new solution is to use `slice()` which is a robust way to clone
all the data in a typed array.

This fixes the new regression with Triangle that Ben caught.
2022-02-09 15:41:15 -08:00
Philip Rideout edaff60fbf WebGL: remove buffer sharing optimization.
If emscripten grows the heap inside one of our BufferDescriptor binding
functions, then the old heap becomes "detached" and an error can
occur.

This fixes the issue seen with the Parquet demo that Ben caught.
2022-02-09 12:51:06 -08:00
Philip Rideout b8725ffa22 WebGL: remove buffer sharing optimization.
If emscripten grows the heap inside one of our BufferDescriptor binding
functions, then the old heap becomes "detached" and an error can
occur.

This fixes the issue seen with the Parquet demo that Ben caught.
2022-02-09 12:29:54 -08:00
Mathias Agopian d2da478923 Added Scene::forEach to iterate through a scene's entities
Fixes #3010
2022-02-08 20:23:57 -08:00
Mathias Agopian 0b3e557b65 New Invokable function wrapper 2022-02-08 20:23:57 -08:00
daemyung jang 0d2faa4573 Revert adding APIs 2022-02-08 10:31:17 -08:00
daemyung jang 1924810c17 Deprecate MorphHelper
These changes bring the loading performance optimization by removing
flush and wait.
2022-02-08 10:31:17 -08:00
daemyung jang 6ab45a4cf0 Fix an annotation for the morph target count
Filament now supports the number of morph target up to 256.
2022-02-08 10:23:49 -08:00
Benjamin Doherty 3f64e46557 Bump version to 1.19.0 2022-02-08 09:27:14 -08:00
Benjamin Doherty 32dab23bc6 Update RELEASE_NOTES for 1.18.0 2022-02-08 09:25:41 -08:00
Benjamin Doherty 362de7dd31 Merge branch 'rc/1.18.0' into release 2022-02-08 09:22:21 -08:00
Benjamin Doherty 5e2c94c31a Release Filament 1.18.0 2022-02-08 09:18:10 -08:00
Benjamin Doherty 6b01fbb903 Correct version to 1.18.0 2022-02-08 09:08:49 -08:00
Philip Rideout 4934d9f7bc Vulkan: fix leak when apps do not draw anything. 2022-02-07 14:27:06 -08:00
Philip Rideout c1a99921b0 Vulkan: fix leak when apps do not draw anything. 2022-02-07 14:26:27 -08:00
Mathias Agopian 4a0dbbce12 fix typo in RenderTarget::build attachment size validation
the validation could fail if attachments used different LODs but the
sizes still matched.
2022-02-07 13:40:34 -08:00
Benjamin Doherty 7398183d6f Bump material version 2022-02-07 11:28:45 -08:00
Ben Doherty ed73955b00 Initialize useLegacyMorphing to fix MSAN warning (#5164) 2022-02-07 11:28:03 -08:00
Ben Doherty 3f1f2726c4 Add a MAX_LEGACY_MORPH_TARGETS definition (#5163) 2022-02-07 11:27:45 -08:00
Benjamin Doherty edf405c8fd Fix RELEASE_NOTES 2022-02-07 11:24:50 -08:00
Ben Doherty 4cc8f88a21 Add a MAX_LEGACY_MORPH_TARGETS definition (#5163) 2022-02-07 11:23:49 -08:00
Mathias Agopian 5dba7fdae0 move generateGaussianMipmap to PostProcessManager
also, allow it to specify the output format.
2022-02-04 16:24:27 -08:00
Ben Doherty e2b8573bd7 Initialize useLegacyMorphing to fix MSAN warning (#5164) 2022-02-04 14:43:18 -08:00
Mathias Agopian 6eeb4c9d3a refactor refraction code
filament/src/Renderer.cpp
- make code mode readable, hopefully
- SSR mipmap generation is now more or less standalone
- when possible, resolve color buffer directly into
  mimpmapped texture's base level.
2022-02-04 11:18:16 -08:00
daemyung jang 996981b102 Change CONFIG_MAX_MORPH_TARGET_COUNT's type correctly
CONFIG_MAX_MORPH_TARGET_COUNT should be positive value so size_t is
proper than int.
2022-02-04 11:17:58 -08:00
daemyung jang 4f4330c95e Update RELEASE_NOTES.md 2022-02-04 11:17:58 -08:00
daemyung jang e48f54a863 Fix validation errors on Metal 2022-02-04 11:17:23 -08:00
Philip Rideout 1a7bd7ea8d Rewrite VulkanPipelineCache (without changing its API).
All three types of caches (descriptor sets, pipelines, and pipeline
layouts) are now managed in exactly the same way. They all use an LRU
eviction scheme that is based on a count of command buffer flush
events.

Vulkan objects can only be destroyed if there are no in-flight command
buffers that reference them, so an easy way to know when it is safe to
evict a given entry is to wait for "N" flushes after its last use, where
"N" is the number of command buffers in the command buffer ring.

Another big simplification is that there are no more dirty flags,
instead we store two sets of state vectors for each type of cache: the
"currently bound" state, and the "current requirements" state.
2022-02-03 17:37:40 -08:00
Philip Rideout 2aa8ea4687 Rewrite VulkanPipelineCache (without changing its API).
All three types of caches (descriptor sets, pipelines, and pipeline
layouts) are now managed in exactly the same way. They all use an LRU
eviction scheme that is based on a count of command buffer flush
events.

Vulkan objects can only be destroyed if there are no in-flight command
buffers that reference them, so an easy way to know when it is safe to
evict a given entry is to wait for "N" flushes after its last use, where
"N" is the number of command buffers in the command buffer ring.

Another big simplification is that there are no more dirty flags,
instead we store two sets of state vectors for each type of cache: the
"currently bound" state, and the "current requirements" state.
2022-02-03 17:36:57 -08:00
Mathias Agopian cde055e5bf Minor cleanups
- Rename projectToPixelMatrix to uvFromViewMatrix, this match our 
existing style better.

- slightly more efficient direction transform

- limit roughness to 0.1 instead of 0.01, because in a lot of cases, 
the roughness increases with the LOD, for instance if it comes from
a texture (to combat aliasing).
2022-02-03 14:54:03 -08:00
Mathias Agopian 19729db982 turns out GLES3.x forbids depth texture filtering
warn about this condition on debug builds
2022-02-03 14:28:28 -08:00
daemyung jang 2029c9584e Get the morph target count from glTF
glTF spec says that all primitives MUST have the same number of morph
targets in the same order so these changes are more correct.
2022-02-03 13:26:09 -08:00
Ben Doherty d9cbe60ca6 Fix NaN values encountered with SSR and Metal (#5156) 2022-02-03 13:24:43 -08:00
Romain Guy 04337fdb68 Update Kotlin math API to latest (#5152)
Changes incorporated from github.com/romainguy/kotlin-math
2022-02-03 12:17:21 -08:00
daemyung jang a43b17716f Pass the current variant to GLSLPostProcessor
The current Variant is need to calculate BindingIndexMap correctly.
But we can't use the current Variant when calculate BindingIndexMap
because SamplerBindingMap uses only the dummy Variant. Both are
should be same.
2022-02-02 11:59:04 -08:00
daemyung jang 63032ed0a6 Add the morphing sampler group always
The morphing sampler group can be added if skinning or morphing is
enabled. However SamplerBindingMap can't know skinning or morphing
is enabled because only dummy Variant is used. It causes generating
the different sampler bindings between SamplerBindingMap and
program's sampler groups.

Fixes #5139
2022-02-02 11:59:04 -08:00
Ben Doherty 946ea43436 Fix sampler overflow check in SamplerBindingMap (#5143) 2022-02-02 11:04:48 -08:00
Ben Doherty b6cd6668a6 Fix sampler overflow check in SamplerBindingMap (#5143) 2022-02-02 11:04:08 -08:00
Romain Guy dee41e6120 Fix notebook 2022-02-02 10:04:48 -08:00
Mathias Agopian 7b03cb9b76 A few screen space reflections improvements
- Make sure to disabled SSR when it's... disabled.

- Fade the reflection when the ray direction is towards de camera,
  where it will likely hit a back face

- Simplify the fading code, for near identical results.
2022-02-02 09:36:20 -08:00
Philip Rideout 8aa83d4886 VulkanPipelineCache: fix spurious SEGV.
Fixes #5142 by replacing unsafe pointers with map keys.

One of the differences between robin_map and unordered_map is the
following:

    pointers to keys or values in the map are invalidated in the same
    way as iterators to these keys-values

Therefore it is unsafe to track the pointer to a value that is stored
in a robin_map.
2022-02-01 16:35:34 -08:00
Philip Rideout c17b3756ea VulkanPipelineCache: code cleanup and minor fixes.
This is mostly just code cleanup. One actual bug was the fact that the
dummy sampler was re-created every time a new pipeline layout was
created.

It also felt strange to use `auto&` to refer to a C-style array. I
changed this into a `std::array` which is more consistent with other
fixed size arrays in this class.
2022-02-01 16:35:34 -08:00
Philip Rideout 7f42385f5f VulkanPipelineCache: fix spurious SEGV.
Fixes #5142 by replacing unsafe pointers with map keys.

One of the differences between robin_map and unordered_map is the
following:

    pointers to keys or values in the map are invalidated in the same
    way as iterators to these keys-values

Therefore it is unsafe to track the pointer to a value that is stored
in a robin_map.
2022-02-01 16:34:34 -08:00
Philip Rideout 8845ac2b75 VulkanPipelineCache: code cleanup and minor fixes.
This is mostly just code cleanup. One actual bug was the fact that the
dummy sampler was re-created every time a new pipeline layout was
created.

It also felt strange to use `auto&` to refer to a C-style array. I
changed this into a `std::array` which is more consistent with other
fixed size arrays in this class.
2022-02-01 16:34:27 -08:00
Mathias Agopian 73e339b05d be more consistant with defines names in shaders
all defines coming from material parameters are named `MATERIAL_HAS_...` 
and all defines coming from the variant are named `VARIANT_HAS_...`
2022-01-31 22:53:48 -08:00
Ben Doherty 42172c7395 Add iterator include to Range.h (#5141) 2022-01-31 12:54:27 -08:00
Philip Rideout fbc0b8dab5 gltf_viewer: fix bad ReadPixels size in headless mode
This fixes the gltf_viewer automated testing mode, invoked via
`--batch=default --headless`.

ReadPixels was being issued with an out-of-bounds size on high DPI
platforms, which caused weird backend errors.

Since we create an invisible SDL window while in headless mode, the
presence of the SDL window does *not* indicate headless vs non-headless.

Partial fix for #5111
2022-01-31 11:34:13 -08:00
Mathias Agopian 91b45d2890 fix an out-of-bound access when setting morphing buffer
Because the morphing buffer is actually a texture, it's possible that
the last line is not a full width when updating the buffer.
Because texture are updated via a rectangle, it was possible to read
past the malloc'ed buffer during the update.

Moreover, because the count can be specified, we can't just blindly send
more "dummy" data. 

Finally, added an offset to match the skinning API, and in that case, 
the first line can also be incomplete.


We fix this by issuing up to 3 texture update calls if needed.


The java/js API update will come later.
2022-01-30 16:53:11 -08:00
daemyung jang 9df13c1cd2 Cleanup code 2022-01-28 21:41:19 -08:00
daemyung jangandMathias Agopian 5a3853a442 Optimize memory of MorphTargetBuffer (#5046)
* Optimize memory of MorphTargetBuffer

Co-authored-by: Mathias Agopian <mathias@google.com>
2022-01-27 21:19:13 -08:00
Mathias Agopian 70e14a1757 try to workaround optimizer/compiler bugs
Fixes #5088
2022-01-27 19:24:11 -08:00
Ben Doherty 4c4a93d9b5 Support legacy morphing (#5129)
Support legacy morphing (morphing with targets supplied via VertexAttributes) for older clients. This gives clients more time to transition over to the new MorphTargetBuffer API.
2022-01-27 16:16:53 -08:00
Ben Doherty da85001d4d Support legacy morphing (#5129)
Support legacy morphing (morphing with targets supplied via VertexAttributes) for older clients. This gives clients more time to transition over to the new MorphTargetBuffer API.
2022-01-27 16:08:46 -08:00
Mathias Agopian 001dcefd8a simplify how we select a material Variant
Instead of building the Variant based on flags in RenderPass, we just
pass the Variant itself to RenderPass. The caller has more knowledge
of what it wants to do.
2022-01-27 15:48:24 -08:00
Mathias Agopian d114d547be update material version to 18 2022-01-26 14:49:09 -08:00
Mathias Agopian 8d15079937 update material version to 18 2022-01-26 14:32:46 -08:00
adc542b5cd Bind samplers to specified shader stages (#5036)
Co-authored-by: Ben Doherty <bendoherty@google.com>
Co-authored-by: Mathias Agopian <mathias@google.com>
2022-01-26 14:31:30 -08:00
Philip Rideout 72feb044a3 Vulkan now supports offsets when uploading texture data.
This allows `MorphStressTest` to work on Vulkan.

However, `Horse` is still broken because it provides positions but not
tangents.  Separate fix for that is coming.

Partial fix for #5109.
2022-01-26 14:31:00 -08:00
Philip Rideout c0ba260ddf Vulkan: clean up image layout management.
This fixes validation errors and makes a first pass at simplification.
VulkanTexture now tracks image layout using RangeMap, which paves the
way for further simplification.
2022-01-26 14:30:45 -08:00
Philip Rideout 2da215e8e7 RangeMap: improve naming convention, etc. 2022-01-26 14:30:23 -08:00
Philip Rideout 4d0368b5f1 RangeMap: improve the auto-merge functionality. 2022-01-26 14:30:09 -08:00
Philip Rideout d11c78857d utils: introduce RangeMap container and unit test.
This will allow the Vulkan backend to efficiently track the subresource
image layouts for each texture.

This is a sparse container for a series of ordered non-overlapping
integer intervals, where each interval maps to a concrete value.
2022-01-26 14:29:45 -08:00
Mathias Agopian e829d90c4a A morphing buffer must be bound when skinning is active
This is because we're using the same program variant for skinning
and morphing, in the skinning-only case, the buffer won't be accessed
in the shader, but it must be present.

fixes #5085
2022-01-26 14:20:25 -08:00
Mathias Agopian a8006acd33 [GL backend] fix sampler binding bug
When a program had an unused SamplerInterfaceBlock, other samplers
could be bound to the wrong TMU

Fixes #5088
2022-01-26 14:20:12 -08:00
Philip Rideout 6403e0ce44 gltfio morphing: generate normals when they are missing.
This allows the `Horse.glb` model to work with Vulkan without any
validation errors. As a reminder, the glTF spec says:

```
When normals are not specified, client implementations MUST calculate
flat normals
```

Fixes #5115.
2022-01-26 13:48:05 -08:00
41cf507746 Bind samplers to specified shader stages (#5036)
Co-authored-by: Ben Doherty <bendoherty@google.com>
Co-authored-by: Mathias Agopian <mathias@google.com>
2022-01-26 12:22:07 -08:00
HanYunChenLuo c49fcf9018 WebGL: Support compile filament.wasm on Linux platform. (#5120) 2022-01-26 10:28:03 -08:00
daemyung jangandMathias Agopian 354c39be6b Get the morph target count from the renderable (#5077)
* Get the morph target count from the renderable
* Set the morph target count by Builder
* Update morph target weights partially
* Remove noexcept at functions could throw exceptions
* Update Java bindings at RenderableManager
* Add missing comments
* Update morph target weights from offset

Co-authored-by: Mathias Agopian <mathias@google.com>
2022-01-26 10:27:25 -08:00
wangjinhan 26bbe8ade1 fix build android aar on Linux because of case sensitive 2022-01-25 22:39:40 -08:00
daemyung jang 1952f0a1f7 Change morphing APIs to support LOD (#5080)
* Change morphing APIs to support LOD
* Add Java and Web bindings for morphing
* Omit and fix JS bindings
* Fix styles in MorphTargetBuffer.java
2022-01-25 21:57:11 -08:00
daemyung jang 61fdc0d375 Fix styles in SkinningBuffer.java (#5117) 2022-01-25 21:46:55 -08:00
Mathias Agopian 4060b558c7 Minor optimizations and documentation cleanup
- Document that both positions and tangents must be provided.
- Don't memset buffer before filling it
- Don't read 4 identical weights in shader
2022-01-25 17:16:43 -08:00
Philip Rideout a783df39ba Vulkan now supports offsets when uploading texture data.
This allows `MorphStressTest` to work on Vulkan.

However, `Horse` is still broken because it provides positions but not
tangents.  Separate fix for that is coming.

Partial fix for #5109.
2022-01-25 17:06:33 -08:00
Philip Rideout a9ccaf2ffb Vulkan: clean up image layout management.
This fixes validation errors and makes a first pass at simplification.
VulkanTexture now tracks image layout using RangeMap, which paves the
way for further simplification.
2022-01-25 15:45:58 -08:00
Mathias Agopian f40b08d826 Simplify and optimize morphing
There is no need to go through all primitive and call updateSamplerGroup,
because the SamplerGroup never changes -- it just hold the texture that
holds the data.
2022-01-25 14:08:15 -08:00
Mathias Agopian 9fd0397d45 A morphing buffer must be bound when skinning is active
This is because we're using the same program variant for skinning
and morphing, in the skinning-only case, the buffer won't be accessed
in the shader, but it must be present.

fixes #5085
2022-01-25 13:11:02 -08:00
Philip Rideout 69fb7170a7 Fix typo in BlueVK script that caused segfault.
Fixes #5026.
2022-01-25 10:23:07 -08:00
Mathias Agopian b69546c229 [GL backend] fix sampler binding bug
When a program had an unused SamplerInterfaceBlock, other samplers
could be bound to the wrong TMU

Fixes #5088
2022-01-25 10:09:22 -08:00
Alexey Pelykh 45054eece9 gltfio: support material extras 2022-01-25 10:04:10 -08:00
Philip Rideout 785f7de25d RangeMap: improve naming convention, etc. 2022-01-25 09:58:53 -08:00
Philip Rideout 509fb4ad23 RangeMap: improve the auto-merge functionality. 2022-01-25 09:58:53 -08:00
Philip Rideout 6577519bd7 utils: introduce RangeMap container and unit test.
This will allow the Vulkan backend to efficiently track the subresource
image layouts for each texture.

This is a sparse container for a series of ordered non-overlapping
integer intervals, where each interval maps to a concrete value.
2022-01-25 09:58:53 -08:00
Philip Rideout 43948421d7 Re-generate BlueVK and update to latest Vk headers.
Fixes #5026.
2022-01-25 09:14:23 -08:00
Philip Rideout 328650df17 BlueVK: Do not double initialize vkGetInstanceProcAddr.
This fixes a double-initialization problem for one of the function
pointers, and also updates the BlueVK generator to fix issues with the
latest Khronos XML file.

The corollary C++ changes will be made in a subsequent PR since they
will be difficult to review.

See #5026.
2022-01-24 13:40:49 -08:00
Benjamin Doherty 86ec502040 Bump version to 1.17.1 2022-01-24 12:52:22 -08:00
Benjamin Doherty b19a73cc50 Merge branch 'rc/1.17.0' into release 2022-01-24 12:50:22 -08:00
Benjamin Doherty b657ccd75a Release Filament 1.17.0 2022-01-24 12:48:28 -08:00
Benjamin Doherty a99c695932 Update RELEASE_NOTES for 1.17.0 2022-01-24 12:45:05 -08:00
Ondrej Stava 11cbb3d395 Fixed VulkanTexture::copyBufferToImage for 2D texture arrays
2D array textures are initialized with .depth = 1 and layerCount = depth (see line 58 in VulkanTexture.cpp). By setting layerCount = 1 only the first layer was copied over, leaving the other layers uninitialized.
2022-01-24 10:38:03 -08:00
Mathias Agopian c21d7c3f5e try to use the Variant type instead of uint8_t everywhere 2022-01-24 09:45:34 -08:00
Philip Rideout 975665c9c9 gltf_viewer: fix the "Export screenshot" checkbox.
This functionality (in the Automation section) was violating a
constraint that was landed in November.

1) Call postRender inside beginFrame / endFrame.

2) Use RGBA when issuing ReadPixels (required by some backends) and
   convert to RGB when dumping out the PPM file.
2022-01-24 08:32:29 -08:00
daemyung jang 613e1052c7 Make morphable entities selectable in UI 2022-01-21 16:18:19 -08:00
Mathias Agopian ba9e7fa17f Improve (again) comments in Variants.h
- Improved formating
- Added more compile-time sanity checks
- Renamed Variant bits to 3 letters
2022-01-21 14:24:24 -08:00
daemyung jang fa54bdd682 Update imgui to v1.86 2022-01-21 09:53:44 -08:00
Mathias Agopian 1678d02c87 Allow more flexible quality settings for the ColorGrading LUT 2022-01-20 09:55:16 -08:00
daemyung jang 5e535165a6 Get morph target names from FilamentAsset (#5066)
Get morph target names from FilamentAsset
Make morphable entities selectable in UI
2022-01-19 17:11:24 -08:00
Mathias Agopian 3de427b74f Fix integration of screen-space reflections with lighting
screen-space reflections are integrated in the indirect light computation
(similarly to screen-space refraction), this is because it can be seen as
the specular term of screen-space GI.

However, because this effect is screen-space, the data it accesses has 
the ibl luminance (and exposure) applied.

Besides some minor refactoring, this change just applies the 
screen-space reflections *after* the ibl's specular term is exposed.
2022-01-19 17:10:10 -08:00
Mathias Agopian 15899af7cf randomly jitter the ray with screen-space reflections
this helps a lot when stride is > 1
2022-01-19 17:09:54 -08:00
daemyung jang 443181c719 Enhance code readability 2022-01-19 15:54:08 -08:00
daemyung jang 02f96e2a1e Store morph weight buffer at PrimitiveInfo to avoid dereference 2022-01-19 15:54:08 -08:00
daemyung jang 67e0aa5488 Store morph target buffer at PrimitiveInfo to avoid dereference 2022-01-19 15:54:08 -08:00
daemyung jang c969005bcc Create and bind morphing buffer if skinning is enabled
The morphing buffer is needed even if skinning is enabled
because shader is generated by HAS_SKINNING_OR_MORPHING.
2022-01-19 15:54:08 -08:00
Mathias Agopian 5417d0953b Allow screen space refraction and reflection together
We can now do screen-space refraction and reflections at the same time.
This change mostly removes the checks that were preventing it from
working.

The real change in the PR is to adjust the reprojection matrix based
on whether the SSR buffer (both for refractions and reflections) comes
from this or the previous frame.
2022-01-19 13:30:12 -08:00
Mathias Agopian ddb4865ceb allow a scene to have both transmission and reflection
what's not allowed at this point is an object which has both screen
space refraction and reflection.

this is accomplished by just always disabling screen-space reflections
for the translucent step of the refraction pass.
2022-01-19 13:30:12 -08:00
Philip Rideout 7b5cac6d4f Do not include <algorithm> unless necessary. 2022-01-19 13:11:04 -08:00
Ben Doherty fb76f8ed80 Add Java / WebGL bindings for screen-space reflections (#5054) 2022-01-19 12:50:32 -08:00
daemyung jang 4b572cf065 Remove duplicated APIs 2022-01-19 09:55:59 -08:00
daemyung jang 3e3fc76688 Add FilamentAsset Java bindings 2022-01-19 09:55:59 -08:00
Romain Guy 700b4d5d38 Update docs and readmes 2022-01-18 16:54:31 -08:00
daemyung jang 9e29d042b9 Add a comment for further work 2022-01-18 16:53:04 -08:00
daemyung jang 13f3ebca89 Transition the initial image layout if TextureUsage::SAMPLEABLE 2022-01-18 16:53:04 -08:00
Philip Rideout 3e30632b8c Reduce cascade of run-time warnings.
The `uint8_t` here needs to be cast to an integer to be printed
correctly. Also these warnings seem to be quite common so we should
hide them in Release builds.

These warnings probably indicate an actual problem that I do not fully
understand yet.
2022-01-18 16:04:16 -08:00
Benjamin Doherty 8cd720b53a Bump version to 1.17.0 2022-01-18 13:54:40 -08:00
Benjamin Doherty 04df79e58f Merge branch 'rc/1.16.1' into release 2022-01-18 13:53:02 -08:00
Benjamin Doherty a8d72bb226 Release Filament 1.16.1 2022-01-18 13:52:08 -08:00
Benjamin Doherty a4b3717762 Update RELEASE_NOTES for 1.16.1 2022-01-18 13:48:36 -08:00
Ben Doherty bf3f7e0aef Fix, assertion with shadowReceiver = false and VSM (#5055) 2022-01-18 13:44:48 -08:00
Mathias Agopian 0fb04c576d improve structure pass performance when not used
Move the command generation of the structure pass into its execute 
block, meaning that if the structure pass is culled, the command 
generation is now skipped too.
2022-01-18 12:21:36 -08:00
Mathias Agopian caaa404d96 add basic support for Android Thermal Manager 2022-01-18 11:37:26 -08:00
daemyung jang 2fa6e6d031 Remove an useless log 2022-01-18 10:35:39 -08:00
daemyung jang 62bb25b26d Fix, potential null dereferences in OpenGLProgram
Morphing is enabled but no morph targets in some models.
2022-01-18 10:35:39 -08:00
Mathias Agopian 8d1402d37b Bring back the 3x3 filter for PCF shadows
The same can be achieved with VSM + blur=3 however, this is noticeably
slower. Also when using transparent shadows, VSM needs a much larger
blur to iron out the dithering pattern.

Fixes #5048, #5039
2022-01-14 15:08:46 -08:00
Ben Doherty afd657d6af Fix, incorrect refractions with screen-space reflections disabled (#5051) 2022-01-13 16:54:47 -08:00
Romain Guy 27a5158147 Update tone mapping operators notebook 2022-01-13 15:38:19 -08:00
Mathias Agopian dead7ab2ac Use NDK29 new (and experimental) way to access NDK functions
This uses compile time guarded calls to weak symbols, and allows us to
call NDK APIs without having to dlsym() them.
2022-01-13 15:20:26 -08:00
Mathias Agopian 352acff396 improve documentation regarding post-processing and render targets
Fixes #5015
2022-01-13 09:59:58 -08:00
Ben Doherty 00d9c6921d Add initial glossy screen-space reflections (#4946) 2022-01-12 13:59:11 -08:00
daemyung jang 6805940bbf Compute morphing on GPU (#4999) 2022-01-12 11:06:47 -08:00
Romain Guy 954f9112e4 Replace generic tonemap curve with a simpler one (#5041)
* Replace generic tonemap curve with a simpler one

This change removes the shoulder parameter which had inconsistent
behaviors. The new curve is simpler and designed to still match
by default the gray point and the contrast of ACES in a bright
surround.

* Fix build
2022-01-12 09:55:35 -08:00
hzzengxiaoqi 6465b9ade8 fix bug of GLTFIO_LITE, the macro GLTFRESOURCES_LITE_LIT_BLEND_DATA is not defined anywhere, it should be GLTFRESOURCES_LITE_LIT_FADE_DATA. This solves the issue of rendering transparent objects using GLTFIO_LITE macro, i.e. using gltfresources_lite.bin. If not change this macro, the transparent objects will be rended using LIT_OPAQUE material instead of LIT_FADE material. 2022-01-11 10:31:49 -08:00
Jared Fowler b67963176b Moving UiHelper to the constructor which allows for more composable control of the underlying views & surface 2022-01-11 08:56:42 -08:00
Ankbzpx fb1eb35ba5 Fix aabb misalignment for skinned gltf model (#4973) 2022-01-10 15:06:23 -08:00
Mathias Agopian 047543a4a6 make our ostream thread safe
ostream internals are now protected by a lock, which ensures the
internal state stays consistant, however, this won't prevent 
multiple threads to have their output ominterfering with each other,
which is no different from the stl behavior.


This fixes #4992
2022-01-10 15:04:26 -08:00
Mathias Agopian 5e0615040d refactor our ostream
The main change here is that we factorize all the interesting code in
a single function. This should result in smaller code.
2022-01-10 15:04:26 -08:00
Mathias Agopian 1ceed1519b attempt to fix compilation failure with gcc
fix #4990
2022-01-10 15:04:09 -08:00
Benjamin Doherty 1035e442ee Bump version to 1.16.1 2022-01-10 10:47:46 -08:00
Benjamin Doherty 60d3638f15 Merge branch 'rc/1.16.0' into release 2022-01-10 10:44:36 -08:00
Benjamin Doherty a1a3adf8af Release Filament 1.16.0 2022-01-10 10:43:35 -08:00
Benjamin Doherty 3e7d3c9035 Update RELEASE_NOTES for 1.16.0 2022-01-10 10:41:14 -08:00
jeanlemotan eb360be2ad Fixed cubemap update 2022-01-10 10:34:49 -08:00
Ben Doherty 620a693c11 FilamentApp: use PrtScn key to capture debug frame (#5032) 2022-01-10 10:28:34 -08:00
jeanlemotan 4511af6f9e Removed code duplication, better style. 2022-01-08 06:17:56 -08:00
jeanlemotan 214e54f2ad Make sure the width/height don't reach zero. 2022-01-08 06:17:56 -08:00
jeanlemotan 2eefbe11ae Fixed cubemap update 2022-01-08 06:17:56 -08:00
Mathias Agopian 74ea3d50c2 Make sure to object are aligned properly when allocated in the renderstream
fix #4991
2022-01-07 10:49:12 -08:00
jeanlemotan 9a8159ab04 Fixed compiler warning (int -> float conversion) 2022-01-07 10:17:04 -08:00
Ben Doherty 2f3aac29da Enable GL_ARB_shading_language_packing in vertex shaders (#5022) 2022-01-06 13:17:31 -08:00
jeanlemotan 9d7f5f593e Added line/triangle strip support (#5017)
* Added line/triangle strip support

* Added strip support for Java and JS
Changed README to indicate strip support for gltf
2022-01-06 13:07:32 -08:00
Ben Doherty 2596273a94 Avoid calling std::string(nullptr) in MockConfig.cpp (#5019) 2022-01-06 10:52:01 -08:00
Benjamin Doherty 210a8c2260 Update Renderer comment 2022-01-06 10:47:54 -08:00
Benjamin Doherty 485ac8704d Bump version to 1.16.0 2022-01-04 11:55:19 -08:00
Benjamin Doherty dc74540423 Merge branch 'rc/1.15.2' into release 2022-01-04 11:53:02 -08:00
Benjamin Doherty eaefaf8e59 Release Filament 1.15.2 2022-01-04 11:52:31 -08:00
Benjamin Doherty 96219c22db Update RELEASE_NOTES for 1.15.2 2022-01-04 11:49:50 -08:00
Romain Guy f3b7048775 Add missing JNI impl (#4959) 2022-01-04 11:43:19 -08:00
Romain Guy aaed6fb376 Fix rounding math 2022-01-04 11:43:13 -08:00
Ben Doherty 7873e6f5aa Metal: clamp readPixels width and height to texture dimensions (#4994) 2021-12-28 10:27:11 -07:00
abwood 251abf0545 Add support for the glTF extension KHR_materials_emissive_strength (#4975) 2021-12-23 01:32:45 -08:00
Mathias Agopian b5c4b30ff6 Fix a double release with Android bitmaps callbacks
The version of Texture::setBitmap() that tool an Android bitmap handled
callbacks differently and in certain case caused a "double release" of
the callback object. This didn't actually cause problems though.

We now use the same mechanism used elsewhere (i.e. JniCallback).
2021-12-15 09:18:23 -08:00
Mathias Agopian eb941a0868 Make normal skinning more efficient
With this change the cofactor matrix is partially precomputed on the 
CPU side.
2021-12-14 10:00:10 -08:00
Mathias Agopian 304ffe0049 Fix skinning calculations
it was incorrect to store bone matrices as quaternions because it is
allowed for these matrices to have a skew component.

We now store the 4x4 matrix -- which is the same amount of data as
before, however we compute the cofactor matrix in the vertex shader when
transforming normals.

fixes #4887
2021-12-14 10:00:10 -08:00
Mathias Agopian 88edbc7df8 Fix a java global reference leak
We were acquiring a reference twice by accident.

Fix #4957
2021-12-13 15:16:48 -08:00
Mathias Agopian 6fa82ea73d Fix typo when setting cubemap faces mip levels. 2021-12-13 15:16:33 -08:00
Mathias Agopian 92e7ff3de7 fix debug checks for compressed textures
Fixes #4941
2021-12-13 15:16:33 -08:00
Romain Guy 35a5d3310f Fix preprocessor test 2021-12-13 13:53:20 -07:00
Romain Guy 2739eb146a Fix rounding math 2021-12-13 10:54:31 -08:00
Romain Guy 59ccc3021f Add missing JNI impl (#4959) 2021-12-13 10:52:47 -08:00
Romain Guy 36e9fa42f4 Fix preprocessor test 2021-12-13 10:42:07 -08:00
Benjamin Doherty 9da79a1d2d Bump version to 1.15.2 2021-12-13 11:08:28 -07:00
Benjamin Doherty 595b355d1b Merge branch 'rc/1.15.1' into release 2021-12-13 11:06:45 -07:00
Benjamin Doherty 8111c50a5a Release Filament 1.15.1 2021-12-13 11:06:12 -07:00
Romain Guy 0e5e7e940c Fix typo in JNI binding 2021-12-10 08:35:16 -08:00
Ben Doherty 9f75d34bb8 Rework color history in preparation for SSR (#4932) 2021-12-08 13:35:54 -08:00
Mathias Agopian df42213daf update remote ui 2021-12-08 00:25:25 -06:00
Mathias Agopian b73caceb1f fix libibl on mobile
- the hammersley sequence was completely wrong because of a missing
  highp precision qualifier

- roughness 0 was also wrong because of divide-by-0

Fixes #4668
2021-12-08 00:17:29 -06:00
Mathias Agopian c91f28b6be fix remote UI when dropping a new .hdr ibl file
- the ibl wasn't updated in internal structures
- the previous ibl was leaked
2021-12-08 00:17:29 -06:00
Mathias Agopian 078de4e422 Add support for basic PCSS 2021-12-08 00:17:12 -06:00
Romain Guy 332d5681e6 Update dependencies 2021-12-07 09:34:28 -08:00
Benjamin Doherty 3a67d769f4 Update RELEASE_NOTES for 1.15.1 2021-12-06 16:54:28 -08:00
Romain Guy de1281dd9f Be more specific about anisotropyDirection 2021-12-06 15:37:41 -08:00
Benjamin Doherty f3849a1f57 Update web docs for 1.15.0 2021-12-06 12:59:23 -08:00
Mathias Agopian 3fd63b1b3d use the correct normal when calculating spotlight bias
`vertex_worldNormal` should never be used directly, for one thing it's
not guaranteed to be normalized.
2021-12-06 14:11:45 -06:00
Benjamin Doherty 6fb536a937 Bump version to 1.15.1 2021-12-06 11:17:37 -08:00
Benjamin Doherty bb460d78d8 Merge branch 'rc/1.15.0' into release 2021-12-06 11:14:00 -08:00
Benjamin Doherty 3a33220dad Release Filament 1.15.0 2021-12-06 11:12:58 -08:00
Mathias Agopian 09a9deafc0 Fade lights out when close to light far plane
the fade takes place over 10% of the light far distance.
2021-12-06 11:45:15 -06:00
Mathias Agopian 4de3470de5 remove 'exponent' from VsmShadowOptions
this is an internal parameter and has no reason to be user settable.
2021-12-03 14:45:59 -06:00
Romain Guy f03d654862 Update README.md 2021-12-03 09:28:02 -08:00
Mathias Agopian b8a39c2f3d disable workaround on recent adreno drivers
A workaround for the tile load/store is no longer needed on recent
version of the GLES3.x drivers on qualcomm SoC.
2021-12-03 11:25:38 -06:00
Romain Guy 291b5dcec5 Update README.md 2021-12-02 23:36:57 -08:00
Mathias Agopian 087f29c6c9 Added support for DPCF 2021-12-03 01:20:50 -06:00
Mathias Agopian aac3ac579c add global temporal noise uniform when TAA is enabled
this can be used to easily add temporal noise to "things" when
TAA is also enabled.
2021-12-03 01:20:50 -06:00
Benjamin Doherty 838835a715 Update RELEASE_NOTES for 1.15.0 2021-12-02 11:52:04 -08:00
Romain Guy c275f61aeb Add missing destroy method (#4921) 2021-12-02 08:53:55 -08:00
MasTraER f297948216 Expose Engine::destroy(SkinningBuffer*) (#4919) 2021-12-02 08:41:10 -08:00
Ben Doherty dbe1386785 Fix live wallpaper sample with Android 12+ (#4917) 2021-12-01 12:29:11 -08:00
Joel Winarske 687f4aff13 Flags to support embedded Linux (#4911)
- FILAMENT_SKIP_SDL2=ON is used to  skip dependencies of sdl2 and sdl2 CMake

- FILAMENT_LINUX_IS_MOBILE is used for Mobile build

Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
2021-12-01 08:31:06 -08:00
Romain Guy dd4853bcc5 Replace ANDROID with __ANDROID__ (#4909)
__ANDROID__ is always set by the toolchain and less likely to cause
conflicts than ANDROID. This change also removes the -DANDROID flag
we set ourselves in our toolchain CMake files since we don't need
it anymore.
2021-11-30 16:27:56 -08:00
Benjamin Doherty ffbfc13530 Fix RELEASE_NOTES 2021-11-30 15:52:17 -08:00
Ben Doherty 2aa160a98c Fix release build crash in gltf_viewer (#4908) 2021-11-30 12:29:45 -08:00
Ben Doherty 477a3a8771 Pin web docs Filament version (#4907) 2021-11-30 12:05:40 -08:00
Romain Guy 63acd53e23 Use __ANDROID__ instead of ANDROID 2021-11-30 11:15:49 -08:00
Romain Guy fcd2d0457b Workaround for a build system issue 2021-11-30 11:15:42 -08:00
Romain Guy c0e8686297 Use __ANDROID__ instead of ANDROID 2021-11-30 11:14:35 -08:00
Romain Guy 01f18caf53 Workaround for a build system issue 2021-11-30 10:05:32 -08:00
Joel Winarske 56971520a2 Fix typo and remove extraneous return
Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
2021-11-30 11:18:57 -06:00
Joel Winarske f5e38b1198 Requested changes
- remove const

- remove egl references in wayland struct

Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
2021-11-30 11:18:57 -06:00
Joel Winarske 984ef2a089 Remove un-implemented test case
Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
2021-11-30 11:18:57 -06:00
Joel Winarske ad960c73b6 Remove traces of Wayland EGL
Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
2021-11-30 11:18:57 -06:00
Joel Winarske 0dcc631aa8 Backout Wayland EGL backend
Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
2021-11-30 11:18:57 -06:00
Joel Winarske af9b670cfd Wayland 2021-11-30 11:18:57 -06:00
Benjamin Doherty 58fc26461b Bump version to 1.15.0 2021-11-29 14:08:28 -08:00
Benjamin Doherty fd82f6b04e Merge branch 'rc/1.14.2' into release 2021-11-29 14:07:03 -08:00
Benjamin Doherty 519ae4d143 Release Filament 1.14.2 2021-11-29 14:05:55 -08:00
Mathias Agopian 8d72869437 Fix spotlight normal bias calculation (#4844)
The calculation was completely wrong due to several typos more or less
canceling each other, that led to some misunderstanding!
2021-11-29 14:05:40 -08:00
Romain Guy 2cbacb532a Cache calls to Enum.values() (#4902)
Each call to .values() allocates a new array. Let's cache them once
and for all to avoid unncessary allocations.
2021-11-29 11:35:58 -08:00
Romain Guy 1da2bf2f7a Update WebGl demos 2021-11-29 11:29:22 -08:00
Benjamin Doherty cef3200533 Add additional RELEASE_NOTES for 1.14.2 2021-11-29 10:21:56 -08:00
Ben Doherty 634500c398 Fix, avoid divide-by-zero inside makeBone (#4889) 2021-11-24 16:29:33 -08:00
Ben Doherty 802bc7a5dc Fix, avoid divide-by-zero inside makeBone (#4889) 2021-11-24 16:28:44 -08:00
Romain Guy 8875806c5d Use locale-independent string->float conversion (#4885)
* Use locale-independent string->float conversion

strtof and friends are locale aware and won't parse decimal numbers
with a period ("12.6" for instance) in locales that use another
character for the decimal period ("," in French for instance).

This change introduces a new function called strtof_c that forces
the use of a specific locale (called "C") to make sure we always
parse floats in the desired "C" format ("12.6").

With C++17 we should be able to use std::from_chars but this API
is not implemented in clang for floats at the moment.

* Fix Linux
2021-11-23 12:32:54 -08:00
Benjamin Doherty c9df807f1f Update backend-test project with filamat dependency 2021-11-23 12:14:05 -08:00
Ben Doherty b3e294ac54 Fix Metal depth comparison initialization (#4886) 2021-11-23 12:09:43 -08:00
Ben Doherty 3feef4e84b Fix Metal depth comparison initialization (#4886) 2021-11-23 12:00:58 -08:00
Benjamin Doherty 2bf7535ad0 Update RELEASE_NOTES for 1.14.2 2021-11-22 10:16:00 -08:00
Benjamin Doherty 3315f75de9 Bump version to 1.14.2 2021-11-22 10:12:44 -08:00
Benjamin Doherty bbe7dbfa92 Merge branch 'rc/1.14.1' into release 2021-11-22 10:11:06 -08:00
Benjamin Doherty 15001524bd Release Filament 1.14.1 2021-11-22 10:10:35 -08:00
Romain Guy c1713e7501 Export activities on Android 12+ 2021-11-22 09:25:13 -08:00
Romain Guy 0181584735 Update build tools (#4866)
* Update build tools

SDK API level 31
NDK 23
Kotlin 1.6

* Preserve tool suffix for Windows
2021-11-17 13:19:45 -08:00
Ben Doherty df06e8dc41 Fix material compilation error with device vertex domain (#4865)
A recent refactor was causing the following error when the vertex domain
was set to `device`:
```
ERROR: main.vs:23: 'material' : undeclared identifier
ERROR: main.vs:23: 'materialVertex' : no matching overloaded function found
```
2021-11-17 12:04:41 -08:00
Benjamin Doherty 5697922a65 Update RELEASE_NOTES for 1.14.1 2021-11-17 12:04:26 -08:00
Ben Doherty 4da83df2b9 Fix material compilation error with device vertex domain (#4865)
A recent refactor was causing the following error when the vertex domain
was set to `device`:
```
ERROR: main.vs:23: 'material' : undeclared identifier
ERROR: main.vs:23: 'materialVertex' : no matching overloaded function found
```
2021-11-17 12:03:55 -08:00
Ben Doherty 8f156d6588 Android: re-enable VSM cascade fix (#4863) 2021-11-17 10:19:09 -08:00
Ben Doherty b0ce077ace Android: re-enable VSM cascade fix (#4863) 2021-11-17 10:14:47 -08:00
Ben Doherty 9d29d2e32c Update spirv-tools to v2021.4 (#4862) 2021-11-16 17:13:42 -08:00
Ben Doherty a29b438161 Update glslang to eb92526 (#4861) 2021-11-16 13:26:58 -08:00
Ben Doherty 50a042bb16 Metal: fix validation error when rendering to RT without depth (#4860) 2021-11-16 11:50:23 -08:00
Benjamin Doherty cec0871c11 Bump version to 1.14.1 2021-11-15 10:09:45 -08:00
Benjamin Doherty 41a809368b Merge branch 'rc/1.14.0' into release 2021-11-15 10:07:56 -08:00
Benjamin Doherty f690015a88 Release Filament 1.14.0 2021-11-15 10:06:45 -08:00
Ben Doherty 342deb5a64 speed up under ThreadSanitizer (#4842) 2021-11-12 09:52:58 -08:00
Mathias Agopian fdc480ff6e Gaussian blur is now applied only on the needed channels
The gaussian blur code was always processing 3 channels no matter the
source or destination. We now have 4 versions for all possible cases.
2021-11-11 23:35:10 -08:00
Mathias Agopian 378b7cd4dd rearrange EVSM code to make it easy to test full EVSM
We're currently only using the positive layer of EVSM which works
work small blurs and anti-aliasing. This just rearranges the code to
make it easy to test the full formulation.
2021-11-11 23:35:10 -08:00
Mathias Agopian f779fc7a0e move the shadowmap position computation inside shadow()
This is possible because, in fact, we know if we're dealing with a
spot or directional light when we invoke shadow(). So a conditional
inside it is resolved at compile time.

This will allow more flexibility in the future. Also now the shadow()
function only needs the shadow index and cascade -- which is more
future proof (e.g. if we want to handle more than one directional
shadow or spot lights with cascades).
2021-11-11 23:35:10 -08:00
Mathias Agopian fe11f495d6 simplify how we compute the shadow position
this effectively undoes a recent change, where we had a method for
spot lights and one for the directional light. instead, we can
calculate the bias at the correct Z on the caller side -- which is
needed only for spotlights.
2021-11-11 23:35:10 -08:00
Mathias Agopian 265876c849 store the texel size in world-space in the spot shadow structure 2021-11-11 23:35:10 -08:00
Mathias Agopian c9c52518c0 repair transparent shadows 2021-11-10 19:48:25 -08:00
Mathias Agopian 96c9ac6f8b fix point-lights which broke recently.
The faulty commit was:

commit 23dab0a013
Author: Mathias Agopian <mathias@google.com>
Date:   Fri Oct 29 12:03:14 2021 -0700

    Fix very narrow spotlight lighting and other minor issues
2021-11-10 15:22:38 -08:00
Ben Doherty bdeb30a847 Use workflow_dispatch instead of repository_dispatch (#4834) 2021-11-10 13:38:58 -08:00
Romain Guy ea53eb9290 Skip task incompatible with configuration caching (#4831) 2021-11-09 15:56:00 -08:00
Benjamin Doherty 05875057c9 Update RELEASE_NOTES for 1.14.0 2021-11-09 15:51:13 -08:00
Romain Guy d67210155b Skip task incompatible with configuration caching (#4831) 2021-11-09 15:01:02 -08:00
Mathias Agopian ae92c50cee more robust GL compiler error parsing 2021-11-09 14:59:50 -08:00
Mathias Agopian 43429dc0ec remove depth_main.vs from source tree 2021-11-09 12:34:19 -08:00
Mathias Agopian 04cf92a27f Remove all "Shadow Receiver Plane Depth Bias" related code
Shadow Receiver Plane Depth Bias is only needed when using large PCF
filters, which we are no longer doing. Large filter kernels are now 
supported through VSM sampling.
2021-11-09 12:31:43 -08:00
Mathias Agopian 57a57f50f6 most methods can be static in CodeGenerator 2021-11-09 12:31:28 -08:00
Mathias Agopian 5e5a75e6c5 fix bug with MASKED blending mode introduced in previous PR 2021-11-09 10:27:52 -08:00
Mathias Agopian 109c86aaf7 get rid of depth_main.vs
It's functionality is now handled in main.vs which, hopefully will be
less error prone.
2021-11-09 09:54:50 -08:00
Mathias Agopian 10e7e7727a filamat cleanup
This changes how we select the "optimized depth vertex shader", but
this shouldn't change the current behavior.

We now select the "optimized depth vertex shader" if and only if the
user code is empty. In that case, we can safely assume we can remove
all the code that's not necessary for the depth, since it is all
controlled by filament.
2021-11-09 09:54:50 -08:00
Mathias Agopian a39775050a workaround a IDE (CLion) code parsing bug
It looks like some parts of CLion don't like MaterialDomain because
it exists as an enum value
2021-11-09 09:54:50 -08:00
Benjamin Doherty 44125926d1 Disable configuration-cache 2021-11-08 17:05:34 -08:00
Benjamin Doherty 60734349de Bump version to 1.14.0 2021-11-08 11:52:50 -08:00
Benjamin Doherty fbfd5ec0ec Merge branch 'rc/1.13.0' into release 2021-11-08 11:50:19 -08:00
Benjamin Doherty 157c0264af Release Filament 1.13.0 2021-11-08 11:49:39 -08:00
Mathias Agopian 9bacfdb390 simplify shadowing code
- remove PCF "low" quality, we only use "HARD" now, when using PCF.
  Higher quality levels are achieved by using VSM.

- added a version of PCF that doesn't use a shadowSampler for future
  use.
2021-11-04 23:01:08 -07:00
Mathias Agopian f9aaf5c42e Fix normal bias for spotlights.
The normal bias is now computed correctly, this requires to compute
the z in lightspace in the shader.
Note that this would not work as well if we used LISPSM, but we'll
cross that bridge when we get there.
2021-11-04 14:56:00 -07:00
Ben Doherty a74a95cc65 Call VirtualMachineEnv::JNI_OnLoad for non-Android Java builds (better fix) (#4779) 2021-11-04 13:28:17 -07:00
Ben Doherty 21db695e79 Call VirtualMachineEnv::JNI_OnLoad for non-Android Java builds (better fix) (#4779) 2021-11-04 13:28:08 -07:00
Mathias Agopian cf917f1093 Add a (crude) way to have structs in our UBOs
The struct must be declared in common_type.fs, so custom
structures are not supported.
2021-11-04 12:43:50 -07:00
Ben Doherty a8d3a61c25 Enforce readPixels is called within frame (#4802) 2021-11-03 10:59:25 -07:00
Mathias Agopian 80f13a8149 fix typo in comments 2021-11-03 10:54:05 -07:00
Mathias Agopian e172f3a67f Fix java shadow biases + minor cleanups
- constant bias and normal bias default values in java didn't match
  C++ or the documentation

- stable shadows were enabled by default in java

- polygon offset biases were missing from the java API

- document and don't apply polygon offset to VSM

- remove unused code
2021-11-03 00:20:48 -07:00
Mathias Agopian c382c0a9cc Tighten spotlights near/far further
We now cull the shadow casters before computing the near/far plane
for spotlights -- we can do that because we know the light's frustum.
So only these casters that contribute to the shadow are accounted for
when calculating the near/far plane.

This PR also include more cleanup and simplifications.
2021-11-02 14:05:09 -07:00
Benjamin Doherty bc0ea16ff0 Update RELEASE_NOTES for 1.13.0 2021-11-02 13:15:53 -07:00
Mathias Agopian b2dc8aa84c Fix typo that broke the directional shadowmap 2021-11-02 13:11:44 -07:00
Mathias Agopian 78b29fe967 Fix typo that broke the directional shadowmap 2021-11-01 16:41:30 -07:00
Benjamin Doherty 9987e8b6ab Bump version to 1.13.0 2021-11-01 14:59:11 -07:00
Benjamin Doherty 0d9bdcc008 Merge branch 'rc/1.12.11' into release 2021-11-01 14:55:58 -07:00
Benjamin Doherty 81fa33abeb Release Filament 1.12.11 2021-11-01 14:55:54 -07:00
Mathias Agopian af7f87e19b make sure the near plane for spot shadows is not negative 2021-11-01 14:19:13 -07:00
Mathias Agopian 3073b03d56 Improve computation of spotlight near/far plane
Near/far plane is now computed dynamically, this significantly
improves the shadowmap depth resolution.

Quite a bit of refactoring was necessary to get all the right data 
in the right place, in particular SceneInfo is now passed around for
both directional and spot shadows.
2021-10-29 18:57:26 -07:00
Mathias Agopian 23dab0a013 Fix very narrow spotlight lighting and other minor issues
The froxel code was failing when a spotlight cone was too narrow. This
is fixed here by never using a cone smaller than 0.5 degrees during
forxelization. 

Additionally we now silently clamp the cone angles to 0.5 degrees at
the API level because, the falloff was also failing due to floating
point precision in the shader.

Finally, we clamp the inner cone upper value to the outer cone's
instead of the other way around. i.e. the outer cone defines the 
spotlight while the inner cone just controls the falloff.
2021-10-29 15:08:05 -07:00
Mathias Agopian fd68144ba2 fix depth precision with VSM
When calculating the linear depth for VSM, we were using the whole
range between 0 and the far plane, the near plane wasn't taken into
account.

This can be a problem is the light is very far, but it's near plane is
closer to the camera/scene, in this case the depth precision wasn't
used optimally.

Note that we don't hit this problem currently, because the directional
light is constructed such that its origin is at the near plane, and the
spotlights have a fixed near plane (which is a problem and will be 
fixed at a later time).
2021-10-29 12:03:41 -07:00
Mathias Agopian 51e92cd142 Fix spotlight direction and falloff
Direction and falloff were recently changed to fp16 int the shader,
which is not enough (far from it) when a spotlight is over 100m away.
2021-10-28 21:59:01 -07:00
Mathias Agopian 50f33f7196 fix some warnings and typos 2021-10-28 21:58:45 -07:00
Benjamin Doherty b5c634045e Update RELEASE_NOTES for 1.12.11 2021-10-28 16:13:50 -07:00
Ben Doherty 1f05531d53 Call VirtualMachineEnv::JNI_OnLoad for non-Android Java builds (better fix) (#4779) 2021-10-28 16:02:23 -07:00
Benjamin Doherty 88f382f0e3 Revert "refactor colorgrading materials"
This reverts commit fb86a77cf8.
2021-10-28 15:56:50 -07:00
Benjamin Doherty 3e59925900 Remove problematic configuration-cache setting for release build 2021-10-28 15:56:26 -07:00
Mathias Agopian 1182d30fb9 MSAA VSMs seem to now work on Qualcomm h/w
The bug that prevented them to work has been worked around, but we 
don't know when or how. The original bug still exists as demonstrated
by our standalone test apk.

For now, we reenable MSAA VSM on Adreno.
2021-10-26 16:06:20 -07:00
095179eeb3 Enabled Gradle configuration caching and rename properties (#4769)
* Fix configurationg caching problems

* Enable Gradle configuration caching

* Update BUILDING.md

* Update RELEASE_NOTES.md

Co-authored-by: Mathias Agopian <mathias@google.com>

Co-authored-by: Benjamin Doherty <bendoherty@google.com>
2021-10-26 12:47:35 -07:00
Romain Guy 69b48eaadb Fix erroenous warning 2021-10-26 12:05:49 -07:00
Timo Röhling 4031c6f0d3 Simplify devendoring (#4765)
* Perform sanity check when combining static libraries

This is a small modification that simplifies Debian packaging when one
or more vendored dependencies are replaced by system shared libraries
and no longer need to be combined with a Filament library.

* Verify vendoring before including license texts

This is another small modification to simplify Debian packaging when one
or more vendored dependencies are removed and replaced by system
libraries, so they no longer need to be considered when compiling the
license texts.
2021-10-26 11:31:35 -07:00
Mathias Agopian 7a22f7dfc5 move some VSM computations into the vertex shader 2021-10-26 11:26:21 -07:00
Mathias Agopian 728ebf5023 cleanup shadowing shader code
- remove PCF MEDIUM and HIGH quality -- these were never used in
practice, and "quality" really meant "blurriness", now we have VSM
for doing that with much more control and more efficiently.

PCF_HARD is now the default. PCF_LOW is still available at compile time
for now. It shouldn't be needed though because VSM can achieve the same.

Moved the divide-by-w of light space into the shadow() method -- which
known if it should be done or not.
2021-10-26 11:26:21 -07:00
Timo Röhling 62476d2f06 Fix compatibility with libstdc++ (#4763)
The codebase needs only a few additional standard #includes to compile
against libstdc++ on Linux; presumably those headers are implicitly
included with MSVC's and Clang's standard C++ library, but even if
libstdc++ compatibility is not a goal, it is advisable to have them
included directly.
2021-10-26 11:07:39 -07:00
Benjamin Doherty ea404f8d4f Remove problematic configuration-cache setting for release build 2021-10-26 10:09:51 -07:00
Benjamin Doherty 602a550d93 Bump version to 1.12.11 2021-10-25 12:30:37 -07:00
Benjamin Doherty 12abbe2d23 Merge branch 'rc/1.12.10' into release 2021-10-25 11:06:18 -07:00
Benjamin Doherty 5fea428243 Release Filament 1.12.10 2021-10-25 11:06:12 -07:00
Benjamin Doherty fb0ee97588 Update RELEASE_NOTES for 1.12.10 2021-10-25 11:00:06 -07:00
Ben Doherty 56ef48c9c3 Fix, call VirtualMachineEnv::JNI_OnLoad for non-Android Java builds (#4749) 2021-10-25 10:39:24 -07:00
Benjamin Doherty 47c3dd3dd1 Revert "refactor colorgrading materials"
This reverts commit fb86a77cf8.
2021-10-25 10:37:52 -07:00
clayly 9a3c9ccbf3 android-samples-gradle-plugin-id (#4740) 2021-10-24 11:12:15 -07:00
Ben Doherty ef4dfcecd6 Metal: support framebuffer fetch on M1 devices (#4735) 2021-10-21 11:27:05 -07:00
Ben Doherty 5943382d23 iOS: avoid precision issues with CACurrentMediaTime (#4753) 2021-10-21 11:13:51 -07:00
Benjamin Doherty c181648bfa Bump version to 1.12.10 2021-10-20 12:15:51 -07:00
Benjamin Doherty 0cf78b3abe Merge branch 'rc/1.12.9' into release 2021-10-20 12:12:33 -07:00
Benjamin Doherty 1dcf347b87 Release Filament 1.12.9 2021-10-20 12:11:46 -07:00
Ben Doherty 47714007f7 Fix VirtualMachineEnv.cpp with older JNI versions (#4752) 2021-10-20 11:18:03 -07:00
Ben Doherty 22889a7ad9 Fix VirtualMachineEnv.cpp with older JNI versions (#4752) 2021-10-20 11:16:55 -07:00
Ben Doherty a14451d0ac Fix, call VirtualMachineEnv::JNI_OnLoad for non-Android Java builds (#4749) 2021-10-20 10:41:34 -07:00
Benjamin Doherty 5dfdab10b7 Revert "refactor colorgrading materials"
This reverts commit fb86a77cf8.
2021-10-19 16:13:21 -07:00
Mathias Agopian 54277572d2 code health: cleanup FrameInfo and FrameSkipper a bit
in particular add a terminate() method to FrameSkipper instead of
destroying driver objects in the destructor -- this matches all other
objects.

also remove dependency on FEngine which wasn't needed.
2021-10-18 18:41:59 -07:00
Mathias Agopian 52f2c0e107 don't use static initialization when not needed
static init/destruction is always dangerous
2021-10-18 15:36:17 -07:00
Mathias Agopian 59abc8cc20 use NEAREST filtering for the final blit
the final blit, when used, is never upscaling, so always use the 
NEAREST filter.
2021-10-18 12:18:57 -07:00
Mathias Agopian e15796b348 Rewrite controller for dynamic resolution scaling
- move the control code out of FrameInfo and into
  View itself. FrameInfo now just gathers information about the 
  frames instead of also doing part of the control.

- the control code has been refactored into a more formal PIDController.

- a few bugs were fixed in the control loop and default parameters
  tuned. 


The control loop itself now outputs a relative scale factor instead
of an absolute one. The relative scale factor seems easier to
control and is less jittery, and doesn't have to rely on the "integral"
term of the PID.

It's possible that more tuning is needed, but the scaling is now 
more stable.
2021-10-18 10:06:44 -07:00
Mathias Agopian 1711eaa4d6 Minor improvements to DebugRegistry
- remove getProperties() we'll put it back if we need it some day

- use unordered_map because it generates less code than robin_map and
  here performance is not critical
2021-10-18 10:06:44 -07:00
Mathias Agopian acbd6a5ca8 Improve dynamic resolution scaling
- defaults to 31 history points instead of 3, this gives a much better 
  estimate of the frame rate.

- make sure the calculations work for any definition of our internal
  duration<> (it's useful to use milliseconds when dealing with
  refresh periods).

- don't round to 8 pixels if the scale factor is exactly 1

- fix a few comments and warnings
2021-10-18 10:06:44 -07:00
Romain Guy 775090fdda Re-fix tests 2021-10-15 17:30:06 -07:00
Romain Guy 0915b86927 Fix tests 2021-10-15 16:23:45 -07:00
BStringhamVRSK c10f7b01f4 Fixes normal map issues in mipgen and exposes a couple of SurfaceOrientation functions for Web
* mipgen: Linearized PNG bitmaps (such as normal maps) no longer perform gamma transform on read.

* mipgen: Using "-k normals" argument now works for all file types, not just KTX

* Web: Exposed SurfaceOrientation functions getQuatsHalf4() and getQuatsFloat()
2021-10-15 14:23:41 -07:00
Mathias Agopian 84142ac506 move platform related files into a platforms directory
this is just to improve source code readability.
2021-10-14 22:48:16 -07:00
Mathias Agopian ff190847a1 ExternalStreamManagerAndroid actually depends on GLES
Since ExternalStreamManagerAndroid depends on GLES, move it to the 
opengl directory.
2021-10-14 22:48:16 -07:00
Mathias Agopian 3ceec28189 added a way to check for adreno driver version
not used yet, but good too have.
2021-10-14 19:35:17 -07:00
Benjamin Doherty d6f2e3b8e9 Update RELEASE_NOTES for 1.12.9 2021-10-14 18:22:20 -07:00
Romain Guy 481038152f Cleanup of Android projects (#4730) 2021-10-13 18:17:12 -07:00
Rupert Rawnsley 60bd72730d ASTC texture enum missing in JNI interface 2021-10-13 10:18:54 -07:00
Benjamin Doherty df30517743 Bump version to 1.12.9 2021-10-11 11:06:43 -07:00
Benjamin Doherty 8f80643c1a Merge branch 'rc/1.12.8' into release 2021-10-11 11:02:56 -07:00
Benjamin Doherty eabfd08473 Release Filament 1.12.8 2021-10-11 11:02:30 -07:00
Mathias Agopian a66af0ac58 Minor settings cleanup
- set sensical default for gltf-viewer
- fix some warnings in ToneMapper
- fix some warnings in Settings.cpp
- minor refactor in Settings.h
2021-10-08 18:10:05 -07:00
Mathias Agopian 15187e9d99 Workaround for incorrect glInvalidateFramebuffer on Adreno
Unfortunately this bug appeared in recent drivers on some devices, it's
virtually impossible to know which device/drivers have this issue, so
the workaround is active for all Adreno GPUs.

glInvalidateFramebuffer is too aggressive and prevents loading of the
GMEM even if it's only called at the end of the render pass.
2021-10-07 20:58:34 -07:00
Mathias Agopian 681e8f8b59 Add VERBOSE log level
It is accessible through slog.v. On android it goes to the VERBOSE
log, on desktop, it's suppressed in release.
2021-10-07 20:58:34 -07:00
Mathias Agopian fbb406ca7d fix dynamic scaling internal debugging 2021-10-07 19:51:55 -07:00
Benjamin Doherty 5aea9be2fb Update RELEASE_NOTES for 1.12.8 2021-10-07 11:03:45 -07:00
Ben Doherty aacaf5055e Fix typo in View.java 2021-10-07 10:55:41 -07:00
Romain Guy a5dbddfd12 Fix release distribution (#4713)
Statically link SDL2 to make our samples (glTF Viewer, etc.) completely
standalone, and include missing resources (fonts and default environment
map for the IBL).
2021-10-07 10:11:27 -07:00
Mathias Agopian 764a0df669 Add DynamicResolution to Settings
update remote ui
2021-10-06 21:25:17 -07:00
BStringhamVRSKandRomain Guy f04864c216 Expose ColorGrading$Builder, View.setPostProcessingEnabled()/View.setAntiAliasing() JS bindings
Co-authored-by: Romain Guy <romainguy@curious-creature.com>
2021-10-06 14:21:18 -07:00
Mathias Agopian 11a1b31a4c HDR aware MSAA resolve
When supported and enabled, resolve MSAA using an HDR aware filter,
which improves anti-aliasing quality.

This is only supported with backends that support multi-sampled
framebuffer-fetch. Currently, only Metal on iOS and GLES.

Update remote ui.
2021-10-06 14:15:09 -07:00
Mathias Agopian fb86a77cf8 refactor colorgrading materials 2021-10-06 14:15:09 -07:00
Mathias Agopian d512357928 update remote ui 2021-10-06 12:45:41 -07:00
Mathias Agopian b850bc827e Fix MSAA settings ostream operator 2021-10-06 08:54:04 -07:00
Mathias Agopian 0229077293 added some missing javascript APIs 2021-10-06 08:08:18 -07:00
Mathias Agopian 23f2679bbe MoltenVk actually does support subpasses on M1
The actual problem is with the basic "blit" functionality which
is broken, and is sometimes triggered when subpasses are used.
2021-10-06 08:07:32 -07:00
Mathias Agopian e6243b3df3 better API for MSAA options 2021-10-05 22:58:16 -07:00
Mathias Agopian 375b46d866 fix an issue where we'd use the FSR scaling instead of a dumb blit
The DSR options were carried all the way to the final blit that is 
sometimes needed to impedence-match our rendering features with the
swapchain. This blit is never a scaling blit, but we were using the
FSR option, which would sometimes trigger the FSR scaling code.
2021-10-05 20:07:13 -07:00
Mathias Agopian 4577c8d57f don't use quotes with #error 2021-10-04 23:35:35 -07:00
Mathias Agopian 24d1e9c3d2 dont use ES 3.1+ APIs
FSR assumes modern OpenGL. The functions that pose problem are in fact
never used in filament, so it doesn't matter how they're implemented.
We use the HLSL version instead.
2021-10-04 23:35:35 -07:00
Mathias Agopian f7a630d614 Use a dedicated thread for dispatching callbacks
This isolates our backend thread from user code and the java VM.
2021-10-04 10:56:43 -07:00
Mathias Agopian 1c1cb11cf5 Use the new CallbackHandler in the java bindings
Java callbacks are now directly dispatched to their handler, instead
of first going through filament's opportunistic dispatch, reducing
callback latency.
2021-10-04 10:56:43 -07:00
Mathias Agopian 3ac8a6a21c Improvement to callbacks throughout filament
All APIs that take a callback as argument now also takes a 
CallbackHandler* which is a new interface used to dispatch the
callback.

CallbackHandler* can always be nullptr in which case the behavior is
unchanged. 

When CallbackHandler* is specified however, it is used to dispatch the
callback: its post() method is called from a service thread as soon
as possible (this will NEVER be the main thread), CallbackHandler::post
is then responsible for scheduling the callback onto the thread the
user desires. This is intended to make callbacks interoperate with
the platform/OS's own messaging system.
2021-10-04 10:56:43 -07:00
Mathias Agopian c524c39867 Fix JNI bindings for depth of field options 2021-10-04 10:56:43 -07:00
Benjamin Doherty ad02e483d0 Bump version to 1.12.8 2021-10-04 10:26:57 -07:00
Benjamin Doherty f463d53036 Merge branch 'rc/1.12.7' into release 2021-10-04 10:21:42 -07:00
Benjamin Doherty e203edc12a Release Filament 1.12.7 2021-10-04 10:21:10 -07:00
Benjamin Doherty b8d4408524 Update RELEASE_NOTES for 1.12.7 2021-10-04 10:18:56 -07:00
Mathias Agopian 5447baab00 rework Vulkan image layout transitions
The main issue that gets fixed here are:

- VK_IMAGE_LAYOUT_UNDEFINED cannot be used if the image content is to 
be preserved after the transition. Unfortunately, there is more than a 
few places in the VK backend where we use VK_IMAGE_LAYOUT_UNDEFINED on
images that are later used as sources.

- accessing an image memory from the host is only supported if the the 
layout is PREINITIALIZED or GENERAL. However, images in the staging
pool were transitioned to other layouts and put back into the pool,
later they would be mapped/memcpy'ed into. Instead we now always use
the GENERAL layout and never change it.

- images that where in the pool where transitioned using the miplevel
of the texture we were copying into, however this didn't make sense
because images from the pool don't have mip levels.


As part of these fixes, we also refactor imageLayoutTranstion(),
because there was two copies of this function, one specific to texture
and another one more generic. We now always use the more generic one,
with a new helper for textures.


Note: didn't fix "readPixels" which has at least problem (1), because
it's a tricky implementation, and it requires more toughts.
2021-10-01 13:20:21 -07:00
Mathias Agopian 904989f7f4 improve user callbacks latency
A new Engine::pumpMessageQueues() method can be used to trigger all
pending user callbacks right away. This can help reducing latency
of certain callbacks such as picking queries.
This is typically called once before calculating the next frame's
parameters (e.g. object positions or appearance that may depend on a 
callback result).

Fix some comments and documentation.
2021-09-30 16:55:17 -07:00
Romain Guy 4846ccd86d Use the more common EOTF/OETF acronyms (#4691)
Nothing wrong with EOCF/OECF but the "T" version is more common and readers will
therefore be more likely to be more familiar with it.
2021-09-30 14:44:46 -07:00
Ben Doherty 0fd1c3182e Add script to check that public headers can compile independently (#4675) 2021-09-29 13:47:47 -07:00
Mathias Agopian 7d80052dae Implement picking functionality
This is a pixel accurate implementation of picking. Picking queries
can be created on view, and upon completion a user provided callback
is called with the Entity of the renderable at the queried coordinates
in the viewport.

Picking queries typically have 1 or 2 frame of latency and may impact
performance on some drivers.

It is mostly intended for use by editors, or when latency is not a major
concern. This api should not be used for dragging/moving objects, it is
intended for initial picking only.

Picking is implemented in the structure pass.

The depth buffer value is retrieved and the fragment coordinate is
reconstructed and passed to PickingQueryResult. This can be used in
turn to calculate the view and/or world space position.
2021-09-29 13:02:05 -07:00
Mathias Agopian b71ee48477 vulkan: add some format to data reshaper
This is just a minimal change to get the R_INTEGER format to work.

- if src/dst types are identical, just copy (this avoids a mul and a div)
- add R,RG and INTEGER types
2021-09-29 13:02:05 -07:00
Ben Doherty 7a285dc55a Metal: support integer formats with readPixels (#4682) 2021-09-29 12:30:02 -07:00
Mathias Agopian a0f3a4d9bb new helpers for setting {Pixel}BufferDescriptor callbacks
There a just new inline helpers to more easily use lambdas, functors and 
method callbacks with {Pixel}BufferDescriptor.

A BufferDescriptor can be constructed like this:

auto bd = BufferDescriptor::make(buffer, size, [](void* b, size_t s){ });

or

auto bd = BufferDescriptor::make(buffer, size, &Foo::bar, *foo);
2021-09-28 15:26:10 -07:00
Mathias Agopian 304090d39f fix readPixels vertical offset in vk backend
vulkan expected a vertical offset from the top, but the api is in
gl convention with the offset from the bottom.
2021-09-28 14:02:26 -07:00
Benjamin Doherty fef70be848 Bump version to 1.12.7 2021-09-27 11:15:58 -07:00
Benjamin Doherty bdb12d9b24 Merge branch 'rc/1.12.6' into release 2021-09-27 11:12:42 -07:00
Benjamin Doherty 510f51d934 Release Filament 1.12.6 2021-09-27 11:12:08 -07:00
Ben Doherty 47c9fd67e2 Fix, missing call to setTransparencyMode (#4674) 2021-09-24 13:35:54 -07:00
Ben Doherty 43ad283a83 Fix, missing call to setTransparencyMode (#4674) 2021-09-24 13:32:49 -07:00
Benjamin Doherty 1f403fdae0 Revert "fix a race in jobsystem"
This reverts commit 2feb0ad325.
2021-09-24 11:33:14 -07:00
Benjamin Doherty 2e4936afc4 Revert "fix a race in jobsystem"
This reverts commit 2feb0ad325.
2021-09-24 11:24:44 -07:00
Benjamin Doherty 891ffabd11 Update RELEASE_NOTES for 1.12.6 2021-09-23 17:25:25 -07:00
Ben Doherty e2c19498b4 Metal: don't call createTextureViewWithsSwizzle directly (#4662) 2021-09-23 11:28:04 -07:00
Ben Doherty c32630b265 Fix MetalBlitter crash when shader contains warnings (#4663) 2021-09-23 11:27:56 -07:00
Ben Doherty 1a3cee9da9 Metal: don't call createTextureViewWithsSwizzle directly (#4662) 2021-09-23 11:27:07 -07:00
Ben Doherty 3acfd6fc78 Fix MetalBlitter crash when shader contains warnings (#4663) 2021-09-23 11:26:50 -07:00
Alexey Pelykh bf21e78d02 Podspec: include headers in nested directories (#4658) 2021-09-22 16:48:12 -07:00
Alexey Pelykh 83a9bb3a6f Podspec: include headers in nested directories (#4658) 2021-09-22 11:57:23 -07:00
Mathias Agopian 0744876327 improve how the structure pass commands are generated
the code generating the commands for the structure pass (called DEPTH)
in the code was different that from the color. This made sense, but 
isn't great from an architectural standpoint.
Moreover, the special filtering flags DEPTH_FILTER_*_OBJECTS were
useless because part of their functionality was handled in the DEPTH
code directly.

Instead, we now generate the DEPTH commands the same way than we do for
COLOR, but we honor the DEPTH_FILTER_*_OBJECTS flags properly.
2021-09-20 21:25:10 -07:00
Romain Guy 8b92519113 Emissive needs to be applied after shadowing (#4653)
By definition, an emissive surface won't be affected by shadowing
since it's its own light source.
2021-09-20 11:25:26 -07:00
Benjamin Doherty 525d4e08a3 Bump version to 1.12.6 2021-09-20 10:17:18 -07:00
Benjamin Doherty 2e9bf6d694 Merge branch 'rc/1.12.5' into release 2021-09-20 10:14:37 -07:00
Benjamin Doherty 1980107925 Release Filament 1.12.5 2021-09-20 10:14:01 -07:00
Benjamin Doherty e845f01d85 Update RELEASE_NOTES for 1.12.5 2021-09-20 10:10:56 -07:00
Romain Guy 409a84be1f Update release notes 2021-09-17 14:53:46 -07:00
Romain Guy b2fef7988e Use twoPassesTwoSides when doubleSided is true in gltfio (#4635)
This should help Filament properly support more glTF assets with
transparency, and should make Filament behave more like other
renderers such as three.js.
2021-09-17 14:52:47 -07:00
Mathias Agopian 82623c8fd4 IBLPrefilter relied on finalizer which could cause crashes
The finalizer can't be used to dispose of filament resource, because
it runs on its own thread.

Added a destroy() method to all IBLPrefilter related classes that must
be called once the object is no longer needed.

note: Resources will be freed eventually anyways when the Engine itself is
destroyed.


fixes #4633
2021-09-17 14:34:31 -07:00
Mathias Agopian 552a3ab103 Fix timer queries in Vulkan backend
The timestamps are given in "ticks", not in nanoseconds, like our
API expects.

Fixes #4588
2021-09-16 21:03:03 -07:00
Mathias Agopian 52c376a8a7 Fix filament-utils-android 'lite' flavor
Fixes #4601
2021-09-16 14:16:51 -07:00
Romain Guy dd3b7ca65c Update coroutines in samples to match libraries 2021-09-15 18:01:39 -07:00
Mathias Agopian 9776a38d48 run the lod bias transform only from the material() node 2021-09-15 17:19:40 -07:00
Mathias Agopian ceeccde92c Implement lod bias for user materials
A lod bias can be applied to textures when dynamic resolution is
enabled. A proper lod bias is calculated and applied for quality levels
HIGH and ULTRA.

Lod Bias is implemented in glslang, which mean it's ignored when
glslang is not used, which currently happens with OpenGL backends with
optimization turned off (which includes filament LITE). This may be
fixed in the future.
2021-09-15 17:19:40 -07:00
Romain Guy 1a8550e8e0 Call getMaterial() to avoid getting an NPE 2021-09-15 08:31:04 -07:00
Mathias Agopian 2feb0ad325 fix a race in jobsystem
We were decrementing activeJobCount after removing the job from the
queue, which could cause other threads in the pool to preempt us before
the decrement, causing them to spin forever trying to get a non-existant
job, until the decrement actually happened.

Now we always decrement first and fix-up the count if we couldn't get
a job from the queues. The race is inverted, and doesn't cause threads
to spin a long time.
2021-09-14 16:05:30 -07:00
Ben Doherty 7f2c9c2326 Fix, specify BGRA color ordering for iOS OpenGL single-plane external images (#4600) 2021-09-13 12:31:26 -07:00
Romain Guy 9e5f4be85d Update cgltf to version 1.11 (#4612) 2021-09-13 12:29:38 -07:00
Ben Doherty b5874af40b Use more sensible defaults for spot light inner outer cone angles (#4607) 2021-09-13 12:27:53 -07:00
Benjamin Doherty bef48be7b4 Bump version to 1.12.5 2021-09-13 10:47:09 -07:00
Benjamin Doherty b54fdc9e6e Merge branch 'rc/1.12.4' into release 2021-09-13 10:43:06 -07:00
Benjamin Doherty cc70b827a8 Release Filament 1.12.4 2021-09-13 10:42:35 -07:00
Benjamin Doherty cedbf2e30b Update RELEASE_NOTES for 1.12.4 2021-09-13 10:40:55 -07:00
Mathias Agopian 9ff195ce19 don't run the component manager gc in a job each
the gc usually runs for a very short amount of time, so the jobsystem
overhead is very significant compared to the actual work.

additionally this works around a scheduling issue that happens sometimes
on some devices where a thread could be "runnable but not running" for
many milliseconds.
2021-09-10 15:49:22 -07:00
Romain Guy 8e7aaaa662 Update dependencies and expose Filament as API in gltfio/utils (#4605) 2021-09-10 12:35:19 -07:00
Romain Guy 77a744b20b Update RELEASE_NOTES.md 2021-09-09 10:07:29 -07:00
Romain Guy 51fd1ef645 Update README.md 2021-09-09 10:06:26 -07:00
Benjamin Doherty 592f8d1b0d Bump version to 1.12.4 2021-09-08 11:05:44 -07:00
Benjamin Doherty 29612a684e Merge branch 'rc/1.12.3' into release 2021-09-08 11:03:53 -07:00
Benjamin Doherty 3500cc693d Update RELEASE_NOTES for 1.12.3 2021-09-08 11:03:24 -07:00
Benjamin Doherty 807b9882c5 Release Filament 1.12.3 2021-09-08 11:02:45 -07:00
Mathias Agopian b2920a68fb Only apply EASU split workaround if needed. 2021-09-07 20:09:35 -07:00
Mathias Agopian f4ef283908 workaround FSR low performance on some GPUs
On some GPU such as Adreno, the shader compiler flattens the early
exit condition, which becomes useless. We work around this by using a
two pass version of the algorithm using the depth buffer for
skipping "fast" fragments that have already been rendered.
This improves performance significantly, e.g. from 5ms to 1.3ms on
Pixel4.

Currently this mode is always enabled, which hurst performance on GPUs
that don't have this problem. This will be remediated later.
2021-09-07 20:09:35 -07:00
Mathias Agopian 09a38f4e43 use FSR upscaling for all quality levels above LOW
Now that FSR scaling is cheap enough on mobile, we use it for quality
levels MEDIUM to ULTRA.

MEDIUM and HIGH use the mobile optimized version, which has a slightly
lower quality, ULTRA uses the original version.

Additionally the RCAS sharpening pass can always be disabled by setting
the sharpen value to 0.
2021-09-07 20:09:35 -07:00
Mathias Agopian 04acd1885a fix typo where not all requested draw buffers would be cleared
we were not handling drawbuffers 4 to 7.
2021-09-07 20:08:11 -07:00
Mathias Agopian d9fde833b4 Fix integration bug in FSR mobile
We used the "float" code with the "half" texture coords, turns out FSR
uses slightly different code for both.
We're now using the "half" code (using mediump float).
2021-09-07 14:42:24 -07:00
Romain Guy 378ba4e1df Fix crash when duplicating material instances (#4596) 2021-09-07 09:59:52 -07:00
Mathias Agopian 4522ce342b don't use integer approximations on mobile
these approximations don't work in mediump and int/float bitcasting
is not well supported on mobile (can be slow).

This fixes RCAS on Mali.
2021-09-04 15:26:46 -07:00
Mathias Agopian 04402ed412 compute all texture coordinates in highp
Currently we do this only in the _mobile version
2021-09-03 09:46:40 -07:00
Mathias Agopian dc3cf5df49 rename ffx_fsr1_mobile.h to .fs 2021-09-03 09:46:40 -07:00
Mathias Agopian 9261769c5a all texture coordinates must be highp 2021-09-03 09:46:40 -07:00
Mathias Agopian f5e74f8d5a use textureFetchOffset instead of textureLodOffset
the idea here is that it allows us to not have to pass an additional
NEAREST sampler, because texelFetch.
2021-09-03 09:46:40 -07:00
Mathias Agopian e87c140255 gltfio: generate tangents if requested by the material
fixes #4565
2021-09-03 09:43:55 -07:00
Mathias Agopian 00d36110d5 Integrate optimized EASU.
filament cannot use fp16, so we make the necessary changes for the
float version. Note that we are using mediump float, which ends up
using 16 bits floats anyways.

This provides 78% reduction in execution time (i.e. 4.6x performance 
improvement). We see the EASU go from 4.2ms to 0.9ms.
The quality is slightly impacted.
2021-09-02 10:51:42 -07:00
Mathias Agopian c11364b89f AMD FidelityFX FSR1 EASU optimization for mobile
See https://atyuwen.github.io/posts/optimizing-fsr/

This is the unmodified optimized file.
2021-09-02 10:51:42 -07:00
Mathias Agopian 89f8b8663c store configuration as vec4 instead of uvec4
this avoids having to use the conversion functions
2021-09-02 10:51:42 -07:00
Mathias Agopian 6734cdd923 Fix textureGather() emulation 2021-09-02 10:51:42 -07:00
Romain Guy 3bf4ff78d9 Temporary fix for glTF assets with rough transmission (#4580) 2021-09-01 17:51:31 -07:00
Ben Doherty b52cef2fd0 Support linear filtering in MetalBlitter (#4571) 2021-09-01 13:14:49 -07:00
Mathias Agopian 66747e69c5 More cleanup in preparation of dynamic resolution improvements
- added viewport parameter to FSR
- cleanup ssao parameters for linearizing the depth
- added some sliders to simpleviewer
2021-09-01 11:29:33 -07:00
Romain Guy 4085336db5 Cleanup integration 2021-09-01 08:14:11 -07:00
Romain Guy c666a79d12 Cleanup notebook 2021-08-31 19:52:56 -07:00
Romain Guy 22a464f76f Update notebook 2021-08-31 19:47:46 -07:00
Romain Guy 60e88a6069 Add Mathematica notebook for Rec.709 to LMSR matrix 2021-08-31 19:29:10 -07:00
Mathias Agopian ff3a9a46cc Fix resizing issue when MSAA is active
Non sampleable buffers (Renderbuffers) are always rounded to 32 pixels
currently and on the backend side this buffer can end up being cached
as a sidecar buffer for MSAA. When it is created, it needs to be created
with the size of the texture it represents, not the size of the FBO,
which might be smaller.
2021-08-31 16:56:43 -07:00
Mathias Agopian 8c53ad0906 code simplification
We already have 'pAttachementTexture', as it is
passed as argument.
2021-08-31 16:56:43 -07:00
Mathias Agopian 93cc32f34d Fix texture swizzle when cache is deactivated for debugging 2021-08-31 15:58:24 -07:00
Romain Guy dd764d2c3f Update comments 2021-08-31 10:33:49 -07:00
Romain Guy 5a7ae8f1c7 Fix comments 2021-08-31 09:28:37 -07:00
Romain Guy 4ed5085422 Replace ad-hoc scale factor with more reasoned one (#4566) 2021-08-31 08:57:12 -07:00
Romain Guy 0e574f3fce Add night adaptation control to ColorGrading (#4559)
In low-light conditions, peak luminance sensitivity of the eye shifts
toward the blue end of the visible spectrum. This effect called the
Purkinje effect occurs during the transition from photopic (cone-based)
vision to scotopic (rod-based) vision. Because the rods and cones use the
same neural pathways, a color shift is introduced as the rods take over to
improve low-light perception.

This function aims to (somewhat) replicate this color shift and peak
luminance sensitivity increase to more faithfully reproduce scenes in
low-light conditions as they would be perceived by a human observer
(as opposed to an artificial observer such as a camera sensor).

The night adaptation can be controlled using a 0..1 factor for artistic
reasons: `ColorGrading::Builder::nightAdaptation()`.
2021-08-30 17:19:56 -07:00
Romain Guy dcfc27857f Update WebGL demos (#4564) 2021-08-30 12:45:02 -07:00
Benjamin Doherty e6d5807399 Bump version to 1.12.3 2021-08-30 11:46:51 -07:00
Benjamin Doherty fa2553251f Merge branch 'rc/1.12.2' into release 2021-08-30 11:44:00 -07:00
Benjamin Doherty b04c398202 Update RELEASE_NOTES for 1.12.2 2021-08-30 11:43:20 -07:00
Benjamin Doherty fe8e1d0734 Release Filament 1.12.2 2021-08-30 11:42:07 -07:00
Benjamin Doherty 7387718852 Update RELEASE_NOTES for 1.12.2 2021-08-30 11:41:52 -07:00
Ben Doherty a503a6209a Fix regression with clipSpaceTransform (#4552) 2021-08-26 14:14:58 -07:00
Ben Doherty 9f5d6e79da Fix regression with clipSpaceTransform (#4552) 2021-08-26 14:14:23 -07:00
Ben Doherty ce3e5f74e8 Fix Metal STREAM buffers (#4543) 2021-08-25 09:48:34 -07:00
Ben Doherty 9b06ab6084 Fix Metal STREAM buffers (#4543) 2021-08-25 09:48:07 -07:00
Ben Doherty f37112358e Fix missing bookkeeping in bindUniformBufferRange (#4538) 2021-08-24 09:51:40 -07:00
Ben Doherty 76d4fc08f1 Fix missing bookkeeping in bindUniformBufferRange (#4538) 2021-08-24 09:51:05 -07:00
Mathias Agopian 90548a148b Add FFX FSR as a dynamic resolution setting 2021-08-23 18:10:02 -07:00
Mathias Agopian 270bbe4218 FidelityFX-FSR initial commit 2021-08-23 18:10:02 -07:00
Mathias Agopian 3f26c8b893 Move definitions of operator<< overload in their own cpp
also always include these definitions on debug builds
2021-08-23 15:23:56 -07:00
Benjamin Doherty f368b14621 Bump version to 1.12.2 2021-08-23 12:41:33 -07:00
Benjamin Doherty 6960b1148a Merge branch 'rc/1.12.1' into release 2021-08-23 12:39:38 -07:00
Benjamin Doherty 9cea332f61 Update RELEASE_NOTES for 1.12.1 2021-08-23 12:38:47 -07:00
Benjamin Doherty 93ce14659a Release Filament 1.12.1 2021-08-23 12:37:59 -07:00
Benjamin Doherty 2d49b36b3e Fix stack-use-after-scope error 2021-08-23 10:46:39 -07:00
Benjamin Doherty 3cc23aac25 Update RELEASE_NOTES for 1.12.1 2021-08-23 10:45:59 -07:00
Romain Guy ab9d132964 Use wide gamut color grading and gamut mapping (#4524)
* Use wide gamut color grading and gamut mapping

This change introduces a new API on ColorGrading to enable or disable gamut mapping at will. This feature is currently off by default and while useful and recommended, it isn't cheap and we need to figure out what we want our defaults to be especially on mobile targets.

Gamut mapping can be combined with luminance scaling to properly control hue skews.

* Small cleanup

* More precise Rec.2020 conversion
2021-08-20 15:40:45 -07:00
Benjamin Doherty 11dc8740f2 Fix stack-use-after-scope error 2021-08-20 15:40:06 -07:00
Mathias Agopian b30e4f9a4b enable GL_ARB_shading_language_packing on GL 4.1
might fix #4515
2021-08-20 15:02:23 -07:00
Ben Doherty 4b797cff88 Windows: fix incorrect CRT flags with Visual Studio generators (#4516) 2021-08-20 10:56:41 -07:00
Ben Doherty 22afc3a93b Metal: support efficient BufferUsage::STREAM usage (#4525) 2021-08-20 10:51:30 -07:00
Ben Doherty 8aba6f0dcd BlueGL: hide GL symbols on Windows (#4523) 2021-08-20 10:34:52 -07:00
Mathias Agopian 97cee30383 Increase the number of spot shadows to 14 (from 6)
Adresses #4473
2021-08-19 23:15:21 -07:00
Ben Doherty 7f4832706b Metal: skip loop when unbinding uniform buffer objects (#4509) 2021-08-19 10:40:01 -07:00
Philip Rideout 5f16fe45b1 Java gltfio: fix use-after-free error in shutdown.
Fixes #4517.
2021-08-18 12:42:39 -07:00
Ben Doherty 8c8e0ce8a3 Metal: implement texture swizzling for external textures (#4514) 2021-08-18 10:57:50 -07:00
Ben Doherty 1b9dea5b75 Windows: fix incorrect CRT flags with Visual Studio generators (#4516) 2021-08-18 10:51:46 -07:00
Mathias Agopian 7ed073ec3f more cleanup: remove unused code, hardcoded types...
- don't use a separate array for "reversedWindingOrder"
  it's just one bit of data and we had 7 bits left in the Visibility structure.

- use Culler::result_type instead of hardcoded value everywhere

- other minor cleanups
2021-08-17 17:30:33 -07:00
Mathias Agopian e2c5bb025b Small ShadowMapManager refactoring
The main changes are:
- shadowmap command generation is now done in the framegraph pass 
  itself, which allows it to be culled should the pass be culled.
- CameraInfo is created only once instead of twice / shadowmap. 
  It's not super heavy but also not cheap, as several matrices are 
  computed.
- simplified code.
2021-08-17 10:54:01 -07:00
Mathias Agopian a86077e9fe Break dependency of ShadowMap over View 2021-08-17 10:54:01 -07:00
Mathias Agopian cd903b412f move some private headers out of src/details
src/details now only has the private headers of public types/classes.
Private/implementation classes have their header next to them under src.

This makes things more consistant.
2021-08-16 16:50:35 -07:00
Mathias Agopian dd914066f3 more cleanup
The main change here is that PostProcessManager doesn't need to depend
on View.h anymore.

Renamed some variables, fixed more include guards.
2021-08-16 16:50:35 -07:00
Ben Doherty 7af07a1c0f Fix CSM glitch with ground plane (#4487) 2021-08-13 16:31:43 -07:00
Mathias Agopian b980d0a7fd Encapsulate all the code managing the per-view uniforms
This used to reside in View and it is now its own class. The reality is
that "per view" UBO is a bit of a misnomer -- currently we indeed have
one per View, but that's not required and in fact, in the future we might
want to have a separate one for shadow maps for instance.

A better name would be "per camera". Currently it is dynamically updated 
when rendering the View and shadow maps. In the future this probably need
to be separated.
2021-08-12 16:55:34 -07:00
Mathias Agopian 5f10ab56bc move all view Options struct to Options.h
View now uses aliases to these top level structs
2021-08-12 16:55:34 -07:00
Mathias Agopian 383da5f661 cleanup include guards of our private headers 2021-08-12 16:55:12 -07:00
Mathias Agopian 8f0591c9a6 cleanup include guards of our public headers
e.g.: the guard for `FooBar.h` should look like:

  TNT_FILAMENT_FOOBAR_H
  TNT_FILAMENT_BACKEND_FOOBAR_H
  TNT_UTILS_FOOBAR_H
2021-08-12 16:55:12 -07:00
Ben Doherty afb0ceac57 Bump minimum macOS support to 10.15 (#4478) 2021-08-11 16:31:03 -07:00
Ben Doherty fc2660eb39 Metal: support format conversions for texture array and cubemap loads (#4485) 2021-08-11 14:54:58 -07:00
Mathias Agopian 1b8f4b97dd Minor camera code and comments cleanup 2021-08-11 14:35:38 -07:00
Mathias Agopian 3671469046 compute projection inverse in double precision
also concatenate transforms used for rendering using double precision
intermediates.
2021-08-11 14:35:38 -07:00
Mathias Agopian 53d4fa3095 fix assert for ortho projection 2021-08-11 14:35:38 -07:00
Mathias Agopian 94999e55e1 make sure SSAO works with ortho projections 2021-08-11 14:35:38 -07:00
Ben Doherty ba9415b514 Fix, potential null dereferences in MetalBlitter (#4481) 2021-08-10 16:31:03 -07:00
Ben Doherty fe1c1736cd Fix, potential null dereferences in MetalBlitter (#4481) 2021-08-10 16:30:11 -07:00
Benjamin Doherty abb6ae304c Metal: fix debug text spacing 2021-08-09 20:56:38 -07:00
Mathias Agopian 885a69710e fix typo causing ShadowOptions::shadowFar to not work properly 2021-08-09 16:56:16 -07:00
Benjamin Doherty 4058ef5f09 Bump version to 1.12.1 2021-08-09 12:06:47 -07:00
Benjamin Doherty d25ca01624 Merge branch 'rc/1.12.0' into release 2021-08-09 12:03:33 -07:00
Benjamin Doherty e7bebcdea9 Update RELEASE_NOTES for 1.12.0 2021-08-09 12:02:51 -07:00
Benjamin Doherty 5ef234153d Release Filament 1.12.0 2021-08-09 12:02:13 -07:00
Benjamin Doherty d96f87dbbf Update RELEASE_NOTES for 1.12.0 2021-08-09 12:01:46 -07:00
Mathias Agopian bbee5599f1 Fix froxelization (computation of z slice)
We need to take into account our new clip space.

This broke recently with #4440.
2021-08-08 23:26:26 -07:00
Mathias Agopian a4212d5ace Fix VERTEX_DOMAIN_DEVICE world space
this fixes the skybox's fog.

this broke recently with #4440
2021-08-06 15:18:41 -07:00
Mathias Agopian 6d0e719e06 fix display of active shader in matdbg
the database of variant was stored in hex, but the list of active
variant was sent in decimal
2021-08-06 14:00:27 -07:00
Mathias Agopian 3fa9b08a52 don't do a hashmap lookup while iterating the hashmap 2021-08-06 14:00:27 -07:00
Mathias Agopian 4b1a451804 fix VariantList type
There was a confusion on utils::bitset<> API, it specifies the number
of words to use, not then number of bits in the set.
VariantList was sized to store 8192 bits instead of 128.
2021-08-06 13:56:58 -07:00
Mathias Agopian f9d7d60f7d fix contact shadows on mobile
We were missing a few "highp" math.
2021-08-06 09:49:29 -07:00
Ben Doherty aaf9d95411 Metal: support blitting 3D textures (#4460) 2021-08-06 09:37:29 -07:00
Mathias Agopian 90d1ebefae double precision translation for model/view matrices
model/view matrices on Camera now store their translation as double
double precision. This allows filament to handle a very large world
space (thousands of kilometers).
2021-08-05 23:13:33 -07:00
Mathias Agopian a7e4a759e9 double-precision accurate translation
Augment the TransformManager so it can maintain the 4th column as
double precision; we accomplish this by storing an extra float3 per matrix.
It's calculated as `doubleTranslation - float3{doubleTranslation}`.

We also add methods to set and get a transform as mat4, internally only
the 4th column is kept as double precision.

Finally when we calculate the worldTransform, we take this extra data into
account, but only for calculating the new 4th column, so the extra work
is small.
2021-08-05 23:13:33 -07:00
Mathias Agopian 283992088f fix contact-shadow ray iteration
this broke recently with #4440
2021-08-05 19:10:59 -07:00
Romain Guy 75c9ee5982 Slight tweak to the generic tone mapper (#4461)
The new default values match almost exactly the filmic tone mapper which
is itself a close approximation of ACES. This result in a slightly more
contrasty and pleasing image out of the box.
2021-08-05 18:39:35 -07:00
Romain Guy 4d88ff116c Improve image_viewer compatibility (#4459)
- Images with an alpha channel are now properly supported. Blending is implemented directly in the image material by blending against the known opaque background color.
- Non-EXR/HDR images were not applying the proper transfer function and were therefore displayed incorrectly.
2021-08-05 16:27:19 -07:00
Mathias Agopian cf3cc37392 use glClear instead of glInvalidateFrambuffer on desktop
glInvalidateFramebuffer is not available before GL4.3.
2021-08-05 12:59:33 -07:00
Romain Guy f804c9e346 Switch white balance to CAT16 and add gamut mapping code (#4457) 2021-08-05 12:44:49 -07:00
Ben Doherty 8a2e31023f Attempt to fix TSAN failure in ColorGrading.cpp (#4447) 2021-08-05 11:54:07 -07:00
Ben Doherty 4e33e9c3d1 Attempt to fix TSAN failure in ColorGrading.cpp (#4447) 2021-08-05 11:53:35 -07:00
Mathias Agopian 18ac9fd0cc fix TAA reprojection
It broke with #4440
2021-08-05 09:46:14 -07:00
Romain Guy d0f28a48a8 Fix formatting 2021-08-04 18:57:11 -07:00
Romain Guy 706780e3a6 Speed up EXR encoding/decoding (#4446) 2021-08-04 12:39:57 -07:00
Mathias Agopian b5f9c66503 model/view matrices on Camera now use double precision
This PR only changes the API, internal storage and computation are 
still done in float, but this paves the way to double precision 
transforms.
2021-08-03 18:41:48 -07:00
Romain Guy 41f34b8d55 Properly address the color grading LUT (#4443)
* Properly address the color grading LUT

With this change we properly sample from the texel centers when we should, thus avoiding a bias toward the low values. This was particularly problematic in the darks, resulting in darker results than they should have been.

* Save 3 scalar muls
2021-08-03 16:42:44 -07:00
Mathias Agopian 04731b937a views with custom render target should be blendable
We made this wrong assumption that views with a custom rendertarget
are never blended, but it's not true -- e.g. two views can use the
same rendertarget.

Fixes #4430
May impact #2802
2021-08-03 15:42:02 -07:00
Mathias AgopianandBen Doherty 7278e5b5ba Use a clip space that matches our screen space for the z axis (#4440)
* Use a clip space that matches our screen space for the z axis

We now set the projection matrix so that the clip space for the z
axis follows the inverted DX convention, i.e.: z_clip between 1 (near)
and 0 (far), which matches our screen space.

Note that the actual clip space in the GPU can revert to the "inverted
GL convention", i.e.: z_clip between -1 and 1, if the clip_control
extension is not present. In that case the precision benefits are 
mostly lost.

Also note that there shouldn't be any user facing changes. 
The projection matrix at the API level, still follows the GL convention.

Also, currently, the VERTEX_DOMAIN_DEVICE for materials also keeps
the GL convention (this is corrected in the vertex shader).


The gist of this change is to move the "reversed DX" mapping from the
vertex shader to the projection matrix.

* Update shaders/src/getters.vs

Co-authored-by: Ben Doherty <bendoherty@google.com>

Co-authored-by: Ben Doherty <bendoherty@google.com>
2021-08-03 14:37:58 -07:00
Benjamin Doherty 891184bc77 Remove outdated TODO
We already set the correct store action for attachments.
2021-08-03 12:23:46 -07:00
Romain Guy 3d51f9ab23 Tag SDL2 windows as sRGB (#4439) 2021-08-03 11:55:18 -07:00
Benjamin Doherty 1ea8e171d9 Bump version to 1.12.0 2021-08-03 11:18:56 -07:00
Benjamin Doherty e2be3dd0ac Merge branch 'rc/1.11.2' into release 2021-08-03 11:15:19 -07:00
Benjamin Doherty 35c0092b84 Update RELEASE_NOTES for 1.11.2 2021-08-03 11:14:31 -07:00
Benjamin Doherty d249f70750 Release Filament 1.11.2 2021-08-03 11:11:24 -07:00
Mathias Agopian 0dc25cd2a8 Camera::get*ProjectionMatrix should return the value set by the user
Camera::getProjectionMatrix and Camera::getCullingProjectionMatrix used
to return the projection matrix modified by scaling and shift, instead
they should return the value set by the user, especially when
setCustomProjection() is used.
2021-08-02 22:43:21 -07:00
Romain Guy 1c51164e7b Fix inverse tone mapping issues (#4437)
Bring color grading back into the Rec.709 color space to match
previous behaviors. This change also implements an exact inverse
tone map function for the "Filmic" operator.
2021-08-02 20:54:44 -07:00
Romain Guy 91b5cc4bea Fix inverse tone mapping issues (#4437)
Bring color grading back into the Rec.709 color space to match
previous behaviors. This change also implements an exact inverse
tone map function for the "Filmic" operator.
2021-08-02 18:53:35 -07:00
Benjamin Doherty f190f03530 Update RELEASE_NOTES for 1.11.2 2021-08-02 11:17:42 -07:00
jeanlemotan af6f19e390 Fixed compiler warning 2021-08-02 10:34:37 -07:00
Ben Doherty 47446e6cfd Include needed headers in DataReshaper.h (#4423) 2021-08-02 10:15:01 -07:00
Romain Guy 8fada7d6c7 Fix specular AO for the sheen and clear coat layers (#4424)
* Fix specular AO for the sheen and clear coat layers

We used a single specular AO term for the sheen and clear coat layers,
computed for the base layer. This was creating occlusion that was way
too strong when the roughness from the top layers was very different from
the roughness of the base layer. The effect was particularly obvious
on clear coat materials (car paint for instance).

With this change we can also remove the "grazing angle fade" artistic
hack that was previously introduced to combat this effect.

* Safer code
2021-07-31 22:36:46 -07:00
Mathias Agopian 8a81486f5d Implement light channels
Currently there are 8 light channels, both renderables and lights can
be associated to one or several light channel, lighting occurs when
at least one channel is active on both the light and the renderable.

Fixes #4275
2021-07-30 18:54:32 -07:00
Mathias Agopian e483699fba pack booleans together in PerRenderableUib
This frees two uint32 + 30 bits.
2021-07-30 18:54:32 -07:00
Mathias Agopian ae40a12f54 inject unpackHalf2x16 if needed
unpackHalf2x16 is only needed on OpenGL 4.1 or less.
2021-07-30 18:54:32 -07:00
Mathias Agopian 73d4279f00 optimize the Light UBO for space
We use fp16 for most values (e.g.: direction, color), which 
ultimately frees a vec4 (Currently unused) and a few other bits.
2021-07-30 18:54:32 -07:00
Mathias Agopian a0e2f722f6 cached sidecar renderbuffer must honor MS count
When we associate a sidecar renderbuffer (for MSRTT emulation) to a 
texture, the msaa count comes from the rendertarget -- if this texture
is later used with a rendertarget with a different MS count, it should
still work -- in this case we have to reallocate the sidecar buffer.
2021-07-30 18:52:53 -07:00
Romain Guy 5c0da86e04 Fade specular AO from bent normals at grazing angles (#4411)
This helps prevent over-darkening but it's an artistic hack.
We need to check how we compute the bent normals as it seems we
find occlusion where there is no occlusion. The effect is
particularly visible on clear coat materials like a car's body.
2021-07-30 16:02:12 -07:00
Ben Doherty 055fc7cbc1 Attempt to fix Windows CI by turning off concurrent builds (#4395) 2021-07-30 14:09:07 -07:00
Ben Doherty 37d8f96927 Metal: support Apple GPU pixel formats on M1 Macs (#4422) 2021-07-30 14:07:15 -07:00
Mathias Agopian e9e3ce78ca Fix a possible out of bound access on the GPU
When calculating the froxel z slice, a depth buffer value of exactly
1 (i.e. far plane) would map to after the last slice, this value
must be clamped.

made the code more readable, hopefully.

Fixes #4388
2021-07-30 14:06:58 -07:00
Romain Guy 2dadad1e87 Upgrade AGP (#4402)
* Upgrade AGP

* Request Java 11 to build Android artifacts with AGP 7.0

* Add distribution

* Use a cheaper method to pick Java 11
2021-07-28 15:43:03 -07:00
Ben Doherty 9073fc3dc3 Attempt to fix Windows CI by turning off concurrent builds (#4395) 2021-07-28 10:49:37 -07:00
Alexey Pelykh 8c36e6d95f MaterialKey: expose constrainMaterial to Android (#4398) 2021-07-28 09:58:41 -07:00
Alexey Pelykh 2b6d99f5e7 Fix nCreateMaterialInstance in UbershaderLoader: JNI_ABORT does not propagate changes (#4396) 2021-07-28 08:35:34 -07:00
Mathias Agopian 6f29358cb6 Tweak SSAO sampling parameters to improve quality 2021-07-27 21:54:54 -07:00
Mathias Agopian 4e9dcb45ea Implement SSAO bent normals
We now have an option for evaluating the bent normals from SSAO.
This is used to improve specular AO.
Currently these bent normals are not used for diffuse lighting because
they're "flat" (face normals), which is too distracting.

The bent normal buffer is stored in the SSAO texture, in a separate
layer. This is the first post processing effect that uses 2D array
in order to limit our sampler usage.

This CL also changes how we handle SPECULAR_AO_BENT_NORMALS when
material bent normals are not available: we're now using the "Cones"
algorithm with the regular normal, instead of Lagarde's approximation.
2021-07-27 21:54:54 -07:00
Mathias Agopian 282b6f72c1 split SSAO code into multiple files
- depthUtils.fs and geometry.fs are actually completely generic
  at this point, and could be moved out of the SSAO folder.

- saoImpl and ssctImpl are just a way to be able make several versions
  of the SAO material easily (which will be needed soon)
2021-07-27 21:54:54 -07:00
Mathias Agopian cd48be5265 SSAO is now generated in a 2D array 2021-07-27 21:54:54 -07:00
Ben Doherty 3cba26a4c5 Attempt to fix Windows CI by turning off concurrent builds (#4395) 2021-07-27 19:54:51 -07:00
Ben Doherty dd2119268b Metal: avoid std::vector in a few places (#4394) 2021-07-27 16:33:40 -07:00
Romain Guy 5e51ff78d9 Add KHR_material_volume support to MaterialProvider (#4391)
* Add KHR_material_volume support to MaterialProvider

* Fix typo
2021-07-27 14:56:50 -07:00
Alexey Pelykh 6bf27c7356 Fix NoSuchMethod exception (#4390) 2021-07-27 12:20:41 -07:00
Ben Doherty 3abd4fdf09 Cache Metal MSAA sidecar textures in MetalTexture (#4387) 2021-07-27 11:05:07 -07:00
Ben Doherty 2409dc9bc4 Expose Engine::flush (#4385) 2021-07-26 15:09:14 -07:00
Ben Doherty 432434e7e9 Expose Engine::flush (#4385) 2021-07-26 15:08:35 -07:00
Benjamin Doherty 6586c8d70b Bump version to 1.11.2 2021-07-26 12:50:29 -07:00
Benjamin Doherty ac0c94da69 Merge branch 'rc/1.11.1' into release 2021-07-26 12:48:36 -07:00
Benjamin Doherty ba68ea89cd Update RELEASE_NOTES for 1.11.1 2021-07-26 12:12:49 -07:00
Benjamin Doherty 26661375ae Release Filament 1.11.1 2021-07-26 12:11:44 -07:00
Ben Doherty d19d6a72b0 Expose Engine::flush (#4385) 2021-07-26 12:10:19 -07:00
Benjamin Doherty c81b5d98ef Update RELEASE_NOTES for 1.11.1 2021-07-26 10:05:41 -07:00
Mathias Agopian f45b7626eb make blit() of all backend more similar
This all started because the gl backend version of blit() didn't
handle color attachments other than COLOR0 *AND* would actually
corrupt the destination attachments other than COLOR0 if present. 
This is due to how very stateful the gl API is.

Since this is a case we're not running into currently, the GL backend will
now assert in that case.

Updated the Vulkan and Metal backends to also reject blits where
color buffers other than COLOR0 are requested.

Ultimately, we need to change entirely our backend blit API so it 
is less GL centric.
2021-07-23 14:10:04 -07:00
Ben Doherty 2aa21e2a43 Support float3 post-process outputs with Metal (#4376) 2021-07-22 15:12:29 -07:00
Mathias Agopian ad876b91e7 cleanup colorGradingAsSubpass shader
It was confusing how it reused the input as a temporary variable.
2021-07-22 13:51:32 -07:00
Mathias Agopian 73514f6c91 Make sure SpinLock cannot be used by accident on ARMv7
Fixes: #4371
2021-07-22 13:51:12 -07:00
Mathias Agopian 385a05d197 don't use Vulkan subpasses on Apple M1
It looks like they are not working, at least with the current version
of the drivers and/or MoltenVK. It is not impossible that we have a
bug in how we set the subpasses as well. This will need more investigation
later.
2021-07-22 12:06:31 -07:00
Mathias Agopian 306f6e1ca3 fix some broken samples and add -a option
- disable material optimizations in debug builds
- add backend selection
- generate materials for all backends
2021-07-21 18:09:52 -07:00
Mathias Agopian 756866675f fix an issue where a sampler could fail to be updated
SamplerGroup was comparing texture handles to decide if a texture needed
to be updated, however, texture handles are (quickly) recycled and
therefore can't be used for that purpose. e.g. if a texture is destroyed,
its handle could be reused quickly by another texture, if that texture 
is now set on the SamplerGroup, it will ignore it, thinking it's not
different.
2021-07-21 14:46:44 -07:00
Philip Rideout 41baa7bcf0 gltfio: fix AssetLoader leak, remove unwanted destructor.
This fixes two bugs that combined in a way that prevented a double-free
error.

The destructor of the impl class for AssetLoader was never called, which
was sort of good, because it should not destroy the material provider.
The asset loader was never meant to have ownership over the provider.
2021-07-21 14:33:23 -07:00
Mathias Agopian 694204d54a fix an issue where a sampler could fail to be updated
SamplerGroup was comparing texture handles to decide if a texture needed
to be updated, however, texture handles are (quickly) recycled and
therefore can't be used for that purpose. e.g. if a texture is destroyed,
its handle could be reused quickly by another texture, if that texture 
is now set on the SamplerGroup, it will ignore it, thinking it's not
different.
2021-07-21 14:32:59 -07:00
Ben Doherty 85bc1c1758 Fix reshaped image uploads with buffer padding or offsets (#4362) 2021-07-21 12:49:50 -07:00
Ben Doherty 0c9cb72e53 Add more resource libraries to attempt to fix Windows build (#4360) 2021-07-21 12:10:10 -07:00
Mathias Agopian d113c0f01f fix a build warning 2021-07-21 11:35:38 -07:00
Mathias Agopian 98b8871f34 Change back default AO's bilateral blur edge to 5cm
Experimenting more with this, it seems better to be too blurry than
not enough for AO. The 5cm default seems to work better with more
scenes.
2021-07-21 11:19:44 -07:00
Ben Doherty 7cb16afcb5 Metal: take buffer usage into account (#4358) 2021-07-21 11:07:03 -07:00
Philip Rideout 1a79e5463f matdbg: build+link filamat if necessary. 2021-07-21 10:49:13 -07:00
Philip Rideout fd444b2fd0 matdbg: call GLSLTools init / shutdown. 2021-07-21 10:49:13 -07:00
Philip Rideout 15db005dc6 ShaderReplacer: add note about package ownership. 2021-07-21 10:49:13 -07:00
Philip Rideout a26b05bbbb matdbg: add support for editing Vulkan GLSL 2021-07-21 10:49:13 -07:00
Philip Rideout 12b9ee46b9 matdbg: add UI for language selection. 2021-07-21 10:49:13 -07:00
Philip Rideout ce1eb83a0e matdbg: update Monaco editor. 2021-07-21 10:49:13 -07:00
Philip Rideout 27529730ca matdbg: fix bug in selectMaterial(). 2021-07-21 10:49:13 -07:00
Philip Rideout 7b398c01f6 matdbg: support multiple simultaneous clients.
Previously, if you accidentally had two matdbg tabs open in Chrome, the
web app would hang. This fixes two bugs that prevented multiple
simultaneous clients:

1) The websocket handler broadcasted edit events to only the most
   recent connection.

2) The number of server threads was only 2, but the actual web app
   requires at least 2 threads for each instance, due to the
   externally linked CSS file.
2021-07-21 10:48:43 -07:00
Philip Rideout cdb0bb9490 Vulkan: move sidecar ownership to VulkanTexture. 2021-07-21 10:47:57 -07:00
Mathias Agopian ee82f76846 Take byteOffset into account when updating a buffer. 2021-07-21 10:47:08 -07:00
Ben Doherty b77a23ff9d Remove BufferUsage flag from createVertexBuffer (#4352) 2021-07-21 10:04:57 -07:00
Ben Doherty 0d8cdab4e4 Metal: correctly handle byte offsets for updateIndexBuffer and updateBufferObject (#4349) 2021-07-20 21:03:00 -07:00
Romain Guy 67b53d0115 Optimize matrix multiplications to avoid allocations (#4350)
The previous code was a lot cleaner but caused 1+N (where N is
the dimension of the matrix) on each multiply.
2021-07-20 17:51:10 -07:00
Ben Doherty c3291d0137 Attempt to fix failing Windows CI (#4347) 2021-07-20 15:02:58 -07:00
Ben Doherty 7f2ebd25bc Update glslang's tnt/CMakeLists.txt (#4348) 2021-07-20 15:02:22 -07:00
Mathias Agopian fc32fa3a78 Improve s3tc_srgb detection on desktop
Fixes #4336
2021-07-19 23:22:12 -07:00
Mathias Agopian a3cf2ee61a Add bilateral threshold in SSAO options.
This can have a dramatic effect on SSAO and needs 
to be adjusted based on the scene's scale/units.

The default value used to be about 6cm, and has 
been changed to 5mm.
2021-07-19 18:26:19 -07:00
Mathias Agopian cc287386aa associate sidecar MS buffer to its texture instead of RenderTarget
this allows the sidecar buffer to have the same lifetime than the
texture it represents, and therefore participate to the caching of
that texture.

Fixes #4338
2021-07-19 18:26:00 -07:00
Romain Guy 9ea1dbad93 Update AGP and Kotlin versions 2021-07-19 17:29:50 -07:00
Romain Guy 4a849c7caf Update RELEASE_NOTES.md 2021-07-19 17:22:27 -07:00
Romain Guy a77a9ade29 New tone mapper API (#4330)
* WIP New tone mapper API

* Implement tone mapper constructors and destructors

* Add new genertic tone mapper

* Make the generic tone mapper available in our sample UIs

* Fix warnings and crashes

* Fix generic tone mapper and graph mappers in the UI

* Add Java APIs for ToneMapper

* Implement copy/move operators for GenericToneMapper
2021-07-19 17:19:53 -07:00
Ben Doherty 090d23434c Metal: use private instead of memoryless textures for MSAA (#4333) 2021-07-19 11:21:07 -07:00
Ben Doherty 83850c8201 Metal: Use an intermediate texture to avoid setting UsageRenderTarget on all textures (#4334) 2021-07-19 11:20:31 -07:00
Benjamin Doherty ebcd4925f7 Bump version to 1.11.1 2021-07-19 10:24:01 -07:00
Benjamin Doherty 13bed4fdf9 Merge branch 'rc/1.11.0' into release 2021-07-19 10:20:29 -07:00
Benjamin Doherty d306bfe147 Update RELEASE_NOTES for 1.11.0 2021-07-19 10:19:32 -07:00
Benjamin Doherty adfc4a5b0c Release Filament 1.11.0 2021-07-19 10:18:37 -07:00
Benjamin Doherty 1dae5c6b6c Update RELEASE_NOTES for 1.11.0 2021-07-19 10:18:07 -07:00
Philip Rideout 6b249bde4b Enable debug info in materials in debug builds.
This lets you see highly readable GLSL when transpiling the generated
SPIRV back to GLSL, with the original variable names preserved.

For now this is only useful when using `matinfo`, but it will soon be
useful in `matdbg` too.
2021-07-16 10:32:42 -07:00
Benjamin Doherty 1036759f39 Remove os_release in MetalDriver
os_release is only needed (and available) when ARC is turned off.
2021-07-15 19:09:13 -07:00
Ben Doherty 302c07048c Switch Metal driver to use HandleAllocator (#4326) 2021-07-15 16:56:19 -07:00
Ben Doherty 2686b0bbac Allow iOS gltf-viewer to load models from documents directory (#4327) 2021-07-15 16:42:59 -07:00
Mathias Agopian cece128bb9 Update bug_report.md 2021-07-15 16:35:57 -07:00
Mathias Agopian 3e5471d32a Implement sharing of bones for skinning
The API now allows to create a standalone SkinningBuffer containing
Bones for skinning. This SkinningBuffer can even be very large and
contain bone data for several renderables.

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


Fixes #3238
2021-07-15 16:29:26 -07:00
Romain Guy 272f786f35 Fix build warning 2021-07-15 14:05:38 -07:00
Romain Guy 0dd04f6e73 Update README.md 2021-07-15 09:23:56 -07:00
Romain Guy a5221fc816 Update BUILDING.md 2021-07-15 09:21:36 -07:00
Romain Guy 29f6616cee Update BUILDING.md 2021-07-15 09:19:50 -07:00
Romain Guy 0d08402004 Fix test_settings 2021-07-14 23:04:39 -07:00
Romain Guy 64c2ab7048 Generalize luminance scaling in color grading (#4321)
* Generalize luminance scaling in color grading

Previously the luminance scaling step was tied to a specific tone
mapping operator, called "EVILS" in the API. This was however
somewhat misleading as EVILS really is a color handling system
that's independent of what we call tone mapping.

This change splits the luminance scaling step from the tone mapping
step, allowing the use of luminance scaling (the LICH part of EVILS)
with any tone mapping operator.

As a result, the operator known as EVILS is currently mapped to the
linear operator and renamed to "RESERVED" until it is replaced by
a proper — configurable — operator.

* Update release notes

* Fix web build
2021-07-14 22:18:07 -07:00
Philip Rideout 26a54ba86a Consolidate definitions of VariantList. 2021-07-14 16:37:53 -07:00
Philip Rideout 32b3f16573 matdbg: fix active variant list, update README. 2021-07-14 16:37:53 -07:00
Romain Guy 4080a0a5d5 Small cleanup and improvements in ColorGrading (#4320)
Saturation and vibrance were using the wrong luminance weights,
and this change switches EVILS to HK weighted luminance weights
to give better results.
2021-07-14 16:23:55 -07:00
Mathias Agopian 17d67f2a39 get rid of the GPUBuffer class which was used in one place only 2021-07-14 11:45:00 -07:00
Philip Rideout 9c20efd235 Parameterize HandleAllocator and use it in VulkanDriver. (#4309)
* Parameterize HandleAllocator and use it in VulkanDriver.

* Provide macros for HandleAllocator instantiations.
2021-07-14 10:16:54 -07:00
Romain Guy b46833680d Simplify image loading now that Metal can reshape textures (#4315) 2021-07-14 09:42:41 -07:00
Mathias Agopian 4bcd862c0e fix a case where blended views + dynamic scaling didn't work
What was happening is that we were doing two blits at the end of the
frame instead of one, those blits are setup so that they only work
when the destination is the an imported target (it doesn't have to be
this way, but currently that's the only case we should have). Because
of the 2nd blit, the first one's destination would not be the
imported target and it would fail.

The real problem is that we shouldn't be doing two blits, just one
is enough. That was happening because the logic to decide if we 
needed the last blit was flawed.


Fixes #4306
2021-07-13 21:07:12 -07:00
Mathias Agopian c414ba9b2f Remove HwUniformBuffer and replace with HwBufferObject 2021-07-13 17:33:22 -07:00
Mathias Agopian 27a070c8f9 Remove some dependency on HwUniformBuffer 2021-07-13 17:33:22 -07:00
Mathias Agopian c8aea02d7d Use correct access and pipeline flags 2021-07-13 17:33:22 -07:00
Mathias Agopian 46ff9a433c don't store context/stagepool in each VulkanBuffer
This reduces the size of VulkanBuffer by 16 bytes, instead we just
pass those objects when needed.
2021-07-13 17:33:22 -07:00
Mathias Agopian c135b4aa19 don't use heap allocation for VulkanBuffer 2021-07-13 17:33:22 -07:00
Mathias Agopian 89d5f4a418 HwBufferObject can now be a uniform buffer 2021-07-13 17:33:22 -07:00
Mathias Agopian 003fe86ffb Add a BufferUsage parameter to HwBufferObject 2021-07-13 17:33:22 -07:00
Mathias Agopian 94c250a241 don't use a heap allocation for MetalBufferObject 2021-07-13 17:33:22 -07:00
Philip Rideout f1a69c8c36 Prep for using new handle allocator in Vulkan. (#4307)
Previously we were zero filling the data blob used to store all Vulkan
handles. This occured in VulkanDriver::alloc_handle().

There were several places that depended on the zero fill. These
have now been fixed up so that the handle can be constructed in a
more natural way.

Also: remove the OPENGL specific constant from HandleAllocator. This
breaks in non-CMake build systems (e.g. Bazel) that do not provide the
constant at a global level.
2021-07-13 16:37:28 -07:00
Mathias Agopian 2bd8faaef5 Improve HandleAllocator API
We now have:

  allocate<> which just allocates the handle's memory
  construct<> which constructs the handle allocated with allocate<>

  allocateAndConstruct<> which allocates AND constructs the handle
  destroyAndConstruct<> which destroys and constructs a handle in place

Normally you'd use allocate/construct but with synchronous calls, it
might be necessary to have an initialized handle immediately.
2021-07-13 16:32:17 -07:00
Ben Doherty 94a25452e8 Refactor Metal texture uploads (#4238)
Previously, Metal was never performing any texture conversions during upload. For example, `iblprefilter` loads `FLOAT` image data into the `R11F_G11_B10F` texture format. This PR fixes the issue, refactors the upload pipeline, and adds a new backend test for coverage.
2021-07-13 15:12:02 -07:00
Romain Guy 505cb39e1c Improvements to image_viewer (#4305)
Image loading errors are handled more gracefully by showing a
background color.

Added UI to set the background color.

Replaced fragment discards with solid background color.
2021-07-13 11:24:13 -07:00
Romain Guy 127dd8f675 Add new sample app: image_viewer (#4301)
* Add new sample app: image_viewer

This app shows how to load and visualize images. It's also useful to work
on color grading and other post-processing effects by just loading an HDR
or EXR image as a reference.

This change also adds a new exposure setting to the color grading LUT.

* Fix comments and build

* Fix Metal

* Use high precision for the UV coordinates

* Fix refactoring issue
2021-07-13 10:07:42 -07:00
Ian Brown fc5837b1b6 default to openGL when windows does not support VULKAN 2021-07-12 23:01:34 -07:00
Mathias Agopian 46e3d10e62 remove unneeded namespace qualifications 2021-07-12 18:03:47 -07:00
Ben Doherty 64c5dc63ab Audit usage of UTILS_PUBLIC and fix bluegl linking warning (#3988) 2021-07-12 17:09:13 -07:00
Romain Guy 31adb1213e Make white balance faster in ColorGrading 2021-07-12 12:18:53 -07:00
Benjamin Doherty 8e6663e4b0 Bump version to 1.11.0 2021-07-12 10:49:43 -07:00
Benjamin Doherty ba804444b8 Merge branch 'rc/1.10.7' into release 2021-07-12 10:47:12 -07:00
Benjamin Doherty 0344de57e9 Update RELEASE_NOTES for 1.10.7 2021-07-12 10:46:34 -07:00
Benjamin Doherty 750252b297 Release Filament 1.10.7 2021-07-12 10:45:43 -07:00
Benjamin Doherty 58cfb85004 Update RELEASE_NOTES for 1.10.7 2021-07-12 10:45:24 -07:00
Mathias Agopian ab46481b45 Fix colorgrading as subpass
We were inserting the colorgrading subpass command between the
refracted and blended objects, instead of after all of them.

Another bad side effect of this was to trigger the refraction pass for
no reason.
2021-07-12 10:35:01 -07:00
Mathias Agopian 4296782399 don't crash when refraction pass is empty 2021-07-12 09:53:37 -07:00
Romain Guy 4f28734042 Add support for KHR_materials_volume (#4291)
* Add support for KHR_materials_volume

* Add ubershader support for KHR_materials_volume

* Update readmes

* User highp on anything that affects UVs

* Add missing precision qualifiers

* Fix transmission
2021-07-09 20:50:27 -07:00
Philip RideoutandRomain Guy 4289c03ce5 gltfio: fix precision in KHR_texture_transform (#4290)
* gltfio: fix precision in KHR_texture_transform

Fixes #4253.

* Update to the new order of parameters

Co-authored-by: Romain Guy <romainguy@curious-creature.com>
2021-07-09 17:55:10 -07:00
Romain Guy bdbc85773c Improve parameter API to be more consistent with sampler parameters (#4292) 2021-07-09 17:51:12 -07:00
Philip Rideout 0a2fa36d5a API CHANGE: honor user-defined precision, rename SamplerPrecision. (#4287)
* API CHANGE: honor user-defined precision, rename SamplerPrecision.

matc now honors 'precision' on non-samplers in mat files, and
the filamat API now allows clients to specify precision for
non-samplers.

This involved flattening a union that is internal to filamat.

* MaterialBuilder: Add Java bindings for precision.
2021-07-09 17:32:08 -07:00
Mathias Agopian 0c244bc2ac Fix colorgrading as subpass
We were inserting the colorgrading subpass command between the
refracted and blended objects, instead of after all of them.

Another bad side effect of this was to trigger the refraction pass for
no reason.
2021-07-09 16:41:55 -07:00
Ben Doherty 67a49e5770 Add signposts to Metal backend (#4289) 2021-07-09 15:47:16 -07:00
Benjamin Doherty a98395bee7 Add back pointer 2021-07-09 15:04:27 -07:00
Benjamin Doherty 26c9732b4e Fix, MSVC's std::sort fails on Zip2Iterator 2021-07-09 15:04:27 -07:00
Mathias Agopian 62787de97b Don't store Handle<> debug state inline
We use a hashmap instead, which won't change the behavior of the
HandleAllocator (due to the increased size of the handles) between
debug and release modes.
2021-07-09 15:04:10 -07:00
Mathias Agopian 830c379958 reduce size of HwIndexBuffer
this limits the index count to 27 bits
2021-07-09 15:04:10 -07:00
Mathias Agopian 1a24de8735 cleanup handle size comments 2021-07-09 15:04:10 -07:00
Philip Rideout 121489f2af Work around Qualcomm issue with point lights. (#4278)
Fixes #3602.
2021-07-09 12:52:23 -07:00
Mathias Agopian 0e7295a469 fix a warning in release 2021-07-09 11:35:11 -07:00
Mathias Agopian 602b3d0796 Sort and discard lights early
We always may need to discard lights because we have a limited 
number we can use in the shader. We now do this earlier, in particular
before we set up the shadowmaps.

Because we also have a limited (smaller) number of shadowmap, this 
allows us to automatically select the ones that are closer to the 
camera, which gives better results.
2021-07-09 11:26:56 -07:00
Mathias Agopian fda06fe8a0 fix a few easy "fixmes" and "todos" 2021-07-09 10:25:22 -07:00
Philip Rideout 92628ade8e Remote UI: auto load last loaded model. (#4277)
The most recently loaded model is now automatically re-loaded if you
re-start the sampler-gltf-viewer app.

Super useful in my case for `rgb-lights.glb` :)
2021-07-09 08:46:58 -07:00
Romain Guy b399d64024 Update README.md 2021-07-08 20:46:34 -07:00
Mathias Agopian a8e8c04c7b Skip lighting/shadowing when possible
We can skip lighting in the areas fully shadowed, we can also skip
shadowing outside the radius of punctual lights.
2021-07-08 16:37:06 -07:00
Romain Guy 313b9944fd When IOR=1.0, there should be no transmission roughness (#4276)
* When IOR=1.0, there should be no transmission roughness

See https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/TransmissionRoughnessTest
for details.

* Use a smoothsteph instead

* Don't modify roughness twice
2021-07-08 16:08:55 -07:00
Romain Guy 5a61d28eee Add Java bindings for transparent shadow (#4272)
* Add Java bindings for transparent shadow

* Fix JNI binding typo

* Fix typo
2021-07-08 12:50:18 -07:00
Ben Doherty 4eb0937d21 matc: log error when input material definition is empty (#4273) 2021-07-08 11:34:46 -07:00
Romain Guy a082e94235 Update RELEASE_NOTES.md 2021-07-08 10:32:39 -07:00
Romain Guy 9bd3684893 Add support for transparent shadows (#3298)
* Add support for transparent shadows

This solution uses an 8x8 Bayer matrix. We could find a better
noise. We also need better filtering of the shadow maps. A PCF
is barely enough and VSM fails without blurring.

* Use a fixed Bayer matrix, fix pre-caching of depth shaders

* Use gradient noise instead of fixed bayer pattern

* Update docs
2021-07-08 10:31:52 -07:00
Philip Rideout 0cd9fd9ad9 sample-gltf-viewer: fix remote control of IndirectLight. (#4267) 2021-07-07 20:41:12 -07:00
Mathias Agopian efcc690f42 update remote ui 2021-07-07 17:45:58 -07:00
Mathias Agopian 1ed1a5efb6 Allow MSAA when post-processing is disabled
There was no good reason not allow this.
Fixes #2533
2021-07-07 17:19:57 -07:00
Mathias Agopian 2d7de6ecc0 enable up to 6 spot shadows
This is a trivial change since we moved the lightspace computation
in the fragment shader. The limitation to 6 is due to how we're storing
the culling result.
2021-07-07 17:19:42 -07:00
Romain Guy 4a1edc4281 Add gltf_viewer and material_sandbox to release archives (#4264) 2021-07-07 17:19:12 -07:00
Romain Guy d6b32e5923 Remove support for Java/desktop builds (#4263)
* Remove support for Java/desktop builds

These builds are never tested nor used on our end. We cannot
guarantee their proper support. It should also be possible
for an app to handle this itself.

* Remove Tungsten since it cannot be compiled anymore
2021-07-07 17:18:58 -07:00
Philip Rideout 105ae8abb6 Update prebuilt MoltenVK to 1.2.182. (#4260) 2021-07-07 17:16:44 -07:00
Philip Rideout 1f33dad675 Update glslang. (#4258) 2021-07-07 15:27:18 -07:00
Mathias Agopian 90ee59512b don't crash when refraction pass is empty 2021-07-07 14:28:48 -07:00
Romain Guy 7f2a189641 Update docs 2021-07-07 13:50:37 -07:00
Romain Guy 1ab59ca35a Update to the latest version of Markdeep for local use (#4257) 2021-07-07 13:49:38 -07:00
Philip Rideout 5c0826963e Update spirv-tools. (#4255) 2021-07-07 13:28:59 -07:00
Mathias Agopian 7555fe6196 enforce CLAMP_TO_EDGE for external textures
Fixes #2978
2021-07-07 13:28:21 -07:00
Mathias Agopian 1dbb9c7ded HandleArena now can deal with running out of space
When HandleArena is full, we now revert to a slower system-heap
based mechanism. The problem is logged once. This allows the
system to continue to run.
2021-07-07 12:07:25 -07:00
Mathias Agopian ac798c1350 moved HandleAllocator outside of the OpenGL backend
This means it can easily be used by our other backend.

HandleAllocator uses 3 pool (which currently can't be configured),
and is very efficient in terms of memory overhead and handle to
pointer conversion.

A Handle<> is just an offset into a large heap managed by the 3 pools.
2021-07-07 12:07:25 -07:00
Philip Rideout 00682bd911 Add simple ReadPixels performance test. (#4248)
* Add simple ReadPixels performance test.

This simply lets the gtest framework report the total test time, which
includes startup and teardown.  However we perform 100 runs of the
render+readback code to reduce the run-to-run variance. For 100 runs of
a 2000x2000 buffer, I see the following results on my mac:

- Vulkan: 1881 ms
- Metal: 1625 ms
- OpenGL: 978 ms

The test can be built & invoked like this:

```
./build.sh release backend_test_mac && \
    ./out/cmake-release/filament/backend/backend_test_mac -a opengl --gtest_filter="*ReadPixelsPerformance"
```

See also issue #4246.

* ReadPixels test: minor refactor.
2021-07-07 12:00:04 -07:00
Benjamin Doherty ef375a7103 Bump version to 1.10.7 2021-07-07 11:02:30 -07:00
Benjamin Doherty fd258b7765 Merge branch 'rc/1.10.6' into release 2021-07-07 10:59:12 -07:00
Benjamin Doherty ceced43e93 Update RELEASE_NOTES for 1.10.6 2021-07-07 10:58:31 -07:00
Benjamin Doherty 55fdc47e66 Release Filament 1.10.6 2021-07-07 10:57:56 -07:00
Benjamin Doherty 147de8d372 Update RELEASE_NOTES for 1.10.6 2021-07-07 10:57:25 -07:00
Philip Rideout eb2a1928b6 ShadowMapManager: fix MSAN use-of-uninitialized-value.
The operator!= in std::array compares SPLIT_COUNT elements, which
is potentially greater than cascadeCount, which was the number of
initialized elements in splitPercentages.
2021-07-07 10:51:18 -07:00
Philip Rideout 53a92451e6 ShadowMapManager: fix MSAN use-of-uninitialized-value.
The operator!= in std::array compares SPLIT_COUNT elements, which
is potentially greater than cascadeCount, which was the number of
initialized elements in splitPercentages.
2021-07-07 07:51:28 -07:00
Mathias Agopian 77016f34a5 More simplifications of the ShadowMapManager code
- the ShadowMap cache is now inline and doesn't use unique_ptr<>

- reduced the size of ShadowMap significantly, it used some temporary
  storage as member, but now that we have many of those, we shouldn't
  do that.

- removed some duplication of fields

- fixed some headers inclusion
2021-07-02 10:08:09 -07:00
Mathias Agopian 19db911d46 Use a custom command to handle color-grading subpass
This is cleaner and what custom commands are for.
2021-07-02 10:08:09 -07:00
Mathias Agopian 46a88c7ed8 Rework RenderPass allocations
Instead of managing a GrowingSlice<> more or less shared between
several RenderPass, RenderPass now works directly with an Arena which
owns the commands. We do this so RenderPass can be copiable, which is
useful for creating a RenderPass from a "template" RenderPass
(usually empty, but with some scene parameters set).

RenderPass is now a lot more self contained.

Execution of the commands is now done with a RenderPass::Execcutor
which can be obtained from a RenderPass.

This change led to some code clean-up as well.

We also had to improve Arena<> to be able to take a custom Area.
2021-07-02 10:08:09 -07:00
Philip Rideout ca3b841974 gltfio: Add fast path for native material providers. 2021-07-01 16:11:55 -07:00
Philip Rideout e9ff2157bc gltfio: Cache the JNI field ids for MaterialKey. 2021-07-01 16:11:55 -07:00
Philip Rideout d270c42109 gltfio: Allow Java / Kotlin clients to customize MaterialProvider.
This adds some significant JNI glue in order to make the Java API for
gltfio materials much more consistent with C++, and create feature
parity between the two languages.

The motivation is to allow Java clients to provide their own
ubershader-based solution or filamat-based solution.

- The `MaterialProvider` Java class is now an interface.
- The `UbershaderLoader` Java class is now a concrete implementation.
- Users can now write their own provider class using Java / Kotlin.

To streamline the amount of JNI work that occurs at run time, the
MaterialProvider Java interface uses ints in a couple spots instead
of enums. This sacrafices some readability for Java clients who wish
to write their own provider, but makes the JNI much simpler.

This replaces #3975.
2021-07-01 16:11:55 -07:00
Philip Rideout f4558fee1d Update remote UI. 2021-06-30 09:44:05 -07:00
Philip Rideout 86461663d8 Settings UI: LightManager ShadowOptions now affect all lights. 2021-06-30 09:42:00 -07:00
Mathias Agopian fcca62ec6a spotlight light-space position moved to the fragment shader
We have a limited number of interpolants, and 2 were used for spotlights,
but this is a fairly uncommon case, so we move the calculation to the
fragment shader. A side effect of this is that we are not limited to 
two spot-light anymore from the shader's point of view.

This essentially adds a vector transform per fragment, but on the other
hand, it removes communication between the vertex and fragment shader,
as well as interpolation of the position.
2021-06-29 17:19:43 -07:00
Mathias Agopian f6dde81a16 workaround drivers that don't implement textureSize() properly
On some qualcomm drivers, textureSize() with a level != 0 aborts the
pixel shader.
2021-06-29 10:12:38 -07:00
Romain Guy d77e66d1e8 Update README.md 2021-06-28 23:08:33 -07:00
Mathias Agopian 702f906d49 PCF shadows need some math in highp
mediump is not enough for sampling positions.
2021-06-28 16:29:36 -07:00
xjdkc 2f257b54e7 fix the bug of not mapping depth24 to depth32 on iOS platform when stencil is enabled 2021-06-28 15:54:03 -07:00
Mathias Agopian c1b9e47a90 fix virtual near/far shadow hint for lispsm
the virtual near/far plane used by lispsm wasn't computed correctly,
which would sometimes result to incorrect "optimization" of the
lispsm range.
2021-06-28 15:28:33 -07:00
Mathias Agopian a93e10308c specify sample count for vsm's depth buffer
This basically expresses the fact that we won't need an "auto-resolve",
indeed the temporary depth buffer is always discarded. In the GLES
backend, this is likely (if MSRTT is supported) to take a less
complicated code path.

Improve some comments.
2021-06-28 15:28:33 -07:00
Mathias Agopian 204fc0359c Fix out of bounds access in java bindings
Fixes #4154
2021-06-28 15:28:12 -07:00
Philip Rideout eb483281dc Update remote control web app. 2021-06-28 15:10:50 -07:00
Philip Rideout b841709729 gltf_viewer: make auto-scale into a UI setting. 2021-06-28 15:08:59 -07:00
Benjamin Doherty 35b033102f Bump version to 1.10.6 2021-06-28 12:07:58 -07:00
Benjamin Doherty 7bc65421a9 Merge branch 'rc/1.10.5' into release 2021-06-28 12:04:31 -07:00
Benjamin Doherty 736514cf37 Update RELEASE_NOTES for 1.10.5 2021-06-28 12:04:27 -07:00
Benjamin Doherty 6307fb3563 Update RELEASE_NOTES for 1.10.5 2021-06-28 12:03:59 -07:00
Benjamin Doherty 35b3542b2e Release Filament 1.10.5 2021-06-28 12:03:22 -07:00
Mathias Agopian db0158dae8 fix webgl build
we need to select opengl on webgl.
2021-06-28 08:27:46 -07:00
Philip Rideout 0fa5ca9a6a Fix 'Last Updated' in the Vulkan document. 2021-06-26 10:30:15 -07:00
Mathias Agopian 36285f2ca5 Increase OpenGL backend handle arena to 4 MiB 2021-06-25 19:04:20 -07:00
Mathias Agopian 9e19a1aca4 The gaussian blur running sum must be in highp
This is to acomodate hdr and evsm blurring.
2021-06-25 17:44:40 -07:00
Mathias Agopian 19c7949cc4 update remote ui 2021-06-25 17:32:19 -07:00
Mathias Agopian 36d7f6ff94 Fix more issues with VSM settings for the remote UI 2021-06-25 16:55:13 -07:00
Mathias Agopian e7b90f9c12 update remote ui 2021-06-25 15:18:33 -07:00
Mathias Agopian 8bd499c60c fix webgl build
we need to select opengl on webgl.
2021-06-25 14:03:57 -07:00
Mathias Agopian 0d61d47f28 update remote ui 2021-06-25 13:21:23 -07:00
Mathias Agopian 4b5dc5b3af Fix VSM mipmap generation
- the clear color was broken since we switched dot EVSM
- use the scissor instead of the viewport, it makes it easier to compute
  the uv-scale.
- the min/max lod level wasn't reset properly
- also clamp the minimum shadowmap size to 8, and document it.
2021-06-25 12:12:37 -07:00
Mathias Agopian 61bf472426 VSM blur is now specified as a width in pixels
This is a lot more intuitive than using the standard deviation.
2021-06-25 12:12:37 -07:00
Mathias Agopian ef6199a792 Improve shadow generation code
We make better use of the framegraph, by using a pass per shadowmap,
instead of generating all shadowmaps in a single framegraph pass.
This allows us to use less temporary memory when blurring, but also
simplifies the code.
2021-06-25 12:12:37 -07:00
Mathias Agopian 7bd0b45a2b Implement blurring of VSM shadow maps
This is still somewhat work-in-progress, but good enough to be useful.

Some caveats:
- large blurs don't work well with cascades
- the implementation uses more memory than it could
2021-06-25 12:12:37 -07:00
Philip Rideout eb0c346969 gltfio: remove hacky RTTI from MaterialProvider.
We want anybody to write their own class that descends from
MaterialProvider, so it doesn't make sense to have an enum of
concrete types.
2021-06-24 15:24:13 -07:00
Philip Rideout bf2938f345 PostProcessManager: call setMinMaxLevels for DoF.
Depth of field now works on Vulkan, wooot!  This is also required for
OpenGL, for Intel drivers.
2021-06-24 13:22:47 -07:00
Philip Rideout c7e4116154 gltfio: introduce support for extras strings.
This allows clients to obtain the extras strings for the asset and
for individual nodes.  Note that extras for buffer views, accessors, etc
are not supported, although C++ clients can access the raw cgltf data
directly if they need to.
2021-06-24 10:41:40 -07:00
Philip Rideout db521e0e5e gltfio: add getAsset to FilamentInstance. 2021-06-24 10:41:26 -07:00
Philip Rideout a219629ead Fix vsm options serialization. 2021-06-24 10:03:13 -07:00
Mathias Agopian ba10393f48 Rework a bit UniformBuffer and friends
Filament uses a handful of known UBO, the code for creating their
interface block is not needed in filament (via filabridge), so
reorganize things so that we can move that code to filamat.

On the other hand, filament needs the C structure corresponding to
the UBO, to find the fields offset and ubo size and name.

We now have a UibStructs.h in filabridge which only defines C struct
with a static name for the interface block's.

This should slightly reduce the size of filament proper.

We also now have a new helper TypedUniformBuffer<> which simply holds
one of these structs (or an array), and allows to set the fields
directly and more naturally from C++. std140 alignment is now left to
the caller, when going through that class.
2021-06-24 09:58:06 -07:00
Philip Rideout 091e399d0f Vulkan: ensure sample count is supported. 2021-06-24 09:06:10 -07:00
Mathias Agopian 5de6779d72 VSM improvements and fixes
- use EVSM (exponential VSM), helps a lot with light bleeding
- don't apply shadow biases with VSM
- improve VSM user settings: added more controls, expose to java
- minor code cleanups:
   - rename some structures
   - remove unused parameters
   - remove unused uniforms
2021-06-23 18:08:57 -07:00
Mathias Agopian 4b3a983b23 Handle shadow receivers w/ VSM more robustly
VSM requires shadow receivers to be in the shadowmap, instead of
handling this in the shadow mapping code, we're handling it in 
FScene::prepare(), which guarantees it'll ripple everywhere it needs to.
2021-06-23 18:08:57 -07:00
Ben Doherty 1b53e78ea7 Metal, ensure sample counts are supported by device (#4185) 2021-06-23 14:34:33 -07:00
Philip Rideout ef08323b25 Vulkan: fix swizzle support.
When creating a texture with a swizzle, the swizzle should be applied to
the image view only when sampling from that texture.  When a swizzled
texture is used as a render target attachment, the image view should not
have any swizzle applied.
2021-06-23 12:03:11 -07:00
Philip Rideout 24c6917267 Fix Android build. 2021-06-23 09:42:57 -07:00
Mathias Agopian 9ab25fa19e Fix a crash where flare is on but starburst off 2021-06-23 08:33:25 -07:00
Philip Rideout d5f785ff41 matc and Vulkan: apply smol-v to raw programs. 2021-06-23 08:27:26 -07:00
Philip Rideout f2a8e2aef7 Vulkan: add support for depth resolves.
The DepthResolve test now passes with Vulkan, although DoF still
triggers validation errors, which I'll look into next.
2021-06-23 08:27:26 -07:00
Philip Rideout 7bdd1fe096 FCV: emphasize trivial default construction in the note. 2021-06-23 08:26:19 -07:00
Philip Rideout f677eef422 FixedCapacityVector: add note about default construction. 2021-06-23 08:26:19 -07:00
Romain Guy 70f3824b14 Update README.md 2021-06-22 20:57:15 -07:00
Mathias Agopian 11b980832c fix ground plane's bounding box 2021-06-22 17:01:42 -07:00
Benjamin Doherty e706695ed1 Bump version to 1.10.5 2021-06-21 11:18:26 -07:00
Benjamin Doherty e8877ffe2d Merge branch 'rc/1.10.4' into release 2021-06-21 11:16:10 -07:00
Benjamin Doherty 300e853646 Update RELEASE_NOTES for 1.10.4 2021-06-21 11:15:44 -07:00
Benjamin Doherty a403279fa6 Release Filament 1.10.4 2021-06-21 11:14:58 -07:00
Benjamin Doherty 1fd5d9dae6 Update RELEASE_NOTES for 1.10.4 2021-06-21 11:14:35 -07:00
Philip Rideout 8f6f831d5b Add missing #include. 2021-06-21 09:11:04 -07:00
Philip Rideout 599077b54c Use FixedCapacityVector in backend::Program. 2021-06-18 13:31:01 -07:00
Ben Doherty 9b7414b60c Fix, set mBackend to resolved backend in FilamentApp.cpp (#4160) 2021-06-17 18:00:40 -06:00
Philip Rideout 78430858fe gltfio: do not set clear coat in GLTFIO_LITE config.
This avoids an assertion in debug builds. We will document this behavior
much more thoroughly in a subsequent PR.

Fixes #4143.
2021-06-17 14:44:05 -07:00
Mathias Agopian fe8528a963 Backend::DEFAULT now selects a backend most suited for the platform (#4155)
- OpenGL ES on Android
- Metal on MacOS/iOS
- Vulkan everywhere else (Linux/Windows)

The main change here is that OpenGL is no longer the default on
desktop.

Most of our samples have a `-a` option that can be use to specify the
desired backend.
2021-06-17 14:42:29 -07:00
Mathias Agopian f365cb965b fix a potential memory corruption when using more than 4 render targets
The array size in the GL structure didn't match the number of supported
render targets.
2021-06-17 14:40:48 -07:00
Romain Guy 2b38cf4c65 Include ProGuard rules in our AARs (#4158) 2021-06-17 14:29:55 -07:00
Philip Rideout 2e9080a179 Fix issues in test_FeedbackLoops and VulkanDriver.
1) Add a missing destroyTexture to the test, which I believe fixed
the Metal assert that I was seeing, as well as some Vulkan validation
warnings.

2) Add a flushAndWait() utility to BackendTest, which is useful for
diagnostics.

3) Fix a layout validation issue in VulkanSwapChain for empty render
passes.
2021-06-17 11:29:39 -07:00
Mathias Agopian 0a50ee989e fix a possible crash when bloom is enabled
This reworks how we compute the bloom buffer size. The main changes are:

- The BloomOptions.resolution is changed to height instead of minor axis.
  This keeps a consistant look of the bloom regardless of the viewport.

- The anamorphism setting now dilates the bloom rather than to compress
  it (in the other direction), which maintains the same amount of bloom.
  However, the resolution decreases meaning that the user might need to
  adjust resolution and/or levels.

- limit the resolution do 2048 which is gles minspec.
2021-06-17 10:17:31 -07:00
Mathias Agopian c9c9103ede disable skybox/clear optimization
We were disabling the color pass render target clear when a skybox
was present. This optimization doesn't work when the viewport is not
full. Currently there is no way to know that, so we disable this 
optimization for now. Performance loss is not expected to be significant
if present at all.
2021-06-16 16:20:15 -07:00
Mathias Agopian 1ce9e96490 fix automatic clearing of rendertargets
We were automatically clearing the color pass render target when
the view was translucent -- the idea was that when it gets blended at
the end it wouldn't override the content of the render target.

Unfortunately, this doesn't work when the rendertarget is imported,
because in that case, it's not actually blended, we're just rendering
into it directly. The clear would then erase the previous content.

This is fixed by moving the clearing decision in the execute closure and
piggy-backing on the computed discard flag. Discard means clear.
The discard flag will be set for newly created buffers and not for an
imported target that needs to keep its content.
2021-06-16 16:20:15 -07:00
Mathias Agopian 1f9c802e10 Fix imported target discard and clear flags
An imported target shouldn't specify the discardStart flags, those
are calculated from the graph. However, it needs to specify "keep" flags,
to take into account constaints that the graph cannot see (due to the fact
that it's imported into the graph). i.e. the imported target may have
content that needs to be preserved.

An imported target can specify a clear color and clear flags that will
override the flags from the logical Descriptor -- this is a way to
delay the swapchain clear to when we're actually rendering into it
(which usually happens in the very last pass).
2021-06-16 16:20:15 -07:00
Mathias Agopian c6fda8385a fix opaque blit with imported render targets
When the source of a blit refers to an imported render target,
we can't create a HwRenderTarget from it because the resource
is not a real texture and doesn't have a HwTexture.
However, it can be converted back to the HwRenderTarget it
represents, using the FrameGraph's declareRenderPass API.
It's a slightly strange usage of this API, but not technically
wrong.

This is the main fix for bug #4085
2021-06-16 16:20:15 -07:00
Mathias Agopian d0664bc119 add post-processing option to gltf-viewer 2021-06-16 16:20:15 -07:00
Philip Rideout e7ed85ec94 Update WebGL tutorials. 2021-06-16 14:24:47 -07:00
Philip Rideout 5d1d4ff4d6 Update web site with latest WebGL artifacts. 2021-06-16 14:17:12 -07:00
Philip Rideout 57040ebb22 Fix and refactor support for S3TC + SRGB. 2021-06-16 14:08:51 -07:00
Philip Rideout 03b018e7f3 Repair FeedbackLoops test. 2021-06-16 14:07:49 -07:00
Romain GuyandPhilip Rideout 04ada346b0 Materials can now provide custom lighting/shading (#4142)
* Materials can now provide custom lighting/shading

When a material uses the "lit" shading model, customSurfaceShading can
be enabled to replace Filament's lighting implementation. When this
feature is enabled, the material *must* provide the following function
in the fragment shader block:

    vec3 surfaceShading(
            const MaterialInputs materialInputs,
            const ShadingData shadingData,
            const LightData lightData
    ) {
        return vec3(1.0); // custom lighting here
    }

Please refer to the docs in Materials.html for more information about
this feature and the different values provided by the data structures
passed to the function.

* Update docs

* Update docs/Materials.md.html

Co-authored-by: Philip Rideout <philiprideout@gmail.com>

Co-authored-by: Philip Rideout <philiprideout@gmail.com>
2021-06-16 09:53:58 -07:00
Philip Rideout f53c7723fb Vulkan: fix ReadPixels regression, refactor VMA inclusion. 2021-06-15 18:07:01 -07:00
Ben Doherty cd48089318 filament-utils-android: fix string literal conversions (#4137) 2021-06-15 16:19:32 -06:00
Ben Doherty 0a6a74c78c filament-utils-android: fix string literal conversions (#4137) 2021-06-15 11:00:31 -06:00
Philip Rideout b40982d579 Vulkan: repair headless swap chains.
I broke this when migrating to FixedCapacityVector.
2021-06-15 08:23:04 -07:00
Philip Rideout 2605633e1e Upgrade vkmemalloc. 2021-06-14 12:58:14 -07:00
Benjamin Doherty 6379ab22c9 Bump version to 1.10.4 2021-06-14 11:06:42 -06:00
Benjamin Doherty 0bf02b75d5 Merge branch 'rc/1.10.3' into release 2021-06-14 11:04:25 -06:00
Benjamin Doherty 2f7e873137 Update RELEASE_NOTES for 1.10.3 2021-06-14 11:03:54 -06:00
Benjamin Doherty bb9e23519d Release Filament 1.10.3 2021-06-14 11:03:11 -06:00
Benjamin Doherty c4259b5598 Update RELEASE_NOTES for 1.10.3 2021-06-14 11:02:45 -06:00
Philip Rideout acfae2882d Vulkan: Use custom VMA pools to speed up Mali.
This makes the car load in 3 seconds instead of 30 seconds on Mali.

On devices that have bufferImageGranularity set to 1 in the
VkPhysicalDeviceLimits caps structure, we observe that vmaCreateBuffer
can be two orders of magnitude faster than with devices that have a
higher value for their bufferImageGranularity.

According to the Vulkan spec, the bufferImageGranularity aligment
constraint needs to be honored only when linear and non-linear resources
live next to each other in memory.  Since all VkBuffer objects are
linear, we can allocate them all from the same pool and ignore the
alignment constraint.
2021-06-11 14:48:29 -07:00
Philip Rideout 180eb61620 Vulkan: Fix uninitialized vector contents. 2021-06-11 10:40:04 -07:00
Philip Rideout a92bb87cd8 Vulkan refactoring. 2021-06-11 09:18:18 -07:00
Philip Rideout 2c967b821b Minor Vulkan cleanup. 2021-06-11 08:48:07 -07:00
Philip Rideout abe9a9731d Vulkan: use FixedCapacityVector in one more spot. 2021-06-11 08:24:54 -07:00
Philip Rideout 2837a48001 Vulkan: Use FixedCapacityVector in lots of places. 2021-06-10 14:41:03 -07:00
Philip Rideout 4aef84342d gltfio: Cache the dummy buffer to optimize load time.
This greatly improves the load time on some Mali devices. On one device,
loading the car model went from 85 seconds to 35 seconds.
2021-06-10 14:40:47 -07:00
Philip Rideout 9be6153875 Refactoring: simplify VulkanDisposer. 2021-06-10 13:49:37 -07:00
Philip Rideout 444640afb7 Refactoring: decouple VulkanBuffer and VulkanDisposer. 2021-06-10 13:49:37 -07:00
Philip Rideout 122908587b Fix build break. 2021-06-10 09:53:54 -07:00
Philip Rideout c1654537e2 Vulkan: use debug_utils for custom labels.
VK debug markers do not show up in an AGI system trace, but we can sneak
them in by using debug_utils to assign labels to VkFramebuffer.

Note that the debug_utils extension is enabled only when launching your
app from AGI.
2021-06-10 09:32:10 -07:00
Philip Rideout 984a172cec Enable EXT_debug_utils on Android. 2021-06-10 09:32:10 -07:00
Mathias Agopian ee2767875c Fix FixedCapacityVector::reserve()
We were initializing the new data with the default
Actor by accident.
2021-06-09 17:07:34 -07:00
Philip Rideout fa0a41e62e sample-gltf-viewer: log the load time (useful for large models)
More precisely, this logs the time that the Filament backend takes
to process all the commands that were issued in the gltfio synchronous
loading phase, which mostly consists of creating and populating vertex
buffers.

This can be quite slow for vertex-heavy (CAD-style) models, and seems to
vary by several orders of magnitude from device to device on Vulkan.
2021-06-09 13:40:16 -07:00
Philip Rideout edaf718281 Vulkan: fix storeOp for depth attachment.
This gets rid of the "GMEM Store Depth / Stencil" bars seen with AGI.
2021-06-08 14:34:31 -07:00
Philip Rideout 7cd5963d3a Adjust VK_MAX_COMMAND_BUFFERS to prevent a 5 ms stall.
This constant was previously set to 3 because of triple buffering, which
does not account for the fact that Filament may issue multiple commit()
calls during a single frame.

This new number was determined via experimentation.

On a Pixel 4, this reduces a 4.5 ms gap in "GPU Queue 0" to 420 us.
2021-06-08 14:34:23 -07:00
Philip Rideout 60f5512c5f JS bindings: remove bogus stride argument.
Fixes #4106.
2021-06-08 14:23:41 -07:00
Ben Doherty 6b3c1179bc Include sample-gltf-viewer with Android releases (#4099) 2021-06-08 10:41:48 -07:00
Ben Doherty d1b9a1b996 Include sample-gltf-viewer with Android releases (#4099) 2021-06-08 10:32:49 -07:00
Mathias Agopian 1bd91e7e94 JobSystem: simplify callback code
we can use the lambda syntax instead of a static method.
2021-06-08 09:47:16 -07:00
Mathias Agopian 5e2f73c74e JobSystem: reduce parallel_for overhead
We reuse the current job for the right side instead of spawning a new
job, which has overhead. This also cuts in half the number of times we
need to copy the user functor.
2021-06-08 09:47:16 -07:00
Mathias Agopian 4a269e37c5 Don't use very small jobs when using parallel_for
The overhead of the jobsystem / job is about 50-100us, so we should
try to use jobs about an order of magnitude bigger -- which is actually
quite rare.

In particular the culling is so efficient that we'd need to process
10000 or more primitives for the jobsystem to be of any help, so for
now we never use the jobsystem for culling.
2021-06-08 09:47:16 -07:00
Mathias Agopian 3eceaf20a2 JobSystem: set thread pool count to ncores - 2
We need to reserve at least a code for the user and another one for the
backend thread.
2021-06-08 09:47:16 -07:00
Mathias Agopian bbc4f4f21d JobSystem: remove the DONT_SIGNAL flag
A side effect of this flag was that we had to always use notify_all
when starting a job, instead of notify_one -- in practice, we found
experimentally that more calls to notify_one is cheaper than fewer
calls to notify_all.
2021-06-08 09:47:16 -07:00
Mathias Agopian c5ef1d6252 JobSystem: signal condition with lock held
This seems to improve parallelism on multicores and at least on
Android, doesn't seem to impact performance.
2021-06-08 09:47:16 -07:00
Philip Rideout a4280881d5 Fix BindingType in TypeScript definitions.
Fixes #4102.
2021-06-08 09:14:22 -07:00
Philip Rideout 8ef4c54712 Upgrade emsdk to 2.0.23 2021-06-08 08:36:32 -07:00
Philip Rideout 5ebc8c3e1a Ensure FILAMENT_MIN_COMMAND_BUFFERS_SIZE_IN_MB is available.
If your build system does not provide a definition for this macro, then
you cannot compile CommandBufferQueue.cpp.

Since Allocators.h provides a backup value, it needs to be included.
2021-06-08 08:09:51 -07:00
Philip Rideout c1a0e61e8e Fix FixedCapacityVector destructor.
std::allocator::deallocate() expects the same value that was given
during allocate().

Interestingly, this bug did not manifest any issues (even with ASAN) on
some platforms.
2021-06-07 15:56:33 -07:00
Philip Rideout cbcb3e95c6 Fix FixedCapacityVector destructor.
std::allocator::deallocate() expects the same value that was given
during allocate().

Interestingly, this bug did not manifest any issues (even with ASAN) on
some platforms.
2021-06-07 15:56:02 -07:00
Benjamin Doherty fc06298ed4 Bump version to 1.10.3 2021-06-07 11:22:04 -07:00
Benjamin Doherty 4ca87b188c Merge branch 'rc/1.10.2' into release 2021-06-07 11:19:51 -07:00
Benjamin Doherty f1f60c3e0d Turn off warnings as errors for spirv-tools 2021-06-07 11:18:56 -07:00
Benjamin Doherty 76d21b56af Update RELEASE_NOTES for 1.10.2 2021-06-07 11:18:09 -07:00
Benjamin Doherty 02a8cffb18 Update RELEASE_NOTES for 1.10.2 2021-06-07 11:15:22 -07:00
Benjamin Doherty d53f7ecd6a Release Filament 1.10.2 2021-06-07 11:14:43 -07:00
Philip Rideout e297f65d8c getLight() should initialize all fields.
Fixes #4014.
2021-06-03 18:29:05 -07:00
Mathias Agopian 5356f65040 use "debug" namespace for system properties
"filament.perfcounters" is renamed to "debug.filament.perfcounters", 
because otherwise it can't be set by users on recent Android 
versions.
2021-06-03 17:13:52 -07:00
Mathias Agopian 5056abc357 Systrace now uses the official ATrace API
Use the official systrace API when available.
2021-06-02 18:28:39 -07:00
Philip Rideout 46029acd14 VulkanPipelineCache: fix padding with MSVC. 2021-06-02 17:51:54 -07:00
Philip Rideout 28e414c9a5 VulkanPipelineCache: stop using Vk structs for state tracking. 2021-06-02 17:51:54 -07:00
Philip Rideout 29c036d826 VulkanPipelineCache: do not hash uninitialized data.
This fixes an issue caught by a memory sanitizer, whereby padding in the
cache key structure was being consumed by a hashing function. In
practice this oversight was fairly harmless, but this change makes the
code more safe and predictable.
2021-06-02 17:51:54 -07:00
Philip Rideout 831a6d9480 gltfio: fix crash with non-triangles.
Fixes the "triangle count is zero" assertion with the big car model.

We do have nominal support for points and lines, but we should not
attempt to compute tangents for these.

As a reminder, glTF also supports loops, strips, and fans; this is the
only way in which Filament is non-conformant.
2021-06-02 16:47:14 -07:00
Mathias Agopian fb2a95470a bring some improvements to logging from a reverted change
- cleanup Log header file
- lazy initialization of the log buffer
- aggressively resize down the log buffer
2021-06-02 16:40:58 -07:00
Mathias Agopian 4d73583f86 Better systrace logging and small improvements to JobSystem
Tweak how we signal/wakeup threads so we get better parallelism 
on Android.
2021-06-02 16:40:40 -07:00
Mathias Agopian 9a24c4001f Flush the CommandStream in a few strategic places
The CommandStream hold backend commands, but it has a limited size.
With some large models, we can run out of space especially during
initialization.

We can combat this by flushing the command stream regularly. With this
change, we do this every 128 renderable creation.

We also flush the CommandStream just before generating the draw
commands for the frame.

If the buffer is not sized correctly (currently at compile time), this
could cause stalls, which will be logged in DEBUG builds.
2021-06-02 12:16:45 -07:00
Mathias Agopian 4c9ae9dd91 use c++ thread_local now that it's supported on Android
there are cases where thread_local still doesn't work well, but
we're not using those cases.
2021-06-02 12:12:09 -07:00
Mathias Agopian 384d6921f6 add system property to override the backend selection
On Android, set `debug.filament.backend` to the desired backend:
0: default
1: gl/gles
2: vulkan
3: metal
4: noop

example:
   `adb shell setprop debug.filament.backend 2`

This will affect all filament apps on the device.

This sets the backed as if it was set from the public API.
2021-06-02 12:11:51 -07:00
Benjamin Doherty 0ab0e50a4f Turn off warnings as errors for spirv-tools 2021-06-02 11:16:42 -07:00
Benjamin Doherty e0a8284fcf Update filament-specific-changes.patch 2021-06-02 10:58:44 -07:00
Benjamin Doherty eafbf699a2 Turn off warnings as errors for spirv-tools 2021-06-02 10:58:44 -07:00
James Walker 4d3f10477a fix macOS main thread checker warnings with OpenGL (#4011)
* fix runtime warnings about certain NSView methods being called off the main thread

* address code style issues

* fix code style and threading concerns

* Remove unneeded __strong qualifiers, put __weak after the star as recommended by Apple, convert weak to strong before testing for nil to avoid a race

* convert tabs to spaces
2021-06-01 16:35:23 -07:00
Mathias Agopian 9a83805f19 build.sh -C option entirely cleans the android/ directory
All (and only) git-ignored files under android/ are deleted.

This is to prevent a recurring problem where "clean" builds were not
actually clean in some cases.
2021-06-01 14:10:08 -07:00
Mathias Agopian 6fcc2b579d fix LightManager::getFalloff
fixes #4043
2021-06-01 14:09:08 -07:00
Mathias Agopian e04a3d7d3a AttachmentPoint in java and c++ mismatch
fixes #4055
2021-06-01 14:08:51 -07:00
Benjamin Doherty 34f4c06a5c Bump version to 1.10.2 2021-06-01 11:17:32 -07:00
Benjamin Doherty 6de36f1e53 Merge branch 'rc/1.10.1' into release 2021-06-01 11:15:49 -07:00
Benjamin Doherty be61ea2dc8 Update RELEASE_NOTES for 1.10.1 2021-06-01 11:14:29 -07:00
Benjamin Doherty c594d6a07e Release Filament 1.10.1 2021-06-01 11:13:41 -07:00
Benjamin Doherty 2a9a3b1ac2 Update RELEASE_NOTES for 1.10.1 2021-06-01 11:13:04 -07:00
Mathias Agopian ee7feff9cc Revert "improve logs and tls support"
This reverts commit cc6201b0db.

On Android the loggers are not always initialized when several .so are
used, leading to crashes. It's not completely clear what is exactly 
happening.
2021-06-01 10:21:10 -07:00
Philip Rideout 02ce911405 Vk: Fix some synchronization validation warnings.
This fixes most of the warnings that are emitted by the relatively new
SYNCHRONIZATION_VALIDATION feature that LunarG provides.

This commit does not fix a warning that is emitted when SSAO is enabled,
when we sample from the currently bound depth attachment. This one is
tricky to fix.
2021-06-01 08:01:55 -07:00
Mathias Agopian f12ee8f54c unit test for FixedCapacityVector 2021-05-28 09:16:18 -07:00
Mathias Agopian 81a98c6769 panic in release builds when command stream is corrupted
the CommandStream is limited in size and can get corrupted if
that size (default 1 MiB) is exceeded. We used to catch this
only on Debug builds, but this is too serious and unrecoverable, so
it must be caught in Release builds too.

At the point of detection the stream is corrupted, which can cause
the backend to get in an unknown state. But worse, program execution
could end up anywhere because the stream contains function pointers.
2021-05-28 09:16:02 -07:00
Mathias Agopian e3f626934f fix sstream::c_str() when the buffer is first created (#4050) 2021-05-27 22:04:42 -07:00
Romain Guy 94ff2ea6b1 Add support for KHR_materials_specular to glTF (#4046)
* Add support for KHR_materials_specular to glTF

* Add support for IOR to ubershaders

* Update release notes

* Remove unused variable, fix comment
2021-05-27 17:33:24 -07:00
Mathias Agopian cc6201b0db improve logs and tls support
- libutil's slog, cout, cerr, cwarn and cinfo were not thread safe
  at all.

- they are now thread_local

- for that reason the log buffer (which now exists per thread) is not
  allocated until it's needed and is aggressively shrunk.

- removed our thread_local emulation which was incomplete.

- don't expose LogStream publicly.
2021-05-27 15:54:19 -07:00
Mathias Agopian d079df9ce5 make use of FixedCapacityVector in various places 2021-05-27 15:53:53 -07:00
Mathias Agopian 6a2c944bbd A fixed capacity vector.
This is (almost) drop-in replacement for std::vector, the main
difference is that FixedCapacityVector has a fixed (at runtime)
capacity, which makes it a lot more efficient and small for operations
like push_back();

The capacity can be set (and re-set) as usual with reserve(),
but exceeding the capacity when adding items will throw.
The capacity is also set when creating the vector with a size.

In addition a FixedCapacityVector<> instance is only 16 bytes instead
of 24 for std::vector<>.

The aim here is to reduce code bloat.
2021-05-27 15:53:53 -07:00
Mathias Agopian 266fea5e6c replace all size_t with uint32_t in the backend API
this helps save a lot of space in the CommandStream, it especially
matters with scenes with a lot of draw calls.
2021-05-27 15:53:31 -07:00
Mathias Agopian 6da3f85362 RenderPass.cpp got mistakenly renamed, fix that. 2021-05-27 15:53:09 -07:00
Philip Rideout 1d58892fed Vk: repair validation on Android. 2021-05-27 15:18:28 -07:00
Philip Rideout ff1b6d28a8 Vk: fix handling of instance extensions. 2021-05-27 11:27:01 -07:00
Ben Doherty ff935e05f2 image: Respect sRGB option for compressed formats (#4039) 2021-05-26 20:37:58 -07:00
Mathias Agopian d378f5e4bb repair CommandStream logging 2021-05-26 20:33:47 -07:00
Philip Rideout 44eee6550c Vk: emit best practices warnings when validation is enabled. 2021-05-26 15:48:33 -07:00
Philip Rideout 260b8fb672 VulkanCommands: add diagnostics. 2021-05-26 15:48:33 -07:00
Mathias Agopian 2f240acc43 increase max job count to 16384 from 4096
the cost is only 2 bytes per job.
2021-05-26 12:18:05 -07:00
Mathias Agopian 189b528b3d improve handle creation in opengl backend
- we issue better logs when the allocation fails
- the pool selection is now performed at compile time
2021-05-26 12:17:50 -07:00
Philip Rideout 2b265d54a1 VulkanSwapChain: simplify and repair swap chain resizing.
Newer versions of MoltenVK seem to behave similarly to Android,
so there's no need to separate codepaths. I tested this by not only
resizing the window, but also dragging between displays with different
pixel ratios, and rotating on Android with & without `orientation` in
`configChanges`. I also tried our headless unit tests.
2021-05-26 10:34:39 -07:00
Philip Rideout c61d67301f sample-gltf-viewer: fix lifetime cycle for RemoteServer.
The sample would crash when removing `orientation` from `configChanges`
and rotating the device, because the old RemoteServer would still be
alive when creating the second one, so the WebSocket port would be
unavailable.
2021-05-26 09:22:08 -07:00
Philip Rideout 5f3d8096f3 Vulkan: big refactor of VulkanSwapChain.
This has no behavioral changes, it's mostly just moving code around,
except that VulkanDriver::createSwapChain() is simpler now, and some
of the logic in beginRenderPass() makes more sense too.

This removes the useless `VulkanSurfaceContext` structure by moving
its data directly into `VulkanSwapChain`. Also created a new cpp file
just for the swap chain wrapper, which makes `VulkanContext` much less
unwieldy.
2021-05-25 20:04:08 -07:00
Alexey PelykhandFabian Rueckert 6e5b05d0b5 KTXLoader.getSphericalHarmonics
Co-authored-by: Fabian Rueckert <fabi.rueckert@gmail.com>
2021-05-25 20:02:19 -07:00
Benjamin Doherty 6bbae681ef Fix HelloCocoaPods iOS sample 2021-05-25 17:19:52 -07:00
Philip Rideout 097fac4cca Add support for drag-and-drop HDR.
This adds Java bindings for IBLPrefilterContext and uses them
in `sample-gltf-viewer`.
2021-05-25 12:46:52 -07:00
Philip Rideout 97515b0d7d Vulkan: minimize calls to vkCmdSetScissor. 2021-05-25 12:28:52 -07:00
Philip Rideout 3500101816 Repair live WebGL demos.
Fixes #4027.
2021-05-25 12:22:05 -07:00
Romain Guy 1cebf51672 Update README.md 2021-05-24 16:08:42 -07:00
Mathias Agopian 3b59dff577 fix some build warnings 2021-05-24 13:25:11 -07:00
Mathias Agopian cd01ad06fd update SPIRV-CROSS to latest
SHA: ff61890722a91e97c44940494be5b6eed0d5ff5b
2021-05-24 13:24:54 -07:00
Benjamin Doherty 84b73a3770 Bump version to 1.10.1 2021-05-24 10:52:02 -07:00
Benjamin Doherty 662a10e273 Merge branch 'rc/1.10.0' into release 2021-05-24 10:49:10 -07:00
Benjamin Doherty 331332fab0 Update RELEASE_NOTES for 1.10.0 2021-05-24 10:48:45 -07:00
Benjamin Doherty f3572876a1 Release Filament 1.10.0 2021-05-24 10:48:03 -07:00
Benjamin Doherty ecce02502e Update RELEASE_NOTES for 1.10.0 2021-05-24 10:47:39 -07:00
Ben Doherty c827004821 Add getPlatform API to Engine, move functionality into MetalPlatform (#4007)
This change allows access to the Engine's underlying Platform object. This is useful for Metal clients to access a new method on MetalPlatform, createAndEnqueueCommandBuffer.
2021-05-24 10:36:56 -07:00
Mathias Agopian 786eee4eb9 Fix a crash when using custom rendertargets
This was introduced recently.

Fix #3962
2021-05-24 09:53:54 -07:00
Mathias Agopian 92d2de5279 fix MRTs >= COLOR4 in the GL backend
These would be ignored.
2021-05-24 09:53:05 -07:00
Ben Doherty f4070f3fb5 Fix Automation test_settings (#4009) 2021-05-24 09:10:25 -07:00
Alexey Pelykh 856a6567a1 LightManager: cone angles API (#3979) 2021-05-22 22:04:50 -07:00
Mathias Agopian 363edb1427 added MaterialInstance::duplicate(...)
It's now possible to duplicate a MaterialInstance.
2021-05-21 22:57:28 -07:00
Mathias Agopian c209232950 a way to keep the content of custom RenderTarget attachments (#4008)
* a way to keep the content of custom RenderTarget attachments

Until now, all attachments of RenderTarget beyond COLOR0 were discarded
after rendering.

With this change, attachment whose texture has the SAMPLEABLE usage
bit set will be kept.

Fixes #3962
2021-05-21 22:54:52 -07:00
Ben Doherty 3f9120b129 Fix focusDistance warning in gltf_viewer (#4005) 2021-05-21 15:31:46 -07:00
Philip Rideout d17875aea1 ImGuiHelper: fix support for custom images.
The texture binding in the material instance needs to be restored to the
glyph atlas when a custom image is not in use.
2021-05-21 12:49:37 -07:00
Philip Rideout b1f0f905e5 HDRLoader: use HDRDecoder, not stb. 2021-05-21 12:36:43 -07:00
Philip Rideout c71c7c70d4 imageio: split HDRDecoder into its own file 2021-05-21 12:36:43 -07:00
Philip Rideout 613ae56cc1 Add HDRLoader for JVM clients.
This adds support for decoding HDR files, dropping them into the remote
web page, and sending them over the wire.  However the decoded results
are not yet passed into IBLPrefilterContext, that will be subsequent
PR.

Rename KtxLoader to KTXLoader.

The remote UI has been tweaked a bit, so that it shows a more helpful
message when disconnected.
2021-05-21 12:36:43 -07:00
Philip Rideout 6607002939 ImGuiHelper: fix support for custom images.
The texture binding in the material instance needs to be restored to the
glyph atlas when a custom image is not in use.
2021-05-21 11:49:14 -07:00
Philip Rideout 2e40bb46e7 Fix minor typos. 2021-05-21 11:34:08 -07:00
Philip Rideout b8897a68f9 matc: detect missing end brace.
matc was failing to report certain kinds of syntax errors and would
read out-of-bounds memory.

This change casuses the flare material to fail.
2021-05-21 09:20:33 -07:00
Philip Rideout 720288c420 JNI Cleanup: Remove useless constructors, publicize RenderTarget.
(1)
The C++ RenderTarget API might be used by an external Android library
such as filament-utils-android and therefore needs to be in the map
file.

(2)
Texture, Skybox, and IndirectLight each had two "nativeObject"
constructors which exist for the benefit of filament-utils-android,
but each of these classes only need one nativeObject constructor.
2021-05-20 15:18:34 -07:00
Romain Guy 97651a0ff4 Use CIE 2006 10-deg CMFs instead of CIE 1931 2021-05-19 12:42:41 -07:00
Ben Doherty 84efd4871e API CHANGE: remove some Camera, Engine, and View deprecated APIs (#3965) 2021-05-19 12:02:13 -07:00
Philip Rideout 3125c44ce1 Vulkan: change depth layout to permit feedback loops.
Vulkan does not permit the GENERAL layout when the depth buffer that is
currently being used for depth testing is also sampled from.

This (finally) fixes the last validation error that we were silencing,
which would occur only when SSAO was enabled.
2021-05-18 16:38:42 -07:00
Philip Rideout d909b38d57 Vulkan: enable the maintenance extensions if available.
This prevents potentially bogus validation messages from arising.
2021-05-18 16:36:12 -07:00
Ben Doherty 5572ef8574 API CHANGE: remove some Camera, Engine, and View deprecated APIs (#3965) 2021-05-18 16:02:49 -07:00
Philip Rideout 3c4192bd0e matc: detect missing end brace.
matc was failing to report certain kinds of syntax errors and would
read out-of-bounds memory.

This change casuses the flare material to fail.
2021-05-18 10:58:15 -07:00
Philip Rideout 3fc9dc3684 Repair build when FILAMENT_VULKAN_VERBOSE is enabled. 2021-05-17 18:13:51 -07:00
Benjamin Doherty 85ea5a6b70 Bump version to 1.10.0 2021-05-17 11:00:42 -07:00
Benjamin Doherty 77891acb92 Merge branch 'rc/1.9.25' into release 2021-05-17 10:57:30 -07:00
Benjamin Doherty a06e01a196 Update RELEASE_NOTES for 1.9.25 2021-05-17 10:57:02 -07:00
Benjamin Doherty 034b6892f4 Release Filament 1.9.25 2021-05-17 10:55:58 -07:00
Benjamin Doherty 74fe102035 Update RELEASE_NOTES for 1.9.25 2021-05-17 10:54:38 -07:00
Philip Rideout 25cc554925 WASM: fix "Missing field" error for lensFlare. 2021-05-17 10:06:56 -07:00
Ben Doherty bd8ea711fd Add a FILAMENT_SUPPORTS_OPENGL CMake option (#3966) 2021-05-15 14:40:06 -07:00
Mathias Agopian c1347e55cb add java API for Texture::Builder::import()
deprecate Stream::stream(intptr_t).

This method was needed for ARCore back in the days, but there is now a
zero-copy way to achieve the same thing. This API shouldn't be used anymore.
2021-05-14 17:26:30 -07:00
Philip Rideout afbd6e6606 gltfio: fix morphing bugs uncovered by MorphStressTest.
The code that determined the "base slot" (i.e. the buffer object index
for the first morphed attribute) was very fragile and buggy.
MorphHelper now simply looks up the slot index in a stored mapping,
rather than trying to mimic the AssetLoader to determine the base slot.

Until now, most of the models we tested against only morphed the
position attribute, and never had a large set of target weights that
could be non-zero in a given time slice.
2021-05-14 17:05:27 -07:00
Mathias Agopian d6c5cb7778 workaround a shader compiler bug on qualcomm h/w 2021-05-14 16:58:40 -07:00
Mathias Agopian 43d47745dd API CHANGE: remove deprecated populateTangentQuaternions 2021-05-14 13:35:25 -07:00
Mathias Agopian f0d99070e4 Use a UBO instead of a texture for froxels data structure
MATERIAL BREAKAGE: this change breaks materials

In order to use one less sampler, we now use a UBO instead of a texture
to store the "froxel records". Currently this UBO is limited to 16KiB
vs. 64KiB before with the texture.

We also handle running out of record space better, by using a predefined
record that has all the lights in the scene. This way the scene will be
rendered properly, albeit at a potentially large performance cost.
2021-05-14 11:20:24 -07:00
Alexey Pelykh 6a49d67c6c Allow using specific NDK version, for CI don't use latest but required (#3950)
* Allow using specific NDK version, for CI don't use latest but required

* Default to highest available NDK version within same major release sequence

* Refactor NDK version selection
2021-05-14 11:06:31 -07:00
Philip Rideout 6b7c1b21cb VulkanPipelineCache: fix unbound pipeline error. 2021-05-13 23:33:06 -07:00
Philip Rideout b7d1b4ca1a VulkanPipelineCache: create dummy sampler. 2021-05-13 23:13:49 -07:00
Philip Rideout 8a04d5761b Fix validation on Windows. 2021-05-13 18:25:47 -07:00
Benjamin Doherty 8d8729be8e Remote UI: update viewer with new URL input 2021-05-13 16:46:26 -07:00
Ben Doherty d4325de47d Add URL input to Filament Remote Viewer (#3955) 2021-05-13 16:27:46 -07:00
Philip Rideout e29c76465b Minor improvement to Vulkan robustness. 2021-05-13 13:16:57 -07:00
Philip Rideout a220407aef Vulkan: Fix bistro, implement descriptor pool growth. 2021-05-13 12:28:12 -07:00
Philip Rideout 4df214003e Revert accidental Vulkan diagnostic commit.
This reverts commit 59a6758fce.
2021-05-13 08:56:48 -07:00
Philip Rideout 182250b9c0 VulkanPipelineCache: minor cleanup. 2021-05-13 08:34:02 -07:00
Philip Rideout 59a6758fce DO NOT COMMIT 2021-05-13 08:33:57 -07:00
Philip Rideout 73aa996444 VulkanPipelineCache: add a descriptor set arena.
This fixes the "descriptor set fragmentation" error that we would see on
Mali.

The pipeline cache now maintains an arena of descriptors that can be
re-used. We call this an "arena" to avoid confusion with
VkDescriptorPool.

Descriptors are returned to the arena only when they are not in use
by any pending command buffer. This allows them to be mutated safely
without worrying about synchronization.
2021-05-12 16:48:59 -07:00
Ben Doherty d787a521b5 Fix DIST_DIR setting for Windows builds (#3945) 2021-05-12 11:16:30 -07:00
Ben Doherty 46e52c71e1 Fix DIST_DIR setting for Windows builds (#3945) 2021-05-12 11:15:49 -07:00
Ben Doherty 08769ec35e Fix DIST_DIR setting for Windows builds (#3945) 2021-05-12 11:15:10 -07:00
Philip Rideout 3aa18eafb3 VulkanPipelineCache: refactor and simplify.
The API of the pipeline cache is now easier to use. Internally, it now
maintains separate pipeline and descriptor bindings for each command
buffer, since that's how Vulkan works.
2021-05-11 12:46:48 -07:00
Philip Rideout 8d4a0e5aa9 Vulkan: fix uninitialized cmd buffer handle. 2021-05-11 11:03:17 -07:00
Ben Doherty e8183d09c2 Fix MissingRequiredAttributes backend test with Metal (#3943) 2021-05-11 10:49:47 -07:00
Philip Rideout 5f1da1dfc0 VulkanDriver: Misc cleanup.
This cleanup is being done in preperation for a new descriptor set
strategy.
2021-05-10 18:26:12 -07:00
Philip Rideout 1dad27a172 Repair WebGL and fix potential INVALID_OPERATION.
We should take care not to call glVertexAttribPointer when there is
no bound ARRAY_BUFFER (i.e. when its binding is zero).

This fixes the black screen seen with some WebGL samples after
the recent memory leak fix related to the new BufferObject API.
2021-05-10 13:38:56 -07:00
Philip Rideout c1c5776439 Serialization: enforce correctness for bool.
If expecting a bool and receiving anything other than true or false,
this is invalid and should fail. This change triggered a unit test
failure which uncovered several actual problems.
2021-05-10 13:27:41 -07:00
Mathias Agopian da418fc7f2 fix another serialization bug 2021-05-10 12:15:52 -07:00
Philip Rideout fcaae825b7 Repair WebGL and fix potential INVALID_OPERATION.
We should take care not to call glVertexAttribPointer when there is
no bound ARRAY_BUFFER (i.e. when its binding is zero).

This fixes the black screen seen with some WebGL samples after
the recent memory leak fix related to the new BufferObject API.
2021-05-10 12:13:00 -07:00
Philip Rideout f5ee074674 Remote UI: fix lensFlare serialization. 2021-05-10 12:11:25 -07:00
Mathias Agopian 0c787b94b8 update remote ui 2021-05-10 11:22:55 -07:00
Philip Rideout 02f5f07db0 WASM: fix "Missing field" error for lensFlare. 2021-05-10 09:28:48 -07:00
Philip Rideout a97591a193 Fix minor logic warning. 2021-05-10 08:36:34 -07:00
Benjamin Doherty 60d230b380 Bump version to 1.9.25 2021-05-07 21:42:48 -07:00
Benjamin Doherty d7cb38e706 Merge branch 'rc/1.9.24' into release 2021-05-07 21:39:17 -07:00
Benjamin Doherty 80485bf520 Update RELEASE_NOTES for 1.9.24 2021-05-07 21:38:43 -07:00
Benjamin Doherty ce00cca6ee Update RELEASE_NOTES for 1.9.24 2021-05-07 21:36:49 -07:00
Benjamin Doherty 401bd8ce73 Bump version to 1.9.24 2021-05-07 21:35:30 -07:00
Mathias Agopian c23a7343d4 update remote ui 2021-05-07 16:57:05 -07:00
Romain Guy 75a24ee41f Update RELEASE_NOTES.md 2021-05-07 16:51:17 -07:00
Mathias Agopian 7e9a69df64 fix lens flare Settings writer 2021-05-07 16:18:52 -07:00
Mathias Agopian 12bf8d9659 DoF: don't use hole filling for the background
It did improve the look of the blur on far way geometry in some case,
but overall it hurts a lot more.
The case that falls appart is when everything is in the background layer
but there is a large depth difference anyways.
This creates a halo around edges.

Fixes #3221
2021-05-07 16:18:34 -07:00
Mathias Agopian d1c8d42bd2 update remote ui 2021-05-07 15:19:15 -07:00
Mathias Agopian c0fe2d1c09 new screen space lens flare effect
- this PR also improves bloom slightly


Note: for now this is not available on WebGL due to complications
in the bloom pass.
2021-05-07 13:20:16 -07:00
Philip Rideout 812f0d577b VulkanTexture: support format conversion via vkCmdBlitImage. 2021-05-07 12:46:37 -07:00
Philip Rideout 4a25ba1111 Minor VulkanTexture simplification. 2021-05-07 12:46:37 -07:00
Philip Rideout 0b4f3f76fc Vulkan: enable the mutableComparisonSamplers feature. 2021-05-07 11:09:17 -07:00
Philip Rideout e7e19a88e6 Add missing files to BlueVK. 2021-05-07 09:22:23 -07:00
Philip Rideout 4295eaa311 Vulkan refactor 2 of 2 (Binder => PipelineCache) 2021-05-06 18:47:19 -07:00
Philip Rideout 43e78f7a93 Vulkan refactor 1 of 2 (VulkanTexture and VulkanConstants) 2021-05-06 18:47:19 -07:00
Philip Rideout d627d57bad Second memory leak fix. (#3906)
Fixes #3888.
2021-05-06 14:25:46 -07:00
Philip Rideout 0a305a710a VulkanCommands now stalls when absolutely necessary. 2021-05-06 14:24:42 -07:00
Ben Doherty ef45d695d0 metal: Query max color render targets (#3895) 2021-05-06 11:33:49 -07:00
Philip Rideout ac50cb69f7 Vulkan: fix blit and readPixels for cubemaps. (#3903) 2021-05-06 11:16:28 -07:00
Philip RideoutandBen Doherty 9fc6e398c6 BackendTest: add blit cubemap test. (#3901)
* BackendTest: add blit cubemap test.

This test is similar to manual mipmap generation for cubemaps and
can uncover issues that are provked by libiblprefilter. It simply
dumps out a PNG that can be manually inspected.

Also, this test does not do makeCurrent / commit and is therefore
similar to renderStandaloneView.

* Update filament/backend/test/test_Blit.cpp

Co-authored-by: Ben Doherty <bendoherty@google.com>

Co-authored-by: Ben Doherty <bendoherty@google.com>
2021-05-06 10:38:55 -07:00
Ben Doherty e06b948343 Use 16 bit format for VSM (#3899) 2021-05-06 10:33:11 -07:00
Philip Rideout 28ca9df5a0 Second memory leak fix. (#3906)
Fixes #3888.
2021-05-06 10:15:20 -07:00
Romain Guy c66915209e Update our build to the latest and greatest (#3902)
The new requirements are as follow:
- CMake 3.19
- Ninja 1.10
- Android Studio 4.2
- Android NDK 22.1
- Gradle 7.0
- Kotlin 1.5
2021-05-06 10:13:10 -07:00
Philip Rideout cb4ffe39f4 Fix build break. 2021-05-05 15:00:59 -07:00
Philip Rideout e07f91ce8b Vulkan: use more aggressive barriers (Mali). 2021-05-05 14:22:29 -07:00
Philip Rideout 03fcbfea62 Regenerate BlueVK and update MoltenVK binaries. (#3897)
LunarG just released a new SDK so we're updating everything.
2021-05-05 14:15:52 -07:00
Philip Rideout f9d05a879a Vulkan: add a barrier after each render pass. (#3898)
The need for this barrier is fairly obvious, so it is surprising that
its absence has not caused problems on any platform except Mali.
2021-05-05 14:11:36 -07:00
Philip Rideout 8ffc776f1c Fix horrible memory leak in the GL driver. (#3894)
This leak was introduced in the following PR on April 7.
https://github.com/google/filament/pull/3775

The guilty party has been contacted and properly admonished for his
transgression.

This was tested by adding the following code after applyAnimation in
gltf_viewer.cpp

        static int nframes = 0;
        if (!gpath.empty() && nframes++ > 100) {
            static int count = 0;
            printf("reloading %d\n", count++);
            nframes = 0;
            app.resourceLoader->asyncCancelLoad();
            app.resourceLoader->evictResourceData();
            app.viewer->removeAsset();
            app.assetLoader->destroyAsset(app.asset);
            loadAsset(gpath, app);
            loadResources(gpath, app);
        }
2021-05-04 18:22:08 -07:00
Philip Rideout 7a8dd52c4c Fix horrible memory leak in the GL driver. (#3894)
This leak was introduced in the following PR on April 7.
https://github.com/google/filament/pull/3775

The guilty party has been contacted and properly admonished for his
transgression.

This was tested by adding the following code after applyAnimation in
gltf_viewer.cpp

        static int nframes = 0;
        if (!gpath.empty() && nframes++ > 100) {
            static int count = 0;
            printf("reloading %d\n", count++);
            nframes = 0;
            app.resourceLoader->asyncCancelLoad();
            app.resourceLoader->evictResourceData();
            app.viewer->removeAsset();
            app.assetLoader->destroyAsset(app.asset);
            loadAsset(gpath, app);
            loadResources(gpath, app);
        }
2021-05-04 17:50:46 -07:00
Mathias Agopian ef48cad322 cleanup bloom
- remove areFeedbackLoopsSupported from backend API, since this is only
  a problem on WebGL

- binary only include either the regular or webgl version of the bloom
  code, never both, which should save some binary size

- bloom pass is now called outside of the colorGrading pass, which is
  cleaner and makes it available for other pass, should they need it
  (not the case right now).

- always pass ColorGradingConfig to all color grading related methods,
  instead of individual parameters

- very minor optimization in bloom shader
2021-05-04 17:25:45 -07:00
Ben Doherty c39d692757 ios: Don't evict gltfio materials between asset loads (#3893) 2021-05-04 16:33:10 -07:00
Ben Doherty 4c1d8f310a Fix Filament remote file upload (#3891) 2021-05-04 14:52:42 -07:00
Mathias Agopian 1e1542fe16 ipbprefilter: simplify cpu side
- move kernel weight computation to the gpu side as a small cost, in
order to simplify the CPU side and reduce the binary size.

- skip samples with a weight of 0, which is a completely coherent 
check.

- fix a typo in move ctor
2021-05-04 13:12:39 -07:00
Mathias Agopian 647ac34c8c improve Texture::generateMipmap fallback
We now handle SAMPLER_2D_ARRAY, but SAMPLER_3D is still unsupported.
2021-05-04 10:53:27 -07:00
Mathias Agopian ea34691625 Support a maximum of 8 render buffers (from 4)
We chose 8 renderbuffer because it seems to be commonly supported
on mobile gpu and is more than 6 which is needed for generating
cubemaps. 4 was the minimum guaranteed by ES3.0.

The main changes here are:
- TargetBufferFlags is now a uint32_t instead of uint8_t
- The number of render buffer supported by filament and supported by
  the hardware can now be different. Applications/users now must
  query this value if more than 4 is needed.
- added a backend query (used gl terminology)


This is a redo of a previous attempt. There was an issue in the GL
backend that caused MRT to fail on some devices.
2021-05-04 10:53:07 -07:00
Philip Rideout 4557255ce1 Vulkan: fix initial image layout for cubemaps. (#3885) 2021-05-04 09:45:15 -07:00
Philip Rideout 4cb951461b Vulkan: enable anisotropic filtering if supported. (#3884) 2021-05-04 09:43:52 -07:00
Philip Rideout 750dcbb9d8 Vulkan: fix image view type for render target attachments. (#3883)
When rendering into a single cubemap face, we should use
VK_IMAGE_VIEW_TYPE_2D rather than VK_IMAGE_VIEW_TYPE_CUBE.
2021-05-04 09:41:54 -07:00
Romain Guy 459f70f7b4 Update docs 2021-05-03 17:55:32 -07:00
Mathias Agopian 61748fa7dc improve opengl backend program failure logs 2021-05-03 15:10:14 -07:00
Benjamin Doherty be032b52c1 Bump version to 1.9.24 2021-05-03 10:42:19 -07:00
Benjamin Doherty 4388e81e5f Merge branch 'rc/1.9.23' into release 2021-05-03 10:40:49 -07:00
Benjamin Doherty a36d432b88 Update RELEASE_NOTES for 1.9.23 2021-05-03 10:40:15 -07:00
Benjamin Doherty b3f43eea13 Release Filament 1.9.23 2021-05-03 10:39:26 -07:00
Benjamin Doherty 71a185d139 Update RELEASE_NOTES for 1.9.23 2021-05-03 10:38:59 -07:00
James Walker df3c7e2c1c Improve documentation formatting
* Improve doxygen formatting of docs for Renderer::readPixels

* slight tweaks
2021-05-03 09:28:27 -07:00
Philip Rideout cbc4c75a7e Vulkan: fix logic in Disposer, simplify StagePool. 2021-05-01 19:55:17 -07:00
Mathias Agopian e068d8b698 ssao: fix a typo in the accurate normal reconstruction 2021-04-30 17:15:27 -07:00
Mathias Agopian 06e9a3d31f ssao: high quality upsampling didn't work when low pass was disabled 2021-04-30 17:15:27 -07:00
Philip Rideout e5ac49f86d Vulkan: big refactor for command buffer management. (#3875)
This removes a lot of caveats that we had in the Vulkan backend. Many
driver API calls were unsupported due to a lack of command buffer, but
in the new scheme, a command buffer can *always* be made available,
and there's no weird separate "work and swap chain command buffers".

Here's how various driver API entry points now map into Vulkan actions:

```
makeCurrent => Acquire Swap Chain.
beginFrame => Do nothing.
endFrame => Submit command buffer and create a new one.
commit => Submit commit buffer again if necessary, Present Swap Chain.
```

This handles both copyFrame (which does not do beginFrame / endFrame)
and renderStandaloneView (which does not do makeCurrent / commit).
2021-04-30 15:31:24 -07:00
Ben Doherty 7fdc63b6ae Fix incorrect units documented for getIntensity (#3870) 2021-04-30 10:09:52 -07:00
Ben Doherty 808abdb6d7 Fix memory leak inside utils::details::SafeString (#3871) 2021-04-29 14:42:07 -07:00
Ben Doherty 037982a0ef Add gltf-viewer iOS sample (#3873) 2021-04-29 12:13:34 -07:00
Philip Rideout 5f86233218 Enable Vulkan in our Android Release package. (#3864)
This makes release builds consistent with continuous builds and default
local builds. It also makes it easier to test the Vulkan backend.
Clients who need a smaller APK size can always make their own build.

This also makes filament-android-release.aar go from 1.8M to 2.3M.
Note that we are now including bluevk, vkshaders (for the blit shader),
smol-v (for SPIRV decompression) and vk_mem_alloc (for mem allocation).
2021-04-27 23:00:57 -07:00
Mathias Agopian 8bd73a44c9 Revert "Support a maximum of 8 render buffers (from 4)" (#3868)
This reverts commit 6f948c101f.

This is breaking rendering on Android when certain postprocessing
effects are disabled (e.g. bloom/msaa/dof).
2021-04-27 22:56:10 -07:00
Mathias Agopian f1984b19cc lightbulb: clear background
Fixes #3849
2021-04-27 20:50:48 -07:00
Mathias Agopian c2330fe55a ssao: improve LOW and HIGH quality levels
Simply tweak the "spiralTurns" parameter, empirically to improve the
noise pattern produced by the gradient noise. In turn, this helps the
gaussian filter.
2021-04-27 20:50:03 -07:00
Mathias Agopian dc56408d5f ssao: implement accurate normal reconstruction
This removes "false AO" effect on geometry edges.
Currently this is enabled on desktop only (quality == high).
2021-04-27 20:50:03 -07:00
Romain Guy f5adbbddb8 Fix typo 2021-04-27 20:33:58 -07:00
Mathias Agopian 036bfa9b20 Materials now have a quality property.
We used to have that before, but it was hardcoded and depended on
mobile vs. desktop.
With this change, users can set the quality on the material itself.
The default match the current settings. There are 3 quality levels:

low: enables optimization that might not be 100% correct 
     (e.g. abs(x) instead of sqrt(x*x))

normal: like low, but doesn't sacrifices correctness.

high: could be improved upsampling, etc...
2021-04-27 14:20:50 -07:00
Mathias Agopian 2d9064d2bf Cleanup some shader #defines
- create a new FILAMENT_HAS_FEATURE_TEXTURE_GATHER, which can be used
  in the shaders to use textureGather.

- A new TARGET_GLES_ENVIRONMENT and TARGET_GL_ENVIRONMENT in addition
  to TARGET_METAL_ and TARGET_VULKAN_, for completeness.

- Rename TARGET_LANGUAGE_SPIRV to FILAMENT_VULKAN_SEMANTICS and add
  FILAMENT_OPENGL_SEMANTICS for completeness.

- expose the shader model to shaders as: FILAMENT_SHADER_MODEL_ES30 and
  FILAMENT_SHADER_MODEL_GL41

Use these new #define where appropriate.

The main change here is that TARGET_MOBILE is now only used for dealing
with the `mediump` default on mobile.

This change also enables textureGather on Metal.
2021-04-27 14:20:50 -07:00
Mathias Agopian 6f948c101f Support a maximum of 8 render buffers (from 4)
We chose 8 renderbuffer because it seems to be commonly supported
on mobile gpu and is more than 6 which is needed for generating
cubemaps. 4 was the minimum guaranteed by ES3.0.

The main changes here are:
- TargetBufferFlags is now a uint32_t instead of uint8_t
- The number of render buffer supported by filament and supported by
  the hardware can now be different. Applications/users now must
  query this value if more than 4 is needed.
- added a backend query (used gl terminology)
2021-04-27 12:15:22 -07:00
Romain Guy 9c123a59ab New experimental tone mapper (#3850)
* New experimental tone mapper

The new tone mapper proposed in this change replaces Uchimura (see
below) and is composed of two distinct algorithms:

- The first is the customizable compression curve from Timothy Lotte
  (from GDC 2015). The curve's default parameters were chosen to
  match the overall appearance (contrast) of the ACES curves used
  as our current default tone mapper. This was done to provide a
  good migration path to making this new solution the default in
  a future version of Filament.
  The compression curve can be customized via its contrast, shoulder,
  input middle gray, output middle gray, and maximum "HDR value"
  (scene referred).
  It is important to note that the compression is only applied to
  the luminance of the input scene referred value.
- The second is a novel approach by Troy Sobotka called Exposure
  Value Invariant Luminance Scaling (or EVILS). This solution works
  on the largest chromatic channel of the input value as opposed
  to mapping all RGB channels as we do in our other tone mappers.
  The algorithm effectively scales all channel by a ratio that
  depends on both the compressed luminance from the first stage
  and the luminance of input value normalized by the largest
  channel.

This new solution offers important benefits as it manages to
preserve chromaticity for high input values. It is also designed
to provide a desirable rolloff to white on overexposure. This
means that even without gamut mapping, this solution avoids many
hue skews (red to orange, blue to purple, etc.). The results
provided by this solution are much more natural and make using
other color grading tools much easier.

* Use std::pow instead of pow

* Fix Web builds
2021-04-26 18:09:37 -07:00
Philip Rideout 4006018907 Fix Java warnings. (#3856) 2021-04-26 13:49:49 -07:00
Mathias Agopian 02c1e1dc60 Improve libiblprefilter
- move public headers from filament/foo to filament-foo/
  to avoid confusion with libfilament's headers
- add support for equirectangular to cubemap conversion
- add support for using an .hdr file directly in all our samples
2021-04-26 12:17:42 -07:00
Ben Doherty 03d74f1313 Update web docs, add note about shadowMultiplier (#3855) 2021-04-26 12:05:25 -07:00
Benjamin Doherty d2cf5985ac Bump version to 1.9.23 2021-04-26 10:55:10 -07:00
Benjamin Doherty debcbb8e5c Merge branch 'rc/1.9.22' into release 2021-04-26 10:52:43 -07:00
Benjamin Doherty 4f2460a23c Update RELEASE_NOTES for 1.9.22 2021-04-26 10:52:37 -07:00
Benjamin Doherty f68dbe1902 Release Filament 1.9.22 2021-04-26 10:52:37 -07:00
Benjamin Doherty b9dd62c7d3 Update RELEASE_NOTES for 1.9.22 2021-04-26 10:47:11 -07:00
Mathias Agopian d589634968 don't set sun parameters if we didn't have SH
The parameters would turn out as NaN.
We might need a better API for this, but it's
never okay to set NaN values.
2021-04-26 10:44:12 -07:00
Benjamin Doherty dc2b430f34 Bump version to 1.9.22 2021-04-26 10:39:16 -07:00
Mathias Agopian 9914eb84a4 Fix documentation for getNormalizedViewportCoord
Fixes #3821
2021-04-23 22:39:01 -07:00
Mathias Agopian 0a6886e43b improve the importance sampling code
- fix a lod selection bug
- add interleaved gradient noise when sampling the brdf
- compute the diffuse using importance sampling too
2021-04-23 15:21:07 -07:00
Mathias Agopian bcd4b65f7d fix a memory corruption introduced recently
fixes #3844
2021-04-23 15:20:51 -07:00
Philip Rideout 820717df0e gltfio: Use the new Transcoder API in some cases. (#3840)
Fixes issue seen with Vulkan + the quantized version of Avocado.

We already support the quantized glTF extension, which is when this
comes up. Technically this is only needed for Vulkan but gltfio does
not (and should not) know which backend is being used, so we simply
apply these transformations assuming the worst.

In practice this code usually won't be activated, and if even when it
is, it won't hurt loading time as much as other things like large
textures.
2021-04-22 16:11:34 -07:00
Philip Rideout 6178ba4a6b Add Transcoder API for C++ clients. (#3837)
* Add Transcoder API for C++ clients.

We will add JavaScript and Java support in a later PR.

* Transcoder: use fixed inner loop in some cases.

This lets clang produce better ARM code for common cases.

* Transcoder: stronger typing in Config, etc.

* Transcoder: add UTILS_RESTRICT and noexcept.
2021-04-22 13:29:52 -07:00
Mathias Agopian 6f14c1fa91 don't hardcode drawbuffer to 4
This is the first step at trying to un-hardcode the number of drawbuffer
we support. The ultimate goal is to go from currently 4 to 8.

Until now the maximum render buffer supported was the same than the actual
number of render buffer supported. At some point in the future this will
change, it this will have to be dynamic.

This change is to allow rendering a cubemap in a single pass on h/w that
support it. Many mobile GPU support 8 draw buffers.
2021-04-22 11:59:10 -07:00
Philip Rideout 6a94c77b1e Vulkan: fix VK_FORMAT to correctly handle non-integer types.
The SCALED formats are useful when the shader consumes a float, but
you want to give it an integer.
2021-04-22 11:18:49 -07:00
Philip Rideout c3d6c853ab gltfio: robustness improvements for Draco meshes.
These changes are motivated by #3815.

See also:
    https://github.com/KhronosGroup/glTF-Blender-IO/issues/1326
    https://github.com/KhronosGroup/glTF-Blender-IO/issues/1345
2021-04-21 18:09:45 -07:00
Mathias Agopian 9575a7453e add an option to control the strength of the importance sampling
This is very useful either with a low sample count, or with a very
HDR image.
2021-04-21 15:41:43 -07:00
Mathias Agopian cfd9689444 fix several bugs in the gpu prefilter code
- the miplevel wasn't computed correctly
- the random rotation was incorrect
- the default HDR compression was too aggressive
- better validation of the input cubemap
2021-04-21 15:41:43 -07:00
Mathias Agopian c819265597 Add README.md file and fix some comments 2021-04-21 15:41:43 -07:00
Mathias Agopian 0427787cb7 Generate the kernel texture on the GPU
This avoids having to upload data from the cpu.
2021-04-21 15:41:43 -07:00
Mathias Agopian e372cc25f2 more fixes from review comments
- get rid of createREflectionsTextures public api
- use default material instance
2021-04-21 15:41:43 -07:00
Mathias Agopian b98d9dcff3 clarify requirements 2021-04-21 15:41:43 -07:00
Mathias Agopian 91b08705da rename library to filament-iblprefilter 2021-04-21 15:41:43 -07:00
Mathias Agopian 503abb3c94 rename a few things 2021-04-21 15:41:43 -07:00
Mathias Agopian 4b8d98af8c compute all lod kernel at once
we now store the kernel for each lod in a texture, this has several
advantages:
- the texture can be reused, so we can amortize that cost a bit
- we could generate the texture with a shader, so that we don't
  have to do any texture uplaod (TBD).
2021-04-21 15:41:43 -07:00
Mathias Agopian ced6c3de1f GPU based IBL prefiltering library 2021-04-21 15:41:43 -07:00
Mathias Agopian f8ced1170e fix typo that broke java apps 2021-04-21 15:15:01 -07:00
Ben Doherty a166fcdcdf Specific sampler precision only on GLES (#3829) 2021-04-21 10:11:55 -07:00
Ben Doherty faac96730a Disable VSM MSAA on Adreno devices (#3816) 2021-04-21 10:06:03 -07:00
Mathias Agopian 4929f11793 attempt to fix web build 2021-04-20 22:16:01 -07:00
Mathias Agopian b1d877e7db Add Engine::getEntityManager() 2021-04-20 16:12:40 -07:00
Romain Guy 3f09e62f23 Fix docs 2021-04-20 14:40:04 -07:00
Ben Doherty 03bc9926dd Check that drawSwapChain exists inside endFrame (#3828) 2021-04-20 14:07:43 -07:00
Mathias Agopian e64e8927ce don't use TARGET_MOBILE for quality settings
Until now we were using TARGET_MOBILE in our shaders for both 
quality setting and correctness.

With this PR we introduce a new define FILAMENT_QUALITY which currently
can take two value FILAMENT_QUALITY_LOW and FILAMENT_QUALITY_HIGH and
we use that instead of TARGET_MOBILE for quality settings.

Currently, FILAMENT_QUALITY_LOW is selected when TARGET_MOBILE is set.
2021-04-20 13:39:16 -07:00
Philip Rideout 0643b9e7dd Specify a version range for Pygments. 2021-04-20 12:30:11 -07:00
Benjamin Doherty e5ef4e8868 Update RELEASE_NOTES for 1.9.21 2021-04-19 11:36:37 -07:00
Benjamin Doherty 032ce5ff83 Update RELEASE_NOTES for 1.9.21 2021-04-19 11:36:08 -07:00
Benjamin Doherty c0d6cd3ac3 Merge branch 'rc/1.9.21' into release 2021-04-19 11:34:23 -07:00
Benjamin Doherty b63ab2dc19 Update RELEASE_NOTES for 1.9.21 2021-04-19 11:32:31 -07:00
Benjamin Doherty 623833a5d6 Release Filament 1.9.21 2021-04-19 11:19:05 -07:00
Mathias Agopian f7eb55f2f5 NEW API: Renderer can process standalone View
New Api:

- Renderer::renderStandaloneView() is a new method that can be used
  outside of beginFrame/endFrame on Views that have a RenderTarget
  associated. This can be used as a poor man's compute API.

Improvements to Renderer:

- more aggressively skip lighting/shadowing code that won't be
  needed by the current view

- Allow up to 64 KiB to be allocated from the render stream, up from
  1 KiB
2021-04-19 11:17:38 -07:00
Philip Rideout b095e65e28 VulkanUtility: mark illegal formats with comments. 2021-04-16 15:26:04 -07:00
Benjamin Doherty 98fd95440f Minor updates to release script / guide 2021-04-16 12:11:43 -07:00
Philip Rideout 5f00e715ea Vulkan: another fix to the UBO barrier. (#3814)
Even though the vertex shader comes before the fragment shader,
both bits needs to be present in the barrier, since a Vulkan
implementation might partition its uniform cache between stages.

Thanks to Chris Forbes for pointing this out.
2021-04-16 10:17:51 -07:00
Mathias Agopian 64187ebe8a fix uninitialized state in rendertarget sample 2021-04-15 12:06:21 -07:00
Philip Rideout 1ab127ff03 Fix unused private field warning. 2021-04-15 11:37:08 -07:00
Philip Rideout 3c09d8784a Minor fixups for drag-and-drop viewer page. 2021-04-15 10:11:05 -07:00
Ben Doherty 31ec6550ec Fix Windows build error in filament_framegraph_test.cpp (#3809) 2021-04-15 10:04:34 -07:00
Philip Rideout 24b88219fa VulkanDriver: clean up pipeline barrier for UBO. (#3810)
After eyeballing this barrier I realized it was configured incorrectly,
but it did not seem to manifest as an actual error anywhere.

Basically, it needs to ensure that the UBO is fully updated before it
is read by the vertex shader associated with the next draw call.
2021-04-14 17:54:57 -07:00
Philip Rideout 5c437d9163 matdbg robustness improvements / cleanup. (#3799)
* matdbg robustness improvements / cleanup.

* matdbg code review feedback
2021-04-14 11:39:42 -07:00
Philip Rideout 09bda8a1dc Add glTF viewer to public website.
This will allow folks to drop a GLB into the following page to get a
WebGL preview. It always uses the latest version of Filament via unpkg.

https://google.github.io/filament/viewer

After the next release we can also use the `<filament-viewer>` component
itself from unpkg and remove the local copy.
2021-04-14 10:42:38 -07:00
Philip Rideout f76084213c Update emscripten to 2.0.17
The latest version of emscripten includes major updates to LLVM and
Binaryen.
2021-04-14 10:13:24 -07:00
Philip Rideout b8ed546555 Fix minor warnings. 2021-04-13 13:59:02 -07:00
Philip Rideout 9553786cd5 <filament-viewer> now supports optional drag-and-drop. 2021-04-13 13:41:34 -07:00
Benjamin Doherty 7ef79ad626 Update RELEASE_NOTES for 1.9.20 2021-04-13 11:49:19 -07:00
Benjamin Doherty 0ac2fe02dc Release Filament 1.9.20 2021-04-13 11:49:19 -07:00
Philip Rideout c994ab9f60 sample-gltf-viewer: more improvements for zip files.
- If a resource file is missing, show toast instead of crashing.
- Allow glb files in zip files.
- Run blocking calls like createTempFile() on IO thread.
2021-04-13 11:20:08 -07:00
Mathias Agopian 600600b9af allow the public RenderTarget API to use MRT 2021-04-13 11:02:37 -07:00
Mathias Agopian 1b870a55e2 silently clamp MSAA sample count to maximum allowed
It's an error to ask for a higher MSAA sample count than supported by
the gl driver, and results in corrupted rendering.
We now always clamp the requested sample count to the maximum allowed 
but the gl driver.

includes some minor refactoring.
2021-04-12 16:05:43 -07:00
Philip Rideout 965e845133 sample-gltf-viewer: Delete zip file when done reading. 2021-04-12 16:03:30 -07:00
Philip Rideout 7107afbf0f sample-gltf-viewer: Prevent OOM for large models like Bistro. 2021-04-12 16:03:30 -07:00
Mathias Agopian cbb809e535 enable contact-shadows functionality in mobile gltf-viewer
contact-shadows needs to be enabled per object.
2021-04-12 15:11:18 -07:00
Philip Rideout c5169a431b Fix warning. 2021-04-12 12:46:07 -07:00
Mathias Agopian 6b798ec274 add README to benchmark folder 2021-04-12 12:15:41 -07:00
Ben Doherty 1cde9b326c Fix bad Javadoc in Texture.java 2021-04-12 11:57:18 -07:00
Benjamin Doherty 5d8dad561c Bump version to 1.9.21 2021-04-12 11:38:27 -07:00
Benjamin Doherty 8933be1ae2 Merge branch 'rc/1.9.20' into release 2021-04-12 11:36:17 -07:00
Benjamin Doherty 6b66b48b1d Update RELEASE_NOTES for 1.9.20 2021-04-12 11:35:45 -07:00
Benjamin Doherty 9c23eb6e33 Release Filament 1.9.20 2021-04-12 11:34:39 -07:00
Benjamin Doherty baea54a3fc Update RELEASE_NOTES for 1.9.20 2021-04-12 09:20:31 -07:00
Philip Rideout 4b9ab66ce7 JavaScript: add missing TextureSampler bindings. 2021-04-09 13:00:50 -07:00
Mathias Agopian ba7ebf5ea6 better handle anisotropic filtering with various drivers
Some drivers claim to support anisotropic filtering but don't allow
setting it via glSamplerParameter. Until now we were disabling 
anisotropic filtering entirely on these drivers at compile time.

With this change, we should detect at runtime which drivers have this
issue and use a workaround -- instead of disabling anisotropic 
filtering entirely.
2021-04-09 12:53:21 -07:00
Ben Doherty afdc3d068c Add default precision qualifiers for special sampler types (#3786) 2021-04-09 10:12:03 -07:00
Mathias Agopian 941e81b3aa rework the "debugCommand" feature of backend
- it was called on the main thread side, which didn't allow to,
  for instance, systrace commands on the backend thread side.

- moved to a begin/end callback model

- implemented basic logging/systracing for all backends in Driver.cpp
  (and removed this functionality for the metal driver).

note: refactored CommandStream class attributes only to work around
a clang bug we running into in CI.
2021-04-08 16:35:07 -07:00
Mathias Agopian de7075ff8f enable timer queries on Mali-G series 2021-04-08 16:34:48 -07:00
Philip Rideout 5deed8dc5a Vulkan: fix image layout validation error on Android. 2021-04-08 15:17:24 -07:00
Philip Rideout 93f0d0576d Improve error reporting for vkAllocateDescriptorSets. 2021-04-08 13:06:22 -07:00
Ben Doherty ec339b0282 Fix texture swizzling crash with older Nvidia GPUs (#3779) 2021-04-08 10:38:59 -07:00
Philip Rideout a67505bbe2 VertexBuffer cleanup and simplification.
This includes changes to OpenGL, Metal, and Vulkan backends.

At the backend level, vertex buffers are now always composed of buffer
objects. This lets us simplify the Driver API and some bookkeeping in
the backends.

This change also splits MAX_VERTEX_ATTRIBUTE_COUNT into two constants
because the maximum number of bound buffers is a separate concept from
the maximum number of attribute semantics (e.g. consider interleaving).
For now these two constants are set to the same value.

We also now store a byte count in HwBufferObject, which allows us to
remove the byte count from the Metal-specific handle, and to add some
asserts to debug builds to prevent size overflow.
2021-04-08 09:56:51 -07:00
Philip Rideout 8fd1cefcdf sample-gltf-viewer: keep screen turned on 2021-04-07 16:39:29 -07:00
Ben Doherty 03f7ac6ef4 Fix Material and MaterialInstance Javadocs (#3778) 2021-04-07 14:21:32 -07:00
Mathias Agopian 274e227f49 Fix some mediump related issues
- DoF: don't convert gl_FragCoord to mediump when generating noise
- SSAO: add a bunch of missing highp qualifiers
- all matrices and UV should be highp
- Also fix some typo in comments.
2021-04-07 11:39:36 -07:00
Mathias Agopian 9302a2e711 update remote controler 2021-04-06 21:18:18 -07:00
Mathias Agopian ee9d87b543 use more reasonable near/far for gltf viewer 2021-04-06 17:55:51 -07:00
Mathias Agopian 391cf2487a add missing parameters in ssao serialization 2021-04-06 17:52:01 -07:00
Philip Rideout 914503a30e gltfio: honor stride in normalizeSkinningWeights.
This fixes the issue seen with RecursiveSkeletons.gltf, which is a model
that might soon be added to the Khronos sample models repo.

Fixes #3765.
2021-04-06 15:42:21 -07:00
Philip Rideout 17b8717557 Fix unit test regression. 2021-04-06 15:04:10 -07:00
Philip Rideout 4f49cdbd1e Update remote control web page. 2021-04-06 14:17:07 -07:00
Philip Rideout 24c5cbac68 ModelViewer and Remote UI now support focal length.
The focal length slider now works over a remote connection. Also, the
slider for focus distance now controls the value in `ViewerSettings`
(which gets applied to Camera) rather than the value in
`DepthOfFieldOptions` (which is deprecated).
2021-04-06 14:17:07 -07:00
Mathias Agopian befc1de389 improve a bit GLES error logging code.
no functionality changes, just easier to use when debugging.
2021-04-06 14:00:32 -07:00
Mathias Agopian 45522f24c9 fix MSAA w/ multisampled_render_to_texture on Mali
according to the gl spec, we can't mix the EXT versions of
glRenderbufferStorageMultisample/glFramebufferMultisample with
the regular versions. Other drivers are more permissive.

When allocating a renderbuffer and the extention is supported, we always
use it.
2021-04-06 14:00:16 -07:00
Mathias Agopian 1bd0bb9b81 fix output location in fragment shaders
It looks like the layout(location) is needed for output parameters of
the fragment shader in GLES. Adreno dirver didn't seem to care, but
Mali drivers do. 

This fixes shaders that use multiple out buffers in debug mode.
2021-04-06 13:59:56 -07:00
Philip Rideout 4229610f05 Update emscripten in Google Actions.
This now matches what is already specified in BUILDING.md
2021-04-06 07:58:26 -07:00
Mathias Agopian c062cd9914 gl backend minor code cleanup
- be more consistant with extension naming
- sort extension queries alphabetically
2021-04-05 22:51:56 -07:00
Mathias Agopian 449a5907d1 Better handle GL_GOOGLE_cpp_style_line_directive
We now alwyas scrap this extension usage if the driver doesn't support
it, regardless of being in debug or release mode.
2021-04-05 15:28:40 -07:00
Ben Doherty 9130ef5451 Check environment variable to force integrated Metal device (#3757) 2021-04-05 14:43:38 -07:00
Philip Rideout 82fcb656d9 gltfio: Use BufferObject API, simplify MorphHelper. (#3737)
* gltfio: Use BufferObject API, simplify MorphHelper.

* Repair Android build.
2021-04-05 13:00:39 -07:00
Philip Rideout a139d7fc01 Fix Java warnings.
This adds the 565 enum to a switch block (which is an actual bug),
and it fixes a JavaDoc warning about missing summary fragments (which
is just a silly warning).
2021-04-05 13:00:15 -07:00
Ben Doherty 3242fbaf20 Implement Metal BufferObjects (#3749) 2021-04-05 12:45:07 -07:00
Philip Rideout 037a783e07 Add web component demo.
Just for fun, this is an example of a web component that allows you to
embed a Filament viewer with a single HTML element. It does not have
many features, but is much easier to use than our raw JavaScript API.
2021-04-05 11:42:27 -07:00
Benjamin Doherty 8c714d5a1f Update RELEASE_NOTES for 1.9.19 2021-04-05 11:14:52 -07:00
Benjamin Doherty 3fbc4f2915 Release Filament 1.9.19 2021-04-05 11:14:51 -07:00
Benjamin Doherty d9f800454c Bump version to 1.9.20 2021-04-05 11:14:17 -07:00
Benjamin Doherty f9ee0de07a Merge branch 'rc/1.9.19' into release 2021-04-05 11:11:13 -07:00
Benjamin Doherty 2786d0a9f7 Update RELEASE_NOTES for 1.9.19 2021-04-05 11:10:50 -07:00
Benjamin Doherty 491e8032e6 Release Filament 1.9.19 2021-04-05 11:10:20 -07:00
Benjamin Doherty ef3f13f5d3 Update RELEASE_NOTES for 1.9.19 2021-04-05 11:09:38 -07:00
Benjamin Doherty bcb5b2d790 Implement Metal BufferObjects 2021-04-05 11:01:36 -07:00
Adrian PerezandPhilip Rideout e29bfc2c86 ImGuiHelper can construct with a context (#3753)
* ImGuiHelper supports client-provided context

this lets impress load >1 embedded  font into the font table

* ImGuiHelper supports client-provided context

this lets impress load >1 embedded  font into the font table

Co-authored-by: Philip Rideout <philiprideout@gmail.com>
2021-04-05 10:42:57 -07:00
Mathias Agopian 8a34f3c289 revive somewhat the importance sampling mode 2021-04-04 23:36:17 -07:00
Mathias Agopian 951802dd73 SSAO: fix high-quality upsampling
Another mediump issue.
2021-04-04 22:20:03 -07:00
Philip Rideout b95d91a65e WebGL: expose fitIntoUnitCube to JS. 2021-04-04 21:38:08 -07:00
Thomas Gorisse fe94f935f1 Expose TransformManager.getParent(int) (#3751)
It will be nice to have access to TransformManager EntityInstance parent.
2021-04-03 15:45:46 -07:00
Romain Guy 6b529bb231 Fix typo 2021-04-02 15:16:00 -07:00
Philip Rideout c2fabbf9d9 WebGL: support for multiple <canvas> elements.
We now annotate the JS wrapper for Engine with a GL context handle.

This is fairly hacky because emscripten hides its internal GL object
from JavaScript, and it does not provide a mechanism to pass JS objects
into inline assembly.
2021-04-02 14:29:48 -07:00
Philip Rideout 7d604cd05b Add script that updates remote UI.
This script makes it easy to update the web page at
https://google.github.io/filament/remote/ even if you do not have the
emscripten SDK. It works by downloadinug the latest continuous web
build, then placing the wasm file in the right place.

After running the script, the user must make a git commit to finish the
operation.
2021-04-02 12:34:16 -07:00
Philip Rideout 57f1932744 Vulkan: add swizzle support. 2021-04-02 12:34:00 -07:00
Mathias Agopian 891fb65daa added a slider to debug dynamic scaling issues
This is a big hackish, but is intended to help us debug scaling issues,
this adds a couple of sliders under [Debug] to control dynamic
scaling manually.
2021-04-02 11:01:53 -07:00
Mathias Agopian f35be05e76 DoF: fix anamorphism of the Bokeh when dynamic scaling is used 2021-04-02 11:01:29 -07:00
Romain Guy bd4a207b37 Switch specular-color to CIE 1931 10 degree observer 2021-04-02 09:55:11 -07:00
Philip Rideout e19dff18c3 Add JSON unit test, fix ring count output.
Shockingly there were no unit tests that did a simple write-then-read.
This is important because it's easy to forget details such as trailing
commas and the fact that uint8_t is a char.
2021-04-01 21:06:44 -07:00
Philip Rideout deee5d2815 Update the remote web page. 2021-04-01 18:00:49 -07:00
Philip Rideout 53f5fd91b7 Add print operator for BufferObjectBinding. 2021-04-01 14:52:06 -07:00
Philip Rideout 0969cec45d BufferObject API: add Vulkan support. 2021-04-01 14:52:06 -07:00
Philip Rideout ded542a543 Introduce BufferObject API.
NOTE: after Metal and Vulkan support lands, we can potentially simplify
the Driver API by removing some of the old VertexBuffer entry points.

This introduces a new API-level object called `BufferObject`, and a new
backend-level object called `HwBufferObject`. This encapsulates a single
VBO. It's especially useful when clients need to share data between
multiple VertexBuffer objects. (e.g. for morphing).

In the future, buffer objects could perhaps be used for non-vertex data
(e.g. for compute).

The existing `VertexBuffer` class can now be configured to use buffer
objects by calling `enableBufferObjects` on the builder. By default its
API is unchanged. If buffer objects are enabled, then clients should use
`setBufferObjectAt` (which takes a buffer object) rather than
`setBufferAt` (which takes CPU data).

OpenGL is the trickiest backend for this, due to existence of VAOs.
The implementation in this PR uses a version-tracking scheme to
figure out when to update the VAO.
2021-04-01 14:52:06 -07:00
Mathias Agopian 385a17b8a5 DoF: add many user settings
- native/half resolution
- gather kernel ring counts
- circle-of-confusion radius clamps
2021-04-01 14:42:10 -07:00
Ben Doherty 0a0588aec8 Add Metal and Vulkan backend support to Suzanne sample (#3736) 2021-04-01 12:22:15 -07:00
Ben Doherty 9af62251b6 Fix Metal texture swizzling (#3732) 2021-04-01 10:19:50 -07:00
Mathias Agopian 819878a1da DoF: implement "background hole filling"
We use the technique used by Jimenez for the foreground applied to the
background, where we "guess" the missing background information from
neighboring pixels. In several papers it's not deemed useful for the
background, however, it does improve the blur quality a lot very shallow
DoF, i.e. when a moderately blurred background sits over a strongly 
blured one.
2021-03-31 17:49:41 -07:00
Mathias Agopian e7364cdcb3 DoF: don't rely on texture swizzle being supported 2021-03-31 12:17:34 -07:00
Mathias Agopian e5bfe81d0c DoF: use only a single low res source for both fg and bg
Before we were keeping a foreground and background version of the
low resolution source, but in practice it really doesn't make a big
difference and we save a fair amount of bandwidth this way.

The bulk of the change is to remove a texture/target which mostly
affects the downsample and mipmap passes.
Also renamed some variables to be less confusing (MaxMin to MinMax for e.g.)
and fixed a few typos.
2021-03-31 12:17:34 -07:00
Mathias Agopian c4eb790065 Add support for texture swizzling in framegraph 2021-03-31 12:17:34 -07:00
Romain Guy ac56efcd95 Revert misguided attempt to fix bloom with glTF (#3728)
* Revert misguided attempt to fix bloom with glTF

* Put back line removed by mistake
2021-03-31 10:08:36 -07:00
Mathias Agopian 9fcb8ccb9e DoF: document a typo
there has been a typo in the DoF code a while, but fixing it looks
much worse. we need to understand why. so for now we at least
document the typo in the code.
2021-03-30 21:34:59 -07:00
Mathias Agopian 67a936d845 fix a linker warning 2021-03-30 15:58:17 -07:00
Ben Doherty d11f3f7d5a Implement Metal texture swizzling (#3720) 2021-03-30 15:38:55 -07:00
Mathias Agopian 625c4d8968 implement query for texture swizzle
unfortunately metal does support texture swizzle on all versions of
macos we support.
2021-03-30 14:24:17 -07:00
Ben Doherty 239b933d5e Fix VSM on Android (#3719) 2021-03-30 14:05:53 -07:00
Philip Rideout 3161f6a8f1 Remote UI now handles keyboard input. 2021-03-30 08:15:01 -07:00
Philip Rideout d2bff95c90 Easy build: add matdbg option and help message. 2021-03-30 08:14:23 -07:00
Philip Rideout a0e7c26a63 Remote pip lockfile from web docs generator. 2021-03-29 14:49:12 -07:00
Ben Doherty 02de3f2e2a Fix, regression with Metal buffers (#3715) 2021-03-29 14:21:34 -07:00
Ben Doherty 5bfa9633d2 Fix, regression with Metal buffers (#3715) 2021-03-29 14:20:40 -07:00
Benjamin Doherty 0e7bb53c07 Bump version to 1.9.19 2021-03-29 11:09:32 -07:00
Benjamin Doherty 759109d478 Merge branch 'rc/1.9.18' into release 2021-03-29 11:06:55 -07:00
Benjamin Doherty ff5ecb17ea Update RELEASE_NOTES for 1.9.18 2021-03-29 11:06:35 -07:00
Benjamin Doherty 83ba56d3e7 Release Filament 1.9.18 2021-03-29 11:05:44 -07:00
Benjamin Doherty 54d5af6edf Update RELEASE_NOTES for 1.9.18 2021-03-29 11:04:57 -07:00
Mathias Agopian 2d398c2398 DoF: fix noise radius calculation (#3709)
This small bug was introduced recently with the dynamic kernel size
changes, the noise radius depends on the number of rings in the kernel.
2021-03-29 10:46:34 -07:00
Philip Rideout 38fbe47ced RenderTarget: fix NPE when depth is not present.
This fixes a recent regression that would occur when a RenderTarget
does not have a depth attachment.
2021-03-29 10:32:22 -07:00
Philip Rideout cf070c6bc7 RenderTarget: fix NPE when depth is not present.
This fixes a recent regression that would occur when a RenderTarget
does not have a depth attachment.
2021-03-29 10:31:04 -07:00
Mathias Agopian 3c577b6191 DoF: fix several mediump-related bugs
The gist of it is that we can't always accumulate samples naively, and
we have to use different strategies with different tile types.

For the fast tiles it seems enough to reorder the sum, accumulating each
ring first, and then accumulating that into the output, because all
samples have the same weight.

For the foreground tiles, for some reason I couldn't find any major
issue and I'm not sure why.

For the background tiles, we need to use highp intermediates because
every sample has different magnitudes (weights)
2021-03-29 09:48:51 -07:00
Mathias Agopian acb2da7759 Improvements to Camera APIs (#3701)
* move the focus distance from DofOptions to Camera

The DofOption parameter is now deprecated, but will still work if the
focus distance is not set on Camera.

* A few new helper APIs on Camera

- getFocalLength() which returns the focal length used internally for
  DoF computations.

- computeEffectiveFov() and computeEffectiveFocalLength() which can be
used to better simulate a real camera's FOV changes with the
focus distance.

Modified gltf_viewer so it uses the effective fov/focallendth when
DoF is active.

* simplify setLensProjection

We can call setProjection directly instead of converting to a fov
first, which ends up performing atan(tan(x)).

Also improve parameters names.
2021-03-25 15:22:19 -07:00
Mathias Agopian a0c2edd1a2 DoF: dynamically and conservatively adjust the kernel density per tile
This adjustment is conservative, i.e. we limit the number of rings in
the kernel based on the kernel size in a way that it won't impact the
result. For instance, if the kernel size is 2 or lower, we don't need 4
rings.

This improves performance significantly, especially with large maximum
right counts.
2021-03-25 15:19:57 -07:00
Ben Doherty ad555d897d Expose MaterialInstance APIs that should have been public (#3703) 2021-03-25 11:29:39 -07:00
Mathias Agopian 4a6e62070b DoF: slightly better opacity for the background
We now use the same calculation than for the foreground, this seems
to produce slightly smoother transitions
2021-03-24 22:10:40 -07:00
Mathias Agopian 0c081d4295 DoF: implement fix for foreground opacity
This fixes an issue where objects in-focus show through the blurred
foreground.
2021-03-24 16:22:22 -07:00
Mathias Agopian 04ff2fb806 DoF: shader code refactoring
here we just move the fast/foreground and background tiles processing
into their own function. this is just to make the code more readable.
2021-03-24 16:22:22 -07:00
Philip Rideout 4fb9ee4470 Remove old emscripten workaround from GL backend.
This was put in as a workaround for #2856. I made a fix to emscripten
itself (yay open source) in July. So, this workaround is no longer
necessary.

Verified with the rigged figure model.

https://github.com/emscripten-core/emscripten/pull/11742
2021-03-24 14:58:53 -07:00
Philip Rideout 3d2734b163 Minor Driver API simplification.
As far as I can tell, there is no need for the `enabledAttributes`
argument in `setRenderPrimitiveBuffer`. This helps pave the way for
the upcoming BufferObject API.
2021-03-24 14:31:18 -07:00
Philip Rideout c4a12fe48a Update cgltf to v1.10 2021-03-24 14:31:09 -07:00
Ben Doherty 40b8667aef Fix Metal bug when setGeometryAt is called multiple times (#3693) 2021-03-24 12:42:55 -07:00
Mathias Agopian cb9578327b attempt to improve doxygen formating
fixes: #3692
2021-03-24 12:24:12 -07:00
Mathias Agopian 7b0a8cf2c2 fix JNI setImage and friends buffer size calculation
- setImage() used the width of the texture for calculating the required
  user buffer size, but this was too large when only updating a
  portion of the texture. It would result in a BufferOverFlowException.

- setImage3D() had the opposite problem where it didn't take into
  account the depth of the texture.

- the offset in the user buffer was called "bottom" on the C++ JNI side,
  but it is called "top" on the java and filament side.

Fixes #3685
2021-03-24 12:20:16 -07:00
Philip Rideout 4197afba49 Web site: update Filament in /remote. 2021-03-24 08:24:00 -07:00
Philip Rideout 495fb14b9c Move Camera settings from gltf_viewer to SimpleViewer. 2021-03-24 08:24:00 -07:00
Mathias Agopian 4de1b0de2d DoF: add a "filter" parameter to the DoF settings
Currently the only NONE and MEDIAN are available options, at some 
point we may add a "MAX" option which is cheaper.

There is no real practical uses for this option with these only two
choices, other than for debugging.
2021-03-23 17:27:31 -07:00
Mathias Agopian abcf4010dd DoF: support full-resolution DoF
This is mostly used for debugging and having somewhat of a reference.
Change to the shader are minimal because all CoC values were always
treated as full-resolution. We just need to replace the downsampling
shader by one that just calculates the CoC. And we need to introduce
a CoC scale factor to compute the LOD to use (this was hardcoded
before).

On the C++ side, it's mostly a matter of replacing hardcoded buffer size
scales by a runtime or compile time variable.
2021-03-23 16:12:03 -07:00
Philip Rideout 65928612b1 Add vkshaders to README. 2021-03-23 12:38:50 -07:00
Adrian PerezandMathias Agopian a33c85bdd4 CString can construct from a string_view (#3677)
* CString can construct from a string_view

(string_views lack a null terminator)

* Update libs/utils/src/CString.cpp

Co-authored-by: Mathias Agopian <pixelflinger@gmail.com>
2021-03-23 00:46:18 -07:00
Mathias Agopian 3ec3f222c5 Dof: improve significantly foreground layer
We're implementing the two-layer technique described in
Jimenez DoF paper, where the foreground field is split in two layers, front
and back. In addition we compute accurately the foreground field alpha.

From a performance standpoint, most of the extra work is increased
register pressure and a bit of ALU.
2021-03-22 16:55:40 -07:00
Mathias Agopian e9a43e7344 DoF: code cleanup
- mostly rename variables
2021-03-22 16:55:40 -07:00
Mathias Agopian fc835aebc6 DoF: fix a few small bugs
- foreground in-layer feather was off
- sample weights was off my 2x
2021-03-22 16:55:40 -07:00
Mathias Agopian a3504bd9b6 DoF: make code a bit less confusing
Always store min CoC in the red channel and max Coc in the green
channel for both the CoC and Tiles textures.
(The tiles texture was doing the opposite).
2021-03-22 16:55:40 -07:00
Mathias Agopian 7c604623e6 DoF: code cleanup
Remove the RING_DENSITY variable because it
can't be changed.
2021-03-22 16:55:40 -07:00
Ben Doherty 3d3f19aa71 Enable VSM shadows with shadow multiplier (#3678) 2021-03-22 12:37:07 -07:00
Benjamin Doherty f066c925ba Bump version to 1.9.18 2021-03-22 10:16:34 -07:00
Benjamin Doherty 00f4b45df6 Update RELEASE_NOTES for 1.9.17 2021-03-22 10:16:20 -07:00
Benjamin Doherty 07140cf2fa Release Filament 1.9.17 2021-03-22 10:16:02 -07:00
Benjamin Doherty 994fdf4e1d Merge branch 'rc/1.9.17' into release 2021-03-22 10:12:20 -07:00
Benjamin Doherty 50b50d65e3 Update RELEASE_NOTES for 1.9.17 2021-03-22 10:11:02 -07:00
Romain Guy 28acd0fa6a Update build scripts to match latest AGP and Kotlin 2021-03-19 12:44:25 -07:00
Philip Rideout 0b91f3d785 Add deprecation annotation to Camera. 2021-03-19 11:04:30 -07:00
Mathias Agopian 1bb18f5f0a DoF: fix a bug that caused black dots around the fast tiles
this would happen only when a fast tile had a CoC < 2, because it
would then have an opacity, but we were ignoring it. It's color then
didn't match the color of the surrounding layer and the median filter
would spread a pixel from the surrounding layer into the fast tile.

we simply fix this by (1) generating the alpha/color for fast tiles,
which is easy to do and on the combine pass, skip the fast tile 
combine when the tile has a an opacity.
2021-03-18 14:57:46 -07:00
Mathias Agopian 2e1d88caae DoF: always apply the correct sample weight
before we were not doing that because it caused some aliasing
artifacts with mipmapping, however it turns out that there are artifacts
anyways, and using the proper weights actually reduces the most severe
ones.

the artifacts are due -- it seems -- to the low density of the kernel.
2021-03-18 14:57:46 -07:00
Mathias Agopian a59f4dd3fc DoF: minor optimizations
we can refactor the code to get rid off the call to mergeRings() for 
the first ring, and we don't need to initialize the current bucket
either.
2021-03-18 14:57:46 -07:00
Mathias Agopian 0aaa985649 Fix a hang in JobSystem
The hang was caused by a subtle race. When a job is completed, its 
thread must signal all the threads that might be waiting on this job.
The signaling code was attempting to signal only the minimum number
of threads -- this was important especially in the case where no threads
were waiting, then the call to notify() could be avoided.

Unfortunately, for performance reasons we're not calling notify() with
the condition lock held, this meant that between the time the number of 
waiting threads was latched and the time of the notify() call, more
threads could enter their condition variable wait(), and it would
then be possible for these threads to wake up, instead of the thread
we were trying to wake up (the one waiting on the job).

It would then get stuck forever.

This bug was introduced in 2df639133b


Also add some debugging code for this kind of failure (disabled)
2021-03-18 09:57:25 -07:00
prewettg 46b356cb2c Fix blanking windows not being drawn into on macOS (#3616)
* Fix blanking windows not being drawn into on macOS

* Refactored to create swap chain info object; added fixes for resizing; added sample.

* CocoaGLSwapChain should inherit from Platform::SwapChain

* Link to SDL directly for multiple_windows example

* SDL apparently redefines main to SDL_main and requires C++ linkage

* Fix main to have SDL-approved signature
2021-03-18 09:49:20 -07:00
Philip Rideout a20ae75d11 gltfio: Add support for data:// in image URI's. (#3662) 2021-03-17 17:57:41 -07:00
Philip Rideout 8d78b1f2e1 gltfio: Add internal MorphHelper, enable up to 255 targets. (#3661)
* gltfio: Add internal MorphHelper, enable up to 255 targets.

Previously, gltfio could not animate models with more than 4 morph
targets. Now we can handle up to 255 targets, as long as no more than
4 targets are ever used simultaneously. This allows us to handle
many more models, such as those exported by Modo, and the horse model
in #1852.

We do this by picking the highest 4 weights. The indices for these
weights are called the "primary indices", and we construct a new
VertexBuffer for each unique set of primary indices.

In the near future this will be made more efficient by adding a new
VertexBuffer API to the Filament core.

Fixes #1487.

* Code review fixups.
2021-03-17 15:52:24 -07:00
Ben Doherty 9030abaa89 Fix RenderTarget slice bug (#3656) 2021-03-17 15:47:31 -07:00
Mathias Agopian e8b16d600e Fix a hang in JobSystem
The hang was caused by a subtle race. When a job is completed, its 
thread must signal all the threads that might be waiting on this job.
The signaling code was attempting to signal only the minimum number
of threads -- this was important especially in the case where no threads
were waiting, then the call to notify() could be avoided.

Unfortunately, for performance reasons we're not calling notify() with
the condition lock held, this meant that between the time the number of 
waiting threads was latched and the time of the notify() call, more
threads could enter their condition variable wait(), and it would
then be possible for these threads to wake up, instead of the thread
we were trying to wake up (the one waiting on the job).

It would then get stuck forever.

This bug was introduced in 2df639133b


Also add some debugging code for this kind of failure (disabled)
2021-03-17 13:44:30 -07:00
Benjamin Doherty 24121a4734 Fix typo with Metal createRenderTarget 2021-03-17 10:29:07 -07:00
Philip Rideout 6eabe0491c gltfio: Refactor Animator.
This does not change any behavior, it just prepares for the upcoming
MorphHelper class.
2021-03-17 07:38:00 -07:00
Philip Rideout 20b0972130 gltfio: Refactor the tangents job.
This cleans up the glTF tangents generator and allows it to be used
in other parts of the library.
2021-03-16 16:43:02 -07:00
Mathias Agopian 98da09b247 fix rendertarget sample app
we can't use a projection with infinite far as a custom
projection matrix, because this is not suited for culling.

recently a new version of setCustomProjection was added which allows
to specify both the rendering and culling projections.
2021-03-16 16:09:14 -07:00
Mathias Agopian cc13420e31 add missing includes
Should fix #3633
2021-03-15 22:45:31 -07:00
Benjamin Doherty 29564f8eae Bump version to 1.9.17 2021-03-15 10:15:25 -07:00
Benjamin Doherty c15db68a5b Merge branch 'rc/1.9.16' into release 2021-03-15 10:12:56 -07:00
Benjamin Doherty fd55da0319 Update RELEASE_NOTES for 1.9.16 2021-03-15 10:12:24 -07:00
Benjamin Doherty 240d9d0919 Release Filament 1.9.16 2021-03-15 10:11:11 -07:00
Benjamin Doherty 3452fb3e56 Update RELEASE_NOTES for 1.9.16 2021-03-15 10:10:40 -07:00
Mathias Agopian 41634a301e demangle callstacks in debug builds (unixes only)
This requires dladdr() and __cxa_demangle().
2021-03-13 23:22:01 -08:00
Philip Rideout cf75b11cba Add missing deprecated annotations. 2021-03-12 13:33:14 -08:00
Philip Rideout 81bba4644a Remove unused imports. 2021-03-12 13:07:29 -08:00
Mathias Agopian 35eb8e7be1 Revert GL backend handle tracking
This wasn't very useful in the first place because we're recycling
handles very quickly. Additionally there was a race condition
which cause false positives.

This reverts commit bc6acd5c5a.
This reverts commit 3a15756c78.
2021-03-12 13:02:55 -08:00
Mathias Agopian f7e92b0ee3 Revert GL backend handle tracking
This wasn't very useful in the first place because we're recycling
handles very quickly. Additionally there was a race condition
which cause false positives.

This reverts commit bc6acd5c5a.
This reverts commit 3a15756c78.
2021-03-12 12:57:03 -08:00
Mathias Agopian 1e58fd4842 minor jobsystem fixes
- one version of run() ignored the flags parameter
- don't immediately signal created jobs in froxelizer
  to avoid redundant calls to signal()
2021-03-12 11:47:28 -08:00
Ben Doherty fa7ad8d867 Fix dominant light shadows in Metal and Vulkan (#3631) 2021-03-12 10:08:33 -08:00
Mathias Agopian 834b774128 Fixes some issues with imported rendertargets
We were not declaring the attachments it was using.

Fixes #3628
2021-03-12 08:26:16 -08:00
Philip Rideout eb40fa753f gltfio: Fix tangents when morphing is enabled.
The vertex data for glTF morph targets are deltas rather than final
values, so we were passing incorrect data into the SurfaceOrientation
helper.

This has been a long-standing bug that affected models with morphing,
including Buster Drone. However in practice we have observed visual
issues only with AnimatedMorphCube.

Tested against AnimatedMorphCube, Buster Drone, Cesium Man, Fox, and
Littlest Tokyo.

Fixes #1609
2021-03-11 14:09:52 -08:00
Mathias Agopian dc36b228d6 Fixes some issues with imported rendertargets
We were not declaring the attachments it was using.

Fixes #3628
2021-03-11 14:06:26 -08:00
Philip Rideout 11e3eff009 Update TypeScript bindings. 2021-03-11 10:28:44 -08:00
Philip Rideout 52abe75cfd RemoteServer code cleanup and logcat cleanup.
This fixes two different logcat messages that would occur when scrubbing
a slider in the UI:

- "Discarding message, message queue overflow."
- "Downloading model..." would repeat itself needlessly
2021-03-11 07:52:32 -08:00
Romain Guy 8065d18f54 Update release notes 2021-03-10 16:15:18 -08:00
Philip Rideout 1b3684933d Repair WebGL build. 2021-03-10 16:01:29 -08:00
Mathias Agopian e657921b5a Camera API improvements
- Add a "shift" parameter to Camera. This has the effect of translating
  the viewport, without changing its size. 
  This is an effect similar to using a shift lens.

- Camera::setScaling() now takes a double2 instead of double4, this is
  because scaling the result of the projection in the Z direction 
  can lead to very confusing problems -- it will essentially move the
  near/far planes, and we don't want to expose that as a public API.

- setCustomProjection() now allows to set a different projection for
  rendering and culling (useful for e.g. for using an infinite far 
  rendering projection matrix).
2021-03-10 16:01:29 -08:00
Seth Vargo 91ce5c785b Improve Actions hygiene (#3630)
Only run GitHub Actions for pushes and PRs against the main branch of the repository.
2021-03-10 15:02:16 -08:00
Philip Rideout 676b0542c4 sample-gltf-viewer: fix ColorGrading JNI assert 2021-03-10 11:14:31 -08:00
Philip Rideout dced766999 Update Remote Control page. 2021-03-10 10:51:19 -08:00
Philip Rideout eb0b5d16bf Migrate ColorGrading to SimpleViewer. 2021-03-10 09:27:51 -08:00
Mathias Agopian 2845f37ac7 improve CoC computation comment 2021-03-09 22:21:28 -08:00
Mathias Agopian 922ce83f48 add the --split-view option to gltf_viewer
useful for debugging shadows problems
2021-03-09 10:48:23 -08:00
Mathias Agopian 7445d80202 Improve circle-of-confusion computation
- generously document the CoC computation

- rewrite the code so that the computation will work for any
  perspective projection matrix, instead of assuming
  an "infinite-far" projection.
2021-03-09 10:48:08 -08:00
Philip Rideout 4d6f3ad392 JsonSerializer: do not repeatedly re-construct ostringstream. 2021-03-08 15:13:01 -08:00
Philip Rideout c4ac8a9f06 AutomationEngine can now be used as a remote control. 2021-03-08 10:32:06 -08:00
Philip Rideout b554a68186 Remote page now has UI and pushes settings. 2021-03-08 10:32:06 -08:00
Philip Rideout b7ad20249d Improve the Settings serialization API, expose to JS.
This not only makes it easier to expose to JavaScript, it also paves the
way for a much more efficient implementation.
2021-03-08 10:32:06 -08:00
Philip Rideout 65f4b600bc Polish up the Remote Control page. 2021-03-08 10:32:06 -08:00
Philip Rideout 03945b88c8 ImGuiHelper now manages the UI camera. 2021-03-08 10:32:06 -08:00
Philip Rideout 24583332a2 Add filagui and SimpleViewer to the WASM build. 2021-03-08 10:32:06 -08:00
Benjamin Doherty 5aa0eb9f9d Bump version to 1.9.16 2021-03-08 10:09:14 -08:00
Benjamin Doherty d9a6e2e649 Merge branch 'rc/1.9.15' into release 2021-03-08 10:07:00 -08:00
Benjamin Doherty ce26801a91 Update RELEASE_NOTES for 1.9.15 2021-03-08 10:06:30 -08:00
Benjamin Doherty 7fd5b65f3b Release Filament 1.9.15 2021-03-08 10:05:56 -08:00
Benjamin Doherty cb823b16a1 Update RELEASE_NOTES for 1.9.15 2021-03-08 10:05:19 -08:00
Philip Rideout 61b1542468 Add new remote page to site. 2021-03-08 08:57:57 -08:00
Mathias Agopian d740378277 More code size optimizations and bvecn fixes
MaterialInstance: generate versions of setParameter() methods that
are templated on the parameter sizeof(), which allows us to
coalesce implementations, e.g. vec4<float> and vec4<int> are now
the same. We make the compiler generate non-inline version of all
these methods, the typed version just call through, taking
advantage of the tail-call optimization in clang.


MaterialParser: improve code to avoid calling multiple methods that
all did more or less the same thing and were inlined.

PostProcessManager: use a loop to initialize the materials

ToneMapping: de-dup ACES implementation

And other more minor optimizations.


Fix alignment issues with setting booleans in UBOs
2021-03-05 10:59:30 -08:00
Philip Rideout 0815adf722 PostProcessManager: fix setMinMaxLevels for StructureMipmap. 2021-03-05 08:15:04 -08:00
Philip Rideout ef1eacf22e PostProcessManager: fix setMinMaxLevels for StructureMipmap. 2021-03-05 08:15:04 -08:00
Benjamin Doherty fc896f81f0 Fix broken filamat lite build 2021-03-04 10:09:26 -08:00
Ben Doherty 884d5c1b87 Make material compilation deterministic (#3610)
With multithreaded variant compilation, compiled materials differ based on which variants finish first. This change ensures that compiled materials are always bit-for-bit identical.

This is helpful when comparing two compiled materials. Hashing the material files can be used to check for equality. It's also convenient for variants to occupy the same index when using matinfo's --print-glsl flag, for example.
2021-03-03 16:55:35 -08:00
Romain Guy 627186abc8 Update incorrect documentation (#3608) 2021-03-03 14:42:47 -08:00
Philip Rideout 30b0f39a36 sample-gltf-viewer: add polish to the drag-and-drop feature. 2021-03-03 14:41:22 -08:00
Philip Rideout c3c2a732cd gltfio: Add ResourceLoader evict API. 2021-03-03 14:41:22 -08:00
Philip Rideout 5cc8ebd3e1 gltfio: fix ResourceLoader cache bug. 2021-03-03 14:41:22 -08:00
Philip Rideout 9ceb3b016c sample-gltf-viewer: add drag-and-drop feature.
This adds a WebSockets server to filament-utils-android.

Unlike my first attempt (#3599), this does not use a piping server and
is therefore much faster to use over a LAN. It also has lower user
friction because there is no need to touch a button in the app or
scan a QR code.
2021-03-03 14:41:22 -08:00
Philip Rideout 76e18475d3 gltf_viewer: avoid writeJson when automation is off. 2021-03-03 12:10:42 -08:00
Philip Rideout 2964e99175 sample-gltf-viewer: add URL hint. 2021-03-03 12:10:42 -08:00
Mathias Agopian 1189c9e294 FrameGraph rewrite from the ground up
The main goal of this rewrite was to make the code
simpler and easier to maintain.

The API is mostly unchanged, however there are some differences.
- we now have the concept of subresources, e.g. for Textures, as
  subresource is a mip level or layer.
- RenderTargets are no longer resources, instead they are transiant
  objects associated to a pass and are now called RenderPasses.
- RenderPasses take subresources for attachments.
- We have better validation of graph building.

We should also compute discard flags more accurately.
2021-03-02 22:25:56 -08:00
Philip Rideout 50799f3760 Replace QR code page with something better. 2021-03-02 18:36:38 -08:00
Philip Rideout 4b580b6eb1 Add automation to Android build, change PNG to PPM.
This adds libs/viewer to filament-utils-android and provides JNI
bindings for AutomationEngine.

This commit also changes the AutomationEngine to use PPM for screenshots
rather than PNG. The reasoning is that it is wasteful to include stb and
our two image-related libraries just to dump screenshots, especially for
a feature we might not use on Android.
2021-03-02 10:41:06 -08:00
Ben Doherty 8d6e794486 Remove exceptions on iOS (#3600) 2021-03-02 10:38:19 -08:00
Ben Doherty 0bd41e877e Downgrade Linux GitHub Actions environment to fix error (#3588) 2021-03-01 11:21:11 -08:00
Benjamin Doherty ecc3e73967 Bump version to 1.9.15 2021-03-01 11:13:44 -08:00
Benjamin Doherty 464b4c24f9 Merge branch 'rc/1.9.14' into release 2021-03-01 11:11:53 -08:00
Benjamin Doherty 7fa2053c55 Update RELEASE_NOTES for 1.9.14 2021-03-01 11:11:15 -08:00
Benjamin Doherty cb7f81ccd6 Release Filament 1.9.14 2021-03-01 11:10:46 -08:00
Benjamin Doherty 32367516e8 Update RELEASE_NOTES for 1.9.14 2021-03-01 11:10:06 -08:00
Philip Rideout 6227496478 Update MoltenVK to 1.1.2 2021-03-01 09:42:23 -08:00
Philip Rideout 74aa7d3c87 Add QRCode page for glTF files. 2021-02-28 17:59:53 -08:00
Ben Doherty bc107e7def Downgrade Linux GitHub Actions environment to fix error (#3588) 2021-02-26 17:00:56 -08:00
Ben Doherty 09e05ae00d Label Metal render encoders with group markers (#3583) 2021-02-26 10:37:34 -08:00
Philip Rideout 1709a55606 filamat: Fix data race with SPIRV error registrations. 2021-02-26 10:34:36 -08:00
Philip Rideout 1921536f90 filamat: Fix data race with SPIRV error registrations. 2021-02-24 10:17:51 -08:00
Philip Rideout 1a9334e818 Modernize Python print syntax. 2021-02-23 14:43:30 -08:00
Mathias Agopian bc6acd5c5a GL backend: fix race condition when asserting a handle exists 2021-02-22 23:25:43 -08:00
Mathias Agopian 3a15756c78 GL backend: track handles lifetime in debug builds 2021-02-22 17:22:18 -08:00
Mathias Agopian f1fd96983b assert_invariant() now terminates the program in failure
rename logAndPanic to panicLog, since it doesn't actually panics.
2021-02-22 14:57:41 -08:00
Benjamin Doherty 58b4455979 Bump version to 1.9.14 2021-02-22 10:32:56 -08:00
Benjamin Doherty ea1dede19c Merge branch 'rc/1.9.13' into release 2021-02-22 10:29:57 -08:00
Benjamin Doherty 1f000bd10d Update RELEASE_NOTES for 1.9.13 2021-02-22 10:29:30 -08:00
Benjamin Doherty ce2c49217f Release Filament 1.9.13 2021-02-22 10:29:02 -08:00
Benjamin Doherty 20ea3381fa Update RELEASE_NOTES for 1.9.13 2021-02-22 10:28:21 -08:00
Philip Rideout ec9640695c Provide a docstring for the Stream class.
Mathias noticed that the `setAcquiredImage` method was not well
documented on the C++ side. While fixing this I figured I'd try to write
up a docstring for the class itself.
2021-02-22 10:15:01 -08:00
Romain Guy f2ed3480d8 Attempt at improving bloom/emissive with glTF files (#3560)
* Attempt at improving bloom/emissive with glTF files

* Publicly expose Exposure API for gltfio
2021-02-22 09:40:31 -08:00
Romain Guy 5d9384fca7 Fix docs typos 2021-02-20 16:43:12 -08:00
Romain Guy 22d16c1910 Fix typo in docs 2021-02-19 12:04:45 -08:00
Philip Rideout 7aa6fccd7c Modernize Python print syntax to appease external codebase. 2021-02-19 11:38:18 -08:00
Philip Rideout adbd54f4f8 Change abs() to std::abs to appease external codebase. 2021-02-19 11:38:18 -08:00
Philip Rideout 9d54261f18 Move vk_mem_alloc to its own cpp.
This will improve parity between the GitHub repo and its sister codebase
within Google.
2021-02-19 11:38:18 -08:00
Philip Rideout a97757c9ae Avoid uninitialized reads in computeVisibilityMasks.
I verified that this code is not enabled in our GitHub builds, and I
verified that the MSAN error goes away.
2021-02-19 11:38:18 -08:00
Philip Rideout 7c79d9f89d Remove some Windows line endings.
These line endings cause annoying diffs when comparing Filament's GitHub
source with its twin sister within Google.
2021-02-19 11:38:18 -08:00
Philip Rideout 20dadf06f1 Modernize Python print syntax to appease external codebase. 2021-02-18 13:31:02 -08:00
Romain Guy b3a4788e56 Fix doc warning 2021-02-17 15:05:45 -08:00
Philip Rideout 811e7c59cf Change abs() to std::abs to appease external codebase. 2021-02-17 14:45:17 -08:00
Philip Rideout be22360903 Move vk_mem_alloc to its own cpp.
This will improve parity between the GitHub repo and its sister codebase
within Google.
2021-02-17 14:40:19 -08:00
Philip Rideout 2b68665cd8 Avoid uninitialized reads in computeVisibilityMasks.
I verified that this code is not enabled in our GitHub builds, and I
verified that the MSAN error goes away.
2021-02-17 14:33:56 -08:00
Philip Rideout 6297ef9193 Remove some Windows line endings.
These line endings cause annoying diffs when comparing Filament's GitHub
source with its twin sister within Google.
2021-02-17 10:11:22 -08:00
Mathias Agopian 68e99240d0 don't use assert() inside filament
assert() is now replaced by assert_invariant() which has the same
prototype and (currently) behaves the same than assert().

<assert.h> should not be used anymore, and is replaced by 
<utils/debug.h>, which is where assert_invariant() is found.

The main motivation for this is to be able to set a breakpoint on the
assertion as lldb doesn't handle abort() very well, and doesn't
permit to inspect the stack trace.

A secondary motivation is to be able (at some point) to enable 
assertions without necessarily doing a debug build.
2021-02-16 20:30:04 -08:00
Benjamin Doherty bf0914f813 Bump version to 1.9.13 2021-02-16 10:48:24 -08:00
Benjamin Doherty b96bc30fbd Merge branch 'rc/1.9.12' into release 2021-02-16 10:44:13 -08:00
Benjamin Doherty 7bf04e1f71 Update RELEASE_NOTES for 1.9.12 2021-02-16 10:43:46 -08:00
Benjamin Doherty 939f3b975c Release Filament 1.9.12 2021-02-16 10:43:06 -08:00
Benjamin Doherty 62b50eb8ba Update RELEASE_NOTES for 1.9.12 2021-02-16 10:42:41 -08:00
Romain Guy e247ffad9b Correctly name JNI methods so they can be found (#3539) 2021-02-16 10:07:42 -08:00
Philip Rideout fb29ae9fa5 Add MSAA resolve (color and depth) to the blit test. 2021-02-16 08:05:11 -08:00
Philip Rideout 706a685ca6 Add a depth blit to the unit test.
Since we cannot upload a depth buffer, this test works by first drawing
a triangle into COLOR + DEPTH, copying them both to a new render target,
then drawing a slightly larger triangle just underneath the first one.
2021-02-12 17:20:30 -08:00
Romain Guy 4ad947f0ad Update docs 2021-02-12 10:54:54 -08:00
Philip Rideout a1939189ea Code cleanup for test_Blit. 2021-02-12 10:34:59 -08:00
Philip Rideout fe49c1eb82 Add backend unit test for blit.
This is fairly simple for now, only does color.
Will enhance in a future PR.
2021-02-12 10:34:59 -08:00
Philip Rideout 4d18c0d61c BlueVK: use slog for dlopen error message. 2021-02-11 12:51:40 -08:00
Philip Rideout 6fa8f48be5 BlueVK: optionally consult environment variable.
One of Filament's Linux clients at Google wishes to specify a special
path to the SwiftShader library that proffers Vulkan entry points, and
this path can only be determined at run time.

An environment variable seems like the easiest way to support this
functionality. To prevent a security hazard, the env var is checked only
if a special build-time flag is enabled.
2021-02-11 12:51:40 -08:00
Philip Rideout ba32cef717 Vulkan: conform to PORTABILITY_SUBSET for Molten.
According to the portability spec: "If this extension is supported by
the Vulkan implementation, the application must enable this extension."

On my 2019 MacBook, enabling this extension triggers errors relating to
depth comparison samplers which I believe to be bogus, so I filed a
LunarG bug. For now we silence this specific error message.
2021-02-11 12:51:24 -08:00
Ben Doherty e6d3d26c6b Fix, computeDataSize returns incorrect value for USHORT_565 (#3530) 2021-02-10 16:35:39 -08:00
Romain Guy 180cf24b58 Update cgltf to latest 2021-02-10 13:22:17 -08:00
Philip Rideout 0f9cee0b83 Update WebGL demos on website.
This includes an important fix for Chrome on Windows, which does not
support RGB16F.
2021-02-09 11:41:09 -08:00
Romain Guy 317c82711b Improve docs generation (#3527)
build.sh -w now performs a full install of dependencies instead
of relying on local installation tricks.
2021-02-09 11:40:02 -08:00
Ben Doherty 3f32146849 Fix Android compilation error in UbershaderLoader (#3526) 2021-02-09 10:50:19 -08:00
Romain Guy 9da69dac46 Update documentation 2021-02-09 10:43:49 -08:00
Ben Doherty b4932e384a matc: Use consistent params for semantic code analysis (#3524)
When running semantic analysis on a material, we were arbitrarily choosing the first code gen permutation to analyze. So, running matc with arguments --api metal versus --api all would run analysis on slightly different shader code. This causes bugs when flags passed to glslang differ during semantic analysis. This change updates all semantic analysis to always use the same shader code.
2021-02-08 14:06:47 -08:00
Ben Doherty 1516b135fd matc: Use consistent params for semantic code analysis (#3524)
When running semantic analysis on a material, we were arbitrarily choosing the first code gen permutation to analyze. So, running matc with arguments --api metal versus --api all would run analysis on slightly different shader code. This causes bugs when flags passed to glslang differ during semantic analysis. This change updates all semantic analysis to always use the same shader code.
2021-02-08 14:06:11 -08:00
Philip Rideout 06538145b5 Vulkan: implement setMinMaxLevels, refactor VulkanTexture. 2021-02-08 13:33:25 -08:00
Philip Rideout ec486b888c PostProcessManager: call setMinMaxLevels in more places.
This fixes some OpenGL non-compliance (as per "Rendering Feedback
Loops" in the spec), as well as validation errors with Vulkan.

I'm hopeful this can be automatic in the new frame graph. :)
2021-02-08 13:33:02 -08:00
Philip Rideout 7b7d63a91f Fix ubershader regression with Transmission / Sheen. 2021-02-08 13:04:25 -08:00
Philip Rideout 466629d967 Ignore VK_KHR_portability_subset for now.
This is a temporary workaround to allow running validation with MoltenVK
even though we do not conform to the portability subset.
2021-02-08 12:24:02 -08:00
Benjamin Doherty 5e68dc5f8d Bump version to 1.9.12 2021-02-08 09:58:15 -08:00
Ben Doherty c4d0dcf639 Update RELEASE_NOTES for 1.9.11 2021-02-08 09:54:27 -08:00
Benjamin Doherty ad90fa1183 Release Filament 1.9.11 2021-02-08 09:54:27 -08:00
Philip Rideout ed57d6a40f Vulkan: fix lifetime issue with image views.
This prevents an "Invalid VkImageView Object" error that would occur
after disabling bloom.

This was caused by the fact that we do not bother zeroing out all the
descriptor slots that are not used by the current draw call.
2021-02-08 09:53:42 -08:00
Benjamin Doherty f222f1b925 Merge branch 'rc/1.9.11' into release 2021-02-08 09:51:08 -08:00
Ben Doherty 22e4a54782 Update RELEASE_NOTES for 1.9.11 2021-02-08 09:50:23 -08:00
Benjamin Doherty 1289922c5f Release Filament 1.9.11 2021-02-08 09:48:50 -08:00
Ben Doherty 2839c352b8 Update RELEASE_NOTES for 1.9.11 2021-02-08 09:47:18 -08:00
Ben Doherty 6a01cbc312 Draft: fix TSAN issue by using lock in ColorGrading constructor (#3510)
This is a second attempt to fix Google3 TSAN failures seen inside of the ColorGrading constructor.

Related first attempt: #3462
2021-02-05 14:06:40 -08:00
Ben Doherty 00f50c5f5a Draft: fix TSAN issue by using lock in ColorGrading constructor (#3510)
This is a second attempt to fix Google3 TSAN failures seen inside of the ColorGrading constructor.

Related first attempt: #3462
2021-02-05 14:05:21 -08:00
Philip Rideout 23c90a624d RenderTarget demo should create depth attachment.
This "fixes" #3501, which was not really a bug.  (doh)
2021-02-05 11:21:06 -08:00
Philip Rideout 0e27f0c162 RenderTarget demo now disables post-processing in offscreen view.
The color now match up perfectly.  Woops.

(#3402)
2021-02-05 11:21:06 -08:00
Philip Rideout 297f3d9808 Fix logcat spam with ubershaders.
Since the ubershader does not have variants for clear coat, the dummy
texture there should be unconditional.
2021-02-05 09:07:58 -08:00
Philip Rideout b4f6400d2e Do not exclude Vulkan from continuous Android CI. 2021-02-05 09:07:27 -08:00
Philip Rideout 4d905eb4bb Repair Vulkan-enabled Android builds.
We should probably change our continuous CI so that it does not
exclude Vulkan, but keep our release CI as is (for small binaries).

Fixes #3505
2021-02-05 08:41:39 -08:00
Philip Rideout 83a58033d1 Re-enable optimal bloom on Intel GPUs. 2021-02-05 08:38:29 -08:00
Philip Rideout edc8162ebb PostProcessManager Bloom: fix call to setMinMaxLevels.
This was being called on the wrong texture.
2021-02-05 08:38:29 -08:00
Romain Guy da2c9b8092 Fix doc typo 2021-02-04 14:47:22 -08:00
Romain Guy 2cf3fb569a Update Kotlin to 1.4.30 2021-02-04 14:42:50 -08:00
Benjamin Doherty 0c6de2cb58 Update RELEASE_NOTES 2021-02-04 12:47:53 -08:00
Ben Doherty 07ddd52dcf Add getVertexIndex API for vertex shaders (#3493) 2021-02-04 12:40:21 -08:00
Philip Rideout f6425fdcfb VulkanBlitter progress. 2021-02-03 17:59:59 -08:00
Philip Rideout 521c7fc713 Restore "magic resolve" as per code review. 2021-02-03 17:56:01 -08:00
Philip Rideout 3175711323 Fix MSAA for OpenGL ES 3.0 core.
This fixes `GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE` caused by the
following spec clause being violated:

```
The value of RENDERBUFFER_SAMPLES [must be] the same for all
attached renderbuffers and, if the attached images are a mix of
renderbuffers and textures, the value of RENDERBUFFER_SAMPLES
is zero.
```

Tested on Chrome with Triangle and Helmet demos (after enabling MSAA).
Also tried running the automation suite in a debug build on macOS.

Fixes #3128.
2021-02-03 17:56:01 -08:00
Philip Rideout d669b1b26f Add null terminator to fix Windows build. 2021-02-03 14:56:34 -08:00
Philip Rideout c2b4b6347e matc: add --raw argument for internal use.
This feature can generate SPIRV blobs and will be used by VulkanBlitter.

(#3485)
2021-02-03 14:56:34 -08:00
Philip Rideout 8d13b7634c Upgrade MoltenVK. 2021-02-03 09:54:19 -08:00
Philip Rideout 89bf201b6c Refactoring: Add VulkanBlitter, inspired by MetalBlitter.
This is a prep step to fix #3485.
2021-02-03 08:13:21 -08:00
Philip Rideout 9f68daeb8f Remove unused sampler params. 2021-02-02 10:51:16 -08:00
Philip Rideout c62b88013b Add setMinMaxLevels to DriverAPI.
This adds setMinMaxLevels to the DriverAPI and calls it from
PostProcessManager and the new unit test. The allows us to be compliant
to the OpenGL specification. The new unit test now looks much better on
Intel GPUs. Chrome still gives an INVALID_OPERATION.

Unfortunately the actual bloom effect still has issues on my Intel GPU,
even though the test passes. So, we need to keep the ping-pong
implementation both for Chrome and for Intel.
2021-02-02 10:51:16 -08:00
Philip Rideout 2e8df10e6e Quaternion slerp: ensure "short path" when falling back to lerp.
I noticed that our slerp function sometimes produces a jolt in
animation, but only when the time delta is very small, and only when the
two operands have completely opposing signs.

For example, let's say you are slerping from <0.76, 0.39, 0.51, 0.19>
to <-0.72, -0.45, -0.49, -0.17>.

These quats are actually quite near to each other because the total
negation of the second quat is similar to the first quat.

We were already doing the short path check in the proper slerp path, but
not when falling back to lerp due to a small angle.
2021-02-01 14:35:05 -08:00
Romain Guy 2f9c310127 Update RELEASE_NOTES.md 2021-02-01 14:24:02 -08:00
Benjamin Doherty 6193156556 Bump version to 1.9.11 2021-02-01 11:49:12 -08:00
Benjamin Doherty fe23aa917d Merge branch 'rc/1.9.10' into release 2021-02-01 11:45:47 -08:00
Benjamin Doherty eb8a29a332 Update RELEASE_NOTES for 1.9.10 2021-02-01 11:45:17 -08:00
Benjamin Doherty 6eec2cde81 Release Filament 1.9.10 2021-02-01 11:44:33 -08:00
Philip Rideout 98ae61ffe5 gltfio: Fix "_maskThreshold not found" error.
MaterialGenerator selects a custom blend mode for transmissive models,
therefore the AssetLoader should look at the material's blend mode when
it sets up properties, not the one requested by the glTF file.

Fixes #3444.
2021-02-01 09:52:06 -08:00
Romain Guy adb489c77a Compile Android libraries with fPIC (#3473)
* Compile Android libraries with fPIC

* Rmove warning
2021-01-29 15:23:34 -08:00
Philip Rideout eeccfed8e4 Rewrite and enhance test_FeedbackLoops.
Previously this test was actually finding a ReadPixels failure on Intel
GPU's, rather than a failure of feedback loop behavior. This was due to
the fact that it was calling ReadPixels on a non-zero miplevel, which
seems to be unsupported on Intel GPU's.

The test now follows the downsample phase with an upsample phase, just
like the real bloom effect. This allows us to issue ReadPixels on the
base level, thus making the test more targetted to rendering feedback
loops.
2021-01-29 15:06:57 -08:00
Philip Rideout 893ed861e9 gltfio on Java: free material cache in AssetLoader#destroy
Fixes #3469
2021-01-29 14:42:54 -08:00
Romain Guy 411ae23512 Update Kotlin, Gradle and NDK dependencies (#3470)
* Update Kotlin, Gradle and NDK dependencies

* Update CI build
2021-01-29 12:09:08 -08:00
Romain Guy 8f05984551 Update release notes 2021-01-29 09:31:36 -08:00
Romain GuyandPhilip Rideout 4567b01c1d Multi-thread shaders generation when compiling materials (#3464)
* Stop using members as globals between methods

* Multi-thread shaders generation with JobSystem

* Pass JobSystem to MaterialBuilder::build()

* Fix MeshAssimp to use the new API

* Allow the Java API to pass a job system via Engine

* Update docs

* Apply suggestions from code review

Co-authored-by: Philip Rideout <philiprideout@gmail.com>
2021-01-29 09:30:37 -08:00
Philip Rideout 29315f9a1b gltfio: fix crash during async texture decode.
Recall that we now use shared_ptr to simplify lifetime management of
cgltf source data (#3413).

Before this commit, we were only using shared_ptr to retain the source
data during buffer uploads. After this commit, we are using it to retain
source data during texture decoding.

Fixes #3428.
2021-01-29 09:06:32 -08:00
Ben Doherty 0626902530 Fix sporatic data race warning seen in Google3 (#3462) 2021-01-27 16:40:16 -08:00
Ben Doherty d4a2d30a1c Fix sporatic data race warning seen in Google3 (#3462) 2021-01-27 16:38:38 -08:00
Philip Rideout cec5f3e988 gltfio: disable shader optimizations by default
Note that ubershaders (which are always used on Android and WebGL) are
still optimized by default.
2021-01-27 11:40:51 -08:00
Romain Guy 02501c6e60 Modulate emissive by alpha on blended objects (#3459)
This prevents light from being emitted from completely
transparent pixels.
2021-01-26 16:35:49 -08:00
Ben Doherty 4d8da14c1f Update universal library option in build.sh for Apple silicon (#3458) 2021-01-26 16:34:46 -08:00
Philip Rideout 4fae917fb5 Introduce optional ping-ping bloom implementation.
Second attempt after abandoning #3451.

Feedback loops do not work with Chrome or Intel GPU's, so we now have an
optional ping-pong implementation of Bloom.

Issue #2338.
2021-01-26 15:08:39 -08:00
Philip Rideout c84036c8c4 Update JavaScript bindings and demo to prep for Bloom workaround. 2021-01-26 13:18:03 -08:00
Philip Rideout 34429f5490 Add unit test for feedback loops.
This test passes on my Radeon GPU MacBook but fails with an Intel GPU.
2021-01-26 13:12:46 -08:00
Philip Rideout 59c2d5bef3 Plumbing for disabling feedback loops on Intel.
This is a follow-on to #3451, which adds optional ping-pong support to
the bloom generator.
2021-01-26 13:12:24 -08:00
Ben Doherty a3412c4f45 Remove shadow cascade visualization from unlit variants (#3455) 2021-01-26 11:20:54 -08:00
Philip Rideout 564d846be5 Repair backend unit tests on macOS.
This fixes "illegal hardware instruction" seen on my MacBook, which
is the same as #1839, but triggered only in a test environment where
the main thread is the same as the driver thread, and filament is built
with HAS_THREADING enabled.
2021-01-26 08:57:16 -08:00
Romain Guy 41186340c9 Change visibility of a few color grading options 2021-01-25 08:49:25 -08:00
Ben Doherty 96bba71739 Update combine-static-libs.sh script to work with universal binaries (#3447) 2021-01-22 15:57:43 -08:00
Adrian PerezandMathias Agopian 5ab7a9e3ab Add swap() methods to Allocator.h (#3445)
* Add swap() methods to Allocator.h

This allows StructureOfArraysBase's move constructor to compile.
Removed an apparent workaround in SingleInstanceComponentManager.

* swap can be noexcept

* Add swap() methods to Allocator.h

This allows StructureOfArraysBase's move constructor to compile.

Co-authored-by: Mathias Agopian <pixelflinger@gmail.com>
2021-01-22 15:45:20 -08:00
Mathias Agopian 4c30067dac fix missing froxel
Fix a possible out-of-bound access when reading the x-planes array. 
Also account for the fact that the loops filling the froxels assume
stl-like iterators (1-past the end on the right), while the indices
themselves were right-inclusive.

fixes #3142
2021-01-19 17:31:43 -08:00
Philip Rideout 243ba77025 gltfio: support animation in dynamically-added instances.
I tested this by viewing CesiumMan with our `gltf_instances` sample app.

There is now a need for some general refactoring in gltfio. I feel that
the high-level objects have become too tightly coupled to each other.

Fixes #3137.
2021-01-19 16:37:54 -08:00
Mathias Agopian 229f1f6d95 make sure the ResourceAllocator stays below the cache size limit
Only items older than a certain value were purged from the cache,
this allowed the cache to grow unbounded before this age limit was
reached.

We now purge the cache at each frame if it's above the size threshold.

Fixes #3381
2021-01-19 15:20:37 -08:00
Mathias Agopian bc2eae2ecd fix filament_test on aarch64 mac
don't use slog from a static variable, because it might not have been
constructed yet, due to static initialized order.
For some reason, this happens on aarch64 macs, but this was actually
a real problem.
2021-01-19 15:20:11 -08:00
Philip Rideout e468ec91b7 Metal: honor inverseFrontFaces RasterState.
Fixes #3402.
2021-01-19 10:35:14 -08:00
Philip Rideout ca2829461a Add options to planar reflection demo.
By default, the demo now reflects the camera instead of the renderable.
However this can be changed via the command line. Users can now change
the backend too.
2021-01-19 09:16:50 -08:00
Philip Rideout 7805687f7a Update emsdk version in README. 2021-01-16 09:17:56 -08:00
Mathias Agopian af82aaa0fc remove unused code that causes warnings 2021-01-15 14:38:01 -08:00
Mathias Agopian 410ecfd014 support for Apple Silicon macs
- add darwin-aarch64 support to bluegl
- remove all aarch64 conditions in our cmakefiles, the architecture
  is better handled in the source files (to allow fat binaries later)
2021-01-15 14:02:19 -08:00
Mathias Agopian 0df1f9fcce hack libfilament_jni to compile on Apple Silicon
The problem is that we're trying to link against an x86 jdk and that
fails, in turn preventing the library to link.
2021-01-15 14:02:19 -08:00
MirsfangandMathias Agopian 45f7e07832 fix material use (#3417)
* fix material use

* Update filament/src/PostProcessManager.cpp

Co-authored-by: Mathias Agopian <pixelflinger@gmail.com>
2021-01-15 13:59:09 -08:00
Mathias Agopian 1aefe741b2 update libpng to 1.6.37 2021-01-15 12:10:03 -08:00
Mathias Agopian d1842919cf update zlib to 1.2.11 2021-01-15 12:10:03 -08:00
Philip Rideout 6473771f1e Update Draco to 1.4.1
Tested with gltf_viewer release macOS on:

- CesiumMan/glTF-Draco/CesiumMan.gltf
- MorphPrimitivesTest/glTF-Draco/MorphPrimitivesTest.gltf
2021-01-15 11:03:29 -08:00
Philip Rideout 2d57a82b49 Add simple RenderTarget demo (planar reflection)
When we removed the old "ghetto bloom" demo, we ceased to have any
samples demonstrating the RenderTarget API. This demo is a fairly simple
demonstration of planar reflection.
2021-01-14 16:27:18 -08:00
Romain Guy dc2d55c409 Update static documentation 2021-01-14 10:29:38 -08:00
Romain Guy c0b8e98a93 Update documentation to fix broken links 2021-01-14 10:28:56 -08:00
Philip Rideout 8252bbe512 gltf_viewer: fix very sporadic crash when exiting.
This could occur when trying to exit the app while textures
are still being decoded.
2021-01-13 09:48:36 -08:00
Philip Rideout a4817f3e2a Simplify lifetime management of cgltf_data.
The gltfio API allows users to destroy ResourceLoader or FilamentAsset
even when various asynchronous work (e.g. uploading buffers to the GPU)
has not yet been completed. This was achieved in an error-prone manner
using manual reference counting and an internal management object called
AssetPool.

This PR refactors gltfio by wrapping cgltf_data in shared_ptr, which I
usually try to avoid. However in this case it provides the precisely the
functionality that is needed.

I tested this PR for memory leaks and crashes by hacking gltf_viewer
and monitoring memory usage in Activity Monitor.

This fixes #3383 and makes it easier to implement some missing features,
such as animation support for instanced assets.
2021-01-13 09:44:56 -08:00
Philip Rideout fa879b4bd0 gltf_viewer: call asyncCancelLoad in drop handler
Relates to #3383
2021-01-08 09:40:39 -08:00
Ben Doherty 005e4ba2ec Fix Filament RenderingTest (#3407) 2021-01-07 12:10:53 -08:00
Romain Guy d2299c4502 List supported glTF 2.0 features 2021-01-06 14:20:46 -08:00
Philip Rideout 5c666c254e gltfio: Improve robustness when decoding textures.
Bad texture files would cause the background decoder thread to never
finish and would generate textures with 0x0 dimensions, which eventually
triggers GL_INVALID_VALUE.

To recap, gltfio texture loading has two phases: the first phase is
synchronous and uses stbi_info to gather texture info. The second phase
is asynchronous and uses stbi_load to do the actual decoding.

During the first phase, we now check the return code from stbi_info
rather than assuming that it worked.  :)

Fixes #3344
2021-01-05 12:00:29 -08:00
ritwik a09c17bd4f Make install gltfio_resources and gltfio_resources_lite for desktop builds also 2021-01-05 10:35:13 -08:00
Ben Doherty 57df4481e9 Update Material query API to work with subpasses (#3203)
* Update Material query API to work with subpasses

* Add JNI binding
2020-12-23 13:27:04 -08:00
Ben Doherty 47af85aed1 Remove libSPIRV-Tools-shared from spirv-tools (#3390) 2020-12-23 13:26:14 -08:00
Ben Doherty 44fc295913 Unbind texture from all sampler groups upon destroy (#3386) 2020-12-22 11:34:05 -08:00
Philip Rideout 6878b0be36 build.sh: Add TypeScript bindings to the tgz file.
This makes the tgz consistent with the npm package. Fixes #3268.

Note that we already stopped packaging the old HTML docs. Going forward,
we would like to use the TS declarations as documentation because they
must be kept up to date anyway, and they already contain type
information. This was discussed in #3250.
2020-12-21 17:27:46 -08:00
Romain Guy 6c222bf4e3 Update README 2020-12-15 14:48:38 -08:00
Philip Rideout 042bfe2597 Partial fix for MSVC build. 2020-12-14 12:15:06 -08:00
Ben Doherty 97133f3591 Fix Windows iterator issue in Zip2Iterator and StructureOfArrays (#3322) 2020-12-14 12:14:53 -08:00
Philip Rideout d06cc4390e filamat: minify struct fields.
This shrinks the arm64 so file by 24 KiB.
2020-12-14 11:19:43 -08:00
Philip Rideout 6047d3235f Remove VSM variant from Skybox material. 2020-12-14 11:19:31 -08:00
Philip Rideout 2cda6e35bd math: reduce template bloat for matrices
This does not change our API, it merely reduces the number of
non-inlined function instantiations appearing in non-optimized binaries.
2020-12-14 11:19:22 -08:00
Philip Rideout 8f8d51e17b Code review fixups for libibl_lite. 2020-12-14 11:19:16 -08:00
Philip Rideout 6919e3b274 libibl: use C callback for progress 2020-12-14 11:19:09 -08:00
Philip Rideout 10bf944410 Add libibl_lite. 2020-12-14 11:19:03 -08:00
Romain Guy eb70fd5dee Sample the proper channel for sheenRoughness 2020-12-12 18:05:02 -08:00
Romain Guy 986a3869cc Fix struct initialization 2020-12-12 17:40:48 -08:00
Romain Guy 9ad3d88d74 Fix build breakage.
We were declaring one too many material properties which would
lead to out of bounds writes/reads.
2020-12-12 12:04:24 -08:00
Romain Guy a3bfdb89fa Update release notes 2020-12-12 11:09:28 -08:00
Romain Guy 2895530e09 Add support for sheenColor and sheenRoughness (#3358)
* Add support for sheenColor and sheenRoughness

This work is necessary to support the glTF extension KHR_materials_sheen.
This change effectively adds the specular lobe from the cloth material
model to the base material model. The cloth model remains useful for
its extra subsurface color feature but also because it's cheaper.

* Add support for KHR_materials_sheen to gltfio

* Update documentation

* Document default shading values
2020-12-12 11:07:40 -08:00
Romain Guy f8069aa99f Update to cgltf 1.9 (#3361) 2020-12-11 16:42:36 -08:00
Philip Rideout b70eea9556 filamat: minify struct fields.
This shrinks the arm64 so file by 24 KiB.
2020-12-10 11:20:14 -08:00
Philip Rideout 44a8da6a8e Remove VSM variant from Skybox material. 2020-12-10 11:20:01 -08:00
Philip Rideout 3bd066f993 math: reduce template bloat for matrices
This does not change our API, it merely reduces the number of
non-inlined function instantiations appearing in non-optimized binaries.
2020-12-10 11:19:46 -08:00
Philip Rideout 1b10afa9e6 Code review fixups for libibl_lite. 2020-12-10 11:19:36 -08:00
Philip Rideout 024910ba8e libibl: use C callback for progress 2020-12-10 11:19:36 -08:00
Philip Rideout f2e3a132db Add libibl_lite. 2020-12-10 11:19:36 -08:00
Philip Rideout 87abd1f8bc Fix RenderableManager docs for "index"
I also double-checked the backends, they indeed treat it as an index
count.

Fixes #3351
2020-12-10 10:11:46 -08:00
Philip Rideout 57662c52f2 matdbg / matinfo: fix post-process variant string
Also some minor HTML stuff:

- Hide "Required attributes" header when there are none.
- Remove legend for variants (takes too much space).
2020-12-09 14:44:27 -08:00
Philip Rideout a50cd1f8c8 zbloat now includes chunk sizes 2020-12-06 21:54:37 -08:00
Philip Rideout fe907398d4 resgen / zbloat fixups 2020-12-06 15:25:08 -08:00
Philip Rideout 8b6ddfe97a Add zbloat tool.
This tool makes it easy to analyze the composition of Android
applications that use Filament.

- Filament materials are shown in the treemap if `resgen --json` was
  used in the build.
- The input path can be a so file, folder, or zip archive (apk or aar).
- If the path is a zip or folder, helps you find the file to analyze.
- The generated web report is a self-contained HTML file.
- Reports the gzipped size of all Filament materials.

For example, from a mac, you can generate a self-contained HTML file by
typing this from the Filament repo root:

    ./tools/zbloat/zbloat.py ./android/filament-android
    open index.html

This tool uses Python, `nm`, and `objdump`.

The `nm` tool works slightly differently between macOS and Linux, so a
`Dockerfile` is provided that installs dependencies inside a Linux
container. This is also convenient if you do not have both versions of
Python on your system.

The easy way to use docker is to invoke the helper bash script. Simply
type `zbloat.sh [args...]` instead of `zbloat.py [args...]`. The first
time you run it, it will be slow but subsequent times will be fast.

Many thanks to Evan Martin for his interactive treemap widget.
2020-12-06 14:36:25 -08:00
Philip Rideout 3226b20ece resgen: add --json option.
This option embeds a small JSON string inside the resgen blob that lists
all materials and their respective sizes. This is useful when analyzing
the footprint of the binary executable.
2020-12-06 14:36:13 -08:00
MasTraER 61d473887f Fix clearing Rendertarget multiple times
This fixes a bug Renderer clearing a render target multiple times when the first time and back again.

Usually the default RenderTarget is unintentionally cleared/discarded in the current behavior.
1) Renderer renders a view without custom RenderTarget having full-screen viewport,
2) Renderer renders a view with custom RenderTarget
3) And Renderer renders an another view without custom RenderTarget having different viewport from 1)
You may see junk or empty pixels in outside of the viewport of the view 3), depending on ClearOptions and the backend.

This fix make Renderer put cleared RenderTargets into a set and check them to be cleared only for the first time, instead of comparing the previous RenderTarget to the current RenderTarget.
2020-12-06 14:35:26 -08:00
cjsliuj b3d7819e78 Fix computeTangents 2020-12-05 15:24:34 -08:00
Philip Rideout de6220594d WebGL: RGB16F is not color renderable.
This was problematic with Chrome's ANGLE backend; more information at:
https://bugs.chromium.org/p/chromium/issues/detail?id=941671#c10

Fixes #3308
2020-12-02 14:31:19 -08:00
Philip Rideout d9dfe69a81 Android: do not export internal symbols.
We now export only two groups of symbols: (1) JNI and (2) dynamic linker
symbols used by the companion libraries.

This commit has the following impact:

- Shrinks the arm64 so from 1024 KiB to 954 KiB.
- Shrinks the arm64 aar from 560 KiB to 538 KiB.

Note that the patterns in the map file are tested against mangled names
and therefore should not be used to match the double-colon operator.
2020-12-02 13:11:38 -08:00
Ben Doherty 22d4e63787 Fix Windows iterator issue in Zip2Iterator and StructureOfArrays (#3322) 2020-12-01 14:05:15 -08:00
Philip Rideout f033799a43 Fix incorrect JNI binding for destroyColorGrading. 2020-12-01 09:02:51 -08:00
Ben Doherty 30e150c016 Fix Metal assertion when loading into texture arrays (#3314) 2020-11-24 10:46:16 -08:00
Ben Doherty f5f27749a4 Update native window documentation (#3315) 2020-11-23 14:03:10 -08:00
Philip Rideout b5f95213db Partial fix for MSVC build. 2020-11-20 14:18:08 -08:00
Philip Rideout 9a2f6fdb53 Vulkan: change vkWaitForFences usage for SwiftShader.
When passing only 1 fence to vkWaitForFences, the `waitAll` argument
should not have any effect, but SwiftShader seems to skip the wait
when this argument is set to VK_FALSE.

More specifically, the failure to wait in `acquireWorkCommandBuffer`
causes the subsequent destruction of an in-use fence, which causes
a TSAN failure with Google's internal tests.

I am consulting with the SwiftShader team on a real fix, meanwhile
we can commit this easy workaround.

We have 5 usages of vkWaitForFences, one of which uses multiple fences
and should have used VK_TRUE anyway.
2020-11-20 09:37:54 -08:00
Philip Rideout d42865373d Vulkan: change vkWaitForFences usage for SwiftShader.
When passing only 1 fence to vkWaitForFences, the `waitAll` argument
should not have any effect, but SwiftShader seems to skip the wait
when this argument is set to VK_FALSE.

More specifically, the failure to wait in `acquireWorkCommandBuffer`
causes the subsequent destruction of an in-use fence, which causes
a TSAN failure with Google's internal tests.

I am consulting with the SwiftShader team on a real fix, meanwhile
we can commit this easy workaround.

We have 5 usages of vkWaitForFences, one of which uses multiple fences
and should have used VK_TRUE anyway.
2020-11-20 09:36:06 -08:00
Philip Rideout 761977d385 Filament should always bind an IBL texture.
This prevents a SwiftShader crash and/or a slew of "no texture bound"
warnings that would appear when the client provides an IBL without
providing reflections texture, which should be a valid thing to do.

Note that it is okay to declare a sampler in GLSL that never gets bound,
as long as it is never sampled from. Since we always sample from the
IBL specular texture, we should always bind something to it.
2020-11-19 13:28:19 -08:00
Philip Rideout f83eb114bc Filament should always bind an IBL texture.
This prevents a SwiftShader crash and/or a slew of "no texture bound"
warnings that would appear when the client provides an IBL without
providing reflections texture, which should be a valid thing to do.

Note that it is okay to declare a sampler in GLSL that never gets bound,
as long as it is never sampled from. Since we always sample from the
IBL specular texture, we should always bind something to it.
2020-11-19 10:22:45 -08:00
Philip Rideout 9c20294e4b gltfio: Fix animator crash for orphaned nodes.
Fixes #3285
2020-11-18 11:26:39 -08:00
Ben Doherty 40e7a86f5f Fix, matc crash when building mobile materials (#3296) 2020-11-16 14:41:15 -08:00
Ben Doherty 21248f15b5 Fix, matc crash when building mobile materials (#3296) 2020-11-16 14:37:55 -08:00
Ben Doherty 34707431f7 Fix spirv-tools CMake warning (#3289) 2020-11-16 14:30:06 -08:00
Benjamin Doherty 4f32817f6d Bump version to 1.9.10 2020-11-16 12:37:49 -08:00
Benjamin Doherty cc9e05e711 Merge branch 'rc/1.9.9' into release 2020-11-16 12:34:13 -08:00
Benjamin Doherty 5e585496b2 Update RELEASE_NOTES for 1.9.9 2020-11-16 12:33:43 -08:00
Benjamin Doherty 1e501eb00b Release Filament 1.9.9 2020-11-16 12:32:38 -08:00
Benjamin Doherty 419d68d4db Update RELEASE_NOTES for 1.9.9 2020-11-16 12:17:02 -08:00
Ben Doherty fdc28801a2 Silence spirv-opt warnings in release builds (#3288) 2020-11-13 13:55:19 -08:00
Ben Doherty c008109335 Update Android building instructions on Windows 2020-11-13 11:04:24 -08:00
Philip Rideout 8450232448 Improve the "unbound texture" warnings.
With Vulkan, this warning would sometimes be a false positive. It could
trigger for internal samplers like `ssao` and `structure`, even though
they were not declared in SPIR-V.

With OpenGL, this warning would never be a false positive because it has
the luxury of calling `glGetUniformLocation`.

This adds a private attribute to our samplers called `strict` that
indicates whether or not a sampler should always have a bound texture.
For now the only strict samplers are the custom ones declared in the
user's material.

At some point I think we should consider adding `spirv-reflect` to our
tree to help with problems like this.
2020-11-12 16:21:13 -08:00
Philip Rideout 99c5fc7388 Improve the "unbound texture" warnings.
With Vulkan, this warning would sometimes be a false positive. It could
trigger for internal samplers like `ssao` and `structure`, even though
they were not declared in SPIR-V.

With OpenGL, this warning would never be a false positive because it has
the luxury of calling `glGetUniformLocation`.

This adds a private attribute to our samplers called `strict` that
indicates whether or not a sampler should always have a bound texture.
For now the only strict samplers are the custom ones declared in the
user's material.

At some point I think we should consider adding `spirv-reflect` to our
tree to help with problems like this.
2020-11-12 16:02:32 -08:00
Ben Doherty 90c156ebef Add fog variant filter to matc (#3286) 2020-11-12 12:47:42 -08:00
Ben Doherty 2df02d81d3 Add setFrameCompletedCallback JNI binding (#3275) 2020-11-12 12:24:41 -08:00
Ben Doherty 8019b11589 Update glslang and friends (#3277) 2020-11-12 12:23:51 -08:00
Philip Rideout cc51726590 Vulkan: improve robustness by providing 1x1 fallback. 2020-11-12 10:36:13 -08:00
Philip Rideout 16454e0de6 Vulkan: improve robustness by providing 1x1 fallback. 2020-11-12 10:35:50 -08:00
Philip Rideout 318e22af51 Fix clear behavior with RenderTarget API.
This fixes a bug seen with client applications that use ClearOptions
instead of Skybox, and one or more offscreen RenderTarget objects.
These apps would see junk pixels because Filament would only clear the
first render target in the frame.

The fix is to factor some the flag-setting logic in `beginFrame()` into
a private method, and call this method from `render()` each time
the user-level RenderTarget has been changed.

I wrote a simple C++ demo to reproduce the issue and to verify that
this fix works.
2020-11-11 09:25:36 -08:00
Philip Rideout 3bf934f5d7 Fix clear behavior with RenderTarget API.
This fixes a bug seen with client applications that use ClearOptions
instead of Skybox, and one or more offscreen RenderTarget objects.
These apps would see junk pixels because Filament would only clear the
first render target in the frame.

The fix is to factor some the flag-setting logic in `beginFrame()` into
a private method, and call this method from `render()` each time
the user-level RenderTarget has been changed.

I wrote a simple C++ demo to reproduce the issue and to verify that
this fix works.
2020-11-11 09:25:07 -08:00
Philip Rideout 68ac87dc24 NOOP backend should not care about GLSL vs SPIRV.
This fixes errors that would occur when using the NOOP backend with
materials that were built without OpenGL support.
2020-11-10 15:44:01 -08:00
Ben Doherty b4a6d0a83e Add callback API to SwapChain (#3270) 2020-11-10 14:52:04 -08:00
Ben Doherty a09037cec0 Revert "macOS: fix headless rendering." (#3273) 2020-11-10 12:02:12 -08:00
Philip Rideout 50a61984ec NOOP backend should not care about GLSL vs SPIRV.
This fixes errors that would occur when using the NOOP backend with
materials that were built without OpenGL support.
2020-11-09 11:11:12 -08:00
Romain Guy 6486eba7e2 Fix typo in docs 2020-11-09 09:37:10 -08:00
Benjamin Doherty acb8f00075 Bump version to 1.9.9 2020-11-09 09:32:55 -08:00
Benjamin Doherty 06d9183aaa Merge branch 'rc/1.9.8' into release 2020-11-09 09:28:58 -08:00
Benjamin Doherty c92d13c0c9 Update RELEASE_NOTES for 1.9.8 2020-11-09 09:28:15 -08:00
Benjamin Doherty bd9aba35f6 Release Filament 1.9.8 2020-11-09 09:27:06 -08:00
Benjamin Doherty 75af25419d Update RELEASE_NOTES for 1.9.8 2020-11-09 09:26:27 -08:00
Benjamin Doherty f6b90d2a31 Bump version to 1.9.8 2020-11-09 09:21:36 -08:00
Philip Rideout 7fbd00e59b Repair Windows build, maybe. 2020-11-09 08:35:43 -08:00
Philip Rideout f814138f83 Regenerate BlueVK, use a C++ namespace.
This moves all Vulkan entry points into the bluevk namespace
to avoid conflicts with other Vulkan loaders.

This also updates the header files and loader code to version 1.2.159 of
the Vulkan spec, which is currently available at the following links.

https://khronos.org/registry/vulkan/specs/1.2/html/vkspec.html
https://github.com/KhronosGroup/Vulkan-Headers/commit/87451c55aa8b4f00831fab6ffc4b721d0f148102
2020-11-09 08:35:43 -08:00
Philip Rideout 96d3f2f16b More fixes for signed integer overflow.
Fence.cpp:

My previous fix to the fix was insufficient because a signed integer
overflow could still occur as follows (this was observed in an internal
test at Google).

If the conditional on line 87 is true, then a clamped value is passed
into `wait`, which causes the conditional on line 133 to fail, which
causes `wait_for` to be called inappropriately, which is where an
overflow would occur.

MetalHandles.mm:

This is more theoretical, but to prevent potential integer overflow
within STL, I think we should call `wait()` rather than `wait_for()`
when an infinite timeout is desired.

This is our fourth fix to fences in since November 2; see also dcca236,
e9c9e45, and 8969416.  :)
2020-11-09 08:35:17 -08:00
Philip Rideout 89694168a6 Another fix for FENCE_WAIT_FOR_EVER.
FFence::wait() has some logic that tests if "timeout" is equal to
FENCE_WAIT_FOR_EVER, which is actually impossible because it would
be modified by the clamp in this situation.

In practice I think this oversight would not cause any problems. I
noticed it while reviewing the code.

To recap why the clamp exists: according to the ISO C++ spec, the
"nanoseconds" duration in chrono is at least a signed 64-bit type, but
our sentinel constant might not (and does not) fit within this range.
2020-11-05 17:24:44 -08:00
Romain Guy 63d5698a78 Update Gradle, AGP, and other dependencies (#3257)
* Update Gradle and AGP

* Update other dependencies
2020-11-05 10:47:12 -08:00
Romain Guy 24ca2bf181 Fix JNI binding 2020-11-04 13:01:16 -08:00
Ben Doherty f37a3e9497 Support CVPixelBuffer SwapChains with Metal (#3251) 2020-11-04 11:05:45 -07:00
Ben Doherty 90ad9b457a Implement copyFrame for Metal (#3249) 2020-11-03 12:25:29 -07:00
Ben Doherty 30f5a97ea1 Consolidate surface-related functionality into MetalSwapChain (#3246) 2020-11-03 12:00:03 -07:00
Philip Rideout 964a1bd7f2 BlueVK: improved error messaging. 2020-11-03 10:23:06 -08:00
Philip Rideout a3822f4af0 Fix FENCE_WAIT_FOR_EVER in Linux.
The number of infinite nanoseconds was negative because we asked
chrono for a signed integer, so "wait forever" really meant "do not
wait at all".
2020-11-02 16:12:53 -08:00
Philip Rideout e9c9e45ac9 Fix FENCE_WAIT_FOR_EVER in Linux.
The number of infinite nanoseconds was negative because we asked
chrono for a signed integer, so "wait forever" really meant "do not
wait at all".
2020-11-02 16:02:27 -08:00
Philip Rideout fb831dec0a Vulkan: adjust usage flags to allow DEPTH blits. 2020-11-02 11:00:57 -08:00
Benjamin Doherty bcdad769ff Merge branch 'rc/1.9.7' into release 2020-11-02 11:03:57 -07:00
Benjamin Doherty dc1c5529c0 Update RELEASE_NOTES for 1.9.7 2020-11-02 11:00:55 -07:00
Benjamin Doherty 8b8d563b0f Bump version to 1.9.7 2020-11-02 11:00:09 -07:00
Benjamin Doherty be4fb4fdbb Update RELEASE_NOTES for 1.9.7 2020-11-02 10:59:19 -07:00
Ben Doherty dcca236f60 Fix bug with Fence timeouts (#3243) 2020-11-02 10:47:28 -07:00
Philip Rideout 70dba2398e gltfio: add createInstance() to AssetLoader.
Note that this API is on the loader rather than the asset. This is
because the loader knows how to create Filament entities by traversing
a cgltf node hierarchy.

Animation on dynamically added instances is not yet supported.

We did not add destroyInstance() because gltfio favors flat arrays for
long term storage of entity lists and instance lists, which would be
slow to shift. We also wish to discourage create/destroy churn since it
is more efficient to pre-allocate instances and selectively add them
into the scene.

Fixes #3137.
2020-11-02 09:47:14 -08:00
Philip Rideout 47521d70a1 gltfio: fix ASAN issue when consuming invalid animation.
Release builds do not call cgltf_validate() so it was possible to
read out-of-bounds animation data when encountering a badly formed glTF
file with mismatched counts between sampler inputs and outputs.
2020-10-31 15:17:15 -07:00
Philip Rideout 468992f4cd gltfio: do not segfault on invalid primitives. 2020-10-31 13:28:13 -07:00
Philip Rideout 0db7057983 Vulkan: disable unreliable blit diagnostics. 2020-10-31 12:37:42 -07:00
Philip Rideout 8a63834607 Vulkan: fix layout mismatch after blitting to swap chain. 2020-10-31 12:37:42 -07:00
Philip Rideout 4e4d4f9ee3 Vulkan: add blit support for depth and MRT. 2020-10-31 10:29:25 -07:00
Philip Rideout 6abef94d95 mathio: add ostream operator for quaternions. 2020-10-29 17:04:03 -07:00
Philip Rideout 4b1c557bb1 Vulkan: fix color attachment list in first subpass.
This fixes a slew of validation warnings and errors seen when multiple
subpasses are enabled, starting with:

    Attachment 1 not written by fragment shader; undefined values will
    be written to attachment

The Vulkan driver was using the same color attachment list for both
subpasses, so the first subpass had unused attachments.

Note that Vulkan makes a distinction between color attachments and input
attachments and requires separate lists to be supplied for each subpass,
but our Driver API consolidates everything into a single list. This
should perhaps be refactored at a later date.
2020-10-29 15:03:34 -07:00
Philip Rideout 94a1eb27b4 Do not declare unused fragColor in GLSL.
This fixes a Vulkan validation warning when building a pipeline that
does not have a color attachment.
2020-10-29 11:08:13 -07:00
Philip Rideout a9754273b0 Vulkan: minor fix for diagnostic output. 2020-10-28 15:41:07 -07:00
Philip Rideout 2fe4f6cbe7 AutomationEngine: fix regression with screenshots. 2020-10-28 12:58:54 -07:00
Philip Rideout 1159435d47 gltfio: add safety checks to getAnimator. 2020-10-28 11:51:06 -07:00
Philip Rideout a6f364e0f3 gltfio: fix segfault when consuming invalid file. 2020-10-28 11:50:54 -07:00
Philip Rideout c6942a52e6 gltfio: refactor the instancing cache.
This prepares for #3137 by moving the mesh cache and material instance
cache out of the loader (where they were transient anyway) and into the
actual asset. This paves the way for a `createInstance()` API.
2020-10-27 10:30:18 -07:00
Philip Rideout c65dc99771 Fix colorGradingAsSubpass when dithering is off.
This fixes the blank screen seen with Vulkan when all view options are
disabled.
2020-10-26 15:33:42 -07:00
Benjamin Doherty 65394f6301 Bump version to 1.9.7 2020-10-26 11:34:20 -06:00
Benjamin Doherty b0beee03bc Merge branch 'rc/1.9.6' into release 2020-10-26 11:29:45 -06:00
Benjamin Doherty 6971b3b6b0 Update RELEASE_NOTES for 1.9.6 2020-10-26 11:28:06 -06:00
Benjamin Doherty 4270384661 Bump version to 1.9.6 2020-10-26 11:27:08 -06:00
Benjamin Doherty fe1de41b8e Update RELEASE_NOTES for 1.9.6 2020-10-26 11:25:31 -06:00
Philip Rideout 82cb13936c Vulkan: warn instead of panic for sampler overflow.
This makes behavior in release builds similar to the OpenGL backend.

In debug builds, we will still assert.
2020-10-23 11:11:35 -07:00
Philip Rideout 212b64ea5f Vulkan: make ReadPixels synchronous.
This makes it so that the PixelBufferDescriptor callback triggers at a
time consistent with other backends.

ReadPixels is still asynchronous in the sense that the callback is
triggered on the main thread. However, it is now guaranteed to trigger
during (or before) flushAndWait(), which is less surprising behavior.
2020-10-22 17:42:07 -07:00
Philip Rideout 2849dc6a2a Fix iOS build break. 2020-10-22 17:03:06 -07:00
Philip Rideout d84bb82e44 Merge duplicated implementations of toLinear(). 2020-10-22 17:03:06 -07:00
Philip Rideout 5746532b7c Add PNG output to test_ReadPixels. 2020-10-22 17:03:06 -07:00
Philip Rideout 2e10fe6680 PlatformVkLinux now supports all combos of XLIB and XCB.
You can now build Filament with support for both X11 APIs, or neither.
If both are supported, run-time selection is achieved using a SwapChain
flag.

Supporting only one API at build time (or neither) is useful because our
list of "required" VkInstance extensions can vary according to which
API's are supported. During VkInstance creation, we do not have a priori
knowledge about what kinds of swap chains will be created. (headless vs
non-headless, XCB vs XLIB, etc)

Note that some Vulkan implementation (e.g. some builds of SwiftShader)
only support XCB.
2020-10-22 16:55:25 -07:00
Philip Rideout f55c9ee437 Fix Windows build. 2020-10-22 13:08:09 -07:00
Philip Rideout 06e639ae91 Vulkan: fix destroy-while-used for UBOs. 2020-10-22 11:43:16 -07:00
Philip Rideout 8de19cb582 Vulkan: fix leak with headless swap chain. 2020-10-22 11:43:16 -07:00
Philip Rideout 47b1ece804 Vulkan: Improve refcounting for vertex buffers.
This avoids the following validation error when clients create then
immediately destroy vertex buffers, index buffers, and uniform buffers.

        VUID-vkDestroyBuffer-buffer-00922

        Cannot free VkBuffer that is in use by a command buffer.

Buffers that are used across multiple frames were fine, but
create-and-destroy scenarios were problematic.
2020-10-22 11:39:57 -07:00
Philip Rideout d47189536f Vulkan: fix thread safety regression in Disposer.
This fixes a regression introduced by 548b28c6e manifesting as
intermittent assertions. The VulkanDisposer gc() should only be called
from the driver thread.
2020-10-22 11:39:46 -07:00
dsternfeld7 4533a42a6f Makes it possible to have multiple instances of ImGuiHelper at the same time
This change fixes an issue where ImGuiHelper would crash on destruction if you created more than one instance at the same time.

This crash occurred when ImGui::DestroyContext() was called, because when the second instance was destroyed there was no current context causing it to crash.

This fixes it by making ImGuiHelper store and manage it's own context.

Having two instances of ImGuiHelper is useful in cases where you want to use imgui with multiple views.
2020-10-22 11:39:33 -07:00
Philip Rideout 853247f32f Vulkan: ReadPixels y-flip workaround. 2020-10-21 17:42:46 -07:00
Philip Rideout 5f6cbc779a Allow test_ReadPixels with SwiftShader. 2020-10-21 16:24:27 -07:00
Philip Rideout 548b28c6e2 Vulkan: improve the ReadPixels implementation.
This adds support for more format conversions and removes a bogus
assert that prevented ReadPixels within beginFrame / endFrame.
This was tested with:

    backend_test_mac --api vulkan --gtest_filter=BackendTest.ReadPixels
2020-10-21 16:04:31 -07:00
Ben Doherty 239246e221 Add ability to specify post-process material output location (#3205) 2020-10-21 12:19:46 -06:00
Philip Rideout 75c4f36f96 Add Dockerfile and test script for SwiftShader.
This adds a Dockerfile and a new bash script that makes it
east to invoke the appopriate Docker commands.

This does not yet enable a GitHub Action because of intermittent
issues that we have not yet ironed out.
2020-10-21 10:50:25 -07:00
Philip Rideout 7260bab7b3 Fix TypeScript binding for TextureUsage. 2020-10-20 14:09:05 -07:00
Ben Doherty e7250571e7 Add subpass parameter type to materials (#3193) 2020-10-19 16:28:26 -06:00
Philip Rideout c68d0a4e46 Vulkan: add missing field to VmaVulkanFunctions. 2020-10-19 11:57:37 -07:00
Benjamin Doherty a37b431e87 Bump version to 1.9.6 2020-10-19 11:55:13 -06:00
Benjamin Doherty 98107016b9 Merge branch 'rc/1.9.5' into release 2020-10-19 11:51:30 -06:00
Benjamin Doherty 37d080dfd1 Update RELEASE_NOTES for 1.9.5 2020-10-19 11:50:54 -06:00
Benjamin Doherty de75b9d125 Bump version to 1.9.5 2020-10-19 11:49:57 -06:00
Benjamin Doherty 8bccfc2863 Update RELEASE_NOTES for 1.9.5 2020-10-19 11:49:05 -06:00
Philip Rideout 07fd883f9a Vulkan + Android: fix build break.
Fixes #3200.
2020-10-19 09:36:12 -07:00
Philip Rideout 5ceb9fc5d5 Add optional XCB support to PlatformVkLinux.
This allows clients to build the Vulkan backend with either XLIB or XCB
support. I did a quick smoke test of the XCB option, but for now we are
continuing to default to XLIB. Note that the native window type used to
create the swap chain differs between these two API's.
2020-10-19 09:24:13 -07:00
Ben Doherty d14ba856a7 matc: fix some compilation failures still exit with code 0 (#3192) 2020-10-15 14:11:46 -06:00
Ben Doherty 7eec70276e Add release scripts and RELEASE_GUIDE (#3191) 2020-10-15 12:57:38 -06:00
Ben Doherty 4f58a7e5fb Fix Vulkan black screen on Windows with NVIDIA hardware (#3190) 2020-10-15 12:00:42 -06:00
Ben Doherty 30565a5afc Add capture frame button to gltf_viewer (#3189) 2020-10-14 12:43:05 -06:00
Ben Doherty 62d06592d3 VSM: add support for mipmaps and anisotropic sampling (#3185) 2020-10-14 11:48:23 -06:00
Benjamin Doherty e74e583b97 Fix CocoaPod version 2020-10-13 15:16:25 -06:00
Benjamin Doherty f54a0a3452 Fix CocoaPod version 2020-10-13 15:15:02 -06:00
Benjamin Doherty 6778ab0624 Fix CocoaPod version 2020-10-13 15:09:59 -06:00
Philip Rideout 37768ed9e1 Various changes to help clients upgrade Filament.
The non-const getSkybox() method is especially useful to client code
that needs to change the clear color, but does not have direct
access to the Renderer object.
2020-10-13 10:10:59 -07:00
Philip Rideout 20abfec7d3 Minor change to adhere to CODE_STYLE. 2020-10-12 11:15:45 -07:00
Benjamin Doherty 269d636785 Bump version to 1.9.5 2020-10-12 12:03:29 -06:00
Benjamin Doherty 39862c91ce Merge branch 'rc/1.9.4' into release 2020-10-12 11:56:24 -06:00
Benjamin Doherty 03df97d0e3 Update RELEASE_NOTES for 1.9.4 2020-10-12 11:55:39 -06:00
Benjamin Doherty 40e10817dd Bump version to 1.9.4 2020-10-12 11:52:49 -06:00
Benjamin Doherty 523f4026b4 Update RELEASE_NOTES for 1.9.4 2020-10-12 11:52:01 -06:00
Philip Rideout b82dca4fac JobSystem: work around hang on 2-CPU machines
If hardware_concurrency() returned 2 while UTILS_HAS_HYPER_THREADING was
enabled, `mThreadCount` was resulting in zero, so jobs (such as texture
decoding) would simply never start. This problem was noticed with
GitHub Actions.

I tested this fix locally by replacing `hardware_concurrency()` with
fixed values like 1 or 2, and verified that the hang went away.
2020-10-09 16:14:50 -07:00
Philip Rideout 5ebc6bce04 Add schema for automation specs.
This can help when authoring a spec using your favorite text editor.
2020-10-09 10:23:27 -07:00
Benjamin Doherty a6bf162431 Bump version to 1.9.4 2020-10-07 16:06:23 -06:00
Ben Doherty bd625e42e9 Fix Vulkan crash when using shadow cascades (#3172) 2020-10-07 15:36:45 -06:00
Philip Rideout 7471237178 Linux fixes for headless SwiftShader. 2020-10-07 11:24:33 -07:00
Ben Doherty 52698aab14 Destroy dummyOneTextureArray in PostProcessManager (#3171)
* Destroy dummyOneTextureArray in PostProcessManager

Fixes #3166

* Update RELEASE_NOTES.md
2020-10-07 12:19:02 -06:00
Philip Rideout 3d121eb873 Vulkan ReadPixels: fix platforms that use BGRA.
Fixes a color issue seen with SwiftShader in non-headless mode.
2020-10-06 15:22:14 -07:00
Ben Doherty 1dd7b06e6f Fix null pointer dereference in FIndirectLight (#3163) 2020-10-06 15:27:28 -06:00
Philip Rideout d2ca1c79d2 Fix Windows build by avoiding nested initializers.
Note that designated initializers are technically a C++20 feature so we
should not be using them. However they are really nice for Vulkan code.
2020-10-06 13:45:26 -07:00
Philip Rideout 52913e685e Vulkan: support readPixels and headless swap chains.
This adds support for headless rendering as well as readPixels. These
features are necessary for automated testing.

NOTE: invoking readPixels with a non-headless SwapChain seems to fail
with MoltenVK. I will investigate this later.
2020-10-06 13:45:26 -07:00
Benjamin Doherty f30332b12b Fix RELEASE_NOTES 2020-10-06 11:17:30 -06:00
Ben Doherty f31eb09ca0 Add Live Wallpaper Android sample (#3161) 2020-10-06 11:03:55 -06:00
Ben Doherty 0bec65701a VSM: render both shadow casters and receivers (#3147) 2020-10-05 17:03:10 -06:00
Ben Doherty 59ef044ce0 Add support to UiHelper for SurfaceHolder (#3155) 2020-10-05 12:04:05 -06:00
Benjamin Doherty 826e8d181c Merge branch 'rc/1.9.3' into release 2020-10-05 11:36:16 -06:00
Benjamin Doherty 76f1e91fd2 Update RELEASE_NOTES for 1.9.3 2020-10-05 11:35:44 -06:00
Benjamin Doherty d72d3533e6 Bump version to 1.9.3 2020-10-05 11:34:19 -06:00
Benjamin Doherty 16dfadbba0 Update RELEASE_NOTES for 1.9.3 2020-10-05 11:29:36 -06:00
Yixing Lao 9ce2c319a9 ARM64 support for bluegl (#3150)
* ARM64 support for bluegl

* Detect arch with uname

* Use register x16
2020-10-05 10:19:05 -07:00
Philip Rideout 4fe5832333 gltf_viewer: add --headless option.
This should only be used in combination with --batch. Users are
admonished if they try using it on its own.
2020-10-04 10:02:10 -07:00
Philip Rideout 79f1744823 Automation: fix segfault when closing the app early.
The Filament View that gets passed to tick() is retained briefly when
screenshots are enabled, but it may be destroyed by the time the
PixelBufferDescriptor callback is invoked. So, we needed a way of
notifying the AutomationEngine.
2020-10-04 10:01:43 -07:00
Philip Rideout e352542e24 Automation: add support for materials.
This adds a `material` key to `Settings`, as a sister to `view`.

Here's an example of an automation spec that manipulates material
parameters:

    [{
      "name": "metallic_vs_roughness",
      "permute": {
          "material.scalar.roughnessFactor": [0.0, 0.5, 1.0],
          "material.scalar.metallicFactor": [0.0, 1.0]
      }
    }]

Currently this is limited to float, vec3, and vec4 parameters.
2020-10-02 11:57:23 -07:00
Philip Rideout 5938242d61 gltf_viewer: Add automation UI and functionality.
This adds `AutomationEngine` to libs/viewer, which iterates through
`Settings` instances that were generated from a JSON spec and applies
them to a Filament `View`. It can be configured to sleep between tests
using a time delay or a frame count.

This also adds command line arguments and user-interface elements to
`gltf_viewer` for automated testing.
2020-10-02 11:00:26 -07:00
Philip Rideout cfddd5b273 Rename AutomationList to AutomationSpec. 2020-10-01 19:07:24 -07:00
Philip Rideout 8a865e531e gltf_viewer: minor refactoring 2020-10-01 17:15:25 -07:00
Philip Rideout d05fb52ebf gltf_viewer: use integers for Temperature / Tint. 2020-10-01 16:41:24 -07:00
Philip Rideout fd142b9b84 gltf_viewer: add --settings, prep for automation. 2020-10-01 16:41:24 -07:00
Philip Rideout 6658283617 FilamentApp: Do not call postRender when skipping. 2020-10-01 16:41:24 -07:00
Pixelflinger 8b3caeffb9 ssct: decouple shadow distance from sample count 2020-10-01 10:20:38 -07:00
Philip Rideout 5fae33bde5 Automation: simplify API by flattening the test cases. 2020-09-30 16:17:23 -07:00
Philip Rideout 43cc5f9906 Automation: add a built-in default spec. 2020-09-30 16:17:23 -07:00
Philip Rideout 902eb32e3c Fix typo in copyright headers. 2020-09-30 16:17:23 -07:00
Philip Rideout 08f7973d0c Refactor Automation API. 2020-09-30 16:17:23 -07:00
Philip Rideout a736b8b018 Rename parse.h to jsonParseUtils. 2020-09-30 16:17:23 -07:00
Philip Rideout 094e7169cc Introduce a configurable test case generator.
This lets us generate long lists of settings permutations by writing a
simple JSON spec. For example, the following spec would generate six
`Settings` objects, all of which have SSAO enabled. See the unit test
for a larger example.

```
{
    "name": "viewopts",
    "base": { "view.ssao.enabled": true }
    "permute": {
        "view.dithering": ["NONE", "TEMPORAL"],
        "view.sampleCount": [1, 4, 8]
    }
}
```
2020-09-30 16:17:23 -07:00
Ben Doherty 44d4694c29 Add JNI binding for vsm msaa samples (#3139) 2020-09-30 16:12:45 -06:00
Ben Doherty 42862ddcde Fix RELEASE_NOTES 2020-09-30 14:53:01 -06:00
Ben Doherty 236ed9680c Add MSAA option to VSM (#3084) 2020-09-30 14:51:40 -06:00
Ben Doherty 229fdc9be5 Add View::setShadowType JNI binding (#3094) 2020-09-30 13:20:39 -06:00
Ben Doherty 4af0cdfd4d Use light space Z as VSM depth metric (#3131) 2020-09-30 12:31:03 -06:00
Philip Rideout 451fac7d7b Fix writeJson() for vectors and enums. 2020-09-30 11:12:10 -07:00
Philip Rideout 617dc932bb Fix unit test failure. 2020-09-29 19:59:53 -07:00
Pixelflinger 583c1c07cf SSCT optimizations and fixes
- Use lower depth LOD as the cone radius increases.
  This is the same technique we use for SAO.
  The better cache access significantly improve performance.
  On a test on Pixel4 at 585MHz, SAO pass improves by 30%.
  This also helps the algorithm scale with the shadow distance.

- Shadow direction/length no longer dependent on aspect-ratio and camera
  orientation.
  This is fixed by doing all the computations in screen-space instead of 
  normalized screen space.

- Shadow parameters are no longer dependent on the field of view.

- Also rename dominantLightShadowing.fs to ssct.fs

- remove zoom parameter, it wasn't very useful.
2020-09-29 17:00:32 -07:00
Benjamin Doherty 9e01348dd5 Fix CocoaPod Podspec for Xcode 12 2020-09-29 12:25:13 -06:00
Philip Rideout ec2579bad5 Viewer Settings: remove SSCT scale. 2020-09-29 10:47:35 -07:00
Philip Rideout e5a9a259de Fix build break. 2020-09-29 10:47:35 -07:00
Philip Rideout 6472f645fc viewer: add SCCT to JSON serializer. 2020-09-29 10:47:35 -07:00
Philip Rideout e9ace4e5fb Add jsmn to third_party. 2020-09-29 10:47:35 -07:00
Philip Rideout c119f9bdca gltf_viewer: Re-use ViewSettings structs. 2020-09-29 10:47:35 -07:00
Philip Rideout 7997e4aa21 Introduce libs/viewer and serializable view settings.
This introduces the `viewer::Settings` struct, and a JSON reader /
writer.

This will be used for automated testing and for client / server
communication.

Note that `viewer::Settings` is closely associated with the
`filament::View` API; when updating the latter we will often need to
update the former, as well as some serialization code. This increases
the maintenance burden and I think we should consider using a parser
library like libclang or a macro-based reflection utility.

This PR also migrates SimpleViewer into libs/viewer and un-inlines its
implementation. It does not belong in gltfio because it has an imgui
dependency.
2020-09-29 10:47:35 -07:00
Pixelflinger cdb0f20c6c Save some ALU by assuming the shape of the projection matrix 2020-09-28 10:53:30 -07:00
Pixelflinger 4da58ecb29 Fix mediump issue on mobile 2020-09-28 10:53:30 -07:00
Pixelflinger 075486724f Add JNI support for SSCT 2020-09-28 10:53:30 -07:00
Pixelflinger 530f41c29c fix light vector transform 2020-09-28 10:53:30 -07:00
Pixelflinger 5cbd80136c control the number of rays per pixel 2020-09-28 10:53:30 -07:00
Pixelflinger bfd1de809a Implement screen space cone tracing (SSCT)
This is a technique from Naughty Dog used in TLOU2, where we compute
the "ambient" shadowing of a dominant light in screen-space.

This is currently integrated to the SSAO pass.
2020-09-28 10:53:30 -07:00
Pixelflinger 0f2993aec7 Decouple SSAO bilateral filter from quality setting 2020-09-28 10:53:30 -07:00
Pixelflinger e8bb895c58 refactor SSAO shader a bit
the main change here is that we now have ssaoUtils which contains
utilities that will soon be shared with other "ambiant" effects.
2020-09-28 10:53:30 -07:00
Benjamin Doherty 5cbb97551f Bump version to 1.9.3 2020-09-28 11:40:31 -06:00
Benjamin Doherty f7fc2a0af6 Update RELEASE_NOTES for 1.9.2 2020-09-28 11:34:32 -06:00
Benjamin Doherty 42733c10b7 Bump version to 1.9.2 2020-09-28 11:34:32 -06:00
Benjamin Doherty defee767c3 Merge branch 'rc/1.9.2' into release 2020-09-28 11:27:47 -06:00
Benjamin Doherty 9560318521 Update RELEASE_NOTES for 1.9.2 2020-09-28 11:26:21 -06:00
Philip Rideout d8c7bba403 gltfio: Fix animation by clamping the per-channel interpolant.
Tested with the model in #3124 as well as Fox, BusterDrone, CesiumMan,
InterpolationTest, and VC.

Fixes #3124.
2020-09-26 09:26:40 -07:00
Romain Guy 50e5db4347 Add tasks to manage Sonatype releases (#3127)
* Add tasks to manage Sonatype releases

* Edit comments
2020-09-25 16:07:12 -07:00
Philip Rideout 7019629bcb Vulkan: fix final image barrier used for swap chain.
The image barrier must wait until all write operations are complete;
this was not set up correctly but somehow did not cause problems.
Also tried to document this better, since using an image barrier for
the swap chain seems to be an unusual thing to do (e.g. the Sascha
Willems demos do not do this).
2020-09-25 09:40:12 -07:00
Philip Rideout 5549adc020 JavaScript bindings: fix TextureUsage bitmask.
There's no really good solution, so this just keeps it simple and makes
is so that embind consumes an integer rather than an embind enum object.

Tested by hacking _createTextureFromImageFile.

Fixes #3028.
2020-09-24 15:53:20 -07:00
Philip Rideout 947d178f2b matdbg: stable ordering for anonymous materials.
For example, this makes it so that the primary material in Sponza
is *always* "untitled 0", which makes it easier to figure out which
material to modify.
2020-09-24 10:23:58 -07:00
Philip Rideout 29cd7bb6b4 matdbg: use Shift+Ctrl for navigation.
This avoids interference with both the default VSCode bindings and
Mission Control.
2020-09-24 09:54:19 -07:00
Philip Rideout eb5d346e60 matdbg: repair keyboard navigation.
Recall that Ctrl + Up / Down navigates between materials while
Left / Right navigates between variants.

- Make this behavior more explicit in the documentation.
- Shortcuts now use the same ordering as the displayed list.
- Shortcuts now use Cmd on macOS instead of Ctrl to avoid conflict with
  Mission Control defaults.
2020-09-24 09:54:19 -07:00
Philip Rideout 1afb0e2ea4 matdbg: allow edits without trailing newline. 2020-09-24 09:54:11 -07:00
Philip Rideout 89485ae0ae matdbg: fix edits for large shaders.
If the websocket message exceeds a certain size, we might receive it
in chunks and civetweb does not auto-consolidate for us.

Fixed this by adding a length prefix to the edit command.
2020-09-24 09:53:59 -07:00
Philip Rideout 92e1e91261 matdbg: warn user when editing unused variant. 2020-09-24 09:53:59 -07:00
Philip Rideout ac07719414 CString should allow arbitrary data. 2020-09-24 09:53:59 -07:00
Philip Rideout 4a604c2513 matdbg: do not hide anonymous materials
This change also makes it so that matdbg shows a numeric suffix to help
with duplicated names, and fixes a bug with names that start with
non-alpha characters.
2020-09-23 16:03:03 -07:00
Philip Rideout 22312b2090 cmgen / mipgen: add opt-in for ASTC / ETC support.
Block compression is currently only used when we invoke mipgen for the
suzanne demo. This PR makes it easy to disable.

Block compression is still enabled in our CMake build, but other build
systems can simply omit BlockCompression.{h,cpp} from imageio (as well
as the two third_party libs) and it will "just work".
2020-09-23 11:17:27 -07:00
Philip Rideout 1ebdb18eae gltfio: add async cancellation API 2020-09-23 10:53:55 -07:00
Philip Rideout 450fe214f9 Flip the shading normal when det < 0.
This was tested by replacing the node 0 scale in BusterDrone with
[-1, 1, 1].

For future reference, commit f728776 shows when we switched from
transpose(inverse()) to cof(). This was a good change, but before that
particular change, we had a "two wrongs made a right" situation for
mirrored normals.

Fixes #3001.
2020-09-22 16:54:44 -07:00
Philip Rideout 97c1f99cab gltfio: Fix "uniform not found" errors.
The equality operator for MaterialKey was missing some fields (also, its
ordering was inconsistent with the struct), which caused faulty behavior
in the material cache.

I ran into this bug when testing against a Blender-exported model that
has some materials with texture transforms, and some without.
2020-09-22 14:12:47 -07:00
Romain Guy 9830925a96 Disable clear coat layer IOR change in glTF files (#3104)
The glTF spec doesn't call for this and there are extensions
to deal with this manually.
2020-09-21 20:40:35 -07:00
Pixelflinger c3975f2640 APIs to enable/disable screen space refraction
Just like with shadows, this is a toggle to entirely disable
screen space refraction.

Added missing getters, and minor refactoring.
2020-09-21 16:30:56 -07:00
Pixelflinger 6c8e134d01 Random engine should be owned by Engine
This way it can be used elsewhere.
2020-09-21 11:01:58 -07:00
Benjamin Doherty ef09feb048 Bump version to 1.9.2 2020-09-21 11:16:53 -06:00
Benjamin Doherty a0fb396ba4 Update RELEASE_NOTES headings 2020-09-21 11:08:57 -06:00
Benjamin Doherty b3a79bf82b Update RELEASE_NOTES for 1.9.1 2020-09-21 11:02:20 -06:00
Benjamin Doherty 35ace36b7d Bump version to 1.9.1 2020-09-21 11:02:11 -06:00
Benjamin Doherty 39f323fe09 Merge branch 'rc/1.9.1' into release 2020-09-21 11:00:07 -06:00
Benjamin Doherty 11b95304ea Merge branch 'release' into rc/1.9.1 2020-09-21 10:59:52 -06:00
Benjamin Doherty b7c30a7916 Update RELEASE_NOTES for 1.9.1 2020-09-21 10:59:06 -06:00
Pixelflinger 73f1ddfebf ssao: reduce creases caused by geometry tessellation
We borrow a page from the HBAO book here and allow to limit the angle
with the horizon of SSAO samples. This can help reducing the effects
of low tessellation, which tend to create unwanted creases with SSAO.
2020-09-20 22:34:34 -07:00
Pixelflinger ed8db2f58f fix a recent regression with contact shadows
contact shadows wouldn't work if shadowmap-based shadows were not
enabled, in this case the (unneeded) shadow pass would run and
attempt to create the shadow-map with an incorrect size (0), which
would later crash/assert in the backend.
2020-09-20 22:34:14 -07:00
Pixelflinger 06a13d2e25 remove remnants of when we had a depth preps
DEPTH_PREPASS is never set, not need to check for it.
2020-09-18 12:17:38 -07:00
Pixelflinger 377f043ded smooth out the transition from the background layer
This is a bit of a hack but it helps a lot -- for some reason the
background layer often has a sharp transition to the in-focus plane and 
because we're calculating the DoF at 1/4 resolution these transitions
are quite visible. We work around this by fading out the transition over
a 1 CoC unit, specifically between a CoC of 2 to 1 pixel. Below 1 pixel,
we currently clamp to 0.
2020-09-18 09:42:23 -07:00
Pixelflinger ea057ca754 fix typo -- ResourceAllocator is not in fg:: namespace anymore 2020-09-17 15:17:22 -07:00
Romain Guy 60ef6581c1 Fix compilation issue with clang 12 2020-09-17 10:02:08 -07:00
Romain Guy 2708b3d076 Initialize fields to nullptr to avoid crashes
This happens when a Texture with no callback is created.
2020-09-17 09:00:34 -07:00
Romain Guy 6dc278c551 Update cgltf (#3092)
Adds support for glTF extensions we want to support:
  KHR_materials_ior
  KHR_materials_specular
2020-09-17 08:52:30 -07:00
Pixelflinger e4c1557159 fix how we handle "emulated" MSRTT
The sidecar buffer for multisampled_render_to_texture emulation was
stored with the texture, instead of the rendertarget, this prevented
a single texture to be used as an attachment of multiple render targets
with different sample counts.
2020-09-16 17:36:41 -07:00
Pixelflinger 090c02b2cf non-sampleable textures didn't support "magic resolve"
There was an inconsistency in the gles backend where non-sampleable,
non-MS textures failed (assert) if they were used with a render target 
with MS (i.e. "magic resolve" case).

We fix this by taking the same code path for textures and renderbuffers,
the only difference being the calls to glFrameBufferRenderbuffer
instead of glFramebufferTexture2D.
2020-09-16 17:36:41 -07:00
Pixelflinger 86125ca72a fix use after free in the framegraph
resources structures where not cleared when destroyed, and some code
relies in the handles being set or not to decide if a texture should
be used.  in this case, the texture would be set in the shader after
it was destroyed, because its handle wasn't cleared.
2020-09-16 16:55:59 -07:00
Pixelflinger 14532a2e69 several fog fixes
- inScatteringSize actually cannot be set to zero because it produces
  a 0^0 in the shader. So with this change, in-scattering must be
  strictly > 0 to enable.

- inScatteringSize on the java side had an incorrect default value of
  zero (which of course, now doesn't matter anymore).

- also clamp the fog altitude to 1mm which simplifies the shader quite
  a bit for the same result.

Fixes #3069
2020-09-16 00:18:49 -07:00
Pixelflinger 2312d483c1 fix typo and static analysis warnings in libutils 2020-09-15 15:43:03 -07:00
Mathias Agopian 842425e784 code cleanup (typos and warnings) (#3082)
fix typos and some static analysis warnings
2020-09-15 08:33:03 -07:00
Pixelflinger 6211820a70 increase framegraph vector heap
this is needed now that shadows are using the framegraph
2020-09-14 22:23:13 -07:00
Pixelflinger dc16eb04f8 rename .blurScale to .cocScale in dof options
.blurScale was in fact a scale factor applied to the circle of
confusion (which makes it indeed a "blur scale", but let's use
a more precise language here). 

Update comments to show how to  use .cocScale to control the DoF
effect independently from the camera aperture, which can be useful for
artistic reasons.
2020-09-14 22:22:52 -07:00
Ben Doherty 15a24318e8 Render shadow passes with frame graph (#3073) 2020-09-14 15:57:40 -07:00
Ben Doherty c0bd3590b2 Support texture layers in frame graph (#3072) 2020-09-14 15:35:25 -07:00
Ben Doherty b1c78dfc8c Add branching guide (#3077) 2020-09-14 12:12:12 -07:00
Benjamin Doherty 4cae48fc77 Bump version to 1.9.1 2020-09-14 11:51:36 -07:00
Romain Guy 489e926635 Update README.md 2020-09-14 11:36:39 -07:00
Benjamin Doherty b7c38ef0f1 Update release notes for 1.9.0 2020-09-14 11:07:22 -07:00
Benjamin Doherty 38d37d0d59 Bump version to 1.9.0 2020-09-14 11:07:22 -07:00
Benjamin Doherty d1a93f0557 Update release notes for 1.9.0 2020-09-14 10:54:28 -07:00
Pixelflinger 5701ca939a Improvements to SSAO quality
- simulate a standard deviation of 8 by skipping every other pixel
  when blurring the AO buffer at LOW or MEDIuM quality. This creates
  a faint checker pattern, but does look much better than the low
  frequency noise that is introduced otherwise.

- tweak AO parameters to give a more uniform and smooth AO effect by
  default. This also makes AO even more consistant between quality
  modes.

- add a simple dithering stage to AO blur to help eliminate banding
  artifacts at higher sample counts.
2020-09-13 20:26:11 -07:00
Benjamin Doherty 014abbfb63 Fix documentation bug 2020-09-11 15:43:20 -07:00
Benjamin Doherty f097ec7d5a Fix const warning 2020-09-11 15:00:40 -07:00
Ben Doherty be8bd92a34 Remove Google-style line directives driver-side (#3064) 2020-09-11 11:59:50 -07:00
Pixelflinger fb42817304 add float versions of math constants to libmath
e.g. `F_PI` is also available as `d::PI` and `f::PI` as `double` or
`float` respectively.

Most of our uses of those constants are `float` and it was error prone
and cumbersome to have to cast to that each time we used them.

The `F_` constants are intended to mimic `math.h`, however these new
constants are not, and all the "n over" constants are named
`N_OVER_` instead of `N_`, which helps avoiding the confusion that e.g.:
`F_2_PI` is actually `2/pi` and not `2*pi`.

Also added `F_TAU` which is 2 * PI.
2020-09-10 15:39:16 -07:00
Romain Guy c92ebada6f Fix simpler viewer UI, add SSAO options 2020-09-10 09:17:40 -07:00
Pixelflinger c3c535e256 bilateral blur is more configurable
all parameters of the bilateral blur can now be set from the CPU, 
instead of being hardcoded -- this probably prevent the shader compiler
from unrolling the filter, but it's also probably not a big deal.

additionally, we now use a kernel size of 23 (12 samples) when the
SSAO quality is set to HIGH or more.

ssaogen is no longer needed

Higher quality levels used to darken the ssao a lot, now they all have
a consistant look.

Add quality control to material sandbox.

Slightly simplify shader code.
2020-09-09 18:15:31 -07:00
daichen 6c25f5e50f CoroutineScope job should be canceled before destory (#3056) 2020-09-08 21:31:26 -07:00
Pixelflinger b57510cb3c attempt at a better noise for SSAO
We add noise do the radius of the samples on the spiral 
(instead of adding noise only to the angle), this reduces a visible
"echo", especially at higher radii.
2020-09-08 19:17:02 -07:00
Pixelflinger 69d9a178bf rework a bit dithering noise
- don't use frameUniform.time as the temporal noise seed because
  this has a cycle to it. It's not very visible on dithering but
  obvious when used for other things.

- don't use fract(time) since time was already in [0,1] -- though it's
  moot now.

- instead of time pass a random number in [0,1] generated on the CPU
  each frame.
  This will also allow to control temporal noise more easily if
  needed in the future (e.g. for accessibility or rendering tests)
2020-09-08 13:54:54 -07:00
Benjamin Doherty b93059fad7 Bump version to 1.9.0 2020-09-08 10:47:23 -07:00
Ben Doherty 4ddd28a542 Update GitHub workflows to build release and release candidate branches (#3052) 2020-09-08 10:28:13 -07:00
Romain Guy 3092063ebb Revert recent change to depth_main
This shader is only used when the user doesn't specify anything that
could affect depth rendering. As such it must not attemp to read
material inputs.
2020-09-04 10:19:06 -07:00
Pixelflinger b1070c6508 ssao code improvements and bug fixes
- fix a recent typo that affected SSAO quality
- add a upsampling quality checkbox in material_sandbox
- make use of textureLodOffset instead of texelFetch, so that
  we emulate more closely textureGather
- don't hardcode bilateral filter edge-distance in the shader
  (still hardcoded on the cpu side)
2020-09-03 22:44:48 -07:00
Ben Doherty 604e4ea77d Add VSM control to SimpleViewer (#3043) 2020-09-03 15:52:29 -07:00
Romain Guy 949855f1c8 Update README.md 2020-09-03 09:21:17 -07:00
Romain Guy e984d92968 Update release notes 2020-09-03 09:20:16 -07:00
Pixelflinger 915c4d89f3 don't do the "reverse-z" in the shader for shadows
it can be done more easily on the cpu side
2020-09-02 20:52:46 -07:00
Pixelflinger 7fb1b853ac fix dynamic lighting frozen calculation
this broke recently with the reverse-z, the froxel calculation relies
on the depth, which is now inverted.

we actually fix our getNormalizedViewportCorrd() public API, which the
froxel code uses.
2020-09-02 15:13:34 -07:00
Mathias Agopian 513b3b8c3a improve stability of DoF with highlights (#3035)
apply the "fireflies" reduction during the downsampling pass instead of
the mipmap pass -- which didn't make a lot of sense.
2020-09-02 14:20:23 -07:00
Pixelflinger f1b310ba0f minor refactor + comments in the main render pass
This just move the "finish color passes" pass before TAA and 
depth-resolve, where it belongs.
2020-09-02 09:18:13 -07:00
Pixelflinger 6329b865cf New API to create an Engine asynchronously
Because initializing the backend can be relatively slow, creating an
Engine can block the main thread, is this is a problem, this new API
can be used instead; while a bit more complex, it allow the engine to
be initialized asynchronously.
2020-09-01 15:34:04 -07:00
Pixelflinger 13cfad43b7 Use "inverted-Z" depth buffer
This significantly improve the depth-buffer resolution utilization
through the near-infinity range on Metal and Vulkan.

On OpenGL, this benefit is only seen when glClipControl is available.

The user-facing clip plane is unchanged [-1,1], the conversion
happens in filament's vertex shaders.


The bulk of this change consists in:

- invert the clip space's z in the vertex shader
- clear the depth buffer with 0
- invert all depth function comparisons
- fix all screen-space effects, e.g. ssao, DoF
- fix shadows and shadow biases
- use floating-point depth
- add a driver API to query which clip-space is used
- add glClipControl support to the gl backend
2020-09-01 09:46:46 -07:00
Pixelflinger bb8cd6677d optionally compress highlights before bloom
This avoid unrealistic looking bloom halos from very strong highlights.
This is enabled by default.
2020-09-01 09:46:23 -07:00
Romain Guy 35ed1cb906 Update release notes 2020-08-31 13:52:04 -07:00
Pixelflinger bcd8ce3c93 fix refraction + MSAA + TAA (depth resolve)
the depth buffer wasn't resolved in this case. We fix this by always
creating a depth buffer resolve pass -- which is a lot more robust.
this pass automatically culled if the depth is not used (i.e. TAA or 
DoF are off). The pass is a no-op if resolving is not needed.
2020-08-31 12:00:41 -07:00
Pixelflinger 84f0e97c78 apply the material clip-space transform to the depth 2020-08-31 11:59:52 -07:00
Philip Rideout ae9504cbf9 Remove third_party/swiftshader.
These standard headers were unused, we already have them elsewhere in
the repo.
2020-08-31 11:34:07 -07:00
Philip Rideout 696327b35a Add SwiftShader to BUILDING.md 2020-08-31 11:34:07 -07:00
Pixelflinger 1a95c2b39b Fix a few issues with alpha-masked objects
- don't apply SSAO to blended objects
  these are not drawn into the structure buffer, so they don't 
  participate in SSAO.

- remove unused code that was needed for the depth prepass, which
  simplifies handling of blended objects.

- always treat alpha-masked objects as opaque.
2020-08-28 17:27:54 -07:00
toppa102 07393d6237 Changed ifdef WIN32 to WIN32 or _WIN32 (#3022) 2020-08-28 11:27:31 -07:00
Philip Rideout 2f294549a7 Migrate the SwiftShader build to Vulkan.
This also adds a -t flag to the easy build script for convenience.

SwiftShader on Vulkan can now be used as follows.

    git clone https://github.com/google/swiftshader.git
    cd swiftshader/build
    cmake .. &&  make -j && export SWIFTSHADER_LD_LIBRARY_PATH=`pwd`
    cd ../filament
    ./build.sh -t debug && ./out/cmake-debug/samples/gltf_viewer -a vulkan

Note that third_party/swiftshader does not need to exist since we
already have Vulkan headers. I will remove it in a subsequent PR.
2020-08-28 09:47:29 -07:00
Philip Rideout 2732d3ac13 Vulkan: Add support for VK_EXT_debug_utils.
Motivated by upcoming SwiftShader support, The old debug_report
extension is apparently deprecated but we need to keep it alive
for Android.
2020-08-28 09:46:49 -07:00
Pixelflinger d7f7ab7aa4 fix a whole screen flicker when enabling TAA
the history projection wasn't initialized for the first frame.
2020-08-27 17:57:55 -07:00
Philip Rideout 0aa23945bb Do not pass a zero sample count to the backend.
FrameGraphTexture::Descriptor uses "0" to mean "auto" but the
sample count that is passed to the backend should always be 1 or
greater.

See also #2957.
2020-08-27 17:10:08 -07:00
Pixelflinger 6f5ff9dd4b render passes now also specify the depth range 2020-08-27 16:54:13 -07:00
Ben Doherty 8f32c9ad98 Handle blitting only depth in Metal backend (#3007) 2020-08-27 11:04:34 -07:00
Yadikaer Yasheng c529a511f5 typescript defs for Texture & RenderTarget APIs (#3008)
* typescript defs for Texture &   RenderTarget APIs

* suggest to use helper functions to create textures
2020-08-26 18:52:07 -07:00
Pixelflinger ab9c14d336 better multisample setup for depth buffer in color pass
The depth buffer was always set with a sample count of 1, this was
mostly moot because we almost never need the depth buffer after the
color pass; except for refraction and DoF.

In the case of refraction, we need to preserve the MS depth buffer
(just like we preserve the MS color buffer), moreover "backward resolve"
is not supported. So in that case, the depth buffer needed to be set to
MSAA samples.

In the case of DoF, we need to access a resolved depth texture, and
there is 2 cases here:
1) without refraction, a magic resolve is adequate -- in this case
   the depth MS count must be 1.
2) with refraction, we are forced in to a MS depth, so it needs a
   special resolve pass to be accessible from DoF.
2020-08-26 16:57:23 -07:00
Pixelflinger 6c471bc98c improve resolve pass so it works with depth buffers 2020-08-26 16:57:23 -07:00
Pixelflinger 96dc7c62d9 depth/stencil attachment's sample count validation
depth/stencil attachments must have the same MS sample count
than the FBO (rt) they're attached to.
this is because EXT_multisampled_render_to_texture[2] doesn't
resolve depth attachments. In this case, we can't use this extension.
2020-08-26 16:57:23 -07:00
Pixelflinger a33b418478 EXT_multisampled_render_to_texture only support COLOR_ATTACHMENT0
For other attachments, we need EXT_multisampled_render_to_texture2.
2020-08-26 16:57:23 -07:00
Pixelflinger 037aa08cf2 remove support for "reverse multisample resolve"
- We will never allow this.
- minor code formating
2020-08-26 16:57:23 -07:00
Ben Doherty bde0b477e0 Add ShadowType API and VSM rendering logic (#3004) 2020-08-26 15:41:08 -07:00
Philip Rideout a922caed6b Vulkan: fix clear value list with MSAA. 2020-08-25 17:24:24 -07:00
Philip Rideout 040adc7fef Vulkan: add support for MSAA render targets.
This does not include lazy allocation or support for an MSAA swap chain.
Those features will come later.
2020-08-25 17:24:24 -07:00
Philip Rideout 079fda2e74 Fix VSCode warning. 2020-08-25 17:24:24 -07:00
Philip Rideout 3258972e0e WebGL: repair beginFrame() bindings.
This regressed when we added a callback argument, because the callback
cannot be bound.

This commit also modifies the helmet example to use the low-level API
for testing purposes.

Note that this omits the optional nanoseconds argument. JavaScript
does not support overloading and this argument probably cannot be
accurately provided anyway in a web environment.

Fixes #3002.
2020-08-25 17:24:04 -07:00
Philip Rideout 79b7e15c7b Vulkan + Metal: fix bad cache gc due to unsigned overflow.
This fixes a Vulkan validation error seen on Android about destroying a
framebuffer that is still in use by an active command buffer.
2020-08-25 10:56:27 -07:00
Ben Doherty 49cfbe79eb Add asserts to avoid loading into the MSAA sidecar texture (#2998) 2020-08-25 10:44:25 -07:00
Philip Rideout 44f4061227 Vulkan: request the driver info extension. 2020-08-24 17:35:17 -07:00
Philip RideoutandBen Doherty fe280c0c3b BUILDING.md, add Windows hints. (#2997)
* BUILDING.md, add Windows hints.

* Update BUILDING.md

Co-authored-by: Ben Doherty <bendoherty@google.com>

* Update BUILDING.md

Co-authored-by: Ben Doherty <bendoherty@google.com>

Co-authored-by: Ben Doherty <bendoherty@google.com>
2020-08-24 13:42:31 -07:00
Philip Rideout 86946acf08 Vulkan: log driver version info.
This is useful to see which version of MoltenVK is actually being used.
2020-08-24 10:16:25 -07:00
Philip Rideout 29bb48be09 Regenerate BlueVK. 2020-08-22 11:57:58 -07:00
Pixelflinger a528c0367c cleanup gl context init 2020-08-21 19:46:28 -07:00
Philip Rideout 6d733091e0 Update our BlueVK generator and prep for new headers. 2020-08-21 16:46:05 -07:00
Philip Rideout b656918c4d Update MoltenVK and its README.
LunarG stopped releasing tarballs for macOS, they use dmg files now.
2020-08-21 16:45:52 -07:00
Ben Doherty d3c1964822 Fix IBL loading bug with missing cubemap levels (#2986) 2020-08-21 16:07:22 -07:00
Philip Rideout cf6c518aea FrameGraph: add graphviz labels for size and MSAA. 2020-08-21 11:26:15 -07:00
Ben Doherty af2fc39bad Add JNI bindings for CSM (#2979)
* Add JNI bindings for CSM

* Fix Windows build

* Fix jovadoc
2020-08-21 10:21:31 -07:00
Philip Rideout 83b35e5ac2 Refraction: enable SUBPASS usage flag.
This was causing a Vulkan error when refraction was enabled.
2020-08-21 09:38:35 -07:00
Pixelflinger 67030982ec minor improvements and cleanups
- more flexible linearization of depth, doesn't impact performance
  at all in the shader, but takes into account 3 parameters of
  the projection matrix instead of true. Mathematically identical
  to before.

- use depth test "less or equal" for depth only passes to be consistant
  with the color pass. Unsure if using "less" would be better.

- use textureLod() when sampling the skybox

- use mediump for all samplers in the shadowing.fs, which correspond to
  their actual definition.
2020-08-21 09:34:38 -07:00
Pixelflinger 0aea56e22d slightly improve the depth_test
we just make the output more readable
2020-08-21 01:39:08 -07:00
Philip Rideout 9c7a8fef24 Fix Windows build. 2020-08-20 10:16:11 -07:00
Philip Rideout 5b0e01329a Vulkan: add very simple cache of VkImageView.
Filament calls createRenderTarget very frequently, so this PR has the
side effect of reducing a huge amount of create-destroy churn in other
Vulkan objects such as VkRenderPass and VkFramebuffer.
2020-08-20 09:39:33 -07:00
Philip Rideout 7950b83b58 Vulkan: fix leak of VkRenderPass objects. 2020-08-19 18:39:22 -07:00
Benjamin Doherty af99270aaa Fix another VSM shader error 2020-08-19 14:08:18 -07:00
Ben Doherty 76fe0e36fb Fix VSM shader error (#2975) 2020-08-19 14:05:12 -07:00
Pixelflinger 4e3bb9c7c8 fix translucent views with custom render targets
Marking a view with a custom render target will now disable blending
for that view but require an alpha channel for intermediate buffers.
Blending is disabled because it is meaningless.

fixes #2802
2020-08-19 11:55:13 -07:00
Ben Doherty 3e5d9fa0b4 Add VSM shader changes (#2971) 2020-08-19 10:56:48 -07:00
Philip Rideout 331d7c3e00 Repair Vulkan after vkalloc upgrade. 2020-08-18 11:15:25 -07:00
Philip Rideout 345455cf24 Update vkmemalloc. 2020-08-18 11:12:26 -07:00
Romain Guy 29a33ef215 Fix formatting error 2020-08-18 10:29:44 -07:00
Philip Rideout 7ca281d2b9 Expose ShadowOptions to JS, fix #2958. 2020-08-18 09:44:55 -07:00
Ben Doherty ce37315ef9 Add new lightPosition uniform (#2969) 2020-08-17 18:01:24 -07:00
Ben Doherty d3e3974179 Add new shader variants for VSM (#2968) 2020-08-17 18:00:01 -07:00
Ben Doherty 785c11a240 Metal: resolve MSAA textures to correct level / slice (#2967) 2020-08-17 12:46:42 -07:00
MorphTail 4dfc78674d Add documentation for cmgen (#2966)
* Create cmgen README

* add more description for --size attribute

resolve #454

* Update README.md
2020-08-17 11:50:59 -07:00
Philip Rideout 1c726fcef6 DriverAPI sample count should be > 0.
For single-sampled textures we were using 0 in some places and 1 in some
places. It's better to be consistent.
2020-08-14 14:49:03 -07:00
Philip Rideout 897593a8ed Vulkan: fix bad shadow map boundaries.
This fixes the long-standing "black rectangle" issue in our shadowtest
sample.

We were mistakenly constraining the clear to the viewport, which
is meant only to affect the vertex pipeline.

Also, we were needlessly setting the scissor rect in BeginRenderPass(),
since we already do so in Draw().
2020-08-14 12:12:24 -07:00
Pixelflinger 4f58be1ef1 minor micro optimizations 2020-08-13 23:44:38 -07:00
Ben Doherty 003911f0ec Set the model matrix and projection separately for shadow cameras (#2951) 2020-08-13 15:07:23 -07:00
Ben Doherty de377c8e37 Apply clipspace fixup in GLSLPostProcessor (#2950) 2020-08-13 12:14:29 -07:00
Romain Guy bf59b04ad0 Update release notes. 2020-08-13 11:20:01 -07:00
Ben Doherty d14e29d4d3 Audit material variants (#2948) 2020-08-13 10:58:27 -07:00
Pixelflinger afaac3f18c Allow color-gradding-as-subpass with TAA
while support for this is added, this is disabled because
it is actually ~0.5ms slower on qualcomm devices.
2020-08-12 22:25:10 -07:00
Philip Rideout 68c647abdb Metal: use explicit shader fixup for clip space Z.
This is more similar to the Vulkan shader pipeline and less magical.

There are 3 places in our shader code where we perform fixups like this:

- main.vs
- depth_main.vs
- post_process_getters.vs

That last one needs no change since it does not involve Z.
2020-08-12 21:12:42 -07:00
Pixelflinger 7852a9b8cb Add public APIs for texture 3D and texture 2D arrays
Also cleanup all setImage() error reporting. All error checks are
changed from silent to NON_FATAL_ASSERT, which means they'll throw
if exceptions are enabled or do a no-op and log a message otherwise.

Also added more precondition checks.
2020-08-12 17:32:46 -07:00
Philip Rideout acdb8addfd Vulkan: enforce constraints for scissor / renderArea / blit. 2020-08-12 16:55:18 -07:00
Ben Doherty faa785f3f6 Switch to C++17 (#2940) 2020-08-12 15:21:39 -07:00
Philip Rideout a0a8d62587 Vulkan: fix rotation on Android. 2020-08-12 13:25:08 -07:00
Pixelflinger 681f8fae2e fix incorrect assert in GL backend
Fixes #1966
2020-08-12 12:54:18 -07:00
Philip Rideout 4d48cac0aa Vulkan: fix regression with window resizing. 2020-08-12 10:31:37 -07:00
Richard Chang 4d51042170 Add back proguard file for Android (#2933)
* Add back proguard file for Android and update README.md

The proguard-rules.pro file provided by Jeff McGlynn (9fe60a636)
works perfectly for Android projects with minifyEnabled.
Add the config file back to the repository and update README.md
to help other Android users setup release build.

* Refine android proguard file and remove proguard section in README.md
2020-08-12 10:08:53 -07:00
Philip Rideout 2dec7f7996 Fix Windows build. 2020-08-11 18:29:52 -07:00
Philip Rideout 0b653273dc Vulkan: fix zealous frame skipping on Android.
The stride passed to Vulkan for query pools is the stride between
queries, not the stride between individual values. I realized this after
seeing the SwiftShader implementation of queries.

I also used log statements to confirm that this fixes bogus frame
skipping on my Pixel 4.
2020-08-11 16:52:07 -07:00
Philip Rideout b45d45048c Vulkan: fix Android after pause / resume.
This fixes the visual hang that would occur after going to the task
switcher and back.

After recreating the swap chain, all of its associated fences and sync
objects become invalid. Since we were not tracking this, FrameSkipper
was going into an infinite wait after the swap chain was created.
2020-08-11 16:51:45 -07:00
Philip Rideout fb8c51c5e1 Fix resizing issues with MoltenVK.
This removes the old getClientExtent stuff that I added a while back,
and replaces it with the strategy espoused by the MoltenVK author found
here:

https://github.com/KhronosGroup/MoltenVK/issues/428

I tested this PR on macOS with Vulkan and Metal. I tested both on high
and low DPI displays. I also tried dragging the window between the two
displays.

Android still has issues with rotation, I will deal with that next.

cleanup
2020-08-11 16:51:23 -07:00
Pixelflinger 6a47924482 make use of textureLodOffet where appropriate
this really makes the code easier to read and has a chance to be
more efficient
2020-08-11 10:39:56 -07:00
Philip Rideout 8fdcd8fa62 Vulkan: allow blit to default render target.
This fixes a null pointer exception that we saw after disabling several
View -process effects.
2020-08-11 09:24:29 -07:00
Philip Rideout 6b6f80562f Vulkan: add null checks for Molten. 2020-08-11 09:24:29 -07:00
Pixelflinger 08e411aeac API CHANGE: make ssao options work like all other options
setAmbientOcclusion (and associates) is now deprecated (but still works),
in favor of the new .enabled field in AmbientOcclusionOptions.
2020-08-10 17:23:03 -07:00
Pixelflinger b3c57a4ee1 add TAA controls in material_sandbox 2020-08-10 13:30:05 -07:00
Pixelflinger 0947f80974 TAA: tweak quality parameters for mobile
on mobile we only use the variance box instead of
min/max+variance, this saves a few hundred us.
2020-08-10 11:14:34 -07:00
Pixelflinger 8155bf04a8 Implement variance clamping
variance clamping further shrinks the min/max AABB
2020-08-10 11:14:34 -07:00
Pixelflinger 815483c5e0 execute structure pass before TAA
This fixes a lot of flickering when SSAO and TAA are enabled.
SSAO TAA shouldn't be done based on a jittered depth buffer, but
rather on jittered samples.
2020-08-10 11:14:34 -07:00
Pixelflinger 05bfa632ff Add TAA java bindings 2020-08-10 11:14:34 -07:00
ruitaocc 931daf3a69 fix typo 2020-08-10 08:58:24 -07:00
Pixelflinger 4821a95f16 Implement basic tamporal antialiasing (TAA)
while this started as a sample to demonstrate how to use the new
frame history feature, this is now solid enough to become a feature.

this version of TAA doesn't use motion vectors, so it is prone to
various artifacts (e.g. ghosting). It also has the typical issues
TAA has (e.g. transparents).

with that said, performace is good and quality is overall superior
to FXAA or MSAAx4.
2020-08-07 20:51:46 -07:00
Romain Guy 4c0a5b5f1d CMake cleanup 2020-08-07 14:21:27 -07:00
@roxlu ☾ 4ba95428c2 New options that allow you to specify the buffer sizes. (#2925)
* New options that allow you to specify the buffer sizes.

* Removed debug info

* Style/location fixes
2020-08-07 14:17:44 -07:00
Philip Rideout 732a6c08de Add Texture getters to IndirectLight and Skybox.
Fixes #2851.
2020-08-07 11:49:24 -07:00
Romain Guy 0584cea125 Update website 2020-08-07 11:02:38 -07:00
Romain Guy 058c9cd28b Update docs 2020-08-07 10:55:11 -07:00
Romain Guy 2ce3b88a13 Fix ccache scripts 2020-08-07 09:03:51 -07:00
Philip Rideout c7c1c01a0e JavaScript: fix typo in clearAssetCache. 2020-08-06 16:47:29 -07:00
Philip Rideout 827e73b682 JavaScript: add clearAssetCache helper. 2020-08-06 16:41:35 -07:00
Philip Rideout 7ada8372f2 gltf_viewer: fix ColorGrading leak. 2020-08-06 15:12:53 -07:00
Philip Rideout 749a4d01af gltfio: fix some small memory leaks.
This fixes two oversights in the FilamentAsset destructor:

- Destroy the faux root Entity.
- If it exists, remove the name component from each Entity.
2020-08-06 15:12:53 -07:00
Philip Rideout f4004cf047 JavaScript bindings: fix a frequent 4-byte memory leak.
In retrospect, I should've exposed ints to JS instead of entities.
Making this fix is already a TODO, but it will be a tedious change. For
now, this PR fixes two issues that were causing tiny but frequent memory
leaks, according to the emscripten memory leak widget.

(1) Do not include Entity in the list of classes that should only be
passed around by pointer.

(2) Clients should always call delete() on returned Entities.
2020-08-06 14:45:28 -07:00
Philip Rideout dc74ee2ddc Refactor CallbackUtils. 2020-08-05 17:27:12 -07:00
Philip Rideout 2727cddd7a TextureHelper: add overload with a release callback.
Fixes #2909.
2020-08-05 17:27:12 -07:00
Pixelflinger 4f239c3e3c fix a moveResource which was broken recently
a recent fix actually badly broke moveResource, we were using the
index of the newly created resource instead of the pass index.
2020-08-05 13:10:16 -07:00
Philip Rideout 4bf0d0c0a8 Web: Remove broken webpack example.
This example has fallen out of date, I tried to resurrect it but it
turned out to be non-trivial, given the special nature of emscripten's
generated JavaScript wrappers.

It might be better to provide an example that uses rollup, since that's
the bundler that model-viewer uses, or a simple TypeScript example.

For now, I think our simple HTML + raw JS samples are sufficient.
2020-08-05 11:19:08 -07:00
Pixelflinger d70f1c0ab2 Infrastructure for frame history data
We can now save an arbitrary (but decided at compile time) number of
entries containing information about previous frames and it for while
drawing the current frame. Typically this is used for such effects as
TAA, screen-space reflection, building probes over time, etc...

Currently the frame history consists of one frame per View. FView 
provides a new (internal) getFrameHistory() method used to access
previous frames entries as well as to save the current's frame
information.

The FrameGraphPassResources (which is available in the execute closure
of a FrameGraph pass) has a new detach() method which can be used to
remove that resource from the FrameGraph lifetime management, at which
point it becomes the responsibility of the caller. Typically this
resource will be stored in the frame history.
2020-08-04 15:01:09 -07:00
Pixelflinger 991861a512 make fg resources creation/destruction more generic
creation/destruction now takes a ResourceAllocatorInterface instead of
a FrameGraph.
2020-08-04 15:01:09 -07:00
Pixelflinger d0367a359b move ResourceAllocator out of the fg namespace 2020-08-04 15:01:09 -07:00
Mathias Agopian d2be23045f fix a FG crasher when we have more than 32 passes (#2911)
The FrameGraph cannot store pointers internally because all objects
are stored in vectors. Unfortunately we were storing the writer of
resources as a pointer. 

This is fixed by storing an index instead.
2020-08-04 15:00:38 -07:00
Ben Doherty 4cb903a09e Fix variant-limiting bug in matdbg (#2903) 2020-08-03 11:16:33 -07:00
Philip Rideout 3ca0a8cd8d Transmission should use FADE. (#2908)
Fixed #2907.
2020-08-03 10:51:26 -07:00
Philip Rideout 2c18d7f576 Revert "Transmission should use FADE."
This reverts commit 379f92417f.
2020-08-03 10:45:46 -07:00
Philip Rideout 379f92417f Transmission should use FADE.
Fixed #2907
2020-08-03 10:44:15 -07:00
Ben Doherty 13574f793c Run MergeReturnPass only on mobile (#2901) 2020-07-31 18:40:47 -07:00
Ben Doherty f69ba63046 Don't crash for invalid Metal programs when using matdbg (#2902) 2020-07-31 18:39:57 -07:00
Pixelflinger a13620c66d reorganize material folder
Sets of post-process materials are in their own folder now.

Also moved fxaa.fs from shaders/ to materials/ so it's next to the 
material that includes it. This file is not shared with any other
material.
2020-07-31 10:36:44 -07:00
Pixelflinger b4a35c3ee2 fxaa: highp precision seems overkill 2020-07-30 23:46:09 -07:00
Ben Doherty a4e3e0c2d1 Ignore commented-out #includes in material files (#2897) 2020-07-30 18:46:16 -07:00
Ben Doherty 1a85c93894 Fix DEBUG identifier used in Log.h (#2895) 2020-07-30 16:43:42 -07:00
Philip Rideout 2c114a9a9f Add mask smoothing to the unlit path. 2020-07-30 15:14:46 -07:00
Philip Rideout f4d8753c24 MASKED mode now leaves destination alpha intact.
This prevents strange behavior with semi-transparent render targets,
which the model viewer team discovered when testing against the Khronos
alpha test conformance model.
2020-07-30 15:14:46 -07:00
Ben Doherty 6f28da4798 Fix Podspec for 1.8.1 (#2894) 2020-07-30 13:54:12 -07:00
Philip Rideout a6390355da Fix typos. 2020-07-30 13:50:51 -07:00
Romain Guy a120e0a4bb Filament 1.8.1 2020-07-30 12:25:53 -07:00
Romain Guy 642fb5859b Filament 1.8.1 2020-07-30 12:18:38 -07:00
Philip Rideout b4623c9afc Add lightroom IBL, enable ColorGrading by default in gltf_viewer.
The non-legacy ACES is now default, it looks much better.

I also tested this IBL with WebGL and Android.
2020-07-30 11:39:36 -07:00
ruitaocai c4546f1777 fix typo (#2892) 2020-07-29 22:46:50 -07:00
Pixelflinger ea5e8c2d14 fix refraction roughness when specular AA is active 2020-07-29 16:36:24 -07:00
Philip Rideout 440687e05a Add JavaScript bindings for Fog and Vignette. 2020-07-29 15:01:05 -07:00
Mathias Agopian bd30abb168 attempt to reduce code size in PostProcessManager (#2880)
* attempt to reduce code size in PostProcessManager

The two main changes are:
- materials are now stored in a hash map which allows us to
  automatically destroy all of them using one loop -- instead of
  having to call terminate() for each of them.

- factored a very common sequence of code:
  commit()
  use()
  beginRenderPass()
  draw()
  endRenderPass()

  This makes the code easier to write and also results in less code.

There are also minor other changes, e.g. RenderPass constructor is not
inline anymore.
2020-07-29 13:01:23 -07:00
Pixelflinger d15a906855 multithread the conversion to RGB10_A2
we just move the conversion code into the already existing jobs.
2020-07-29 12:59:55 -07:00
Philip Rideout 7584a7bebe Merge pull request #2885 from google/pr/jscolorgrading
WebGL: use color grading in demo, expose destroy.
2020-07-29 12:22:11 -07:00
Philip Rideout 8f3f30e9cd gltfio: fix depth writes for transmissive materials.
This fixes the depth fighting in the column of red spheres in the test
model while in filamat mode. Thanks Romain for catching this.

It also makes filamat mode more consistent with ubershader mode.
2020-07-29 11:55:21 -07:00
Philip Rideout 664e7b8a8d ColorGrading: add JavaScript and TypeScript bindings.
This is not tested but seems fairly straightforward.
2020-07-28 14:45:51 -07:00
Philip Rideout aa5f88ae0f WebGL: Add workaround for skinning with Emscripten.
So...we use integers for bone indices, and that makes them special. :)

On May 26, the emsdk WebGL 2.0 wrapper for the integer variant of
VertexAttribPointer was broken due to an incomplete renaming operation
from an emscripten contributor.

I have a pending upstream fix to the emscripten repo (#11742) but for
now we can workaround this with a simple monkeypatch.

Fixes #2856.
2020-07-28 09:21:27 -07:00
Pixelflinger 6f5e04d489 enforce correct type with printf-style logs 2020-07-27 14:06:48 -07:00
Ben Doherty 2113c9a3be Fix Metal crash when >16 samplers are bound (#2873) 2020-07-27 13:18:13 -07:00
Pixelflinger b0d4934d02 Add validation for Texture::setImage()
We now validate supported combinations of internalFormat vs. format/type.
We currently follow the GLES specification, but we could be more 
restrictive if needed for vulkan/metal.

The validation terminates in debug builds and logs (and becomes a no-op)
in release builds.
2020-07-27 11:22:41 -07:00
Philip Rideout 2f4dd0bbd4 sample-page-curl: add comments to variables, etc. 2020-07-27 07:35:58 -07:00
Pixelflinger e34db6fc29 fix a few issues with color grading
- we were not clamping the color grading output to [0,1]

- we were not using a supported input (cpu) pixel format for the
  3d LUT in low and medium quality
2020-07-24 17:24:51 -07:00
Pixelflinger 087e2480d1 DoF: fix tiles dilate pass edges
We were using texelFetch which doesn't handle wrap modes, and this
resulted in all edge tiles to be undefined. Use textureLod() instead.
2020-07-24 11:38:26 -07:00
Ben Doherty 45efe2df75 CSM: allow setting individual split positions (#2835) 2020-07-24 11:04:28 -07:00
Ben Doherty 85ae21fa26 Remove Google-style line directives in filamat lite (#2860) 2020-07-24 11:04:01 -07:00
Pixelflinger 77939ad269 DoF: improve quality in "fast tiles"
fast tiles (i.e. where all pixels have the same circle-of-confusion)
are allowed to use bilinear filtering.
this results in better looking DoF in these areas.
2020-07-23 22:49:13 -07:00
Tim Psiaki 4a59e6e1ce Fix node hierarchy corruption when a node is set to parentless. 2020-07-23 22:48:40 -07:00
Pixelflinger ca68ef22e1 update glslang to latest
glslang repo SHA: f3cb1896971f449706bb1df5053d0e8fad6b0675


This fixes another highp bug.
2020-07-23 16:11:14 -07:00
Pixelflinger 7067500a9c DoF: improve quality
Using a ring density of 4 was wrong -- apparently I can't add.
With a density of 8 we can guarantee we don't have gaps between samples
when using mips properly (or at least gaps are consistant and 
predictable).
2020-07-23 13:52:24 -07:00
Romain Guy 6ed1fb3b7b Add quality option to ColorGrading (#2858)
* Add quality option to ColorGrading

Low: 16x16x16 LUT in 10 bit
Medium: 32x32x32 LUT in 10 bit
High: 32x32x32 LUT in 16 bit
Ultra: 64x64x64 LUT in 16 bit

* Move comment
2020-07-23 13:49:01 -07:00
Romain Guy 1613c1bb0e Ensure we respect the desired size on layout change (#2859) 2020-07-23 12:45:02 -07:00
Richard Chang 1162ae4ddc Fix typo in SurfaceOrientation jni wrapper (#2853) 2020-07-23 09:06:26 -07:00
Ben Doherty a25179b91e Update imgui to v1.77 (#2834) 2020-07-22 16:15:31 -07:00
Pixelflinger 81388ab4b4 DoF: bug fixes and quality improvements
- Use the random offset to calculate the correct intersection radius.
  For the center sample, the ring radius is otherwise zero, which means
  any sample in the random disk with a CoC radius > 0 would intersect,
  and that seems wrong.

- The selected mip was off by one.
  We were always picking a mip too high because the CoC are in
  high resolution, but our mip-chain is 1/4 res from that.
  This improves rendering quality quite a lot.
2020-07-22 15:22:28 -07:00
Pixelflinger ec9fd58fc0 use more inclusive language 2020-07-22 15:20:54 -07:00
Ben Doherty b786b486b6 Add getCullingProjectionMatrix JNI method (#2847) 2020-07-22 15:12:03 -07:00
Romain Guy 06b191cd53 Fix broken IBLs (#2850) 2020-07-22 14:02:49 -07:00
Philip Rideout cd168148d8 gltfio for web: add and use destroyAsset.
Fixes #2839.
2020-07-22 13:40:08 -07:00
Philip Rideout 0da20cccdc Introduce removeEntities API / fix leak in ModelViewer (!)
For testing purposes, sample-gltf-viewer reloads the model when the
user double-taps the screen. This operation was causing a buildup of
blank entities in the Scene, because we were merely destroying the
components, not removing them from the Scene.
2020-07-22 13:38:38 -07:00
Aleksi Sapon ecbdeb9e6d Remove case KtxBundle::R11F_G11F_B10F in toPixelDataFormat 2020-07-22 13:20:54 -07:00
Aleksi Sapon e14c8258f7 Fix KTX texture format for latest version 2020-07-22 13:20:54 -07:00
Philip Rideout 3862b44ef4 gltfio: Add support for KHR_materials_transmission.
This chooses type=THIN, mode=SCREENSPACE, and blending=TRANSPARENT.

Due to sampler overload, we print a friendly error message and enable a
fallback if the user tries to simultaneously enable ubershader mode, the
clearcoat extension, and the transmission extension.
2020-07-22 08:40:55 -07:00
Romain Guy f3ed31b5a0 Don't recompute the color grading LUT every frame in sandbox 2020-07-20 17:08:22 -07:00
Romain Guy 06f4920033 Don't recompute color grading LUT on every frame 2020-07-20 16:56:26 -07:00
Ben Doherty b0c11c17e9 Add outputs block to material definition (#2823) 2020-07-20 16:48:00 -07:00
Pixelflinger 27c4174abd DoF: fix many quality/performance issues
- make sure all downsampling is exactly correct and use proper
  uv values to access these textures. This stabilizes the DoF a bit.

- for now only use NEAREST filtering, as bilinear can't be used naively.

- noise is now mandatory, fix noise radius

- add a median pass (performance is not impacted because DoF is faster
  due to using NEAREST filtering)

- fix  be consistant in how the kernel radius is computed, fix a couple
  errors in that area.

- change ring density from 8 to 4 (but starting with 8), so each new
  ring is 4 samples larger than the previous. This reduces the number
  of samples needed from 25 to 21 on mobile, and 49 to 37 on desktop. 
  It also makes it conceivable to use 5 rings (57 samples). Quality is
  not visibly impacted because the center ring is still 8 samples.
  This density, matches the number of samples required for "square"
  rings.

- fix scaling issue with diaphragm simulation

- fix typos in background accumulation code -- this fixes a lot of 
  quality issues.

- improve performance of "fast tiles" during both DoF and combine passes

Overall the effect runs about 0.5ms faster and quality is greatly
improved.
2020-07-20 12:58:11 -07:00
Philip Rideout 71f256585d Update cgltf (includes transmission ext). 2020-07-20 12:04:51 -07:00
Pixelflinger 710f83dcf5 Enable specular anti-aliasing in gltfio 2020-07-19 22:14:51 -07:00
Mingwei Samuel 36b3cc7bf0 Filament.d.ts: add Vector<T> interface, vectorToArray<T> fn, fix getResourceUris() return vec 2020-07-18 10:50:44 -07:00
Romain Guy c6d9d4a9ae Update AGP, NDK and androidx.core (#2826) 2020-07-17 09:24:33 -07:00
Philip Rideout 665b198db0 Vulkan: add support for subpasses. 2020-07-15 17:39:29 -07:00
Philip Rideout 9f267de1b7 Fix garbage in "Exceeded max sampler" message.
uint8_t is char, so it makes junk on the screen and wakes up your dog
with beeping sounds.
2020-07-15 13:54:56 -07:00
Pixelflinger 5c71b0eae2 update glslang to latest
This fixes a lot of issues regarding precision qualifiers.

This should resolve cases where "highp" were introduced needlessly.
2020-07-14 23:24:50 -07:00
Pixelflinger e58043f156 update spire-cross to latest
This fixes an issue where "expensive" operations can be moved to
inside loops.
2020-07-14 23:24:31 -07:00
Philip Rideout c6a8ad9fbe Refactor colorGradingSubpass to fix #2780. 2020-07-14 19:25:43 -07:00
Romain Guy 97e8035b40 Give materials unique names 2020-07-14 15:57:56 -07:00
Philip Rideout 1d474b30b9 Add simple subpass support to the Driver API.
This makes two changes to the Driver API:
1. Adds the beginSubpass() method.
2. Adds subpassMask to RenderPassParams.

Locally I've proven that this PR is sufficient by making a series of
Vulkan changes; sneak peek is available at commit
bfef6914a7d288bbd25926c02ec93d231a8c0d07.

Note that this PR moves the new usage flag to a different texture;
I had placed it on the wrong one.

See also #2780.
2020-07-14 14:48:24 -07:00
Romain Guy 4c81bb0158 Fix material parameters enum (#2814)
* Fix material parameters enum

Fixes bug #2812

* Add  missing sampler type to filamat
2020-07-14 09:29:20 -07:00
Mingwei Samuel a2e5cacee0 Filament.d.ts: Add BufferReference type alias, update to accept typed arrays
- buffers processed by getBufferDescriptor can be an asset string or JS typed array.
  - https://github.com/google/filament/blob/185ed0cc68cf5e2a148ff36bd817acc6b5c2b811/web/filament-js/extensions.js#L17-L27
2020-07-13 20:56:12 -07:00
Ben Doherty 7cfc2c9f24 Set Filament iOS support to iOS 11 (#2809) 2020-07-13 18:04:47 -07:00
Ben Doherty fec214a772 Include Filament version instead of date in release assets (#2808) 2020-07-13 17:23:36 -07:00
Philip Rideout 6eac638fd2 Remove old method for JS doc generation.
The new way is to follow the instructions at the top of
`web/docs/build.py`.

The option in build.sh has been unused for a while. Invoking Python from
CMake was pointless, especially since I don't want to force other
developers to install a specific version of Python etc.
2020-07-13 16:07:49 -07:00
Philip Rideout dc891f7299 CMake: specify -fPIC at root level.
Fixes #1881.
2020-07-13 16:07:07 -07:00
Ben Doherty 7c4661cc6b Fix glTF camera aspect ratio (#2807) 2020-07-13 14:42:26 -07:00
Ben Doherty c7b6d45958 Add CocoaPods tutorial to site (#2798) 2020-07-13 14:41:56 -07:00
Max Rebuschatis c0bf8fa83b NoopDriver now uses ShaderModel::GL_ES_30 on WASM 2020-07-13 13:39:53 -07:00
Philip Rideout 4fa987c698 WebGL: Upgrade emsdk and refactor initialization.
Since postRun can no longer be set from within the extern post JS, we
now use the promise rather than postRun.

This upgrades emsdk to 1.39.19 (see note in #2800).
2020-07-13 13:02:26 -07:00
Philip Rideout ec533e6047 DriverEnums: add usage flag for SUBPASS_INPUT 2020-07-11 09:22:28 -07:00
Pixelflinger bdf1272942 update comments to reflect code change 2020-07-11 01:03:20 -07:00
Benjamin Doherty 2e8a80f726 Fix, add xcsharedata for HelloCocoaPods sample, removal MetalKit 2020-07-10 18:00:57 -07:00
Ben Doherty 2516484566 Add HelloCocoaPods iOS sample (#2795) 2020-07-10 17:05:54 -07:00
Ben Doherty c91d02ab29 Add bluevk.lib to Windows README (#2796) 2020-07-10 13:16:45 -07:00
Philip Rideout 41f7ea436d Update the descriptor set index in colorGrading. 2020-07-10 10:19:06 -07:00
Romain Guy b224916f09 Prevent crash if the glTF doesn't have animations 2020-07-09 17:23:06 -07:00
Philip Rideout 38d2509aaf Web tutorials now use a CDN for the npm package.
This makes the tutorials more consistent with the live demos and lets us
more easily ensure that the tutorials are kept up to date without
errors. In fact it caught an error in the Suzanne tutorial.

Since this affects source rather than served files, this PR is intended
for main.  The master branch will be updated in a subsequent PR.
2020-07-09 14:56:05 -07:00
Ben Doherty 185ed0cc68 Add Filament Podspec (#2788) 2020-07-09 12:43:24 -07:00
Philip Rideout 5d2b12b9a6 Fix javadoc syntax error. 2020-07-09 12:12:41 -07:00
Romain Guy 77aec40a56 Prepare Filament v.1.8.0 (#2787) 2020-07-09 11:44:15 -07:00
Philip Rideout 25d42c939d filagui: publicize the low-level draw data handler.
The existing API was fine for FilamentApp but it prevented clients from
making ImGui calls from arbitrary places, which forced them in some
cases to queue up their ImGui calls using vector<function<>>.

This PR publicizes the low-level method that consumes the ImGui draw
list and removes calls to global functions.
2020-07-09 11:31:36 -07:00
Philip Rideout 1ad6bccbc2 Vulkan: add support for input attachment descriptors.
This is step 1 for supporting subpasses (aka framebuffer fetch).

Vulkan requires us to explicitly bind the shader to any framebuffers
that we read from. These are called input attachments in Vulkan
parlance, and each binding is called a descriptor.

For simplicity we only create homogeneous descriptor sets where each
descriptor set is comprised of only one type of binding (i.e. all
uniforms or all samplers). I see no reason to break with that
architecture right now, so input attachments live in their own set.
In the long term, we should probably think about partitioning
descriptors differently (e.g. according to their frequency of change).

This PR also renames some internal fields in order to avoid nomenclature
confusion, such as `mDescriptorSets` => `mDescriptorBundles` . Each
entry in this map is a set of descriptor sets, or what we are now
calling a "bundle".
2020-07-09 11:26:06 -07:00
Ben Doherty 3c1ea07502 Add Metal support for Texture::import (#2782) 2020-07-09 10:39:22 -07:00
Philip Rideout 07e4d1c148 Fix TypeScript error for the Render Fidelity folks. 2020-07-09 07:49:22 -07:00
Pixelflinger 1816883428 Some infrastructure to support arbitrary shaped diaphragm
This is still work in progress and disabled.
2020-07-08 17:18:40 -07:00
Pixelflinger 6a6775ebec fix typo in IBL computation comment 2020-07-08 17:18:18 -07:00
Romain Guy 767764e4ff Swizzle textures when swizzle is enabled, not the other way around (#2779)
Fixes #2777
2020-07-08 13:33:09 -07:00
Philip Rideout d3f6ce6990 Minor fixes for "matinfo --web-server" 2020-07-08 13:15:28 -07:00
Philip Rideout 96032eada5 Vulkan code cleanup. 2020-07-08 11:04:04 -07:00
Philip Rideout c8aad378c4 Vulkan: add support for MRT. 2020-07-08 11:01:43 -07:00
@roxlu ☾ c067d76d1d Add View::getVisibleLayers() 2020-07-08 09:24:55 -07:00
Romain Guy 630f816e7a Remove iostream from GLX backend (#2774) 2020-07-07 11:29:12 -07:00
Ben Doherty bbf37a5480 Add error message when parsing material with missing backend (#2766) 2020-07-06 11:29:01 -07:00
Ben Doherty a07894ca9f Fix gltf_viewer crash when switching models with glTF cameras (#2767) 2020-07-06 11:28:36 -07:00
Mingwei Samuel e03c663bc3 filament.d.ts make init, fetch callbacks optional 2020-07-04 09:20:51 -07:00
Ben Doherty 1af254db43 Add matc support for command-line preprocessor defines (#2760) 2020-07-01 10:42:46 -07:00
Philip Rideout 7621f7e830 Vulkan: fix SSAO by removing bogus workaround.
This fix has the side effect of causing a validation warning due to
a declared fragment shader output that has no corresponding attachment.
We can fix that in a future PR.

Fixes #2752
2020-06-30 16:59:03 -07:00
Philip Rideout d7cd247dfc matdbg: auto-select variant when clicking a material.
The UI was in a weird state after the user selected a new material but
before they had chosen a particular variant. The highlighted
material did not match the content of the source editor.
2020-06-30 16:56:19 -07:00
Philip Rideout 9a58bf2460 matdbg: support scenes that have many materials.
We now download shader source only after the user selects a variant.
Previously we tried to download all shaders at once. This caused Chrome
to throw ERR_INSUFFICIENT_RESOURCES.

Fixes #2759
2020-06-30 16:56:19 -07:00
Philip Rideout 7ee1279792 Vulkan: add diagnostics to check if format is sampleable.
Motivated by #2752.
2020-06-30 12:43:45 -07:00
Ben Doherty 7131bbf62c Fix VS 2019 build failure with Vulkan (#2758) 2020-06-30 11:29:00 -07:00
Michael LouandMichael Lou 820f551eea filamat: Resolve string processing inefficiency (#2754)
Co-authored-by: Michael Lou <ylou@amazon.com>
2020-06-30 10:39:31 -07:00
Ben Doherty a6872c840c Silence more deprecation warnings (#2750) 2020-06-30 10:14:57 -07:00
Philip Rideout c0452b5e9d JS: Update API for Camera construction / destruction. 2020-06-29 18:35:24 -07:00
Philip Rideout b136b4aca5 JS: Temp workaround for bloom binding error. 2020-06-29 18:35:24 -07:00
Philip Rideout 59cf9e3b75 JS: Fix typo in bindings for bloom options. 2020-06-29 18:35:24 -07:00
Pixelflinger 7ca508cb7a ssao: optimize sin/cos per sample
We now get away with a sin/cos per fragment instead of per-sample,
this increases a little bit the ALU load but decreases the EFU's.
This is not necessarily faster, but sin/cos may cost more power or
have longer latencies.
2020-06-29 17:46:53 -07:00
Philip Rideout 96feea1dee Avoid deprecated API in the root README. 2020-06-29 15:12:52 -07:00
Philip Rideout c5acacff67 Vulkan: add note about #1532. 2020-06-29 12:36:47 -07:00
Ben Doherty 92f2004c4b Improve matc error reporting (#2741) 2020-06-29 11:21:56 -07:00
Pixelflinger aed8c7fcb4 DoF: make all function parameter const
glslang generate much less code when function parameters are marked
const (it also works around a bug where highp intermediate variables
are introduced -- but this will be fixed soon).

Also remove non-trivial uses of ?: as it also triggers a similar problem 
in glslang.
2020-06-29 10:45:08 -07:00
Philip Rideout 29f50e0feb Vulkan: fix intermittent InvalidQuery on Android.
This prevents the following validation error:

    Cannot get query results on queryPool 0x2 with index 0 as data has
    not been collected for this index.

This was occasionally triggered when we attempted to query a timer that
had not yet been inserted into any command stream. (The error seems
bogus to me since we've enabled the AVAILABILITY flag, but we might as
well fix it anyway.)
2020-06-28 04:43:06 -07:00
Romain Guy 2aeb33b260 Fix Windows build 2020-06-26 23:20:23 -07:00
Romain Guy 132e94b3bb Add vignette post-processing effect (#2743)
* Add a vignette post-processing effect

* Use numeric limits instead of hard coded values
2020-06-26 17:44:17 -07:00
Romain Guy f7f86a7c56 Remove skygen
This will be replaced by a runtime implementation. skygen was
never finished to begin with.
2020-06-26 17:25:08 -07:00
Ben Doherty 4a3984692a Flush pending command buffer in Metal terminate (#2737) 2020-06-26 11:38:56 -07:00
Philip Rideout c87cffd57a Transition to PRESENT layout only once per frame. 2020-06-25 19:50:34 -07:00
Philip Rideout 4bbc0c05c4 Allow LOAD_OP_LOAD when rendering to swap chain. 2020-06-25 19:50:34 -07:00
Philip Rideout 697b1b6907 Fix intermittent InvalidImageLayout error for main depth buffer. 2020-06-25 19:50:34 -07:00
Mathias Agopian d3f5164fcb New DoF implementation (#2700)
This implementation is an order of magnitude more efficient, running
in about 6ms on Pixel 4.

We're using the ring binning technique described in "Life of a Bokeh",
SIGGRAPH 2018.
2020-06-25 16:37:16 -07:00
Pixelflinger 8882132f43 fix a use after free in filamat
This would happen when using math -E -a vulkan. GLSLangCleaner lifetime
must be shorter than TProgram/TShader.
I think we can fix this by using another scoped GLSLangCleaner.

Tested successfully with ASAN.
2020-06-25 12:20:16 -07:00
Ben Doherty 89a8592714 Fix, incorrect camera view matrix with non-rigid transformations (#2735) 2020-06-25 11:22:09 -07:00
Philip Rideout 9d35aff2d3 Vulkan: fix bloom on Android by supporting LOAD_OP_LOAD.
If a render target attachment is not cleared or discarded, then it
should be preserved and therefore requires VK_ATTACHMENT_LOAD_OP_LOAD.
2020-06-24 22:33:57 -07:00
Romain Guy c6e7382cb9 Update README.md 2020-06-24 16:30:23 -07:00
Mingwei Samuel 0be094cd4f Update TypeScipt declarations
- Add missing LightManager$Builder methods.
- Fix IcoSphere.tangents type to be unsigned.
- Add missing IcoSphere.suvdivide() method.
2020-06-24 15:37:15 -07:00
Ben Doherty 81c60c4efa Remove use of deprecated APIs in libfilamentapp (#2729) 2020-06-24 10:47:42 -07:00
Pixelflinger 456e057754 texelFetch w/ LOD requires at least MIPMAP_NEAREST
if NEAREST or LINEAR min filter is used, texelFetch is actually
undefined when the LOD is not 0.
2020-06-23 18:23:16 -07:00
Ben Doherty ab12881888 Remove camutils dependency on utils (#2727) 2020-06-23 15:28:20 -07:00
Philip Rideout efaf02ca61 CMake: fix macOS build break. 2020-06-23 15:19:04 -07:00
Philip Rideout 8f7b25088d CMake: build matdbg / civetweb only when enabled.
Also group FILAMENT_ENABLE_MATDBG with all our other CMake options.
2020-06-23 15:19:04 -07:00
Philip Rideout 8f4ffbc782 gltfio: various improvements to skinning normalization.
- Allow JavaScript and Java / Kotlin clients to configure this setting.
- Opt in by default (this was disabled in #2621)
- Optimize large assets like Bistro by iterating through prims only when
  the asset actually has skins.

Fixes #2714.
2020-06-23 13:30:45 -07:00
Mingwei Samuel 455bed917b Fix typescript missing options parameter for createTextureFromX 2020-06-23 09:25:44 -07:00
Ben Doherty d5033b5857 Silence warnings in public headers (#2722) 2020-06-22 16:56:55 -07:00
Philip Rideout cf5b6ccba3 Use MAX_MORPH_TARGETS instead of magic number. 2020-06-22 16:02:12 -07:00
Philip Rideout 42c80d5d5e Fix CUBICSPLINE interpolation for morph weights.
Tested with Polly the robo-hound and ensured that InterpolationTest
did not regress.

Partial fix for #2714.
2020-06-22 16:02:12 -07:00
Philip Rideout 2b92b5e060 gltf_viewer: move "Animation" UI
The Animation selector is now a top-level group (collapsed by default),
previously it was in the Hierarchy group, which was non-intuitive.

Also:

- Use indent() for consistency with other UI groups.
- Remove un-necessary usage of a lambda.
2020-06-22 15:43:35 -07:00
Ben Doherty 1762baab61 Remove unused SPIRV-Tools-shared library (#2719) 2020-06-22 14:30:43 -07:00
Ben Doherty ab98548e75 Fix iOS projects build (#2718) 2020-06-21 22:31:12 -07:00
Ben Doherty 5e2c9e3aff Create universal libraries for iOS releases (#2717) 2020-06-21 19:43:03 -07:00
Ben Doherty b8ece355d7 Install Filament LICENSE alongside README (#2712) 2020-06-19 18:10:27 -07:00
Ben Doherty 79fb878fb9 Update build instructions link (#2711) 2020-06-19 13:26:18 -07:00
Ben Doherty 026298182e Fix gltfio-java build errors on Windows (#2709) 2020-06-19 10:55:15 -07:00
Philip Rideout a79effc78b Page Curl: fix CPU animation. 2020-06-18 19:38:41 -07:00
Philip Rideout 66471ee990 Page Curl: add configurable curl style. 2020-06-18 19:35:42 -07:00
Ben Doherty 1fc57b8bf0 Add bitcode to iOS builds (#2708) 2020-06-18 14:00:05 -07:00
Philip Rideout 6b5d21639e gltf_viewer: collapse all UI panels by default 2020-06-18 12:54:45 -07:00
Ben Doherty d70e317065 Use local iOS toolchain instead of downloading (#2705) 2020-06-18 12:16:40 -07:00
Philip Rideout a5c49cc1b6 Improve JS API for Scene::addEntities.
This repairs the `animation.html` sample. Using a JS array is more
natural for web developers and more consistent with the latest
JavaScript bindings in gltfio.
2020-06-18 12:16:01 -07:00
Philip RideoutandWojciech Czerniak ce995d021a Improve JS API for SurfaceOrientation helper. (#2706)
* Improve JS API for SurfaceOrientation helper.

Web developers should not be expected to call malloc on the emscripten
heap. This new API is better aligned with how we handle vertex buffers.

Fixes #2702.

* Update web/filament-js/extensions.js

Co-authored-by: Wojciech Czerniak <wojciech.czerniak@gmail.com>

Co-authored-by: Wojciech Czerniak <wojciech.czerniak@gmail.com>
2020-06-18 12:02:02 -07:00
Ben Doherty 9cd2f2edc1 Check in pristine copy of Clang iOS toolchain (#2703) 2020-06-18 10:19:31 -07:00
Philip Rideout 5c64ed5125 gltfio: use highp for UV coords.
Fixes #2500.
2020-06-17 17:27:53 -07:00
Ben Doherty 623cd1a5f2 Remove PDB and ILK files when building for Windows CI (#2698) 2020-06-17 11:13:47 -07:00
Ben Doherty 94776a01b3 Add JNI bindings for gltfio camera (#2693) 2020-06-16 15:24:24 -07:00
Romain Guy f462eafed0 Update workflows from master branch to main (#2697) 2020-06-16 13:40:34 -07:00
Romain Guy 7d1dbba2b4 Rename reference from master to main 2020-06-16 13:39:51 -07:00
Romain Guy 8c9cc988a6 Update references to master with references to main 2020-06-16 13:35:57 -07:00
@roxlu ☾ 7a1d9968a7 Check if an existing material parameter is a sampler (#2694)
* Check if an material parameter is a sampler

* Rename hasSampler to isSampler
2020-06-16 13:32:23 -07:00
Romain Guy 56682794d3 Update getTime() documentation 2020-06-16 13:14:48 -07:00
Philip Rideout 87ee5783b7 export_graphviz() now includes name string. 2020-06-15 15:11:54 -07:00
Ben Doherty 7a1c079050 Use an int, not byte, for variantFilter (#2691) 2020-06-15 11:38:43 -07:00
Philip Rideout 242e8d1b56 Update live JS demos and tutorials.
At some point I should probably change the tutorials to use a versioned
NPM package rather than a checked-in prebuilt Filament WASM file.

Fixes #2686.
2020-06-15 11:34:59 -07:00
Ben Doherty 42d55f226b Support Metal in the iOS simulator (#2678) 2020-06-15 11:08:52 -07:00
Ben Doherty 25b43d7c2a iOS samples: set opaque = YES on CAMetalLayer (#2675) 2020-06-15 11:05:17 -07:00
Ben Doherty de3f757013 Add JS bindings to gltfio camera funcs (#2681) 2020-06-15 11:04:16 -07:00
Philip Rideout ebd195f8e4 matdbg: Add support for Android.
See the matdbg README for details.
2020-06-14 22:42:55 -07:00
Romain Guy a2ce57ade3 Fir applyAnimation() when scale is close or equal to 0 2020-06-13 14:48:07 -07:00
Ben Doherty 7a78ccd184 Turn off Windows DEBUG builds for continuous builds (#2682) 2020-06-12 16:48:53 -07:00
Philip Rideout 963a8958ec Fix Ubuntu build. 2020-06-12 13:47:54 -07:00
Philip Rideout 899ac1224f gltfio: Add Java bindings for desktop.
This is completely untested.

Fixes #2670.
2020-06-12 13:47:54 -07:00
Romain Guy a019de3363 Add (improved) color grading UI to gltf-viewer (#2676) 2020-06-12 08:30:43 -07:00
Ben Doherty 79c83f509c Fix Metal bug not creating default depth attachment (#2677) 2020-06-11 17:55:20 -07:00
Ben Doherty fde2d2e483 Fix MeshReader material bug (#2674) 2020-06-11 14:49:25 -07:00
Ben Doherty b2c63b6cd2 Add support to gltfio for glTF cameras (#2663) 2020-06-11 13:57:01 -07:00
Philip Rideout 1f9d073a64 gltfio: enable unused UV attributes when possible.
Reproduced the issue by hacking the TexturedCube glTF file.

Verified the fix by viewing TexturedCube in ubershader mode, then
hacking the shader with matdbg in order to visualize texture
coordinates.

Fixes #2659
2020-06-11 12:05:43 -07:00
Philip Rideout fa0f5e0501 Prep the build for multi-platform matdbg. 2020-06-10 20:00:24 -07:00
Philip Rideout fee6a2f075 Miscellaneous matdbg improvements
matdbg
    - Materials are now sorted by name and the sha id is hidden.
    - PostProcess materials now separated from Surface materials.
    - PostProcess details now hide the non-existing properties.
    - Larger default pane size for the material list.
    - Use nicer font.

matinfo
    - Print out the Material Domain.

filament
    - get*Slow methods in FMaterial are now private.
2020-06-10 20:00:24 -07:00
Romain Guy 19a212389b Perform non-ACES grading in BT.2020 (#2662)
* Perform non-ACES grading in BT.2020

* Don't use BT.2020 with legacy filmic tone mapper

* Fix comments

* Use == operator instead of memcmp
2020-06-10 13:41:17 -07:00
Mathias Agopian 1b1ef591a4 fix typo that prevented fxaa to work properly (#2667)
It caused the wrong fxaa variant to be chosen, in turn causing
flickering due to temporal dithering.
2020-06-10 08:53:09 -07:00
Rupert Rawnsley b0acb3216a eglInitialize requires a non-null IntArray reference and different offsets for major and minor. (#2668) 2020-06-10 08:52:20 -07:00
Philip Rideout 10e1aaadff Vulkan: fix mipmap generation on Android.
The blit DriverAPI command was not enforcing correct synchronization.
On Android, this manifested as an intermittent issue with bad mipmap
levels.

This did not trigger any validation warnings and therefore took a long
time to track down.

Fixes #2643
2020-06-09 21:11:44 -07:00
Pixelflinger 00b522669c minor fixes for matdbg
- don't crash when a material doesn't have a name
- don't cache the program in PostProcessManager so we can do live
  editing. Not needed anyways, because Material has a cache.
2020-06-09 13:27:56 -07:00
Philip Rideout f125e1730d Throw Java exception when using destroyed Animator.
Someone wise once said: "It is better to throw in Java than to crash in
Native."

Motivated by #2654.
2020-06-09 10:36:35 -07:00
Rupert Rawnsley 18776fc432 SamplerType JNI definition was out of step with the native definition. (#2658)
When invoking MaterialBuilder.samplerParameter with Java enum SAMPLER_EXTERNAL it was wrongly recast as native enum SAMPLE_CUBEMAP in the JNI interface because the Java enum was missing SAMPLE_2D_ARRAY.
2020-06-09 08:35:33 -07:00
Romain Guy 4bf21876b4 Add new color grading feature, vibrance (#2656)
* Add new color grading feature, vibrance

* Address code review comment
2020-06-09 08:34:10 -07:00
Pixelflinger 1feca23477 don't attempt to call Android private APIs
This used to be tolerated, but no more with recent versions of android.
2020-06-08 16:18:33 -07:00
Romain Guy b4d2a1991a Add new curves color grading tool (#2651)
* Add new curves color grading tool

* Add release notes
2020-06-08 12:17:53 -07:00
Romain Guy 3e6ee4ca5e Fix libimageio's HDR format decoder (#2653)
See https://cbloomrants.blogspot.com/2020/06/widespread-error-in-radiance-hdr-rgbe.html
2020-06-08 11:48:11 -07:00
Pixelflinger ee6ddf675e syscall (futex) errors are returned in errno
this fixes a problem where our implementation of Condition would not
handle timeouts properly
2020-06-06 15:50:38 -07:00
@roxlu ☾andRomain Guy 7e6c38d098 Fix: cannot use parts index for material index. (#2652)
* Fix: cannot use parts index for material index.

* Fix formatting

Co-authored-by: Romain Guy <romainguy@curious-creature.com>
2020-06-06 10:42:53 -07:00
Ben Doherty 7a8755b5b2 Implement framebuffer fetch for Metal backend (#2648) 2020-06-05 17:31:12 -07:00
Pixelflinger 6461370cb8 more debug code to help catch an ANR
- assert that shutdown() is called from the main thread
- attempt to catch whether CommandBufferQueue::mExitRequested gets corrupted
  (which could explain the ANR).
2020-06-05 14:50:16 -07:00
Ben Doherty e56882d20f Update tinyexr to 944c740 (#2644) 2020-06-05 12:22:28 -07:00
Philip Rideout 43f7bad8a3 Kotlin cleanup 2020-06-05 08:23:25 -07:00
Romain Guy 31bdb61047 Add PQ transfer functions 2020-06-04 18:18:01 -07:00
Romain Guy 2fcca9677d Add Ushimura tone mapping operator
Also fix potential negative values when applying white balance
during color grading.
2020-06-04 15:17:08 -07:00
Philip Rideout a4094193c3 gltfio: fix AABB when instancing is enabled
If a client opts in to AABB computation and uses instancing, the AABB
would be clobbered with an infinite box.

Fixes #2639
2020-06-04 14:06:50 -07:00
Romain Guy 1935598a7d Add Java bindings for ColorGrading (#2638) 2020-06-04 11:03:15 -07:00
Romain Guy 6c3b7a2282 Update RELEASE_NOTES.md 2020-06-03 19:05:37 -07:00
Romain Guy 23b62e2d12 Add ASC CDL (Color decision list) to color grading (#2635)
A CDL is made of slope/offset/power, and is roughly equivalent
to lift/gamma/gain.
2020-06-03 19:01:22 -07:00
Philip Rideout b281022eb0 sample-page-curl: flip the backface image. 2020-06-03 12:07:43 -07:00
Philip Rideout 910c2e9b0e Vulkan: implement insertEventMarker.
Note that pushGroup / popGroup are already supported.
2020-06-03 11:54:36 -07:00
Romain Guy 9007de03d9 Update README.md 2020-06-02 22:56:11 -07:00
Romain Guy 1aa57fc425 Color grading: add saturation and contrast (#2627)
* Add transforms for ACEScct and enabling/disabling color grading in sample

* Add saturation and contrast adjustments

* Rename ACES to ACES_LEGACY and introduce ACES

ACES_LEGACY is ACES with a brightness boost to match our old
tone mapping operator.
2020-06-02 22:54:00 -07:00
Philip Rideout 7418fc0222 gltfio: JNI bindings for get-by-name.
Tested in Android Studio by starting sample-gltf-viewer and typing the
following into the debugger:

    modelViewer.asset!!.getFirstEntityByName("Drone_Body")
    modelViewer.asset!!.getEntitiesByName("Drone_Body")
    modelViewer.asset!!.getEntitiesByPrefix("Drone")
2020-06-02 18:38:36 -07:00
Philip Rideout 9437907eb4 ModelViewer now uses a coroutine. 2020-06-02 18:36:49 -07:00
Philip Rideout 91a009f94c Add new async method to ModelViewer.
If you now try loading Bistro, the skybox shows up fairly quickly.
This works by moving AssetManager uncompression off the UI thread.
2020-06-02 18:36:49 -07:00
Mingwei Samuel ca6b1860be Fix typescript View set/getAmbientOcclusion wrong type 2020-06-02 16:40:50 -07:00
Romain Guy fbb8742cbd Add new color grading feature: shadows/mid-tones/highlights (#2623)
* Add new color grading feature: shadows/mid-tones/highlights

This feature can be used to color correct specific tonal ranges.
The tonal zones can be precisely controlled.
2020-06-02 12:28:38 -07:00
Philip Rideout 6c173489d7 gltfio: Add get-by-name and get-by-prefix methods.
Java bindings will be forthcoming in a separate commit.
2020-06-02 10:17:12 -07:00
Philip Rideout 0abe262094 Patch hat-trie to remove exceptions. 2020-06-02 10:17:12 -07:00
Philip Rideout bd72f1fd6a Add hat-trie to third_party. 2020-06-02 10:17:12 -07:00
Philip Rideout 28912b6f57 filamat-android: fix string leaks 2020-06-02 10:16:41 -07:00
Philip Rideout a3e336921e gltfio: improve performance by assuming assets are well-formed.
glTF assets are required to provide min/max attributes for POSITION,
so in theory we never need to compute the AABB. However the option is
still there.

This PR also makes it so that Java clients can choose this option,
previously it was hardcoded for all non-native clients.
2020-06-01 10:30:09 -07:00
Romain Guy 524da0af28 Update RELEASE_NOTES.md 2020-06-01 09:37:21 -07:00
Philip Rideout adccf9f432 gltfio: remove details namespace 2020-06-01 09:19:18 -07:00
Romain Guy c49ffcc354 Add channel mixer and docs to ColorGrading (#2618) 2020-06-01 09:07:34 -07:00
Romain Guy 50adc1f661 Add per-view color grading LUT (#2615)
* Add the ability to set a ColorGrading LUT per View

In this change, material_sandbox allows to change the tone mapping
operator at runtime.

* Add Mathematica notebook used to explore white balance

The implementation is meant to reproduce the temperature/tint sliders
founds in Adobe Lightroom. The temperature can be offset from 2,000K
to 50,000K using a slider between -100 and +100 (-1.0 to 1.0 in our
API). The range of tint was modelled after the range used for the
temperature.

* Fix various issues

- A refactoring wrongly remamed the color grading pass
- Setting a View's ColorGrading to null selects the
  default color grading options

* Implement white balance in ColorGrading
2020-05-31 19:24:42 -07:00
Romain Guy b77e024de9 Introduce ColorGrading API (#2613)
* Introduce ColorGrading API

A ColorGrading object will eventually be settable on a View to
choose the tone mapping and other color transformations.

There is currently only a single default ColorGrading instance
used by all views.

* Use raw function pointers
2020-05-29 18:54:48 -07:00
Pixelflinger 1f77fb5995 minor cleanup of PostProcessManager ctor
make sure all fields are always initialized and the IDE stops 
complaining.
2020-05-29 18:44:48 -07:00
Philip Rideout bf1f32e308 gltfio: Use JobSystem to compute bounding boxes. 2020-05-29 18:13:49 -07:00
Philip Rideout 2c6042bd44 Add systrace markers to gltfio. 2020-05-29 18:13:49 -07:00
Philip Rideout 96c770ad9e gltfio: Use JobSystem to compute tangents. 2020-05-29 18:13:49 -07:00
Ben Doherty b1563dabe9 Metal: use render target height to adjust viewport when blitting (#2610) 2020-05-29 16:08:47 -07:00
Romain Guy 3ef37f8925 Prep work for proper color grading (#2611)
* Prep work for proper color grading

* Bring back local colorGrading bool to drive that pass

* Fix formatting issue

* Add missing case for the color grading pass

* Fix formatting issues

* Formatting issues
2020-05-29 15:29:15 -07:00
Philip Rideout ede09e28e3 gltfio: add JavaScript bindings for instancing. 2020-05-29 09:22:17 -07:00
Philip Rideout 81ea280ea9 gltfio: add Java bindings for instancing. 2020-05-29 09:22:17 -07:00
Philip Rideout 92c017bdd3 Simplify WebGL context creation. 2020-05-29 09:09:49 -07:00
Philip Rideout 6870d360cd gltfio: Simplify FilamentInstance. 2020-05-29 07:43:44 -07:00
Philip Rideout 2d62daf5e8 Add sample for testing glTF instancing.
Fixes #1513.
2020-05-29 07:43:44 -07:00
Philip Rideout 83cff32856 gltfio: Add support for instanced animation.
When animation is applied to the master asset, all instances are
animated.

Instances can also be individually animated via the Animator in
FilamentInstance.

Fixes #1513.
2020-05-29 07:43:44 -07:00
Philip Rideout 8de730f76c gltfio: Add support for simple instancing.
This adds createInstancedAsset() to AssetLoader, which creates a master
asset and a set of slave instances. Vertex buffers, index buffers,
textures, and material instances are shared. Entities and components are
duplicated.

Instances have their own API object that is very simple. Light sources
and material instances are not instanced, so are not accessible through
the instance API object.

The master-slave ownership model lets us avoid complex shared ownership
semantics. The existing cache structures in AssetLoader allow the
implementation of this feature to be fairly simple.

The master asset exposes the union of all entities and allows clients to
modify all instances en masse if they wish. This design also works
naturally with ResourceLoader, which does not need to know about
instancing. For example, asynchronous loading is completely unchanged;
the dependency graph simply contains the union of entities across all
instances.

Support for animation is added in a subsequent commit.

Fixes #1513.
2020-05-29 07:43:44 -07:00
Romain Guy 1f29df6da4 Add a note about AGP 4.0.0 2020-05-28 14:05:20 -07:00
Philip Rideout c087eb6825 gltfio: Add Java / JavaScript bindings for lights. 2020-05-28 11:51:35 -07:00
Pixelflinger 038c35fbda add a few systraces during init 2020-05-28 11:28:22 -07:00
Ben Doherty 80fcd133de Add correct scheduleDestroy calls to Metal backend (#2600) 2020-05-27 15:54:54 -07:00
Pixelflinger 62d0f9f033 perfcounters are now disabled by default
To enable some basic profiling of the gl thread using performance
counters, the "filament.perfcounters" property must be set to 1
(before the Filament Engine is created):

    adb shell setprop filament.perfcounters 1

This is so that filament doesn't interfere with simpleperf by default.
2020-05-27 15:53:45 -07:00
Pixelflinger 1e65b4d8af load post process materials lazily
We aim to reduce start-up time and memory usage.
2020-05-27 11:17:10 -07:00
Pixelflinger f3731fa797 cleanup and code reformatting
This change mostly reorders PostProcessManager's methods roughly
in order that appear in the pipeline.
2020-05-27 11:17:10 -07:00
Romain Guy 28f031e95f Update RELEASE_NOTES.md 2020-05-27 10:52:04 -07:00
Jaime Blasco 5104318fff Initialize DisplayHelper when using textureView in ModelViewer (#2598) 2020-05-27 10:10:13 -07:00
Pixelflinger 68f0ab6312 Implement ACES tone mapping
this leverages the new LUT based tone mapping
2020-05-26 23:46:37 -07:00
Pixelflinger 62a591bc73 Add a new tone mapping option using a LUT
This is now the default, and the tone mapper used
is now the same on desktop and mobile.
In the future this will allow us to implement many features such as
color grading at no cpu cost.
2020-05-26 23:46:37 -07:00
Benjamin Doherty 0f6a06a2e1 Add 3D texture support to Metal 2020-05-26 23:46:17 -07:00
Pixelflinger b620a5e358 Add support for 3D textures in the vulkan backend 2020-05-26 23:45:35 -07:00
Pixelflinger 0d652d61f8 fix typo causing textureGather to always be used 2020-05-26 17:59:01 -07:00
Ben Doherty 1b033c7de3 Implement MRT for Metal (#2590) 2020-05-26 17:38:37 -07:00
Pixelflinger eb5eb6c827 fix EGL config selection 2020-05-26 17:22:30 -07:00
Philip Rideout 0e437d244f Vulkan: fix dummy type for disabled attribs.
OpenGL allows vertex shaders to consume attributes that are never
assigned values from a vertex buffer. When this occurs, GL provides a
default zeroed-out value, or a value from the most recent call to
`glVertexAttrib*v`.

Vulkan does not allow this, so our Vulkan backend provides dummy data by
re-using the position buffer, which we know exists. This was an existing
hack, but it did not always assign a compatible type, which resulted in
validation spew with gltf_viewer + BusterDrone.

This fixes one of the two bugs reported in #2573.
2020-05-26 13:20:06 -07:00
Philip Rideout 9024b4afd7 gltfio: fix vertex attribute type mismatch.
Vulkan complains if a pipeline declares an integer vec2 attribute but
the shader consumes it as "vec2" rather than "ivec2". gltfio was doing
this when supplying dummy texture coordinates.

This fixes one of the two bugs reported in #2573.
2020-05-26 13:19:52 -07:00
Pixelflinger 62ff7b7d0a Improve AO buffer upsampling
Since AO is computed at 1/4 resolution, it is necessary to upsample
the AO buffer. Until now this was done with a bilinear tap, which is
less than ideal as it can creates jaggies at edges.

High quality upsampling can now be enabled and uses a bilateral filter.
The cost is about 2.0 ms at 250MHz on Pixel 4. ES3.1 is required.
2020-05-26 12:59:47 -07:00
Pixelflinger d1ed4f837c improve SSAO quality
SSAO starts at 1/4 resolution, and because we used derivatives
to calculate a cheap pre-blur, the output was mostly 1/4 resolution
of that, leading to 1/4 of the destination pixels being mostly identical.
This, in turn caused sampling issues when reading the SSAO buffer during
the color pass.

We fix this by getting rid of the pre-blur, and increasing slightly the
size of the gaussian blur from 9 samples to 13, which increases the
SSAO pass time by 20%, or 0.3ms at 430 MHz on Pixel 4.

With this change and bilinear filtering in the color pass, we get rid
of all the sampling artifacts.
2020-05-26 12:59:47 -07:00
Pixelflinger d62f664957 ssao: restrict the scaling to 0.5 and 1.0
until now we allowed any resolution for SSAO, but it didn't make
much sense, especially that the depth pass is now used for other things.
To keep things more manageable, we only allow 0.5 and 1.0 scale
factor settings (respectively quarter and full resolution).
2020-05-26 12:59:47 -07:00
Philip Rideout 6311b538e1 Add "if" when compiling subpass material.
This avoids error spew on some platforms such as Chrome + WebGL 2.0
2020-05-26 11:03:55 -07:00
Philip Rideout 58bb1f61e6 Add JS bindings for DoF.
Adding this for completeness, although the feature triggers a known
issue with Chrome's WebGL implementation that emits an error when
source and destination textures of a draw call are the same.
2020-05-26 10:06:40 -07:00
Mathias Agopian 8415d18401 Fix refracted objects drawing order (#2577)
Refracted objects could be drawn on top of opaque objects that were
closer to the camera.

Du to a typo, we were not reusing the existing depth buffer during the
refraction pass.

Fixes #2576
2020-05-23 17:08:53 -07:00
neshumeandneshume 6df1265bef Fix compilation issues under ubuntu 20 and latest clang (#2562)
Co-authored-by: neshume <alex.andel@gmail.com>
2020-05-23 17:08:19 -07:00
Philip Rideout dc51dc197c Gradle: update old property name.
I forgot to update this in 0b1fa7f.
2020-05-22 23:28:30 -07:00
Philip Rideout 1292610289 Vulkan: fix synchronization issues with timestamps.
This contains the following two fixes, but the second fix is more
important because it prevents an actual validation error on Android.

1. The query pool bitset was written in the main thread but read
   in the driver thread, this is now protected with a mutex.

2. Querying a timestamp before it has been written into the command
   buffer was still causing validation errors, despite the fact
   that we are now properly using the AVAILABILTY flag. This is a
   CPU-side synchronization problem and can therefore be fixed using
   std::atomic<bool>.
2020-05-22 15:40:37 -07:00
Romain Guy e9d1e3a82e Stop using deprecated APIs for incremental builds (#2574) 2020-05-21 22:15:55 -07:00
Philip Rideout c749f7e798 Emit a one-time warning for VK_SUBOPTIMAL_KHR.
This was sometimes causing a cascade of log messages and swap chain
re-creations on Android.

To support resizing, we still re-create the swap chain when encountering
VK_ERROR_OUT_OF_DATE_KHR.

Suboptimal means: "A swapchain no longer matches the surface properties
exactly, but can still be used to present to the surface successfully."
2020-05-21 15:04:08 -07:00
Romain Guy f5068457f2 Update README.md 2020-05-21 14:44:34 -07:00
Pixelflinger 3a3cd1c0ec Better fix iOS lack of GL_EXT_multisampled_render_to_texture 2020-05-21 11:49:54 -07:00
Philip Rideout 7dfe26def8 Vulkan: update instructions for enabling validation. 2020-05-21 11:29:27 -07:00
Philip Rideout 3b3dc0af81 Vulkan: refactor the ENABLE_VALIDATION flag.
It is convenient to control the debug_info extension and the validation
layers from one central place. This makes it easier to force-enable
validation in Release builds to validate optimized shaders.
2020-05-21 10:46:53 -07:00
Philip Rideout 0e38cc770d filamat: generate spirv 1.0 rather than spirv 1.3
Since we are still on Vulkan 1.0, we cannot use SPIR-V 1.3.
If we try to do so, this error is generated:

    Invalid SPIR-V binary version 1.3 for target environment SPIR-V 1.0

In non-optimized builds, we were already generating spirv 1.0, but
when we enabled the shader optimizer, we generated spirv 1.3.

This bug has actually been around forever, but we did not notice because
we were only invoking the optimizer in release builds, which does not
enable validation.

We cannot upgrade Vulkan 1.1 because the latest LunarG SDK for macOS
does not support it.
2020-05-21 08:41:53 -07:00
Ben Doherty c0eb058728 Shadow cascades: adjust near / far planes to tightly bound scene (#2537) 2020-05-20 16:31:13 -07:00
Pixelflinger 8b515ee4c2 Make MSAA fast(er) again on Mobile
Due to a typo that became relevant when we switched the gles headers to
3.0 from 3.1, MSAA started to take the emulated path.
2020-05-20 11:53:27 -07:00
Philip Rideout 65e286e7de Vulkan: fix version selection. 2020-05-19 17:58:21 -07:00
Philip Rideout cdd099951a sample-page-curl: add rigidity parameter. 2020-05-19 16:48:55 -07:00
Philip Rideout 432ed50cb3 sample-page-curl: use inverseTonemap() etc. 2020-05-19 16:48:55 -07:00
Philip Rideout d4a396d52f matinfo / matdbg: fix SPIRV version, add validation.
The value we pass to spvContextCreate() is not SPV_ENV_UNIVERSAL_1_3,
which is what we use in GLSLPostProcessor.

Also add a call to spvValidateBinary(), which would have caught this
oversight.
2020-05-19 16:48:36 -07:00
Ben Doherty 97c9ad7599 Metal: implement lod clamping to fix IBL bug (#2556) 2020-05-19 15:40:07 -07:00
Philip Rideout 15e2447cb5 Vulkan: fix usage of timestamp queries. 2020-05-19 14:17:03 -07:00
Philip Rideout 21ed172c55 Vulkan: add support for sync objects.
This allows FrameSkipper to work on desktop.

Similar to the GL backend, we can only query the fence from tick().
The Vulkan spec stipulates that a fence object cannot be accessed by
more than one thread simultaneously. My initial implementation violated
this, which was caught by the validation layer.
2020-05-19 14:16:07 -07:00
Pixelflinger c619f089e7 add support for 3D textures
Only gl backend in this PR.
2020-05-19 14:09:16 -07:00
Pixelflinger 29db39b6a7 Use a subpass for tone mapping when possible
This allows to never store/load to main memory the HDR color buffer,
saving precious bandwidth. This mode relies on the
ext_framebuffer_fetch extension being present and can't be enabled
with certain features (currently msaa, Bloom, DoF).

This will eventually be supported on Metal and Vulkan as well.
2020-05-19 12:25:41 -07:00
Pixelflinger b50f7dd7de Add isFrameBufferFetchSupported() to the backend API 2020-05-19 12:25:41 -07:00
Pixelflinger 6df20f3083 Add a private property to materials to control framebuffer_fetch
this is intended to be temporary until we properly add support
for vulkan's subpasses. this PR just helps us activate
ext_framebuffer_fetch on select materials.
2020-05-19 12:25:41 -07:00
Philip Rideout 5f34b8974f Fix buffer size bug in sample-page-curl. 2020-05-18 14:34:46 -07:00
Ben Doherty bf13f76dea Fix, Metal validation error with SSR and post-processing turned off (#2550) 2020-05-18 13:17:37 -07:00
Philip Rideout 92048e6b65 filagui: Fix "1 leaked FScene" warning.
Fixes #2542.
2020-05-18 11:51:23 -07:00
Ben Doherty c37c04762d Fix Metal memory leak inside MetalTimerQuery (#2548) 2020-05-18 11:48:16 -07:00
Pixelflinger 53a8fd94ba get rid of our details namespace
in practice it wasn't really useful, and it'll save some binary
space. everything is still isolated in the filament namespace.
2020-05-18 10:51:46 -07:00
Philip Rideout b4d16ab3b5 Tweak WebGL build settings. 2020-05-18 10:02:21 -07:00
Philip Rideout 0b1fa7fc80 Enable Vulkan for Android by default.
The presence of a special Gradle property is now used to exclude Vulkan
support from the build. By making Vulkan "always on" for local
development, we can avoid stale CMake cache issues that arise from
toggling the Gradle property. It also lets you avoid adding the flag
to Android Studio preferences.

This is motivated by testing and does not indicate production readiness.
Clients still need to pass VULKAN into the Engine constructor to select
the Vulkan backend.

To keep APK size down and keep CI fast, we are continuing to exclude
Vulkan from official Android builds.

After syncing this change, you might need to use `./build.sh -c` to
clobber various build caches.
2020-05-18 09:34:55 -07:00
Romain Guy 010ce1c069 Update README.md 2020-05-16 14:33:07 -07:00
Romain Guy f6c3663789 Update RELEASE_NOTES.md 2020-05-16 14:32:17 -07:00
Philip Rideout d49d0f1762 Add JavaScript bindings for setVisibleLayers. 2020-05-15 12:53:02 -07:00
Ben Doherty 8780d7aae5 Bump version to 1.7.0 (#2541) 2020-05-15 10:41:51 -07:00
Ben Doherty 1ac6f5bbfe Cast shadows by default in gltf_viewer (#2538) 2020-05-15 09:43:21 -07:00
Philip Rideout 764d4198bc Add headless support to FilamentApp and frame_generator.
These changes make it easier to test headless rendering in macOS.

I verified that this works using the frame_generator tool, however
it requires the fixes in PR #2529.
2020-05-14 16:41:39 -07:00
Philip Rideout d5d77a46ec macOS: fix headless rendering. 2020-05-14 16:38:07 -07:00
Philip Rideout fb8b9af8fd FilamentApp: do not recreate SwapChain upon resize.
This is done for consistency with the Android samples. Tested with
gltf_viewer against Vulkan, Metal, and OpenGL. Dragged window between
high DPI and low DPI displays.

Since resizing does not trigger the "NSView has changed" handler in
PlatformCocoaGL, it now must to detect a resize in order to make the
required call to NSOpenGLContext::update() as per the following
documentation.

https://developer.apple.com/documentation/appkit/nsopenglcontext/1436135-update

Fixes #2528
2020-05-14 16:38:07 -07:00
Ben Doherty f26b556fce Metal: allow swapchain size to change (#2535) 2020-05-14 15:47:49 -07:00
Pixelflinger 9e11e52c92 always hold a global ref on the surfacetexture
We were not holding a global ref on more recent version of android,
this made the Stream API inconsistant. 
Filament now always keeps a global ref on the surfacetexture while in
use.
2020-05-14 15:27:15 -07:00
Pixelflinger 52573ecd95 don't kick the driver thread after each framegraph pass
this was a misguided optimization, on low-end devices this actually
has a large overhead (presumably because of the smaller cache and
increased branch missprediction as well as extra synchronization).

on some low-end devices we see the gl thread go from ~40ms to ~10ms
with the gltf sample.
2020-05-13 19:36:19 -07:00
Pixelflinger 79995349d8 use systrace when EXT_debug_marker is not supported
EXT_debug_marker is not supported GL debuggers won't show these
markers, so as an alternative, we dump them in systrace.
2020-05-13 19:36:03 -07:00
Pixelflinger e31ebb7a82 Fix a few issues with dithering
- only triangular noise needs to be scaled between +/-1, other noises
  have a uniform distribution and need to be scaled between +/-0.5

- all dither routines work in RGBA

- fixed FXAA in opaque mode when dithering modified the alpha channel
  (which is used by FXAA). This fixes flickering when FXAA and dithering
  was enabled.

- use triangular noise dithering on mobile and desktop. The cost in
  not measurable on a pixel 4 / 1080p, and the quality is better.

- refactor dithering code a bit such that:
  - noise methods are not temporal
  - all dither functions have the same structure
2020-05-13 17:16:58 -07:00
Pixelflinger b4f09325f1 PerViewUib header and .cpp padding didn't match
It wouldn't really cause any issues, because still.
2020-05-13 10:58:23 -07:00
Mathias AgopianandPhilip Rideout ee3c3d0965 debug option to track Entities (#2526)
* debug option to track Entities

Set FILAMENT_UTILS_TRACK_ENTITIES to true when building libutils to
activate entity tracking. This adds two public methods:

getActiveEntities() and dumpActiveEntities() the later displays the
stack trace of where the remaining entities were allocated.

This is useful for tracking leaks.

* Update libs/utils/include/utils/EntityManager.h

Co-authored-by: Philip Rideout <philiprideout@gmail.com>

Co-authored-by: Philip Rideout <philiprideout@gmail.com>
2020-05-12 17:55:39 -07:00
Mathias Agopian d08a4e8bd9 Very basic SwiftShader support (#2523)
* Very basic SwiftShader support

- we only provide SwiftShader's khornos headers in third_party

- swiftshader itself must be available on the host (for instance it
  can be compiled from source).

- to enable pass -DFILAMENT_USE_SWIFTSHADER=ON option to cmake

- only GLES 3.0 is supported. Vulkan is not yet supported.

CMake should find the swiftshader libraries automatically, but if
they're installed in a non-standard place, the environment variable
SWIFTSHADER_LD_LIBRARY_PATH can be set to that place.


We also use the GLES 3.0 headers everywhere, since we don't rely on 3.1
at this point.

* add a tnt folder with a README
2020-05-12 17:45:16 -07:00
Philip Rideout 0a9236c2eb Make JNI constructors private unless they take Engine.
This removes (rather than deprecates) all public constructors that
take a native pointer without an accompanying Engine.

Most notably, MaterialInstance had a public pointer constructor which
is now package private. This means that FilamentAsset needs an Engine,
so it now takes the one from AssetLoader.
2020-05-12 15:41:19 -07:00
Philip Rideout 0a61faa57a KtxLoader should pass Engine to Texture constructor. 2020-05-12 10:57:21 -07:00
Philip Rideout 26520c8d23 filament-utils: Improve ModelViewer flexibility. 2020-05-12 10:57:21 -07:00
Pixelflinger 64b3d7807b Fix Entity leaks with Camera
- When creating a Camera component, it is the responsibility of the caller
to destroy the Entity. ShadowMap didn't do that, so it would leak two
entities.

- When destroying a Camera component with the legacy (and deprecated)
API, Engine::destroyCamera() should destroy the associated Entity
(and was documented as doing so). However, it actually didn't.

- don't use the static EntityManager is ShadowMap.
2020-05-12 10:08:13 -07:00
Pixelflinger ec77086186 only libbackend should link against gl/vlukan/etc...
filament itself should be agnostic to the rendering api
2020-05-12 10:07:53 -07:00
brian.wangandbrian.wang 0187caf10f Fix minor bug in Vulkan backend on Windows
* fix compile error when vulkan

* matc:print shaders support

* fix link error

* ussage for matc print flag

Co-authored-by: brian.wang <brian.wang@noitom.com>
2020-05-12 08:59:25 -07:00
Philip Rideout 823f5c9c1f WebGL: upgrade and accommodate EMSDK.
Fixes #2515.
2020-05-11 13:58:07 -07:00
Philip Rideout 9a47178b3d gltfio: expose getMaterialInstances to Java.
Tested locally by hacking gltf-viewer on Android, added the following
lines to MainActivity:

```kotlin
for (mat in modelViewer.asset!!.materialInstances) {
    Log.d("gltf-viewer", mat.name)
}
```
2020-05-11 10:39:13 -07:00
Ben Doherty a3fb5c41f1 Make note of VS2019 for building Android on Windows 2020-05-11 09:47:14 -07:00
Ben Doherty 58df2681dd Fix unused variable in release (#2504) 2020-05-11 09:33:51 -07:00
Kostiantyn Zghirovskyi 5ef816ef2a Clarify Windows build instructions (#2507) 2020-05-11 09:33:14 -07:00
Romain Guy 91f052a9b0 Clarify doc 2020-05-10 14:15:42 -07:00
Romain Guy 6a0a2d965e Update documentation 2020-05-09 15:13:25 -07:00
Kostiantyn Zghirovskyi 2260fe5b62 Fix filament-utils-android build on Windows (#2508)
* Fix filament-utils-android build on Windows

* Update build.gradle

* nit: use char version instead

* Fix No signature of method: java.lang.String.replace() is applicable for argument types: (Character, String) values: [\, /]
2020-05-08 16:57:16 -07:00
Pixelflinger e07f0dd244 Texture(Engine, long) instead of Texture(long)
deprecated Texture(long nativeTexture) in favor of
Texture(Engine, long nativeTexture), there is no difference
currently,  but in the future Texture(Engine, long nativeTexture) 
will be able to validate the native pointer.
2020-05-08 15:39:14 -07:00
Pixelflinger d194eec0ad report to java when an object can't be destroyed
The JNI layer already does this, but can only track objects it created,
sometimes developers might create filament objects on the native side
and wrap them into java objects and this might cause a failure to
detected when objects are double-destroyed.

However, this can often be caught by the native code -- so, when the
native side is asked to destroy an object that doesn't exist, we now
return an error (exception if enabled) and we throw an exception
on the java side.

Filament typically doesn't do this kind of tests, however these bugs
can be very hard to find, and the cost is small.
2020-05-08 15:39:14 -07:00
Pixelflinger addf325d42 better handling of invalid handles
- all backend return nullptr when handle_cast<> is called with
  an invalid handle. this ensures a prompt crash on all backends rather
  than different behaviors, some including potential memory corruptions.
  assert() in debug builds. The proper way to check is to cast the
  handle to bool.

- be more consistent in the GL backend about where we check for the
  validity of handle -- which is basically nowhere, except for destroy
  (because we have the same semantic than free(nullptr) -- i.e. no-op.
  Other places are treated like bad pointers, and as per above
  handle_cast<> will return nullptr.

- make sure we don't call FScene::updateUBOs with an invalid handle
  when the scene is empty
2020-05-08 15:39:14 -07:00
Pixelflinger c019781471 only log "no texture bound" in debug builds
This is way to verbose in release builds, and since it's not
a bug issue on GLES, we silence this for now.
2020-05-08 15:39:14 -07:00
Pixelflinger de849fa21f removed a wrong assert() 2020-05-08 15:39:14 -07:00
Philip Rideout 072d17d64f gltfio: use the new material name feature.
To see proof that this works, use gltf_viewer with -u and examine the
node hierarchy. You will now see the correct material names instead of
the ubershader names.
2020-05-08 11:24:38 -07:00
Philip Rideout 38b9cf4fe3 Vulkan: add support for resizing the window.
Fixes #334.
2020-05-08 09:46:49 -07:00
Philip Rideout d0a8c6b4fa Vulkan: refactor destroySwapChain. 2020-05-08 09:46:49 -07:00
Philip Rideout ab2ae245ba Vulkan: refactor createVkSurfaceKHR. 2020-05-08 09:46:49 -07:00
Philip Rideout f53f03b5dd Java MaterialInstance::getName now creates string lazily. 2020-05-08 09:44:49 -07:00
Philip Rideout 474fe9c5ed Change behavior of MaterialInstance::getName. 2020-05-08 09:44:49 -07:00
Philip Rideout c3c8293862 MaterialInstance now has an optional name.
When no name is provided during instance creation, it does NOT inherit
the name of its parent material. This is because instances should be
lightweight and users can already do instance->getMaterial()->getName().

In a subsequent PR, this feature will be exercised and tested via the
gltfio AssetLoader.

Fixes #2485.
2020-05-08 09:44:49 -07:00
Ben Doherty 3c42ace496 Fix, don't sample from cascades without visible shadows (#2501) 2020-05-07 16:50:34 -07:00
Romain Guy 2702ef123c Update README.md 2020-05-07 13:26:57 -07:00
Romain Guy 89e76fde57 Update README.md 2020-05-07 13:18:23 -07:00
Romain Guy 37c8f1d8ea Update README.md 2020-05-07 13:16:43 -07:00
Romain Guy 8416553724 Update README.md 2020-05-07 13:15:12 -07:00
Romain Guy f3baecc4be Update README.md 2020-05-07 13:11:20 -07:00
Ben Doherty 89df8355aa Fix build warning (#2499) 2020-05-06 18:30:58 -07:00
Ben Doherty 0e00dbb967 Add up and down movement to free flight camera (#2494) 2020-05-06 18:30:43 -07:00
Pixelflinger 786dbdc6e4 fix JNI objects allocation and memory corruption
- we were allocating objects with a destructor in the command stream
  which is always invalid because there is no guarantee that when 
  the callback is called, the underlaying memory is still valid
  (and it wasn't).

- AutoBuffer move-ctor wasn't moving some of its state, which would
  lead to destroying the same ref several times.
2020-05-06 18:08:13 -07:00
KJ Liu 920dc6b167 AssetLoader now loads names for mesh-free nodes. 2020-05-06 17:59:20 -07:00
Pixelflinger 809379b93d only implement flushAndWait() debugging on android
it's causing some unrelated problem on the iOS simulator, and we're
looking for an Android bug anyways.
2020-05-06 17:42:48 -07:00
Ben Doherty 4701945c87 Add rudimentary cascading shadow map support (#2482) 2020-05-06 17:20:04 -07:00
Kostiantyn Zghirovskyi 2c79f4c480 Update building instruction on (#2496) 2020-05-06 16:14:38 -07:00
Philip Rideout cc29359897 gltfio: fix unbound texture warnings in ubershader mode. 2020-05-06 15:24:21 -07:00
Philip Rideout b54000ccb9 Add CMAKE_EXPORT_COMPILE_COMMANDS. 2020-05-06 12:21:49 -07:00
Philip Rideout c65194fce1 gltfio-lite: fix UBO errors. 2020-05-06 09:09:56 -07:00
Pixelflinger d8e2e60692 remove CreateEliminateDeadMembersPass which breaks UBO layout
this fixes a crasher when using --optimize-size
2020-05-05 18:17:31 -07:00
Philip Rideout fb643eb422 Update web site and JS tutorials.
This updates the tutorial markdown, fixes up the literate programming
Python script, and updates the web site itself.

The doc build script now uses a Pipfile instead of "requirements.txt",
which I find less frustrating since it does not interfere with other
Python projects on your machine.

Fixes #2483.
2020-05-05 12:39:25 -07:00
Pixelflinger e80ea979a4 improvements to DoF
- bokeh rotates with the aperture diameter
- match sample count on cpu and cpu sides which affects CoC calculation
- feather blur radius to avoid visible "steps" in bokeh size
2020-05-05 11:38:32 -07:00
Romain Guy 3e5fe994b9 Fix default lighting intensities in ModelViewer
They were waaay too high
2020-05-05 00:25:19 -07:00
Romain Guy 05def1a789 Update AGP 2020-05-04 17:55:39 -07:00
Philip Rideout b36d29ef77 Vulkan: fix array textures.
This fixes a crash with `lightbulb -m`.

- During VkImage creation, the subresource depth should be 1 since it is
  meant for 3D textures.
- Render targets should select a single level from an array texture, not
  all of them.
- Add debug_trap to validation errors to make them easier to debug.
2020-05-04 15:51:27 -07:00
Pixelflinger 898ae083ee asserts that the engine is not terminated in flushAndWait() 2020-05-04 14:29:01 -07:00
Nakshathru Ajay 9c75c1ecfa Adding support for openjdk 13 (#2477)
Updated gradle version to 6.3 for openjdk 13 support
2020-05-04 09:15:12 -07:00
Pixelflinger 13767c3bb4 Don't use gl_FragCoord anywhere as it breaks with custom viewports
This fixes dynamic lighting and SSAO when a viewport is not in 0,0.
In practice this currently happens only when all post-processing is
disabled.

Instead of using gl_FragCoord we introduce a new API, 
getNormalizedViewportCoord(), which as the name implies returns
normalized [0, 1] viewport coordinates with origin at the bottom-left,
on all platforms.

This is implemented in this PR by interpolating gl_Position.
2020-05-01 23:51:17 -07:00
Pixelflinger 064ebd56e0 Reduce DoF sample count from 25 to 11
We keep very the same (or very close) quality by exploiting h/w
filtering. On the flip side, this is not compatible with dithering,
which is removed here.
2020-05-01 23:50:49 -07:00
Pixelflinger b514b2e996 GL backend: Fix an issue with discardEnd flags
In OpenGL with use glInvalidateFramebuffer() for hinting controlling
the load/store of tiles. However, glInvalidateFramebuffer() conceptually
destroys the content of the framebuffer attachment.

This causes a problem when we want for instance to use a buffer for
reading only (e.g. a depth buffer) in multiple passes. In such
scenario, the attachment will be marked as "discard" (which is a
misnomer for storeOp==DONT_CARE in vulkan parlance), without the
intention of making the buffer invalid.

We fix this by ignoring the discardEnd flags entirely if a buffer
has not been written. In this case, we relying on the driver to not
write the tiles out -- but we don't have any other way to express
this in GL.

This issue cannot be encountered currently because the framegraph 
is not aggressive enough setting the discardEnd flags.
2020-05-01 18:19:23 -07:00
Philip Rideout 8c7fbb2e01 Fix stale IBL string in shadowtest sample. 2020-05-01 16:45:59 -07:00
Ben Doherty 3e67f628ee Bump version to 1.6.0 (#2474) 2020-05-01 15:58:56 -07:00
Pixelflinger 3bd1afedbd compute bitangeant in fragment shader
This saves 4 varying components.
Fixes #2092
2020-05-01 14:41:03 -07:00
Pixelflinger f19533b149 fix a arithmetic error in SSR when a symmetry was present
Make sure that Camera returns a positive field-of-view, even when
the projection matrix has a symmetry (negative scaling).
2020-05-01 10:15:07 -07:00
Pixelflinger dc5c48de33 fix a couple missing 'highp' qualifiers 2020-05-01 10:14:44 -07:00
Ben Doherty fc4b88b5e9 Fix incorrect lightspace 2D bounds calculation for stable shadows (#2468) 2020-05-01 08:56:09 -07:00
Philip Rideout 116b475161 Both Vulkan timestamps should use BOTTOM.
As per the spec:

```
vkCmdWriteTimestamp latches the value of the timer when all previous
commands have completed executing as far as the specified pipeline
stage, and writes the timestamp value to memory.
```
2020-04-30 13:37:21 -07:00
Philip Rideout cab4a660d3 Vulkan: fix race condition with queries. 2020-04-30 13:37:21 -07:00
Philip Rideout 72dafa4887 Vulkan: add support for timer queries. 2020-04-30 13:37:21 -07:00
Pixelflinger 4e873e8007 A new depth of field (DoF) post-process effect 2020-04-30 13:22:28 -07:00
Ben Doherty 64609cc4aa Update RELEASE_NOTES.md 2020-04-30 10:15:46 -07:00
Ben Doherty 8dc526b536 Update RELEASE_NOTES.md 2020-04-30 10:14:24 -07:00
Ben Doherty 0769aabf29 Add intensityCandela API to LightManager (#2465) 2020-04-30 10:12:09 -07:00
Pixelflinger db53ce62ad fix LightManager::forEachComponent()
the Instance id was off-by-one and didn't match the
given entity.

in gltf_viewer this caused contact shadows to not work
when there was only a single directional light
2020-04-30 00:23:39 -07:00
Ben Doherty d91eb1180f Respect all of ShadowOptions when building a light (#2463) 2020-04-29 08:46:41 -07:00
Philip Rideout 89d47eb05a Vulkan: fix lots of validation errors. 2020-04-29 08:45:23 -07:00
Ben Doherty e985546e81 Set a clear color when no IBL is present (#2440) 2020-04-28 17:57:12 -07:00
Romain Guy 8036d65adf Don't trip assert in debug 2020-04-25 17:01:28 -07:00
Romain Guy 6a95807105 Better fix for texture unit spew 2020-04-25 16:55:30 -07:00
Romain Guy 0a387e16d9 More key fixes for ImGui 2020-04-25 16:15:32 -07:00
Romain Guy 1ec45c670b Fix more ImGui key clashes 2020-04-25 16:10:53 -07:00
Romain Guy 5a9ebf8db0 Always bind the structure sampler (#2462) 2020-04-25 14:33:48 -07:00
Romain Guy abd852a9aa Improve matinfo output 2020-04-25 14:17:38 -07:00
Romain Guy 2c29c67df0 Cleanup on exit 2020-04-25 14:10:13 -07:00
Romain Guy 1d73027df6 Use a different key for spotLightEnabled 2020-04-25 13:59:36 -07:00
Romain Guy 54a4545ac5 Update README 2020-04-25 10:37:13 -07:00
Romain Guy 14ce9e30b9 Make the build more quiet (#2457)
* Make the build more quiet

* Add mising include
2020-04-25 01:13:30 -07:00
Romain Guy cc6361e4f9 Make CI scripts safer (#2456)
- Added an extra README file detailing what the scripts are for
- The scripts now display a warning and a prompt before requiring user confirmation to continue
- The system install commands are only executed in CI environments (ninja and cmake being installed as root without checking for the environment was a leftover from a previous non-GitHub based CI setup)
2020-04-25 01:03:29 -07:00
Ben Doherty 45ce2d3a17 Fix crash when using free flight and hovering outside of the window (#2454) 2020-04-24 15:38:15 -07:00
Pixelflinger 1b6c25ce68 some old adreno drivers don't support bool in UBOs
Fixes #2418
2020-04-24 15:10:37 -07:00
Philip Rideout e10530d3bb Vulkan: fix InvalidImageLayout validation errors.
It is illegal for shaders to sample from images that have a blit layout.
2020-04-24 08:47:19 -07:00
Pixelflinger 043cdcfcff simpify froxel GPU data structure
instead of storing two counters for point and spot lights, we now
only have a single counter for both, and the light data structure
has a type, the shader can use to decide what to do -- instead of
using two loops. In practice spot and point light code is very similar 
anyways. 

This simplify a lot the CPU side (as in make it less complex) and frees
up 8-bits in the per-froxel GPU data structure.
2020-04-24 01:42:27 -07:00
Pixelflinger 880bf0f061 remove the froxel remaping (unused) code
this was just an experiment, we'll never use it.
2020-04-24 01:42:27 -07:00
Philip Rideout 7bbea3e503 Vulkan: add support for 2D texture arrays.
In Vulkan, the arrayness of a texture is an aspect of the "image view",
not the image itself.

In my earlier attempt I used VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT on
the image, which MoltenVK does not support. Confusingly, that flag is
actually meant for rendering into a slice of a 3D texture, which we are
not doing.

Vulkan is hard.
2020-04-23 13:03:18 -07:00
Mathias AgopianandBen Doherty f8e0cedcdb Add java doc for LightManager (#2441)
* Add java doc for LightManager

Co-Authored-By: Ben Doherty <bendoherty@google.com>

Co-authored-by: Ben Doherty <bendoherty@google.com>
2020-04-23 11:02:57 -07:00
Pixelflinger 2a2c339cf5 improve code that generates froxel planes
we can calculate each plane direction from its clip-space equation
(which is trivial), instead of back-projecting 2 points and computing
the cross-product
2020-04-23 10:59:13 -07:00
Benjamin Doherty 9dcb1181f3 Fix camera mode optstr 2020-04-22 16:38:22 -07:00
Ben Doherty 09d9bbb035 Add camera flag to gltf_viewer and material_sandbox (#2438) 2020-04-22 15:23:18 -07:00
Philip Rideout 354d3222cb Vulkan: fix bad depth clears.
The Vulkan backend was failing to clear the depth buffer in apps that do
not have a textured skybox, such as hellotriangle.
2020-04-22 15:22:32 -07:00
Philip Rideout e6be4c312b Fix warnings. 2020-04-22 15:19:37 -07:00
Philip Rideout 0e2cf44ca4 Skybox now binds dummy texture.
This fixes unbound sampler warnings, as seen in our hellotriangle app.
2020-04-22 13:08:20 -07:00
Ben Doherty 2e0e19d9ce Add a new free flight camera manipulator (#2436) 2020-04-22 13:04:19 -07:00
Pixelflinger 63b863d55d fix yet another froxelization bug
This came up when trying to use a very small number of froxels like
1x1x1 (just one!). 

Some froxels where not detected as used when scanning horizontally,
this would happen when a sphere was fully inside a froxel (i.e. not
actually intersecting any planes), and this was the very last
column on the right.

Now we use the same code we use for Z and Y (which where working fine)
for the X loop.
2020-04-22 11:51:51 -07:00
Pixelflinger 39c85dcbbb handle the case where we have only a single z-slice 2020-04-22 11:51:51 -07:00
Pixelflinger 45119fe15b fix a floating-point exception when the viewport is too small
this could lead to w/h froxel count to be 0, later leading to
divide-by-zero. There could also be a case where the viewport itself
had w/h of zero, also leading to divide-by-zero exception.
2020-04-22 11:51:51 -07:00
Pixelflinger 44c6ba2618 more clear fixes
- there was a case where setting a clear color on the Renderer
  would clear a blended view with that color instead of transparent
  pixels.

- move configuring the ui view into ImGuiHelper

- fix gltf_viewer sidebar so its background is not uninitialized
2020-04-22 00:43:37 -07:00
Pixelflinger af48d7cff1 add a warning log when there is no texture bound to a used texture unit
sometimes this happens because the shader actually doesn't use the
texture (e.g. in a uber shader model), however this is an error in
metal and vulkan.
2020-04-22 00:43:14 -07:00
Philip Rideout 277a999bca Fix swizzle warning in WebGL. 2020-04-21 13:51:00 -07:00
Ben Doherty f231368031 Update README on supported iOS version 2020-04-21 10:06:03 -07:00
Philip Rideout a55b75a739 Remove monkey mesh dependency from samples.
The only apps that need this filamesh are suzanne and hellopbr. This
change allows us to modify + test Filament without re-invoking resgen.
2020-04-20 18:25:43 -07:00
Philip Rideout f51a6aacc8 Update cgltf to fix memory leak. 2020-04-20 16:24:27 -07:00
Philip Rideout cc61707cc2 Improve build turnaround by breaking dependencies.
This adds a new "backend_headers" target because small changes to any
backend cpp file was resulting in a huge build, causing materials to be
rebuilt, etc. Note that filabridge only needs DriverEnums, nothing else.
2020-04-20 15:37:21 -07:00
Romain Guy e7268a0d1a Update README.md 2020-04-20 14:57:58 -07:00
Romain Guy 94f5dcc984 Update README.md 2020-04-20 14:57:13 -07:00
Romain Guy 030e97b381 Update screenshots in README.md 2020-04-20 14:56:00 -07:00
Pixelflinger 760ec8861a fix an SSAO bug with transparents objects
it's not good enough to clear the SSAO buffer, we also need to clear
*all* buffers involved in the final SSAO buffer, in particular the
bilateral blur buffers.
all this clearing is needed because we ignore skybox pixels based on the
depth buffer test, yet we need an initialized buffer.
2020-04-20 13:24:12 -07:00
Philip Rideout 4c1fb83379 sample-page-curl: move license file out of resources 2020-04-20 12:24:12 -07:00
Philip Rideout 0e39423506 Vulkan: improve staticness and constness. 2020-04-20 10:16:28 -07:00
Ben Doherty cb53a68d71 Fix race condition with Metal timer queries (#2413) 2020-04-20 09:33:22 -07:00
Romain Guy 06593a97bb Add new --mip-levels option to mipgen (#2421)
This option (short: -m) can be used to limit the number of mip
levels generated. Using -m 1 allows to use mipgen as a cheap-ish
image converter.
2020-04-18 16:43:39 -07:00
Romain Guy c28d9ddb9d Fix support of paletted images and alpha channel in imageio (#2420) 2020-04-18 16:32:05 -07:00
Romain Guy 038cecd8e2 Fix emissive 2020-04-17 18:46:16 -07:00
Philip Rideout 26f6349487 Update MoltenVK, enable validation. 2020-04-17 17:53:40 -07:00
Romain Guy ddef5ec3c4 Change how emissive works (#2415)
Emissive was previously defined in exposure compensation stops, which
was confusing to many. It is now a value in nits, with the alpha
channel controlling how much the camera exposure affects the emissive.
At 0, the emissive value is just added to the final pixel color, at
1 the emissive value is multiplied by the exposure just like with
regular lights.

The intensity of the emissive property can be computed from an
exposure value (EV) easily with the following formula:

emissive.rgb = emissive.rgb * pow(2.0, EV - 3.0);

This formula is available as Exposure::luminance(float) already
in Filament.
2020-04-17 17:42:21 -07:00
Pixelflinger 56285d6227 improve contact shadows support
- contact shadows are now supported for point and spot lights
- and are now independent from regular shadows, that is they can
  be enabled without enabling regular shadows

The only limitation currently is that the distance and step count for
ALL contact shadow are taken from the directional light options.
2020-04-17 17:40:32 -07:00
Philip Rideout 0691283a99 Fix crash in "strobecolor" test. 2020-04-17 11:49:50 -07:00
Philip Rideout 1e4fa12f21 Fix IBL in hellopbr. 2020-04-17 11:47:55 -07:00
Philip Rideout e20442cad7 Use default backend in shadowtest. 2020-04-17 11:42:15 -07:00
Ben Doherty 6555e09a96 Metal backend: get rid of non-const global variables (#2406) 2020-04-17 11:31:41 -07:00
Philip Rideout bee9ab31bc Add new Android demo: sample-page-curl.
Pure Java app that demonstrates custom vertex shader animation and
two-sided texturing.
2020-04-17 11:12:55 -07:00
Romain Guy 6ef7f82df8 Fix debug builds 2020-04-17 10:59:39 -07:00
jaynus 6f38aaea31 Add USE_STATIC_LIBCXX to CmakeLists.txt for the ability to toggle whether to compile with static or dynamic libc++. The current configuration forces static libc++ compilations (#2410) 2020-04-17 10:23:48 -07:00
Philip Rideout 98b17780fb matc: do not crash when material passes bad out arg.
Our enum-to-string converter was throwing an exception rather than
printing a friendly error message in some cases.

To be specific, I hit this when writing:

    vec3 worldTangent;
    toTangentFrame(mesh_tangents, material.worldNormal, worldTangent);
2020-04-16 17:49:55 -07:00
Pixelflinger 3159bb2516 texture swizzling is immutable
texture swizzling is now set at creation time to accommodate 
vulkan/metal texture immutability
2020-04-16 15:23:38 -07:00
Pixelflinger 6054a28b78 fog: correct for exp2 used in the shader 2020-04-16 15:02:29 -07:00
Romain Guy 1ccb311266 Really fix the continuous builds 2020-04-16 12:44:21 -07:00
Romain Guy 8587d6b15d Fix continuous builds 2020-04-16 12:09:48 -07:00
Romain Guy 2ad1e9a9a8 Safer build script (#2403)
Fix a ton of warnings, mostly around escaping values to avoid
splitting.
2020-04-16 11:35:40 -07:00
Romain Guy 9b1a0e2f58 Remove of static JNI fields (#2400)
Static JNI lookups were causing issues with multiple libraries.
We now do the lookups when we need them as they are effectively
just hashmap lookups and we do them only in places where the
work we need to perform will be much larger than a simple hash
map lookup anyway.

This chane also manually registers filament-utils JNI bindings
to get rid of unnecessary symboles. We should do the same for
other Filament libraries (the symbols are pretty long and
we now have many of them).
2020-04-16 09:00:54 -07:00
Pixelflinger e7df636368 fix spotlight documentation and clamping
filament spotlights use half-angles, which is the same as gltf.
2020-04-15 22:00:26 -07:00
Pixelflinger afade93bad Fix a froxelization bug
we would be short by one froxel on the left, usually this wasn't
a problem due to the light falloff.
2020-04-15 22:00:10 -07:00
Pixelflinger 8ae8dd59b1 fix a strange static initialization problem on macOS
It looks like using `half` during static initialization causes issues,
where sometimes these values are not initialized correctly.
The problem goes away when some other random static initializer 
executes, which suggests a race, except there is only a single thread
at that point.

I think for some reason `half4` are not put in the data section where
float4 are.

note: we don't understand the exact issue yet
2020-04-15 19:13:50 -07:00
Romain Guy bf97e7e15a Add ground-truth option to cso-lut (#2398)
The ground truth is computed using a Monte Carlo simulation.
2020-04-15 14:51:52 -07:00
Romain Guy b29311f23e Use a simplified fast acos() for specular AO (#2397)
The two spherical caps used in the intersection computations
have angles in the range 0..pi/2.
2020-04-15 14:48:46 -07:00
Romain Guy 5d3cceb2bf Fix typos in documentation 2020-04-15 10:58:13 -07:00
Philip Rideout c52f8908f8 Vulkan: populate all fields of VmaVulkanFunctions. 2020-04-15 10:02:39 -07:00
Pixelflinger cb5fcbc784 get rid of the static list of Engines
Originally it was used for validating the Engine* used, but this
makes no sense (no reason to validate this pointer more than any
other one).

The list also made sure that Engine instances were automatically 
destroyed when the filament library was unloaded, but again, there
is no reason to do this -- it's C++ after all!
2020-04-14 18:48:40 -07:00
Mathias Agopian ca7ef8cbae Fix point/spot lights when viewport is not in 0,0 (#2392)
the problem was that the actual viewport's origin can be different
from the viewport set by the user, for instance when the view is
rendered in an intermediate buffer.
2020-04-14 18:48:04 -07:00
Pixelflinger ed326e1e68 Implement texture swizzling 2020-04-14 18:46:21 -07:00
Romain Guy 8094955fc1 Add new tool cso-lut (#2394)
* Add new tool cso-lut

This tool is for internal usage only. It computes a 3D lookup table
for cone/sphere occlusion computations. These can be used to implement
specular occlusion, directional ambient occlusion, etc.

* Improve generated comment

* Fix Windows build
2020-04-14 18:22:56 -07:00
Pixelflinger d31f57eb22 ssao blur: don't forget to attach the depth buffer
the depth buffer in this case is only used for 
skipping the skybox
2020-04-13 15:54:44 -07:00
Pixelflinger ada5444997 fix issues with ignoring beginFrame() return value
ignoring beginFrame() return value is allowed, but doing so would
leave filament in an invalid state.

we now make sure that we don't execute any code after determining whether
the frame should be skipped, and execute the remainder of beginFrame() 
upon the first call to render(View*).

We also make sure the FrameSkipper can deal with its endFrame() being 
called when the current fence hasn't signaled.
2020-04-13 15:54:29 -07:00
Romain Guy 3c26c2cec1 Fix another typo 2020-04-13 15:47:43 -07:00
Romain Guy 7cdc0c032f Fix typos 2020-04-13 14:27:31 -07:00
Philip Rideout 854fcc7eac Desktop samples now use default backend.
There is nothing specific to Vulkan in these tests, I meant to remove
the backend override when I removed the `vk_` prefix last week.
2020-04-13 13:55:32 -07:00
Ben Doherty 0e82fdbddd Use the correct size for the ImGui glyph atlas (#2386) 2020-04-13 12:56:55 -07:00
Ben Doherty f26b761d72 Revamp MetalFence and implement Metal sync objects (#2380) 2020-04-13 10:22:42 -07:00
Philip Rideout 167493b85c Update Skybox / Clear API for web. 2020-04-10 17:06:47 -07:00
Pixelflinger 7fc60db151 update Release Notes 2020-04-10 17:05:40 -07:00
Mathias Agopian 1b36f82c1e API BREAKAGE: this change aims to fix multi-view support (#2376)
* API BREAKAGE: this change aims to fix multi-view support


What has changed:
- View doesn't have a notion of clear color anymore
- View doesn't have a notion of discard flags anymore
- The clear color and color-buffer discard/clear flags are moved to Renderer
- Skybox can now be set to a constant color
- View have a blend-mode

What does is all mean:
"Clearing" (i.e.) setting its background is now handled by Skybox, by
setting a constant color to the Skybox. This should take care of
drawing views side by side.

When a view needs to be drawn on top of another, it's BlendMode needs to
be set to TRANSLUCENT and of course and, generally, it wither won't have
a skybox, or will have one that sets some translucent pixels.

As an optimization, a View with BlendMode::OPAQUE will have its
background cleared with the color specified in Renderer.

If the SwapChain already has some content, it's now possible to set
the Renderer to not discard the content, together with TRANSLUCENT views,
it's possible to draw on top of that content.


It is NOT possible to share depth/stencil buffers between views.

Fixes: #2369, #2372, #2364

* Address reviewers comments.

Note: WebGL is still broken with this PR
2020-04-10 15:54:14 -07:00
Romain Guy 95c8dd0185 Update README.md 2020-04-10 11:26:06 -07:00
Ben Doherty 63801d2460 Implement headless swapchains on Windows (#2374) 2020-04-09 15:09:18 -07:00
Ben Doherty a60ee4914f Fix getRootAssetsPath on Windows (#2375) 2020-04-09 13:01:25 -07:00
Mathias Agopian d4f9ede84b improve DisplayHelper to handle frame rate changes (#2366) 2020-04-09 11:32:22 -07:00
Pixelflinger 6bb909bd0e newly created color buffers were not cleared properly
there were cleared with the view's clear color instead of 0
2020-04-09 11:30:31 -07:00
Romain Guy c5a5d15fe3 Fix Vulkan linking with specific versions of CMake 2020-04-09 08:50:44 -07:00
Romain Guy c69547f8ea Only build x86 and arm64-v8a in presubmit (#2370)
* Only build x86 and arm64-v8a in presubmit

* Pass the ABI arguments to the build script

* Pass comma delimited list to Gradle
2020-04-08 18:43:15 -07:00
Romain Guy 1ef3535ba7 Expose Java API to control discard flags (#2368)
* Expose Java API to control discard flags

This change also adds the new sample sample-multi-view that shows
how to use discard flags to render multiple views.

* Disable clears
2020-04-08 16:03:49 -07:00
Romain Guy 3945c232d7 Build all ABIs by default with Gradle 2020-04-08 15:36:49 -07:00
Romain Guy db18b2e07b Add the ability to build speific ABIs for Android (#2367)
For instance to build only 64 bit variants:
./build.sh -q x86_64,arm64-v8a release

This change also cleans up build.sh and Gradle files.
2020-04-08 15:06:47 -07:00
Pixelflinger a9814f8a88 Improve dynamic resolution tracking
This new code is better able to reach the desired target as it 
continuously evaluates the best scale factor based on the current
known state.
2020-04-08 11:27:34 -07:00
Pixelflinger 2adfb259c6 fix shader overflows leading to black pixels
we clamp the output of post_process materials to 0,FLT16_MAX
2020-04-08 11:27:18 -07:00
Pixelflinger 240d8cd79b improve latency a bit
we now flush the backend (e.g. GL) after the color pass, this a 
good time because a lot of GPU work has been queued by that point, this
allows the GPU to start while we queue the post-processing commands.
This reduces latency by about 2.5ms on pixel4.
2020-04-08 11:27:03 -07:00
Romain Guy 85c563b628 Fix BusterDrone
Some parts where marked as transparent but they truly are opaque.
This was causing issues with SSAO.
2020-04-08 11:18:56 -07:00
Philip Rideout 68a78a77a8 gltfio-lite: remove tex matrices, spec-gloss, etc.
gltfio-lite now has its own template file rather than re-using the
ubershader one, which allows us to optimize the materials by removing
support for various glTF extensions like texture matrices,
specular-glossiness, and clear coat.
2020-04-07 20:36:05 -07:00
Philip Rideout ad27d10503 Do not clobber VK_ICD_FILENAMES.
Fixes #2343
2020-04-07 16:28:01 -07:00
Philip Rideout 1366e3dcd1 gltfio: simplify skinning processing.
Moved all the skinning processing into one place.
2020-04-07 16:23:46 -07:00
Romain Guy 52086fe4d5 Remove debug code 2020-04-07 15:55:52 -07:00
Logan Lawrence d99f9cffb2 GEOSP-97 Added javascript binding 2020-04-07 13:09:48 -07:00
Logan Lawrence 33cbc6bba3 GEOSP-97 Added comments 2020-04-07 13:09:48 -07:00
Logan Lawrence 7794cd4c65 GEOSP-97 Removed some unnecessary changes 2020-04-07 13:09:48 -07:00
Logan Lawrence 574058e81e Added and updated javascript bindings 2020-04-07 13:09:48 -07:00
Pixelflinger 3ad4f2eceb fix a some problems with timer queries in the OpenGL backend
in OpenGL we need to check the status of queries on the gl thread,
so we did this in when beginFrame was called -- however, this is
too late, because beginFrame is asynchronous, so we were always
behind by 1 frame.

we fix this by running the callbacks more often.
2020-04-07 12:16:09 -07:00
Alexey Pelykh 56d9e1f727 Fix Gltfio.init(): call Filament.init() as well 2020-04-07 10:01:51 -07:00
Romain Guy 7c8849065c Update release notes 2020-04-07 09:38:23 -07:00
Romain Guy bf0dc32ee3 Change specularAmbientOcclusion from boolean to enum (#2352)
The user can now choose amongst 3 specular AO methods:
- None, specAO is off
- Simple, specAO is inferred from roughness and diffuse AO
- Bent normals, specAO is computed accurately from cone intersections

The last method is more expensive but produces the best results.

This change also fixes a few issues:
- Rename materialRefraction() and materialRefractionType() for
  consistency
- Fixes user time in shaders
2020-04-07 09:19:48 -07:00
Pixelflinger 887f8e8a1c better GPU timings on Android
On drivers that don't implement timer queries properly, we use
fences instead, however we can't use a fence to determine the start
time of the GPU work (only the end time). To workaround this we
use the last call to glFlush() as a proxy.
At least on Pixel it works very well.

We also remove all mid-frame calls to flush(), we did this to kick
cpu work early, but it's not as efficient as overlapping the work
with the previous frame, it increases latency a bit though.
2020-04-07 00:30:59 -07:00
Pixelflinger b1f95646d9 Add "sync" objects to the driver
A sync object for us is like a fence that cannot be waited on. It can
only be queried.
This is useful for filament to know if (not when) some previous
commands have finished executing.

In OpenGL this is different from "fences" which only exist in EGL and
can be waited on from any thread.
"sync" objects correspond to GLsync object in OpenGL and are widely
supported, as opposed to EGL fences.

So we use the term "fence" to refer to synchronization object that are
external to OpenGL and the term "sync" for the native gl synchronization
objects. This distinction may or may not exist in other APIs.


rewrite the FrameSkipper to use this, which enables it on MacOS.
2020-04-06 21:09:28 -07:00
piggie a282da78cd Adds texture support to filagui
Stores font texture as RGBA instead of R. This is because the ui material will not be compatible for RGBA textures, as it is expecting an R texture. I was unable get a texture with ALPHA format to function as I wanted.

This also removes material instance caching by scissor rect. Instead it just assigns the scissor rect to each new primitive, as well as an optional texture.
2020-04-06 19:21:20 -07:00
Pixelflinger 746e273336 rework how dynamic resolution scaling is specified
- now the DynamicResolutionOptions don't specify the target frame rate,
  they only specify how to scale this given view

- there is a new FrameRateOptions setting on Renderer, which is used
  to specify the desired target frame rate for the whole Renderer

- the frame rate is now specified as a "frame interval" in units of
  the display frame period.

- the display frame period is (indirectly) set via DisplayInfo.

In other words, the use must set (and update) DisplayInfo properly
(the default are reasonable, but assume 60 Hz). They must also set the
desired interval (default is 1, which is probably what you want).
Finally they must enable dynamic scaling per View, the defaults are
also reasonable.

Currently Renderer doesn't attempt (yet) to actually target the
requested frame rate, so it's up to the caller to push frames at the
desired speed. however, dynamic resolution, like before, will attempt
to shrink work to fit the target.
2020-04-06 16:55:24 -07:00
Pixelflinger b2dd6683be Add a way to query and set Display information
Renderer can now be given a DisplayInfo that contains some
important information about the current display. This will be used
for frame-pacing and dynamic-resolution.

This is most relevant on Android, where we can accurately query these
parameters. Added support for that in our samples.


This also sets the minSDK to 19 (including gltf viewer's), since this is
the version we support. We were cheating before by under-reporting our
minSdk.
2020-04-06 16:55:24 -07:00
Pixelflinger 526898e7d6 add vsync timestamp to Renderer::beginFrame() API 2020-04-06 16:55:24 -07:00
Pixelflinger 00f1c3dae9 [GL backend] ensure that Handle<> are synchronously constructed
Until now, only the memory of Hw handes was allocated synchronously,
handles were constructed later asynchronously. This was error prone
with the few (but growing) synchronous calls we have.

Now we have an init<> call that allocates and constructs handles synchronously,
the asynchronous construction if needed, is still performed with construct<>,
which is now implemented as "destroy+construct", this is okay because
most of our handles have trivial dtors.

This fixes a race with TimerQuery and Fence. Fences are still not fully 
working though, but at least won't access uninitialized memory.
Currently backend fences MUST be used trough FFence.
2020-04-06 16:44:35 -07:00
Ben Doherty bb88487b79 Fix test_material_parser build issue creating resource directory (#2350) 2020-04-06 15:33:25 -07:00
Romain Guy 92b7ee97f5 Kill specular AO at low roughness (#2348)
On metals (made only of specular light), specular AO can
create large black spots. This change simply kills specular
AO to avoid this artifact. In practice we should take into
account multiple bounces but this is rasterization...
2020-04-06 15:30:32 -07:00
Romain Guy 72056ee9e3 Fix support for 565 textures (#2347)
* Fix support for 565 textures

This requires exposing a new USHORT_565 pixel data type.

* Update JS bindings
2020-04-06 12:01:41 -07:00
Romain Guy 6330b1625c Udpate to AGP 3.6.2 2020-04-06 09:28:54 -07:00
Benjamin Doherty 27f4504dfc Implement timer queries for Metal backend 2020-04-03 18:10:39 -07:00
Pixelflinger fb0e89d969 fix a race-condition in JobSystem
mThreadMap needs to be protected as it's accessed from multiple threads.
2020-04-03 17:25:17 -07:00
Ben Doherty 2ad932f345 Convert from half to full angles for gltfio spot lights (#2340) 2020-04-03 17:06:03 -07:00
Philip Rideout d8ac60009c FilamentApp: use angle bracket syntax for includes. 2020-04-03 16:28:38 -07:00
Philip Rideout 37e2f46e10 Move FilamentApp into libs/filamentapp.
This will make it easier to migrate gltf_viewer into tools.

This is not a rewrite of FilamentApp, just a baby step.
2020-04-03 16:28:38 -07:00
Romain Guy 17dd44fd91 Fix documentation bug: the definition of SPOT and FOCUSED_SPOT was inverted. 2020-04-03 15:53:33 -07:00
Philip Rideout 26297feba7 WebGL: fix typo in default SSAO options. 2020-04-03 12:37:40 -07:00
Philip Rideout 05bc60f953 Bump version number to 1.5.2 2020-04-02 17:15:04 -07:00
Ben Doherty df2caf4f62 Expose setCulling to public RenderableManager API (#2331) 2020-04-02 17:07:19 -07:00
Philip Rideout 2dbe0b64be gltfio misc fixups 2020-04-02 14:54:19 -07:00
Philip Rideout c79f5a1a29 JobSystem: replace TLS with tid mapping. 2020-04-02 14:53:20 -07:00
Philip Rideout e072e30841 Expose Engine's JobSystem. 2020-04-02 14:53:20 -07:00
Pixelflinger aa770d54ae fix a potential use-after-free
It's possible for a timer query to be destroyed before the result is
known, in this case, we don't want to write through that pointer!
2020-04-02 12:02:21 -07:00
Romain Guy 559642d54c Move IBL settings in their own category 2020-04-02 10:49:07 -07:00
Philip Rideout 583157d4ef Remove vk_ prefix from desktop samples. 2020-04-02 09:06:50 -07:00
Philip Rideout 44422b3d69 Remove gltf_baker and related libraries. 2020-04-02 09:06:29 -07:00
Philip Rideout f084e50829 Remove old bloom samples to avoid confusion.
These should not be confused with our core bloom feature. For testing
the RenderTarget API, it would be better to create a small focused demo.
2020-04-02 09:05:36 -07:00
Pixelflinger e8a7d9f0c2 add support for timer queries in the backends
This adds a simple query API to the backend.
There are 2 methods to create/destroy queries, which are
essentially futures.  And 3 methods to mesure elapsed time:
beginTimerQuery/endTimerQuery and getTimerQueryValue.
The begin/end pair is not nestable.

On the GL backend side, there are 2 implementations of this, one uses
arb_timer_query or disjoint_timer_query, the other uses fences.
We need both implementations because on some GPUs, including
qualcomm's elapsed-time timer query is useless, as it measures
cpu time. 

Metal/Vulkan implementations will be part of subsequent PRs. Vulkan
will be able to implement this with vkWriteTimestamp which is
reported to be accurate.

An immediate benefit is that we can now get frame times on MacOS, which
should allow it to use dynamic-resolution.
2020-04-01 22:18:50 -07:00
Pixelflinger a389de3deb enable dynamic-resolution in android gltf viewer 2020-04-01 22:18:50 -07:00
Romain Guy 06eca637b0 Remove a mul from specular AO computations 2020-03-31 22:55:05 -07:00
Romain Guy 201bd2c845 Fix release action 2020-03-31 18:09:29 -07:00
Romain Guy e6500a8b3b Update web docs 2020-03-31 18:07:40 -07:00
Romain Guy db6636aff8 Preserve dependency version 2020-03-31 17:39:21 -07:00
Romain Guy ef35654ce9 Update to v1.5.1 2020-03-31 16:06:44 -07:00
Pixelflinger 4248eb148e fix uninitialized variable which could cause clearing errors 2020-03-31 15:31:54 -07:00
Pixelflinger 73c2a87444 fix a clearing bug with imported rendertargets
the view clear flags would not be honored when rendering directly
into an imported render target.

note: now that this works this could cause an issue when using
multiple views side-by-side and one of them doesn't have a skybox,
that view will trigger a clear of the whole buffer (because clears
clear everything, not just the viewport).
A solution will come in a later PR.

Fixes #2312
2020-03-31 15:31:38 -07:00
Philip Rideout 55d0063ced Fix "no texture bound" warnings in WebGL. 2020-03-31 15:20:18 -07:00
Ben Doherty ca70489556 Add a material parser presubmit check (#2313) 2020-03-31 15:04:01 -07:00
Philip Rideout 8d817ac787 ShadowMap: Fix potentially wrong EntityManager. 2020-03-31 14:39:09 -07:00
Romain Guy 9a550d69b8 Fix Github actions 2020-03-31 09:33:28 -07:00
Romain Guy 07d6aebafc Update release action 2020-03-30 21:48:41 -07:00
Romain Guy 32604e2c57 Fix sample-textured-object 2020-03-30 18:54:46 -07:00
Romain Guy adb107afc2 Fix sample-gltf-viewer 2020-03-30 18:53:14 -07:00
Romain Guy 8d9bd5f4fa Fix flavor dependencies, introduce flavors for filament-utils 2020-03-30 18:28:18 -07:00
Ben Doherty c88bbc21d0 Link hello-gltf iOS project with Draco (#2311) 2020-03-30 17:11:49 -07:00
Romain Guy 917edec0a7 Update RELEASE_NOTES.md 2020-03-30 16:22:45 -07:00
Philip Rideout 34959dd5e8 New version number for release notes, npm, maven. 2020-03-30 16:19:37 -07:00
Ben Doherty 82ab74efb0 Update RELEASE_NOTES and LightManager documentation for spot shadows (#2310) 2020-03-30 16:14:07 -07:00
Pixelflinger 968dbdb847 make sure "structure" pass is culled when not needed
the structure (depth path) wasn't culled even if both ssao and
contact-shadows were disabled.
2020-03-30 16:13:41 -07:00
Philip Rideout e43466d2bc Enable Draco for WebGL and iOS. 2020-03-30 15:58:55 -07:00
Philip Rideout cdf03f91c9 Apply Draco compression to FlightHelmet. 2020-03-30 15:58:55 -07:00
Philip Rideout abe70caeae Bump material version to prep for release. 2020-03-30 15:58:35 -07:00
Philip Rideout 4891bb6157 Fix SameSite warning for locally run web samples. 2020-03-30 15:58:24 -07:00
Ben Doherty f5e6ec42b3 Fix draco build with Xcode (#2306) 2020-03-30 15:06:53 -07:00
Romain Guy 92b2dd835d Add support for bent normals (#2303)
* Add support for bent normals

Bent normals can be enabled via the bentNormal property of a material.
When specular occlusion is enabled, bent normals improve the quality
of the computation.

* Save a couple of multiplications in bent specular AO
2020-03-29 17:00:03 -07:00
Philip Rideout 76f0309b58 Remove unused Draco targets from build. 2020-03-27 17:07:55 -07:00
Philip Rideout d9e9fabec5 Disable unused Draco features. 2020-03-27 16:32:44 -07:00
Philip Rideout a922e914b4 Enable Draco for Android. 2020-03-27 16:32:44 -07:00
Philip Rideout 4b7677fd13 Apply Draco compression to BusterDrone. 2020-03-27 16:32:44 -07:00
Ben Doherty 0474a6b8b5 Try to fix Windows build by reducing disk space footprint (#2301) 2020-03-27 16:05:50 -07:00
Philip Rideout 241f08bd74 Draco: do not add files to the build root. 2020-03-27 13:59:41 -07:00
Ben Doherty b8f8067a87 Support lights in gltfio (#2288) 2020-03-27 13:56:28 -07:00
Pixelflinger 965777da85 fix an assert() when using custom render targets
we now always mask out target bits that don't exist in the render
target before converting them to GLenums.

Fixes #2285
2020-03-27 13:45:54 -07:00
Romain Guy ffa62d4236 Check for CMake version before setting the policy 2020-03-27 11:50:21 -07:00
Romain Guy 94a01c6010 Be compatible with CMake 3.10 again (#2296)
* Be compatible with CMake 3.10 again

* Windows fix

* Add CMake changes to patch file
2020-03-27 11:15:18 -07:00
Romain Guy 232bf728c6 Update readme for Windows 2020-03-27 09:31:50 -07:00
Romain Guy 0e367580da Update CMake requirement to 3.12 2020-03-27 09:25:23 -07:00
Romain Guy 40aad197da Fixes various issues (#2292)
* Fixes various issues

- Fix gltf_baker crash
- Fix Python3 discovery on macOS
- Fix TBB CMake warning
- Fix bent normals baking

* Find Python 3 on Windows
2020-03-26 22:53:44 -07:00
Kai Chieh Liu (KJ) 劉凱傑 124fd2c978 Fix NameComponentManager dependency and Android build (#2291) 2020-03-26 20:02:03 -07:00
Philip Rideout 0d32c58e41 gltfio: add support for Draco (desktop only)
This needs a bit more testing before merging, but I wanted to put up the
PR for review. I will look into supporting Android after we land this.

Fixes #1932.
2020-03-26 19:52:26 -07:00
Romain Guy 09fa87ddfa Update README.md 2020-03-26 16:58:51 -07:00
Pixelflinger cb356606d9 fog improvements
- handle heightFalloff=0 (i.e. fog doesn't depend on height) correctly,
  previously, a divide-by-zero on the cpu side would get in the way.
  The fix is to clamp heightFalloff to a small-enough value, and to
  make sure that this is handled correctly in the shader.

- default fog distance is 0 instead of 1m

- inScatteringSize parameter should be allowed to be large in samples
2020-03-26 16:01:56 -07:00
Kai Chieh Liu (KJ) 劉凱傑andKJ Liu 3de9cc1533 Expose Renderable::getLayerMask() (#2289)
TEST: built on mac

Co-authored-by: KJ Liu <kjliu@amazon.com>
2020-03-26 15:31:38 -07:00
Ben Doherty f1aaf16082 Add spot light controls to material_sandbox (#2270) 2020-03-26 13:29:39 -07:00
Kai Chieh Liu (KJ) 劉凱傑 4c23f7a436 Fix cmakelist to install subdir properly (#2283) 2020-03-25 18:20:24 -07:00
Pixelflinger 2188923153 Fix fog with transparent objects 2020-03-25 17:10:36 -07:00
Romain Guy 2f47bab237 Update README screenshots 2020-03-25 14:23:36 -07:00
prewettg fe547a7690 Fixes resizing window not resizing the framebuffer on macOS (#2281) 2020-03-25 14:03:49 -07:00
Pixelflinger b4f5a4a0a0 Fog improvements
- optimized the fog computations
- fixed issues with the skybox
- added the option of getting the fog color modulated by the IBL envmap
2020-03-24 22:29:25 -07:00
Pixelflinger 5929d5d9dd improve quality of diffuse sampling on desktop
We 4-tap filter the diffuse map, which generally is very small
(e.g. 16x16), to improve quality a bit.
2020-03-24 22:28:59 -07:00
Romain Guy 0b7de0ec65 Turn off contact shadows by default in gltf viewer (#2277) 2020-03-24 16:44:48 -07:00
Romain Guy 87ac282014 Export missing headers for NameComponentManager (#2276) 2020-03-24 16:32:48 -07:00
Pixelflinger e525a7c7c4 enable some more features in lightbulb
spotlight/contact shadows, ssao, fog, bloom.
2020-03-24 16:15:58 -07:00
Romain Guy 8a84c7f0a3 Install all public headers from libutils 2020-03-24 15:46:23 -07:00
Ben Doherty e462c22a07 Fix MetalBufferPool crash in completion handler (#2273) 2020-03-24 12:35:54 -07:00
Philip Rideout 3ea8a25127 Add Draco 1.3.6 to third_party. 2020-03-24 10:13:13 -07:00
Romain Guy 45df197bd6 Expose libutils APIs that should have been public (#2269)
* Expose libutils APIs that should have been public

* Don't make JobSystem public for now
2020-03-24 09:57:04 -07:00
Philip Rideout 1ecb83bf73 gltfio: Big internal refactoring / simplification.
This replaces the "bindings" structures with simple types that re-use
data structures from cgltf.

This also moves some trivial work from ResourceLoader to AssetLoader,
which simplifies the communication between these two classes.

Motivated by #1932.
2020-03-24 09:22:20 -07:00
Ben Doherty aefa03291e Fix spot light shadow bugs related to light culling (#2264) 2020-03-23 16:12:44 -07:00
Pixelflinger 6e02fa186a generateMipmap needs at least 2 levels allocated 2020-03-23 15:05:00 -07:00
Pixelflinger 756074d8bd don't generate fog code in post-process materials 2020-03-23 15:04:42 -07:00
Pixelflinger 2caa09bebd Fix IBL mip calculation
The max mip (i.e. mip at roughness 1) was off by one.
2020-03-23 15:04:24 -07:00
Ben Doherty 72a182122a Update spirv-cross to 871c85d (#2262) 2020-03-20 16:59:47 -07:00
Pixelflinger 0688db7da3 fix a shadow clipping bug
In some situations the shadow map would be too aggressively clipped.
This was due to a bug in the box-frustum intersection algorithm, which
could fail when some vertices of the frustum were inside the box, and
some vertices of the box inside the frustum and the total number
of vertices such classified was 8.
2020-03-20 11:13:18 -07:00
Mathias Agopian 0c6d96c407 Add support for basic fog (#2256)
* Add support for basic fog

* address reviewers comments
2020-03-19 18:01:07 -07:00
Pixelflinger 1f48bd3e79 fix contact-shadows with shadow multiplier 2020-03-19 18:00:41 -07:00
Ben Doherty 7103f4f0b3 Share material dictionaries between GLSL / MSL (#2252) 2020-03-19 11:16:01 -07:00
Ben Doherty 210234255c Fix contact shadow GLSL compilation error (#2254) 2020-03-18 10:05:58 -07:00
Romain Guy 73312bc6bb Update README.md 2020-03-17 12:42:23 -07:00
Pixelflinger 6ea9872a3e fix computation of shading_posiiton for clip space domain shader
When reconstructing the position from clip-space, we need to apply
the .w divide.

Also use getWorldFromClipMatrix() directly.
2020-03-17 00:01:50 -07:00
Mathias Agopian d54ceff7a3 Add support for screen-space contact shadows (#2245)
* Add support for screen-space contact shadows

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

* Plumb settings for screen-space contact shadows

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

Additionally there is a per-renderable toggle.

Both toggles are off by default.

* Allow contact shadows when shadowing is auto-disabled


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

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

* apply micro-shadowing after contact shadows

also, don't compute contact shadows when we know we're fully shadowed.
2020-03-16 22:39:24 -07:00
Ben Doherty 6cf3e86c8a Fix iOS build samples CI (#2249) 2020-03-13 14:34:37 -07:00
Ben Doherty acc36e8d9b Deprecating Clang on Windows in CMakeLists (#2243) 2020-03-13 12:33:02 -07:00
Pixelflinger 1670e73287 Revert "enable ASAN's -fsanitize=address in debug builds"
This caused failures in CI builds.

This reverts commit c132ede510.
2020-03-13 11:20:47 -07:00
Romain Guy 3b52b89fd6 Update release notes 2020-03-12 19:18:55 -07:00
Pixelflinger c132ede510 enable ASAN's -fsanitize=address in debug builds 2020-03-12 19:18:29 -07:00
Pixelflinger 4e62e4f696 include alpha-masked objects in SSAO
this helps a lot with vegetations, which often uses alpha masking
2020-03-12 19:17:39 -07:00
Pixelflinger c0addf22ed Cleanup render loop to prepare for more features
- decouple the depth and ssao passes, so that the depth
  pass could be used by another client, down the framegraph

- set uniforms/samplers from the execute closure of the color pass,
  instead of using a separate pass. This is more correct and it 
  potentially reduces calls to commitUniforms.

- make setSampler check that the value set is different,
  the idea here is that it's much more costly to have to commit the
  samplers rather than having to compare them. Also realistically we
  don't have a lot of samplers in a frame, so that's not a lot of
  compares.

- one downside of this change is that commands for the SSAO pass are
  always generated, we will fix that in an upcoming change.
2020-03-12 14:31:56 -07:00
Romain Guy 880642ef4a Fix crash in glTF sample for Android 2020-03-12 14:27:11 -07:00
Pixelflinger 2f94e5990c workaround a framegraph bug with imported rendertargets
Imported render targets are only partially implemented, which
caused a discard flags bug. It would happen when an imported
 render target is used more than once like when using SSrefr
without tone mapping.  In that case, the 2nd pass would use the same
discard flags as the first pass.
2020-03-11 22:58:22 -07:00
Pixelflinger 4a5ce16322 Trivially make LinearAllocator 16 bytes instead of 24 2020-03-11 17:04:08 -07:00
Pixelflinger 454b08362d minor code cleanups
- go through 'FIXMEs' & `TODOs` and either fix or remove obsolete ones.
- add a few asserts
- fix some comments and IDE warnings
2020-03-11 17:04:08 -07:00
Ben Doherty f80c584db0 Update glslang to dbb56a1 (#2232) 2020-03-11 12:34:08 -07:00
Pixelflinger 68bcd6c159 fix setting an array mat3 as a parameter of material instance
this actually makes it possible to set mat3s from java.
2020-03-11 12:26:52 -07:00
Pixelflinger a9a9061f96 update GLSLPostProcessor optimization passes to latest
deactivate "mergeReturnPass" because it triggers a segfault with
AMD drivers on MacOS.
2020-03-11 11:11:28 -07:00
Pixelflinger 196c98fc2a Fix framebuffer clears
We make sure to only (and always) clear newly allocated buffers,
but only clear existing buffers based on the user request. This
should allow to share the depth buffer between drawing two
Views (if post-process is disabled). This should also fix 
a bug where the intermediate buffer wasn't cleared when blending
a view on to of another.

This should fix #2138
2020-03-11 11:11:09 -07:00
Ben Doherty 9ea2e69579 Fix gltf_viewer (#2233) 2020-03-10 17:57:59 -07:00
Ben Doherty f4da2ef8ec Add support for spot light shadows (#2209) 2020-03-10 17:53:25 -07:00
Pixelflinger 8fb65a19b4 fix utils::ctz() when builtins are not available
Our fallback 64-bits ctz() was completely wrong. 
The unit tests were wrong too.
2020-03-10 15:41:43 -07:00
Ben Doherty a2c6c34739 Update SPIRV-Tools to 2020.1 / SPIRV-Cross to 65aa0c3 (#2121) 2020-03-10 15:32:41 -07:00
Romain Guy a2818037b3 matinfo can print dictionaries, shrink Metal dictionary (#2230)
This change adds new commands to matinfo to print dictionaries.
This feature is useful to debug dictionaries, and I just used
it to identify that using a shared dictionary would save ~12 KiB
in the Android build. The macOS build (GLSL + Metal) would go
down to 71 KiB from 136 KiB.

The SPIRV to Metal conversion leaves leading spaces and some
comments. This change also runs the shrinker on optimized Metal
shaders to further reduce the size of shaders.
2020-03-10 11:42:19 -07:00
Romain Guy 02c7a22d43 Remove build time warning 2020-03-10 08:41:28 -07:00
Pixelflinger f6e993dfc8 fix bloom upsample shaders
We were not using the correct offsets, however because everything
was so blurry, it wasn't obvious that something was wrong.
This should result in a bit smoother bloom effect.
2020-03-08 22:28:25 -07:00
Pixelflinger 8866e2829f Add a quality option to dynamic-scaling
It controls the quality of the upsampling filter. This can help a lot
if heavy scaling is needed to maintain performance, it also helps if
MSAA is not enabled.

There are 3 quality levels, low, medium and high. 1, 4 and 9 bilinear
taps are used for each level respectively. The high quality setting
employs a tent filter.
2020-03-08 22:28:10 -07:00
Matthias Moulin d016e0f443 Replaced unnecessary std::forward with std::move
`execute` is an rvalue reference and not a forwarding reference, so `std::move` is more appropriate
2020-03-08 22:27:46 -07:00
Pixelflinger 0cbf6f8d76 disable spinlocks on ARMv7
we've had issues with some devices running in arm mode, where they
would throw spurious SIGILL on the WFE instruction used in spin locks.
Since on Android Mutexes are very efficient, we just use that instead.

This might fix #2197
2020-03-07 13:54:58 -08:00
Romain Guy 641b58c409 Be explicit about which NDK to use (#2221) 2020-03-06 16:53:41 -08:00
Romain Guy 5f0204f7b1 Clean build script 2020-03-06 15:36:14 -08:00
Romain Guy 660d1a1800 Enforce NDK 21 2020-03-06 15:24:45 -08:00
Pixelflinger 8d209a16c5 framegraph: destroy resources in reverse order
This is so that render targets are destroyed before their
attachments. In practice it doesn't matter too much, at least
on OpenGL, but it is cleaner.
2020-03-06 11:21:35 -08:00
Pixelflinger ed786701fc The FrameGraph is now emitting debug markers
A debug marker is emitted for each pass.
This greatly improves debugging with RenderDoc for instance.
2020-03-06 11:21:17 -08:00
Mathias Agopian 4842b1ca13 rework stream operators for libmath
libmath itself doesn't expose any stream operators anymore. However,
libutils is able to automatically print libmath types into its
io::ostream -- however matrices are not formatted nicely.

Added a new optional library, libmathio, that provides std::ostream
operators for all libmath types. libmathio does a better job at
formating matrices.

Also removed apply() and map() from libmath because there were not used
anywhere and they forced us to depend on <functional> in public headers.
2020-03-05 22:50:49 -08:00
Ben Doherty 0990550f45 Fix, mathfwd does not work correctly with MSVC (#2214) 2020-03-05 17:46:21 -08:00
Romain Guy 84b215c3b0 Switch to AGP 3.6.1 2020-03-05 17:11:47 -08:00
Ben Doherty 2a7724f601 Introduce ShadowMapManager class (#2207) 2020-03-05 15:32:00 -08:00
Ben Doherty b119d763da Fix visibility mask, encode enough SENTINEL commands (#2210) 2020-03-05 15:31:38 -08:00
Mathias Agopian ff25e6c18f Add support for MRT in the framegraph 2020-03-05 13:17:18 -08:00
Mathias Agopian 2677f05f0d get rid of the 'ignoreScissor' flag in beginRenderPass
The scissor is now always ignored -- i.e. when we clear, the whole
surface is cleared, which echoes how discard flags work. 
Geometry must be used to clear only a sub-region of the screen.

This simplifies a lot of things because we had workaround for Adreno
GPUs, which were slow when clearing with the scissor enabled.
2020-03-05 13:17:18 -08:00
Mathias Agopian bbfa47bbf0 More MRT support in the GL backend
in particular, we can now clear the proper draw buffer and
basic functionality works (tested on Adreno with systrace)
2020-03-05 13:17:18 -08:00
Mathias Agopian 060c0d2e6f remove discardSubRenderTargetBuffers() which isn't used right now 2020-03-05 13:17:18 -08:00
Romain Guy 414396efb6 Add background color selector to gltf_viewer 2020-03-05 12:58:52 -08:00
Philip Rideout 6825781718 gltf_viewer: fix string lifetime for #2190. 2020-03-05 09:26:27 -08:00
Ben Doherty 2494fff094 Refactor renderable partitioning scheme for spot light shadows (#2195) 2020-03-04 20:46:35 -08:00
Ben Doherty 924422261f Update ShadowMap for spot light shadows (#2206) 2020-03-04 20:20:32 -08:00
Philip Rideout f81e819901 gltfio: simplify API, privatize bindings.
The binding list can be internalized, clients should instead use
`getResourceUris` and `ResourceLoader` to load external resources.
2020-03-04 16:30:12 -08:00
Ben Doherty 81a2d70251 Use array texture for shadow maps (#2199) 2020-03-04 11:59:25 -08:00
Ben Doherty 3a2a40c76a Add additional shadow info to lights uniform (#2200) 2020-03-04 11:58:51 -08:00
Ben Doherty 6c3fa13e41 Changes to frameUniforms for spot shadows (#2201) 2020-03-04 11:58:31 -08:00
Philip Rideout 0ea2354be5 More TypeScript annotations. 2020-03-04 11:20:01 -08:00
Mathias Agopian 079056cfbc major FrameGraph rewrite (#2202)
Major changes are:

- RenderTarget are now real resources as opposed to ad-hoc objects.
  This allows to remove a lot of code and simply a lot of things.

- ResouceNode now have a level of indirection (i.e. we store a pointer
  to them), which allow fast and more correct implementation of
  moveResource(). 
  A new unit test checks that all scenarios of moveResource with a 
  generic resource are working.

- We have a special version of moveResource that moves a RenderTarget
  resource into a TextureResource -- this shouldn't be allowed, but
  this helps make the API better. What it means is that
  "all rendertargets that use the specified texture as attachment
   are replaced with the given rendertarget".

- In this version there are a lot of limitations when moving
  a rendertarget into a texture resource; be we cover the case that
  is useful to us.
2020-03-04 11:13:29 -08:00
Philip Rideout 1230fccbf9 JavaScript: Expose bloom and SSAO options.
Fixes #2198.
2020-03-04 08:43:20 -08:00
Ben Doherty 73e0facaed Save spot light outer clamped radius in light manager (#2193) 2020-03-03 14:25:26 -08:00
Ben Doherty 94b1ad52fa Add new Shadows uniform buffer (#2194) 2020-03-03 14:25:03 -08:00
Philip Rideout 6878d0d6e6 npm package now has a gl-matrix dep.
Our wasm API does not actually use gl-matrix, but we do import it
from our TypeScript declarations file.
2020-03-03 09:46:53 -08:00
Ben Doherty 76e7568994 Add visibility mask to RenderPass (#2183) 2020-03-02 16:14:52 -08:00
Romain Guy b176b2f0e6 Remove broken setLensProjection API (#2192) 2020-03-02 14:35:35 -08:00
Ben Doherty af5805e396 Update XcodeGen and iOS sample projects (#2191) 2020-03-02 12:54:17 -08:00
Romain Guy b98f45df60 Fix WebGL build (#2189) 2020-02-29 09:14:49 -08:00
Romain Guy bb2571233d Update RELEASE_NOTES 2020-02-28 23:50:35 -08:00
Romain Guy 00629bac48 Add camera controls to gltf_viewer (#2188)
Exposure: shutter speed, aperture and ISO
Focal length

The shadow plane can now be toggled  at runtime.
2020-02-28 23:46:17 -08:00
Romain Guy 81e7f619eb Try to fix compilation error on Android (#2187)
* Try to fix compilation error on Android

* Try with a newer NDK...
2020-02-28 13:10:16 -08:00
Ben Doherty b0ab9bb697 Remove unnecessary quotes from shader (#2186) 2020-02-28 10:50:52 -08:00
Romain Guy ae1e6f43f2 Only compile materials for Vulkan when necessary 2020-02-28 09:51:47 -08:00
Romain Guy 6eba2f145e Properly fetch project properties (#2185) 2020-02-28 09:20:35 -08:00
Romain Guy 13666027cc Switch native code API level back to 21 2020-02-28 07:55:09 -08:00
Ben Doherty 62cef096e1 Refactor computeVisibilityMasks logic, visibility bits (#2179) 2020-02-27 16:28:47 -08:00
Mathias Agopian af48b60876 split FrameGraphPassResources out of FrameGraph.cpp 2020-02-27 14:15:26 -08:00
Mathias Agopian b71357a955 Allocators shouldn't crash when allocation fails
The allocator debug code didn't check that allocations where
successful before filling buffers.
2020-02-27 14:15:11 -08:00
Romain Guy 9865a609da Refactor Gradle files (#2180)
We now share all the C++/CMake flags from the root project.
2020-02-27 12:46:01 -08:00
Romain Guy 77bafb295e Fix library loading issue on API level 22 and below (#2178)
This change fixes #2176
2020-02-27 11:30:47 -08:00
Philip Rideout ba4c9dbd09 Vulkan: use GENERAL layout for render target textures.
This fixes the validation error that occurs when rendering to one
miplevel while sampling from another. It might even be faster since
fewer layout transitions are required.
2020-02-27 09:33:38 -08:00
Mathias Agopian 4e9cf8ac02 Fir a deadlock when exiting on MacOS (GL backend)
Closes #2159

There was two issues:
1) Fence::wait would return prematurely when the the timeout was
   set to WAIT_FOREVER.

2) (At least) when running from the command line, events were not
   read from the main queue. Instead we have to use NSRunLoop instead
   of NSApplication APIs.
2020-02-27 09:33:14 -08:00
Romain Guy 108dae11e9 Add ground shadow option to gltf_viewer (#2174)
* Add ground shadow option to gltf_viewer

The shadow is always positioned at the bottom of the loaded object's
bounding box to ground it perfectly.

* Remove unused include
2020-02-26 17:09:31 -08:00
Benjamin Doherty 16de98291f Fix Metal filtering bug 2020-02-26 16:00:01 -08:00
Benjamin Doherty 547f8917b4 Update comment 2020-02-26 15:58:16 -08:00
Benjamin Doherty f1da2ca643 Update RELEASE_NOTES 2020-02-26 15:58:16 -08:00
Benjamin Doherty 9e6ea9454f Refactor depth variant 2020-02-26 15:58:16 -08:00
Pixelflinger fcd7e198c2 First step in reworking how rendertargets work in the framegraph
The ultimate goal is to get rid of the concept of render targets in
the framegraph, and this is the first step. Here RenderTarget doesn't
store the discard flags anymore. These flags are now calculated
per-resource, per-pass.

A side effect of this change is that the discard flags are now slightly
better, as they don't contain attachments that don't exist.
i.e. we won't see the STENCIL flag set for instance.
2020-02-26 15:57:42 -08:00
Pixelflinger 82523bd1d3 Add support for MRT to the backend
- this simply changes the createRenderTarget() API to take an
  'MRT' structure for the color attachment. The MRT structure is
  just a wrapper around an array of four TargetBufferInfo.

- in this PR only implemented for OpenGL
2020-02-26 11:39:57 -08:00
Romain Guy 4ec5fac95c Add support for KHR_materials_clearcoat to gltfio (#2169) 2020-02-26 10:11:34 -08:00
Pixelflinger 7fb3810eb1 cleanup command stream parameter passing
- the tuple<> where we store the parameters should only remove the
  reference, but not decay, so that arrays could theoretically
  be stored (more on this below).

- use std::forward<> instead of std::move<> in Command's ctor, this is
  more appropriate, we just want to forward the arguments unchanged.

- add std::move() to all parameters on the command stream stub, it is
  appropriate here, because we receive parameters by value or r-value 
  references.

All this was an attempt to support C-style arrays as parameters, but
it doesn't work because they are decay'ed to pointers when they
appear as parameters.
2020-02-25 21:29:59 -08:00
Romain Guy ed2fe83491 Update cgltf to latest (#2168) 2020-02-25 19:21:48 -08:00
Philip Rideout 3fd9c49fb9 Update WebGL docs and website. 2020-02-25 13:50:34 -08:00
Philip Rideout 69c0843d20 MaterialInstance refactor duplicated code. 2020-02-25 13:43:32 -08:00
Philip Rideout 3f7ef9738d Fix regression with getDefaultInstance().
This caused color writes to be disabled in our "hello triangle" samples.

Fixes #2164.
2020-02-25 13:43:32 -08:00
Romain Guy 3cfc6981a4 Only build OpenGL and Vulkan shaders in Android samples 2020-02-25 10:24:25 -08:00
Romain Guy 8b2ea72be2 Fix emissive in unlit shaders
This change applies exposure compensation just like with
lit shaders.
2020-02-25 09:47:06 -08:00
Romain Guy 8eaa1f5e88 Add options to skip samples (#2163)
-DFILAMENT_SKIP_SAMPLES=ON with CMake
-Pfilament_skip_samples with gradle

This change also renames CMake options specific to Filament
to avoid clashes with subprojects.
2020-02-24 18:15:33 -08:00
Pixelflinger c72f622a87 Minor changes to SAO
- minor uniform optimizations (saves ~0.1ms)
- fix some missing highp precision qualifers
- make it easier to tweak the blur filter
- make sure samples's radius goes from 0 to 1
- update comments
2020-02-24 18:06:49 -08:00
Ben Doherty 8a0505eb6f Fix Metal crash on Catalina (#2161) 2020-02-24 17:18:43 -08:00
Romain Guy 799e837f35 Upgrade to latest AGP 2020-02-24 12:28:29 -08:00
Philip Rideout 4690ce5602 WebGL: Improve the callback API for glTF.
After the native async functionality landed, there was no way for web
clients to be notified that the decoding has finished. This PR changes
the existing `onDone` callback so that it gets called after all textures
have been decoded. (Previously it was called after downloading rather
than decoding.)

This has the side effect of simplifying the API because clients no
longer need to call a finalize function.
2020-02-24 11:38:55 -08:00
Philip Rideout e972126cea Add missing TypeScript declarations.
This patches up all the holes discovered when I tried porting the
fidelity tests in `model-viewer` to our TypeScript declarations.
2020-02-24 09:35:22 -08:00
Mathias Agopian db40fd8983 More accurately evaluate the size of MSAA textures 2020-02-22 00:18:30 -08:00
Mathias Agopian c2db7b8afd fix a crasher when enabling bloom from java 2020-02-21 16:55:59 -08:00
Philip Rideout f403876784 Fix JNI signature for RenderTarget API.
Fixes #2151
2020-02-21 15:08:47 -08:00
Mathias Agopian 3a9d4c7c77 Another SSAO optimization saving another ~16%
During the SSAO pass, we pack the decoded depth to the GB channels of
the AO texture, which reduces our bandwidth requirements during the
blurring pass, as well as some ALU usage.
It puts SSAO at about 2ms on pixel4/1080p.
2020-02-21 14:15:06 -08:00
Mathias Agopian e737ece570 rollback misguided "optimization"
use gpu's sin/cos instead of approximation
2020-02-21 14:15:06 -08:00
Philip Rideout 948d19c446 Fix typo in upload script. 2020-02-20 16:31:57 -08:00
Philip Rideout ee81c9516a gltfio full flavor should use the old aar and maven names.
This should fix the Android build break. We do not want to change the
maven package name for existing gltfio clients.
2020-02-20 15:05:31 -08:00
Pixelflinger 675012a2eb Added a quality level parameter for SSAO
Currently it only selects how many samples are used.
Low,medium,high and ultra respectively map to 7,11,16 and 32 samples.
The default is "low", which is sufficient for most mobile applications.
2020-02-20 11:26:10 -08:00
Pixelflinger 31a4ef10e1 Use a smoother falloff function.
The improvement is really subtle, it makes the SSAO effect a bit 
softer.
2020-02-20 11:26:10 -08:00
Philip Rideout a0d43d51c9 Add gradle flavor for gltfio-lite.
This cribs the strategy from filamat-lite and also fixes a "more than
one file" gradle error.
2020-02-20 09:45:33 -08:00
Philip Rideout 31035d2b3c Optimize filament-utils (230 KB => 190 KB). 2020-02-20 09:45:33 -08:00
Mathias Agopian 4e8f323e47 Reduced AO processing time by 1/3
This is achieved by computing a small 2x2 box blur in the AO pass
taking advantage of quad shading, which allows to halve the size
of the bilateral blur kernel.

Reducing the size of the blur kernel has a side effect to kick Adreno
gpu into direct mode, which apparently is much faster here.

Overall we go from 3.4ms to 2.4ms on Pixel4.

The quality is impacted, but not severely. This probably assumes 
GPU that have working derivatives.
2020-02-19 22:09:53 -08:00
Pixelflinger 4dd3d7ab5e Greatly improve SSAO quality by using better samples
The power parameter now really controls the contrast. It's default value
is now 1, instead of 0.
2020-02-19 22:09:53 -08:00
Mathias Agopian 63a7bf5ee9 tweak SSAO
- got rid of all the precomputed samples for now, it makes things
  much more simple, and actually doesn't slow things down. Use the
  analytic offsets (spiral) instead.

- use textureLod instead of texelFetch in places where we need to do
  how own clamping, turns out it's faster (as measured on pixel4).

- use a interleaved gradient noise instead of a hardcoded blue noise,
  the difference isn't big.

Overall we're actually 0.2ms faster out of 3.5ms. It's not immediately
clear why, might just be noise.
2020-02-19 22:09:53 -08:00
Romain Guy 0473da9f05 Add support for ccache (#2148)
* Add support for ccache

To benefit from ccache, first install ccache (for instance with
brew install ccache on macOS). On my machine a clean build takes
~5 minutes the first time. A second clean build with ccache enabled
takes 34 seconds.

* Enable more aggressive caching
2020-02-20 11:36:36 +09:00
Pixelflinger e5447f7417 Cleanp-up PostProcessManager a bit 2020-02-19 14:41:00 -08:00
Ben Doherty 62810d8c87 Rework array texture support (#2136) 2020-02-19 10:52:12 -08:00
Philip Rideout ca81d48432 gltfio-lite: add BLEND material
This increases the size to 538K.
2020-02-18 11:55:47 -08:00
Philip Rideout b9c857130a Introduce gltfio-lite.
This is 466 KB insted of the usual 850 KB. It assumes that users do not
need spec-gloss, non-lit, or a special transparency mode.

(uncompressed SO size on arm64)

We can add a new maven project for this next week.
2020-02-18 11:55:47 -08:00
Philip Rideout a9bbc6d3c4 Fix syntax error in TypeScript annotations. 2020-02-17 09:26:27 -08:00
Pixelflinger 3a273b1837 fix a typo when thresholding for bloom
- also use step() to implement the threshold
- improve bloomOptions documentation
2020-02-15 22:19:35 -08:00
Romain Guy 5e6ff5a44f Update to a more recent version of AGP 2020-02-14 15:26:05 -08:00
Philip Rideout 65129d1b52 filament-utils-android: fix recent crash regression. 2020-02-14 14:56:38 -08:00
Philip Rideout 54d9d870ee gltfio size reduction 3/3: compile gltfio directly
This takes libgltfio-jni.so from 882 KB to 850 KB
2020-02-14 14:56:38 -08:00
Philip Rideout ffff6dd580 gltfio size reduction 2/3: proper shared linking
This takes libgltfio-jni.so from 966 KB to 882 KB
This takes libfilament-jni.so from 810 KB to 802 KB
2020-02-14 14:56:38 -08:00
Philip Rideout dc4a1ed5e5 gltfio size reduction 1/3: add more opt flags
This takes libgltfio-jni.so from 1.5 MB to 966 KB.
2020-02-14 14:56:38 -08:00
Mathias Agopian 8bbf0ce9ef Bloom can now have a dirt texture applied 2020-02-13 20:51:43 -08:00
Romain Guy a4e4021950 Update README.md 2020-02-13 20:03:51 -08:00
Mathias Agopian 87fe48225f On mobile, use a more efficient up-sampler
This doesn't affect quality significantly, but saves 30% of gpu time
on the upsampling, overall it's about 0.1 ms. This brings The bloom
effect below 2ms on Pixel4.
2020-02-13 17:40:55 -08:00
Ben Doherty af47fa9b6d Fix incorrect twoPassesOneSide rendering with Metal (#2133) 2020-02-13 17:32:26 -08:00
Mathias Agopian 3de1e197aa improve SSrefr highlights at low roughness
We untonemap/tonemap the first level of blur to reduce the very high
frequencies due to HDR highlights in the image, this produce a softer
image at higher roughness. This can programmatically be turned off,
but that setting is not exposed.
2020-02-13 12:26:25 -08:00
Mathias Agopian 2a1cbe67c6 Improve bloom performance on mobile
The very first downsample stage costs us a lot because it reads from
a full-res texture. We mitigate this by always doing a blit to
1/4 res. Blits are quite a bit faster, this saves about 1ms on
Pixel4.
2020-02-12 17:19:26 -08:00
Mathias Agopian f57404a3f0 split downsample and upsample passes 2020-02-12 17:19:26 -08:00
Mathias Agopian 87d815c659 Minor cleanup. Add FTexture::maxLevelCount()
We were computing this is many places. Validate better SSAO depth
buffer size.
2020-02-12 17:19:26 -08:00
Mathias Agopian 651ccb183e New mathfwd.h header
math/mathwfd.h forward declares all {mat|vec}{2|3|4}<> classes,
which allows us to remove their respective #include in a lot of
our public headers.
Our math headers are full of templates, so this should help build times
a bit.

Also we want to keep the public headers as minimalist as possible.
2020-02-12 15:30:13 -08:00
Philip Rideout 67406c42ec Clamp viewport width to prevent floating point exception.
To trigger an exception users could either shrink the window or enlarge
the sidebar. Constraining both of these is somewhat tricky so let's
just clamp the viewport width at a low level.
2020-02-12 12:07:51 -08:00
Philip Rideout cb953b4203 Remove usage of <regex> from Path.
There was actually no need to give special treatment to leading drive
designators since they effectively form the first path segment anyway.
To help prevent regressions, I added a few unit tests in a previous CL.

The motivation for the CL is to remove a dependency on `locale.cpp`,
which can result in shorter build times and reduced binary sizes.
2020-02-12 10:03:06 -08:00
Philip Rideout c0e2cfb684 Minor enhancements to test_Path. 2020-02-12 10:03:06 -08:00
Philip Rideout 9358c7313e Remove STL from ResourceLoader API. 2020-02-12 10:03:06 -08:00
Philip Rideout 02b377c244 gltfio: remove locale.cpp dependency
For Android and wasm we do not use the filesystem and therefore do not
need `utils::Path`.

```
libgltfio-jni.so BEFORE 1.9 MB (693 KB gzipped)
libgltfio-jni.so AFTER  1.4 MB (542 KB gzipped)
```
2020-02-12 10:03:06 -08:00
Romain Guy d2287f584a Fix comment 2020-02-11 17:33:56 -08:00
Mathias Agopian cc94820cb3 clean-up of dynamic scaling code 2020-02-11 16:31:21 -08:00
Mathias Agopian b17c51e340 Add a threshold option (enabled by default) for bloom.
Threshold can be either on or off, and only thresholds at 1.0 when 
activated (in pre-exposed mode).

This allows to use very high strengths values for the bloom without
softening the rest of the image, and is useful for artistic considerations.
2020-02-11 16:15:04 -08:00
Romain Guy 34dcc90ac7 Save a couple of mul 2020-02-11 16:12:23 -08:00
Mathias Agopian 8a1dc0ac65 Make sure sun in the skybox blooms enough
This is a temporary (hopefully) hack to make the skybox sun look 
better when bloom is enabled (this doesn't affect how the "sun" lights
objects, only how it looks in the skybox).
This scale factor was adjusted empirically.
2020-02-11 16:12:23 -08:00
Philip Rideout a61bc51271 Add Java bindings for SurfaceOrientation.
Note that libgeometry is already included in `filament-android`, this
simply exposes more of its existing functionality.

The Java version of SurfaceOrientation is similar to the JavaScript
version because we are bundling it into the main Filament package, even
though it is a separate library in C++. This is much simpler than
creating a brand new Java package.

New Android sample that tests this is forthcoming.

Fixes #1729.
2020-02-11 12:38:06 -08:00
Mathias Agopian bccb8260e2 Implement a Bloom post-process effect 2020-02-11 12:15:57 -08:00
Philip Rideout bedc609051 RenderPass: remove overrideMaterial. 2020-02-10 17:05:02 -08:00
Mathias Agopian f1cab9296a Fix a SSRefr when dynamic-scaling is enabled
because the intermediate buffer could have non-square pixels, blurring
the buffer would result in an anamorphic blur.

We fix this by properly scaling the buffer before blurring.
2020-02-10 16:07:40 -08:00
Philip Rideout 4665f6027f Add dynamic raster states to MaterialInstance.
Fulfills a request from tirichards@.

This is similar in some ways to dynamic backface culling but simpler
because there is no interaction with double-sided lighting.

For reference, dynamic backface culling was implemented with #1936, #1877, #1641.
2020-02-10 14:33:14 -08:00
Philip Rideout 891e85ba2b gltfio: add nominal support for flat shading.
This "fixes" the new animated Fox model in the glTF conformance suite.
As per the glTF spec, we now generate per-face normals for the case
where normals are not specified in the model.

Note that true flat shading (i.e. flat interpolation) is not a
requirement in the glTF spec, since some Khronos members advocate for
WebGL 1.0 compatibility.

Fixes #2088.
2020-02-10 14:29:04 -08:00
Mathias Agopian 6957f54547 improve SSRefr roughness with very strong highlight
Chose a filter width that preserve the "gaussianness" of the 
blur filter.
2020-02-10 11:22:15 -08:00
Ben Doherty 48ba111ccc Fix crash in Metal backend with screen-space refractions (#2104) 2020-02-10 10:34:44 -08:00
Philip Rideout 8f2df79a96 gltfio: clean up finalize(). 2020-02-07 18:54:46 -08:00
Philip Rideout 415aeef95b gltfio JNI: fix broken getName() method. 2020-02-07 17:15:28 -08:00
Philip Rideout cabd9be5f0 ModelViewer now implements OnTouchListener for convenience. 2020-02-07 15:20:41 -08:00
Philip Rideout 45e6e6eb18 sample-gltf-viewer now supports landscape orientation. 2020-02-07 15:20:41 -08:00
Philip Rideout b89cac48c5 gltfio: fix regression with un-textured renderables. 2020-02-07 09:44:42 -08:00
Mathias Agopian 00d55cddb5 fix screen-space refraction roughness calculation (#2108)
It turns out that textureLod() only reads the base layer if the sampler
is not set to xxx_MIPMAP_xxx. This prevented the gaussian-blur code
to work properly.
Specifically, the horizontal pass would always use the base layer. Not
only this made the blur unstable, but also hurt performance significantly.

With this change, the untonamap/tonemap is no longer needed and the 
results are much more convincing with objects with highlights.
2020-02-07 08:55:23 -08:00
Romain Guy 88dd32b1a7 Add emissive to material_sandbox 2020-02-06 16:20:22 -08:00
Mathias Agopian 20e7acd24d fix a typo in blit post-process material 2020-02-06 15:32:25 -08:00
Romain Guy 9be871f14b Don't use a LOD bias but a specific LOD in SSAO code 2020-02-06 15:31:33 -08:00
Pixelflinger 0b358081c3 make the gaussian blur pass more generic
the input and output are now separate (don't need to be the same
texture)
2020-02-06 14:37:04 -08:00
Mathias Agopian d172ae78fd minor improvements to SSRef code 2020-02-06 13:05:25 -08:00
Pixelflinger 5f1c9bc41b More comments and small bug fixes regarding MSAA
- always take the "blit" path (rather than quad path) when MSAA
  and is on. we now rely on the render target to have been resolved
  into its texture (implicitly or explicitly). This means in some cases
  there will be 2 bliss in a row -- but that's still better than a
  blit and a quad. These are unavoidable without using a custom resolve.

- removed creating renderbuffer with the EXT_multisampled_render_to_texture
  extension because we didn't support it fully and didn't support
  the fallback mode (for desktop or if the extension is not there).
  Also this case never happens currently.

- added more assert()

- added a bunch of comments explaining the restrictions of using MSAA
  regarding blitting.
2020-02-06 13:05:02 -08:00
Philip Rideout 317d78d7c6 sample-gltf-viewer: enable gzip compression for bin and ktx. 2020-02-05 18:45:30 -08:00
Romain Guy 46090793a8 Fully document refraction properties 2020-02-05 17:45:03 -08:00
Romain Guy c3a995dd3d Update README.md 2020-02-05 11:01:26 -08:00
Philip Rideout 8020f7eb78 gltfio: add plural version of popRenderable 2020-02-04 12:47:32 -08:00
Philip Rideout e8e847a662 gltfio: various cleanup in response to PR review 2020-02-04 12:47:32 -08:00
Philip Rideout d2c883877d gltfio: hide entities with not-yet-ready textures.
This feature adds one new method to `FilamentAsset` and uses it in our
Kotlin, JavaScript, and C++ helpers:

    utils::Entity popRenderable() noexcept;

This pops a ready renderable off an internal queue, or returns 0 if no
renderables have become ready. It provides a simple way for clients to
gradually add renderables to the scene as they become ready. Previously
clients could only get the entire list of entities, regardless of
whether they had Renderable components or complete textures.

To facilitate this feature, this PR adds a new internal-only class to
gltfio called `DependencyGraph`, which is a temporary object used for
bookkeeping during the asynchronous load.

`DependencyGraph` discovers ready-to-render entities by tracking the
textures that each entity depends on. This is a graph because
renderables connect to a set of material instances, which in turn
connect to a set of parameter names, which in turn connect to a set of
texture objects. These relationships are not easily inspectable using
the Filament API or ECS.
2020-02-04 12:47:32 -08:00
Romain Guy 0f7f6f6004 Update to cgltf v1.5 (#2097) 2020-02-04 12:27:38 -08:00
Philip Rideout ebadf9d6a3 Fix gradle invocation in build.sh for Vulkan. 2020-02-04 11:06:20 -08:00
Philip Rideout 94fb74d6aa Missing backend now throws Java exception, not segfault.
If a client application selects a backend that is not supported by the
build, Engine::create() now returns null, which allows the Java wrapper
to throw IllegalStateException. Prevously, we would crash in the native
layer by hitting a null pointer in Engine::loop().
2020-02-04 11:06:20 -08:00
Mathias Agopian 60b664d3b9 rework refraction filtering/blurring to improve performance
We now use a fixed-size kernel (right now 17), for each mip-level.
And we workout the mapping from roughness to such mip.

This improves performance by reducing significantly the number of taps
per mip, however, we don't control how much blur is actually applied
at each level. This gives a mip-chain that is proportional to
'roughness'.

It's now easier to tune quality vs. speed by tweaking the kernel's width
as well as how we map 'sigma' to a the kernel width.
2020-02-03 11:45:17 -08:00
Romain Guy eee9249dfc Fix table 2020-02-03 09:35:30 -08:00
Philip Rideout 7f7625b4a0 gltfio internal rename: URL => URI 2020-01-31 09:31:04 -08:00
Philip Rideout c681cd243a gltfio: Introduce the asynchronous API and use it.
We were already using jobs for decoding PNG and JPEG files, but we were
doing a join. This add three methods to ResourceLoader that allow
clients to amortize the decoding process across multiple frames, even on
single-threaded platforms like WebGL.

This PR adds async loading to the following demos:
- samples/gltf_viewer (now shows a progress bar in the UI)
- android/sample-gltf-viewer
- web/samples/helmet.html

Fixes #1876.
2020-01-31 09:20:48 -08:00
Romain Guy 503e66790b Docs fixup 2020-01-30 17:52:39 -08:00
Romain Guy a8dc91c238 Update static version of Materials.md.html 2020-01-30 17:46:46 -08:00
Romain Guy bc554f77f4 Add documentation for refractive materials 2020-01-30 17:43:21 -08:00
brian.wang dada7332c6 fixed compile error by vs2019 (#2087) 2020-01-30 16:50:23 -08:00
Philip Rideout 02b1d0a950 Add validation to VertexBuffer::build()
Clients should be prevented from allocating unused buffer slots because
uploading to an unused slot triggers undefined behavior in the backend.

Motivated by #2042
2020-01-30 15:25:18 -08:00
Pixelflinger bcde742bbc Revert "wip: rework filtering"
This reverts commit 79a83e8c46.
2020-01-30 11:37:41 -08:00
Mathias Agopian 79a83e8c46 wip: rework filtering 2020-01-30 11:33:06 -08:00
Mathias Agopian 3d56ff3547 Process SSR buffer in 11.11.10 format
This will help reducing bandwidth requirements while not affecting
quality significantly.
2020-01-30 11:33:06 -08:00
Mathias Agopian 218c3af11b Fix documentation about Camera's field-of-view. 2020-01-30 11:32:46 -08:00
Philip Rideout ad20a312d6 gltfio: refactor to prep for async API.
This adds most of the asynchronous functionality but does not expose it.
2020-01-30 08:53:01 -08:00
Benjamin Doherty ad788d6338 Fix some warnings 2020-01-29 13:33:02 -08:00
Benjamin Doherty 02b2b79060 Fix iOS samples 2020-01-29 13:32:45 -08:00
Mathias Agopian 610dca88a3 Remove everything related to the depth-prepass
depth-preass is no longer supported.
2020-01-29 13:32:45 -08:00
Romain Guy 00a6a68b9c Update Gradle plugin 2020-01-29 11:52:20 -08:00
Ben Doherty 7852fd2ffb Build iOS samples during CI jobs (#2076) 2020-01-29 10:59:19 -08:00
Mathias Agopian ead4b1d222 Stabilize the blur with an invertible tone-mapping
This helps if some refracted objects have very strong highlights.
2020-01-29 10:17:08 -08:00
Mathias Agopian f290742f1b Screen-space refraction
With this PR screen-space refraction is functional.

Caveats:

The blur passes for supporting rough refractive materials is quite
heavy and increases with the resolution.

SSR uses a gaussian approximation for the brdf and therefore doesn’t
match perfectly cubemap-based refraction and IBL.

The use of MSAA with screen-space effects, while working, is going
to incur a large cost, especially on tilers.
2020-01-29 10:17:08 -08:00
Mathias Agopian b31f267467 Get one step closer to have screen-space refraction
In this PR we look for object rendered with refraction
(which currently never happens), and split the command buffer into
two passes in that case.
2020-01-29 10:17:08 -08:00
Mathias Agopian 47db11a205 Added a post-process resolve() and blit() utility pass
- resolve can be used when resolving a multi-sample color
  buffer is needed

- quadBlit() can be used to blit a texture using a quad.
2020-01-29 10:17:08 -08:00
Mathias Agopian b263a89b07 Use SFINAE for Material::setParameter
This gives us a compile time error instead of link-time error, when
using a parameter type not supported. The code is also a bit more
self-documenting.
2020-01-29 10:17:08 -08:00
Mathias Agopian dbe01d76a2 Minor shader improvement to the bilateral blur 2020-01-29 10:17:08 -08:00
Romain Guy aa3b0a4e16 Add --single to only edit the first renderable 2020-01-28 17:12:20 -08:00
Philip Rideout ff66e980eb Add ResourceLoader::hasResourceData. 2020-01-28 14:51:02 -08:00
Philip Rideout 6fbf8a8be0 Fix event pumping with non-owned platforms.
Tested with WebGL and macOS.
2020-01-28 13:39:58 -08:00
Philip Rideout 1452ce62f4 Remove srcDirs hack, use packagingOptions / exclude. 2020-01-28 12:31:14 -08:00
Philip Rideout d84d095c97 The Android support libs now use dynamic linking.
In my first attempt I kept the multiple project-level dependencies in
each sample's `build.gradle` but that resulted in a gradle error
concerning multiple copies of the same SO file. To work around this
we now append to "srcDirs" to bring in Java dependencies rather than
using project-level dependencies.

The new APK contents are now much more reasonably sized:

    libfilament-jni.so         981 KB
    libgltfio-jni.so           817 KB
    libfilament-utils-jni.so    96 KB

Previously this was:

    libfilament-utils-jni.so    1.8 MB
    libgltfio-jni.so            1.8 MB (unused)
    libfilament-jni.so          1 MB (unused)

Fixes #2070
2020-01-28 12:31:14 -08:00
Philip Rideout e1b498f82c Repair iOS error due to STBI_NO_STDIO.
Fixes #2072.
2020-01-28 12:26:31 -08:00
Benjamin Doherty 06726fe361 Regenerate Xcode project for hello-ar iOS sample 2020-01-28 11:09:34 -08:00
Ben Doherty ba3a274357 Fix headers in iOS samples (#2074) 2020-01-28 10:56:28 -08:00
Romain Guy 30a3d31a3d Update README 2020-01-27 13:46:56 -08:00
Romain Guy 191c89c3b1 Exclude .kt files from javadocs 2020-01-27 13:46:25 -08:00
Romain Guy 42b739154e Update Maven library version 2020-01-27 13:30:34 -08:00
Philip Rideout 721a251b34 Bump package.json to 1.4.5 2020-01-27 13:02:19 -08:00
Ben Doherty 1a66f85b67 Update RELEASE_NOTES for 1.4.5 2020-01-27 12:59:35 -08:00
Romain Guy 3bba92f813 Fix build message 2020-01-27 12:03:56 -08:00
Philip Rideout 93c9674e2a Fix WebGL build. 2020-01-27 11:37:17 -08:00
John Davis a4b879227d fix case sensitivity problem for linux 2020-01-26 19:17:57 -08:00
Philip Rideout 485dfa6cde Fix typo. 2020-01-24 20:51:31 -08:00
Mathias Agopian 3105a8330e remove unneeded includes in public headers
Replace with forward declarations if needed and includes in .cpp that
now need them.
The idea here is to have our headers have the least amount of impact as
possible on our clients (e.g. compilation time).
2020-01-24 12:13:48 -08:00
Mathias Agopian 88e8661bf3 New API to import textures into filament
If you need this, you know who you are.
The new Texture::Builder::import() allows to specify a OpenGLES texture
id from a shared GL context, effectively importing the texture into
filament.
The texture is NOT destroyed when calling Engine::destroy(Texture*), only
its filament handle.
2020-01-24 12:13:20 -08:00
Mathias Agopian 3a9629d93c Fix a NOOP backend threading bug (#2064)
The NOOP backend didn’t call user-API callbacks from the main thread
(instead calling them from the “backend thread”). This caused problems
with unit tests for instance.
2020-01-23 14:55:25 -10:00
Mathias Agopian 29c14b1053 Fix typo in documentation (#2065)
lastest -> latest
2020-01-23 14:55:09 -10:00
Philip Rideout bd5aeb6b69 Allow non-WebGL builds to disable threads. 2020-01-23 11:06:17 -08:00
Philip Rideout 3674361f20 ModelViewer now automatically detaches. 2020-01-23 09:55:51 -08:00
Philip Rideout 4a29456a7a ModelViewer now works with TextureView. 2020-01-23 09:55:51 -08:00
Philip Rideout 3179a83cfb Android: introduce ModelViewer helper.
This reduces the LOC of our gltf-viewer app from 260 to 146. This could
have been more, but I feel this provides good balance between
flexibility and convenience.

The raw gltfio API involves multiple objects (FilamentAsset,
AssetLoader, ResourceLoader) whereas the ModelViewer has a simple facade
consisting of two methods, one for GLB and one for GLTF. The underlying
gltfio objects are available via non-settable properties.
2020-01-23 09:55:51 -08:00
Ben Doherty 5fe1fe73c4 Use Objective-C availability tests for Metal backend (#2046) 2020-01-23 09:16:19 -08:00
Philip Rideout 5025d8eb6e Remove usage of the invariant keyword. 2020-01-21 14:42:58 -08:00
Philip Rideout 71697b59a3 Disable depth prepass everywhere.
Fixes #737 and #1472. See also #475 and #1295.
2020-01-21 14:42:58 -08:00
Philip Rideout 518ae9658f gltfio + Android: improve memory management.
Add bindings for releaseSourceAsset() and fix a double-free issue.

According to the Android Studio profiler, this makes Java memory usage
go from 18.6 MB to 6.5 MB.
2020-01-21 13:01:55 -08:00
Philip Rideout 41ad8b5c18 Remove unused copy of the parquet PNG. 2020-01-21 12:58:46 -08:00
Philip Rideout 51cef3b5ca WebGL: unify the PNG and JPEG codepaths.
Fixes #2055.
2020-01-21 12:58:46 -08:00
Philip Rideout 491d16a4e5 Exercise JPG decoding in web samples. 2020-01-21 12:58:46 -08:00
Philip Rideout e752b6fb6f Factor STB config into a header. 2020-01-21 12:58:46 -08:00
Philip Rideout 46bf6fbfdd Simplify sample-gltf-viewer as much as possible. 2020-01-21 12:57:50 -08:00
Philip Rideout fd5fe3d18d Convert KtxLoader to Kotlin and remove usage of reflection.
Fixes #1510
2020-01-21 12:57:09 -08:00
Philip Rideout ca2da39614 Migrate TextureLoader to filament-utils. 2020-01-21 07:59:51 -08:00
Philip Rideout 067dad2d38 camutils: rename internal enums. 2020-01-17 11:37:57 -08:00
Philip Rideout f91a8890a6 camutils: fix bad defaults in Manipulator. 2020-01-17 11:37:10 -08:00
Philip Rideout dd9b84f06e GestureDetector cleanup. 2020-01-17 10:45:17 -08:00
Philip Rideout 9ac17a88b3 Add new sample for glTF models and the camera manipulator.
This differs from the bloom demo in that it supports touch interaction,
has animation, loads from GLTF rather than GLB, and is overall simpler.
2020-01-17 09:09:46 -08:00
Philip Rideout 9ea8148d84 Add doubles to Manipulator for convenience. 2020-01-17 09:09:46 -08:00
Romain Guy 16c65550bb Fix javadoc syntax 2020-01-16 17:27:06 -08:00
Philip Rideout 961860adee Introduce filament-utils and Java bindings for camutils.
This library houses the KTX loader, camutils bindings, and a Kotlin math
library. More will come later. Sample app is forthcoming.
2020-01-16 16:00:23 -08:00
Philip Rideout 6146b4d2d9 Fix out-of-bounds when glTF has many UV sets.
glTF specifies that client implementations must support at least two UV
texture coordinate sets but does not seem to have an upper limit.

We use a mapping table in order to honor high-numbered UV set indices,
but our mapping table only accomodates 8 entries.

Fixes #2042
2020-01-16 14:09:48 -08:00
Philip Rideout 274cd3a1f3 Refactor some Android build things for gltfio.
We currently use static linking and will continue to do so. This means
that libfilament-jni is a subset of of libgltfio-jni, and libgltfio-jni
will become a subset of the upcoming libutils-jni.

This is a simple layer cake, but requires adding some CMake logic to the
gltfio-android CMakeLists, similar to what we already did for the
filament-android CMakeLists. This prevents an obscure CMake error about
duplicated build artifacts.

Also, previously we required clients to call AssetLoader#init(), this
is now renamed to Gltfio#init(), which is more consistent with
Filament#init().
2020-01-16 10:11:36 -08:00
Romain Guy 762e8b8b6a Add more control to surface ordering (#2041)
When UiHelper is set to translucent with setOpaque(false), the
target SurfaceView's surface is set to be composited on top of
the activity's window. There are situations however where one
may want to render regular Views on top of the SurfaceView.

The new setMediaOverlay() API allows exactly that: when this
property is enabled, rendering to a translucent target will
cause the SurfaceView's surface to be composited above other
surfaces, but below the activity's surface.
2020-01-16 10:00:26 -08:00
Philip Rideout a5a6e9be8a Add animated GLTF model to third_party.
This asset will be used in an upcoming Android sample. I converted the
textures from PNG to JPG to reduce the footprint.
2020-01-15 16:56:46 -08:00
Philip Rideout 4ab65975f4 Update Android Studio required version. 2020-01-15 11:22:57 -08:00
BStringhamVRSK 041f26a7c5 Implemented sRGB support for DXT encoded textures (#2026)
* Added sRGB support for DXT compressed textures - OpenGL

* Added sRGB support for DXT compressed textures - Vulkan and Metal

* Added detection if OpenGL driver supports sRGB compressed textures (EXT_texture_sRGB extension)

* Fixed whitespace to use spaces rather than tabs

* Test for GL_EXT_texture_sRGB or GL_EXT_texture_compression_s3tc_srgb support for sRGB DXT compressed textures

* GL ES uses GL_EXT_texture_compression_s3tc_srgb instead of GL_EXT_texture_sRGB
2020-01-15 10:26:29 -08:00
Mathias Agopian b351e709c1 Framegraph improvements
- added a way to compare two handle's underlaying resource
  (i.e. do they refer to the same resource)

- minor refactoring and comment fixes
2020-01-15 10:22:10 -08:00
Mathias Agopian fbad683810 Implement a "black board" for the framegraph
FrameGraph always keeps a default Blackboard, but additional ones 
can be created if needed.

A blackboard is just a registry of FrameGraphHandles, queryable by name.
2020-01-15 10:22:10 -08:00
Philip Rideout 2854c0627d camutils: add support for Builder pattern.
This makes the upcoming Java bindings simpler and improves parity with
existing API conventions.

Note that camutils does not depend on filament and therefore cannot use
BuilderBase.

Note that the Manipulator Builder state is public which breaks with
convention but makes implementation simple and allows C++ clients to
continue using modern initializer syntax if they wish.
2020-01-14 15:26:22 -08:00
Mathias Agopian c5fa6fe7f2 More fixes to sampled textures in the framegraph
The main purpose of this change is to fix a problem where a resource
marked as sampleable by a *culled* pass would stay sampleable.
This happened because the sampleable state was tracked on the resource
itself.

We fix this by treating sample() just like read(), such resources are
added to an array living in the pass, which ensures the state is correct
when passes are culled.

Also fixed:
- simplified read() code a bit (minor)
- simplified resource aliasing code
- don't resolve() renderTargets of culled passes
2020-01-14 11:16:34 -08:00
Mathias Agopian 40c7232bb2 revert part of a recent TransformManager change
setParent() is not supposed to reorder child/parents in the array
because it doesn't rely on them being orderer. This also has the
advantage of not invalidating Instances.

However, commitLocalTransformTransaction() does rely on child/parent
ordering and the previous change did fix that.
2020-01-14 11:16:07 -08:00
Ben Doherty 59e3465b6b Update Assimp to 5.0.1 (#2027) 2020-01-13 15:00:27 -08:00
tpsiaki 2c591d2dca Correct out-of-order transform instances (#2025)
The current code only updates the order in the transaction commit if there's a single out-of-order node in the scene graph, but if multiple are out of order (or one swap doesn't fully fix the ordering), then we end up with out of order scenes, and incorrect world transforms.

Additionally, when nodes are reparented outside of a transaction, the order is not updated.
2020-01-13 13:22:49 -08:00
Mathias Agopian 4673545f45 Fix a multisample related bug in the FrameGraph
The FrameGraph would erroneously specify a sample count on textures
that are sampleable and used as an attachment to a multisampled 
target -- however, that's not allowed.

We didn't run into issues, because had a workaround for this when
creating the texture. This is augmented by an assertion.
2020-01-13 11:29:14 -08:00
Mathias Agopian 4703a45ff5 Ensure we don't use RTTI when not available
also don't implement the graphviz export in release builds.
2020-01-13 11:28:50 -08:00
Mathias Agopian 35aabd5e44 Fix a couple minor issues in the OpenGLES backend
- we were not unbinding the renderbuffer int the right place,
  when it's created, instead we were doing that when using it the 
  first time. Unbinding soon makes sense because we never need to
  rebind it after that.

- in debug builds we were clearing render targets at creation time,
  but this was wrong because a render target won't necessarily be written
  (it could be used as the source of the blit for instance).
  This didn't cause any trouble in the framegraph, by chance, it was smart
  enough to reuse existing render targets in the case of blitting.
  Ideally we'd clear textures/renderbuffer at creation time,
2020-01-13 11:28:50 -08:00
Mathias Agopian 118944be9a Improve/simplify OpenGLDriver a bit
merge frameBufferRenderbuffer() and framebufferTexture() because
the filament API doesn't have a distinction. This actually removes
quite a bit of code too.
2020-01-13 11:28:50 -08:00
Mathias Agopian 8e1ecbb0ea Minor FrameGraph improvements
- write() is marked as [[nodiscard]] since it's
  generally an error to discard it

- graphviz export not display wether a texture resource is
an actual texture or renderbuffer
2020-01-13 11:28:50 -08:00
Romain Guy 00ba8c09f8 Rewrite Maven publish tasks to support multiple flavors (#2022)
* Rewrite Maven publish tasks to support multiple flavors

* Don't build filamat with an unused CMake option

* Don't compiler debug in release mode

* ... for real

* Link to BUILDING.md
2020-01-10 18:02:46 -08:00
Philip Rideout 15b071acaa gltfio: support external resources on Android.
This was untested because our only glTF Android sample uses glb instead
of JSON. We will soon be adding a new Android demo that uses an actual
gltf file.

This fixes #1841.
2020-01-10 09:15:38 -08:00
Romain Guy aa3dfb9a4b Revert "Disable filamat-android's flavors for now"
This reverts commit 95e22d878a.
2020-01-09 19:17:50 -08:00
Romain Guy 95e22d878a Disable filamat-android's flavors for now 2020-01-09 17:49:30 -08:00
Philip Rideout 4f8c495563 Another gltf_bloom fixup. 2020-01-09 14:31:43 -08:00
Romain Guy 1d6ea1db0f Update README.md 2020-01-09 14:23:41 -08:00
Romain Guy 393cc5c634 Update README 2020-01-09 14:23:05 -08:00
Philip Rideout 34c2772a60 Remove unused source file. 2020-01-09 14:10:33 -08:00
Philip Rideout 4d258ab5e8 Remove a build output file. 2020-01-09 14:07:20 -08:00
Philip Rideout a306f9074a Clean up gltf-bloom to prep for new gltf-viewer app.
This renames the app namespace and removes the unused Io file.
2020-01-09 13:49:24 -08:00
Philip Rideout 6e30566363 Bump version number in package.json 2020-01-09 12:33:17 -08:00
Romain Guy 2908224c95 Filament 1.4.4 2020-01-09 12:19:05 -08:00
Romain Guy e011853e7e Update androidx.annotation to 1.1.0 2020-01-09 08:55:43 -08:00
Romain Guy 104105c937 Fix the build 2020-01-08 18:01:18 -08:00
Romain Guy 3fa98419a6 Add more .gitignore 2020-01-08 17:59:49 -08:00
Romain Guy 44d08ce41e Fixup javadocs 2020-01-08 17:55:17 -08:00
Mathias Agopian 0a1c1be00e Refactoring to allow rendering multi-pass rendering
specifically into the same render target.
2020-01-08 16:10:09 -08:00
Mathias Agopian 7efd7abffe Don't combine clearFlags when retrieving a rendertarget
Instead we use the clear flags that the user specified. This is needed
in the case where we're rendering in the target in two passes, the
first pass might want to clear the buffers, while the 2nd one will not.
If we were combining the clear flags, the first pass's flags would be
sticky and the view would always be cleared.

If combining is needed it must be specified by the user.
2020-01-08 16:10:09 -08:00
Mathias Agopian e27158507e refactor Renderer to make it more flexible
This is in preparation to supporting screen-space effects.
There are two major changes:

- RenderPass is now copiable and intended to be passed by copy to
  the execute stage of frame graph passes

- The color pass is in its own function now


This actually simplify RenderPass api.
2020-01-08 16:10:09 -08:00
Romain Guy d9ee2fa10d Use a proper Gradle plugin to generate Filament assets in samples (#2018) 2020-01-08 15:45:44 -08:00
Mathias Agopian b30a7aa5a2 Make ResourceAllocator mockable and update test
We have one very important unit test that is supposed to make sure
the framegraph reuses the same rendertarget between 2 passes, this
unit test would always succeed when using the NoopDriver.
Now that we can mock the ResourceAllocator, we can ensure this unit
test is doing its job.
2020-01-08 15:39:40 -08:00
Mathias Agopian 34c1aaac18 improve cmgen prefiltered cubemaps
Rotate the sample pattern at every light direction, which trades
aliasing for noise (which is arguably more pleasant) for IBLs with
very high frequency (i.e. high level of HDR-ness).
2020-01-08 15:39:21 -08:00
Ben Doherty 8dbb4c6b7e Add new heightfield sample (#2004) 2020-01-08 11:55:28 -08:00
Romain Guy f5d5afba74 Re-organize Android Gradle files (#2013)
* Re-organize Android Gradle files

Clean up our Gradle files, share versioning, etc. and prepare for
publication to sonatype.

* Use androix annotations for desktop

* Add samples as subprojects to root Gradle

* Fix build script

* Don't break when samples aren't compiled

* Better organize the Android Studio project
2020-01-07 18:37:45 -08:00
Philip Rideout e09f0bb99f Repair gradle IBL path for gltf_bloom.
I broke this when I changed the cmgen KTX behavior.
2020-01-07 14:05:40 -08:00
Mathias Agopian fddf51dc74 cmgen -d would force importance sampling mips generation 2020-01-06 17:43:11 -08:00
Mathias Agopian b8d4b981e0 Better roughness remapping and comments
We were conflating two concepts in our comments about the roughness
remapping, which was confusing. Also changed the remapping so it 
matches a log2 mapping in our default configuration.
2020-01-06 17:42:56 -08:00
Daniel Lehmann 892302442f Fix Backend enum in Java to be consistent with C definition (#2006)
The C definition was changed to include METAL, moving NOOP further down.
The Java definition never caught up, making NOOP mean METAL and making the
real NOOP unreachable.

This patch puts them back in sync. Also, updated the Java comments to match
the comments from the C definition.
2020-01-06 16:27:15 -08:00
Philip Rideout 39046ddfe1 camutils: fix MSVC error. 2020-01-06 16:12:05 -08:00
Philip Rideout ac14074bc4 camutils: flip zoom to match old manipulator. 2020-01-06 16:12:05 -08:00
Philip Rideout 7d548151d7 Introduce camutils library.
This moves the camera manipulator into its own library and adds new
functionality including a new "Google Maps" manipulator and a bookmark
feature to facilitate camera animation.

Java bindings and an Android sample will land later this week.
2020-01-06 16:12:05 -08:00
Philip Rideout 898ed70aa0 Remove <iostream> from math headers.
This speeds up our build time by using <iosfwd> and un-inlining the
vector print functions.
2020-01-06 15:09:06 -08:00
Romain Guy 78842b59c9 Only build FBX and OBJ importers (#2003) 2020-01-06 14:38:32 -08:00
Ben Doherty f4f4f9ccd5 Implement flush for Metal backend (#1999) 2020-01-06 12:28:11 -08:00
Mathias Agopian 2ef9d72dbd Simply refraction code
This makes it easier to add new shapes and experiment.
Added a "sold box" shape that is not used yet.
2020-01-06 11:33:06 -08:00
Tim Psiaki b030f67eb7 Make EntityManager and Panic dynamic-linkable. 2020-01-06 10:24:17 -08:00
Romain Guy 8380a87a6e Update HTML docs 2020-01-05 11:44:45 -08:00
Philip Rideout 06b9bb0c34 gltfio: honor node labels if they exist.
In glTF, multiple nodes can refer to the same mesh, and each node can be
assigned a unqiue string label. Previously we used NameComponentManager
to annotate entities with mesh labels rather than node labels. This was
wrong because Filament entities are 1:1 with nodes, not meshes.

We still fall back to mesh labels when node labels are not provided.
2020-01-03 10:13:59 -08:00
Philip Rideout 17893ecefd Repair Android extension pointers.
Fixes #1989 by fetching extension function pointers that were refactored
in #1977. Moved string-splitting utility to a common location so that
the base class and concrete classes can both use it.
2020-01-03 07:16:56 -08:00
Ben Doherty efc1b01901 Respect colorWrite in Metal backend (#1996) 2020-01-02 13:36:59 -07:00
Ben Doherty 88fa93f1de Add support for ASTC textures on iOS / Metal (#1992) 2020-01-02 11:35:23 -07:00
Ben Doherty 36385a2432 Improve Metal textures (#1991) 2019-12-30 11:15:04 -07:00
brian.wang 1e05327c5d Fix compile error for VS 2019 16.4.2 with Vulkan (#1990) 2019-12-27 10:44:24 -07:00
Philip Rideout 0b7a08a2d8 Repair web samples by fixing typo in previous fix. 2019-12-18 18:06:21 -08:00
Philip Rideout 237e0ee367 Revert "Revert "gltfio: enable specular AO to "fix" #1870""
This reverts commit f9230856af.
2019-12-18 13:56:13 -08:00
Philip Rideout f9230856af Revert "gltfio: enable specular AO to "fix" #1870"
This reverts commit 9bf9c3a439.
2019-12-18 13:17:52 -08:00
Philip Rideout 9bf9c3a439 gltfio: enable specular AO to "fix" #1870 2019-12-18 13:07:05 -08:00
Philip Rideout 25c4efd2db cmgen: do not create useless folder for KTX files
With KTX, we should simply create the specified output folder and put
the KTX file(s) in there. There is no need to create a subfolder of the
output folder.

This change also allows users to pick a custom name for their KTX file,
because we only use the "deployment" name when generating filenames.
2019-12-18 13:03:02 -08:00
Ben Doherty 8f6f0ef511 Add continuous build artifacts (#1978) 2019-12-16 10:38:57 -08:00
Pixelflinger a924fbb490 Better roughness remapping for IBLs
This greatly improves the quality of semi-rough
materials.
2019-12-14 16:36:58 -08:00
Philip Rideout 4c01dfc9fd macOS: fix flash of red upon resize.
Previous to this change, we suffered from a flash-of-red followed by a
flash-with-wrong-projection every time we resized an OpenGL window.

SDL throttles the window resize events, so FilamentApp updates the View
only on the final low-level resize event. However we were calling
Cocoa's update method on every low-level resize event. Thus we were
showing uninitialized content during the resize.

FilamentApp recreates the SwapChain after the final resize event; one
reason for this is the fact that Vulkan swap chains must be recreated.

The fix is to defer the Cocoa update until the swap chain gets
recreated. This is the perfect time because FilamentApp has already set
the new Viewport at this point.
2019-12-14 09:29:35 -08:00
Mathias Agopian 5ee15239fd Split Android specific code out of PlatformEGL (#1977)
We now should be able to use PlatformEGL for all generic EGL platforms
(not tested though). Most texture streaming operations are not supported
in that case, since they're platform specific.
2019-12-13 14:23:19 -08:00
Philip Rideout 69d36b0226 WebGL: fix usage of direction estimator. 2019-12-13 12:46:11 -08:00
Philip Rideout 87db1aaa57 WebGL: remove old broken test. 2019-12-13 12:46:11 -08:00
Philip Rideout 5e096de534 Disable rounding FBO sizes on WebGL. 2019-12-13 12:46:11 -08:00
Philip Rideout 97d53bf7e9 Remove warnings about deadlock. 2019-12-13 10:25:38 -08:00
Philip Rideout 6fbc690097 macOS: pump the event queue while waiting. 2019-12-13 10:25:38 -08:00
Jordan Rupprecht 311f6eacd7 Add missing <assert.h> include. (#1969)
An version of clang is smarter about generating warnings for template code. `assert` here is not included, so clang generates: `error: use of undeclared identifier 'assert'`
2019-12-13 09:26:02 -08:00
Ben Doherty 0dee8c5f34 Deprecate Kokoro-specific logic from build scripts (#1973) 2019-12-12 13:23:43 -08:00
Philip Rideout ddf85bae72 CMake: add a convenient "run" target for quick testing.
This is just a shortcut for building gltf_viewer, then immediately
running it, which is something we do a lot.
2019-12-12 13:12:23 -08:00
Pixelflinger 695d61f87c fix CubemapUtils::processSingleThreaded()
the state wasn't initialized from the user given prototype
2019-12-11 15:26:12 -08:00
Philip Rideout 9584371f89 macOS: add a check for "is this the right view?" 2019-12-11 14:49:23 -08:00
Philip Rideout 509bfb5b5e Add warnings (hopefully temporary) about macOS deadlock. 2019-12-11 14:49:23 -08:00
Philip Rideout f853b7dc40 macOS: add cleanup for observer. 2019-12-11 14:49:23 -08:00
Philip Rideout 0693a97577 macOS: fix window resizing regression. 2019-12-11 14:49:23 -08:00
Romain Guy 8e00df1de5 Add Color::absorptionAtDistance() to compute absorption for refraction. (#1964)
Specifying the transmittance color at a specific distance is more
user-friendly than specifying absorption coefficients directly.
2019-12-10 18:20:23 -08:00
Philip Rideout 28f0536b31 Repair JavaScript bindings for IndirectLight. 2019-12-10 18:19:38 -08:00
Mathias Agopian 639bfbfc9a Fix SSAO when blending is used
When doing the depth path for ssao, we need to remove the blended
objects, i.e. produce a depth path similar to the regular depth prepass.

We also need to clear the SAO buffer. It's not needed for opaque
objects because they are written in the SAO's depth buffer. This fixes
"ship in a bottle" scenario.
2019-12-10 17:53:02 -08:00
Philip Rideout 0c734d6db0 Simplify PlatformCocoaGL. 2019-12-10 17:19:41 -08:00
Philip Rideout e0f5b5125c Fix Catalina by moving some calls to the UI thread.
Fixes #1839.
2019-12-10 17:19:41 -08:00
Philip Rideout 28065e36e8 Make builds less verbose.
Fixes #1956.
2019-12-10 17:19:06 -08:00
Mathias Agopian 8088f0cd6f fix android samples
these samples broke with the new 5 lods ibls
2019-12-10 16:56:19 -08:00
Mathias Agopian 36cdadd238 fix gltf_viewer calculated light position/intensity 2019-12-10 14:44:23 -08:00
Ben Doherty 1061d5c5fa Fix MSVC 2019 16.4 build (#1943) 2019-12-10 13:34:48 -08:00
Mathias Agopian c1bd438d89 temporary workaround for build break 2019-12-10 12:26:52 -08:00
Pixelflinger dd8c0a759f Improve IBL's diffuse
If spherical harmonics are not specified in IndirectLight (i.e. 
omitted entirely), we instead use the roughness==1 LOD in the shader.
This produce much better results with absolute HDR environment, and 
generally works better more often.

This is now the preferred solution.

For cases where spherical harmonicas are better or preferred, they
can simply be supplied as before.
2019-12-10 12:26:52 -08:00
Mathias Agopian 0f16f3177e some cmgen fixes
- support equirect/octahedron save in more cases
- apply 1/pi when rendering SH so it's easier to compare 
  (this is used only for debugging anyways)
2019-12-10 12:26:52 -08:00
Ben Doherty acc2fd9c94 Add depth32 fallback for GPUs without packed depth support (#1957) 2019-12-10 12:23:17 -08:00
Romain Guy 8feb842717 Ignore metallicness when refracted objects don't specify reflectance
Metals need a complex IOR but we only accept a scalar IOR.
2019-12-10 11:56:00 -08:00
Romain Guy f19eaaa557 Fix directoy based cubemap loading 2019-12-10 10:03:56 -08:00
Romain Guy 3fa0c2d18b Add refraction to material_sandbox 2019-12-10 09:51:54 -08:00
Mathias Agopian 9393e1369b don't apply roughness remapping for solid refraction
The thin roughness remapping only makes sense for thin surfaces, it was
a mistake to apply it to solids. It assumes that a ray will go
undisturbed though the thin surface with an ior of 1.
2019-12-10 00:02:17 -08:00
Ben Doherty 8342b0ecec Update Windows READMEs for building with VS2019 (#1952) 2019-12-09 17:09:45 -08:00
Ben Doherty 9a291b6543 Refactor Metal buffers, allow in-frame vertex and index updates (#1950) 2019-12-09 15:54:40 -08:00
Romain Guy ec403f8940 Fix material_sandbox 2019-12-09 13:37:09 -08:00
Mathias Agopian 047dab769d fix unit tests 2019-12-09 13:24:49 -08:00
Philip Rideout 5d8cd288d3 Fixed formatting in release notes. 2019-12-09 12:42:17 -08:00
Philip Rideout 8a63682382 Remove unused includes. 2019-12-09 12:41:02 -08:00
Philip Rideout 036f151a42 WebGL: enable depth buffer in swap chain.
In PR #1906 we enabled depth for all backends, but we forgot web.

Note that this required 0 new codelines whereas Vulkan required 116
additional codelines. :)
2019-12-09 10:18:23 -08:00
Ben Doherty 5bc1356192 Update RELEASE_NOTES.md 2019-12-09 10:01:25 -08:00
Ben Doherty c04a111d10 Fix froxel coordinate calculation on Metal and Vulkan (#1934) 2019-12-09 09:57:59 -08:00
Philip Rideout da5eabc91f Fix bad state after setIndirectLight(null).
This cleans up 3 related issues, but only the first of these caused an
actual user-visible bug:

(1) When the IBL was null, prepareLighting was failing to bind the black
1x1 texture.

(2) If you added and removed an IBL from a Scene, then Scene was not
returned to its initial state.

(3) The default 1x1 IBL used an intensity of 1 rather than 30000, which
is inconsistent with the null IBL.

Fixes #1940.
2019-12-09 09:30:59 -08:00
Mathias Agopian 79f8947bfa Improve thin layer refraction
We now take into account the light bouncing between the two interfaces
of the materials. We can do this because we assume thin surfaces, 
meaning that the light will exit where it entered and with the same
direction that the specular.

This strengthen the specular at grazing angles (and reduces the transmission).
2019-12-08 22:18:18 -08:00
Mathias Agopian 160a22519e Use unclamped roughness for IBls
This allows us to have sharp reflection and refraction -- the later
is very important.
2019-12-08 22:18:18 -08:00
Mathias Agopian cc9a1d446c added the concept of micro thickness for thin objects
When dealing with thin objects we really have two thicknesses to 
consider, the thickness in the direction of the normal, which 
corresponds to the value used for solid objects, and the thickness of
the object's walls, which generally is a constant.

Reusing thickness in the later case is problematic for assets that have
a thickness map, but are rendered hollow.

In the future we can even imagine handling double-sided hollow objects
by using the thickness information -- e.g. a hollow cube.
2019-12-08 22:18:18 -08:00
Mathias Agopian b78ea90c27 apply thin roughness remapping to solid as well
this is because for solids we're also handling both interfaces in one
go (as opposed to calculate the actual btdf), and roughness should
depend on the ior.

Also rename some variables for less confusion (we now use 
incident(I)/refracted(R)).
2019-12-08 22:18:18 -08:00
Mathias Agopian cbb5d2b423 fix typos and rename refraction to refractionMode 2019-12-08 22:18:18 -08:00
Pixelflinger c759743e40 Don't saturate absorption, unless it's a constant
Update documentation.
2019-12-08 22:18:18 -08:00
Pixelflinger 3b2ecc6003 Fix a material compiling issue when thickness wasn't defined
We also now assume a thickness of 0, if it's not set in the material.
We don't want to assume any particular thickness, because it depends
on the scene's scale.

Also clamp the remapped roughness.
2019-12-08 22:18:18 -08:00
Mathias Agopian 4790cb5009 Allow materials to override the IOR
Normally the IOR is deduced from the reflectance, but now we allow to
specify the IOR instead or in addition to the reflectance.
In the later case, it's possible to create physically impossible
materials, but this can be useful for artistic reasons.
2019-12-08 22:18:18 -08:00
Pixelflinger ee0080487a finish plumbing for new material parameters 2019-12-08 22:18:18 -08:00
Pixelflinger f70b820cbe update material documentation 2019-12-08 22:18:18 -08:00
Pixelflinger 1ccae61d40 shader plumbing for screen-space refraction
In this PR, the filament side is missing, so we're outputting back.
But all codepaths in the shader are implemented:
 cubemap/screenspace, solid/thin
2019-12-08 22:18:18 -08:00
Mathias Agopian f670472e55 implement thin layers 2019-12-08 22:18:18 -08:00
Mathias Agopian f94aa731ed Add plumbing for refraction type (solid or thin) 2019-12-08 22:18:18 -08:00
Mathias Agopian 5c80bfe430 update documentations with common IOR values 2019-12-08 22:18:18 -08:00
Mathias Agopian 8d7866b58d apply fresnel to refraction
fixes white furnace test.
2019-12-08 22:18:18 -08:00
Mathias Agopian 179bf03caf implement absorption 2019-12-08 22:18:18 -08:00
Pixelflinger 0371a805ed basic refraction 2019-12-08 22:18:18 -08:00
Pixelflinger 57b48e0719 address reviewers comments
- get rid of "thin layer thickness" property
- make absorption a vec3
2019-12-08 22:18:18 -08:00
Mathias Agopian eb767abc55 Add material properties needed for refraction 2019-12-08 22:18:18 -08:00
Mathias Agopian dbda77b091 Improve low roughness significantly
Filament will now allow incomplete mipmap chains for the IBL and
map the roughness to the available chain.

This allows to create roughness cubemaps with a minim size for
roughness==1, instead of always mapping it to 1x1.

cmgen will now use 16x16 cubemaps for roughness==1, which
improves the quality of rough objects significantly.

The beauty of this is that there is no asset or API change. Old assets
will continue to work like before.
2019-12-08 22:17:08 -08:00
Philip Rideout 2c1454270e OpenGL: enable cubemap filtering on desktop.
According to the OpenGL spec, proper cubemap filtering is disabled by
default in non-ES OpenGL.
2019-12-08 22:16:52 -08:00
Mathias Agopian 1ec72e606b Round non-texture FBO attachments to 32 pixels
this helps reducing churn in the resourceallocator cache.
2019-12-06 14:03:07 -08:00
Philip Rideout 24bfdd741a Revert "Fix bad state after setIndirectLight(null)."
This reverts commit f0ce4094dd.
2019-12-06 13:56:21 -08:00
Philip Rideout f0ce4094dd Fix bad state after setIndirectLight(null).
This cleans up 3 related issues, but only the first of these caused an
actual user-visible bug:

(1) When the IBL was null, prepareLighting was failing to bind the black
1x1 texture.

(2) If you added and removed an IBL from a Scene, then Scene was not
returned to its initial state.

(3) The default 1x1 IBL used an intensity of 1 rather than 30000, which
is inconsistent with the null IBL.

Fixes #1940.
2019-12-06 13:54:49 -08:00
Philip Rideout 9cbcd88d4e WebGL: tweak helmet demo for shadows. 2019-12-06 10:27:00 -08:00
Philip Rideout 8ea6e6ce59 Upgrade hello-camera to use AHardwareBuffer. 2019-12-06 08:46:37 -08:00
Philip Rideout 6d0f8c9ead cmgen: add support for non-RLE HDR images.
The new conditional is cribbed from STB, which checks the first three
bytes.

Fixes #1937.
2019-12-06 08:45:12 -08:00
Philip Rideout 43d91a5c40 Repair twoPassesTwoSides transparency.
This regressed when we added support for dynamic backface culling
(#1641). Also note another fix we made: #1877.
2019-12-05 09:00:57 -08:00
Romain Guy 564e527ac7 Fix docs typo 2019-12-05 10:17:00 +01:00
Philip Rideout 6d3b733cb1 Bump package.json version. 2019-12-04 15:59:52 -08:00
Philip Rideout 0e967726de Simplify CameraManipulator.
This removes a lot of code and will make it easier to migrate into a new
library with Java bindings, etc.

- The clipping planes and projection matrix were unused, removed them.

- In split view mode, our demos were using only 2 of the 3 manipulators,
  removed one.

- Instead of callbacks and update methods, users can simply ask for the
  current matrix at every frame.

- The manipulator's job is to consume mouse events and maintain an
  "look at" basis, there is no need to store a reference to a Filament
  Camera.
2019-12-04 08:05:17 -08:00
Mathias Agopian 001a4c46db Added a property chunk to materials
Materials can now reflect which property is in use.
2019-12-03 17:51:44 -08:00
Mathias Agopian 1a9d0926ee Added a torus and simple cube shapes
renamed "cube.obj" to "rounded_cube.obj", which it was (rounded)
2019-12-03 17:49:40 -08:00
Mathias Agopian 05a756beaa ResourceAllocator: minor clean-up and comments 2019-12-03 17:42:43 -08:00
Mathias Agopian 1014847e9d workaround OpenGLES driver bug
some drivers declare supporting anisotropic filtering, but don't
support calling glSamplerParameter() to set the max anisotropy, presumably because they only support glTexParameter().
We simply turn off anisotropic filtering on these drivers.
2019-12-03 17:41:41 -08:00
Ben Doherty d3309c2e84 Fix Windows build variants (#1926) 2019-12-02 17:16:15 -08:00
Romain Guy 565002a918 Remove obsolete comment 2019-12-02 14:23:12 -08:00
Romain Guy 08b83e7ed1 Make including jawt_md.h more resilient (#1922)
Sometimes CMake decides to use the JNI bits included with XCode instead
of those from the installed JDK. The header files are located in different
directories. This does the proper include.
2019-12-02 08:45:20 -08:00
Ben Doherty b4c2f523fe Update RELEASE_NOTES.md 2019-11-27 13:14:12 -08:00
Romain Guy 4ba5d6b9a8 Update release notes 2019-11-27 13:05:34 -08:00
Ben Doherty 59ceb05f99 Add support for mapping individual planes of iOS external images (#1917) 2019-11-27 10:38:13 -08:00
Benjamin Doherty 929c8e96c6 Handle surface size changes in Metal 2019-11-27 01:08:40 -08:00
Philip Rideout 1b5a730358 VulkanDriver: add depth buffer to swap chain. 2019-11-27 01:08:40 -08:00
Benjamin Doherty 79255e8e7d Implement default depth buffer for Metal 2019-11-27 01:08:40 -08:00
Mathias Agopian 50845261fe Swap chains are now always created with a depth buffer
This is to allow direct rendering of 3D objects into the swapchain 
under certain circumstances (no msaa or postprocessing).
2019-11-27 01:08:40 -08:00
Philip Rideout da090f0ff6 Fix missing call to glInvalidateFramebuffer().
We were over-optimizing, not always honoring the flag. This was
incorrect since bindFramebuffer can be called from other places.

Fixes #1914.
2019-11-26 15:25:59 -08:00
Philip Rideout 60ead8c5f3 Add Android sample for testing the Stream API.
This new sample differs from "Hello Camera" in that it exercises all
three ways of using Stream. It also uses Canvas instead of Camera2 to
draw into the external texture. It shows two sets of stripes, one
animated using the shader and the other animated using Canvas. If the
two stripes are aligned, then the stream is perfectly synchronized.
Users can tap the screen to cycle between the three modes.
2019-11-26 07:58:52 -08:00
Ben Doherty 6942569409 Pass shared context on Windows to wglCreateContextAttribs (#1913) 2019-11-25 13:38:07 -08:00
Romain Guy 498a608941 Remove unused lambda capture 2019-11-23 19:55:05 -08:00
Philip Rideout eee7154c33 wasm: add support for DEBUG builds by disabling RTTI.
Unfortunately we require RTTI to be disabled for web builds
due to the way in which we handle array buffers. This may change
in the future but for now I think it's an acceptable constraint,
especially given the fact that RTTI adds bloat anyway.
2019-11-22 14:33:03 -08:00
Ben Doherty a735660af8 Separate resource packages for gltf_viewer and lucy demo (#1908) 2019-11-22 11:34:42 -08:00
Ben Doherty c5ed7172b3 Add release GitHub workflow (#1903) 2019-11-21 11:04:20 -08:00
Mathias Agopian 4b28362920 Better workaround a resource culling issue.
A texture resource can end-up with not usage bit set if it is used as
an attachment of a render target that gets replaced by a moveResource()
call. The framegraph should take care of culling our this resource,
in that case, but currently doesn't.

We worked around this issue by not declaring the resources, but it's
better to do this in the frame graph code, as to not affect the 
user facing API.
2019-11-20 22:26:00 -08:00
Mathias Agopian dfeaa416c0 Tone mapping always sets alpha channel to 1 in opaque mode
This fixes an issue where the alpha channel could be left to garbage in
opaque mode with FXAA disabled.
2019-11-20 17:34:59 -08:00
Mathias Agopian 3ce4dd94f7 Use a larger blur filter for SSAO
We go from 9 to 15 taps to better match the 16x16 noise pattern.
2019-11-20 16:32:28 -08:00
Ben Doherty 0ee1d406e0 Update README.md to reflect build link removal (#1902) 2019-11-20 13:29:51 -08:00
Mathias Agopian dad814e046 Fix a long standing bug preventing the use of transparent views (#1893)
Fix #1165

In order to use transparent views, post-processing had to be disabled
because we were not able to blit post-processed buffers with blending.
This is now fixed by simply reverting to a quad.

A side effect of this, is improved performance when a scaling blit is
needed when MSAA is active.


This also introduced new "bugs", or at least weird behaviors: the
system needs to know when blending is needed, and this has to be
based on heuristics (unless we add a new api). Currently the heuristic
is that the COLOR buffer is not discarded and the view is cleared with 
an alpha value (or not cleared).
2019-11-19 14:05:22 -08:00
Pixelflinger 6246f20e63 Always use SH3 for indirect lighting
We used to use SH2 on mobile/webgl, but the quality degradation is too
prominent. This adds ~16 adds though.
2019-11-19 14:00:37 -08:00
Ben Doherty f4ad55f6d7 Fix Windows CI failures by specifying shell (#1890) 2019-11-19 11:20:59 -08:00
Pixelflinger 027c4b42f7 fix a few issues with MSAA blits
1) When scaling is enabled, we're using a blit at the end of the frame,
   however, if MSAA is also enabled, this blit is not allowed, so we
   need an explicit MSAA resolve.

2) When rendering directly into the default render target with MSAA
   enabled, we need an explicit resolve ONLY IF there is a format
   conversion, because those are also not allowed. 
   Before, we were doing this resolve regardless.

3) The test for "rendering directly into the default target" had
   become wrong because, the Render target can now be a user texture
   (which is assumed to have the proper MSAA-ness and a depth buffer),
   so no intermediate buffer should be needed for those. We now
   check that render target is actually the default render target
2019-11-18 20:25:53 -08:00
Pixelflinger fb6c9f8b7d Use 16x16 blue noise for SSAO samples
The larger, blue noise texture gives a more pleasant, smoother SSAO
effect.
2019-11-18 20:25:29 -08:00
Pixelflinger 33d2eaee5b remove old 'SSAO' algorithm 2019-11-18 16:16:29 -08:00
Ben Doherty ae3ccd7fb6 Implement headless swap chains and readPixels for Metal (#1885) 2019-11-18 11:28:20 -08:00
Russell Chou 72dbea256a Fix comment. 2019-11-16 15:10:15 -08:00
Pixelflinger ea0ff1bc01 Add a way to override the material of a RenderPass
We used to have this functionality, but it we removed it because we
didn't have a use for it and it was costly.

This new implementation is only internal, and would (will?) be useful
if we wanted to generate a special buffer for SSAO for instance (instead
of just depth). This implementation, overrides the material at the time
the commands are executed, which is much cheaper than the previous
implementation.
2019-11-15 17:37:18 -08:00
Philip Rideout 2bca33f535 gltfio: Use JobSystem to decode PNG / JPEG.
For the street light glb from the Khronos suite, this reduces texture
loading time from 290 ms to 110 ms.

Stay tuned for another feature: notification callbacks.

Related to #1876.
2019-11-15 17:30:52 -08:00
Ben Doherty 75c5bb846b Use checkout action for GitHub Actions (#1886) 2019-11-15 16:33:23 -08:00
Pixelflinger 0da551c7fd More improvements to SSAO
- we add an 'intensity' parameter that allows to control the strength
  of the AO effect. This is useful for aesthetic reasons.

- the default intensity is now 2x that of before this change, which
  makes the intensity parameter match AO papers this implementation
  is inspired of.

- bias is now z-dependent, which reduces some self shadowing wrt the
  depth.
2019-11-15 09:42:37 -08:00
Mathias Agopian 5583dc26f9 Added a parameter to control the bilateral filter
This is needed because filament doesn't make strong assumptions about
the units used (e.g. meters), so we can't hardcode a distance in the
shader. But also, this is a cheap change.
2019-11-15 09:42:37 -08:00
Mathias Agopian 339fa3bd60 SAO and ssaogen cleanup
ssaogen now produces better formatted tables, directly usable in
shader code.

SAO shader now squares the sample radius outside of `tapLocation`, also
added some comments.
2019-11-15 09:42:37 -08:00
Mathias Agopian dbaaa977e7 Fix depth mipmaping program
Due to a typo, we were using a nearest neighbor downsampling, instead
of picking one of the 4 pixels based on position.
2019-11-15 09:42:37 -08:00
Mathias Agopian b10e99d374 Turn mipmapDepth material to a post-process material 2019-11-15 09:42:37 -08:00
Philip Rideout a7d572f060 Stream API: improve dlsym usage. 2019-11-15 08:40:41 -08:00
Philip Rideout 127234f655 Stream API: release image sooner. 2019-11-15 08:40:41 -08:00
Philip Rideout 2c13c8fe6e Stream API: rename createAcquiredImage => transformAcquiredImage. 2019-11-15 08:40:41 -08:00
Philip Rideout c0b9900cdc Stream API: privatize the AcquiredImage struct. 2019-11-15 08:40:41 -08:00
Philip Rideout 44e8d57935 Stream API: cleanup as per code review feedback. 2019-11-15 08:40:41 -08:00
Philip Rideout d85f8164c0 Stream API: add support for acquire / release semantics.
Previously, Streams had two modes (native and texid), this adds a third
mode called "acquired", which allows for copy-free synchronized external
textures in OpenGL and paves the way for Vulkan.

The native mode is now deprecated but texid mode needs to stay around
until all clients can be upgraded.

In an early prototype, this functionality was added directly into
Texture but required quite a bit of additional state tracking, so the
Stream API seemed like a better fit.

This API is probably not necessary for Metal due to Metal's shared
ownership semantics.

This has been tested with a new Android sample that will be added in a
subsequent PR.
2019-11-15 08:40:41 -08:00
Mathias Agopian 32407c2ba5 RenderPass cleanup/refactoring
RenderPass's API now doesn't need to know about FScene, instead we
pass the geometry info as parameters.

This is one step towards keeping the "scene" concept more away from
rendering.
2019-11-14 15:31:59 -08:00
Philip Rideout 51e82a5561 Fix dynamic backface culling.
This fixes an oversight in #1641 for scenes that have only 1 primitive
when the depth prepass is enabled. In such cases, the same prim is
rendered twice in a row: once for depth and once for color.

We had enhanced the main render loop to override the primitive's
backface culling state when the material instance changed, but that was
not sufficient since the same material instance can be used for depth
and color passes.

Fixes #1872.
2019-11-13 12:15:44 -08:00
Mathias Agopian 3fb75ca904 custom command support in the renderloop
New internal API to add custom commands (lambda) before or after each
pass. These commands can be added at any point and will be sorted
properly.

e.g.:

    appendCustomCommand(Pass::COLOR, CustomCommand::PROLOG, 0, [](){
       // custom code
    });


Also split appendSortedCommands() in two functions to make it easier
to insert custom commands.
2019-11-13 11:34:34 -08:00
Tim Psiaki 64a70c7c18 Flip Tangents and Bitangents on backfaces. 2019-11-13 11:31:57 -08:00
Mathias Agopian b9a68090b1 fix a data race on Debug builds
On Debug builds, HeapAllocatorArena needs LockingPolicy::Mutex because
it uses a TrackingPolicy, which needs to be synchronized.
On Release builds, HeapAllocatorArena doesn't need a LockingPolicy 
because HeapAllocator is intrinsically synchronized as it relies on
heap allocations (i.e.: malloc/free)
2019-11-13 09:18:57 -08:00
Mathias Agopian 5344854056 tweak how we invoke commandstream's commands
- this is to allow the use of C++17 std::invoke
- don't std::move() each argument of the tuple<> instead
  std::move() the tuple itself and perfectly-forward each argument.
- handle return values
- handle synchronous commands
2019-11-12 11:29:05 -08:00
Ben Doherty abad894fd5 Fix UB inside FMaterial (#1862) 2019-11-12 10:08:42 -08:00
Philip Rideout 8872227af5 Fix normals with skinning when there is no normal map.
I tested this with the CesiumMan model, the lighting seems improved
around his hands.

Fixes #1848.
2019-11-11 15:03:17 -08:00
Mathias Agopian 30a07a49d0 add a way to import/export an Entity from/to an integer
This is intended to be used for interop with other programing languages.
2019-11-11 14:37:10 -08:00
Mathias Agopian 0a37cce5fe don't use our own sync primitives when TSAN is used
TSAN seems to have problems with homegrown sync primitives, such as
spinlocks, so we just don't use them when TSAN is enabled.
2019-11-11 14:36:49 -08:00
flashk fc76ed9949 clampNoV function ignores argument
The "clampNoV" shader function is ignoring the passed dot product argument and recomputing the dot product itself. This will result in the wrong NoV value being used for clear coat IBL computations.
2019-11-08 15:34:25 -08:00
Philip Rideout d55d042a14 Renderer: call updateStreams AFTER makeCurrent.
When using the OpenGL backend, updateStreams makes GL calls such as
glEGLImageTargetTexture2DOES and therefore requires a valid GL context.
2019-11-08 12:21:25 -08:00
Ben Doherty d7e07f4d51 Transition to GitHub Actions for continuous builds (#1850) 2019-11-07 13:38:37 -08:00
Ben Doherty 22a6ecadbb Disable RenderingTest from CI test suite (#1858) 2019-11-07 11:17:41 -08:00
Mathias Agopian 53ff133b03 fix a possible memory corruption in debug builds
TrackingPolicy::Debug didn't store the base pointer of the Area, and
instead relied on the first allocation to discover it, however, because
of alignment, the first allocation may not match the base pointer.
Because of that there could be an overflow in onRewind(), i.e. we
could rewind to a pointer before the (wrongly computed) base. This
overflow caused the debug memset to go awry and stomped on memory.

This is fixed by passing the base pointer to the constructor of the
TrackingPolicy. This base pointer could be nullptr with certain
allocators, but in that case, onReset/onRewind should never be called;
and this is enforced at compile time.

Also fixed a (luckily) harmless buffer overflow when preparing the
dynamic lights, if the number of lights wasn't a multiple of 4. This
was harmless because we use a linear allocator, so overflows are not 
really overflows.
2019-11-07 10:03:41 -08:00
Benjamin Doherty d1ab68ebfa Fix KTX image test on Windows 2019-11-07 09:15:07 -08:00
Philip Rideout 655b7dc13c Emit warning for too many morph targets.
Motivated by #1852.
2019-11-06 15:39:38 -08:00
Philip Rideout 48bfe0453b Fix an assert when the last uniform is an array.
Clients who do not yet have this fix can usually work around this issue
by calling the non-array overload of `MaterialInstance::setParameter`
when the array size is 1.
2019-11-06 15:39:17 -08:00
Philip Rideout 87a05f057a Fix out-of-bounds in an [unused] utility.
This was caught by ASAN.

Our algorithm header has many one-liners that compute the "next power of
two length / 2" but they all have the caveat that if the input is
already POT, then the "/ 2" part does not occur.

Usually we deal with this by testing the difference against zero.
However in `partition_point` we were skipping the test, thus causing a
potential out-of-bounds access.

I fixed `partition_point` and added a few more tests for non-POT cases.
2019-11-05 17:14:15 -08:00
Mathias Agopian 4f540fe7fd Better handling of engine shutdown
- we make sure we don't leak user callbacks or fences
- fix typos
2019-11-05 16:17:46 -08:00
Pixelflinger 1fd675fd09 Make filament's readPixels() asynchronous wrt the GPU
This doesn't change the user facing API because it already used a
callback.

With this change we implement readPixels() with a PBO, which won't
stall the GPU. Then we periodically check a fence to see when the
command is completed, at which point we map the PBO and copy the data
to the user buffer.
2019-11-05 16:17:46 -08:00
Mathias Agopian bf72adbb57 Implement Headless SwapChain mode.
This is useful for unit tests. The content of the swapchain can be
read to main memory with Renderer::readPixels().


This PR doesn't implement this new feature in the following backends and
platforms (TODO):

VulkanDriver.cpp
MetalDriver.mm

PlatformWGL.cpp
PlatformWebGL.cpp
PlatformCocoaTouchGL.mm
2019-11-05 12:19:29 -08:00
Ben Doherty dd45703d73 Fix Metal backend crash when rendering external image before set (#1847) 2019-11-05 09:23:58 -08:00
Ben Doherty 7c0d3cdb10 Add EAC / ETC2 and DXT compression formats to Metal backend (#1800) 2019-11-05 09:21:41 -08:00
Mathias Agopian 5462cc0fcf Renderer::readPixels() can now read back from a RenderTarget
Before it was limited to reading back from the SwapChain.
2019-11-04 17:18:39 -08:00
Philip Rideout 8fe9f15b3b JavaScript: add documentation for fetch utility. 2019-11-04 14:20:51 -08:00
Philip Rideout c49c6e5d19 JavaScript: allow pre-population of asset data.
Fixes #1843.
2019-11-04 14:20:51 -08:00
Philip Rideout 636c54ec6f gltfio: support mesh-level morph weights.
We honored node-level defaults but not mesh-level.

Fixes #1840.
2019-11-04 12:32:02 -08:00
Nicklas Ansman Giertz 52ee07f2fd Add a clarifying comment 2019-11-03 15:03:13 -08:00
Nicklas Ansman Giertz 02ef4a99b7 Add some missing nullability annotations to the gltfio android bindings 2019-11-03 15:03:13 -08:00
Nicklas Ansman Giertz 73a4431a34 Fix some warnings in the gltfio android jni code 2019-11-03 15:03:13 -08:00
Nicklas Ansman Giertz e252558ef6 Expose FilamentAsset.getResourceUris in the Android bindings 2019-11-03 15:03:13 -08:00
Nicklas Ansman Giertz 5680b5d9a6 Add support for GLTF files in the android gltfio bindings 2019-11-03 15:03:13 -08:00
Philip Rideout 86c0a68ccd Work around unaligned stack with clang 11.
Optimized macOS builds can trigger "stack_not_16_byte_aligned_error"
when building with clang 11. We happen to see this with resgen but it
could happen anywhere.

https://forums.developer.apple.com/thread/121887

Fixes #1823
2019-11-01 13:52:47 -07:00
Ben Doherty 9379e7ce45 Use ARC for Metal backend (#1824) 2019-11-01 10:28:28 -07:00
Philip Rideout 04d2234169 Fix WebGL debug build. 2019-11-01 09:14:38 -07:00
Philip Rideout 66f4419518 gltfio: Fix black default material.
Fixes #1828.
2019-10-31 16:45:01 -07:00
Philip Rideout be4ad2ec07 WebGL: add a light source to the animation demo. 2019-10-31 16:45:01 -07:00
Philip Rideout 853b2205dd Upgrade emsdk for improved wasm generation.
This uses clang's wasm backend rather than fastcomp.
2019-10-31 16:41:29 -07:00
Philip Rideout 80f104c522 OpenGL: Fix up my previous fix for uvec4 attribs.
The previous fix for #1726 was not quite right because it did not
set the INTEGER flag unless the attribute was declared.

Fixes #1726.
2019-10-31 11:57:43 -07:00
Philip Rideout 1fa2fd9b7f WebGL: add morphing demo. 2019-10-31 11:57:43 -07:00
Philip Rideout fa108d6a65 Use the Jim Arvo method for transforming AABB's.
This is from the 1990 Graphics Gems article.
2019-10-30 16:15:55 -07:00
prideout a82d93914e Bump to v1.4.2 2019-10-30 13:49:36 -07:00
Philip Rideout 389349198f gltfio-jni: Fix double-init panic caused by build issues.
Filament keeps a global static list of engines for verification purposes
which was being recreated multiple times, causing a panic. After a lot
of experimentation with the build, I was not able to fix this while
keeping the current scheme of dynamically loading both libraries.

As a "solution", we now staticly link filament into gltfio-jni, and ask
clients to load only that.

Fixes #1811.
2019-10-30 09:51:14 -07:00
Philip Rideout 225a844e0f Minor improvements to Engine validation.
This enhances the assert added in 2548da9 in the following ways:

- Adds console output at startup to help detect "double load" bugs.
- Adds PRETTY_FUNCTION to show where the invalid usage is coming from.
- Tweaks the wording since use-after-destroy is not always the cause.
- Consolidates usage of static globals into a helper class.

Motivated by #1811.
2019-10-29 15:48:29 -07:00
Mathias Agopian f018c719a6 a test for the skinning math 2019-10-29 15:38:40 -07:00
Philip Rideout 2a229571ad Minor fixes to gltf-bloom demo. 2019-10-29 10:20:28 -07:00
Romain Guy 35959b547c Use unnormalized vectors to compute bump mapping. (#1813)
If we assume the tangents and bitangents were generated using mikktspace,
we should use the unnormalized vectors, as indicated at mikktspace.com
or in http://www.metalliandy.com/mikktspace/downloads/mikktspace/mikktspace.h
(see last comment at the end of the file).
2019-10-29 09:41:15 +00:00
Philip Rideout 796007377d Revert the Engine validation commit.
This needs to wait until code review and was pushed by accident.

This reverts commit bb90103e74.
2019-10-28 16:14:07 -07:00
Philip Rideout 5c73d0ae75 Update package.json for npm release. 2019-10-28 16:05:45 -07:00
Philip Rideout bb90103e74 Minor improvements to Engine validation.
This enhances the assert added in 2548da9 in the following ways:

- Adds console output at startup to help detect "double load" bugs.
- Adds PRETTY_FUNCTION to show where the invalid usage is coming from.
- Tweak the wording since use-after-destroy is not always the cause.

Motivated by #1811.
2019-10-28 14:08:54 -07:00
Ben Doherty 0149bc504d Fix Windows GitHub Action (#1814) 2019-10-28 12:22:42 -07:00
Philip Rideout 3db035520b gltf-bloom now invokes the gltfio animator.
Tested with CesiumMan.
2019-10-28 09:32:39 -07:00
Philip Rideout 618b59932c gltfio: Add Java / Kotlin bindings for Animator.
Fixes #1529.
2019-10-28 09:32:39 -07:00
Mathias Agopian 9ef05ad456 better fix for NoopDriver on iOS 2019-10-24 14:17:29 -07:00
Adrian Perez c8a0dbb59a Fix OpenGL ES 3.0 support on iOS (#1803) 2019-10-24 12:43:23 -07:00
dsternfeld7 35a0b045f8 Adds missing include in NoopDriver that prevented the correct shader model from being picked when using the Noop backend. 2019-10-24 10:58:16 -07:00
Ben Doherty a4369c833d Add README section on Filament CMake options (#1801) 2019-10-23 13:27:08 -07:00
Philip Rideout 354f1da708 Enhance KHR_debug output + code cleanup. 2019-10-22 12:41:34 -07:00
Philip Rideout 7e47d257d1 OpenGL Driver: add support for KHR_debug.
This extension dumps out some interesting vendor-specific information
to the log, which could be useful for debugging. Interestingly, some
of Android demos produce this output on Pixel 3:

  KHR_debug: EsxBufferObject::Map - Ignoring EsxBufferMapUnsyncedBit

Enabled for debug builds only.
2019-10-22 12:41:34 -07:00
Ben Doherty c3d2b3578d Add Javadoc for Colors, Box, and MathUtils (#1796) 2019-10-21 17:59:05 -07:00
tpsiaki 783aa06a46 Fix typo in Noop on mobile. (#1799) 2019-10-21 17:41:32 -07:00
Mathias Agopian faa82ff35a implement diag() in TMatSquareFunctions
this requires using 'auto' as the return type.
2019-10-21 14:27:40 -07:00
Ben Doherty 3008123d6b Update RELEASE_NOTES for v1.4.1 (#1793) 2019-10-18 13:36:34 -07:00
Ben Doherty 2d2987066d Implement user-controlled frame presentation in Metal (#1760) 2019-10-17 17:11:34 -07:00
Mathias Agopian c84ec04efa remove unneeded loop in TransformManager
during a transaction, it makes no sense iterating through all
children just so that we can iterate through their children...
and do nothing else.
2019-10-17 16:17:32 -07:00
Mathias Agopian 197b45c1d1 fix a double-free when exiting the FroxelData test
We were destroying the engine manually (by calling delete) which is
not allowed.

Also made FEngine::shutdown() private.
2019-10-17 16:17:12 -07:00
Mathias Agopian af9ecf0a61 minor cleanup based on clion suggestions 2019-10-17 16:16:51 -07:00
Ben Doherty 530fb58337 Add Javadoc to IndexBuffer and VertexBuffer (#1788) 2019-10-16 17:59:53 -07:00
Philip Rideout 6a891021b1 MSVC fixes for Vulkan.
Should fix #1772, hopefully.
2019-10-16 17:37:33 -07:00
Ben Doherty 0e7c68b50d Fix, assertion using bones with Metal backend (#1787) 2019-10-16 15:54:08 -07:00
Ben Doherty 32a32d3d21 Remove iOS OpenGL ES 3.1 hack (#1781) 2019-10-16 10:51:55 -07:00
Ben Doherty fca71813d4 Use CMAKE_COMMAND variable in place of cmake (#1783) 2019-10-16 10:50:55 -07:00
Philip Rideout 3618f14531 Add Android sample for Camera Stream.
This simple Kotlin app projects a live feed on the side of a cube.
It looks very similar to the `lit-cube` demo but there is a new Kotlin
class called `CameraHelper` that creates Camera2 objects, starts
the capture session, creates the Filament texture, etc.

For now, this app uses SurfaceTexture. This is a starting point and
provides a testing ground for tentative improvements to our Stream API.
2019-10-16 09:05:24 -07:00
Romain Guy 9de3e76a53 Remove the use of reflection where it's not necessary (#1782)
Fixes #1510
2019-10-15 17:54:02 -07:00
Romain Guy e472fdbce4 Remove Kokoro Windows presubmit 2019-10-15 17:40:24 -07:00
Mathias Agopian c9fcedb40b some optimizations to the math code (#1779)
- we use by-value parameters in some places, which helps the compiler
  (not sure why, but assuming references can be aliased and the
   compiler is cautious about that).
  This helps matrix multiplies (which is almost never inlined) and
  transpose (but that's almost always inlined and merged with
  something else, so the gain here is not completely real)

- remove support for matrices-of-matrices because this wasn't complete
  anyways.

- improve matrix * scalar by inlining the loop manually instead of
  going through *=, this saves some extra writes.
2019-10-15 17:22:54 -07:00
Mathias Agopian bd8c3e9181 don't limit the near plane to ~1mm (#1778)
We were not checking Camera's preconditions properly -- we assumed that
near < 1/1024 meant "near == 0".

Now we check preconditions properly and revert to the same hardcoded
default if they're not met -- doesn't matter what the default is,
it's there only to avoid NaNs and Infs elsewhere -- rendering will
be bogus eitherway.

Fixes #1766
2019-10-15 17:22:38 -07:00
Gregory Popovitch 26d0aa76f8 README.md: add build steps for Visual Studio 2019 / MSVC (#1775) 2019-10-15 12:02:08 -07:00
Ben Doherty 20f4ec6576 Use platform-specific temporary directories for CircularBuffer (#1769) 2019-10-15 12:01:03 -07:00
Ben Doherty d0bc23473c Fix crash when using Filamat lite library (#1780) 2019-10-15 10:49:59 -07:00
Ben Doherty c33f6adf62 Remove BUILD_DEMO CMake option (#1776) 2019-10-14 09:09:46 -07:00
Ben Doherty d4efa105b7 Set up Windows build through GitHub actions (#1767) 2019-10-11 09:28:57 -07:00
Ben Doherty e8641ce257 Additional fixes for MSVC (#1765) 2019-10-10 16:45:06 -07:00
Ben Doherty d7a4bdc3f1 Combine matdbg dependencies into single shared library (#1764) 2019-10-10 12:45:51 -07:00
Philip Rideout e66215295c gltfio: use the new sparse support in cgltf. 2019-10-09 18:45:27 -07:00
Philip Rideout 552bb3e6db Update cgltf with sparse functionality. 2019-10-09 18:45:27 -07:00
Mathias Agopian a96da05ab8 fix CircularBuffer ashmem fallback (#1763) 2019-10-09 16:48:22 -07:00
Ben Doherty fb5ee4a9d0 Add Javadoc comments to Material and MaterialInstance (#1696) 2019-10-08 15:56:26 -07:00
Philip Rideout da13067b57 libmath: prevent NaN's in slerp due to acos.
Fixes #1749.
2019-10-08 15:37:48 -07:00
Ben Doherty d48d69c765 Use custom Git checkout action (#1756) 2019-10-08 15:22:09 -07:00
Mathias Agopian 5098b2af77 SwapChain javadoc 2019-10-08 10:31:32 -07:00
Mathias Agopian 5576d6b014 TextureSampler javadoc 2019-10-08 10:31:14 -07:00
Mathias Agopian b072399229 TransformManager javadoc 2019-10-08 10:30:54 -07:00
Mathias Agopian 4f0ab43d58 Stream Javadoc 2019-10-08 10:27:53 -07:00
Philip Rideout 3f742880b5 gltfio: do not abort for sparse data, warn instead.
Sparse accessors are easy to punt gracefully, we can emit a warning
and instead use the dense "base" data.

Also, after cgltf support for this lands, we will need to apply sparse
data in ResourceLoader, so this adds a bit of plumbing to prep for that.

Relates to #1727.
2019-10-08 08:18:46 -07:00
Mathias Agopian 0704194460 javadoc for Renderer
also made resetUserTime and getUserTime public
2019-10-07 16:13:56 -07:00
Mathias Agopian 56e747f558 Scene javadoc 2019-10-07 16:13:38 -07:00
Ben Doherty 61c22f2295 Fix culling in MaterialInstance (#1750) 2019-10-07 16:08:50 -07:00
Mathias Agopian c4bbaeda86 improve CircularBuffer error message 2019-10-04 13:18:09 -07:00
Philip Rideout 678ffc7503 gltfio: do not loop animation samplers, fixes #1730. 2019-10-04 08:48:35 -07:00
Philip Rideout a080a47268 Add RenderTarget javadoc. 2019-10-04 08:47:55 -07:00
Philip Rideout 82e8104539 Fix javadoc warnings. 2019-10-04 08:47:55 -07:00
Mathias Agopian 11bd8e72ef harden lispsm code against div-by-zero 2019-10-03 22:58:26 -07:00
Mathias Agopian 03c2a90206 noexcept-ize libmath a bit move
this gets rid of a few ide-warnings about static initialization of
arrays with math types.
2019-10-03 17:12:35 -07:00
Mathias Agopian c38ab64b6a Update Engine.cpp 2019-10-03 17:12:18 -07:00
Mathias Agopian 2548da9aed validate Engine in all Builder::build() methods
We now assert if the Engine given is invalid,
which would happen if it was used after being
destroyed.

Builder::build() is a reasonable place for this since it's generally
not in the critical path.
2019-10-03 17:12:18 -07:00
Ben Doherty 2fa08123a0 Add an iOS runner for backend-test (#1720) 2019-10-03 17:02:28 -07:00
Mathias Agopian 20c3d45b9c Engine.flushAndWait() is not needed in most places 2019-10-03 16:04:22 -07:00
Philip Rideout c8af3226de OpenGL driver: fix error with uvec4 attribs, clean up Vulkan/Metal. (#1735)
The vertex shader in the material variant for skinning-and-morphing
declares a `uvec4` attribute that can be unused and disabled, but still
needs to be typed correctly.

The fix is motivated by WebGL, but the issue might occur with other
OpenGL implementations that have strict drivers.

Fixes #1726
2019-10-03 15:42:07 -07:00
Romain Guy 4b669fb1c7 Fix formatting 2019-10-03 14:25:39 -07:00
Mathias Agopian 340f6d721a Texture javadoc 2019-10-03 13:25:06 -07:00
Philip Rideout 489f3ff3c9 Add javadoc for View and Viewport. (#1734)
This CL also fixes warnings in IndirectLight and adds a new C++ getter
to View for consistency with Java.
2019-10-03 08:38:10 -07:00
Mathias Agopian 566d3613d1 Skybox javadoc 2019-10-02 15:58:57 -07:00
Mathias Agopian e691cfa9e3 javadoc fixes for IndirectLight 2019-10-02 15:57:31 -07:00
Romain Guy a4a1bf07aa Use our own constants instead of M_PI, M_*, etc. (#1733)
These constants are not part of the standard. We instead use our own
constexpr definitions in the filament::math namespace, as part of
the scalar.h include.
2019-10-02 15:31:38 -07:00
Ben Doherty 7ea7d1d5f2 Fix, matinfo doesn't work on Windows (#1732) 2019-10-02 13:20:24 -07:00
Philip Rideout 686c68c627 View API: minor doc fixes, add getRenderTarget. (#1723)
Since getRenderTarget() already exists in Java, we should also provide
it for C++ clients.
2019-10-02 10:13:42 -07:00
Romain Guy c652dcfd2a Fix warning 2019-10-02 08:56:39 -07:00
Ben Doherty 01fab5a6e4 Update gtest to latest master (#1718) 2019-10-01 16:48:10 -07:00
Philip Rideout 16a5adcfde Fix quat slerp so it takes shortest path.
Fixes #1716.

This regressed in c65e561c59.
2019-10-01 16:22:00 -07:00
Philip Rideout d550d36637 Add javadoc for RenderableManager, fix javadoc warnings. 2019-10-01 16:09:05 -07:00
Mathias Agopian 3857c1a9b2 javadoc for IndirectLight 2019-10-01 13:32:54 -07:00
Philip Rideout 2f8bc9239b Add JS binding to unary Camera::setExposure. 2019-10-01 12:39:40 -07:00
Philip Rideout 9de934e2bd Add Java annotations to setMorphWeights.
Noticed this while working on javadoc stuff.
2019-10-01 11:16:15 -07:00
Philip Rideout 769f1db011 Fix ambiguous atomic-to-bool conversion. 2019-10-01 10:43:15 -07:00
Philip Rideout da72c58146 mac_runner: disable warning. 2019-10-01 10:43:15 -07:00
Ben Doherty ef34dd2461 Fix operator overrides for Clang / MSVC on Windows (#1715) 2019-09-30 18:39:38 -07:00
prideout 90fdb95429 Update release notes for v1.4.0 2019-09-30 14:55:39 -07:00
Gregory Popovitch d5c0d11404 Final changes for building with msvc 2019 on Windows (#1681) 2019-09-30 14:18:06 -07:00
Romain Guy b0d116632c Add the ability to modify clip space coordinates in the vertex shader (#1704)
* Add the ability to modify clip space coordinates in the vertex shader

This introduces MaterialVertexInputs.clipSpaceTransform, a mat4 that
is applied to gl_Position before exiting the vertex stage.

* Address code review comments
2019-09-28 14:15:32 +03:00
Romain Guy a67d92c2ca Lower limit from API 21 to API 19 (#1701)
* Lower limit from API 21 to API 19

This was requested by an internal application. API 19 is when OpenGL
ES 3.0 support was added so there is no good reason for us to not
support this API level. The only trick is to avoid referring to the
glTexStorage2DMultisample symbol directly as it only exists in 3.1.

* Compile out code we never use

* Use reflection to handle shared EGL contexts pre-API 21.

* Remove comment

* More fixes required to run on API level 19

- dlym() fails for ashmem on API 19, so we only try on API 26+ instead.
- Older emulation for OpenGL ES 3.0 returns error states for valid API calls so we need to clear the GL error bit before we create the GL driver.
- Activity lifecycle changes since API 19 would cause animations to keep running and to reference destroyed objects.
- EGLContext.getNativeHandle() is new in API 21, we need to use reflection on API 19. The new code path uses the class loading trick to avoid a bytecode verification error on API 19.

* Filament now runs properly on API level 19

This commit adds a new api_level() API to libutils which can be used to
query the platform's API level. On Android it works as expected, other
platforms currently return 0.
2019-09-28 14:13:06 +03:00
Philip Rideout 21b208398b Renderable doxygen now uses \see etc. 2019-09-27 15:26:08 -07:00
Philip Rideout 65b3e956df Add doxygen for RenderableManager and NameComponentMananger. 2019-09-27 15:26:08 -07:00
Mathias Agopian c8d0715b16 SamplerParams is not default-initialized anymore
This is to allow designated aggregate initialization in C++20.
We do this because we have been relying on C99 designated
initialization, which is only supported by clang, other compilers need
c++20 to get a similar functionality. Therefore, we now try to limit
Ourselves to C++20 rules.

This could break existing code, since now SamplerParams needs to be
zero-initialized:

SamplerParams p{};

This is generally not an issue because the intended use is:

doSomethingWithSamplerParams({
      .filterMag = LINEAR,
   });
2019-09-27 13:53:11 -07:00
Mathias Agopian 16d307e543 enforce that quaternions are made of arithmetic types
I believe this might fix some msvc compiler issues too.
2019-09-26 19:05:33 -07:00
Mathias Agopian 5ed07639af workaround an MSVC bug with brace initialization
the C++ standard says:

   if T is a class type with a default constructor that is neither
   user-provided nor deleted (that is, it may be a class with an
   implicitly-defined or defaulted default constructor), the object
   is zero-initialized and then it is default-initialized if it has a
   non-trivial default constructor

Unfortunately, MSVC always calls the default constructor, even if it
is trivial, which breaks constexpr-ness.
To workaround this, we're always zero-initializing TVecN<>

Also removed constexpr from default constructors, since they never can
be constexpr as they're not initializing the vector.
2019-09-26 19:05:33 -07:00
Ben Doherty e2655e93bc Add test framework for libbackend (#1697) 2019-09-26 12:30:30 -07:00
Philip Rideout 3a20be1d1a gltfio javadoc: add links, fix formatting. 2019-09-26 14:07:13 -04:00
Philip Rideout 8244f8e9cb Add javadoc comments for gltfio. 2019-09-26 14:07:13 -04:00
Romain Guy c575fd7395 Add new Camera::setExposure(float) API (#1699)
* Add new setExposure(float) API on Camera

This API can be used to set a specific exposure value. For instance:

camera.setExposure(1.0)

Will set the exposure to 1.0 (or ISO 100, apeture 1.0 and shutter speed 1.2s).
This can be useful to match the lighting setup of other engines/tools. Setting
the exposure to 1.0 can for instance be used to treat lights as being unitless
(a directional light could have a strength of 2.0 for instance).

Fixes #1667

* Update release notes

* Fix Java build error

* Fix Web bindings
2019-09-26 20:08:46 +03:00
Philip Rideout 6a67cf0009 Enhance doxygen annotations for gltfio. 2019-09-26 12:18:56 -04:00
Romain Guy 79292481b3 Update documentation 2019-09-26 16:31:55 +03:00
Mathias Agopian 829f341de3 Engine and Camera javadoc (#1698) 2019-09-26 11:53:14 +03:00
Mathias Agopian b509ef4dad handle scalar op vector directly to help some compilers 2019-09-25 22:39:13 -07:00
Mathias Agopian 422c8d9a64 Make DriverAPI.inc work with MSVC19 2019-09-25 13:52:41 -07:00
Romain Guy d0b5c5cee8 Update compile & targetSdk from 28 to 29 (#1691) 2019-09-25 22:25:43 +03:00
Romain Guy 9b9548306d Fix Android samples (#1688)
Fixes #1687
2019-09-25 15:48:30 +03:00
Ben Doherty b28e535540 Combine license file generation functions for MSVC compatability (#1684) 2019-09-24 12:45:38 -07:00
Mathias Agopian 1f7584ace2 Improve backend documentation (#1674)
We need to document the backend headers that are public.
Added documentation for:
- DriverEnums.h
- BufferDescriptor.h
- PixelBufferDescriptor.h

Disabled doxygen for public headers of backend that don't need to
be public for filament's API.

Also improved documentation for:
- LightManager.h
- RenderTarget.h
- TextureSampler.h
2019-09-24 11:18:15 -07:00
Ben Doherty 21512e8228 Update MaterialBuilder header comments for Doxygen (#1673) 2019-09-24 09:11:35 -07:00
Gregory Popovitch a34903aa33 Update CMake configuration to support building with MSVC 2019-09-23 10:15:34 -07:00
Philip Rideout 4eba402adb Enhance the deprecation note. 2019-09-23 12:31:24 -04:00
Philip Rideout 64c5f5aee7 Deprecate populateTangentQuaternions. 2019-09-23 12:09:37 -04:00
Philip Rideout 1bda37776b Rename KtxUtility namespace to image::ktx. 2019-09-23 12:08:57 -04:00
Philip Rideout 1c5d7d6cc3 Build OpenImageDenoise only in host builds.
Fixes #1672
2019-09-21 14:31:54 -04:00
Mathias Agopian b81ff060ae Remove HARD Fence public API
This API will be hard to implement on all backends (e.g. Vulkan) and
isn't that useful other than for timing.
2019-09-20 17:57:48 -07:00
Ben Doherty 0cebbfca23 Fix STB linking issues on Windows (#1669) 2019-09-19 15:31:54 -07:00
prideout b9c7814dfd Remove unused variable. 2019-09-19 11:05:33 -07:00
Philip Rideout ba9fd6719a FrameGraph, OpenGL, Vulkan: Clean up RenderPassFlags. 2019-09-19 10:52:29 -07:00
Mathias Agopian f0ad12ce2e Fix matrix operations when using mixed precision
This is a similar fix to the previous vector fix. Commutative 
operations now always return the same type and the operations are
carried out in the precision resulting from following traditional
C++ rules.
2019-09-18 18:22:05 -07:00
Mathias Agopian 21acf53d3f improve vector operations when using implicit conversion
It used to be that operations e.g. like:

 float3{} + double{} would be computed as
 float3{} + float3{double{}} instead of
 float3{} + double3{double{}}

I other words, when an implicit conversion was involved on the right
it would be converted to the left side’s type, possibly losing 
precision.

Another problem was that swiping the operands could produce different
Results, e.g.:

   float3{1} * 5.0 -> float3{5.0f}
   5.0 * float3{1} -> double3{5.0}


This is no longer the case, now both expressions would return a double3. 

Note:

float3 r{};
r *= 5;

Is now equivalent to:

r[0] *= 5;
r[1] *= 5;
r[2] *= 5;

Instead of before:

r[0] *= 5.0f;
r[1] *= 5.0f;
r[2] *= 5.0f;
2019-09-18 18:22:05 -07:00
Mathias Agopian 2f5927d531 Minor code clean-up 2019-09-18 18:22:05 -07:00
Mathias Agopian cf950a8d6f improve mixed-precision vector operations
We now follow the same rules than for basic types, when performing
mixed-precision operations, e.g.:

  float3 + double3 -> double3
  double3 + float3 -> double3
  dot(float3, double3) -> double

In particular, e.g. swapping the arguments to arithmetic operations
now always yields to the same result type (before, float3 + double3
would not return the same type than double3 + float3).
2019-09-18 18:22:05 -07:00
Philip Rideout 48b73ad998 Vulkan: use a dummy buffer for missing attributes.
To prevent an excess of variants, sometimes our vertex shaders declare
inputs that they never read from. For example, our skin-and-morph
variant might never read from the skinning attribute, but still declares
the input.

This PR is a sister to #1663, which is a fix for #1525.

See also #1279.
2019-09-18 18:14:45 -07:00
Philip Rideout 8fc94f127b Add language bindings for setCullingMode. 2019-09-18 18:12:02 -07:00
Philip Rideout ce33f42e62 Fix warning in WebGL builds 2019-09-18 18:12:02 -07:00
Philip Rideout 61032e55b5 Update release notes. 2019-09-18 18:12:02 -07:00
Gregory Popovitch 6160d3f51e more changes for building with vs2019/msvc (#1506) 2019-09-18 17:25:22 -07:00
Ben Doherty 5d725f6de9 Fix, allow missing bone indices vertex attribute in Metal driver (#1663) 2019-09-18 16:59:43 -07:00
Romain Guy 020e9e59ed Don't use shallow fetches
This can cause issues with some PRs.
2019-09-18 16:39:40 -07:00
Mathias Agopian bd777c1e56 Update View.cpp 2019-09-18 15:25:51 -07:00
Mathias Agopian 087b12c802 Fix minor time calculation imprecision
use double for the shader's 'second' time calculation, since 1 billion cannot be stored
in a float accurately.
2019-09-18 15:25:51 -07:00
prideout 42f2642d72 Vulkan: fix layout and miplevel for depth attachments.
We now use GENERAL layout for depth-sampled images in order to support
the SSAO use case of simultaneous binding + sampling.

We may be able to optimize this in the future by enhancing DriverAPI
so that it feeds more information into the render pass.

Fixes #1627, #1649.
2019-09-18 07:41:04 -07:00
Mathias Agopian 9c8d0ed5a1 handle basis inverting transforms (e.g. planar symmetries)
We now inverse the face winding order based on the determinant of
each render primitive world's transform. This prevents front/back faces
to be reversed when using a left-handed basis, after transform.

Fix #1520
2019-09-17 18:38:52 -07:00
Philip Rideout 9fd1705acf Add support for dynamic backface culling.
Inspired by our recent scissor change (#1639) but motivated by gltfio,
which was forced to create a ton of ubershaders (see #1562).

Tested with:

  gltf_viewer -u ../glTF-Sample-Models/2.0/TextureSettingsTest/glTF/TextureSettingsTest.gltf
2019-09-17 08:22:01 -07:00
Mathias Agopian c981b52832 use enable_if<> instead of static_assert()
This is nicer because this way the methods that don't match don't
even exist. Also make it better when editing code with a C++ aware
ide.

Also use the less verbose std::enable_if_t<>
2019-09-16 18:13:21 -07:00
prideout d074b6fd1a Remove unused field from backend::SamplerParams. 2019-09-16 16:04:26 -07:00
Mathias Agopian 7da5a25e2f Split OpenGLDriver in two files
We now have OpenGLContext which only tracks the OpenGL state.
It exposes an API very similar to OpenGL and does all the state
tracking. Currently, it doesn't expose non state-changing APIs 
(e.g. draw methods) and only implements the state-changing API we
need (to track the state of).
2019-09-16 15:53:02 -07:00
Romain Guy b96b8eb787 Encode sRGB images as sRGB, not linear (#1646)
Fixes #1608
2019-09-16 10:51:17 -07:00
Philip Rideout a25be5ee6e civetweb: do not build unless matdbg is built 2019-09-16 09:43:49 -07:00
Philip Rideout bf9d1f1967 civetweb: fix warnings 2019-09-16 09:43:49 -07:00
Philip Rideout 561221fdc3 Rename PostProcessVertexInputs uv to normalizedUV. 2019-09-16 09:04:14 -07:00
Philip Rideout 8548afa231 Fix full-screen triangle winding and tex coords.
If you tried removing `culling: none` from any post-process materials,
everything would be fine in GL but Vulkan would be black because
our full-screen triangle was back-facing.

Continue reading only if you thrive in absurd situations.

- Metal and OpenGL define clip space as Y-up whereas Vulkan is Y-down.
- Metal and Vulkan define tex coords as Y-down whereas OpenGL is Y-up.
2019-09-16 09:04:14 -07:00
Philip Rideout 803e695d5c Add "uvToRenderTargetUV" to public shading API.
Fixes #1626.
2019-09-16 09:03:30 -07:00
Philip Rideout 5c58776313 Repair WebGL builds. 2019-09-16 08:39:20 -07:00
Romain Guy 0db39ea08a Add Android presubmit (#1644)
* Add Android presubmit

* Build Android on Linux, macOS targets have NDK 18 only

* Consolidate workflows and jobs

* Try to build Android on macOS

* Fix typo

* Cleanup scripts

* Try NDK side by side if NDK bundle has the wrong version

* Simplify logic

* Fix NDK logic

* Only update the NDK when necessary

* Fix typo

* Update required NDK version

* Favor NDK side-by-side

* Remove support for obsolete NDK bundle, require NDK side-by-side

* Install the NDK side by side when missing
2019-09-13 19:28:55 -07:00
Romain Guy d76fb5d7e5 Fix matc dependencies and compilation messages 2019-09-13 18:41:38 -07:00
Romain Guy f37ab8158c Name build jobs (#1643)
* Name build jobs

* Use build/ prefix instead of presubmit prefix

* Rename desktop workflow for consistency

* Forgot a git add...
2019-09-13 17:01:45 -07:00
Romain Guy 33db5acd13 Add web presubmit (#1642)
* Add web presubmit

* Use macOS not Linux
2019-09-13 16:40:57 -07:00
Mathias Agopian e068204876 scissor is now part of PipelineState
setViewportScissor is gone, which will avoid a runtime error if
called outside of begin/endRenderPass, making the driver API more
robust.
2019-09-13 13:58:29 -07:00
Ben Doherty d849231caf Remove old post-process shader pipeline (#1631) 2019-09-13 09:29:28 -07:00
Ben Doherty 996bd58fcb Use bitmask enum utility for MaterialBuilder::TargetApi (#1634) 2019-09-13 09:28:58 -07:00
Mathias Agopian 9b70dc5253 Fix linux/android DEBUG builds 2019-09-12 19:43:27 -07:00
Benjamin Doherty 31af9ca80f Automatically download iOS toolchain for Kokoro / GitHub 2019-09-12 17:41:33 -07:00
Benjamin Doherty 08aa2ec4ca Fix, iOS builds still need to work with Kokoro 2019-09-12 17:15:01 -07:00
Ben Doherty 95be2e24ce Fix iOS CI build (#1635) 2019-09-12 16:59:21 -07:00
Mathias Agopian 7b200ec85e make TextureUsage and TargetBufferFlags enum class
This prevents values like NONE or COLOR which are very generic
names to collide with other classic enums. It also forces us to be
specific about what we're doing when converting to bitfields.

Also added a utility to easily enable any enum or enum class to
support binary operation (i.e. Bitmask contract), e.g.:

template<> struct utils::EnableBitMaskOperators<Foo> : public std::true_type{};

gives all binary operators to 'Foo'. Foo must be an enum.

Also added any() and none() convenience to convert an enum to a boolean.
2019-09-12 11:19:54 -07:00
Mathias Agopian cf1b45c052 Make SamplerParam a C struct
This simplifies its usage at call sites at lot.

The C++ ctor was needed before to create uninitialized objects, which
was needed in SamplerGroup. Instead we use a custom 'static_vector' 
(instead of std::array), this actually makes SamplerGroup's
implementation clearer.

static_vector<> is just a fixed-capacity, fixed-storage dynamic
vector. we currently don't expose it and implement only what we
need.
2019-09-12 11:18:47 -07:00
Ben Doherty 57e7280ac9 Remove post-process uniform / sampler blocks (#1624) 2019-09-11 16:57:48 -07:00
prideout 64d432cb34 PostProcessManager: another Vulkan-related re-ordering.
My fault, I did not catch this while reviewing #1621.
2019-09-11 11:33:43 -07:00
Ben Doherty fde23c89e2 Use post-process material domain for FXAA (#1621) 2019-09-11 09:35:40 -07:00
Ben Doherty 0e3bc8a443 Only install iOS builds if requested (#1614) 2019-09-11 09:35:01 -07:00
Philip Rideout 88bcd133f2 filamat: add Backend-to-TargetApi utility. 2019-09-11 08:38:47 -07:00
Philip Rideout 2072b67e04 PostProcessManager: repair Vulkan by re-ordering commands.
The suzanne Vulkan demo was asserting because `setViewportScissor` can
only be called within a render pass, which means that
`MaterialInstance::use` can only be called within a render pass.

We probably need a better way to enforce these rules...
2019-09-11 08:38:19 -07:00
Philip Rideout 2a2974580c resgen: remove unused / incorrect constant. 2019-09-10 10:19:37 -07:00
Ben Doherty 65f72a48fb Terminate tonemapping material (#1619) 2019-09-10 10:15:15 -07:00
Philip Rideout 65674c7c51 filagui: disambiguate the resources header. 2019-09-10 09:08:34 -07:00
Philip Rideout 8d1b630b24 resgen: repair wasm builds. 2019-09-10 08:02:35 -07:00
Philip Rideout 1235a66f83 resgen: avoid overwriting the header if nothing changed. 2019-09-10 08:02:35 -07:00
Philip Rideout 411e7f4511 resgen: use extern int instead of #define. 2019-09-10 08:02:35 -07:00
Philip Rideout cf095cbdd2 filagui: use resgen for the UI material.
This makes building samples faster when combined with PR #1613.
2019-09-10 08:02:23 -07:00
Philip Rideout 394db90ec9 CMake: Use configure_file for licenses.inc
Every time ninja invoked CMake, we were unconditionally regenerating
all of our "licenses.inc" files which caused a ton of re-compiles.

Before the change, building after touching `ubershader.mat.in` took over
a minute, now it takes 20 seconds.

The CMake "file" commands are bad. The CMake documentation says:

    If the file is a build input, use the configure_file() command
    to update the file only when its content changes.
2019-09-10 08:02:12 -07:00
Philip Rideout 72644f1416 mipgen: add --quiet argument.
Note that some encodings like astc will still be noisy due to
third-party code but this works fine for the s3tc encoder.
2019-09-10 08:01:49 -07:00
Philip Rideout ed2fc0e391 matdbg: opt-in via environment variable. 2019-09-10 08:01:29 -07:00
Ben Doherty c9f4d983a0 Convert SSAO shaders to use post-process materials (#1610) 2019-09-09 16:41:49 -07:00
Philip Rideout 694db54d9d Minor cleanup. 2019-09-09 11:10:39 -07:00
Philip Rideout 15b663ba0b matdbg client: show inactive variants in gray.
This makes it easier to find the variants that are actually being used.
2019-09-09 11:04:02 -07:00
Philip Rideout 23ee5e276c matdbg server: add query for active programs.
This uses the program cache to determine the set of variants that
are actually being used.
2019-09-09 11:04:02 -07:00
Ben Doherty 7c24a1bbaa Add custom vertex shaders for post-process materials (#1606) 2019-09-09 09:17:35 -07:00
Ben Doherty 32eee2cdf1 Tungsten: upgrade Gradle, fix IBL (#1604) 2019-09-09 09:13:06 -07:00
Ben Doherty 7dbad8928f Ensure GitHub actions build presubmit (#1605) 2019-09-06 19:43:42 -07:00
Philip Rideout 0e81207758 WebGL: add demo for glTF animation.
Fixes #1583.
2019-09-06 16:44:03 -07:00
Philip Rideout c67266833a gltfio: rename getResourceUrl => getResourceUri 2019-09-06 16:43:53 -07:00
Philip Rideout d6b0b6ff52 gltfio: expose all resource URI strings.
Some buffers (like animation data) do not contain any vertex data
but web-based clients still need to know about this.

This interface is much simpler than the bindings lists, and in fact
we might remove the binding lists in the future to simplify the API.

Fixes #1593.
2019-09-06 16:43:53 -07:00
Ben Doherty 9d0ad3586d Update tonemapping to use new post-process material domain (#1428) 2019-09-06 15:04:52 -07:00
Philip Rideout 7393d5d98c WebGL: add LightManager getter methods to fix #1599. 2019-09-06 14:12:33 -07:00
Mathias Agopian 7a819a60ae RGB32F is never supported as a render target 2019-09-06 11:09:20 -07:00
Mathias Agopian c735659592 better handle float rendertargets. fixes #1533
some driver don't support all float buffers as rendertarget, so we
improve the backends (opengl in this PR) to return what it actually
supports and we update the client (filament) to take that into
account when making decisions.
2019-09-06 11:09:20 -07:00
Mathias Agopian c36745db97 simplify DriverAPI.inc macros a bit further
we now handle zero argument declaration in some cases.
2019-09-06 11:08:59 -07:00
Philip Rideout a5284af2b8 Use original glTF filename for FlightHelmet. 2019-09-06 10:47:47 -07:00
Philip Rideout 4989c3dc48 Remove unused material. 2019-09-06 10:47:47 -07:00
Philip Rideout 3925b0a8ec matdbg: Add detailed README describing the design. 2019-09-06 08:17:02 -07:00
Mathias Agopian 356610ba1d simplify DriverAPI.inc macros
by using variadic macros we can greatly simplify the macros
definitions for declaring the backend API.

in particular we don't need a macro per number-of-argument, this is
now done automatically.

Unfortunately, we still can't handle zero-argument declarations, so
we keep the _0 variants.
2019-09-05 15:07:25 -07:00
Philip Rideout 9eae72f99d matdbg: allow editing for GLSL shaders.
This performs surgical modification of the IFF chunks rather than
invoking filamat from within matdbg. Low-level direct manipulation
(bypassing optimization passes etc) allows us to diagnose issues with
the shading pipeline.

This CL also adds keystroke bindings to the Monaco editor. You can
press Cmd+S to rebuild the current materials, or use Ctrl+Arrow to
navigate between shader variants and materials.

In a subsequent CL I will add a README that describes how this works in
detail, it will include a list of limitations and a feature wishlist.
2019-09-05 13:03:49 -07:00
Philip Rideout 1d12fc1aaa Fix default IBL in lucy_bloom. 2019-09-04 13:35:34 -07:00
Philip Rideout f9bd085757 OpenGL: shader errors should not cause termination.
We now check for FILAMENT_ENABLE_MATDBG and simply skip the draw call
when the program is invalid. The initial error message is still dumped
to the console, but we will not terminate or dump an infinite cascade of
error messages.
2019-09-04 13:11:11 -07:00
Philip Rideout 1003926665 Engine: add support for material edits.
This only adds Engine-side support for edits. The debugger client will
be enhanced in another PR. This works by simply clearing the program
cache and swapping out the MaterialParser. Neat!

However, there are some gotchas:

- The DebugServer callback is triggered on another thread so to be safe
  we defer the swap until the subsequent call to getProgram().

- The getProgram() method is const but in reality it can insert entries
  into a mutable cache. This CL makes the constness of it even more
  misleading by applying edits.

- The edit operation will leak the old HwProgram but I feel this is
  fine because simplicity is crucial for injected behavior and this is
  a developer-only feature.
2019-09-04 13:10:44 -07:00
Mathias Agopian 709180932e use Builder.sample() instead Builder.read() for textures
Texture are special resources that can be read in different ways; either as
attachment (read) or sampled (sample), the user must now declare explicitly if she intends
to sample from a texture.

sample() implies read() so there is no need to call both.

This was already the case, as read() used to take a boolean, essentially meaning the same
thing. However, the bool didn't make sense for non-texture resources.

This also simplifies the implementation.
2019-09-04 11:40:59 -07:00
Mathias Agopian 132326f8f2 getDescriptor() needn't be const 2019-09-04 11:40:59 -07:00
Mathias Agopian 92e86de630 No need to specify the sample count for attachments
the framegraph will figure it out automatically from the 
rendertarget sample count. this is done during resolve(), and after
moveResource is taken into account (so this works with imported and
moved resources).
2019-09-04 11:40:59 -07:00
Mathias Agopian 3e8a145fce importRenderTarget() now returns a FrameGraphRenderTargerHandle
This makes the API more symetric/logical.
2019-09-04 11:40:59 -07:00
Mathias Agopian a5db6a84b6 add name to rendertarget creation 2019-09-04 11:40:59 -07:00
Mathias Agopian f192b89ef9 sample count for rendertargets doesn't need to be specified
when creating a rendertarget, if the sample count is not specified,
any existing target with the same attachment will match.
this simplifies both the user and implementation.

getRenderTargetDescriptor() now takes a RenderTargetHandle instead
of a texture handle.
2019-09-04 11:40:59 -07:00
Mathias Agopian 637395b075 declaring a rendertarget now returns a FrameGraphRenderTargetHandle
this makes managing render targets more excplicit and simplify the
code a lot. before, render targets were referenced through one of
their attachment.
2019-09-04 11:40:59 -07:00
Philip Rideout b03172f4a2 Java bindings: fix CUSTOM attribute mismatch.
Fix #1578
2019-09-03 15:49:22 -07:00
Romain Guy 24225315fa Add iOS presubmit (#1589)
* Add iOS presubmit

* Use a separate workflow for iOS
2019-09-03 11:56:32 -07:00
Romain Guy 2bc9256a7a Fix compilation error when DEBUG_COMMAND_STREAM is true (#1588)
Fixes issue #1585
2019-09-03 10:00:11 -07:00
Philip Rideout 264cf020b6 Minor TypeScript annotations fix. 2019-09-03 08:44:16 -07:00
Romain Guy ceafc7835b Rename CI workflow to Presubmit 2019-08-31 11:53:20 -07:00
Romain Guy db8d4ee076 Setup Linux for GitHub CI (#1581)
* Setup Linux for GitHub CI

* Pass env var properly
2019-08-30 15:24:29 -07:00
Romain Guy 26f7907b17 Fix punctuation (#1580) 2019-08-30 14:59:25 -07:00
Romain Guy c35f1e0b29 More fixes 2019-08-30 14:53:02 -07:00
Romain Guy e2ee00e36e Fix Linux CI on GitHub 2019-08-30 14:50:40 -07:00
Romain Guy d87f77c41a Don't set $TARGET 2019-08-30 14:45:03 -07:00
Romain Guy 13fcce2d9a Fix workflow 2019-08-30 14:44:47 -07:00
Romain Guy 216761656f Fix CI 2019-08-30 14:38:37 -07:00
Romain Guy 05e9d708ed Update build scripts for workflows 2019-08-30 14:29:44 -07:00
Romain Guy cc321385cd Run CI on Linux and macOS 2019-08-30 14:29:18 -07:00
Romain Guy 038d39f294 Fix path 2019-08-30 14:07:01 -07:00
Romain Guy 3555a01541 Support for workflows 2019-08-30 14:03:55 -07:00
Romain Guy 5d52266eac Add workflow 2019-08-30 14:03:37 -07:00
Romain Guy 5368756983 Remove workflow 2019-08-30 13:59:34 -07:00
Romain Guy f74e136f46 Add GitHub Action for CI duty 2019-08-30 12:02:39 -07:00
Romain Guy 040c1c686a Update build script to support GitHub Actions 2019-08-30 12:02:21 -07:00
Philip Rideout e74c33ce04 Java bindings now define CUSTOM / MORPH attribs.
Fixes #1578.
2019-08-29 17:13:28 -07:00
Philip Rideout ab24634637 Add matdbg to READMEs. 2019-08-29 10:19:18 -07:00
Philip Rideout 8f3bdc20ba matdbg: add "install" directive.
Fixes #1576.
2019-08-29 10:19:18 -07:00
Romain Guy 74aaaed4db Code cleanup 2019-08-29 09:34:12 -07:00
Philip Rideout 9c64c20ceb matdbg: fail gracefully, emit logs, fewer threads. 2019-08-29 09:13:20 -07:00
Mathias Agopian b92c748fcc Use allocator Debug policy in more places 2019-08-28 19:06:54 -07:00
Mathias Agopian 844dde4e6d simple allocation debugger
This can be enabled by using the Tracking::Debug policy,
currently this just fills allocation on alloc() and free(),
which is useful to help detect access to uninitialized memory
and use after free.

Now enabled by default in libfilament allocators on debug builds.

This caught uninitialized access in the froxelizer.
2019-08-28 19:06:54 -07:00
Philip Rideout c0de0ca36d gltfio: fix transforms for nodes with non-uniform scale.
I tested this with the problem model and a couple other models.

This bug is inherited from cgltf_node_transform_local, so I will
upstream the fix. There are two ways to see that the new math is
correct:

1) Look at decomposeMatrix and note that scales belong to rows,
   not columns.

2) Look at the Brandon Jones implementation:
   http://glmatrix.net/docs/mat4.js.html#line1079

Fixes #1519.
2019-08-28 15:31:33 -07:00
Mathias Agopian ad3bc4a6f7 ran "optimize imports" on all files
This removed a few unneeded imports.
2019-08-28 15:19:50 -07:00
Mathias Agopian 572b2cff57 fix use after free
We were storing pointer to RenderTarget objects that were allocated
in a vector<>, which obviously is not safe.
This didn't cause any issue most of the time because our allocator is
a linear allocator.
2019-08-28 15:19:26 -07:00
Philip Rideout fb9cf43768 WebGL: fix JPEG decoding.
We've been using STB for a while now and we already include a JPEG
decoder in our wasm bundle. This removes some vestigial code that was
getting in the way.

Fixes #1565.
2019-08-28 13:15:15 -07:00
Philip Rideout f41db8bb91 gltfio: add lazy loading to ubershader mode. 2019-08-28 13:01:05 -07:00
Philip Rideout 89c8e7c51a gltfio: support doubleSided in ubershader mode.
Fixes #1562
2019-08-28 13:01:05 -07:00
Jordan Rupprecht 0ad21cd47a Avoid undefined behavior when doing pointer calculation.
Performing `base + offset` pointer arithmetic is only allowed when `base` itself is not nullptr. In other words, the compiler is assumed to allow that `base + offset` is always non-null, which an upcoming compiler release will do in this case. The result is that CommandStream.cpp, which calls this in a loop until the result is nullptr, will never terminate (until it runs junk data and crashes).

Avoid this by using intptr_t instead of actual pointers (i.e. char*), which seems to avoid this failure.
2019-08-28 12:13:09 -07:00
Mathias Agopian 7dbf81fe3d FrameGraphPassResources should use typed FrameGraphId<> 2019-08-28 11:43:27 -07:00
Mathias Agopian 3072309574 rename FrameGraphResource to FrameGraphHandle
also FrameFrapheResourceId to FrameGraphId.
2019-08-28 11:43:27 -07:00
Mathias Agopian 573e9220a2 Improve import API and code 2019-08-28 11:43:27 -07:00
Mathias Agopian e22f02d228 public APIs only use FrameGraphResourceId<> 2019-08-28 11:43:27 -07:00
Mathias Agopian b620b7efa1 major framegraph overhaul 2019-08-28 11:43:27 -07:00
Philip Rideout d1593326cb gltfio: support spec-gloss in ubershader mode.
Fixes #1564.
2019-08-28 10:56:56 -07:00
Romain Guy 6a8e6d45b5 Improve materials under white furnace test (#1563)
* Improve materials under white furnace test

Two major changes:
- Mobile target now implements a cheaper variant of the off specular
  peak bias (which moves the reflected vector towards the normal).
  This greatly helps with rough surfaces that may otherwise point
  toward a bright part of the IBL.
- The indirect diffuse love is now properly attenuated to avoid adding
  the energy reflected by the specular layer. This allows dielectrics
  to be correctly energy conserving under a white furnace.
- Tweak the (hacky) clear coat layer attenuation to behave properly
  under a white furnace.

* Use the same reflected vector modification everywhere
2019-08-28 10:39:57 -07:00
Ben Doherty 11336964a1 Add startCapture and stopCapture debug driver methods (#1560) 2019-08-28 10:34:46 -07:00
Mathias Agopian 71e98d54f5 add missing includes 2019-08-27 18:03:45 -07:00
Mathias Agopian 417ba87fcb don't use hard-coded values for Builder::radiance()
Instead we use constexpr expressions of the values,
which makes it much easier to remember where they
come from.
2019-08-26 17:47:28 -07:00
prideout f71fea4ef5 Update release notes. 2019-08-26 14:16:07 -07:00
prideout dc062305b9 Bump to 1.3.2 2019-08-26 14:07:14 -07:00
Philip Rideout bc94269e73 matdbg: fix a warning when building civetweb. 2019-08-26 12:37:38 -07:00
Philip Rideout 876534330a matdbg: add more info to the details panel. 2019-08-23 16:43:16 -07:00
Philip Rideout 2af8ef81b3 matdbg: add required attributes. 2019-08-23 16:43:16 -07:00
Philip Rideout 8da553db58 matdbg: fix active shader highlight. 2019-08-23 16:43:16 -07:00
Philip Rideout 83e9857b30 matdbg: remove bogus hrefs from anchors. 2019-08-23 16:43:16 -07:00
Philip Rideout 088ed2d472 matdbg: make mat list and shader list scrollable. 2019-08-23 16:43:16 -07:00
Ben Doherty c826b03411 Break driver dependency on Texture.h (#1549) 2019-08-23 16:13:24 -07:00
Benjamin Doherty f1257994d1 Disable DirIncluder tests 2019-08-23 13:31:20 -07:00
Benjamin Doherty efb9e005b2 Fix build due to DirIncluder test 2019-08-23 12:40:47 -07:00
Romain Guy 6f30ff31c8 Fix warnings 2019-08-23 11:55:06 -07:00
Romain Guy d0f38c2d5d Update Gradle, AGP and Kotlin 2019-08-23 11:52:30 -07:00
Ben Doherty d4943cc70b Add #include preprocessing to filamat and matc (#1541)
* Add #include preprocessing to filamat and matc

* Update RELEASE_NOTES

* Fix RELEASE_NOTES

* Use final instead of virtual / override

* Clarify comments

* Use pure virtual for includer functions

* Use a callback instead of an interface

* Rename Includer.h to IncludeCallback.h

* Update comment
2019-08-23 11:10:36 -07:00
Ben Doherty 9a47ea1ef0 Fix Tungsten build (#1548) 2019-08-23 11:08:27 -07:00
Romain Guy ac33331fd6 Update documentation to fix typos 2019-08-23 10:58:08 -07:00
Philip Rideout a65998bbc1 Fix Linux build, hopefully. 2019-08-23 10:16:22 -07:00
Philip Rideout 5120c18977 Update third_party/cgltf to latest. 2019-08-23 09:50:08 -07:00
Philip Rideout 21347eaa88 Fix build break, re-enable DebugServer. 2019-08-23 09:49:57 -07:00
Philip Rideout a191cc8171 Fix build break. 2019-08-22 17:07:34 -07:00
Philip Rideout ad3d823fa3 matdbg: Use Variant enum. 2019-08-22 16:12:20 -07:00
Philip Rideout 8d7c00b0d9 matdbg: add DebugServer class.
matdbg is now linked into the Filament Engine in debug config (allowing
live inspection of GLSL / SPIRV) and into the matinfo tool (to support
the --web-server option).

In both cases, the library spins up a small web server that listens to
http://localhost:8080. You can run any Filament app and attach to it.

The web client caches all material information. This allows the user to
close an atttached Filament app, and the web app will continue to
function properly (useful for crash diagnosis). Moreover the user can
launch a second Filament app and the web client will add its materials
to the existing list (useful when comparing two Filament apps).

For now this only supports inspection, not editing. Some of the material
info such as required attributes is not yet displayed but this will be
easy to flesh out in a subsequent PR.
2019-08-22 16:12:20 -07:00
Ben Doherty 99d9ea73ac Fix potential Metal memory leak (#1542) 2019-08-22 14:15:39 -07:00
Philip Rideout c4b0edbfe3 Introduce matdbg library, simplify matinfo.
This moves some of the matinfo functionality into a library which will
soon have an embedded web server.
2019-08-22 08:11:06 -07:00
Philip Rideout 6d74d31ecd Add civetweb to third_party (MIT).
This is a dependency of our upcoming web-based material debugger. This
CL also includes `tnt/CMakeLists.txt`, which builds a static lib in a
minimal configuration that enables WebSocket support. The entire library
is built from only 4 files:

    ${PUBLIC_HDR_DIR}/CivetServer.h
    ${PUBLIC_HDR_DIR}/civetweb.h
    ${SRC_DIR}/civetweb.c
    ${SRC_DIR}/CivetServer.cpp
2019-08-21 17:45:37 -07:00
Ben Doherty bd22bed2fb Fix Windows test cases (#1537) 2019-08-20 15:36:22 -07:00
Ben Doherty f8aa17c245 Preallocate uniform buffers in Metal (#1528)
* Preallocate uniform buffers in Metal

* Allocate empty uniform at draw time

* Remove unnecessary return
2019-08-19 15:37:13 -07:00
Ben Doherty 6ba20f29d4 Fix normal mapping with skinning or morphing in Metal (#1530) 2019-08-16 17:24:01 -07:00
Philip Rideout 95ef8d85db Minor fixup to suzanne Vulkan demo. 2019-08-16 17:04:32 -07:00
Mathias Agopian eca381a5be Rename fg::Resource to fg::TextureResource 2019-08-15 16:58:58 -07:00
Mathias Agopian ea47f0bd87 simplify how we determine if a resource is sample-able 2019-08-15 16:58:58 -07:00
Mathias Agopian b849008ce5 rename useRenderTarget to createRenderTarget 2019-08-15 16:58:58 -07:00
Mathias Agopian 5389ac963f framegraph: useRenderTarget() doesn't set access anymore
access to resources now needs to be done explicitly before calling
useRenderTarget(). This simplifies things and is needed for more
simplifications to come.
2019-08-15 16:58:58 -07:00
Mathias Agopian 0fd16d760a refactor/cleanup of FrameGraph code
this change mostly puts all internal classes into their own file,
making FrameGraph.cpp much smaller and easier to deal with
2019-08-15 16:58:58 -07:00
Philip Rideout 6754e80c75 gltfio: Minor cleanup. 2019-08-15 14:29:07 -07:00
Benjamin Doherty fb95d8e7a4 debug 2019-08-14 18:13:57 -07:00
Benjamin Doherty 40efd5fd23 More debug 2019-08-14 18:13:57 -07:00
Benjamin Doherty d440775775 debug 2019-08-14 18:13:57 -07:00
Benjamin Doherty e1d9f26dbd Try keyserver 2019-08-14 18:13:57 -07:00
Benjamin Doherty ee048d259f Try to fix broken Linux and Android CI 2019-08-14 18:13:57 -07:00
Philip Rideout d7e5f2c26b Web: remove more &free callbacks.
It is not safe to take the address of a stdlib function with emscripten,
this causes an intermittent crash in the WebGL backend.
2019-08-14 15:14:49 -07:00
Philip Rideout c11a61aa15 Web: add setBoolParameter, fixes #1499. 2019-08-14 13:05:17 -07:00
Philip Rideout b859b57797 matc, matinfo et al: improve diagnostic output
This enhances the exisiting matc option "--debug" so that it includes
debug information in the resulting SPIR-V.

Previously we tied this to the build configuration which isn't very
flexible. Moreover this needs to be orthogonal to shader opts, because
we often need to debug problems that arise from optimization.

This CL also gives meaningful names to the ubershader materials and
fixes up the new matinfo analysis so that it prints the entire SPIRV
chunk that corresponds to each potentially problematic GLSL codeline.

Motivated by #1516.
2019-08-14 13:01:43 -07:00
Mathias Agopian 76cca21c65 most StructureOfArray<> methods cannot be constexpr
This is because we can't create a constexpr SoA in the first place,
and it wouldn't be very useful if we could.

This change ripples into users of SoA.
2019-08-13 18:29:15 -07:00
Philip Rideout a09c3b154a Fix paths in android glTF demo. 2019-08-13 12:47:08 -07:00
Philip Rideout 2460f9e721 Better Adreno workaround for #1096.
This is an improved workaround for a known limitation with Vulkan
drivers on Android P. The offending SPIR-V sequence was introduced
during shader optimization and can be avoided by using full precision
for certain variables.
2019-08-13 11:36:59 -07:00
Mathias Agopian d30429e891 make getNativeObject() public
this allows mixed java/native apps to use filament objects on both
sides more easily
2019-08-12 21:56:49 -07:00
Ben Doherty c23c3d48b2 Remove unusued function (#1508) 2019-08-12 15:17:05 -07:00
Philip Rideout 046809cee0 Use --quiet when invoking cmgen in build. 2019-08-12 14:59:46 -07:00
Philip Rideout c9750dd633 Fix gradle bug that created junk folder. 2019-08-12 13:41:52 -07:00
Philip Rideout 18a0bd70fb Restore accidental removal of Adreno workaround. 2019-08-12 11:42:16 -07:00
Philip Rideout 38955a91e5 matinfo: fix ordering of analyze-spirv output. 2019-08-12 11:40:36 -07:00
Mathias Agopian eac2ad7e05 fix some lint warnings in Hash.h 2019-08-12 11:09:24 -07:00
Philip Rideout 5df53f733e Add error message to matinfo. 2019-08-12 10:45:44 -07:00
Romain Guy 50abcf6bfa Don't check for NDK side-by-side if ndk bundle is found 2019-08-12 10:22:06 -07:00
Philip Rideout 4d41b83448 Minor fixups in TypeScript annotations. 2019-08-12 09:13:46 -07:00
Philip Rideout d2324d253c filamat: when building debug, use verbose SPIR-V. 2019-08-12 09:12:59 -07:00
Philip Rideout cf9e87a892 matinfo: add SPIR-V analysis functionality
This adds a new option to matinfo that does some very dumb regex-based
analysis on the disassembled SPIR-V, then dumps out transpiled GLSL
that has annotations added to the end of some codelines. For example:

```glsl
float luminance(vec3 linear) // POTENTIAL MIXED PRECISION %49 = OpDot %float %linear %48; relaxed = %49 %linear
{
    return dot(linear, vec3(0.2125999927520751953125, 0.715200006961822509765625, 0.072200000286102294921875));
}
```

The code currently tries to find potential mixed precision but does not
do the right thing yet for pointers and structs. This is just a starting
point to help diagnose problem areas in our generated SPIR-V.
2019-08-12 09:12:59 -07:00
Romain Guy 829db244f2 Add support for side-by-side NDK (#1505) 2019-08-11 17:36:49 -07:00
Gregory Popovitch 772af1e897 More fixes for building with vs2019/msvc (#1500)
* Update Froxelizer.h

Fix this error when building with msvc from vs2019
error C2926:  'filament::details::Froxelizer::FroxelEntry::<unnamed-tag>::offset': a default member initializer is not allowed for a member of an anonymous struct within a union

* Fix some compilation issues with vs2019/msvc

Program.cpp:
1>C:\greg\github\filament\filament\backend\src\Program.cpp(28,42): error C2610:  'filament::backend::Program::Program(void) noexcept': is not a special member function or comparison operator which can be defaulted
1>C:\greg\github\filament\filament\backend\src\Program.cpp(28,42): message :  exception specification does not match the implicitly declared specification.

GLUtils.h: __PRETTY_FUNCTION__ macro is clang specific. Use MSVC equivalent

Color.h: fix warning

* #1493 - inline constructor in definition as requested by @romainguy

* #1493  "move this #define inside the #else below" as requested

* #1493 revert last change which causes compilation failures on other platforms.

provide empty implementation of Program::Program() in Program.cpp

* More fixes for building with vs2019/msvc

* #1500 use consistent macro definition syntax (@bejado)

* #1500 simplify DEBUG_COMMAND macro as requested by @pixelflinger

* #1500 use `{ 0 }` which is accepted by Visual Studio  (` = 0 ` is not accepted)

* #1500 remove incorrect UTILS_RESTRICT alltogether
2019-08-09 16:38:31 -07:00
Romain Guy 52a8f50539 Fix backface issue in lit-cube sample 2019-08-09 16:10:12 -07:00
Mathias Agopian 9f1cadf77a remplace multimap by a vector for the framegraph texture cache
because we don't expect many items in the cache, using a linear
search is not a problem -- multimap generates tons of code 
by comparison.
2019-08-09 15:36:40 -07:00
Mathias Agopian 308935d706 fix framegraph test 2019-08-09 15:36:40 -07:00
Mathias Agopian 67f75f0ecf reformatting 2019-08-09 15:07:12 -07:00
Mathias Agopian f728776714 better normal transforms
We use the cofactors to transform normals, which preserves its
direction, unlike of the inverse-transpose method.
2019-08-09 15:07:12 -07:00
Mathias Agopian 10259f80f4 Add support for det() and cof()
Respectively computing the determinant and cofactors of a matrix.
2019-08-09 15:07:12 -07:00
Mathias Agopian c65239aec2 Implement a basic Texture cache for the framegraph
We're only caching textures (not render targets yet), and we're
evicting cache entries older than 30 allocations.

This should cut down on texture allocation / gl calls.

The cache should get in a stable state very quickly (less than half
second).
2019-08-09 15:01:04 -07:00
Philip Rideout 0bd9515b3d Add getWorldOffset() shader API, enhance docs.
This allows advanced shader authors like myself to get coordinates
in the API level world space.

Fixes #1485.
2019-08-09 08:28:28 -07:00
Ben Doherty 442315aaa8 Silence Metal shader compilation warnings (#1496) 2019-08-08 18:07:01 -07:00
Gregory Popovitch 614a7d6de8 Fix some compilation issues with vs2019/msvc (#1493)
* Update Froxelizer.h

Fix this error when building with msvc from vs2019
error C2926:  'filament::details::Froxelizer::FroxelEntry::<unnamed-tag>::offset': a default member initializer is not allowed for a member of an anonymous struct within a union

* Fix some compilation issues with vs2019/msvc

Program.cpp:
1>C:\greg\github\filament\filament\backend\src\Program.cpp(28,42): error C2610:  'filament::backend::Program::Program(void) noexcept': is not a special member function or comparison operator which can be defaulted
1>C:\greg\github\filament\filament\backend\src\Program.cpp(28,42): message :  exception specification does not match the implicitly declared specification.

GLUtils.h: __PRETTY_FUNCTION__ macro is clang specific. Use MSVC equivalent

Color.h: fix warning

* #1493 - inline constructor in definition as requested by @romainguy

* #1493  "move this #define inside the #else below" as requested

* #1493 revert last change which causes compilation failures on other platforms.

provide empty implementation of Program::Program() in Program.cpp
2019-08-08 17:03:26 -07:00
Philip Rideout d28189c173 Repaired broken npm package. 2019-08-08 13:27:52 -07:00
Ben Doherty dc75c10014 Update Xcode projects for KTX build step (#1495) 2019-08-08 11:39:13 -07:00
Philip Rideout 91ff1d87eb Replace prebuilt KTX with a build step.
This removes the samples/envs folder and replaces these KTX files with a
build step that is driven by CMake / gradle / bash, depending on
platform.

This makes it easier to use IBL files that are generated by the latest
and greatest version of cmake.
2019-08-08 10:41:13 -07:00
Ben Doherty 6b415273ba Add isTextureFormatMipmappable driver query (#1491) 2019-08-08 09:54:03 -07:00
Philip Rideout 4ce2a03f64 Update release notes before v1.3.1 2019-08-08 09:44:19 -07:00
Philip Rideout f67a71d849 Fix web build, third attempt. 2019-08-08 09:22:05 -07:00
Gregory Popovitch 55d8d93be9 Update Froxelizer.h (#1489)
Fix this error when building with msvc from vs2019
error C2926:  'filament::details::Froxelizer::FroxelEntry::<unnamed-tag>::offset': a default member initializer is not allowed for a member of an anonymous struct within a union
2019-08-07 17:44:39 -07:00
Romain Guy 5d57dee18d Add API to enable/disable shadows on a light (#1492) 2019-08-07 17:39:33 -07:00
Philip Rideout 1d1a0c16ba Quick fix for web build, second attempt. 2019-08-07 16:11:40 -07:00
Philip Rideout 71e2434717 Fix web builds on Kokoro. 2019-08-07 15:11:00 -07:00
Benjamin Doherty f876e6165f Assert that Metal textures are created 2019-08-07 09:51:50 -07:00
Benjamin Doherty 54e224e9fa Label Metal command queue 2019-08-07 09:51:50 -07:00
Philip Rideout 8e76259bac Fix web builds on Kokoro. 2019-08-07 07:40:19 -07:00
Mathias Agopian 13224d9c6e laying the foundations for a rendertarget cache
Some drivers have performance issues when repeatedly (once per frame)
allocating and destroying render targets, so we will
re-introduce a cache for that.

this just adds the hooks for the cache.
2019-08-06 18:17:08 -07:00
Philip Rideout 34ef2a871f Stop using compressed IBL's in more places.
We use R11F_G11F_B10F for HDR so we should stop checking for compressed
IBL files.

Also, make the glTF sample on web more consistent with the default
settings used by gltf_viewer on native and use venetian_crossroads
instead of syferfontein.
2019-08-06 16:18:51 -07:00
Philip Rideout 6f143b1b54 Fix wasm by avoiding the "&free" trick.
We should not use the address of a stdlib function for BufferDescriptor
callbacks. With emcc this compiles without warnings or errors, but
produces incorrect code that causes intermittent out-of-memory errors at
run time.
2019-08-06 15:03:48 -07:00
Philip Rideout 46e85804b1 Disable jsdocs to fix Kokoro. 2019-08-06 13:28:49 -07:00
Philip Rideout 0fe8035309 gltfio: allow names to be queried.
Fixes #1425.
2019-08-06 12:54:29 -07:00
Philip Rideout b3feafe320 Enable shadows in helmet demo. 2019-08-06 11:28:00 -07:00
Philip Rideout ec623e7c1b Add IndirectLight queries to JavaScript / TypeScript. 2019-08-06 09:14:28 -07:00
Mathias Agopian a38f2754ce Add children iterators to TransformManager (C++ only) 2019-08-04 23:16:54 -07:00
Mathias Agopian 932d2746f3 fix typo 2019-08-04 23:16:34 -07:00
Mathias Agopian e176dea383 Add API to extract the color/intensity of the IBL dominant light 2019-08-04 23:16:34 -07:00
Hendrik Wagenaar 8f15964ee6 Use GL_EXTENSION for GL_OES_EGL_image_external_essl3 (#1471)
* Use GL_EXTENSION for GL_OES_EGL_image_external_essl3

A prior change that reworked some code incorrectly attempted to
use the existing EGL extensions to set a GL extension boolean.

Added additional GL extension code.

* Fix typo

* Fix typo
2019-08-01 17:17:36 -07:00
Romain Guy 53a12c3f01 Add flower_road envmap with the sun removed 2019-08-01 16:37:06 -07:00
Romain Guy 2c953b9f08 Add the sun instead of blending it (#1470) 2019-08-01 15:19:18 -07:00
Mathias Agopian b1cdd5452f API to query the direction of the IBL
Initialized the directional light direction to the
IBL direction in material_sandbox and gltf_viewer.
2019-08-01 12:49:40 -07:00
Hendrik Wagenaar cb66324095 OpenGL: Avoid unresolves on render pass (#1469)
Avoid enabling scissors when the viewport is the same size as the
buffer. On Adreno devices, running clearWithGeometryPipe adds
three additional unresolves for each bin.
2019-08-01 10:26:27 -07:00
prideout b16dc443ff Do not bind materials outside of a render pass. (affects GL) 2019-07-31 16:35:55 -07:00
Mathias Agopian 8798d367c5 fix some doxygen comments 2019-07-31 15:47:30 -07:00
prideout c9921cac3d Vulkan: fix issue with mipmapped render targets.
VkFramebuffer requires its attachments to have only one miplevel each,
but our VulkanRenderTarget wrapper was sharing the VkImageView that
associated with the underlying texture object.

This fixes up VulkanRenderTarget so that it owns a unique VkImageView
that is pinned to a specific miplevel.
2019-07-31 15:18:04 -07:00
prideout 485711f7c6 gltfio now uses FADE when the asset is BLEND.
Fixes #1461
2019-07-31 12:36:11 -07:00
prideout 81df9dd705 Desktop samples should not link Embree.
We now build three gltfio libraries:

 - gltfio_core ....... lightweight library with ubershaders
 - gltfio ............ uses filamat to generate materials at runtime
 - gltfio_pipeline ... depends on path tracer functionality
2019-07-31 12:05:22 -07:00
@roxlu ☾ 0faa391470 Copy GLXFBConfig from shared context. (#1456)
* Copy GLXFBConfig from shared context.

* Style fixes
2019-07-31 09:30:45 -07:00
prideout cd59d6cd23 Fix VulkanDriver query for the DEPTH24 format.
This fixes one of the bugs seen with `gltf-bloom` on Android.

We already dynamically map Filament's DEPTH24 format to either
VK_FORMAT_D32_SFLOAT or VK_FORMAT_X8_D24_UNORM_PACK32, depending on
the platform. Therefore we should return `true` when asked if the
backend supports DEPTH24. Otherwise the client will not be able to
create a depth texture.
2019-07-30 14:32:37 -07:00
prideout d46ba48293 Build tweaks for Android.
(1) Sometimes (but not always!) gltfio-android was failing to build due
to two missing ANativeWindow functions. Linking in "android" seems to
fix this, and is consistent with libfilament-jni.

(2) Improve our "build.sh -c" utility by clobbering some additional
Android build directories. This is especially useful after
adding "-Pextra_cmake_args=-DFILAMENT_SUPPORTS_VULKAN=ON", otherwise
Gradle will try to use a cached CMake configuration.
2019-07-30 10:53:17 -07:00
Romain Guy 7d84f97dc1 Add function to compute the Fresnel Lazanyi term 2019-07-30 10:38:42 -07:00
Philip Rideout 3263c46355 Add morphing support to gltfio.
Issue #1149, #1417
2019-07-30 10:20:50 -07:00
prideout 44c7d3ac34 Add workaround for Adreno Vulkan shader bug.
Fixes #1096.
2019-07-30 10:20:21 -07:00
prideout 7dad09dbc4 Fix VulkanRenderTarget attachment ref counts.
By design, VulkanRenderTarget has weak references to its attachments and
does not manage any hardware resources. Therefore, when we start
rendering to a particular render target, we need to inform
VulkanDisposer that the command buffer has acquired a reference to the
underlying textures. This prevents the possibility of the texture being
destroyed while still in use.

This fixes #1450 although we should also add a render target pool for
best performance.
2019-07-29 14:39:57 -07:00
prideout 401bc4b486 Fix warning. 2019-07-29 11:10:21 -07:00
Philip Rideout 2b1f9290a4 Fix skinning regression (uninitialized bytes in UBO).
Fix #1440.
2019-07-29 13:37:46 -04:00
Philip Rideout 90c17ccbad Filament now supports GPU vertex morphing.
This works by aliasing CUSTOM0 - CUSTOM7 to morphing attributes, and by
extending our existing skinning variant.

This PR was tested against some upcoming changes to gltfio.

Issue #1149, #1417
2019-07-26 17:53:46 -04:00
Ben Doherty f8f947addb Handle missing vertex attributes in Metal backend (#1442) 2019-07-26 14:44:34 -07:00
Romain Guy 85449a08fb Give specular-color the ability to compute f82 (or other angles) (#1443) 2019-07-26 08:56:24 -10:00
Ben Doherty 115ce0cb42 Delete empty file 2019-07-25 17:56:56 -07:00
Romain Guy edc2b49196 Add Mathematica notebook for an improved Fresnel term 2019-07-25 16:28:31 -07:00
Ben Doherty a47b5c21cf Update SPIRV-Cross (#1439) 2019-07-24 16:26:24 -07:00
Ben Doherty ada148b819 Add OpenGL scheme to hello-ar (#1437) 2019-07-24 15:49:31 -07:00
Romain Guy 5d5d9af4df Remove trailing semi-colon 2019-07-23 21:20:56 -07:00
Mathias Agopian 064441732e Add support for RGBA buffer formats in Texture::generatePrefilterMipmap 2019-07-23 16:01:57 -07:00
Romain Guy 7b80b31365 Remove unused parameter 2019-07-23 10:04:18 -07:00
Ben Doherty b439ddc5f4 Implement external images for iOS / OpenGL (#1391) 2019-07-23 09:52:24 -07:00
Ben Doherty 5b9351354a Ensure structs used as Metal state keys have no compiler-generated padding (#1433) 2019-07-23 09:49:00 -07:00
Pixelflinger 9bcf10cf44 fix thread count initialization
if hw thread count was 1, we'd end-up with 32 threads
2019-07-22 13:01:53 -07:00
Ben Doherty ff72598b7d Update Material class to handle both surface and post-process materials (#1410) 2019-07-19 12:24:18 -07:00
Pixelflinger 79aeaf3250 added an option to turn of pre-filtering in cmgen
When processing very high dynamic range environments, the importance
sampling code falls appart, it becomes a user choice to decide if
prefilter importance sampling is better or worse than just regular
importance sampling -- both are usually bad.

--ibl-no-prefilter gives the user this choice.
2019-07-19 10:57:48 -07:00
Pixelflinger 261dafa924 Fix a possible infinite loop
In the case where we have 2 cores, we would spawn only one thread in
the thread pool. If that thread got to try to steal() from another
thread before the main thread was adopted, it would end-up always
trying to steal from itself and enter an infinite loop.

This seems to happen during windows builds.
2019-07-19 10:56:41 -07:00
Philip Rideout 90792e7032 Fix upper limit on vertex attributes.
This combines two constants into one, and changes it into a value that
is actually correct.  :)

Technically the movement of the CUSTOM attributes will change the layout
qualifier and therefore merits a materials version bump, however custom
attributes were only recently introduced so this seems unnecessary.

Did some quick testing with 3 samples: gltf_viewer, lucy_bloom, and
point_sprites.
2019-07-18 17:10:16 -07:00
Mathias Agopian 6e375b1bba Automatic SH windowing
Clamping is now disabled by default in cmgen, there is a new option
to enable it "--clamp". 

Automatic SH windowing is also enabled by default and can be controled
with the "--sh-window" option. Accepted parameters are "no" to disable
windowing, "auto" for automatic windowing or a number to specify the
cutoff band.

auto windowing only works for 1, 2, and 3 bands.
2019-07-18 17:04:14 -07:00
Mathias Agopian 4d7ab6547c cmgen: tonemap images instead of clamping
Currently we're arbitrarily clamping environments to 16384 because both
the pre-filtering and SH algorithms can't handle very larger dynamic 
ranges.  Instead of clamping, we now tonemap, which is a little bit better.
2019-07-18 17:04:14 -07:00
Mathias Agopian 58b7084c8b make libmath much more constexpr friendly
It turns out that most of libmath couldn't be used in constexpr
expression due to our use of union{}. The C++ standard requires that
all accesses to a union{} in a constexpr expression be the same
element.

Also because libm and cmath are not constexpr some functions such
as length() or normalize() can't be constexpr. The same is true for
anything needing things like sqrt, cos, sin, ceil, floor.

This change mainly does the following:
- replace all accesses to vector elements by operator[]
  (this ensure all of libmath uses the same union element)

- avoid use of std::min / std::max / std::abs

- avoid uninitialized variables, which can't be constexpr

- remove 'constexpr' keyword on functions that can never be

It is now possible to write things like:

    constexpr mat4f I = inverse(
            transpose(mat4f::translation(float3{ 1, 2, 3 }) 
                 * mat4f::scaling(4)));
2019-07-18 16:48:37 -07:00
Philip Rideout d313fe13fb Add deps to gltfio-android when Vulkan is enabled.
Note that these are SHARED rather than STATIC dependencies.

Issue #1414.
2019-07-17 12:57:55 -07:00
Ben Doherty 4d41c9bde3 Update MaterialBuilder to handle post-process materials correctly (#1408) 2019-07-15 10:56:00 -07:00
Philip Rideout 6c4157767f Restore shadows to helmet web demo. 2019-07-15 09:43:01 -07:00
Ben Doherty 5cceda4155 Pass material domain, variant to ShaderGenerator (#1402) 2019-07-12 13:20:00 -07:00
Philip Rideout 8f45f4ec35 gltfio: Fix skinning offset.
Thanks @iamjinge for the fix.

Fixes #1405.
2019-07-12 09:34:52 -07:00
Mathias Agopian f3e5b46bf9 highlight negative values in SH debug files 2019-07-11 22:45:49 -07:00
Mathias Agopian 497c544f33 fix sh generation when -d is used
When -d was used, the radiance and irradiance ended-up being
swapped in the final file.

Also rename g_coefficients to g_sh_coefficients.
2019-07-11 22:45:49 -07:00
Mathias Agopian 2e4a825fec clamp correctly when converting to RGB_11_11_10
This avoids artifacts with unclipped HDR environments.
2019-07-11 22:45:49 -07:00
Philip Rideout 244c83a77c gltfio JavaScript: add basePath argument to loadResources.
Fixes #1392
2019-07-11 17:52:02 -07:00
Philip Rideout 41e5bb4f78 Add demo for point sprites and custom attribs. 2019-07-11 14:59:16 -07:00
Philip Rideout 2265eca82d Update cgltf. 2019-07-11 14:52:48 -07:00
Ben Doherty 82c7e4d988 Add new post-process functions (#1400) 2019-07-11 14:06:26 -07:00
Philip Rideout 793198f96a Expose setSampleCount to JavaScript. 2019-07-11 12:18:32 -07:00
Philip Rideout f139589423 Update WebGL demos and docs on site. 2019-07-11 12:04:43 -07:00
Mathias Agopian f929b6cee7 New experimental filtering options to cmgen
--sh-window=band, -w band : this low-pass-filters the environment
such that bands above 'band' are zero. This can be used to reduce ringing
when the source environment has high frequencies

--noclamp : turns off clamping before processing the cube map


This is still work in progress.
2019-07-11 11:55:59 -07:00
Pixelflinger 4d6f8c281a fix IndirectLight::radiance()
The conversion factors from radiance to irradiance where wrong.

The bug above was found while refactoring the code to be clearer. Now
the method that computes the coefficients for the shader calls the
regular SH code and applies all the appropriate factors on that.

With this change the options "--sh-shader" and "-sh=3 -i" won't
produce the same result because --sh-shader includes the lambertian
diffuse. "--sh" now always produces actual SH coefficients.
2019-07-11 11:52:33 -07:00
Ben Doherty 943af435aa Handle GL_PROGRAM_POINT_SIZE correctly (#1396) 2019-07-11 10:51:50 -07:00
Ben Doherty f028af3186 Don't build all variants for Windows CI (#1394) 2019-07-11 10:49:51 -07:00
Ben Doherty b15abe9e5e Rename post-process generator functions (#1395) 2019-07-11 10:44:46 -07:00
Philip Rideout 5281f2a511 Enumerate all 8 custom vertex attribs. 2019-07-11 09:00:10 -07:00
Philip Rideout c2c546d671 Add support for custom vertex attributes.
This is a prep step for the upcoming morph feature and does not require
a bump to our material version number.

Stay tuned for a new sample app that demonstrates this feature.
2019-07-11 09:00:10 -07:00
Ben Doherty 6fc10c1dda Fix matc bug when compiling for multiple APIs (#1393) 2019-07-10 17:06:28 -07:00
Ben Doherty 80f3afaac6 Manually define PI to fix MSVC issue (#1388) 2019-07-10 16:23:26 -07:00
Ben Doherty 725c978545 Remove yOffset uniform (#1382) 2019-07-10 15:30:00 -07:00
Philip Rideout a9091570b7 OpenGL driver: allow point sprites on desktop.
I noticed that point sprites were working on mobile and web but not
desktop.  This is why.  :)
2019-07-10 12:39:01 -07:00
Philip Rideout 4e8dac2680 Re-enable shadows in helmet demo. 2019-07-10 09:13:03 -07:00
Ben Doherty da81e857a0 Correct spherical harmonics comments (#1375) 2019-07-09 16:16:30 -07:00
Mathias Agopian 111b3320c0 make sure we never execute a job smaller than requested 2019-07-09 16:12:15 -07:00
Mathias Agopian 665703dbd8 parallel_for now creates jobs in reverse order
this is because the JobSystem's queue works as a LIFO, by creating
jobs in reverse (memory) order, we attempt to help streaming to
the d-cache on that threads -- until the point where
jobs are stolen. 

we also execute the last job immediately instead of creating a job
for it -- since we're already in a job.
2019-07-09 16:12:15 -07:00
Pixelflinger 8170ca7cd1 improve JobSystem::parallel_for + minor optimizations
- parallel_for doesn't use recursion anymore to create the "leaf"
jobs, this is now done linearly on N thread (one thread per CPU).
This uses less stack space, and reduces miss-predicted branches.

- remove almost all SYSTRACE calls because they have a huge impact
on things like parallel_for() and are misleading. They can be
enabled again by setting HEAVY_SYSTRACE to true.
2019-07-09 16:12:15 -07:00
Mathias Agopian 2df639133b improvements to JobSystem
- we simplify the waiting code by using only a single
condition variable instead of two.

- wait() now behaves just like a looper, it will process jobs until
the one it's waiting for finishes -- before it could just sit there
(the idea was that the job would finish quickly, but that's not always
the case).

- we also make sure to never call notify_n() when it's not needed.
We track how many waiters we have and use that to decide if we need
to notify().

notify is pretty slow on all architectures, even on linux it's always
a syscall, so it's better to avoid it.

- don't use stand-alone fences, makes things ugly for no real benefit

- refactored the code a bit, hopefully it's more clear.
2019-07-09 16:12:15 -07:00
Mathias Agopian fc1d39334f separate SpinLock out of Allocator.h 2019-07-09 16:12:15 -07:00
Mathias Agopian af16e43830 add notify_n(int) to our condition variable
notify_n() wakes up n waiters, this is more fine grained than
notify_one() / notify_all(), and the implementation costs nothing.
2019-07-09 16:12:15 -07:00
Mathias Agopian 801c5b57a5 math::half is an arithmetic type even on msvc 2019-07-09 15:45:18 -07:00
Philip Rideout 19d7a3d21f Stop using DXT5 in web samples for the IBL.
Filament no longer decodes RGBM, so it's better to use a
floating-point format such as R11F_G11F_B10F.
2019-07-09 14:23:14 -07:00
Ben Doherty 6af77db79d Fix Android Toolchain issue on Windows (#1383) 2019-07-09 11:57:29 -07:00
Ben Doherty efb2f9a1d8 Fix windows build (#1384) 2019-07-09 11:56:36 -07:00
Romain Guy 3b3f52f48c Add Engine::destroy(Engine*) to match other APIs (#1377) 2019-07-08 14:22:13 -07:00
Ben Doherty ba5b9c733d Add shadow plane to hello-ar iOS sample (#1372) 2019-07-07 21:55:45 -07:00
Philip Rideout e009dbbf96 Minor updates to the webpack sample. 2019-07-03 15:32:01 -07:00
prideout 073a6c7696 Prepare for a new npm release. 2019-07-03 11:26:49 -07:00
Philip Rideout b30f6e5332 gltfio: JavaScript friendly error message for glb files. 2019-07-03 10:20:17 -07:00
Philip Rideout 384651e21a gltfio: fix JavaScript utility for glb files. 2019-07-03 10:20:17 -07:00
Philip Rideout 22dcdc770f gltfio: fix issue with bounding box computation.
If the client opts in to "recomputeBoundingBoxes", then we manually
compute a bounding box that ignores the glTF min / max annotations.

This computation was erroneously including the transform of the injected
root node, which is not part of the model.

This could cause a problem when creating the asset, then immediately
positioning it with its injected root node before the ResourceLoader
is done downloading vertex buffers.
2019-07-03 10:20:17 -07:00
Philip Rideout fd4d6c0d44 Use std::move in MeshAssimp.
Tested this via material_sandbox, seems to be fine.

Fixes #1366.
2019-07-02 14:20:55 -07:00
Philip Rideout ca5b52b2ce Add JavaScript / TypeScript support for RenderTarget. 2019-07-02 13:26:56 -07:00
Ben Doherty cc4e9db81b Fix spherical harmonics parsing (#1370) 2019-07-02 12:54:52 -07:00
Ben Doherty 2bfea16459 Update usage of KtxUtility in iOS projects (#1371) 2019-07-02 12:33:55 -07:00
Philip Rideout 927662ea4d Add JNI for KTX, simplify the bloom Android demo. 2019-07-02 11:02:45 -07:00
Ben Doherty 5b2dc1d3de Link against IBL library in iOS projects, update README (#1369) 2019-07-02 10:43:54 -07:00
Ben Doherty 097feb0372 Delete accidentally committed file (#1368) 2019-07-02 09:58:48 -07:00
Romain Guy 9cd2971b65 Fix typo in documentation 2019-07-01 17:58:03 -07:00
Ben Doherty fb16516480 Post-process materials: add post-process variant enum, split writeChunks function (#1365) 2019-07-01 12:57:41 -10:00
Mathias Agopian 76027cab85 fix a JobSystem bug in waitAndRelease()
We were not checking for jobs to execute during waitAndRelease(), so
this thread would essentially not participate to the work pool.
2019-07-01 14:25:26 -07:00
Mathias Agopian 64c95c615a Fix a theoretical wrapping around issue in WSDQ
The Work-stealing dequeue indices could wrap around after ~2 billion
calls to steal(). This could probably be achieved in a few hours.
By using 64-bits indices, we avoid the problem entirely.
2019-07-01 14:25:26 -07:00
Mathias Agopian 31745f6025 fix benchamrk JobSystem de-initialization
JobSystem's API requires to call emancipate() for each adopt() before
destroying the JobSystem.
2019-07-01 14:25:26 -07:00
Ben Doherty 2a8f04c791 Limit material compilation to supported backends (#1359) 2019-07-01 10:05:00 -10:00
Philip Rideout 3fdecfdefa gltf_viewer should not crash when there is no IBL. 2019-06-28 15:40:43 -07:00
Philip Rideout 26cbef7452 Fix intermittent cmgen crash. 2019-06-28 14:49:40 -07:00
Romain Guy 571a9b1ff3 Update README 2019-06-28 13:52:52 -07:00
Romain Guy b84117eb92 Update READMEs 2019-06-28 13:51:57 -07:00
Romain Guy 6af0c72d0d Add missing getter in IndirectLight (#1356)
This change also factors a bunch of assert methods in a single place
which should slightly decrease binary size.
2019-06-28 13:38:51 -07:00
Mathias Agopian 12fde30f31 better comments and potential fix for work-stealing dequeue
It's better to use std::memory_order_seq_cst in pop() and
steal() because we rely on ordering of access to
mTop and mBottom members.
2019-06-28 13:08:56 -07:00
Philip Rideout 56c2d6338e Add spherical harmonics parser, reduce code duplication.
This uses strtof rather than stringstream and provides a common location
that can be leveraged by the upcoming JNI bindings.

Note that this new method lives in KtxBundle rather than KtxUtility. The
latter creates Filament textures and therefore does not get built into
libimage.
2019-06-28 11:10:04 -07:00
Romain Guy 10c8ff352d Try with clang 7.0.1 on Windows 2019-06-27 10:52:48 -07:00
Romain Guy 53ea1a00ec Fix warnings 2019-06-27 10:46:52 -07:00
Romain Guy 62a458099a Fix more warnings 2019-06-27 09:56:43 -07:00
Romain Guy 826d52bca2 Fix Windows build and warnings 2019-06-27 09:18:31 -07:00
Romain Guy 299a600377 Add CMake to PATH during install 2019-06-26 19:02:21 -07:00
Romain Guy a4ebf23baa Update PATH 2019-06-26 18:53:05 -07:00
Romain Guy d23a703ca5 Echo on again 2019-06-26 18:45:47 -07:00
Romain Guy 2beb9c5588 Don't update PATH 2019-06-26 18:40:43 -07:00
Romain Guy a7fc4d8fbb Update PATH 2019-06-26 18:28:48 -07:00
Romain Guy a5dc89b071 Don't use refreshenv 2019-06-26 18:18:16 -07:00
Philip Rideout 2bfec9f4af gltfio: Disable file formats that we do not need.
This only removes 40k but at least it is easy.
2019-06-26 18:15:02 -07:00
Romain Guy 1aa7fac8c2 Remove ci-common 2019-06-26 18:03:58 -07:00
Romain Guy c01107fd52 Exit from the if statement to see what's going on 2019-06-26 17:55:43 -07:00
Romain Guy 5b27361ef0 Try with LLVM 6 2019-06-26 17:47:41 -07:00
Romain Guy 494ddc10e4 More logging 2019-06-26 17:36:24 -07:00
Mathias Agopian 6151f78d28 Update RELEASE_NOTES.md 2019-06-26 17:29:46 -07:00
Romain Guy 46c67632c7 Add logging to test Windows build 2019-06-26 17:28:33 -07:00
Philip Rideout 3f7cf2f971 Increase epsilon in test_cmgen. 2019-06-26 16:46:57 -07:00
11799 changed files with 1526323 additions and 1032815 deletions
+4
View File
@@ -17,6 +17,10 @@ A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Logs**
If applicable, copy logs from your console here. Please *do not*
use screenshots of logs, copy them as text.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- GPU: [e.g. NVIDIA GTX 1080]
@@ -0,0 +1,10 @@
FROM python:3.10.4
RUN pip3 install pygithub==1.55
ENV PYTHONUNBUFFERED=1
COPY verify_release_notes.py /verify_release_notes.py
RUN chmod +x /verify_release_notes.py
ENTRYPOINT [ "/verify_release_notes.py" ]
@@ -0,0 +1,35 @@
name: 'Verify Release Notes'
description: 'Verifies that a RELEASE_NOTES file has been modified'
inputs:
repo-token:
description: 'The GitHub token'
required: true
pull-request-number:
description: 'The Pull Request number'
required: true
bypass-label-name:
description: 'The Label used to bypass this check'
required: false
default: 'internal'
release-notes-file:
description: 'The path to the RELEASE_NOTES file'
required: false
default: 'RELEASE_NOTES.md'
pull-request-repo-full-name:
description: 'The full name of the Pull Request repo'
required: false
default: ${{ github.event.pull_request.head.repo.full_name }}
pull-request-head-ref:
description: 'The HEAD ref of the Pull Request'
required: false
default: ${{ github.event.pull_request.head.ref }}
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.repo-token }}
- ${{ inputs.pull-request-number }}
- ${{ inputs.bypass-label-name }}
- ${{ inputs.release-notes-file }}
- ${{ inputs.pull-request-repo-full-name }}
- ${{ inputs.pull-request-head-ref }}
@@ -0,0 +1,100 @@
#!/usr/bin/env python3
# Copyright (C) 2022 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.
from github import Github
import sys, os
def print_usage():
print('Verify that a GitHub pull request modifies a RELEASE_NOTES file')
print()
print('Usage:')
print(' verify_release_notes.py [arguments]')
print()
print('Arguments:')
print('1. github token')
print('2. pull request number')
print('3. bypass label name')
print('4. release notes file path')
print('5. pull request repo full name')
print('6. pull request head ref')
print()
print('The GITHUB_REPOSITORY environment variable must be set (e.g., google/filament).')
def leave_single_comment(pull_request, comment_body):
""" Leaves a comment on a PR once, without leaving a duplicate comment. """
# To avoid spamming the PR author, we'll use this comment tag (which will render invisibly on
# GitHub) to check if we've already left a comment on this PR.
COMMENT_TAG = '<!-- verify_release_notes -->\n'
comments = pull_request.get_issue_comments()
for comment in comments:
if comment.body.find(COMMENT_TAG) != -1:
return
# The GitHub token may not have WRITE permissions to leave a comment (for example, for 3P
# contributors). In that case, we simply won't leave a comment.
try:
pull_request.create_issue_comment(f'{COMMENT_TAG}{comment_body}')
except:
print("Unable to leave comment. Continuing.")
# The first argument is the path to this script.
if len(sys.argv) != 7:
print_usage()
sys.exit(1)
authentication_token = sys.argv[1]
pull_number = sys.argv[2]
bypass_label_name = sys.argv[3]
release_notes_file = sys.argv[4]
pr_repo_full_name = sys.argv[5]
pr_head_ref = sys.argv[6]
g = Github(authentication_token)
repo_name = os.environ.get('GITHUB_REPOSITORY')
if repo_name is None:
print("The GITHUB_REPOSITORY environment variable must be set.")
sys.exit(1)
repo = g.get_repo(repo_name)
pull_request = repo.get_pull(int(pull_number))
# First check if the PR has the "bypass" label. This label is used for PRs that don't need to update
# RELEASE_NOTES. If so, we can exit immediately.
labels = [l.name for l in pull_request.labels]
if bypass_label_name in labels:
print(f"PR number {pull_number} in repo {repo_name} contains the '{bypass_label_name}' label.")
print("Exiting with success.")
sys.exit(0)
# Next, check if the release notes file (RELEASE_NOTES.md or similar) has been modified.
files = pull_request.get_files()
for file in files:
if file.filename == release_notes_file:
print(f"PR number {pull_number} in repo {repo_name} modifies '{release_notes_file}'.")
print("Exiting with success.")
sys.exit(0)
# At this point, we issue a warning to the PR author to remember to modify the release notes, and
# exit with failure.
edit_url = f"https://github.com/{pr_repo_full_name}/edit/{pr_head_ref}/{release_notes_file}"
comment = (f"Please add a release note line to [{release_notes_file}]({edit_url}). "
f"If this PR does not warrant a release note, add the '{bypass_label_name}' label "
f"to this PR.")
print(comment)
leave_single_comment(pull_request, comment)
sys.exit(1)
+39
View File
@@ -0,0 +1,39 @@
name: Android
on:
push:
branches:
- main
- release
- rc/**
jobs:
build-android:
name: build-android
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- name: Run build script
run: |
cd build/android && printf "y" | ./build.sh continuous
- uses: actions/upload-artifact@v1.0.0
with:
name: filament-android
path: out/filament-android-release.aar
- uses: actions/upload-artifact@v1.0.0
with:
name: filamat-android-full
path: out/filamat-android-release.aar
- uses: actions/upload-artifact@v1.0.0
with:
name: filamat-android-lite
path: out/filamat-android-lite-release.aar
- uses: actions/upload-artifact@v1.0.0
with:
name: gltfio-android-release
path: out/gltfio-android-release.aar
- uses: actions/upload-artifact@v1.0.0
with:
name: filament-utils-android-release
path: out/filament-utils-android-release.aar
+26
View File
@@ -0,0 +1,26 @@
name: iOS
on:
push:
branches:
- main
- release
- rc/**
jobs:
build-ios:
name: build-ios
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- name: Run build script
run: |
cd build/ios && printf "y" | ./build.sh continuous
- uses: actions/upload-artifact@v1.0.0
with:
name: filament-ios
path: out/filament-release-ios.tgz
- name: Build iOS samples
run: |
cd build/ios && ./build-samples.sh continuous
+23
View File
@@ -0,0 +1,23 @@
name: Linux
on:
push:
branches:
- main
- release
- rc/**
jobs:
build-linux:
name: build-linux
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2.0.0
- name: Run build script
run: |
cd build/linux && printf "y" | ./build.sh continuous
- uses: actions/upload-artifact@v1.0.0
with:
name: filament-linux
path: out/filament-release-linux.tgz
+26
View File
@@ -0,0 +1,26 @@
name: macOS
on:
push:
branches:
- main
- release
- rc/**
jobs:
build-mac:
name: build-mac
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- name: Run build script
run: |
cd build/mac && printf "y" | ./build.sh continuous
- uses: actions/upload-artifact@v1.0.0
with:
name: filament-mac
path: out/filament-release-darwin.tgz
- name: Check public headers
run: |
build/common/check-headers.sh out/release/filament/include
+72
View File
@@ -0,0 +1,72 @@
name: Presubmit
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build-desktop:
name: build-desktop
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-18.04]
steps:
- uses: actions/checkout@v2.0.0
- name: Run build script
run: |
WORKFLOW_OS=`echo \`uname\` | sed "s/Darwin/mac/" | tr [:upper:] [:lower:]`
cd build/$WORKFLOW_OS && printf "y" | ./build.sh presubmit
- name: Test material parser
run: |
out/cmake-release/filament/test/test_material_parser
build-windows:
name: build-windows
runs-on: windows-2019
steps:
- uses: actions/checkout@v2.0.0
- name: Run build script
run: |
build\windows\build-github.bat presubmit
shell: cmd
build-android:
name: build-android
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- name: Run build script
run: |
cd build/android && printf "y" | ./build.sh presubmit
build-ios:
name: build-iOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- name: Run build script
run: |
cd build/ios && printf "y" | ./build.sh presubmit
- name: Build iOS samples
run: |
cd build/ios && ./build-samples.sh presubmit
build-web:
name: build-web
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- name: Run build script
run: |
cd build/web && printf "y" | ./build.sh presubmit
+192
View File
@@ -0,0 +1,192 @@
name: Release
# This Workflow can be triggered two ways:
# 1. A GitHub release is created (using the GitHub web UI). This triggers all of the platforms to
# build and upload assets.
# 2. A workflow_dispatch event is triggered from the GitHub web UI. This triggers a build for only
# the platform specified in the dispatch event.
env:
RELEASE_TAG: ${{ github.event.inputs.release_tag }}
on:
workflow_dispatch:
inputs:
platform:
description: 'Platform to build (desktop, web, android, ios, windows)'
required: true
default: 'desktop'
release_tag:
description: 'Release tag to build (e.g., v1.13.0)'
required: true
default: 'v1.13.0'
release:
types: [created]
jobs:
build-desktop:
name: build-desktop
runs-on: ${{ matrix.os }}
if: github.event_name == 'release' || github.event.inputs.platform == 'desktop'
strategy:
matrix:
os: [macos-latest, ubuntu-18.04]
steps:
- name: Decide Git ref
id: git_ref
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
with:
ref: ${{ steps.git_ref.outputs.ref }}
- name: Run build script
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
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
env:
TAG: ${{ steps.git_ref.outputs.tag }}
GITHUB_API_KEY: ${{ secrets.GITHUB_API_KEY }}
build-web:
name: build-web
runs-on: macos-latest
if: github.event_name == 'release' || github.event.inputs.platform == 'web'
steps:
- name: Decide Git ref
id: git_ref
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
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 }}
build-android:
name: build-android
runs-on: macos-latest
if: github.event_name == 'release' || github.event.inputs.platform == 'android'
steps:
- name: Decide Git ref
id: git_ref
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
with:
ref: ${{ steps.git_ref.outputs.ref }}
- name: Run build script
run: |
cd build/android && printf "y" | ./build.sh release
- name: Sign sample-gltf-viewer
run: |
echo "${APK_KEYSTORE_BASE64}" > filament.jks.base64
base64 --decode filament.jks.base64 > filament.jks
BUILD_TOOLS_VERSION=$(ls ${ANDROID_HOME}/build-tools | sort -V | tail -n 1)
APKSIGNER=${ANDROID_HOME}/build-tools/${BUILD_TOOLS_VERSION}/apksigner
IN_FILE="out/sample-gltf-viewer-release.apk"
OUT_FILE="out/filament-gltf-viewer-${TAG}-android.apk"
${APKSIGNER} sign --ks filament.jks --key-pass=pass:${APK_KEYSTORE_PASS} --ks-pass=pass:${APK_KEYSTORE_PASS} --in ${IN_FILE} --out ${OUT_FILE}
rm "${IN_FILE}"
env:
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
env:
TAG: ${{ steps.git_ref.outputs.tag }}
GITHUB_API_KEY: ${{ secrets.GITHUB_API_KEY }}
build-ios:
name: build-ios
runs-on: macos-latest
if: github.event_name == 'release' || github.event.inputs.platform == 'ios'
steps:
- name: Decide Git ref
id: git_ref
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
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 }}
build-windows:
name: build-windows
runs-on: windows-2019
if: github.event_name == 'release' || github.event.inputs.platform == 'windows'
steps:
- name: Decide Git ref
id: git_ref
run: |
REF=${RELEASE_TAG:-${GITHUB_REF}}
TAG=${REF##*/}
echo ::set-output name=ref::${REF}
echo ::set-output name=tag::${TAG}
shell: bash
- uses: actions/checkout@v2.0.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 }}
@@ -0,0 +1,26 @@
name: Verify Release Notes
on:
pull_request:
branches:
- main
types: [opened, synchronize, reopened, labeled]
jobs:
verify-release-notes:
name: Verify Release Notes
runs-on: ubuntu-latest
steps:
# We *only* need to check out the .github/ directory.
# The verify RELEASE_NOTES script uses the GitHub API to verify that RELEASE_NOTES was
# modified.
- name: Check out action
uses: Bhacaz/checkout-files@73e17cfbe8d7e0c6b2672b20cb05a718e20d18d4
with:
files: .github
token: ${{ secrets.GITHUB_TOKEN }}
- name: Verify release notes
uses: ./.github/actions/verify-release-notes
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ github.event.pull_request.number }}
+23
View File
@@ -0,0 +1,23 @@
name: Web
on:
push:
branches:
- main
- release
- rc/**
jobs:
build-web:
name: build-web
runs-on: macos-latest
steps:
- uses: actions/checkout@v2.0.0
- name: Run build script
run: |
cd build/web && printf "y" | ./build.sh continuous
- uses: actions/upload-artifact@v1.0.0
with:
name: filament-web
path: out/filament-release-web.tgz
+24
View File
@@ -0,0 +1,24 @@
name: Windows
on:
push:
branches:
- main
- release
- rc/**
jobs:
build-windows:
name: build-windows
runs-on: windows-2019
steps:
- uses: actions/checkout@v2.0.0
- name: Run build script
run: |
build\windows\build-github.bat continuous
shell: cmd
- uses: actions/upload-artifact@v1.0.0
with:
name: filament-windows
path: out/filament-windows.tgz
+7 -2
View File
@@ -3,11 +3,16 @@
imgui.ini
cmake-*
ImportExecutables-*.cmake
out
/out*
dist
dist-*
toolchains
filament/docs/html/**
.vscode
gltf_baker.ini
*tmp*.png
civetweb.txt
/TAGS
settings.json
test*.png
test*.json
results
+29
View File
@@ -0,0 +1,29 @@
![Filament branching strategy](art/diagrams/branching.png)
## Which branch do I open my PR against?
For normal development, open PRs against main. Once they're merged, no further action is necessary.
If you discover a bug with the latest *release candidate*, open a bug fix PR against the release
candidate branch (rc/1.9.0, for example). Once the PR is merged, decide whether it makes sense for
the fix to also go into main. If it was a temporary fix, simply make the _correct_ fix in main as
you would any other change. If the fix is good for main as well, use `git cherry-pick <sha>` to
cherry-pick it into main.
If an immediate hotfix is needed on the *release* branch, open a PR against the release branch. Once
the PR is merged, decide whether the fix is temporary or permanent. If the fix was temporary, make
the _correct_ fix in both the next release candidate branch _and_ main. If the fix is good, use `git
cherry-pick <sha>` to cherry-pick it into the relase candidate branch and main.
## What consitutes a bug?
Only bug fix PRs should be opened against the *release candidate* branch.
Bugs are defined as one of the following _introduced since the prior release_:
- crashes
- rendering issues
- unintentional binary size increases
- unintentional public API changes
For example, a long-standing crash just recently discovered would not necessitate a bug fix PR.
+462
View File
@@ -0,0 +1,462 @@
## Building Filament
### Prerequisites
To build Filament, you must first install the following tools:
- CMake 3.19 (or more recent)
- clang 7.0 (or more recent)
- [ninja 1.10](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages) (or more recent)
Additional dependencies may be required for your operating system. Please refer to the appropriate
section below.
To build Filament for Android you must also install the following:
- Android Studio Arctic Fox or more recent
- Android SDK
- Android NDK "side-by-side" 23.1 or higher
### Environment variables
To build Filament for Android, make sure the environment variable `ANDROID_HOME` points to the
location of your Android SDK.
When building for WebGL, you'll also need to set `EMSDK`. See [WebAssembly](#webassembly).
### IDE
We recommend using CLion to develop for Filament. Simply open the root directory's CMakeLists.txt
in CLion to obtain a usable project.
### Easy build
Once the required OS specific dependencies listed below are installed, you can use the script
located in `build.sh` to build Filament easily on macOS and Linux.
This script can be invoked from anywhere and will produce build artifacts in the `out/` directory
inside the Filament source tree.
To trigger an incremental debug build:
```
$ ./build.sh debug
```
To trigger an incremental release build:
```
$ ./build.sh release
```
To trigger both incremental debug and release builds:
```
$ ./build.sh debug release
```
To install the libraries and executables in `out/debug/` and `out/release/`, add the `-i` flag.
You can force a clean build by adding the `-c` flag. The script offers more features described
by executing `build.sh -h`.
### Filament-specific CMake Options
The following CMake options are boolean options specific to Filament:
- `FILAMENT_ENABLE_LTO`: Enable link-time optimizations if supported by the compiler
- `FILAMENT_BUILD_FILAMAT`: Build filamat and JNI buildings
- `FILAMENT_SUPPORTS_OPENGL`: Include the OpenGL backend
- `FILAMENT_SUPPORTS_METAL`: Include the Metal backend
- `FILAMENT_SUPPORTS_VULKAN`: Include the Vulkan backend
- `FILAMENT_INSTALL_BACKEND_TEST`: Install the backend test library so it can be consumed on iOS
- `FILAMENT_USE_EXTERNAL_GLES3`: Experimental: Compile Filament against OpenGL ES 3
- `FILAMENT_USE_SWIFTSHADER`: Compile Filament against SwiftShader
- `FILAMENT_SKIP_SAMPLES`: Don't build sample apps
To turn an option on or off:
```
$ cd <cmake-build-directory>
$ cmake . -DOPTION=ON # Relace OPTION with the option name, set to ON / OFF
```
Options can also be set with the CMake GUI.
### Linux
Make sure you've installed the following dependencies:
- `clang-7` or higher
- `libglu1-mesa-dev`
- `libc++-7-dev` (`libcxx-devel` and `libcxx-static` on Fedora) or higher
- `libc++abi-7-dev` (`libcxxabi-static` on Fedora) or higher
- `ninja-build`
- `libxi-dev`
After dependencies have been installed, we highly recommend using the [easy build](#easy-build)
script.
If you'd like to run `cmake` directly rather than using the build script, it can be invoked as
follows, with some caveats that are explained further down.
```
$ mkdir out/cmake-release
$ cd out/cmake-release
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../release/filament ../..
```
Your Linux distribution might default to `gcc` instead of `clang`, if that's the case invoke
`cmake` with the following command:
```
$ mkdir out/cmake-release
$ cd out/cmake-release
# Or use a specific version of clang, for instance /usr/bin/clang-7
$ CC=/usr/bin/clang CXX=/usr/bin/clang++ CXXFLAGS=-stdlib=libc++ \
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../release/filament ../..
```
You can also export the `CC` and `CXX` environment variables to always point to `clang`. Another
solution is to use `update-alternatives` to both change the default compiler, and point to a
specific version of clang:
```
$ update-alternatives --install /usr/bin/clang clang /usr/bin/clang-7 100
$ update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-7 100
$ update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100
$ update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100
```
Finally, invoke `ninja`:
```
$ ninja
```
This will build Filament, its tests and samples, and various host tools.
### macOS
To compile Filament you must have the most recent version of Xcode installed and you need to
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:
```
$ mkdir out/cmake-release
$ cd out/cmake-release
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../release/filament ../..
$ ninja
```
### iOS
The easiest way to build Filament for iOS is to use `build.sh` and the
`-p ios` flag. For instance to build the debug target:
```
$ ./build.sh -p ios debug
```
See [ios/samples/README.md](./ios/samples/README.md) for more information.
### Windows
#### Building on Windows with Visual Studio 2019
Install the following components:
- [Visual Studio 2019](https://www.visualstudio.com/downloads)
- [Windows 10 SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk)
- [Python 3.7](https://www.python.org/ftp/python/3.7.0/python-3.7.0.exe)
- [CMake 3.14 or later](https://github.com/Kitware/CMake/releases/download/v3.14.7/cmake-3.14.7-win64-x64.msi)
The latest Windows SDK can also by installed by opening Visual Studio and selecting _Get Tools and
Features..._ under the _Tools_ menu.
By default, Windows treats the file system as case insensitive. Please do not enable case
sensitivity in your repo, since this does not align with CMake expectations. This can be queried
using `fsutil.exe file queryCaseSensitiveInfo`.
Next, open `x64 Native Tools Command Prompt for VS 2019`, create a working directory, and run
CMake in it:
```
> mkdir out
> cd out
> cmake ..
```
Open the generated solution file `TNT.sln` in Visual Studio.
To build all targets, run _Build Solution_ from the _Build_ menu. Alternatively, right click on a
target in the _Solution Explorer_ and choose _Build_ to build a specific target.
For example, build the `material_sandbox` sample and run it from the `out` directory with:
```
> samples\Debug\material_sandbox.exe ..\assets\models\monkey\monkey.obj
```
You can also use CMake to invoke the build without opening Visual Studio. For example, from the
`out` folder run the following command.
```
> cmake --build . --target gltf_viewer --config Release
```
### Android
Before building Filament for Android, make sure to build Filament for your host. Some of the
host tools are required to successfully build for Android.
Filament can be built for the following architectures:
- ARM 64-bit (`arm64-v8a`)
- ARM 32-bit (`armeabi-v7a`)
- Intel 64-bit (`x86_64`)
- Intel 32-bit (`x86`)
Note that the main target is the ARM 64-bit target. Our implementation is optimized first and
foremost for `arm64-v8a`.
To build Android on Windows machines, see [android/Windows.md](android/Windows.md).
#### Easy Android build
The easiest way to build Filament for Android is to use `build.sh` and the
`-p android` flag. For instance to build the release target:
```
$ ./build.sh -p android release
```
Run `build.sh -h` for more information.
#### Manual builds
Invoke CMake in a build directory of your choice, inside of filament's directory. The commands
below show how to build Filament for ARM 64-bit (`aarch64`).
```
$ mkdir out/android-build-release-aarch64
$ cd out/android-build-release-aarch64
$ cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=../../build/toolchain-aarch64-linux-android.cmake \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../android-release/filament ../..
```
And then invoke `ninja`:
```
$ ninja install
```
or
```
$ ninja install/strip
```
This will generate Filament's Android binaries in `out/android-release`. This location is important
to build the Android Studio projects located in `filament/android`. After install, the library
binaries should be found in `out/android-release/filament/lib/arm64-v8a`.
#### AAR
Before you attempt to build the AAR, make sure you've compiled and installed the native libraries
as explained in the sections above. You must have the following ABIs built in
`out/android-release/filament/lib/`:
- `arm64-v8a`
- `armeabi-v7a`
- `x86_64`
- `x86`
To build Filament's AAR simply open the Android Studio project in `android/`. The
AAR is a universal AAR that contains all supported build targets:
- `arm64-v8a`
- `armeabi-v7a`
- `x86_64`
- `x86`
To filter out unneeded ABIs, rely on the `abiFilters` of the project that links against Filament's
AAR.
Alternatively you can build the AAR from the command line by executing the following in the
`android/` directory:
```
$ ./gradlew -Pcom.google.android.filament.dist-dir=../../out/android-release/filament assembleRelease
```
The `-Pcom.google.android.filament.dist-dir` can be used to specify a different installation
directory (it must match the CMake install prefix used in the previous steps).
#### Using Filament's AAR
Create a new module in your project and select _Import .JAR or .AAR Package_ when prompted. Make
sure to add the newly created module as a dependency to your application.
If you do not wish to include all supported ABIs, make sure to create the appropriate flavors in
your Gradle build file. For example:
```
flavorDimensions 'cpuArch'
productFlavors {
arm8 {
dimension 'cpuArch'
ndk {
abiFilters 'arm64-v8a'
}
}
arm7 {
dimension 'cpuArch'
ndk {
abiFilters 'armeabi-v7a'
}
}
x86_64 {
dimension 'cpuArch'
ndk {
abiFilters 'x86_64'.
}
}
x86 {
dimension 'cpuArch'
ndk {
abiFilters 'x86'
}
}
universal {
dimension 'cpuArch'
}
}
```
### WebAssembly
The core Filament library can be cross-compiled to WebAssembly from either macOS or Linux. To get
started, follow the instructions for building Filament on your platform ([macOS](#macos) or
[linux](#linux)), which will ensure you have the proper dependencies installed.
Next, you need to install the Emscripten SDK. The following instructions show how to install the
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.15.zip > emsdk.zip
unzip emsdk.zip ; mv emsdk-* emsdk ; cd emsdk
python ./emsdk.py install latest
python ./emsdk.py activate latest
source ./emsdk_env.sh
```
After this you can invoke the [easy build](#easy-build) script as follows:
```
export EMSDK=<your chosen home for the emscripten SDK>
./build.sh -p webgl release
```
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. We recommend using the emrun tool
to create a quick localhost server:
```
emrun out/cmake-webgl-release/web/samples --no_browser --port 8000
```
You can then open http://localhost:8000/suzanne.html in your web browser.
Alternatively, if you have node installed you can use the
[live-server](https://www.npmjs.com/package/live-server) package, which automatically refreshes the
web page when it detects a change.
Each sample app has its own handwritten html file. Additionally the server folder contains assets
such as meshes, textures, and materials.
## Running the native samples
The `samples/` directory contains several examples of how to use Filament with SDL2.
Some of the samples accept FBX/OBJ meshes while others rely on the `filamesh` file format. To
generate a `filamesh ` file from an FBX/OBJ asset, run the `filamesh` tool
(`./tools/filamesh/filamesh` in your build directory):
```
filamesh ./assets/models/monkey/monkey.obj monkey.filamesh
```
Most samples accept an IBL that must be generated using the `cmgen` tool (`./tools/filamesh/cmgen`
in your build directory). These sample apps expect a path to a directory containing the `.rgb32f`
files for the IBL (which are PNGs containing `R11F_G11F_B10F` data) or a path to a directory
containing two `.ktx` files (one for the IBL itself, one for the skybox). To generate an IBL
simply use this command:
```
cmgen -f ktx -x ./ibls/ my_ibl.exr
```
The source environment map can be a PNG (8 or 16 bit), a PSD (16 or 32 bit), an HDR or an OpenEXR
file. The environment map can be an equirectangular projection, a horizontal cross, a vertical
cross, or a list of cubemap faces (horizontal or vertical).
`cmgen` will automatically create a directory based on the name of the source environment map. In
the example above, the final directory will be `./ibls/my_ibl/`. This directory should contain the
pre-filtered environment map (one file per cubemap face and per mip level), the environment map
texture for the skybox and a text file containing the level harmonics for indirect diffuse
lighting.
If you prefer a blurred background, run `cmgen` with this flag: `--extract-blur=0.1`. The numerical
value is the desired roughness between 0 and 1.
## Generating C++ documentation
To generate the documentation you must first install `doxygen` and `graphviz`, then run the
following commands:
```
$ cd filament/filament
$ doxygen docs/doxygen/filament.doxygen
```
Finally simply open `docs/html/index.html` in your web browser.
## SwiftShader
To try out Filament's Vulkan support with SwiftShader, first build SwiftShader and set the
`SWIFTSHADER_LD_LIBRARY_PATH` variable to the folder that contains `libvk_swiftshader.dylib`:
```
git clone https://github.com/google/swiftshader.git
cd swiftshader/build
cmake .. && make -j
export SWIFTSHADER_LD_LIBRARY_PATH=`pwd`
```
Next, go to your Filament repo and use the [easy build](#easy-build) script with `-t`.
## SwiftShader for CI
Continuous testing turnaround can be quite slow if you need to build SwiftShader from scratch, so we
provide an Ubuntu-based Docker image that has it already built. The Docker image also includes
everything necessary for building Filament. You can fetch and run the image as follows:
```
docker pull ghcr.io/filament-assets/swiftshader
docker run -it ghcr.io/filament-assets/swiftshader
```
To do more with the container, see the helper script at `build/swiftshader/test.sh`.
If you are a team member, you can update the public image to the latest SwiftShader by
following the instructions at the top of `build/swiftshader/Dockerfile`.
+385 -111
View File
@@ -1,7 +1,7 @@
# ==================================================================================================
# CMake
# ==================================================================================================
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.19)
# ==================================================================================================
# Project declaration
@@ -11,14 +11,88 @@ project(TNT)
# ==================================================================================================
# Options
# ==================================================================================================
option(FILAMENT_USE_EXTERNAL_GLES3 "Experimental: Compile Filament against OpenGL ES 3" OFF)
option(ENABLE_JAVA "Compile Java projects, requires a JDK and the JAVA_HOME env var" ON)
option(FILAMENT_USE_SWIFTSHADER "Compile Filament against SwiftShader" OFF)
option(USE_EXTERNAL_GLES3 "Experimental: Compile Filament against OpenGL ES 3" OFF)
option(FILAMENT_ENABLE_LTO "Enable link-time optimizations if supported by the compiler" OFF)
option(GENERATE_JS_DOCS "Build WebGL documentation and tutorials" OFF)
option(FILAMENT_SKIP_SAMPLES "Don't build samples" OFF)
option(ENABLE_LTO "Enable link-time optimizations if supported by the compiler" OFF)
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)
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 "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 "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 "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
"Size of the OpenGL handle arena, default 4."
)
set(FILAMENT_METAL_HANDLE_ARENA_SIZE_IN_MB "8" CACHE STRING
"Size of the Metal handle arena, default 8."
)
# ==================================================================================================
# CMake policies
# ==================================================================================================
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.12")
cmake_policy(SET CMP0074 NEW)
endif()
# ==================================================================================================
# Support for ccache
# ==================================================================================================
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")
else()
set(CMAKE_C_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-c")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CMAKE_BINARY_DIR}/launch-cxx")
endif()
endif()
# ==================================================================================================
# Support Vim and Visual Studio Code by generating compile_commands.json
# ==================================================================================================
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# ==================================================================================================
# OS specific
@@ -27,6 +101,50 @@ if (UNIX AND NOT APPLE AND NOT ANDROID AND NOT WEBGL)
set(LINUX TRUE)
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()
if (FILAMENT_SUPPORTS_XLIB)
add_definitions(-DFILAMENT_SUPPORTS_XLIB)
endif()
if (FILAMENT_SUPPORTS_XCB OR FILAMENT_SUPORTS_XLIB)
add_definitions(-DFILAMENT_SUPPORTS_X11)
set(FILAMENT_SUPPORTS_X11 TRUE)
endif()
endif()
endif()
if (ANDROID OR WEBGL OR IOS OR FILAMENT_LINUX_IS_MOBILE)
set(IS_MOBILE_TARGET TRUE)
endif()
if (ANDROID)
add_definitions(-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__)
endif()
if (NOT ANDROID AND NOT WEBGL AND NOT IOS AND NOT FILAMENT_LINUX_IS_MOBILE)
set(IS_HOST_PLATFORM TRUE)
endif()
if (IOS)
# Remove the headerpad_max_install_names linker flag on iOS. It causes warnings when linking
# executables with bitcode.
string(REPLACE "-Wl,-headerpad_max_install_names" "" CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS})
string(REPLACE "-Wl,-headerpad_max_install_names" "" CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS})
string(REPLACE "-Wl,-headerpad_max_install_names" "" CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
string(REPLACE "-Wl,-headerpad_max_install_names" "" CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS})
endif()
if (WIN32)
# Link statically against c/c++ lib to avoid missing redistriburable such as
# "VCRUNTIME140.dll not found. Try reinstalling the app.", but give users
@@ -38,51 +156,52 @@ if (WIN32)
# __declspec(dllexport) in front of each functions).
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# The CMAKE_CXX_FLAGS vars can be overriden by some Visual Studio generators, so we use an alternative
# global method here:
if (${USE_STATIC_CRT})
set(CRT_FLAGS_RELEASE "/MT")
set(CRT_FLAGS_DEBUG "/MTd")
add_compile_options(
$<$<CONFIG:>:/MT>
$<$<CONFIG:Debug>:/MTd>
$<$<CONFIG:Release>:/MT>
)
else()
set(CRT_FLAGS_RELEASE "/MD")
set(CRT_FLAGS_DEBUG "/MDd")
add_compile_options(
$<$<CONFIG:>:/MD>
$<$<CONFIG:Debug>:/MDd>
$<$<CONFIG:Release>:/MD>
)
endif()
# TODO: Figure out why pdb generation messes with incremental compilaton.
# IN RELEASE_WITH_DEBUG_INFO, generate debug info in .obj, no in pdb.
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${CRT_FLAGS_RELEASE} /Z7")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${CRT_FLAGS_RELEASE} /Z7")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /Z7")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /Z7")
# In RELEASE, also generate PDBs.
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CRT_FLAGS_RELEASE} /Zi")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CRT_FLAGS_RELEASE} /Zi")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
# In DEBUG, avoid generating a PDB file which seems to mess with incremental compilation.
# Instead generate debug info directly inside obj files.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CRT_FLAGS_DEBUG} /Z7")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CRT_FLAGS_DEBUG} /Z7")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Z7")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Z7")
# ==================================================================================================
# Check if embree is available.
# This is an optional dependency and can be installed with homebrew, apt-get, etc.
# ==================================================================================================
# Special settings when building on CI.
if (${FILAMENT_WINDOWS_CI_BUILD})
set(LinkerFlags
CMAKE_SHARED_LINKER_FLAGS_DEBUG
CMAKE_EXE_LINKER_FLAGS_DEBUG
CMAKE_MODULE_LINKER_FLAGS_DEBUG
)
foreach(LinkerFlag ${LinkerFlags})
# The /debug flag outputs .pdb files, which we don't need on CI.
string(REPLACE "/debug" "" ${LinkerFlag} ${${LinkerFlag}})
find_package(embree 3.0 QUIET PATHS /usr/lib64/cmake)
if (embree_FOUND AND NOT ANDROID)
message("Found embree in ${embree_DIR}")
set(MKLDNN_THREADING "TBB")
include(third_party/OpenImageDenoise/cmake/resource.cmake)
include(third_party/OpenImageDenoise/mkl-dnn/cmake/Threading.cmake)
include(third_party/OpenImageDenoise/mkl-dnn/cmake/TBB.cmake)
find_package(TBB QUIET)
if (TBB_FOUND AND "${TBB_VERSION_MAJOR}" VERSION_EQUAL 2019)
message("Found TBB ${TBB_VERSION}")
add_definitions(-DFILAMENT_HAS_EMBREE)
set(DENOISE_LIBRARY OpenImageDenoise)
else()
message("TBB 2019 not found.")
# The /INCREMENTAL flag outputs .ilk files for incremental linking. These are huge, and
# we don't need them on CI.
string(REPLACE "/INCREMENTAL" "/INCREMENTAL:NO" ${LinkerFlag} ${${LinkerFlag}})
endforeach()
endif()
else()
message("Embree not found, pipeline features are disabled.")
endif()
# ==================================================================================================
@@ -109,7 +228,7 @@ if (CMAKE_C_COMPILER_ID MATCHES "Clang")
if (CMAKE_C_COMPILER_VERSION VERSION_LESS MIN_CLANG_VERSION)
message(FATAL_ERROR "Detected C compiler Clang ${CMAKE_C_COMPILER_VERSION} < ${MIN_CLANG_VERSION}")
endif()
else()
elseif (NOT MSVC)
message(FATAL_ERROR "Detected C compiler ${CMAKE_C_COMPILER_ID} is unsupported")
endif()
@@ -117,19 +236,21 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS MIN_CLANG_VERSION)
message(FATAL_ERROR "Detected CXX compiler Clang ${CMAKE_CXX_COMPILER_VERSION} < ${MIN_CLANG_VERSION}")
endif()
else()
elseif (NOT MSVC)
message(FATAL_ERROR "Detected CXX compiler ${CMAKE_CXX_COMPILER_ID} is unsupported")
endif()
# Detect use of the clang-cl.exe frontend, which does not support all of clangs normal options
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
set(CLANG_CL true)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if ("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
message(FATAL_ERROR "Building with Clang on Windows is no longer supported. Use MSVC 2019 instead.")
endif()
endif()
# ==================================================================================================
# Link time optimizations (LTO)
# ==================================================================================================
if (ENABLE_LTO)
if (FILAMENT_ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORT)
@@ -143,33 +264,58 @@ endif()
# ==================================================================================================
# General compiler flags
# ==================================================================================================
set(CXX_STANDARD "-std=c++14")
set(CXX_STANDARD "-std=c++17")
if (WIN32)
set(CXX_STANDARD "/std:c++14")
set(CXX_STANDARD "/std:c++17")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD} -fstrict-aliasing -Wno-unknown-pragmas -Wno-unused-function")
if (MSVC)
set(CXX_STANDARD "/std:c++latest")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD} /W0 /Zc:__cplusplus")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_STANDARD} -fstrict-aliasing -Wno-unknown-pragmas -Wno-unused-function -Wno-deprecated-declarations")
endif()
if (USE_EXTERNAL_GLES3)
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()
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_USE_MATH_DEFINES=1")
endif()
if (LINUX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
link_libraries("-static-libgcc -static-libstdc++")
link_libraries(libc++.a)
link_libraries(libc++abi.a)
option(USE_STATIC_LIBCXX "Link against the static runtime libraries." ON)
if (${USE_STATIC_LIBCXX})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
link_libraries("-static-libgcc -static-libstdc++")
link_libraries(libc++.a)
link_libraries(libc++abi.a)
endif()
# Only linux, clang doesn't want to use a shared library that is not PIC.
# /usr/bin/ld: ../bluegl/libbluegl.a(BlueGL.cpp.o): relocation R_X86_64_32S
# against `.bss' can not be used when making a shared object; recompile with -fPIC
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
if (ANDROID)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Werror=unguarded-availability")
endif()
if (CYGWIN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
endif()
if (CLANG_CL)
if (MSVC)
# Since the "secure" replacements that MSVC suggests are not portable, disable
# the deprecation warnings. Also disable warnings about use of POSIX functions (i.e. "unlink").
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE")
@@ -182,19 +328,41 @@ if (UNIX AND CMAKE_GENERATOR STREQUAL "Ninja")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
endif()
# Use hidden by default and expose what we need.
if (NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
endif()
# ==================================================================================================
# Release compiler flags
# ==================================================================================================
if (NOT CLANG_CL)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer -ffunction-sections -fdata-sections")
if (NOT MSVC)
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()
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 WEBGL)
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")
endif()
# With WebGL, we disable RTTI even for debug builds because we pass emscripten::val back and forth
# between C++ and JavaScript in order to efficiently access typed arrays, which are unbound.
# NOTE: This is not documented in emscripten so we should consider a different approach.
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
# ==================================================================================================
@@ -202,17 +370,24 @@ endif()
# -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")
# clang-cl.exe on Windows does not support -fstack-protector.
if (NOT CLANG_CL)
if (NOT MSVC AND NOT WEBGL)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fstack-protector")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${EXTRA_SANITIZE_OPTIONS}")
# Disable the stack check for macOS to workaround a known issue in clang 11.0.0.
# See: https://forums.developer.apple.com/thread/121887
if (APPLE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-stack-check")
endif()
# ==================================================================================================
# Linker flags
# ==================================================================================================
# Strip unused sections
set(GC_SECTIONS "-Wl,--gc-sections")
if (NOT WEBGL)
set(GC_SECTIONS "-Wl,--gc-sections")
endif()
set(B_SYMBOLIC_FUNCTIONS "-Wl,-Bsymbolic-functions")
if (APPLE)
@@ -225,16 +400,13 @@ if (APPLE)
# prevents ar from invoking ranlib, let CMake do it
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qc -S <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qc -S <TARGET> <LINK_FLAGS> <OBJECTS>")
elseif (CLANG_CL)
set(GC_SECTIONS "")
set(B_SYMBOLIC_FUNCTIONS "")
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()
# ==================================================================================================
@@ -246,10 +418,15 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebIn
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTNT_DEV")
endif()
# By default, build with support for OpenGL on all platforms.
option(FILAMENT_SUPPORTS_OPENGL "Include the OpenGL backend" ON)
if (FILAMENT_SUPPORTS_OPENGL)
add_definitions(-DFILAMENT_SUPPORTS_OPENGL)
endif()
# By default, build with Vulkan support on desktop platforms, although clients must request to use
# it at run time. On Android, the build does not include Vulkan support unless CMake is invoked
# with -DFILAMENT_SUPPORTS_VULKAN=ON.
if (ANDROID OR WIN32 OR WEBGL OR IOS)
# it at run time.
if (WIN32 OR WEBGL OR IOS)
option(FILAMENT_SUPPORTS_VULKAN "Include the Vulkan backend" OFF)
else()
option(FILAMENT_SUPPORTS_VULKAN "Include the Vulkan backend" ON)
@@ -259,8 +436,7 @@ if (FILAMENT_SUPPORTS_VULKAN)
endif()
# Build with Metal support on non-WebGL Apple platforms.
# Apple's simulator does not support Metal.
if (APPLE AND (NOT IOS OR IOS_ARCH STREQUAL "arm64") AND NOT WEBGL)
if (APPLE AND NOT WEBGL)
option(FILAMENT_SUPPORTS_METAL "Include the Metal backend" ON)
else()
option(FILAMENT_SUPPORTS_METAL "Include the Metal backend" OFF)
@@ -276,13 +452,72 @@ else()
option(FILAMENT_BUILD_FILAMAT "Build filamat and JNI buildings" OFF)
endif()
# By default, link in matdbg for Desktop + Debug only since it pulls in filamat and a web server.
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND IS_HOST_PLATFORM)
option(FILAMENT_ENABLE_MATDBG "Enable the material debugger" ON)
else()
option(FILAMENT_ENABLE_MATDBG "Enable the material 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)
else()
option(FILAMENT_DISABLE_MATOPT "Disable material optimizations" ON)
endif()
# ==================================================================================================
# Material compilation flags
# ==================================================================================================
# Target system.
if (IS_MOBILE_TARGET)
set(MATC_TARGET mobile)
else()
set(MATC_TARGET desktop)
endif()
set(MATC_API_FLAGS )
if (FILAMENT_SUPPORTS_OPENGL)
set(MATC_API_FLAGS ${MATC_API_FLAGS} -a opengl)
endif()
if (FILAMENT_SUPPORTS_VULKAN)
set(MATC_API_FLAGS ${MATC_API_FLAGS} -a vulkan)
endif()
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)
if (FILAMENT_DISABLE_MATOPT)
set(MATC_OPT_FLAGS -gd)
endif()
set(MATC_BASE_FLAGS ${MATC_API_FLAGS} -p ${MATC_TARGET} ${MATC_OPT_FLAGS})
# ==================================================================================================
# Distribution
# ==================================================================================================
# choose where to put the objects in the dist folder
if (NOT DIST_ARCH)
set(DIST_ARCH x86_64)
# On Apple silicon, the value of CMAKE_HOST_SYSTEM_PROCESSOR varies based on the CMake process's
# own architecture. Because of this, running a x86_64 CMake binary on Apple silicon will cause
# DIST_ARCH to be set incorrectly.
set(DIST_ARCH "${CMAKE_HOST_SYSTEM_PROCESSOR}")
if (CMAKE_OSX_ARCHITECTURES MATCHES ".*;.*")
set(DIST_ARCH "universal")
else()
if (NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
set(DIST_ARCH "${CMAKE_OSX_ARCHITECTURES}")
endif()
endif()
endif()
# On Windows machines, the host processor is set to 'AMD64', which we'll interpret as x86_64.
string(TOLOWER "${DIST_ARCH}" DIST_ARCH)
string(REPLACE "amd64" "x86_64" DIST_ARCH "${DIST_ARCH}")
if (NOT DIST_DIR)
set(DIST_DIR "${DIST_ARCH}")
endif()
@@ -290,20 +525,56 @@ endif()
# ==================================================================================================
# Functions
# ==================================================================================================
## The MSVC compiler has a limitation on literal string length which is reached when all the
## licenses are concatenated together into a large string... so split them into multiple strings.
function(list_licenses OUTPUT MODULES)
file(WRITE ${OUTPUT} "R\"FILAMENT__(\n")
set(STR_OPENER "R\"FILAMENT__(")
set(STR_CLOSER ")FILAMENT__\"")
set(CONTENT)
set(_MODULES ${MODULES} ${ARGN})
foreach(module ${_MODULES})
set(license_path "../../third_party/${module}/LICENSE")
get_filename_component(fullname "${license_path}" ABSOLUTE)
file(APPEND ${OUTPUT} "License and copyrights for ${module}:\n\n")
file(READ ${license_path} license)
file(APPEND ${OUTPUT} ${license})
file(APPEND ${OUTPUT} "\n\n")
if(EXISTS ${fullname})
string(APPEND CONTENT "${STR_OPENER}License and copyrights for ${module}:\n${STR_CLOSER},\n")
file(READ ${license_path} license_long)
string(REPLACE "\n" "${STR_CLOSER},\n${STR_OPENER}" license ${license_long})
string(APPEND CONTENT ${STR_OPENER}${license}\n${STR_CLOSER},)
string(APPEND CONTENT "\n\n")
else()
message(AUTHOR_WARNING "${license_path} not found. You can ignore this warning if you have devendored ${module}.")
endif()
endforeach()
file(APPEND ${OUTPUT} ")FILAMENT__\"\n")
configure_file(${FILAMENT}/build/licenses.inc.in ${OUTPUT})
endfunction(list_licenses)
set(COMBINE_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/build/linux/combine-static-libs.sh")
if (WIN32)
set(COMBINE_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/build/windows/combine-static-libs.bat")
set(CMAKE_AR "lib.exe")
endif()
# Add a custom command to TARGET that combines the static libraries in DEPS into a single archive.
function(combine_static_libs TARGET OUTPUT DEPS)
# Loop through the dependent libraries and query their location on disk.
set(DEPS_FILES )
foreach(DEPENDENCY ${DEPS})
if(TARGET ${DEPENDENCY})
get_property(dep_type TARGET ${DEPENDENCY} PROPERTY TYPE)
if(dep_type STREQUAL "STATIC_LIBRARY")
list(APPEND DEPS_FILES "$<TARGET_FILE:${DEPENDENCY}>")
endif()
endif()
endforeach()
add_custom_command(
TARGET ${TARGET} POST_BUILD
COMMAND "${COMBINE_SCRIPT}" "${CMAKE_AR}" "${OUTPUT}" ${DEPS_FILES}
COMMENT "Combining ${target} dependencies into single shared library"
VERBATIM
)
endfunction()
# ==================================================================================================
# Configuration for CMAKE_CROSSCOMPILING.
# ==================================================================================================
@@ -319,13 +590,13 @@ endif()
# "bluevk" and "samples" targets.
# ==================================================================================================
if (FILAMENT_SUPPORTS_VULKAN AND APPLE)
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}\")
if (FILAMENT_USE_SWIFTSHADER)
if (NOT FILAMENT_SUPPORTS_VULKAN)
message(ERROR "SwiftShader is only useful when Vulkan is enabled.")
endif()
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}\")
endif()
# ==================================================================================================
@@ -354,11 +625,11 @@ function(get_resgen_vars ARCHIVE_DIR ARCHIVE_NAME)
# the equivalent of .incbin, so on Windows we'll just tell resgen to output a C file.
if (WEBGL OR WIN32 OR ANDROID_ON_WINDOWS)
set(RESGEN_OUTPUTS "${OUTPUTS};${ARCHIVE_DIR}/${ARCHIVE_NAME}.c" PARENT_SCOPE)
set(RESGEN_FLAGS -cx ${ARCHIVE_DIR} -p ${ARCHIVE_NAME} PARENT_SCOPE)
set(RESGEN_FLAGS -qcx ${ARCHIVE_DIR} -p ${ARCHIVE_NAME} PARENT_SCOPE)
set(RESGEN_SOURCE "${ARCHIVE_DIR}/${ARCHIVE_NAME}.c" PARENT_SCOPE)
else()
set(RESGEN_OUTPUTS "${OUTPUTS}" PARENT_SCOPE)
set(RESGEN_FLAGS -x ${ARCHIVE_DIR} -p ${ARCHIVE_NAME} PARENT_SCOPE)
set(RESGEN_FLAGS -qx ${ARCHIVE_DIR} -p ${ARCHIVE_NAME} PARENT_SCOPE)
set(RESGEN_SOURCE "${ARCHIVE_DIR}/${ARCHIVE_NAME}${ASM_SUFFIX}.S" PARENT_SCOPE)
set(RESGEN_SOURCE_FLAGS "-I${ARCHIVE_DIR} ${ASM_ARCH_FLAG}" PARENT_SCOPE)
endif()
@@ -370,33 +641,50 @@ endfunction()
# Common to all platforms
add_subdirectory(${EXTERNAL}/libgtest/tnt)
add_subdirectory(${LIBRARIES}/camutils)
add_subdirectory(${LIBRARIES}/filabridge)
add_subdirectory(${LIBRARIES}/filaflat)
add_subdirectory(${LIBRARIES}/filagui)
add_subdirectory(${LIBRARIES}/filameshio)
add_subdirectory(${LIBRARIES}/geometry)
add_subdirectory(${LIBRARIES}/gltfio)
add_subdirectory(${LIBRARIES}/ibl)
add_subdirectory(${LIBRARIES}/iblprefilter)
add_subdirectory(${LIBRARIES}/image)
add_subdirectory(${LIBRARIES}/rays)
add_subdirectory(${LIBRARIES}/ktxreader)
add_subdirectory(${LIBRARIES}/math)
add_subdirectory(${LIBRARIES}/mathio)
add_subdirectory(${LIBRARIES}/uberz)
add_subdirectory(${LIBRARIES}/utils)
add_subdirectory(${LIBRARIES}/viewer)
add_subdirectory(${FILAMENT}/filament)
add_subdirectory(${FILAMENT}/shaders)
add_subdirectory(${EXTERNAL}/basisu/tnt)
add_subdirectory(${EXTERNAL}/civetweb/tnt)
add_subdirectory(${EXTERNAL}/hat-trie/tnt)
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}/cgltf/tnt)
add_subdirectory(${EXTERNAL}/xatlas/tnt)
add_subdirectory(${EXTERNAL}/draco/tnt)
add_subdirectory(${EXTERNAL}/jsmn/tnt)
add_subdirectory(${EXTERNAL}/stb/tnt)
add_subdirectory(${EXTERNAL}/getopt)
if (FILAMENT_BUILD_FILAMAT)
if (FILAMENT_BUILD_FILAMAT OR IS_HOST_PLATFORM)
# spirv-tools must come before filamat, as filamat relies on the presence of the
# spirv-tools_SOURCE_DIR variable.
add_subdirectory(${EXTERNAL}/spirv-tools)
add_subdirectory(${EXTERNAL}/glslang/tnt)
add_subdirectory(${EXTERNAL}/spirv-cross/tnt)
add_subdirectory(${LIBRARIES}/filamat)
# the material debugger requires filamat
if (FILAMENT_ENABLE_MATDBG OR IS_HOST_PLATFORM)
add_subdirectory(${LIBRARIES}/matdbg)
endif()
endif()
if (FILAMENT_SUPPORTS_VULKAN)
@@ -404,43 +692,32 @@ if (FILAMENT_SUPPORTS_VULKAN)
add_subdirectory(${EXTERNAL}/vkmemalloc/tnt)
endif()
if (APPLE)
add_subdirectory(${EXTERNAL}/moltenvk/tnt)
endif()
set (FILAMENT_SAMPLES_BINARY_DIR ${PROJECT_BINARY_DIR}/samples)
set(FILAMENT_SAMPLES_BINARY_DIR ${PROJECT_BINARY_DIR}/samples)
if (WEBGL)
add_subdirectory(web/filament-js)
add_subdirectory(web/samples)
if (GENERATE_JS_DOCS)
add_subdirectory(web/docs)
endif()
add_subdirectory(${EXTERNAL}/imgui/tnt)
endif()
if (NOT ANDROID AND NOT WEBGL AND NOT IOS)
add_subdirectory(${LIBRARIES}/bluegl)
add_subdirectory(${LIBRARIES}/filagui)
if (IS_HOST_PLATFORM)
if (FILAMENT_SUPPORTS_OPENGL)
add_subdirectory(${LIBRARIES}/bluegl)
endif()
if (NOT FILAMENT_SKIP_SDL2)
add_subdirectory(${LIBRARIES}/filamentapp)
endif()
add_subdirectory(${LIBRARIES}/imageio)
add_subdirectory(${FILAMENT}/java/filamat)
add_subdirectory(${FILAMENT}/java/filament)
add_subdirectory(${FILAMENT}/samples)
add_subdirectory(${EXTERNAL}/astcenc/tnt)
add_subdirectory(${EXTERNAL}/etc2comp)
add_subdirectory(${EXTERNAL}/getopt)
add_subdirectory(${EXTERNAL}/imgui/tnt)
add_subdirectory(${EXTERNAL}/libassimp/tnt)
add_subdirectory(${EXTERNAL}/libpng/tnt)
add_subdirectory(${EXTERNAL}/libsdl2/tnt)
add_subdirectory(${EXTERNAL}/libz/tnt)
add_subdirectory(${EXTERNAL}/skylight/tnt)
add_subdirectory(${EXTERNAL}/tinyexr/tnt)
add_subdirectory(${TOOLS}/cmgen)
add_subdirectory(${TOOLS}/cso-lut)
add_subdirectory(${TOOLS}/filamesh)
add_subdirectory(${TOOLS}/glslminifier)
add_subdirectory(${TOOLS}/matc)
@@ -448,16 +725,13 @@ if (NOT ANDROID AND NOT WEBGL AND NOT IOS)
add_subdirectory(${TOOLS}/mipgen)
add_subdirectory(${TOOLS}/normal-blending)
add_subdirectory(${TOOLS}/resgen)
add_subdirectory(${TOOLS}/rgb-to-lmsr)
add_subdirectory(${TOOLS}/roughness-prefilter)
add_subdirectory(${TOOLS}/skygen)
add_subdirectory(${TOOLS}/specular-color)
endif()
if (DENOISE_LIBRARY)
add_subdirectory(${EXTERNAL}/OpenImageDenoise/tnt)
add_subdirectory(${TOOLS}/uberz)
endif()
# Generate exported executables for cross-compiled builds (Android, WebGL, and iOS)
if (NOT CMAKE_CROSSCOMPILING)
export(TARGETS matc cmgen filamesh mipgen resgen glslminifier FILE ${IMPORT_EXECUTABLES})
export(TARGETS matc cmgen filamesh mipgen resgen uberz glslminifier FILE ${IMPORT_EXECUTABLES})
endif()
+1 -2
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.
+15
View File
@@ -40,3 +40,18 @@ information on using pull requests.
This project follows
[Google's Open Source Community Guidelines](https://opensource.google.com/conduct/).
## Dependencies
One of our design goals is that Filament itself should have no dependencies or as few dependencies
as possible. The current external dependencies of the runtime library include:
- STL
- robin-map (header only library)
When building with Vulkan enabled, we have a few additional small dependencies:
- vkmemalloc
- smol-v
Host tools (such as `matc` or `cmgen`) can use external dependencies freely.
+196 -716
View File
@@ -1,28 +1,68 @@
# Filament
<img alt="Android" src="build/img/android.png" width="20px" height="20px" hspace="2px"/>[![Android Build Status](https://filament-build.storage.googleapis.com/badges/build_status_android.svg)](https://filament-build.storage.googleapis.com/badges/build_link_android.html)
<img alt="iOS" src="build/img/macos.png" width="20px" height="20px" hspace="2px"/>[![iOS Build Status](https://filament-build.storage.googleapis.com/badges/build_status_ios.svg)](https://filament-build.storage.googleapis.com/badges/build_link_ios.html)
<img alt="Linux" src="build/img/linux.png" width="20px" height="20px" hspace="2px"/>[![Linux Build Status](https://filament-build.storage.googleapis.com/badges/build_status_linux.svg)](https://filament-build.storage.googleapis.com/badges/build_link_linux.html)
<img alt="macOS" src="build/img/macos.png" width="20px" height="20px" hspace="2px"/>[![MacOS Build Status](https://filament-build.storage.googleapis.com/badges/build_status_mac.svg)](https://filament-build.storage.googleapis.com/badges/build_link_mac.html)
<img alt="Windows" src="build/img/windows.png" width="20px" height="20px" hspace="2px"/>[![Windows Build Status](https://filament-build.storage.googleapis.com/badges/build_status_windows.svg)](https://filament-build.storage.googleapis.com/badges/build_link_windows.html)
<img alt="Web" src="build/img/web.png" width="20px" height="20px" hspace="2px"/>[![Web Build Status](https://filament-build.storage.googleapis.com/badges/build_status_web.svg)](https://filament-build.storage.googleapis.com/badges/build_link_web.html)
[![Android Build Status](https://github.com/google/filament/workflows/Android/badge.svg)](https://github.com/google/filament/actions?query=workflow%3AAndroid)
[![iOS Build Status](https://github.com/google/filament/workflows/iOS/badge.svg)](https://github.com/google/filament/actions?query=workflow%3AiOS)
[![Linux Build Status](https://github.com/google/filament/workflows/Linux/badge.svg)](https://github.com/google/filament/actions?query=workflow%3ALinux)
[![macOS Build Status](https://github.com/google/filament/workflows/macOS/badge.svg)](https://github.com/google/filament/actions?query=workflow%3AmacOS)
[![Windows Build Status](https://github.com/google/filament/workflows/Windows/badge.svg)](https://github.com/google/filament/actions?query=workflow%3AWindows)
[![Web Build Status](https://github.com/google/filament/workflows/Web/badge.svg)](https://github.com/google/filament/actions?query=workflow%3AWeb)
Filament is a real-time physically based rendering engine for Android, iOS, Linux, macOS, Windows,
and WebGL. It is designed to be as small as possible and as efficient as possible on Android.
Filament is currently used in the
[Sceneform](https://developers.google.com/ar/develop/java/sceneform/) library both at runtime on
Android devices and as the renderer inside the Android Studio plugin.
## Download
[Download Filament releases](https://github.com/google/filament/releases) to access stable builds.
Filament release archives contains host-side tools that are required to generate assets.
Make sure you always use tools from the same release as the runtime library. This is particularly
important for `matc` (material compiler).
If you prefer to live on the edge, you can download a continuous build by clicking one of the build
badges above.
If you'd rather build Filament yourself, please refer to our [build manual](BUILDING.md).
### Android
Android projects can simply declare Filament libraries as Maven dependencies:
```gradle
repositories {
// ...
mavenCentral()
}
dependencies {
implementation 'com.google.android.filament:filament-android:1.27.0'
}
```
Here are all the libraries available in the group `com.google.android.filament`:
| Artifact | Description |
| ------------- | ------------- |
| [![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. |
### iOS
iOS projects can use CocoaPods to install the latest release:
```
pod 'Filament', '~> 1.27.0'
```
### Snapshots
If you prefer to live on the edge, you can download a continuous build by following the following
steps:
1. Find the [commit](https://github.com/google/filament/commits/main) you're interested in.
2. Click the green check mark under the commit message.
3. Click on the _Details_ link for the platform you're interested in.
4. On the top left click _Summary_, then in the _Artifacts_ section choose the desired artifact.
## Documentation
@@ -36,26 +76,21 @@ badges above.
- [Material Properties](https://google.github.io/filament/Material%20Properties.pdf), a reference
sheet for the standard material model.
## Samples
## Examples
Here are a few sample materials rendered with Filament:
![Damaged Helmet](docs/images/samples/model_damaged_helmet.jpg)
![Helmet](docs/images/samples/model_helmet.jpg)
![Brushed copper](docs/images/samples/brushed_copper_2.jpg)
![Chess set](docs/images/samples/chess1.jpg)
![Material 1](docs/images/samples/material_01.jpg)
![Material 2](docs/images/samples/material_02.jpg)
![Material 3](docs/images/samples/material_03.jpg)
![Material 6](docs/images/samples/material_06.jpg)
![Material 8](docs/images/samples/material_08.jpg)
![Night scene](docs/images/samples/example_bistro1.jpg)
![Night scene](docs/images/samples/example_bistro2.jpg)
![Materials](docs/images/samples/example_materials1.jpg)
![Materials](docs/images/samples/example_materials2.jpg)
![Helmet](docs/images/samples/example_helmet.jpg)
![Screen-space refraction](docs/images/samples/example_ssr.jpg)
## Features
### APIs
- Native C++ API for Android, iOS, Linux, macOS and Windows
- Java/JNI API for Android, Linux, macOS and Windows
- Java/JNI API for Android
- JavaScript API
### Backends
@@ -63,7 +98,7 @@ Here are a few sample materials rendered with Filament:
- OpenGL 4.1+ for Linux, macOS and Windows
- OpenGL ES 3.0+ for Android and iOS
- Metal for macOS and iOS
- Vulkan 1.0 for Android, Linux, macOS and iOS (with MoltenVk), and Windows
- Vulkan 1.0 for Android, Linux, macOS, and Windows
- WebGL 2.0 for all platforms
### Rendering
@@ -71,661 +106,80 @@ Here are a few sample materials rendered with Filament:
- Clustered forward renderer
- Cook-Torrance microfacet specular BRDF
- Lambertian diffuse BRDF
- Custom lighting/surface shading
- HDR/linear lighting
- Metallic workflow
- Clear coat
- Anisotropic lighting
- Approximated translucent (subsurface) materials
- Cloth shading
- Cloth/fabric/sheen shading
- Normal mapping & ambient occlusion mapping
- Image-based lighting
- Physically-based camera (shutter speed, sensitivity and aperture)
- Physical light units
- Point light, spot light and directional light
- SSAO
- ACES-like tone-mapping
- Temporal dithering
- FXAA, MSAA and specular anti-aliasing
- Dynamic resolution (on Android)
- Point lights, spot lights and directional light
- Specular anti-aliasing
- Spot and directional light shadows
- Cascaded shadows
- EVSM, PCSS, DPCF, or PCF shadows
- Transparent shadows
- Contact shadows
- Screen-space ambient occlusion
- Screen-space reflections
- Screen-space refraction
- Global fog
- Dynamic resolution (with support for AMD FidelityFX FSR)
### Post processing
- HDR bloom
- Depth of field bokeh
- Multiple tone mappers: generic (customizable), ACES, filmic, etc.
- Color and tone management: luminance scaling, gamut mapping
- Color grading: exposure, night adaptation, white balance, channel mixer,
shadows/mid-tones/highlights, ASC CDL, contrast, saturation, etc.
- TAA, FXAA, MSAA
- Screen-space lens flares
### glTF 2.0
- Encodings
- [x] Embeded
- [x] Binary
- Primitive Types
- [x] Points
- [x] Lines
- [ ] Line Loop
- [x] Line Strip
- [x] Triangles
- [x] Triangle Strip
- [ ] Triangle Fan
- Animation
- [x] Transform animation
- [x] Linear interpolation
- [x] Morph animation
- [x] Sparse accessor
- [x] Skin animation
- [x] Joint animation
- Extensions
- [x] KHR_draco_mesh_compression
- [x] KHR_lights_punctual
- [x] KHR_materials_clearcoat
- [x] KHR_materials_emissive_strength
- [x] KHR_materials_ior
- [x] KHR_materials_pbrSpecularGlossiness
- [x] KHR_materials_sheen
- [x] KHR_materials_transmission
- [x] KHR_materials_unlit
- [x] KHR_materials_variants
- [x] KHR_materials_volume
- [x] KHR_mesh_quantization
- [x] KHR_texture_basisu
- [x] KHR_texture_transform
### Future
Many other features have been either prototyped or planned:
- IES light profiles/cookies
- Area lights
- Fog
- Color grading
- Bloom
- TAA
- etc.
## Directory structure
This repository not only contains the core Filament engine, but also its supporting libraries
and tools.
- `android`: Android libraries and projects
- `build`: Custom Gradle tasks for Android builds
- `filamat-android`: Filament material generation library (AAR) for Android
- `filament-android`: Filament library (AAR) for Android
- `samples`: Android-specific Filament samples
- `art`: Source for various artworks (logos, PDF manuals, etc.)
- `assets`: 3D assets to use with sample applications
- `build`: CMake build scripts
- `docs`: Documentation
- `math`: Mathematica notebooks used to explore BRDFs, equations, etc.
- `filament`: Filament rendering engine (minimal dependencies)
- `ide`: Configuration files for IDEs (CLion, etc.)
- `ios`: Sample projects for iOS
- `java`: Java bindings for Filament libraries
- `libs`: Libraries
- `bluegl`: OpenGL bindings for macOS, Linux and Windows
- `bluevk`: Vulkan bindings for macOS, Linux, Windows and Android
- `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)
- `filamat`: Material generation library
- `filameshio`: Tiny filamesh parsing library (see also `tools/filamesh`)
- `geometry`: Mesh-related utilities
- `gltfio`: Loader and optional pipeline for glTF 2.0
- `ibl`: IBL generation tools
- `image`: Image filtering and simple transforms
- `imageio`: Image file reading / writing, only intended for internal use
- `math`: Math library
- `rays`: Simple path tracer used for baking ambient occlusion, etc.
- `utils`: Utility library (threads, memory, data structures, etc.)
- `samples`: Sample desktop applications
- `shaders`: Shaders used by `filamat` and `matc`
- `third_party`: External libraries and assets
- `environments`: Environment maps under CC0 license that can be used with `cmgen`
- `models`: Models under permissive licenses
- `textures`: Textures under CC0 license
- `tools`: Host tools
- `cmgen`: Image-based lighting asset generator
- `filamesh`: Mesh converter
- `glslminifier`: Minifies GLSL source code
- `matc`: Material compiler
- `matinfo` Displays information about materials compiled with `matc`
- `mipgen` Generates a series of miplevels from a source image
- `normal-blending`: Tool to blend normal maps
- `resgen` Aggregates binary blobs into embeddable resources
- `roughness-prefilter`: Pre-filters a roughness map from a normal map to reduce aliasing
- `skygen`: Physically-based sky environment texture generator
- `specular-color`: Computes the specular color of conductors based on spectral data
- `web`: JavaScript bindings, documentation, and samples
## Building Filament
### Prerequisites
To build Filament, you must first install the following tools:
- CMake 3.10 (or more recent)
- clang 7.0 (or more recent)
- [ninja 1.8](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages) (or more recent)
To build the Java based components of the project you can optionally install (recommended):
- OpenJDK 1.8 (or more recent)
Additional dependencies may be required for your operating system. Please refer to the appropriate
section below.
Building the `rays` library (used for light baking) is optional and requires the following packages:
- embree 3.0+
- libtbb-dev
To build Filament for Android you must also install the following:
- Android Studio 3.3
- Android SDK
- Android NDK 19 or higher
### Environment variables
Make sure the environment variable `ANDROID_HOME` points to the location of your Android SDK.
By default our build system will attempt to compile the Java bindings. To do so, the environment
variable `JAVA_HOME` should point to the location of your JDK.
When building for WebGL, you'll also need to set `EMSDK`. See [WebAssembly](#webassembly).
### IDE
We recommend using CLion to develop for Filament. Simply open the root directory's CMakeLists.txt
in CLion to obtain a usable project.
### Easy build
Once the required OS specific dependencies listed below are installed, you can use the script
located in `build.sh` to build Filament easily on macOS and Linux.
This script can be invoked from anywhere and will produce build artifacts in the `out/` directory
inside the Filament source tree.
To trigger an incremental debug build:
```
$ ./build.sh debug
```
To trigger an incremental release build:
```
$ ./build.sh release
```
To trigger both incremental debug and release builds:
```
$ ./build.sh debug release
```
To install the libraries and executables in `out/debug/` and `out/release/`, add the `-i` flag.
You can force a clean build by adding the `-c` flag. The script offers more features described
by executing `build.sh -h`.
### Disabling Java builds
By default our build system will attempt to compile the Java bindings. If you wish to skip this
compilation step simply pass the `-j` flag to `build.sh`:
```
$ ./build.sh -j release
```
If you use CMake directly instead of the build script, pass `-DENABLE_JAVA=OFF` to CMake instead.
### Linux
Make sure you've installed the following dependencies:
- `clang-7` or higher
- `libglu1-mesa-dev`
- `libc++-7-dev` (`libcxx-devel` and `libcxx-static` on Fedora) or higher
- `libc++abi-7-dev` (`libcxxabi-static` on Fedora) or higher
- `ninja-build`
- `libxi-dev`
After dependencies have been installed, we highly recommend using the [easy build](#easy-build)
script.
If you'd like to run `cmake` directly rather than using the build script, it can be invoked as
follows, with some caveats that are explained further down.
```
$ mkdir out/cmake-release
$ cd out/cmake-release
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../release/filament ../..
```
Your Linux distribution might default to `gcc` instead of `clang`, if that's the case invoke
`cmake` with the following command:
```
$ mkdir out/cmake-release
$ cd out/cmake-release
# Or use a specific version of clang, for instance /usr/bin/clang-7
$ CC=/usr/bin/clang CXX=/usr/bin/clang++ CXXFLAGS=-stdlib=libc++ \
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../release/filament ../..
```
You can also export the `CC` and `CXX` environment variables to always point to `clang`. Another
solution is to use `update-alternatives` to both change the default compiler, and point to a
specific version of clang:
```
$ update-alternatives --install /usr/bin/clang clang /usr/bin/clang-7 100
$ update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-7 100
$ update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100
$ update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100
```
Finally, invoke `ninja`:
```
$ ninja
```
This will build Filament, its tests and samples, and various host tools.
### macOS
To compile Filament you must have the most recent version of Xcode installed and you need to
make sure the command line tools are setup by running:
```
$ xcode-select --install
```
After installing Java 1.8 you must also ensure that your `JAVA_HOME` environment variable is
properly set. If it doesn't already point to the appropriate JDK, you can simply add the following
to your `.profile`:
```
export JAVA_HOME="$(/usr/libexec/java_home)"
```
Then run `cmake` and `ninja` to trigger a build:
```
$ mkdir out/cmake-release
$ cd out/cmake-release
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../release/filament ../..
$ ninja
```
### iOS
The easiest way to build Filament for iOS is to use `build.sh` and the
`-p ios` flag. For instance to build the debug target:
```
$ ./build.sh -p ios debug
```
See [ios/samples/README.md](./ios/samples/README.md) for more information.
### Windows
The following instructions have been tested on a machine running Windows 10. They should take you
from a machine with only the operating system to a machine able to build and run Filament.
Google employees require additional steps which can be found here [go/filawin](http://go/filawin).
Install the following components:
- [Windows 10 SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk)
- [Visual Studio 2015 or 2017](https://www.visualstudio.com/downloads)
- [Clang 7](http://releases.llvm.org/download.html)
- [Python 3.7](https://www.python.org/ftp/python/3.7.0/python-3.7.0.exe)
- [Cmake 3.13 or later](https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4-win64-x64.msi)
If you're using Visual Studio 2017, you'll also need to install the [LLVM Compiler
Toolchain](https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.llvm-toolchain)
extension.
Open an appropriate Native Tools terminal for the version of Visual Studio you are using:
- VS 2015: VS2015 x64 Native Tools Command Prompt
- VS 2017: x64 Native Tools Command Prompt for VS 2017
You can find these by clicking the start button and typing "x64 native tools".
Create a working directory:
```
> mkdir out/cmake-release
> cd out/cmake-release
```
Create the msBuild project:
```
# Visual Studio 2015:
> cmake -T"LLVM-vs2014" -G "Visual Studio 14 2015 Win64" ../..
# Visual Studio 2017
> cmake ..\.. -T"LLVM" -G "Visual Studio 15 2017 Win64" ^
-DCMAKE_CXX_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" ^
-DCMAKE_C_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" ^
-DCMAKE_LINKER:PATH="C:\Program Files\LLVM\bin\lld-link.exe"
```
Check out the output and make sure Clang for Windows frontend was found. You should see a line
showing the following output. Note that for Visual Studio 2017 this line may list Microsoft's
compiler, but the build will still in fact use Clang and you can proceed.
```
Clang:C:/Program Files/LLVM/msbuild-bin/cl.exe
```
You are now ready to build:
```
> msbuild TNT.sln /t:material_sandbox /m /p:configuration=Release
```
Run it:
```
> samples\Release\material_sandbox.exe ..\..\assets\models\monkey\monkey.obj
```
#### Tips
- To troubleshoot an issue, use verbose mode via `/v:d` flag.
- To build a specific project, use `/t:NAME` flag (e.g: `/t:material_sandbox`).
- To build using more than one core, use parallel build flag: `/m`.
- To build a specific profile, use `/p:configuration=` (e.g: `/p:configuration=Debug`,
`/p:configuration=Release`, and `/p:configuration=RelWithDebInfo`).
- The msBuild project is what is used by Visual Studio behind the scene to build. Building from VS
or from the command-line is the same thing.
#### Building with Ninja on Windows
Alternatively, you can use [Ninja](https://ninja-build.org/) to build for Windows. An MSVC
installation is still necessary.
First, install the dependencies listed under [Windows](#Windows) as well as Ninja. Then open up a
Native Tools terminal as before. Create a build directory inside Filament and run the
following CMake command:
```
> cmake .. -G Ninja ^
-DCMAKE_CXX_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" ^
-DCMAKE_C_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" ^
-DCMAKE_LINKER:PATH="C:\Program Files\LLVM\bin\lld-link.exe" ^
-DCMAKE_BUILD_TYPE=Release
```
You should then be able to build by invoking Ninja:
```
> ninja
```
#### Development tips
- Before shipping a binary, make sure you used Release profile and make sure you have no libc/libc++
dependencies with [Dependency Walker](http://www.dependencywalker.com).
- Application Verifier and gflags.exe can be of great help to trackdown heap corruption. Application
Verifier is easy to setup with a GUI. For gflags, use: `gflags /p /enable pheap-buggy.exe`.
#### Running a simple test
To confirm Filament was properly built, run the following command from the build directory:
```
> samples\material_sandbox.exe --ibl=..\..\samples\envs\pillars ..\..\assets\models\sphere\sphere.obj
```
### Android
Before building Filament for Android, make sure to build Filament for your host. Some of the
host tools are required to successfully build for Android.
Filament can be built for the following architectures:
- ARM 64-bit (`arm64-v8a`)
- ARM 32-bit (`armeabi-v7a`)
- Intel 64-bit (`x86_64`)
- Intel 32-bit (`x86`)
Note that the main target is the ARM 64-bit target. Our implementation is optimized first and
foremost for `arm64-v8a`.
To build Android on Windows machines, see [android/Windows.md](android/Windows.md).
#### Easy Android build
The easiest way to build Filament for Android is to use `build.sh` and the
`-p android` flag. For instance to build the release target:
```
$ ./build.sh -p android release
```
Run `build.sh -h` for more information.
#### ARM 64-bit target (arm64-v8a)
Then invoke CMake in a build directory of your choice, inside of filament's directory:
```
$ mkdir out/android-build-release-aarch64
$ cd out/android-build-release-aarch64
$ cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=../../build/toolchain-aarch64-linux-android.cmake \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../android-release/filament ../..
```
And then invoke `ninja`:
```
$ ninja install
```
or
```
$ ninja install/strip
```
This will generate Filament's Android binaries in `out/android-release`. This location is important
to build the Android Studio projects located in `filament/android`. After install, the library
binaries should be found in `out/android-release/filament/lib/arm64-v8a`.
#### ARM 32-bit target (armeabi-v7a)
Then invoke CMake in a build directory of your choice, inside of filament's directory:
```
$ mkdir out/android-build-release-arm
$ cd out/android-build-release-arm
$ cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=../../build/toolchain-arm7-linux-android.cmake \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../android-release/filament ../..
```
And then invoke `ninja`:
```
$ ninja install
```
or
```
$ ninja install/strip
```
This will generate Filament's Android binaries in `out/android-release`. This location is important
to build the Android Studio projects located in `filament/android`. After install, the library
binaries should be found in `out/android-release/filament/lib/armeabi-v7a`.
#### Intel 64-bit target (x86_64)
Then invoke CMake in a build directory of your choice, sibling of filament's directory:
```
$ mkdir out/android-build-release-x86_64
$ cd out/android-build-release-x86_64
$ cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=../../filament/build/toolchain-x86_64-linux-android.cmake \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../out/android-release/filament ../..
```
And then invoke `ninja`:
```
$ ninja install
```
or
```
$ ninja install/strip
```
This will generate Filament's Android binaries in `out/android-release`. This location is important
to build the Android Studio projects located in `filament/android`. After install, the library
binaries should be found in `out/android-release/filament/lib/x86_64`.
#### Intel 32-bit target (x86)
Then invoke CMake in a build directory of your choice, sibling of filament's directory:
```
$ mkdir out/android-build-release-x86
$ cd out/android-build-release-x86
$ cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=../../filament/build/toolchain-x86-linux-android.cmake \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../out/android-release/filament ../..
```
And then invoke `ninja`:
```
$ ninja install
```
or
```
$ ninja install/strip
```
This will generate Filament's Android binaries in `out/android-release`. This location is important
to build the Android Studio projects located in `filament/android`. After install, the library
binaries should be found in `out/android-release/filament/lib/x86`.
### AAR
Before you attempt to build the AAR, make sure you've compiled and installed the native libraries
as explained in the sections above. You must have the following ABIs built in
`out/android-release/filament/lib/`:
- `arm64-v8a`
- `armeabi-v7a`
- `x86_64`
- `x86`
To build Filament's AAR simply open the Android Studio project in `android/filament-android`. The
AAR is a universal AAR that contains all supported build targets:
- `arm64-v8a`
- `armeabi-v7a`
- `x86_64`
- `x86`
To filter out unneeded ABIs, rely on the `abiFilters` of the project that links against Filament's
AAR.
Alternatively you can build the AAR from the command line by executing the following the
`android/filament-android` directory:
```
$ ./gradlew -Pfilament_dist_dir=../../out/android-release/filament assembleRelease
```
The `-Pfilament_dist_dir` can be used to specify a different installation directory (it must match
the CMake install prefix used in the previous steps).
### Using Filament's AAR
Create a new module in your project and select _Import .JAR or .AAR Package_ when prompted. Make
sure to add the newly created module as a dependency to your application.
If you do not wish to include all supported ABIs, make sure to create the appropriate flavors in
your Gradle build file. For example:
```
flavorDimensions 'cpuArch'
productFlavors {
arm8 {
dimension 'cpuArch'
ndk {
abiFilters 'arm64-v8a'
}
}
arm7 {
dimension 'cpuArch'
ndk {
abiFilters 'armeabi-v7a'
}
}
x86_64 {
dimension 'cpuArch'
ndk {
abiFilters 'x86_64'
}
}
x86 {
dimension 'cpuArch'
ndk {
abiFilters 'x86'
}
}
universal {
dimension 'cpuArch'
}
}
```
### WebAssembly
The core Filament library can be cross-compiled to WebAssembly from either macOS or Linux. To get
started, follow the instructions for building Filament on your platform ([macOS](#macos) or
[linux](#linux)), which will ensure you have the proper dependencies installed.
Next, you need to install the Emscripten SDK. The following instructions show how to install the
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/a77638d.zip > emsdk.zip
unzip emsdk.zip
mv emsdk-* emsdk
cd emsdk
./emsdk update
./emsdk install sdk-1.38.28-64bit
./emsdk activate sdk-1.38.28-64bit
```
After this you can invoke the [easy build](#easy-build) script as follows:
```
export EMSDK=<your chosen home for the emscripten SDK>
./build.sh -p webgl release
```
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:
```
cd out/cmake-webgl-release/web/samples
python3 -m http.server # Python 3
python -m SimpleHTTPServer # Python 2.7
```
You can then open http://localhost:8000/suzanne.html in your web browser.
Alternatively, if you have node installed you can use the
[live-server](https://www.npmjs.com/package/live-server) package, which automatically refreshes the
web page when it detects a change.
Each sample app has its own handwritten html file. Additionally the server folder contains assets
such as meshes, textures, and materials.
## Running the native samples
The `samples/` directory contains several examples of how to use Filament with SDL2.
Some of the samples accept FBX/OBJ meshes while others rely on the `filamesh` file format. To
generate a `filamesh ` file from an FBX/OBJ asset, run the `filamesh` tool
(`./tools/filamesh/filamesh` in your build directory):
```
filamesh ./assets/models/monkey/monkey.obj monkey.filamesh
```
Most samples accept an IBL that must be generated using the `cmgen` tool (`./tools/filamesh/cmgen`
in your build directory). These sample apps expect a path to a directory containing the '.rgb32f'
files for the IBL (which are PNGs containing `R11F_G11F_B10F` data). To generate an IBL simply use
this command:
```
cmgen -x ./ibls/ my_ibl.exr
```
The source environment map can be a PNG (8 or 16 bit), a PSD (16 or 32 bit), an HDR or an OpenEXR
file. The environment map can be an equirectangular projection, a horizontal cross, a vertical
cross, or a list of cubemap faces (horizontal or vertical).
`cmgen` will automatically create a directory based on the name of the source environment map. In
the example above, the final directory will be `./ibls/my_ibl/`. This directory should contain the
pre-filtered environment map (one file per cubemap face and per mip level), the environment map
texture for the skybox and a text file containing the spherical harmonics for indirect diffuse
lighting.
If you prefer a blurred background, run `cmgen` with this flag: `--extract-blur=0.1`. The numerical
value is the desired roughness between 0 and 1.
## Rendering with Filament
@@ -743,7 +197,7 @@ Renderer* renderer = engine->createRenderer();
To render a frame you must then create a `View`, a `Scene` and a `Camera`:
```c++
Camera* camera = engine->createCamera();
Camera* camera = engine->createCamera(EntityManager::get().create());
View* view = engine->createView();
Scene* scene = engine->createScene();
@@ -790,22 +244,11 @@ if (renderer->beginFrame(swapChain)) {
```
For complete examples of Linux, macOS and Windows Filament applications, look at the source files
in the `samples/` directory. These samples are all based on `samples/app/` which contains the code
that creates a native window with SDL2 and initializes the Filament engine, renderer and views.
in the `samples/` directory. These samples are all based on `libs/filamentapp/` which contains the
code that creates a native window with SDL2 and initializes the Filament engine, renderer and views.
### Java on Linux, macOS and Windows
After building Filament, you can use `filament-java.jar` and its companion `filament-jni` native
library to use Filament in desktop Java applications.
You must always first initialize Filament by calling `Filament.init()`.
You can use Filament either with AWT or Swing, using respectively a `FilamentCanvas` or a
`FilamentPanel`.
Following the steps above (how to use Filament from native code), create an `Engine` and a
`Renderer`, but instead of calling `beginFrame` and `endFrame` on the renderer itself, call
these methods on `FilamentCanvas` or `FilamentPanel`.
For more information on how to prepare environment maps for image-based lighting please refer to
[BUILDING.md](https://github.com/google/filament/blob/main/BUILDING.md#running-the-native-samples).
### Android
@@ -823,23 +266,12 @@ creating the swap chain in the `onNativeWindowChanged()` callback.
### iOS
See `ios/samples` for examples of using Filament on iOS.
Filament is supported on iOS 11.0 and above. See `ios/samples` for examples of using Filament on
iOS.
Filament on iOS is largely the same as native rendering with C++. A `CAEAGLLayer` or `CAMetalLayer`
is passed to the `createSwapChain` method. Filament for iOS supports both OpenGL ES and Vulkan via
MoltenVK.
## Generating C++ documentation
To generate the documentation you must first install `doxygen` and `graphviz`, then run the
following commands:
```
$ cd filament/filament
$ doxygen docs/doxygen/filament.doxygen
```
Finally simply open `docs/html/index.html` in your web browser.
is passed to the `createSwapChain` method. Filament for iOS supports both Metal (preferred) and
OpenGL ES.
## Assets
@@ -847,26 +279,74 @@ To get started you can use the textures and environment maps found respectively
`third_party/textures` and `third_party/environments`. These assets are under CC0 license. Please
refer to their respective `URL.txt` files to know more about the original authors.
## Dependencies
One of our design goals is that Filament itself should have no dependencies or as few dependencies
as possible. The current external dependencies of the runtime library include:
- STL
- robin-map (header only library)
When building with Vulkan enabled, we have a few additional small dependencies:
- vkmemalloc
- smol-v
Host tools (such as `matc` or `cmgen`) can use external dependencies freely.
Environments must be pre-processed using
[`cmgen`](https://github.com/google/filament/blob/main/BUILDING.md#running-the-native-samples) or
using the `libiblprefilter` library.
## How to make contributions
Please read and follow the steps in [CONTRIBUTING.md](/CONTRIBUTING.md). Make sure you are
familiar with the [code style](/CODE_STYLE.md).
## Directory structure
This repository not only contains the core Filament engine, but also its supporting libraries
and tools.
- `android`: Android libraries and projects
- `filamat-android`: Filament material generation library (AAR) for Android
- `filament-android`: Filament library (AAR) for Android
- `filament-utils-android`: Extra utilities (KTX loader, math types, etc.)
- `gltfio-android`: Filament glTF loading library (AAR) for Android
- `samples`: Android-specific Filament samples
- `art`: Source for various artworks (logos, PDF manuals, etc.)
- `assets`: 3D assets to use with sample applications
- `build`: CMake build scripts
- `docs`: Documentation
- `math`: Mathematica notebooks used to explore BRDFs, equations, etc.
- `filament`: Filament rendering engine (minimal dependencies)
- `backend`: Rendering backends/drivers (Vulkan, Metal, OpenGL/ES)
- `ide`: Configuration files for IDEs (CLion, etc.)
- `ios`: Sample projects for iOS
- `libs`: Libraries
- `bluegl`: OpenGL bindings for macOS, Linux and Windows
- `bluevk`: Vulkan bindings for macOS, Linux, Windows and Android
- `camutils`: Camera manipulation utilities
- `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)
- `filamat`: Material generation library
- `filamentapp`: SDL2 skeleton to build sample apps
- `filameshio`: Tiny filamesh parsing library (see also `tools/filamesh`)
- `geometry`: Mesh-related utilities
- `gltfio`: Loader for glTF 2.0
- `ibl`: IBL generation tools
- `image`: Image filtering and simple transforms
- `imageio`: Image file reading / writing, only intended for internal use
- `matdbg`: DebugServer for inspecting shaders at run-time (debug builds only)
- `math`: Math library
- `mathio`: Math types support for output streams
- `utils`: Utility library (threads, memory, data structures, etc.)
- `viewer`: glTF viewer library (requires gltfio)
- `samples`: Sample desktop applications
- `shaders`: Shaders used by `filamat` and `matc`
- `third_party`: External libraries and assets
- `environments`: Environment maps under CC0 license that can be used with `cmgen`
- `models`: Models under permissive licenses
- `textures`: Textures under CC0 license
- `tools`: Host tools
- `cmgen`: Image-based lighting asset generator
- `filamesh`: Mesh converter
- `glslminifier`: Minifies GLSL source code
- `matc`: Material compiler
- `matinfo` Displays information about materials compiled with `matc`
- `mipgen` Generates a series of miplevels from a source image
- `normal-blending`: Tool to blend normal maps
- `resgen` Aggregates binary blobs into embeddable resources
- `roughness-prefilter`: Pre-filters a roughness map from a normal map to reduce aliasing
- `specular-color`: Computes the specular color of conductors based on spectral data
- `web`: JavaScript bindings, documentation, and samples
## License
Please see [LICENSE](/LICENSE).
+171
View File
@@ -0,0 +1,171 @@
# Filament Release Guide
This guide makes use of some "environment variables":
- $RELEASE = the new version of Filament we are releasing today. (e.g., 1.9.3)
- $NEXT_RELEASE = the version we plan to release next week (e.g., 1.9.4)
Before starting, ensure that each of these branches is up-to-date with origin:
- release
- rc/$RELEASE
- main
## 0. Make sure the rc/$RELEASE branch has the correct version.
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.
Checkout main and run the following command to bump Filament's version to $RELEASE:
```
build/common/bump-version.sh $RELEASE
```
Commit changes to main with the title:
```
Release Filament $RELEASE
```
Do not push to origin yet.
## 3. Cherry-pick RELEASE_NOTES change from rc branch to main.
```
git cherry-pick rc/$RELEASE
```
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.
```
git add -u
git commit --amend --no-edit
```
## 4. Run release script.
```
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.
```
git push origin release
```
## 6. 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).
This step is optional. The old rc branch may be left alive for a few weeks for posterity.
```
git push origin --delete rc/$RELEASE
```
## 8. Bump the version on the new rc branch to $NEXT_RELEASE.
```
git checkout rc/$NEXT_RELEASE
build/common/bump-version.sh $NEXT_RELEASE
```
Commit the changes to rc/$NEXT_RELEASE with the title:
```
Bump version to $NEXT_RELEASE
```
## 9. Push main.
```
git push origin main
```
## 10. Push the new rc branch.
```
git push origin -u rc/$NEXT_RELEASE
```
## 11. 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.
+1070 -1
View File
File diff suppressed because it is too large Load Diff
+9
View File
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
/.idea/caches
/.idea/gradle.xml
.DS_Store
/build/
+41 -19
View File
@@ -2,13 +2,32 @@
## Prerequisites
In addition to the requirements for [building Filament on Windows](../README.md#windows), you'll
In addition to the requirements for [building Filament on Windows](../BUILDING.md#windows), you'll
need the Android SDK and NDK. See [Getting Started with the
NDK](https://developer.android.com/ndk/guides/) for detailed installation instructions.
You'll also need [Ninja 1.8](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages) (or
more recent) and [Git for Windows](https://git-scm.com/download/win) to clone the repository and run
Bash scripts.
Ensure the `%ANDROID_HOME%` environment variable is set to your Android SDK installation location.
All of the following commands should be executed in a Visual Studio x64 Native Tools Command Prompt.
On Windows, we require VS2019 for building the host tools. All of the following commands should be
executed in a *Visual Studio x64 Native Tools Command Prompt for VS 2019*.
### A Note About Python 3
Python 3 is required. If CMake errors because it cannot find Python 3:
```
Could NOT find PythonInterp: Found unsuitable version "1.4", but required is at least "3"
```
then add the following flag to the CMake invocations:
```
-DPYTHON_EXECUTABLE:FILEPATH=\path\to\python3
```
## Desktop Tools
@@ -21,11 +40,8 @@ mkdir out\cmake-release
cd out\cmake-release
cmake ^
-G Ninja ^
-DCMAKE_CXX_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" ^
-DCMAKE_C_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" ^
-DCMAKE_LINKER:PATH="C:\Program Files\LLVM\bin\lld-link.exe" ^
-DCMAKE_INSTALL_PREFIX=..\release\filament ^
-DENABLE_JAVA=NO ^
-DFILAMENT_ENABLE_JAVA=NO ^
-DCMAKE_BUILD_TYPE=Release ^
..\..
```
@@ -39,6 +55,12 @@ ninja matc resgen cmgen
The build should succeed and a `ImportExecutables-Release.cmake` file should automatically be
created at Filament's root directory.
If you are going to build Filament samples you should install desktop host tools:
```
ninja install
```
## Build
1. Create the build directories.
@@ -96,28 +118,28 @@ ninja install
## Generate AAR
The Gradle project used to generate the AAR is located at `<filament>\android\filament-android`.
The Gradle project used to generate the AAR is located at `<filament>\android`.
```
cd android\filament-android
gradlew -Pfilament_dist_dir=..\..\out\android-release\filament assembleRelease
copy build\outputs\aar\filament-android-release.aar ..\..\out\
cd android
gradlew -Pcom.google.android.filament.dist-dir=..\out\android-release\filament assembleRelease
copy filament-android\build\outputs\aar\filament-android-release.aar ..\..\out\
```
If you're only interested in building for a single ABI, you'll need to add an `abiFilters` override
inside the `build.gradle` file underneath `defaultConfig`:
If you're only interested in building for a single ABI, you'll need to pass a `com.google.android.filament.abis` parameter:
```
ndk {
abiFilters 'arm64-v8a'
}
gradlew -Pcom.google.android.filament.dist-dir=..\out\android-release\filament assembleRelease -Pcom.google.android.filament.abis=x86
```
If you're only interested in building SDK, you may skip samples build by passing a `com.google.android.filament.skip-samples` flag:
```
gradlew -Pcom.google.android.filament.dist-dir=..\out\android-release\filament assembleRelease -Pfilament_skip_samples
```
See
[NdkOptions](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.NdkOptions.html#com.android.build.gradle.internal.dsl.NdkOptions:abiFilters)
for more information.
`filament-android-release.aar` should now be present at `<filament>\out\filament-android-release.aar`.
See [Using Filament's AAR](../README.md#using-filaments-aar) for usage instructions.
See [Using Filament's AAR](../README.md) for usage instructions.
+224
View File
@@ -0,0 +1,224 @@
// This script accepts the following parameters:
//
// com.google.android.filament.dist-dir
// Path to the Filament distribution/install directory for Android
// (produced by make/ninja install). This directory must contain lib/arm64-v8a/ etc.
//
// com.google.android.filament.tools-dir
// Path to the Filament distribution/install directory for desktop.
// This directory must contain bin/matc.
//
// com.google.android.filament.exclude-vulkan
// When set, support for Vulkan will be excluded.
//
// com.google.android.filament.matdbg
// When set, enables matdbg, disables shader optimizations
//
// com.google.android.filament.skip-samples
// Exclude samples from the project. Useful to speed up compilation.
//
// com.google.android.filament.abis
// List of supported ABIs to build as a comma separated list. Available options are:
// arm64-v8a, armeabi-v7a, x86_64, x86, all
// Defaults to all.
//
// Example:
// ./gradlew -Pcom.google.android.filament.dist-dir=../dist-android-release \
// -Pcom.google.android.filament.abis=x86 \
// assembleRelease
// Publishing to Maven Central:
// - Build and upload artifacts with ./gradlew publish
// - Close and release staging repo on Nexus with ./gradlew closeAndReleaseRepository
//
// The following is needed in ~/gradle/gradle.properties:
//
// SONATYPE_NEXUS_USERNAME=nexus_user
// SONATYPE_NEXUS_PASSWORD=nexus_password
//
// nexusUsername=nexus_user
// nexusPassword=nexus_password
//
// signing.keyId=pgp_key_id
// signing.password=pgp_key_password
// signing.secretKeyRingFile=/Users/user/.gnupg/maven_signing.key
//
buildscript {
def path = providers
.gradleProperty("com.google.android.filament.dist-dir")
.forUseAtConfigurationTime().get()
def directory = objects.fileProperty().fileValue(new File(path)).getAsFile().get()
def filamentPath = directory.absolutePath
// Our CMake scripts require a forward-slash path for the FILAMENT_DIST_DIR
// variable, so here we convert the native path to a forward-slash path.
filamentPath = filamentPath.replace(File.separator, '/')
// 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 abis = ["arm64-v8a", "armeabi-v7a", "x86_64", "x86"]
def newAbis = providers
.gradleProperty("com.google.android.filament.abis")
.forUseAtConfigurationTime()
.get()
.split(',')
if (!newAbis.contains("all")) {
abis = newAbis
}
ext.versions = [
'minSdk': 19,
'targetSdk': 31,
'compileSdk': 31,
'kotlin': '1.7.10',
'kotlin_coroutines': '1.6.1',
'buildTools': '33.0.0',
'ndk': '25.0.8775105'
]
ext.deps = [
'androidx': [
'annotations': "androidx.annotation:annotation:1.3.0",
'core': "androidx.core:core:1.7.0",
],
'kotlin': "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}",
'coroutines': [
'core': "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.kotlin_coroutines}",
'android': "org.jetbrains.kotlinx:kotlinx-coroutines-android:${versions.kotlin_coroutines}",
]
]
dependencies {
// NOTE: See TODO in gradle.properties once we move to Gradle 7.4
classpath 'com.android.tools.build:gradle:7.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
}
ext.cmakeArgs = [
"--no-warn-unused-cli",
"-DANDROID_PIE=ON",
"-DANDROID_PLATFORM=21",
"-DANDROID_STL=c++_static",
"-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()
]
ext.cppFlags = [
"-std=c++17",
"-fno-stack-protector",
"-fno-exceptions",
"-fno-unwind-tables",
"-fno-asynchronous-unwind-tables",
"-fno-rtti",
"-ffast-math",
"-ffp-contract=fast",
"-fvisibility-inlines-hidden",
"-fvisibility=hidden",
"-fomit-frame-pointer",
"-ffunction-sections",
"-fdata-sections",
"-no-canonical-prefixes",
"-Wformat",
"-Werror=format-security",
"-Wno-unused-command-line-argument",
"-Wl,--gc-sections",
"-Wl,-Bsymbolic-functions",
"-Wl,--hash-style=both", // Required to support API levels below 23
]
ext.abis = abis
repositories {
mavenCentral()
google()
}
}
plugins {
id 'io.codearte.nexus-staging' version '0.30.0'
}
// Nexus Staging configuration
// See https://github.com/Codearte/gradle-nexus-staging-plugin/
nexusStaging {
packageGroup = 'com.google.android'
stagingProfileId = '9a75a224a4f17b'
}
subprojects {
group = GROUP
version = VERSION_NAME
repositories {
mavenCentral()
google()
}
if (!name.startsWith("sample")) {
apply plugin: 'com.android.library'
android {
buildToolsVersion versions.buildTools
compileSdkVersion versions.compileSdk
ndkVersion versions.ndk
defaultConfig {
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
externalNativeBuild {
cmake {
arguments.addAll(rootProject.ext.cmakeArgs)
cppFlags.addAll(rootProject.ext.cppFlags)
}
}
ndk {
abiFilters(*rootProject.ext.abis)
}
consumerProguardFiles '../proguard-rules.pro'
}
externalNativeBuild {
cmake {
version "3.19.0+"
path "CMakeLists.txt"
}
}
sourceSets {
main {
jni.srcDirs "src/main/cpp"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
}
}
gradle.taskGraph.whenReady {
gradle.taskGraph.allTasks.each {
it.onlyIf {
!it.project.ext.has('isSample') ||
!project.hasProperty('com.google.android.filament.skip-samples')
}
}
}
-230
View File
@@ -1,230 +0,0 @@
// This script accepts the following parameters:
//
// filament_tools_dir
// Path to the Filament distribution/install directory for desktop
// (produced by make/ninja install). This directory must contain bin/matc
//
// Example:
// ./gradlew -Pfilament_tools_dir=../../dist-release assembleDebug
import java.nio.file.Paths
import org.gradle.internal.os.OperatingSystem
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.LogLevel;
def filamentToolsPath = file("../../../../out/release/filament")
if (project.hasProperty("filament_tools_dir")) {
filamentToolsPath = file("$filament_tools_dir")
}
List<File> getBinaries(String name, File toolsPath) {
def tool = ["/bin/${name}.exe", "/bin/${name}"]
def toolFullPath = tool.collect { path -> Paths.get(toolsPath.absolutePath, path).toFile() }
// Ensure that at least one matc binary and Filament library is present
if (!toolFullPath.any { path -> file(path).exists() }) {
throw new StopActionException("No ${name} binary could be found in " + toolsPath +
"/bin. Ensure Filament has been built/installed before building this app.")
}
return toolFullPath
}
ext.matcFullPath = getBinaries('matc', filamentToolsPath)
ext.cmgenFullPath = getBinaries('cmgen', filamentToolsPath)
ext.filameshFullPath = getBinaries('filamesh', filamentToolsPath)
ext.resgenFullPath = getBinaries('resgen', filamentToolsPath)
class LogOutputStream extends ByteArrayOutputStream {
private final Logger logger;
private final LogLevel level;
public LogOutputStream(Logger logger, LogLevel level) {
this.logger = logger;
this.level = level;
}
public Logger getLogger() {
return logger;
}
public LogLevel getLevel() {
return level;
}
@Override
public void flush() {
logger.log(level, toString());
reset();
}
}
// Custom task to compile material files using matc
// This task handles incremental builds
class MaterialCompiler extends DefaultTask {
File matcPath
@SuppressWarnings("GroovyUnusedDeclaration")
@InputDirectory
File inputDir
@OutputDirectory
File outputDir
MaterialCompiler() {
matcPath = OperatingSystem.current().isWindows() ?
project.ext.matcFullPath[0] : project.ext.matcFullPath[1]
}
@SuppressWarnings("GroovyUnusedDeclaration")
@TaskAction
void execute(IncrementalTaskInputs inputs) {
if (!inputs.incremental) {
project.delete(project.fileTree(outputDir).matching { include '*.filamat' })
}
inputs.outOfDate { InputFileDetails outOfDate ->
if (outOfDate.file.directory) return
def file = outOfDate.file
def out = new LogOutputStream(logger, LogLevel.LIFECYCLE)
def err = new LogOutputStream(logger, LogLevel.ERROR)
def header = ("Compiling material " + file + "\n").getBytes()
out.write(header)
out.flush()
project.exec {
standardOutput out
errorOutput err
executable "${matcPath}"
args('-a', 'all', '-p', 'mobile', '-o', getOutputFile(file), file)
}
}
inputs.removed { InputFileDetails removed ->
getOutputFile(removed.file).delete()
}
}
File getOutputFile(final File file) {
return new File(outputDir, file.name[0..file.name.lastIndexOf('.')] + 'filamat')
}
}
// Custom task to process IBLs using cmgen
// This task handles incremental builds
class IblGenerator extends DefaultTask {
File cmgenPath
@SuppressWarnings("GroovyUnusedDeclaration")
@InputFile
File inputFile
@OutputDirectory
File outputDir
IblGenerator() {
cmgenPath = OperatingSystem.current().isWindows() ?
project.ext.cmgenFullPath[0] : project.ext.cmgenFullPath[1]
}
@SuppressWarnings("GroovyUnusedDeclaration")
@TaskAction
void execute(IncrementalTaskInputs inputs) {
if (!inputs.incremental) {
project.delete(project.fileTree(outputDir).matching { include '*' })
}
inputs.outOfDate { InputFileDetails outOfDate ->
def file = outOfDate.file
def out = new LogOutputStream(logger, LogLevel.LIFECYCLE)
def err = new LogOutputStream(logger, LogLevel.ERROR)
def header = ("Generating IBL " + file + "\n").getBytes()
out.write(header)
out.flush()
project.exec {
standardOutput out
errorOutput err
executable "${cmgenPath}"
args('-x', outputDir, file)
}
project.exec {
standardOutput out
errorOutput err
executable "${cmgenPath}"
args('--format=rgb32f', '--extract-blur=0.08', "--extract=${outputDir.absolutePath}", file)
}
}
inputs.removed { InputFileDetails removed ->
getOutputFile(removed.file).delete()
}
}
File getOutputFile(final File file) {
return new File(outputDir, file.name[0..file.name.lastIndexOf('.') - 1])
}
}
// Custom task to compile mesh files using filamesh
// This task handles incremental builds
class MeshCompiler extends DefaultTask {
File filameshPath
@SuppressWarnings("GroovyUnusedDeclaration")
@InputFile
File inputFile
@OutputDirectory
File outputDir
MeshCompiler() {
filameshPath = OperatingSystem.current().isWindows() ?
project.ext.filameshFullPath[0] : project.ext.filameshFullPath[1]
}
@SuppressWarnings("GroovyUnusedDeclaration")
@TaskAction
void execute(IncrementalTaskInputs inputs) {
if (!inputs.incremental) {
project.delete(project.fileTree(outputDir).matching { include '*.filamesh' })
}
inputs.outOfDate { InputFileDetails outOfDate ->
def file = outOfDate.file
def out = new LogOutputStream(logger, LogLevel.LIFECYCLE)
def err = new LogOutputStream(logger, LogLevel.ERROR)
def header = ("Compiling mesh " + file + "\n").getBytes()
out.write(header)
out.flush()
project.exec {
standardOutput out
errorOutput err
executable "${filameshPath}"
args(file, getOutputFile(file))
}
}
inputs.removed { InputFileDetails removed ->
getOutputFile(removed.file).delete()
}
}
File getOutputFile(final File file) {
return new File(outputDir, file.name[0..file.name.lastIndexOf('.')] + 'filamesh')
}
}
task compileMaterials(type: MaterialCompiler)
task generateIbl(type: IblGenerator)
task compileMesh(type: MeshCompiler)
+9
View File
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
/.idea/caches
/.idea/gradle.xml
.DS_Store
/build/
+16
View File
@@ -0,0 +1,16 @@
plugins {
id 'groovy-gradle-plugin'
}
gradlePlugin {
plugins {
create("filament-tools-plugin") {
id = "filament-tools-plugin"
implementationClass = "FilamentToolsPlugin"
}
}
}
repositories {
mavenCentral()
}
@@ -0,0 +1,345 @@
// This plugin accepts the following parameters:
//
// com.google.android.filament.tools-dir
// Path to the Filament distribution/install directory for desktop.
// This directory must contain bin/matc.
//
// com.google.android.filament.exclude-vulkan
// When set, support for Vulkan will be excluded.
//
// Example:
// ./gradlew -Pcom.google.android.filament.tools-dir=../../dist-release assembleDebug
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.provider.ProviderFactory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.FileType
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.Logger
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.incremental.InputFileDetails
import org.gradle.api.model.ObjectFactory
import org.gradle.internal.os.OperatingSystem
import org.gradle.process.ExecOperations
import org.gradle.work.ChangeType
import org.gradle.work.Incremental
import org.gradle.work.InputChanges
import java.nio.file.Paths
import javax.inject.Inject
abstract class TaskWithBinary extends DefaultTask {
private final String binaryName
private Property<String> binaryPath = null
TaskWithBinary(String name) {
binaryName = name
}
@Inject abstract ObjectFactory getObjects()
@Inject abstract ProviderFactory getProviders()
@Input
Property<String> getBinary() {
if (binaryPath == null) {
def tool = ["/bin/${binaryName}.exe", "/bin/${binaryName}"]
def fullPath = tool.collect { path ->
def filamentToolsPath = providers
.gradleProperty("com.google.android.filament.tools-dir")
.forUseAtConfigurationTime().get()
def directory = objects.fileProperty()
.fileValue(new File(filamentToolsPath)).getAsFile().get()
Paths.get(directory.absolutePath, path).toFile()
}
binaryPath = objects.property(String.class)
binaryPath.set(
(OperatingSystem.current().isWindows() ? fullPath[0] : fullPath[1]).toString())
}
return binaryPath
}
}
class LogOutputStream extends ByteArrayOutputStream {
private final Logger logger
private final LogLevel level
LogOutputStream(Logger logger, LogLevel level) {
this.logger = logger
this.level = level
}
@Override
void flush() {
logger.log(level, toString())
reset()
}
}
// Custom task to compile material files using matc
// This task handles incremental builds
abstract class MaterialCompiler extends TaskWithBinary {
@Incremental
@InputDirectory
abstract DirectoryProperty getInputDir()
@OutputDirectory
abstract DirectoryProperty getOutputDir()
@Inject abstract FileSystemOperations getFs()
@Inject abstract ExecOperations getExec()
@Inject abstract ObjectFactory getObjects()
@Inject abstract ProviderFactory getProviders()
MaterialCompiler() {
super("matc")
}
@TaskAction
void execute(InputChanges inputs) {
if (!inputs.incremental) {
fs.delete({
delete(objects.fileTree().from(outputDir).matching { include '*.filamat' })
})
}
inputs.getFileChanges(inputDir).each { InputFileDetails change ->
if (change.fileType == FileType.DIRECTORY) return
def file = change.file
if (change.changeType == ChangeType.REMOVED) {
getOutputFile(file).delete()
} else {
def out = new LogOutputStream(logger, LogLevel.LIFECYCLE)
def err = new LogOutputStream(logger, LogLevel.ERROR)
def header = ("Compiling material " + file + "\n").getBytes()
out.write(header)
out.flush()
if (!new File(binary.get()).exists()) {
throw new GradleException("Could not find ${binary.get()}." +
" Ensure Filament has been built/installed before building this app.")
}
def matcArgs = []
def exclude_vulkan = providers
.gradleProperty("com.google.android.filament.exclude-vulkan")
.forUseAtConfigurationTime().present
if (!exclude_vulkan) {
matcArgs += ['-a', 'vulkan']
}
matcArgs += ['-a', 'opengl', '-p', 'mobile', '-o', getOutputFile(file), file]
exec.exec {
standardOutput out
errorOutput err
executable "${binary.get()}"
args matcArgs
}
}
}
}
File getOutputFile(final File file) {
return outputDir.file(file.name[0..file.name.lastIndexOf('.')] + 'filamat').get().asFile
}
}
// Custom task to process IBLs using cmgen
// This task handles incremental builds
abstract class IblGenerator extends TaskWithBinary {
@Input
@Optional
abstract Property<String> getCmgenArgs()
@Incremental
@InputFile
abstract RegularFileProperty getInputFile()
@OutputDirectory
abstract DirectoryProperty getOutputDir()
@Inject abstract FileSystemOperations getFs()
@Inject abstract ExecOperations getExec()
@Inject abstract ObjectFactory getObjects()
IblGenerator() {
super("cmgen")
}
@TaskAction
void execute(InputChanges inputs) {
if (!inputs.incremental) {
fs.delete({
delete(objects.fileTree().from(outputDir).matching { include '*' })
})
}
inputs.getFileChanges(inputFile).each { InputFileDetails change ->
if (change.fileType == FileType.DIRECTORY) return
def file = change.file
if (change.changeType == ChangeType.REMOVED) {
getOutputFile(file).delete()
} else {
def out = new LogOutputStream(logger, LogLevel.LIFECYCLE)
def err = new LogOutputStream(logger, LogLevel.ERROR)
def header = ("Generating IBL " + file + "\n").getBytes()
out.write(header)
out.flush()
if (!new File(binary.get()).exists()) {
throw new GradleException("Could not find ${binary.get()}." +
" Ensure Filament has been built/installed before building this app.")
}
def outputPath = outputDir.get().asFile
def commandArgs = cmgenArgs.getOrNull()
if (commandArgs == null) {
commandArgs =
'-q -x ' + outputPath + ' --format=rgb32f ' +
'--extract-blur=0.08 --extract=' + outputPath.absolutePath
}
commandArgs = commandArgs + " " + file
exec.exec {
standardOutput out
errorOutput err
executable "${binary.get()}"
args(commandArgs.split())
}
}
}
}
File getOutputFile(final File file) {
return outputDir.file(file.name[0..file.name.lastIndexOf('.') - 1]).get().asFile
}
}
// Custom task to compile mesh files using filamesh
// This task handles incremental builds
abstract class MeshCompiler extends TaskWithBinary {
@Incremental
@InputFile
abstract RegularFileProperty getInputFile()
@OutputDirectory
abstract DirectoryProperty getOutputDir()
@Inject abstract FileSystemOperations getFs()
@Inject abstract ExecOperations getExec()
MeshCompiler() {
super("filamesh")
}
@TaskAction
void execute(InputChanges inputs) {
if (!inputs.incremental) {
fs.delete({
delete(objects.fileTree().from(outputDir).matching { include '*.filamesh' })
})
}
inputs.getFileChanges(inputFile).each { InputFileDetails change ->
if (change.fileType == FileType.DIRECTORY) return
def file = change.file
if (change.changeType == ChangeType.REMOVED) {
getOutputFile(file).delete()
} else {
def out = new LogOutputStream(logger, LogLevel.LIFECYCLE)
def err = new LogOutputStream(logger, LogLevel.ERROR)
def header = ("Compiling mesh " + file + "\n").getBytes()
out.write(header)
out.flush()
if (!new File(binary.get()).exists()) {
throw new GradleException("Could not find ${binary.get()}." +
" Ensure Filament has been built/installed before building this app.")
}
exec.exec {
standardOutput out
errorOutput err
executable "${binary.get()}"
args(file, getOutputFile(file))
}
}
}
}
File getOutputFile(final File file) {
return outputDir.file(file.name[0..file.name.lastIndexOf('.')] + 'filamesh').get().asFile
}
}
class FilamentToolsPluginExtension {
DirectoryProperty materialInputDir
DirectoryProperty materialOutputDir
String cmgenArgs
RegularFileProperty iblInputFile
DirectoryProperty iblOutputDir
RegularFileProperty meshInputFile
DirectoryProperty meshOutputDir
}
class FilamentToolsPlugin implements Plugin<Project> {
void apply(Project project) {
def extension = project.extensions.create('filamentTools', FilamentToolsPluginExtension)
extension.materialInputDir = project.objects.directoryProperty()
extension.materialOutputDir = project.objects.directoryProperty()
extension.iblInputFile = project.objects.fileProperty()
extension.iblOutputDir = project.objects.directoryProperty()
extension.meshInputFile = project.objects.fileProperty()
extension.meshOutputDir = project.objects.directoryProperty()
project.tasks.register("filamentCompileMaterials", MaterialCompiler) {
enabled =
extension.materialInputDir.isPresent() &&
extension.materialOutputDir.isPresent()
inputDir.set(extension.materialInputDir.getOrNull())
outputDir.set(extension.materialOutputDir.getOrNull())
}
project.preBuild.dependsOn "filamentCompileMaterials"
project.tasks.register("filamentGenerateIbl", IblGenerator) {
enabled = extension.iblInputFile.isPresent() && extension.iblOutputDir.isPresent()
cmgenArgs = extension.cmgenArgs
inputFile = extension.iblInputFile.getOrNull()
outputDir = extension.iblOutputDir.getOrNull()
}
project.preBuild.dependsOn "filamentGenerateIbl"
project.tasks.register("filamentCompileMesh", MeshCompiler) {
enabled = extension.meshInputFile.isPresent() && extension.meshOutputDir.isPresent()
inputFile = extension.meshInputFile.getOrNull()
outputDir = extension.meshOutputDir.getOrNull()
}
project.preBuild.dependsOn "filamentCompileMesh"
}
}
+79 -69
View File
@@ -14,97 +14,107 @@
* limitations under the License.
*/
#include <functional>
#include "CallbackUtils.h"
struct {
#ifdef ANDROID
jclass handlerClass;
jmethodID post;
#endif
jclass executorClass;
jmethodID execute;
} gCallbackUtils;
#include "private/backend/VirtualMachineEnv.h"
JniCallback* JniCallback::make(filament::Engine* engine,
JNIEnv* env, jobject handler, jobject callback) {
void* that = engine->streamAlloc(sizeof(JniCallback), alignof(JniCallback));
return new (that) JniCallback(env, handler, callback);
void acquireCallbackJni(JNIEnv* env, CallbackJni& callbackUtils) {
#ifdef __ANDROID__
callbackUtils.handlerClass = env->FindClass("android/os/Handler");
callbackUtils.handlerClass = (jclass) env->NewGlobalRef(callbackUtils.handlerClass);
callbackUtils.post = env->GetMethodID(callbackUtils.handlerClass,
"post", "(Ljava/lang/Runnable;)Z");
#endif
callbackUtils.executorClass = env->FindClass("java/util/concurrent/Executor");
callbackUtils.executorClass = (jclass) env->NewGlobalRef(callbackUtils.executorClass);
callbackUtils.execute = env->GetMethodID(callbackUtils.executorClass,
"execute", "(Ljava/lang/Runnable;)V");
}
void releaseCallbackJni(JNIEnv* env, CallbackJni callbackUtils, jobject handler, jobject callback) {
if (handler && callback) {
#ifdef __ANDROID__
if (env->IsInstanceOf(handler, callbackUtils.handlerClass)) {
env->CallBooleanMethod(handler, callbackUtils.post, callback);
}
#endif
if (env->IsInstanceOf(handler, callbackUtils.executorClass)) {
env->CallVoidMethod(handler, callbackUtils.execute, callback);
}
}
env->DeleteGlobalRef(handler);
env->DeleteGlobalRef(callback);
#ifdef __ANDROID__
env->DeleteGlobalRef(callbackUtils.handlerClass);
#endif
env->DeleteGlobalRef(callbackUtils.executorClass);
}
// -----------------------------------------------------------------------------------------------
JniCallback* JniCallback::make(JNIEnv* env, jobject handler, jobject callback) {
return new JniCallback(env, handler, callback);
}
JniCallback::JniCallback(JNIEnv* env, jobject handler, jobject callback)
: mEnv(env)
, mHandler(env->NewGlobalRef(handler))
, mCallback(env->NewGlobalRef(callback)) {
: mHandler(env->NewGlobalRef(handler)),
mCallback(env->NewGlobalRef(callback)) {
acquireCallbackJni(env, mCallbackUtils);
}
JniCallback::~JniCallback() {
if (mHandler && mCallback) {
#ifdef ANDROID
if (mEnv->IsInstanceOf(mHandler, gCallbackUtils.handlerClass)) {
mEnv->CallBooleanMethod(mHandler, gCallbackUtils.post, mCallback);
}
#endif
if (mEnv->IsInstanceOf(mHandler, gCallbackUtils.executorClass)) {
mEnv->CallVoidMethod(mHandler, gCallbackUtils.execute, mCallback);
}
}
mEnv->DeleteGlobalRef(mHandler);
mEnv->DeleteGlobalRef(mCallback);
JniCallback::~JniCallback() = default;
void JniCallback::post(void* user, filament::backend::CallbackHandler::Callback callback) {
callback(user);
}
void JniCallback::invoke(void*, size_t, void* user) {
JniCallback* data = reinterpret_cast<JniCallback*>(user);
// don't call delete here, because we don't own the storage
data->~JniCallback();
void JniCallback::postToJavaAndDestroy(JniCallback* callback) {
JNIEnv* env = filament::VirtualMachineEnv::get().getEnvironment();
releaseCallbackJni(env, callback->mCallbackUtils, callback->mHandler, callback->mCallback);
delete callback;
}
JniBufferCallback* JniBufferCallback::make(filament::Engine* engine,
// -----------------------------------------------------------------------------------------------
JniBufferCallback* JniBufferCallback::make(filament::Engine*,
JNIEnv* env, jobject handler, jobject callback, AutoBuffer&& buffer) {
void* that = engine->streamAlloc(sizeof(JniBufferCallback), alignof(JniBufferCallback));
return new (that) JniBufferCallback(env, handler, callback, std::move(buffer));
return new JniBufferCallback(env, handler, callback, std::move(buffer));
}
JniBufferCallback::JniBufferCallback(JNIEnv* env, jobject handler, jobject callback,
AutoBuffer&& buffer)
: mEnv(env)
, mHandler(env->NewGlobalRef(handler))
, mCallback(env->NewGlobalRef(callback))
, mBuffer(std::move(buffer)){
: JniCallback(env, handler, callback),
mBuffer(std::move(buffer)) {
}
JniBufferCallback::~JniBufferCallback() {
if (mHandler && mCallback) {
#ifdef ANDROID
if (mEnv->IsInstanceOf(mHandler, gCallbackUtils.handlerClass)) {
mEnv->CallBooleanMethod(mHandler, gCallbackUtils.post, mCallback);
}
#endif
if (mEnv->IsInstanceOf(mHandler, gCallbackUtils.executorClass)) {
mEnv->CallVoidMethod(mHandler, gCallbackUtils.execute, mCallback);
}
}
mEnv->DeleteGlobalRef(mHandler);
mEnv->DeleteGlobalRef(mCallback);
JniBufferCallback::~JniBufferCallback() = default;
void JniBufferCallback::postToJavaAndDestroy(void*, size_t, void* user) {
JniBufferCallback* callback = (JniBufferCallback*)user;
JNIEnv* env = filament::VirtualMachineEnv::get().getEnvironment();
callback->mBuffer.attachToJniThread(env);
releaseCallbackJni(env, callback->mCallbackUtils, callback->mHandler, callback->mCallback);
delete callback;
}
void JniBufferCallback::invoke(void*, size_t, void* user) {
JniBufferCallback* data = reinterpret_cast<JniBufferCallback*>(user);
// don't call delete here, because we don't own the storage
data->~JniBufferCallback();
// -----------------------------------------------------------------------------------------------
JniImageCallback* JniImageCallback::make(filament::Engine*,
JNIEnv* env, jobject handler, jobject callback, long image) {
return new JniImageCallback(env, handler, callback, image);
}
void registerCallbackUtils(JNIEnv *env) {
#ifdef ANDROID
gCallbackUtils.handlerClass = env->FindClass("android/os/Handler");
gCallbackUtils.handlerClass = (jclass) env->NewGlobalRef(gCallbackUtils.handlerClass);
gCallbackUtils.post = env->GetMethodID(gCallbackUtils.handlerClass,
"post", "(Ljava/lang/Runnable;)Z");
#endif
JniImageCallback::JniImageCallback(JNIEnv* env, jobject handler, jobject callback, long image)
: JniCallback(env, handler, callback),
mImage(image) {
}
gCallbackUtils.executorClass = env->FindClass("java/util/concurrent/Executor");
gCallbackUtils.executorClass = (jclass) env->NewGlobalRef(gCallbackUtils.executorClass);
gCallbackUtils.execute = env->GetMethodID(gCallbackUtils.executorClass,
"execute", "(Ljava/lang/Runnable;)V");
JniImageCallback::~JniImageCallback() = default;
void JniImageCallback::postToJavaAndDestroy(void*, void* user) {
JniImageCallback* callback = (JniImageCallback*)user;
JNIEnv* env = filament::VirtualMachineEnv::get().getEnvironment();
releaseCallbackJni(env, callback->mCallbackUtils, callback->mHandler, callback->mCallback);
delete callback;
}
+61 -21
View File
@@ -18,38 +18,78 @@
#include <jni.h>
#include "common/CallbackUtils.h"
#include "common/NioUtils.h"
#include <backend/CallbackHandler.h>
#include <filament/Engine.h>
struct JniCallback {
static JniCallback* make(filament::Engine* engine,
JNIEnv* env, jobject handler, jobject callback);
static void invoke(void* buffer, size_t n, void* user);
private:
JniCallback(JNIEnv* env, jobject handler, jobject callback);
~JniCallback();
JNIEnv* mEnv;
jobject mHandler;
jobject mCallback;
struct CallbackJni {
#ifdef __ANDROID__
jclass handlerClass = nullptr;
jmethodID post = nullptr;
#endif
jclass executorClass = nullptr;
jmethodID execute = nullptr;
};
struct JniBufferCallback {
void acquireCallbackJni(JNIEnv* env, CallbackJni& callbackUtils);
void releaseCallbackJni(JNIEnv* env, CallbackJni callbackUtils, jobject handler, jobject callback);
struct JniCallback : private filament::backend::CallbackHandler {
JniCallback(JniCallback const &) = delete;
JniCallback(JniCallback&&) = delete;
JniCallback& operator=(JniCallback const &) = delete;
JniCallback& operator=(JniCallback&&) = delete;
// create a JniCallback
static JniCallback* make(JNIEnv* env, jobject handler, jobject runnable);
// execute the callback on the java thread and destroy ourselves
static void postToJavaAndDestroy(JniCallback* callback);
// CallbackHandler interface.
void post(void* user, Callback callback) override;
// Get the CallbackHandler interface
filament::backend::CallbackHandler* getHandler() noexcept { return this; }
jobject getCallbackObject() { return mCallback; }
protected:
JniCallback(JNIEnv* env, jobject handler, jobject runnable);
explicit JniCallback() = default; // this version does nothing
virtual ~JniCallback();
jobject mHandler{};
jobject mCallback{};
CallbackJni mCallbackUtils{};
};
struct JniBufferCallback : public JniCallback {
// create a JniBufferCallback
static JniBufferCallback* make(filament::Engine* engine,
JNIEnv* env, jobject handler, jobject callback, AutoBuffer&& buffer);
static void invoke(void* buffer, size_t n, void* user);
// execute the callback on the java thread and destroy ourselves
static void postToJavaAndDestroy(void*, size_t, void* user);
private:
JniBufferCallback(JNIEnv* env, jobject handler, jobject callback, AutoBuffer&& buffer);
~JniBufferCallback();
JNIEnv* mEnv;
jobject mHandler;
jobject mCallback;
virtual ~JniBufferCallback();
AutoBuffer mBuffer;
};
struct JniImageCallback : public JniCallback {
// create a JniImageCallback
static JniImageCallback* make(filament::Engine* engine, JNIEnv* env, jobject handler,
jobject runnable, long image);
// execute the callback on the java thread and destroy ourselves
static void postToJavaAndDestroy(void*, void* user);
private:
JniImageCallback(JNIEnv* env, jobject handler, jobject runnable, long image);
virtual ~JniImageCallback();
long mImage;
};
+25 -29
View File
@@ -18,20 +18,28 @@
#include <algorithm>
struct {
jclass jniClass;
jmethodID getBasePointer;
jmethodID getBaseArray;
jmethodID getBaseArrayOffset;
jmethodID getBufferType;
} gNioUtils;
#include <utils/Log.h>
AutoBuffer::AutoBuffer(JNIEnv *env, jobject buffer, jint size, bool commit) noexcept : mEnv(env),
AutoBuffer::AutoBuffer(JNIEnv *env, jobject buffer, jint size, bool commit) noexcept :
mEnv(env),
mDoCommit(commit) {
mNioUtils.jniClass = env->FindClass("com/google/android/filament/NioUtils");
mNioUtils.jniClass = (jclass) env->NewGlobalRef(mNioUtils.jniClass);
mNioUtils.getBasePointer = env->GetStaticMethodID(mNioUtils.jniClass,
"getBasePointer", "(Ljava/nio/Buffer;JI)J");
mNioUtils.getBaseArray = env->GetStaticMethodID(mNioUtils.jniClass,
"getBaseArray", "(Ljava/nio/Buffer;)Ljava/lang/Object;");
mNioUtils.getBaseArrayOffset = env->GetStaticMethodID(mNioUtils.jniClass,
"getBaseArrayOffset", "(Ljava/nio/Buffer;I)I");
mNioUtils.getBufferType = env->GetStaticMethodID(mNioUtils.jniClass,
"getBufferType", "(Ljava/nio/Buffer;)I");
mBuffer = env->NewGlobalRef(buffer);
mType = (BufferType) env->CallStaticIntMethod(
gNioUtils.jniClass, gNioUtils.getBufferType, mBuffer);
mNioUtils.jniClass, mNioUtils.getBufferType, mBuffer);
switch (mType) {
case BufferType::BYTE:
@@ -56,16 +64,16 @@ AutoBuffer::AutoBuffer(JNIEnv *env, jobject buffer, jint size, bool commit) noex
jlong address = (jlong) env->GetDirectBufferAddress(mBuffer);
if (address) {
// Direct buffer case
mData = reinterpret_cast<void *>(env->CallStaticLongMethod(gNioUtils.jniClass,
gNioUtils.getBasePointer, mBuffer, address, mShift));
mData = reinterpret_cast<void *>(env->CallStaticLongMethod(mNioUtils.jniClass,
mNioUtils.getBasePointer, mBuffer, address, mShift));
mUserData = mData;
} else {
// wrapped array case
jarray array = (jarray) env->CallStaticObjectMethod(gNioUtils.jniClass,
gNioUtils.getBaseArray, mBuffer);
jarray array = (jarray) env->CallStaticObjectMethod(mNioUtils.jniClass,
mNioUtils.getBaseArray, mBuffer);
jint offset = env->CallStaticIntMethod(gNioUtils.jniClass,
gNioUtils.getBaseArrayOffset, mBuffer, mShift);
jint offset = env->CallStaticIntMethod(mNioUtils.jniClass,
mNioUtils.getBaseArrayOffset, mBuffer, mShift);
mBaseArray = (jarray) env->NewGlobalRef(array);
switch (mType) {
@@ -104,6 +112,7 @@ AutoBuffer::AutoBuffer(AutoBuffer &&rhs) noexcept {
std::swap(mShift, rhs.mShift);
std::swap(mBuffer, rhs.mBuffer);
std::swap(mBaseArray, rhs.mBaseArray);
std::swap(mNioUtils, rhs.mNioUtils);
}
AutoBuffer::~AutoBuffer() noexcept {
@@ -138,18 +147,5 @@ AutoBuffer::~AutoBuffer() noexcept {
if (mBuffer) {
env->DeleteGlobalRef(mBuffer);
}
}
void registerNioUtils(JNIEnv *env) {
gNioUtils.jniClass = env->FindClass("com/google/android/filament/NioUtils");
gNioUtils.jniClass = (jclass) env->NewGlobalRef(gNioUtils.jniClass);
gNioUtils.getBasePointer = env->GetStaticMethodID(gNioUtils.jniClass, "getBasePointer",
"(Ljava/nio/Buffer;JI)J");
gNioUtils.getBaseArray = env->GetStaticMethodID(gNioUtils.jniClass, "getBaseArray",
"(Ljava/nio/Buffer;)Ljava/lang/Object;");
gNioUtils.getBaseArrayOffset = env->GetStaticMethodID(gNioUtils.jniClass, "getBaseArrayOffset",
"(Ljava/nio/Buffer;I)I");
gNioUtils.getBufferType = env->GetStaticMethodID(gNioUtils.jniClass, "getBufferType",
"(Ljava/nio/Buffer;)I");
mEnv->DeleteGlobalRef(mNioUtils.jniClass);
}
+12
View File
@@ -38,6 +38,10 @@ public:
AutoBuffer(AutoBuffer&& rhs) noexcept;
~AutoBuffer() noexcept;
void attachToJniThread(JNIEnv* env) noexcept {
mEnv = env;
}
void* getData() const noexcept {
return mUserData;
}
@@ -65,4 +69,12 @@ private:
jobject mBuffer = nullptr;
jarray mBaseArray = nullptr;
bool mDoCommit = false;
struct {
jclass jniClass;
jmethodID getBasePointer;
jmethodID getBaseArray;
jmethodID getBaseArrayOffset;
jmethodID getBufferType;
} mNioUtils{};
};
+1
View File
@@ -9,3 +9,4 @@
/build
/captures
.externalNativeBuild
/.cxx
+14 -14
View File
@@ -1,4 +1,7 @@
cmake_minimum_required(VERSION 3.6)
cmake_minimum_required(VERSION 3.19)
project(filamat-android)
option(FILAMENT_ENABLE_MATDBG "Enables Material debugger" OFF)
set(FILAMENT_DIR ${FILAMENT_DIST_DIR})
@@ -7,6 +10,10 @@ if(FILAMAT_LITE)
set(FILAMAT_FLAVOR "filamat_lite")
endif()
if (FILAMENT_SUPPORTS_VULKAN)
message("Library filamat ignores Vulkan settings")
endif()
add_library(${FILAMAT_FLAVOR} STATIC IMPORTED)
set_target_properties(${FILAMAT_FLAVOR} PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/lib${FILAMAT_FLAVOR}.a)
@@ -27,22 +34,16 @@ add_library(shaders STATIC IMPORTED)
set_target_properties(shaders PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libshaders.a)
set(FILAMAT_INCLUDE_DIRS
../../libs/utils/include
)
include_directories(${FILAMENT_DIR}/include)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-stack-protector")
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} -ffast-math -ffp-contract=fast")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fvisibility-inlines-hidden")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer -ffunction-sections -fdata-sections")
set(CMAKE_SHARED_LINKER_FLAGS" ${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
set(CMAKE_SHARED_LINKER_FLAGS" ${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic-functions")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -Wl,--version-script=${CMAKE_SOURCE_DIR}/libfilamat-jni.map")
add_library(filamat-jni SHARED
src/main/cpp/MaterialBuilder.cpp
)
add_library(filamat-jni SHARED src/main/cpp/MaterialBuilder.cpp)
target_include_directories(filamat-jni PRIVATE ${FILAMAT_INCLUDE_DIRS})
target_link_libraries(filamat-jni
${FILAMAT_FLAVOR}
@@ -52,4 +53,3 @@ target_link_libraries(filamat-jni
log
smol-v
)
+20 -84
View File
@@ -1,69 +1,5 @@
// This script accepts the following parameters:
//
// filament_dist_dir
// Path to the Filament distribution/install directory for Android
// (produced by make/ninja install). This directory must contain lib/arm64-v8a/ etc.
//
// Example:
// ./gradlew -Pfilament_dist_dir=../../dist-android-release assembleRelease
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
group = "com.google.android.filament"
version = "0.1"
apply plugin: 'com.android.library'
def filament_path = file("../../out/android-release/filament").absolutePath
if (project.hasProperty("filament_dist_dir")) {
filament_path = file("$filament_dist_dir").absolutePath
}
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments.add("-DANDROID_PIE=ON")
arguments.add("-DANDROID_PLATFORM=android-21")
arguments.add("-DANDROID_STL=c++_static")
arguments.add("-DFILAMENT_DIST_DIR=${filament_path}".toString())
cppFlags.add("-std=c++14")
if (project.hasProperty('extra_cmake_args')) {
arguments.add(extra_cmake_args)
}
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
namespace 'com.google.android.filament.filamat'
flavorDimensions "functionality"
productFlavors {
@@ -81,26 +17,26 @@ android {
}
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
jni.srcDirs "src/main/cpp"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-annotations:28.0.0'
implementation deps.androidx.annotations
}
apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
afterEvaluate { project ->
publishing {
publications {
fullRelease(MavenPublication) {
artifactId = POM_ARTIFACT_ID_FULL
from components.fullRelease
}
liteRelease(MavenPublication) {
artifactId = POM_ARTIFACT_ID_LITE
from components.liteRelease
}
}
}
}
@@ -0,0 +1,4 @@
POM_NAME=Filament Material Builder
POM_ARTIFACT_ID_FULL=filamat-android
POM_ARTIFACT_ID_LITE=filamat-android-lite
POM_PACKAGING=aar
Binary file not shown.
@@ -1,5 +0,0 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-172
View File
@@ -1,172 +0,0 @@
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"
-84
View File
@@ -1,84 +0,0 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
-10
View File
@@ -1,10 +0,0 @@
/*
* This file was generated by the Gradle 'init' task.
*
* The settings file is used to specify which projects to include in your build.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user guide at https://docs.gradle.org/4.6/userguide/multi_project_builds.html
*/
rootProject.name = 'filamat-android'
@@ -18,6 +18,8 @@
#include <filamat/MaterialBuilder.h>
#include <utils/JobSystem.h>
using namespace filament;
using namespace filamat;
@@ -45,9 +47,23 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nDestroyMaterialBuilder
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nBuilderBuild(JNIEnv*, jclass,
jlong nativeBuilder) {
jlong nativeBuilder, jlong nativeJobSystem) {
auto builder = (MaterialBuilder*) nativeBuilder;
return (jlong) new Package(builder->build());
auto jobSystem = (utils::JobSystem*) nativeJobSystem;
if (nativeJobSystem == 0) {
jobSystem = new utils::JobSystem;
jobSystem->adopt();
}
jlong result = (jlong) new Package(builder->build(*jobSystem));
if (nativeJobSystem == 0) {
jobSystem->emancipate();
delete jobSystem;
}
return result;
}
extern "C" JNIEXPORT jbyteArray JNICALL
@@ -81,6 +97,14 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderName(JN
auto builder = (MaterialBuilder*) nativeBuilder;
const char* name = env->GetStringUTFChars(name_, nullptr);
builder->name(name);
env->ReleaseStringUTFChars(name_, name);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderMaterialDomain(JNIEnv* env,
jclass, jlong nativeBuilder, jint domain) {
auto builder = (MaterialBuilder*) nativeBuilder;
builder->materialDomain((MaterialBuilder::MaterialDomain) domain);
}
extern "C" JNIEXPORT void JNICALL
@@ -99,18 +123,23 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderInterpo
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderUniformParameter(
JNIEnv* env, jclass, jlong nativeBuilder, jint uniformType, jstring name_) {
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, name);
builder->parameter((MaterialBuilder::UniformType) uniformType,
(MaterialBuilder::ParameterPrecision) precision, name);
env->ReleaseStringUTFChars(name_, name);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderUniformParameterArray(
JNIEnv* env, jclass, jlong nativeBuilder, jint uniformType, jint size, jstring name_) {
JNIEnv* env, jclass, jlong nativeBuilder, jint uniformType, jint size, jint precision,
jstring name_) {
auto builder = (MaterialBuilder*) nativeBuilder;
const char* name = env->GetStringUTFChars(name_, nullptr);
builder->parameter((MaterialBuilder::UniformType) uniformType, (size_t) size, name);
builder->parameter((MaterialBuilder::UniformType) uniformType, (size_t) size,
(MaterialBuilder::ParameterPrecision) precision, name);
env->ReleaseStringUTFChars(name_, name);
}
extern "C" JNIEXPORT void JNICALL
@@ -120,8 +149,9 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderSampler
auto builder = (MaterialBuilder*) nativeBuilder;
const char* name = env->GetStringUTFChars(name_, nullptr);
builder->parameter((MaterialBuilder::SamplerType) samplerType,
(MaterialBuilder::SamplerFormat) format, (MaterialBuilder::SamplerPrecision) precision,
(MaterialBuilder::SamplerFormat) format, (MaterialBuilder::ParameterPrecision) precision,
name);
env->ReleaseStringUTFChars(name_, name);
}
extern "C" JNIEXPORT void JNICALL
@@ -130,6 +160,7 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderVariabl
const char* name = env->GetStringUTFChars(name_, nullptr);
auto builder = (MaterialBuilder*) nativeBuilder;
builder->variable((MaterialBuilder::Variable) variable, name);
env->ReleaseStringUTFChars(name_, name);
}
extern "C" JNIEXPORT void JNICALL
@@ -145,6 +176,7 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderMateria
auto builder = (MaterialBuilder*) nativeBuilder;
const char* code = env->GetStringUTFChars(code_, nullptr);
builder->material(code);
env->ReleaseStringUTFChars(code_, code);
}
extern "C" JNIEXPORT void JNICALL
@@ -153,6 +185,7 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderMateria
auto builder = (MaterialBuilder*) nativeBuilder;
const char* code = env->GetStringUTFChars(code_, nullptr);
builder->materialVertex(code);
env->ReleaseStringUTFChars(code_, code);
}
extern "C" JNIEXPORT void JNICALL
@@ -225,6 +258,13 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderShadowM
builder->shadowMultiplier(shadowMultiplier);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderTransparentShadow(
JNIEnv*, jclass, jlong nativeBuilder, jboolean transparentShadow) {
auto builder = (MaterialBuilder*) nativeBuilder;
builder->transparentShadow(transparentShadow);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderSpecularAntiAliasing(
JNIEnv*, jclass, jlong nativeBuilder, jboolean specularAntiAliasing) {
@@ -246,6 +286,7 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderSpecula
builder->specularAntiAliasingThreshold(threshold);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderClearCoatIorChange(
JNIEnv*, jclass, jlong nativeBuilder, jboolean clearCoatIorChange) {
@@ -260,6 +301,13 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderFlipUV(
builder->flipUV(flipUV);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderCustomSurfaceShading(JNIEnv*,
jclass, jlong nativeBuilder, jboolean customSurfaceShading) {
auto builder = (MaterialBuilder*) nativeBuilder;
builder->customSurfaceShading(customSurfaceShading);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderMultiBounceAmbientOcclusion(
JNIEnv*, jclass, jlong nativeBuilder, jboolean multiBounceAO) {
@@ -269,9 +317,23 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderMultiBo
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderSpecularAmbientOcclusion(
JNIEnv*, jclass, jlong nativeBuilder, jboolean specularAO) {
JNIEnv*, jclass, jlong nativeBuilder, jint specularAO) {
auto builder = (MaterialBuilder*) nativeBuilder;
builder->specularAmbientOcclusion(specularAO);
builder->specularAmbientOcclusion((MaterialBuilder::SpecularAmbientOcclusion) specularAO);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderRefractionMode(JNIEnv* env,
jclass, jlong nativeBuilder, jint mode) {
auto builder = (MaterialBuilder*) nativeBuilder;
builder->refractionMode((MaterialBuilder::RefractionMode) mode);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderRefractionType(JNIEnv* env,
jclass, jlong nativeBuilder, jint type) {
auto builder = (MaterialBuilder*) nativeBuilder;
builder->refractionType((MaterialBuilder::RefractionType) type);
}
extern "C" JNIEXPORT void JNICALL
@@ -304,7 +366,14 @@ Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderOptimiz
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderVariantFilter(JNIEnv*,
jclass, jlong nativeBuilder, jbyte variantFilter) {
jclass, jlong nativeBuilder, jint variantFilter) {
auto builder = (MaterialBuilder*) nativeBuilder;
builder->variantFilter((uint8_t) variantFilter);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_filamat_MaterialBuilder_nMaterialBuilderUseLegacyMorphing(JNIEnv*,
jclass, jlong nativeBuilder) {
auto builder = (MaterialBuilder*) nativeBuilder;
builder->useLegacyMorphing();
}
@@ -16,18 +16,30 @@
package com.google.android.filament.filamat;
import android.support.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
public class MaterialBuilder {
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
// Keep to finalize native resources
private final BuilderFinalizer mFinalizer;
private final long mNativeObject;
private static Class<?> sEngineClass = null;
private static Method sGetNativeJobSystemMethod = null;
static {
System.loadLibrary("filamat-jni");
try {
sEngineClass = Class.forName("com.google.android.filament.Engine");
sGetNativeJobSystemMethod = sEngineClass.getDeclaredMethod("getNativeJobSystem");
} catch (ClassNotFoundException | NoSuchMethodException e) {
// It's okay if we don't find it, this is to avoid creating dependencies
}
}
public enum Shading {
@@ -66,8 +78,10 @@ public class MaterialBuilder {
public enum SamplerType {
SAMPLER_2D, // 2D texture
SAMPLER_2D_ARRAY, // 2D array texture
SAMPLER_CUBEMAP, // Cube map texture
SAMPLER_EXTERNAL, // External texture
SAMPLER_3D // 3D texture
}
public enum SamplerFormat {
@@ -77,7 +91,7 @@ public class MaterialBuilder {
SHADOW
}
public enum SamplerPrecision {
public enum ParameterPrecision {
LOW,
MEDIUM,
HIGH,
@@ -98,7 +112,16 @@ public class MaterialBuilder {
UV0, // texture coordinates (float2)
UV1, // texture coordinates (float2)
BONE_INDICES, // indices of 4 bones (uvec4)
BONE_WEIGHTS // weights of the 4 bones (normalized float4)
BONE_WEIGHTS, // weights of the 4 bones (normalized float4)
UNUSED, // reserved for future use
CUSTOM0, // custom or MORPH_POSITION_0
CUSTOM1, // custom or MORPH_POSITION_1
CUSTOM2, // custom or MORPH_POSITION_2
CUSTOM3, // custom or MORPH_POSITION_3
CUSTOM4, // custom or MORPH_TANGENTS_0
CUSTOM5, // custom or MORPH_TANGENTS_1
CUSTOM6, // custom or MORPH_TANGENTS_2
CUSTOM7 // custom or MORPH_TANGENTS_3
}
public enum BlendingMode {
@@ -110,7 +133,7 @@ public class MaterialBuilder {
FADE, // material is transparent and color is alpha-pre-multiplied,
// affects specular lighting
MULTIPLY, // material darkens what's behind it
SCREN // material brightens what's behind it
SCREEN // material brightens what's behind it
}
public enum VertexDomain {
@@ -137,6 +160,28 @@ public class MaterialBuilder {
// mode is ignored. Can be combined with two-sided lighting
}
public enum MaterialDomain {
SURFACE,
POST_PROCESS
}
public enum SpecularAmbientOcclusion {
NONE,
SIMPLE,
BENT_NORMALS
}
public enum RefractionMode {
NONE,
CUBEMAP,
SCREEN_SPACE
}
public enum RefractionType {
SOLID,
THIN
}
public enum Platform {
DESKTOP,
MOBILE,
@@ -182,6 +227,12 @@ public class MaterialBuilder {
return this;
}
@NonNull
public MaterialBuilder materialDomain(MaterialDomain domain) {
nMaterialBuilderMaterialDomain(mNativeObject, domain.ordinal());
return this;
}
@NonNull
public MaterialBuilder shading(@NonNull Shading shading) {
nMaterialBuilderShading(mNativeObject, shading.ordinal());
@@ -196,19 +247,36 @@ public class MaterialBuilder {
@NonNull
public MaterialBuilder uniformParameter(@NonNull UniformType type, String name) {
nMaterialBuilderUniformParameter(mNativeObject, type.ordinal(), name);
nMaterialBuilderUniformParameter(mNativeObject, type.ordinal(),
ParameterPrecision.DEFAULT.ordinal(), name);
return this;
}
@NonNull
public MaterialBuilder uniformParameter(@NonNull UniformType type,
ParameterPrecision precision, String name) {
nMaterialBuilderUniformParameter(mNativeObject, type.ordinal(), precision.ordinal(), name);
return this;
}
@NonNull
public MaterialBuilder uniformParameterArray(@NonNull UniformType type, int size, String name) {
nMaterialBuilderUniformParameterArray(mNativeObject, type.ordinal(), size, name);
nMaterialBuilderUniformParameterArray(mNativeObject, type.ordinal(), size,
ParameterPrecision.DEFAULT.ordinal(), name);
return this;
}
@NonNull
public MaterialBuilder uniformParameterArray(@NonNull UniformType type, int size,
ParameterPrecision precision, String name) {
nMaterialBuilderUniformParameterArray(mNativeObject, type.ordinal(), size,
precision.ordinal(), name);
return this;
}
@NonNull
public MaterialBuilder samplerParameter(@NonNull SamplerType type, SamplerFormat format,
SamplerPrecision precision, String name) {
ParameterPrecision precision, String name) {
nMaterialBuilderSamplerParameter(
mNativeObject, type.ordinal(), format.ordinal(), precision.ordinal(), name);
return this;
@@ -298,6 +366,12 @@ public class MaterialBuilder {
return this;
}
@NonNull
public MaterialBuilder transparentShadow(boolean transparentShadow) {
nMaterialBuilderTransparentShadow(mNativeObject, transparentShadow);
return this;
}
@NonNull
public MaterialBuilder specularAntiAliasing(boolean specularAntiAliasing) {
nMaterialBuilderSpecularAntiAliasing(mNativeObject, specularAntiAliasing);
@@ -316,6 +390,18 @@ public class MaterialBuilder {
return this;
}
@NonNull
public MaterialBuilder refractionMode(RefractionMode mode) {
nMaterialBuilderRefractionMode(mNativeObject, mode.ordinal());
return this;
}
@NonNull
public MaterialBuilder refractionType(RefractionType type) {
nMaterialBuilderRefractionType(mNativeObject, type.ordinal());
return this;
}
@NonNull
public MaterialBuilder clearCoatIorChange(boolean clearCoatIorChange) {
nMaterialBuilderClearCoatIorChange(mNativeObject, clearCoatIorChange);
@@ -328,6 +414,12 @@ public class MaterialBuilder {
return this;
}
@NonNull
public MaterialBuilder customSurfaceShading(boolean customSurfaceShading) {
nMaterialBuilderCustomSurfaceShading(mNativeObject, customSurfaceShading);
return this;
}
@NonNull
public MaterialBuilder multiBounceAmbientOcclusion(boolean multiBounceAO) {
nMaterialBuilderMultiBounceAmbientOcclusion(mNativeObject, multiBounceAO);
@@ -335,8 +427,8 @@ public class MaterialBuilder {
}
@NonNull
public MaterialBuilder specularAmbientOcclusion(boolean specularAO) {
nMaterialBuilderSpecularAmbientOcclusion(mNativeObject, specularAO);
public MaterialBuilder specularAmbientOcclusion(SpecularAmbientOcclusion specularAO) {
nMaterialBuilderSpecularAmbientOcclusion(mNativeObject, specularAO.ordinal());
return this;
}
@@ -365,14 +457,73 @@ public class MaterialBuilder {
}
@NonNull
public MaterialBuilder variantFilter(byte variantFilter) {
public MaterialBuilder variantFilter(int variantFilter) {
nMaterialBuilderVariantFilter(mNativeObject, variantFilter);
useLegacyMorphing();
return this;
}
/**
* Legacy morphing uses the data in the {@link VertexBuffer.VertexAttribute} slots
* (<code>MORPH_POSITION_0</code>, etc) and is limited to 4 morph targets.
*
* @see RenderableManager.Builder#morphing()
*/
@NonNull
public MaterialBuilder useLegacyMorphing() {
nMaterialBuilderUseLegacyMorphing(mNativeObject);
return this;
}
/**
* Validates, builds, and returns the compiled material. While this method never
* returns null, the returned {@link MaterialPackage} may be invalid. Call
* {@link MaterialPackage#isValid()} before using it.
*
* Calling this method is equivalent to calling {@link #build(Object)} and passing
* <code>null</code> as the job system provider.
*
* @see #build(Object)
*/
@NonNull
public MaterialPackage build() {
long nativePackage = nBuilderBuild(mNativeObject);
return build(null);
}
/**
* Validates, builds, and returns the compiled material. While this method never
* returns null, the returned {@link MaterialPackage} may be invalid. Call
* {@link MaterialPackage#isValid()} before using it.
*
* You can pass a job system provider to this method, or null. When passing null
* or an invalid job system provider, a temporary job system will be created which
* is less efficient than reusing an existing job system.
*
* Currently the only valid type of job system provider is an <code>Engine</code>
* instance from the main Filament library (<code>com.google.android.filament.Engine</code>).
*
* If you are using Filament and the filamat library together you <em>must</em> pass an
* <code>Engine</code> as the job system provider, <em>or</em> invoke
* <code>MaterialBuilder</code> from a thread other than the thread used to invoke Filament
* APIs.
*
* @param jobSystemProvider An <code>Engine</code> instance or null
*/
@NonNull
public MaterialPackage build(@Nullable Object jobSystemProvider) {
long nativeJobSystem = 0;
if (jobSystemProvider != null && sEngineClass != null) {
if (sEngineClass.isInstance(jobSystemProvider) && sGetNativeJobSystemMethod != null) {
try {
//noinspection ConstantConditions
nativeJobSystem = (Long) sGetNativeJobSystemMethod.invoke(jobSystemProvider);
} catch (IllegalAccessException | InvocationTargetException e) {
// Ignore
}
}
}
long nativePackage = nBuilderBuild(mNativeObject, nativeJobSystem);
byte[] data = nGetPackageBytes(nativePackage);
MaterialPackage result =
new MaterialPackage(ByteBuffer.wrap(data), nGetPackageIsValid(nativePackage));
@@ -404,18 +555,19 @@ public class MaterialBuilder {
private static native long nCreateMaterialBuilder();
private static native void nDestroyMaterialBuilder(long nativeBuilder);
private static native long nBuilderBuild(long nativeBuilder);
private static native long nBuilderBuild(long nativeBuilder, long nativeJobSystem);
private static native byte[] nGetPackageBytes(long nativePackage);
private static native boolean nGetPackageIsValid(long nativePackage);
private static native void nDestroyPackage(long nativePackage);
private static native void nMaterialBuilderName(long nativeBuilder, String name);
private static native void nMaterialBuilderMaterialDomain(long nativeBuilder, int domain);
private static native void nMaterialBuilderShading(long nativeBuilder, int shading);
private static native void nMaterialBuilderInterpolation(long nativeBuilder, int interpolation);
private static native void nMaterialBuilderUniformParameter(long nativeBuilder, int type,
String name);
int precision, String name);
private static native void nMaterialBuilderUniformParameterArray(long nativeBuilder, int type,
int size, String name);
int size, int precision, String name);
private static native void nMaterialBuilderSamplerParameter(long nativeBuilder, int type,
int format, int precision, String name);
private static native void nMaterialBuilderVariable(long nativeBuilder, int variable,
@@ -435,23 +587,30 @@ public class MaterialBuilder {
private static native void nMaterialBuilderShadowMultiplier(long mNativeObject,
boolean shadowMultiplier);
private static native void nMaterialBuilderTransparentShadow(long mNativeObject,
boolean transparentShadow);
private static native void nMaterialBuilderSpecularAntiAliasing(long mNativeObject,
boolean specularAntiAliasing);
private static native void nMaterialBuilderSpecularAntiAliasingVariance(long mNativeObject,
float variance);
private static native void nMaterialBuilderSpecularAntiAliasingThreshold(long mNativeObject,
float threshold);
private static native void nMaterialBuilderRefractionMode(long nativeBuilder, int mode);
private static native void nMaterialBuilderRefractionType(long nativeBuilder, int type);
private static native void nMaterialBuilderClearCoatIorChange(long mNativeObject,
boolean clearCoatIorChange);
private static native void nMaterialBuilderFlipUV(long nativeBuilder, boolean flipUV);
private static native void nMaterialBuilderCustomSurfaceShading(long nativeBuilder,
boolean customSurfaceShading);
private static native void nMaterialBuilderMultiBounceAmbientOcclusion(long nativeBuilder,
boolean multiBounceAO);
private static native void nMaterialBuilderSpecularAmbientOcclusion(long nativeBuilder,
boolean specularAO);
int specularAO);
private static native void nMaterialBuilderTransparencyMode(long nativeBuilder, int mode);
private static native void nMaterialBuilderPlatform(long nativeBuilder, int platform);
private static native void nMaterialBuilderTargetApi(long nativeBuilder, int api);
private static native void nMaterialBuilderOptimization(long nativeBuilder, int optimization);
private static native void nMaterialBuilderVariantFilter(long nativeBuilder,
byte variantFilter);
int variantFilter);
private static native void nMaterialBuilderUseLegacyMorphing(long nativeBuilder);
}
@@ -16,7 +16,7 @@
package com.google.android.filament.filamat;
import android.support.annotation.NonNull;
import androidx.annotation.NonNull;
import java.nio.ByteBuffer;
public class MaterialPackage {
+1
View File
@@ -9,3 +9,4 @@
/build
/captures
.externalNativeBuild
/.cxx
-29
View File
@@ -1,29 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>
@@ -1,5 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
-15
View File
@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
</wildcardResourcePatterns>
</component>
</project>
-6
View File
@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
-34
View File
@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="5">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
-8
View File
@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/filament-android.iml" filepath="$PROJECT_DIR$/filament-android.iml" />
</modules>
</component>
</project>
-12
View File
@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
-6
View File
@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
+89 -61
View File
@@ -1,4 +1,9 @@
cmake_minimum_required(VERSION 3.6)
cmake_minimum_required(VERSION 3.19)
project(filament-android)
option(FILAMENT_SUPPORTS_VULKAN "Enables Vulkan on Android" OFF)
option(FILAMENT_ENABLE_MATDBG "Enables Material debugger" OFF)
option(FILAMENT_DISABLE_MATOPT "Disables material optimizations" OFF)
set(FILAMENT_DIR ${FILAMENT_DIST_DIR})
@@ -14,14 +19,18 @@ add_library(utils STATIC IMPORTED)
set_target_properties(utils PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libutils.a)
add_library(ibl STATIC IMPORTED)
set_target_properties(ibl PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libibl.a)
add_library(ibl-lite STATIC IMPORTED)
set_target_properties(ibl-lite PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libibl-lite.a)
add_library(filaflat STATIC IMPORTED)
set_target_properties(filaflat PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libfilaflat.a)
add_library(filamat STATIC IMPORTED)
set_target_properties(filamat PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libfilamat.a)
add_library(geometry STATIC IMPORTED)
set_target_properties(geometry PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libgeometry.a)
@@ -34,73 +43,92 @@ add_library(bluevk STATIC IMPORTED)
set_target_properties(bluevk PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libbluevk.a)
add_library(vkshaders STATIC IMPORTED)
set_target_properties(vkshaders PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libvkshaders.a)
add_library(smol-v STATIC IMPORTED)
set_target_properties(smol-v PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libsmol-v.a)
if (FILAMENT_ENABLE_MATDBG)
add_library(matdbg STATIC IMPORTED)
set_target_properties(matdbg PROPERTIES IMPORTED_LOCATION
${FILAMENT_DIR}/lib/${ANDROID_ABI}/libmatdbg.a)
endif()
include_directories(.. ${FILAMENT_DIR}/include)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-stack-protector")
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} -ffast-math -ffp-contract=fast")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fvisibility-inlines-hidden")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fomit-frame-pointer -ffunction-sections -fdata-sections")
set(CMAKE_SHARED_LINKER_FLAGS" ${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections")
set(CMAKE_SHARED_LINKER_FLAGS" ${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic-functions")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -Wl,--version-script=${CMAKE_SOURCE_DIR}/libfilament-jni.map")
set(VERSION_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/libfilament-jni.map")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -Wl,--version-script=${VERSION_SCRIPT}")
add_library(filament-jni SHARED
src/main/cpp/Camera.cpp
src/main/cpp/Colors.cpp
src/main/cpp/VertexBuffer.cpp
src/main/cpp/Engine.cpp
src/main/cpp/EntityManager.cpp
src/main/cpp/Fence.cpp
src/main/cpp/IndexBuffer.cpp
src/main/cpp/IndirectLight.cpp
src/main/cpp/LightManager.cpp
src/main/cpp/Material.cpp
src/main/cpp/MaterialInstance.cpp
src/main/cpp/MathUtils.cpp
src/main/cpp/RenderableManager.cpp
src/main/cpp/Renderer.cpp
src/main/cpp/RenderTarget.cpp
src/main/cpp/Scene.cpp
src/main/cpp/SkyBox.cpp
src/main/cpp/Stream.cpp
src/main/cpp/Texture.cpp
src/main/cpp/TextureSampler.cpp
src/main/cpp/TransformManager.cpp
src/main/cpp/View.cpp
# Android specific
src/main/cpp/nativewindow/Android.cpp
# Private utils
src/main/cpp/Filament.cpp
# Common utils
../common/CallbackUtils.cpp
../common/NioUtils.cpp
src/main/cpp/BufferObject.cpp
src/main/cpp/Camera.cpp
src/main/cpp/Colors.cpp
src/main/cpp/ColorGrading.cpp
src/main/cpp/Engine.cpp
src/main/cpp/EntityManager.cpp
src/main/cpp/Fence.cpp
src/main/cpp/IndexBuffer.cpp
src/main/cpp/IndirectLight.cpp
src/main/cpp/LightManager.cpp
src/main/cpp/Material.cpp
src/main/cpp/MaterialInstance.cpp
src/main/cpp/MathUtils.cpp
src/main/cpp/MorphTargetBuffer.cpp
src/main/cpp/RenderableManager.cpp
src/main/cpp/Renderer.cpp
src/main/cpp/RenderTarget.cpp
src/main/cpp/Scene.cpp
src/main/cpp/SkyBox.cpp
src/main/cpp/SkinningBuffer.cpp
src/main/cpp/Stream.cpp
src/main/cpp/SurfaceOrientation.cpp
src/main/cpp/SwapChain.cpp
src/main/cpp/Texture.cpp
src/main/cpp/TextureSampler.cpp
src/main/cpp/ToneMapper.cpp
src/main/cpp/TransformManager.cpp
src/main/cpp/VertexBuffer.cpp
src/main/cpp/View.cpp
# Android specific
src/main/cpp/nativewindow/Android.cpp
# Private utils
src/main/cpp/Filament.cpp
# Common utils
../common/CallbackUtils.cpp
../common/NioUtils.cpp
)
# Ordering is significant in the following list. The PRIVATE qualifier prevents transitive deps.
target_link_libraries(filament-jni
filament
backend
filaflat
filabridge
geometry
ibl
utils
log
GLESv3
EGL
android
jnigraphics
PRIVATE filament
PRIVATE backend
PRIVATE filaflat
PRIVATE filabridge
PRIVATE ibl-lite
PRIVATE log
PRIVATE GLESv3
PRIVATE EGL
PRIVATE android
PRIVATE jnigraphics
PRIVATE utils
# libgeometry is PUBLIC because gltfio uses it.
PUBLIC geometry
$<$<STREQUAL:${FILAMENT_ENABLE_MATDBG},ON>:matdbg>
$<$<STREQUAL:${FILAMENT_ENABLE_MATDBG},ON>:filamat>
$<$<STREQUAL:${FILAMENT_SUPPORTS_VULKAN},ON>:bluevk>
$<$<STREQUAL:${FILAMENT_SUPPORTS_VULKAN},ON>:vkshaders>
$<$<STREQUAL:${FILAMENT_SUPPORTS_VULKAN},ON>:smol-v>
)
option(FILAMENT_SUPPORTS_VULKAN "Enables Vulkan on Android" OFF)
target_include_directories(filament-jni PRIVATE
..
${FILAMENT_DIR}/include
../../filament/backend/include
../../third_party/robin-map
../../libs/utils/include)
if (FILAMENT_SUPPORTS_VULKAN)
target_link_libraries(filament-jni bluevk smol-v)
endif()
# Force a relink when the version script is changed:
set_target_properties(filament-jni PROPERTIES LINK_DEPENDS ${VERSION_SCRIPT})
+15 -93
View File
@@ -1,98 +1,20 @@
// This script accepts the following parameters:
//
// filament_dist_dir
// Path to the Filament distribution/install directory for Android
// (produced by make/ninja install). This directory must contain lib/arm64-v8a/ etc.
//
// Example:
// ./gradlew -Pfilament_dist_dir=../../dist-android-release assembleRelease
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
group = "com.google.android.filament"
version = "0.1"
apply plugin: 'com.android.library'
def filament_path = file("../../out/android-release/filament").absolutePath
if (project.hasProperty("filament_dist_dir")) {
filament_path = file("$filament_dist_dir").absolutePath
}
android {
compileSdkVersion 28
defaultConfig {
// Our minSdkVersion is actually 21, we lie and say 14 here so apps don't have
// to increase their minSdkVersion unnecessarily. It is however up to them to
// ensure they do not initialize Filament on API levels < 21.
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments.add("-DANDROID_PIE=ON")
arguments.add("-DANDROID_PLATFORM=android-21")
arguments.add("-DANDROID_STL=c++_static")
arguments.add("-DFILAMENT_DIST_DIR=${filament_path}".toString())
cppFlags.add("-std=c++14")
if (project.hasProperty('extra_cmake_args')) {
arguments.add(extra_cmake_args)
}
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
jni.srcDirs "src/main/cpp"
// To enable validation layers with the Vulkan backend, uncomment the following lines
// to copy the appropriate files from the NDK to the device. Also be sure to use a debug
// configuration for the native build.
// jniLibs {
// srcDirs = ["${android.ndkDirectory}/sources/third_party/vulkan/src/build-android/jniLibs"]
// }
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'com.google.android.filament'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-annotations:28.0.0'
implementation deps.androidx.annotations
}
apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
afterEvaluate { project ->
publishing {
publications {
release(MavenPublication) {
artifactId = POM_ARTIFACT_ID
from components.release
}
}
}
}
@@ -0,0 +1,3 @@
POM_NAME=Filament
POM_ARTIFACT_ID=filament-android
POM_PACKAGING=aar
Binary file not shown.
@@ -1,5 +0,0 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-172
View File
@@ -1,172 +0,0 @@
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"
-84
View File
@@ -1,84 +0,0 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
+25 -1
View File
@@ -1,4 +1,28 @@
LIBFILAMENT {
global: Java_com_google_android_filament_*; JNI*;
global:
Java_com_google_android_filament_*;
JNI*;
*filament*BufferObject*;
*filament*Camera*;
*filament*Color*;
*filament*Exposure*;
*filament*Skybox*;
*filament*Engine*;
*filament*RenderableManager*;
*filament*Aabb*;
*filament*IndirectLight*;
*filament*LightManager*;
*filament*Renderer*;
*filament*RenderTarget*;
*filament*Scene*;
*filament*ToneMapper*;
*filament*Transform*;
*filament*Material*;
*filament*IndexBuffer*;
*filament*VertexBuffer*;
*filament*View*;
*filament*Texture*;
*filament*geometry*;
local: *;
};
-22
View File
@@ -1,22 +0,0 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# JNI is an entry point that's hard to keep track of, so there's
# an annotation to mark fields and methods used by native code.
# Keep the annotations that proguard needs to process.
-keep class com.google.android.filament.proguard.UsedBy*
# Just because native code accesses members of a class, does not mean that the
# class itself needs to be annotated - only annotate classes that are
# referenced themselves in native code.
-keep @com.google.android.filament.proguard.UsedBy* class * {
<init>();
}
-keepclassmembers class * {
@com.google.android.filament.proguard.UsedBy* *;
}
-1
View File
@@ -1 +0,0 @@
rootProject.name = 'filament-android'
@@ -0,0 +1,100 @@
/*
* Copyright (C) 2021 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.
*/
#include <jni.h>
#include <functional>
#include <stdlib.h>
#include <string.h>
#include <filament/BufferObject.h>
#include <backend/BufferDescriptor.h>
#include "common/CallbackUtils.h"
#include "common/NioUtils.h"
using namespace filament;
using namespace backend;
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_BufferObject_nCreateBuilder(JNIEnv *env, jclass type) {
return (jlong) new BufferObject::Builder();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_BufferObject_nDestroyBuilder(JNIEnv *env, jclass type,
jlong nativeBuilder) {
BufferObject::Builder* builder = (BufferObject::Builder *) nativeBuilder;
delete builder;
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_BufferObject_nBuilderSize(JNIEnv *env, jclass type,
jlong nativeBuilder, jint byteCount) {
BufferObject::Builder* builder = (BufferObject::Builder *) nativeBuilder;
builder->size((uint32_t) byteCount);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_BufferObject_nBuilderBindingType(JNIEnv *env, jclass type,
jlong nativeBuilder, jint bindingType) {
using BindingType = BufferObject::BindingType;
BufferObject::Builder* builder = (BufferObject::Builder *) nativeBuilder;
BindingType types[] = {BindingType::VERTEX};
builder->bindingType(types[bindingType]);
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_BufferObject_nBuilderBuild(JNIEnv *env, jclass type,
jlong nativeBuilder, jlong nativeEngine) {
BufferObject::Builder* builder = (BufferObject::Builder *) nativeBuilder;
Engine *engine = (Engine *) nativeEngine;
return (jlong) builder->build(*engine);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_BufferObject_nGetByteCount(JNIEnv *env, jclass type,
jlong nativeBufferObject) {
BufferObject *bufferObject = (BufferObject *) nativeBufferObject;
return (jint) bufferObject->getByteCount();
}
extern "C" JNIEXPORT int JNICALL
Java_com_google_android_filament_BufferObject_nSetBuffer(JNIEnv *env, jclass type,
jlong nativeBufferObject, jlong nativeEngine, jobject buffer, int remaining,
jint destOffsetInBytes, jint count,
jobject handler, jobject runnable) {
BufferObject *bufferObject = (BufferObject *) nativeBufferObject;
Engine *engine = (Engine *) nativeEngine;
AutoBuffer nioBuffer(env, buffer, count);
void* data = nioBuffer.getData();
size_t sizeInBytes = nioBuffer.getSize();
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
// BufferOverflowException
return -1;
}
auto* callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
BufferDescriptor desc(data, sizeInBytes,
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
bufferObject->setBuffer(*engine, std::move(desc), (uint32_t) destOffsetInBytes);
return 0;
}
+117 -11
View File
@@ -18,6 +18,10 @@
#include <filament/Camera.h>
#include <utils/Entity.h>
#include <math/mat4.h>
using namespace filament;
extern "C" JNIEXPORT void JNICALL
@@ -38,18 +42,38 @@ Java_com_google_android_filament_Camera_nSetProjectionFov(JNIEnv*, jclass ,
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nSetLensProjection(JNIEnv*, jclass,
jlong nativeCamera, jdouble focalLength, jdouble near, jdouble far) {
jlong nativeCamera, jdouble focalLength, jdouble aspect, jdouble near, jdouble far) {
Camera *camera = (Camera *) nativeCamera;
camera->setLensProjection(focalLength, near, far);
camera->setLensProjection(focalLength, aspect, near, far);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nSetCustomProjection(JNIEnv *env, jclass,
jlong nativeCamera, jdoubleArray inMatrix_, jdouble near, jdouble far) {
jlong nativeCamera, jdoubleArray inProjection_, jdoubleArray inProjectionForCulling_,
jdouble near, jdouble far) {
Camera *camera = (Camera *) nativeCamera;
jdouble *inMatrix = env->GetDoubleArrayElements(inMatrix_, NULL);
camera->setCustomProjection(*reinterpret_cast<const filament::math::mat4 *>(inMatrix), near, far);
env->ReleaseDoubleArrayElements(inMatrix_, inMatrix, JNI_ABORT);
jdouble *inProjection = env->GetDoubleArrayElements(inProjection_, NULL);
jdouble *inProjectionForCulling = env->GetDoubleArrayElements(inProjectionForCulling_, NULL);
camera->setCustomProjection(
*reinterpret_cast<const filament::math::mat4 *>(inProjection),
*reinterpret_cast<const filament::math::mat4 *>(inProjectionForCulling),
near, far);
env->ReleaseDoubleArrayElements(inProjection_, inProjection, JNI_ABORT);
env->ReleaseDoubleArrayElements(inProjectionForCulling_, inProjectionForCulling, JNI_ABORT);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nSetScaling(JNIEnv* env, jclass,
jlong nativeCamera, jdouble x, jdouble y) {
Camera *camera = (Camera *) nativeCamera;
camera->setScaling({(double)x, (double)y});
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nSetShift(JNIEnv* env, jclass,
jlong nativeCamera, jdouble x, jdouble y) {
Camera *camera = (Camera *) nativeCamera;
camera->setShift({(double)x, (double)y});
}
extern "C" JNIEXPORT void JNICALL
@@ -60,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;
@@ -78,10 +102,19 @@ Java_com_google_android_filament_Camera_nSetModelMatrix(JNIEnv *env, jclass,
jlong nativeCamera, jfloatArray in_) {
Camera* camera = (Camera *) nativeCamera;
jfloat *in = env->GetFloatArrayElements(in_, NULL);
camera->setModelMatrix(*reinterpret_cast<const filament::math::mat4f*>(in));
camera->setModelMatrix((math::mat4)*reinterpret_cast<const filament::math::mat4f*>(in));
env->ReleaseFloatArrayElements(in_, in, JNI_ABORT);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nSetModelMatrixFp64(JNIEnv *env, jclass,
jlong nativeCamera, jdoubleArray in_) {
Camera* camera = (Camera *) nativeCamera;
jdouble *in = env->GetDoubleArrayElements(in_, NULL);
camera->setModelMatrix(*reinterpret_cast<const filament::math::mat4*>(in));
env->ReleaseDoubleArrayElements(in_, in, JNI_ABORT);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nGetProjectionMatrix(JNIEnv *env, jclass,
jlong nativeCamera, jdoubleArray out_) {
@@ -92,26 +125,66 @@ Java_com_google_android_filament_Camera_nGetProjectionMatrix(JNIEnv *env, jclass
env->ReleaseDoubleArrayElements(out_, out, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nGetCullingProjectionMatrix(JNIEnv *env, jclass,
jlong nativeCamera, jdoubleArray out_) {
Camera *camera = (Camera *) nativeCamera;
jdouble *out = env->GetDoubleArrayElements(out_, NULL);
const filament::math::mat4& m = camera->getCullingProjectionMatrix();
std::copy_n(&m[0][0], 16, out);
env->ReleaseDoubleArrayElements(out_, out, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nGetScaling(JNIEnv *env, jclass,
jlong nativeCamera, jdoubleArray out_) {
Camera *camera = (Camera *) nativeCamera;
jdouble *out = env->GetDoubleArrayElements(out_, NULL);
const filament::math::double4& s = camera->getScaling();
std::copy_n(&s[0], 4, out);
env->ReleaseDoubleArrayElements(out_, out, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nGetModelMatrix(JNIEnv *env, jclass,
jlong nativeCamera, jfloatArray out_) {
Camera *camera = (Camera *) nativeCamera;
jfloat *out = env->GetFloatArrayElements(out_, NULL);
const filament::math::mat4f& m = camera->getModelMatrix();
const filament::math::mat4f& m = (math::mat4f)camera->getModelMatrix();
std::copy_n(&m[0][0], 16, out);
env->ReleaseFloatArrayElements(out_, out, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nGetModelMatrixFp64(JNIEnv *env, jclass,
jlong nativeCamera, jdoubleArray out_) {
Camera *camera = (Camera *) nativeCamera;
jdouble *out = env->GetDoubleArrayElements(out_, NULL);
const filament::math::mat4& m = camera->getModelMatrix();
std::copy_n(&m[0][0], 16, out);
env->ReleaseDoubleArrayElements(out_, out, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nGetViewMatrix(JNIEnv *env, jclass, jlong nativeCamera,
jfloatArray out_) {
Camera *camera = (Camera *) nativeCamera;
jfloat *out = env->GetFloatArrayElements(out_, NULL);
const filament::math::mat4f& m = camera->getViewMatrix();
const filament::math::mat4f& m = (math::mat4f)camera->getViewMatrix();
std::copy_n(&m[0][0], 16, out);
env->ReleaseFloatArrayElements(out_, out, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nGetViewMatrixFp64(JNIEnv *env, jclass, jlong nativeCamera,
jdoubleArray out_) {
Camera *camera = (Camera *) nativeCamera;
jdouble *out = env->GetDoubleArrayElements(out_, NULL);
const filament::math::mat4& m = camera->getViewMatrix();
std::copy_n(&m[0][0], 16, out);
env->ReleaseDoubleArrayElements(out_, out, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nGetPosition(JNIEnv *env, jclass, jlong nativeCamera,
jfloatArray out_) {
@@ -174,3 +247,36 @@ Java_com_google_android_filament_Camera_nGetSensitivity(JNIEnv*, jclass,
Camera *camera = (Camera *) nativeCamera;
return camera->getSensitivity();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Camera_nSetFocusDistance(JNIEnv*, jclass,
jlong nativeCamera, jfloat focusDistance) {
Camera *camera = (Camera *) nativeCamera;
camera->setFocusDistance(focusDistance);
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_Camera_nGetFocusDistance(JNIEnv*, jclass,
jlong nativeCamera) {
Camera *camera = (Camera *) nativeCamera;
return camera->getFocusDistance();
}
extern "C" JNIEXPORT jdouble JNICALL
Java_com_google_android_filament_Camera_nGetFocalLength(JNIEnv*, jclass,
jlong nativeCamera) {
Camera *camera = (Camera *) nativeCamera;
return camera->getFocalLength();
}
extern "C" JNIEXPORT jdouble JNICALL
Java_com_google_android_filament_Camera_nComputeEffectiveFocalLength(JNIEnv*, jclass,
jdouble focalLength, jdouble focusDistance) {
return Camera::computeEffectiveFocalLength(focalLength, focusDistance);
}
extern "C" JNIEXPORT jdouble JNICALL
Java_com_google_android_filament_Camera_nComputeEffectiveFov(JNIEnv*, jclass,
jdouble fovInDegrees, jdouble focusDistance) {
return Camera::computeEffectiveFov(fovInDegrees, focusDistance);
}
@@ -0,0 +1,222 @@
/*
* Copyright (C) 2020 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.
*/
#include <jni.h>
#include <filament/ColorGrading.h>
#include <filament/ToneMapper.h>
#include <math/vec3.h>
#include <math/vec4.h>
using namespace filament;
using namespace math;
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_ColorGrading_nCreateBuilder(JNIEnv*, jclass) {
return (jlong) new ColorGrading::Builder();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nDestroyBuilder(JNIEnv*, jclass, jlong nativeBuilder) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
delete builder;
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderBuild(JNIEnv*, jclass, jlong nativeBuilder, jlong nativeEngine) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
Engine *engine = (Engine *) nativeEngine;
return (jlong) builder->build(*engine);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderQuality(JNIEnv*, jclass, jlong nativeBuilder, jint quality_) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
ColorGrading::QualityLevel quality = (ColorGrading::QualityLevel) quality_;
builder->quality(quality);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderFormat(JNIEnv*, jclass, jlong nativeBuilder, jint format_) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
ColorGrading::LutFormat format = (ColorGrading::LutFormat) format_;
builder->format(format);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderDimensions(JNIEnv*, jclass, jlong nativeBuilder, jint dim_) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->dimensions((uint8_t)dim_);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderToneMapper(JNIEnv*, jclass,
jlong nativeBuilder, jlong toneMapper_) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
const ToneMapper* toneMapper = (const ToneMapper*) toneMapper_;
builder->toneMapper(toneMapper);
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderToneMapping(JNIEnv*, jclass,
jlong nativeBuilder, jint toneMapping_) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
ColorGrading::ToneMapping toneMapping = (ColorGrading::ToneMapping) toneMapping_;
builder->toneMapping(toneMapping);
}
#pragma clang diagnostic pop
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderLuminanceScaling(JNIEnv*, jclass,
jlong nativeBuilder, jboolean luminanceScaling) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->luminanceScaling(luminanceScaling);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderGamutMapping(JNIEnv*, jclass,
jlong nativeBuilder, jboolean gamutMapping) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->gamutMapping(gamutMapping);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderExposure(JNIEnv*, jclass,
jlong nativeBuilder, jfloat exposure) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->exposure(exposure);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderNightAdaptation(JNIEnv*, jclass,
jlong nativeBuilder, jfloat adaptation) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->nightAdaptation(adaptation);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderWhiteBalance(JNIEnv*, jclass,
jlong nativeBuilder, jfloat temperature, jfloat tint) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->whiteBalance(temperature, tint);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderChannelMixer(JNIEnv* env, jclass,
jlong nativeBuilder, jfloatArray outRed_, jfloatArray outGreen_, jfloatArray outBlue_) {
jfloat* outRed = env->GetFloatArrayElements(outRed_, nullptr);
jfloat* outGreen = env->GetFloatArrayElements(outGreen_, nullptr);
jfloat* outBlue = env->GetFloatArrayElements(outBlue_, nullptr);
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->channelMixer(
*reinterpret_cast<float3*>(outRed),
*reinterpret_cast<float3*>(outGreen),
*reinterpret_cast<float3*>(outBlue));
env->ReleaseFloatArrayElements(outRed_, outRed, JNI_ABORT);
env->ReleaseFloatArrayElements(outGreen_, outGreen, JNI_ABORT);
env->ReleaseFloatArrayElements(outBlue_, outBlue, JNI_ABORT);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderShadowsMidtonesHighlights(JNIEnv* env, jclass, jlong nativeBuilder,
jfloatArray shadows_, jfloatArray midtones_, jfloatArray highlights_, jfloatArray ranges_) {
jfloat* shadows = env->GetFloatArrayElements(shadows_, nullptr);
jfloat* midtones = env->GetFloatArrayElements(midtones_, nullptr);
jfloat* highlights = env->GetFloatArrayElements(highlights_, nullptr);
jfloat* ranges = env->GetFloatArrayElements(ranges_, nullptr);
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->shadowsMidtonesHighlights(
*reinterpret_cast<float4*>(shadows),
*reinterpret_cast<float4*>(midtones),
*reinterpret_cast<float4*>(highlights),
*reinterpret_cast<float4*>(ranges));
env->ReleaseFloatArrayElements(shadows_, shadows, JNI_ABORT);
env->ReleaseFloatArrayElements(midtones_, midtones, JNI_ABORT);
env->ReleaseFloatArrayElements(highlights_, highlights, JNI_ABORT);
env->ReleaseFloatArrayElements(ranges_, ranges, JNI_ABORT);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderSlopeOffsetPower(JNIEnv* env, jclass,
jlong nativeBuilder, jfloatArray slope_, jfloatArray offset_, jfloatArray power_) {
jfloat* slope = env->GetFloatArrayElements(slope_, nullptr);
jfloat* offset = env->GetFloatArrayElements(offset_, nullptr);
jfloat* power = env->GetFloatArrayElements(power_, nullptr);
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->slopeOffsetPower(
*reinterpret_cast<float3*>(slope),
*reinterpret_cast<float3*>(offset),
*reinterpret_cast<float3*>(power));
env->ReleaseFloatArrayElements(slope_, slope, JNI_ABORT);
env->ReleaseFloatArrayElements(offset_, offset, JNI_ABORT);
env->ReleaseFloatArrayElements(power_, power, JNI_ABORT);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderContrast(JNIEnv*, jclass,
jlong nativeBuilder, jfloat contrast) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->contrast(contrast);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderVibrance(JNIEnv*, jclass,
jlong nativeBuilder, jfloat vibrance) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->vibrance(vibrance);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderSaturation(JNIEnv*, jclass,
jlong nativeBuilder, jfloat saturation) {
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->saturation(saturation);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ColorGrading_nBuilderCurves(JNIEnv* env, jclass,
jlong nativeBuilder, jfloatArray gamma_, jfloatArray midPoint_, jfloatArray scale_) {
jfloat* gamma = env->GetFloatArrayElements(gamma_, nullptr);
jfloat* midPoint = env->GetFloatArrayElements(midPoint_, nullptr);
jfloat* scale = env->GetFloatArrayElements(scale_, nullptr);
ColorGrading::Builder* builder = (ColorGrading::Builder*) nativeBuilder;
builder->curves(
*reinterpret_cast<float3*>(gamma),
*reinterpret_cast<float3*>(midPoint),
*reinterpret_cast<float3*>(scale));
env->ReleaseFloatArrayElements(gamma_, gamma, JNI_ABORT);
env->ReleaseFloatArrayElements(midPoint_, midPoint, JNI_ABORT);
env->ReleaseFloatArrayElements(scale_, scale, JNI_ABORT);
}
+140 -65
View File
@@ -16,8 +16,12 @@
#include <jni.h>
#include <filament/Camera.h>
#include <filament/Engine.h>
#include <utils/Entity.h>
#include <utils/EntityManager.h>
using namespace filament;
using namespace utils;
@@ -41,12 +45,11 @@ extern "C" {
// handle. Whatever object is returned from this method must match what is in
// folder filament/src/driver/opengl/Context* in particular pay attention to
// the object type in makeCurrent method.
extern void *getNativeWindow(JNIEnv *env, jclass, jobject surface);
extern void* getNativeWindow(JNIEnv* env, jclass, jobject surface);
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Engine_nGetBackend(JNIEnv* env,
jclass klass, jlong nativeEngine) {
Java_com_google_android_filament_Engine_nGetBackend(JNIEnv*, jclass, jlong nativeEngine) {
Engine* engine = (Engine*) nativeEngine;
return (jlong) engine->getBackend();
}
@@ -59,6 +62,13 @@ Java_com_google_android_filament_Engine_nCreateSwapChain(JNIEnv* env,
return (jlong) engine->createSwapChain(win, (uint64_t) flags);
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Engine_nCreateSwapChainHeadless(JNIEnv*,
jclass, jlong nativeEngine, jint width, jint height, jlong flags) {
Engine* engine = (Engine*) nativeEngine;
return (jlong) engine->createSwapChain(width, height, (uint64_t) flags);
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Engine_nCreateSwapChainFromRawPointer(JNIEnv*,
jclass, jlong nativeEngine, jlong pointer, jlong flags) {
@@ -66,12 +76,12 @@ Java_com_google_android_filament_Engine_nCreateSwapChainFromRawPointer(JNIEnv*,
return (jlong) engine->createSwapChain((void*)pointer, (uint64_t) flags);
}
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroySwapChain(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeSwapChain) {
Engine* engine = (Engine*) nativeEngine;
SwapChain *swapChain = (SwapChain *) nativeSwapChain;
engine->destroy(swapChain);
SwapChain* swapChain = (SwapChain*) nativeSwapChain;
return engine->destroy(swapChain);
}
// View
@@ -83,12 +93,12 @@ Java_com_google_android_filament_Engine_nCreateView(JNIEnv*, jclass,
return (jlong) engine->createView();
}
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyView(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeView) {
Engine* engine = (Engine*) nativeEngine;
View *view = (View *) nativeView;
engine->destroy(view);
View* view = (View*) nativeView;
return engine->destroy(view);
}
// Renderer
@@ -100,37 +110,38 @@ Java_com_google_android_filament_Engine_nCreateRenderer(JNIEnv*, jclass,
return (jlong) engine->createRenderer();
}
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyRenderer(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeRenderer) {
Engine* engine = (Engine*) nativeEngine;
Renderer *renderer = (Renderer *) nativeRenderer;
engine->destroy(renderer);
Renderer* renderer = (Renderer*) nativeRenderer;
return engine->destroy(renderer);
}
// Camera
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Engine_nCreateCamera(JNIEnv*, jclass,
jlong nativeEngine) {
Engine* engine = (Engine*) nativeEngine;
return (jlong) engine->createCamera();
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Engine_nCreateCameraWithEntity(JNIEnv*, jclass,
jlong nativeEngine, jint entity_) {
Engine* engine = (Engine*) nativeEngine;
Entity& entity = *reinterpret_cast<Entity*>(&entity_);
return (jlong) engine->createCamera(entity);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Engine_nDestroyCamera(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeCamera) {
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Engine_nGetCameraComponent(JNIEnv*, jclass,
jlong nativeEngine, jint entity_) {
Engine* engine = (Engine*) nativeEngine;
Camera *camera = (Camera *) nativeCamera;
engine->destroy(camera);
Entity& entity = *reinterpret_cast<Entity*>(&entity_);
return (jlong) engine->getCameraComponent(entity);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Engine_nDestroyCameraComponent(JNIEnv*, jclass,
jlong nativeEngine, jint entity_) {
Engine* engine = (Engine*) nativeEngine;
Entity& entity = *reinterpret_cast<Entity*>(&entity_);
engine->destroyCameraComponent(entity);
}
// Scene
@@ -142,106 +153,121 @@ Java_com_google_android_filament_Engine_nCreateScene(JNIEnv*, jclass,
return (jlong) engine->createScene();
}
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyScene(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeScene) {
Engine* engine = (Engine*) nativeEngine;
Scene *scene = (Scene *) nativeScene;
engine->destroy(scene);
Scene* scene = (Scene*) nativeScene;
return engine->destroy(scene);
}
// Fence
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Engine_nCreateFence(JNIEnv*, jclass,
jlong nativeEngine, jint fenceType) {
jlong nativeEngine) {
Engine* engine = (Engine*) nativeEngine;
return (jlong) engine->createFence((Fence::Type) fenceType);
return (jlong) engine->createFence();
}
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyFence(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeFence) {
Engine* engine = (Engine*) nativeEngine;
Fence *fence = (Fence *) nativeFence;
engine->destroy(fence);
Fence* fence = (Fence*) nativeFence;
return engine->destroy(fence);
}
// Stream
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyStream(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeStream) {
Engine* engine = (Engine*) nativeEngine;
Stream *stream = (Stream *) nativeStream;
engine->destroy(stream);
Stream* stream = (Stream*) nativeStream;
return engine->destroy(stream);
}
// Others...
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyIndexBuffer(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeIndexBuffer) {
Engine* engine = (Engine*) nativeEngine;
IndexBuffer *indexBuffer = (IndexBuffer *) nativeIndexBuffer;
engine->destroy(indexBuffer);
IndexBuffer* indexBuffer = (IndexBuffer*) nativeIndexBuffer;
return engine->destroy(indexBuffer);
}
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyVertexBuffer(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeVertexBuffer) {
Engine* engine = (Engine*) nativeEngine;
VertexBuffer *vertexBuffer = (VertexBuffer *) nativeVertexBuffer;
engine->destroy(vertexBuffer);
VertexBuffer* vertexBuffer = (VertexBuffer*) nativeVertexBuffer;
return engine->destroy(vertexBuffer);
}
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroySkinningBuffer(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeSkinningBuffer) {
Engine* engine = (Engine*) nativeEngine;
SkinningBuffer* skinningBuffer = (SkinningBuffer*) nativeSkinningBuffer;
return engine->destroy(skinningBuffer);
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyIndirectLight(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeIndirectLight) {
Engine* engine = (Engine*) nativeEngine;
IndirectLight *indirectLight = (IndirectLight *) nativeIndirectLight;
engine->destroy(indirectLight);
IndirectLight* indirectLight = (IndirectLight*) nativeIndirectLight;
return engine->destroy(indirectLight);
}
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyMaterial(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeMaterial) {
Engine* engine = (Engine*) nativeEngine;
Material *material = (Material *) nativeMaterial;
engine->destroy(material);
Material* material = (Material*) nativeMaterial;
return engine->destroy(material);
}
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyMaterialInstance(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeMaterialInstance) {
Engine* engine = (Engine*) nativeEngine;
MaterialInstance* materialInstance =
(MaterialInstance*) nativeMaterialInstance;
engine->destroy(materialInstance);
MaterialInstance* materialInstance = (MaterialInstance*) nativeMaterialInstance;
return engine->destroy(materialInstance);
}
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroySkybox(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeSkybox) {
Engine* engine = (Engine*) nativeEngine;
Skybox *skybox = (Skybox *) nativeSkybox;
engine->destroy(skybox);
Skybox* skybox = (Skybox*) nativeSkybox;
return engine->destroy(skybox);
}
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyColorGrading(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeColorGrading) {
Engine* engine = (Engine*) nativeEngine;
ColorGrading* colorGrading = (ColorGrading*) nativeColorGrading;
return engine->destroy(colorGrading);
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyTexture(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeTexture) {
Engine* engine = (Engine*) nativeEngine;
Texture *texture = (Texture *) nativeTexture;
engine->destroy(texture);
Texture* texture = (Texture*) nativeTexture;
return engine->destroy(texture);
}
extern "C" JNIEXPORT void JNICALL
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Engine_nDestroyRenderTarget(JNIEnv*, jclass,
jlong nativeEngine, jlong nativeTarget) {
Engine* engine = (Engine*) nativeEngine;
RenderTarget* target = (RenderTarget*) nativeTarget;
engine->destroy(target);
return engine->destroy(target);
}
extern "C" JNIEXPORT void JNICALL
@@ -252,25 +278,74 @@ Java_com_google_android_filament_Engine_nDestroyEntity(JNIEnv*, jclass,
engine->destroy(entity);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Engine_nFlushAndWait(JNIEnv*, jclass,
jlong nativeEngine) {
Engine* engine = (Engine*) nativeEngine;
engine->flushAndWait();
}
// Managers...
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Engine_nGetTransformManager(JNIEnv*, jclass,
jlong nativeEngine) {
Java_com_google_android_filament_Engine_nGetTransformManager(JNIEnv*, jclass, jlong nativeEngine) {
Engine* engine = (Engine*) nativeEngine;
return (jlong) &engine->getTransformManager();
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Engine_nGetLightManager(JNIEnv*, jclass,
jlong nativeEngine) {
Java_com_google_android_filament_Engine_nGetLightManager(JNIEnv*, jclass, jlong nativeEngine) {
Engine* engine = (Engine*) nativeEngine;
return (jlong) &engine->getLightManager();
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Engine_nGetRenderableManager(JNIEnv*, jclass,
jlong nativeEngine) {
Java_com_google_android_filament_Engine_nGetRenderableManager(JNIEnv*, jclass, jlong nativeEngine) {
Engine* engine = (Engine*) nativeEngine;
return (jlong) &engine->getRenderableManager();
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Engine_nGetJobSystem(JNIEnv*, jclass, jlong nativeEngine) {
Engine* engine = (Engine*) nativeEngine;
return (jlong) &engine->getJobSystem();
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Engine_nGetEntityManager(JNIEnv*, jclass, jlong nativeEngine) {
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();
}
@@ -16,27 +16,17 @@
#include <jni.h>
extern void registerCallbackUtils(JNIEnv*);
extern void registerMaterial(JNIEnv*);
extern void registerNioUtils(JNIEnv*);
#include "private/backend/VirtualMachineEnv.h"
namespace filament {
extern jint JNI_OnLoad(JavaVM* vm, void* reserved);
};
jint JNI_OnLoad(JavaVM* vm, void* reserved) {
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
JNIEnv* env;
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
return -1;
}
registerCallbackUtils(env);
registerMaterial(env);
registerNioUtils(env);
#if ANDROID
::filament::JNI_OnLoad(vm, reserved);
#endif
// This must be called when the library is loaded. We need this to get a reference to the
// global VM
::filament::VirtualMachineEnv::JNI_OnLoad(vm);
return JNI_VERSION_1_6;
}
@@ -22,6 +22,8 @@
#include <filament/IndexBuffer.h>
#include <backend/BufferDescriptor.h>
#include "common/CallbackUtils.h"
#include "common/NioUtils.h"
@@ -89,7 +91,8 @@ Java_com_google_android_filament_IndexBuffer_nSetBuffer(JNIEnv *env, jclass type
auto* callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
BufferDescriptor desc(data, sizeInBytes, &JniBufferCallback::invoke, callback);
BufferDescriptor desc(data, sizeInBytes,
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
indexBuffer->setBuffer(*engine, std::move(desc), (uint32_t) destOffsetInBytes);
@@ -20,6 +20,7 @@
#include <filament/Texture.h>
#include <common/NioUtils.h>
#include <common/CallbackUtils.h>
#include <math/mat4.h>
using namespace filament;
@@ -92,8 +93,6 @@ Java_com_google_android_filament_IndirectLight_nRotation(JNIEnv *, jclass, jlong
builder->rotation(filament::math::mat3f{v0, v1, v2, v3, v4, v5, v6, v7, v8});
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_IndirectLight_nSetIntensity(JNIEnv*, jclass,
jlong nativeIndirectLight, jfloat intensity) {
@@ -109,9 +108,75 @@ Java_com_google_android_filament_IndirectLight_nGetIntensity(JNIEnv*, jclass,
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_IndirectLight_nSetRotation(JNIEnv *env, jclass type,
jlong nativeIndirectLight, jfloat v0, jfloat v1, jfloat v2, jfloat v3, jfloat v4, jfloat v5,
jfloat v6, jfloat v7, jfloat v8) {
Java_com_google_android_filament_IndirectLight_nSetRotation(JNIEnv*, jclass,
jlong nativeIndirectLight, jfloat v0, jfloat v1, jfloat v2,
jfloat v3, jfloat v4, jfloat v5, jfloat v6, jfloat v7, jfloat v8) {
IndirectLight *indirectLight = (IndirectLight *) nativeIndirectLight;
indirectLight->setRotation(filament::math::mat3f{v0, v1, v2, v3, v4, v5, v6, v7, v8});
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_IndirectLight_nGetRotation(JNIEnv* env, jclass,
jlong nativeIndirectLight, jfloatArray outRotation_) {
IndirectLight *indirectLight = (IndirectLight *) nativeIndirectLight;
jfloat *outRotation = env->GetFloatArrayElements(outRotation_, NULL);
*reinterpret_cast<filament::math::mat3f*>(outRotation) = indirectLight->getRotation();
env->ReleaseFloatArrayElements(outRotation_, outRotation, 0);
}
extern "C" [[deprecated]] JNIEXPORT void JNICALL
Java_com_google_android_filament_IndirectLight_nGetDirectionEstimate(JNIEnv* env, jclass,
jlong nativeIndirectLight, jfloatArray outDirection_) {
IndirectLight *indirectLight = (IndirectLight *) nativeIndirectLight;
jfloat *outDirection = env->GetFloatArrayElements(outDirection_, NULL);
*reinterpret_cast<filament::math::float3*>(outDirection) = indirectLight->getDirectionEstimate();
env->ReleaseFloatArrayElements(outDirection_, outDirection, 0);
}
extern "C" [[deprecated]] JNIEXPORT void JNICALL
Java_com_google_android_filament_IndirectLight_nGetColorEstimate(JNIEnv* env, jclass,
jlong nativeIndirectLight, jfloatArray outColor_, jfloat x, jfloat y, jfloat z) {
IndirectLight *indirectLight = (IndirectLight *) nativeIndirectLight;
jfloat *outColor = env->GetFloatArrayElements(outColor_, NULL);
*reinterpret_cast<filament::math::float4*>(outColor) =
indirectLight->getColorEstimate(math::float3{x, y, z});
env->ReleaseFloatArrayElements(outColor_, outColor, 0);
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_IndirectLight_nGetReflectionsTexture(JNIEnv* env, jclass,
jlong nativeIndirectLight) {
IndirectLight *indirectLight = (IndirectLight *) nativeIndirectLight;
Texture const *tex = indirectLight->getReflectionsTexture();
return (jlong) tex;
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_IndirectLight_nGetIrradianceTexture(JNIEnv* env, jclass,
jlong nativeIndirectLight) {
IndirectLight *indirectLight = (IndirectLight *) nativeIndirectLight;
Texture const *tex = indirectLight->getIrradianceTexture();
return (jlong) tex;
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_IndirectLight_nGetDirectionEstimateStatic(JNIEnv *env, jclass,
jfloatArray sh_, jfloatArray outDirection_) {
jfloat* sh = env->GetFloatArrayElements(sh_, NULL);
jfloat *outDirection = env->GetFloatArrayElements(outDirection_, NULL);
*reinterpret_cast<filament::math::float3*>(outDirection) = IndirectLight::getDirectionEstimate((filament::math::float3*)sh);
env->ReleaseFloatArrayElements(outDirection_, outDirection, 0);
env->ReleaseFloatArrayElements(sh_, sh, JNI_ABORT);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_IndirectLight_nGetColorEstimateStatic(JNIEnv *env, jclass,
jfloatArray outColor_, jfloatArray sh_, jfloat x, jfloat y, jfloat z) {
jfloat* sh = env->GetFloatArrayElements(sh_, NULL);
jfloat *outColor = env->GetFloatArrayElements(outColor_, NULL);
*reinterpret_cast<filament::math::float4*>(outColor) =
IndirectLight::getColorEstimate((filament::math::float3*)sh, math::float3{x, y, z});
env->ReleaseFloatArrayElements(outColor_, outColor, 0);
env->ReleaseFloatArrayElements(sh_, sh, JNI_ABORT);
}
@@ -18,150 +18,225 @@
#include <filament/LightManager.h>
#include <utils/Entity.h>
#include <algorithm>
using namespace filament;
using namespace utils;
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_LightManager_nGetComponentCount(JNIEnv*, jclass,
jlong nativeLightManager) {
LightManager *lm = (LightManager *) nativeLightManager;
return lm->getComponentCount();
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_LightManager_nHasComponent(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nHasComponent(JNIEnv*, jclass,
jlong nativeLightManager, jint entity) {
LightManager *lm = (LightManager *) nativeLightManager;
return (jboolean) lm->hasComponent((Entity &) entity);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_LightManager_nGetInstance(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nGetInstance(JNIEnv*, jclass,
jlong nativeLightManager, jint entity) {
LightManager *lm = (LightManager *) nativeLightManager;
return lm->getInstance((Entity &) entity);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nDestroy(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nDestroy(JNIEnv*, jclass,
jlong nativeLightManager, jint entity) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->destroy((Entity &) entity);
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_LightManager_nCreateBuilder(JNIEnv *env, jclass type,
jint lightType) {
Java_com_google_android_filament_LightManager_nCreateBuilder(JNIEnv*, jclass, jint lightType) {
return (jlong) new LightManager::Builder((LightManager::Type) lightType);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nDestroyBuilder(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nDestroyBuilder(JNIEnv*, jclass,
jlong nativeBuilder) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
delete builder;
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderCastShadows(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderCastShadows(JNIEnv*, jclass,
jlong nativeBuilder, jboolean enable) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->castShadows(enable);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderShadowOptions(JNIEnv *env, jclass type,
jlong nativeBuilder, jint mapSize, jfloat constantBias, jfloat normalBias, jfloat shadowFar,
jfloat shadowNearHint, jfloat shadowFarHint, jboolean stable) {
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 polygonOffsetConstant, jfloat polygonOffsetSlope,
jboolean screenSpaceContactShadows, jint stepCount,
jfloat maxShadowDistance, jint vsmMsaaSamples, jfloat blurWidth, jfloat shadowBulbRadius) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->shadowOptions(
LightManager::ShadowOptions{.mapSize = (uint32_t)mapSize,
.constantBias = constantBias,
.normalBias = normalBias,
.shadowFar = shadowFar,
.shadowNearHint = shadowNearHint,
.shadowFarHint = shadowFarHint,
.stable = (bool)stable});
LightManager::ShadowOptions shadowOptions {
.mapSize = (uint32_t)mapSize,
.shadowCascades = (uint8_t)cascades,
.constantBias = constantBias,
.normalBias = normalBias,
.shadowFar = shadowFar,
.shadowNearHint = shadowNearHint,
.shadowFarHint = shadowFarHint,
.stable = (bool)stable,
.polygonOffsetConstant = polygonOffsetConstant,
.polygonOffsetSlope = polygonOffsetConstant,
.screenSpaceContactShadows = (bool)screenSpaceContactShadows,
.stepCount = uint8_t(stepCount),
.maxShadowDistance = maxShadowDistance,
.vsm = {
.msaaSamples = (uint8_t) vsmMsaaSamples,
.blurWidth = blurWidth
},
.shadowBulbRadius = shadowBulbRadius
};
jfloat *nativeSplits = env->GetFloatArrayElements(splitPositions, NULL);
const jsize splitCount = std::min((jsize) 3, env->GetArrayLength(splitPositions));
for (jsize i = 0; i < splitCount; i++) {
shadowOptions.cascadeSplitPositions[i] = nativeSplits[i];
}
env->ReleaseFloatArrayElements(splitPositions, nativeSplits, 0);
builder->shadowOptions(shadowOptions);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderCastLight(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderCastLight(JNIEnv*, jclass,
jlong nativeBuilder, jboolean enabled) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->castLight(enabled);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderPosition(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderPosition(JNIEnv*, jclass,
jlong nativeBuilder, jfloat x, jfloat y, jfloat z) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->position({x, y, z});
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderDirection(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderDirection(JNIEnv*, jclass,
jlong nativeBuilder, jfloat x, jfloat y, jfloat z) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->direction({x, y, z});
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderColor(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderColor(JNIEnv*, jclass,
jlong nativeBuilder, jfloat linearR, jfloat linearG, jfloat linearB) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->color({linearR, linearG, linearB});
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderIntensity__JF(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderIntensityCandela(JNIEnv*, jclass,
jlong nativeBuilder, jfloat intensity) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->intensityCandela(intensity);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderIntensity__JF(JNIEnv*, jclass,
jlong nativeBuilder, jfloat intensity) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->intensity(intensity);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderIntensity__JFF(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderIntensity__JFF(JNIEnv*, jclass,
jlong nativeBuilder, jfloat watts, jfloat efficiency) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->intensity(watts, efficiency);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderFalloff(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderFalloff(JNIEnv*, jclass,
jlong nativeBuilder, jfloat radius) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->falloff(radius);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderSpotLightCone(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderSpotLightCone(JNIEnv*, jclass,
jlong nativeBuilder, jfloat inner, jfloat outer) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->spotLightCone(inner, outer);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderAngularRadius(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderAngularRadius(JNIEnv*, jclass,
jlong nativeBuilder, jfloat angularRadius) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->sunAngularRadius(angularRadius);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderHaloSize(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderHaloSize(JNIEnv*, jclass,
jlong nativeBuilder, jfloat haloSize) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->sunHaloSize(haloSize);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderHaloFalloff(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderHaloFalloff(JNIEnv*, jclass,
jlong nativeBuilder, jfloat haloFalloff) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->sunHaloFalloff(haloFalloff);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nBuilderLightChannel(JNIEnv*, jclass,
jlong nativeBuilder, jint channel, jboolean enable) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
builder->lightChannel(channel, (bool)enable);
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_LightManager_nBuilderBuild(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nBuilderBuild(JNIEnv*, jclass,
jlong nativeBuilder, jlong nativeEngine, jint entity) {
LightManager::Builder *builder = (LightManager::Builder *) nativeBuilder;
Engine *engine = (Engine *) nativeEngine;
return jboolean(builder->build(*engine, (Entity &) entity) == LightManager::Builder::Success);
}
// ------------------------------------------------------------------------------------------------
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nComputeUniformSplits(JNIEnv* env, jclass,
jfloatArray splitPositions, jint cascades) {
jfloat *nativeSplits = env->GetFloatArrayElements(splitPositions, NULL);
LightManager::ShadowCascades::computeUniformSplits(nativeSplits, (uint8_t) cascades);
env->ReleaseFloatArrayElements(splitPositions, nativeSplits, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nComputeLogSplits(JNIEnv* env, jclass,
jfloatArray splitPositions, jint cascades, jfloat near, jfloat far) {
jfloat *nativeSplits = env->GetFloatArrayElements(splitPositions, NULL);
LightManager::ShadowCascades::computeLogSplits(nativeSplits, (uint8_t) cascades, near, far);
env->ReleaseFloatArrayElements(splitPositions, nativeSplits, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nComputePracticalSplits(JNIEnv* env, jclass,
jfloatArray splitPositions, jint cascades, jfloat near, jfloat far, jfloat lambda) {
jfloat *nativeSplits = env->GetFloatArrayElements(splitPositions, NULL);
LightManager::ShadowCascades::computePracticalSplits(nativeSplits, (uint8_t) cascades, near, far, lambda);
env->ReleaseFloatArrayElements(splitPositions, nativeSplits, 0);
}
// ------------------------------------------------------------------------------------------------
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_LightManager_nGetType(JNIEnv* env,
jclass type, jlong nativeLightManager, jint i) {
@@ -170,133 +245,182 @@ Java_com_google_android_filament_LightManager_nGetType(JNIEnv* env,
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetPosition(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nSetPosition(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jfloat x, jfloat y, jfloat z) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setPosition((LightManager::Instance) i, {x, y, z});
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nGetPosition(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nGetPosition(JNIEnv* env, jclass,
jlong nativeLightManager, jint i, jfloatArray out_) {
LightManager *lm = (LightManager *) nativeLightManager;
jfloat *out = env->GetFloatArrayElements(out_, NULL);
jfloat *out = env->GetFloatArrayElements(out_, nullptr);
*reinterpret_cast<filament::math::float3 *>(out) = lm->getPosition((LightManager::Instance) i);
env->ReleaseFloatArrayElements(out_, out, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetDirection(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nSetDirection(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jfloat x, jfloat y, jfloat z) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setDirection((LightManager::Instance) i, {x, y, z});
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nGetDirection(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nGetDirection(JNIEnv *env, jclass,
jlong nativeLightManager, jint i, jfloatArray out_) {
LightManager *lm = (LightManager *) nativeLightManager;
jfloat *out = env->GetFloatArrayElements(out_, NULL);
jfloat *out = env->GetFloatArrayElements(out_, nullptr);
*reinterpret_cast<filament::math::float3 *>(out) = lm->getDirection((LightManager::Instance) i);
env->ReleaseFloatArrayElements(out_, out, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetColor(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nSetColor(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jfloat linearR, jfloat linearG, jfloat linearB) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setColor((LightManager::Instance) i, {linearR, linearG, linearB});
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nGetColor(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nGetColor(JNIEnv *env, jclass,
jlong nativeLightManager, jint i, jfloatArray out_) {
LightManager *lm = (LightManager *) nativeLightManager;
jfloat *out = env->GetFloatArrayElements(out_, NULL);
jfloat *out = env->GetFloatArrayElements(out_, nullptr);
*reinterpret_cast<filament::math::float3 *>(out) = lm->getColor((LightManager::Instance) i);
env->ReleaseFloatArrayElements(out_, out, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetIntensity__JIF(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nSetIntensity__JIF(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jfloat intensity) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setIntensity((LightManager::Instance) i, intensity);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetIntensity__JIFF(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nSetIntensity__JIFF(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jfloat watts, jfloat efficiency) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setIntensity((LightManager::Instance) i, watts, efficiency);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetIntensityCandela(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jfloat intensity) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setIntensityCandela((LightManager::Instance) i, intensity);
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_LightManager_nGetIntensity(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nGetIntensity(JNIEnv*, jclass,
jlong nativeLightManager, jint i) {
LightManager *lm = (LightManager *) nativeLightManager;
return lm->getIntensity((LightManager::Instance) i);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetFalloff(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nSetFalloff(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jfloat falloff) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setFalloff((LightManager::Instance) i, falloff);
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_LightManager_nGetFalloff(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nGetFalloff(JNIEnv*, jclass,
jlong nativeLightManager, jint i) {
LightManager *lm = (LightManager *) nativeLightManager;
return lm->getFalloff((LightManager::Instance) i);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetSpotLightCone(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nSetSpotLightCone(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jfloat inner, jfloat outer) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setSpotLightCone((LightManager::Instance) i, inner, outer);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetSunAngularRadius(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nSetSunAngularRadius(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jfloat angularRadius) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setSunAngularRadius((LightManager::Instance) i, angularRadius);
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_LightManager_nGetSunAngularRadius(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nGetSunAngularRadius(JNIEnv*, jclass,
jlong nativeLightManager, jint i) {
LightManager *lm = (LightManager *) nativeLightManager;
return lm->getSunAngularRadius((LightManager::Instance) i);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetSunHaloSize(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nSetSunHaloSize(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jfloat haloSize) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setSunHaloSize((LightManager::Instance) i, haloSize);
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_LightManager_nGetHaloSize(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nGetSunHaloSize(JNIEnv*, jclass,
jlong nativeLightManager, jint i) {
LightManager *lm = (LightManager *) nativeLightManager;
return lm->getSunHaloSize((LightManager::Instance) i);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetSunHaloFalloff(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nSetSunHaloFalloff(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jfloat haloFalloff) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setSunHaloFalloff((LightManager::Instance) i, haloFalloff);
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_LightManager_nGetHaloFalloff(JNIEnv *env, jclass type,
Java_com_google_android_filament_LightManager_nGetSunHaloFalloff(JNIEnv*, jclass,
jlong nativeLightManager, jint i) {
LightManager *lm = (LightManager *) nativeLightManager;
return lm->getSunHaloFalloff((LightManager::Instance) i);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetShadowCaster(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jboolean shadowCaster) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setShadowCaster((LightManager::Instance) i, shadowCaster);
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_LightManager_nIsShadowCaster(JNIEnv*, jclass,
jlong nativeLightManager, jint i) {
LightManager *lm = (LightManager *) nativeLightManager;
return (jboolean)lm->isShadowCaster((LightManager::Instance) i);
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_LightManager_nGetOuterConeAngle(JNIEnv*, jclass,
jlong nativeLightManager, jint i) {
LightManager *lm = (LightManager *) nativeLightManager;
return (jfloat)lm->getSpotLightOuterCone((LightManager::Instance) i);
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_LightManager_nGetInnerConeAngle(JNIEnv*, jclass,
jlong nativeLightManager, jint i) {
LightManager *lm = (LightManager *) nativeLightManager;
return (jfloat)lm->getSpotLightInnerCone((LightManager::Instance) i);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_LightManager_nSetLightChannel(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jint channel, jboolean enable) {
LightManager *lm = (LightManager *) nativeLightManager;
lm->setLightChannel((LightManager::Instance) i, channel, (bool)enable);
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_LightManager_nGetLightChannel(JNIEnv*, jclass,
jlong nativeLightManager, jint i, jint channel) {
LightManager const *lm = (LightManager const *) nativeLightManager;
return lm->getLightChannel((LightManager::Instance) i, channel);
}
@@ -22,12 +22,6 @@
using namespace filament;
struct {
jclass parameterClass;
jmethodID parameterAdd;
jfieldID parameterSamplerOffset;
} gMaterial;
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Material_nBuilderBuild(JNIEnv *env, jclass,
jlong nativeEngine, jobject buffer_, jint size) {
@@ -53,6 +47,16 @@ Java_com_google_android_filament_Material_nCreateInstance(JNIEnv*, jclass,
return (jlong) material->createInstance();
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Material_nCreateInstanceWithName(JNIEnv* env, jclass,
jlong nativeMaterial, jstring name_) {
Material* material = (Material*) nativeMaterial;
const char *name = env->GetStringUTFChars(name_, 0);
jlong instance = (jlong) material->createInstance(name);
env->ReleaseStringUTFChars(name_, name);
return instance;
}
extern "C"
JNIEXPORT jstring JNICALL
Java_com_google_android_filament_Material_nGetName(JNIEnv* env, jclass, jlong nativeMaterial) {
@@ -84,6 +88,23 @@ Java_com_google_android_filament_Material_nGetBlendingMode(JNIEnv*, jclass,
return (jint) material->getBlendingMode();
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_Material_nGetRefractionMode(JNIEnv*, jclass,
jlong nativeMaterial) {
Material* material = (Material*) nativeMaterial;
return (jint)material->getRefractionMode();
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_Material_nGetRefractionType(JNIEnv*, jclass,
jlong nativeMaterial) {
Material* material = (Material*) nativeMaterial;
return (jint) material->getRefractionType();
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_Material_nGetVertexDomain(JNIEnv*, jclass,
@@ -174,16 +195,38 @@ Java_com_google_android_filament_Material_nGetParameters(JNIEnv* env, jclass,
size_t received = material->getParameters(info, (size_t) count);
assert(received == count);
jint offset = env->GetStaticIntField(gMaterial.parameterClass, gMaterial.parameterSamplerOffset);
jclass parameterClass = env->FindClass("com/google/android/filament/Material$Parameter");
parameterClass = (jclass) env->NewLocalRef(parameterClass);
jmethodID parameterAdd = env->GetStaticMethodID(parameterClass, "add",
"(Ljava/util/List;Ljava/lang/String;III)V");
jfieldID parameterSamplerOffset = env->GetStaticFieldID(parameterClass,
"SAMPLER_OFFSET", "I");
jfieldID parameterSubpassOffset = env->GetStaticFieldID(parameterClass,
"SUBPASS_OFFSET", "I");
jint offset = env->GetStaticIntField(parameterClass, parameterSamplerOffset);
jint subpassOffset = env->GetStaticIntField(parameterClass, parameterSubpassOffset);
for (size_t i = 0; i < received; i++) {
jint type = info[i].isSampler ? (jint) info[i].samplerType + offset : (jint) info[i].type;
jint type;
if (info[i].isSampler) {
type = (jint) info[i].samplerType + offset;
} else if (info[i].isSubpass) {
type = subpassOffset;
} else {
type = (jint) info[i].type;
}
env->CallStaticVoidMethod(
gMaterial.parameterClass, gMaterial.parameterAdd,
parameterClass, parameterAdd,
parameters, env->NewStringUTF(info[i].name), type, (jint) info[i].precision,
(jint) info[i].count);
}
env->DeleteLocalRef(parameterClass);
delete[] info;
}
@@ -204,14 +247,3 @@ Java_com_google_android_filament_Material_nHasParameter(JNIEnv* env, jclass,
env->ReleaseStringUTFChars(name_, name);
return (jboolean) hasParameter;
}
void registerMaterial(JNIEnv *env) {
gMaterial.parameterClass = env->FindClass("com/google/android/filament/Material$Parameter");
gMaterial.parameterClass = (jclass) env->NewGlobalRef(gMaterial.parameterClass);
gMaterial.parameterAdd = env->GetStaticMethodID(gMaterial.parameterClass, "add",
"(Ljava/util/List;Ljava/lang/String;III)V");
gMaterial.parameterSamplerOffset = env->GetStaticFieldID(gMaterial.parameterClass,
"SAMPLER_OFFSET", "I");
}
@@ -316,3 +316,139 @@ Java_com_google_android_filament_MaterialInstance_nSetDoubleSided(JNIEnv*,
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
instance->setDoubleSided(doubleSided);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetCullingMode(JNIEnv*,
jclass, jlong nativeMaterialInstance, jlong cullingMode) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
instance->setCullingMode((MaterialInstance::CullingMode) cullingMode);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetColorWrite(JNIEnv*,
jclass, jlong nativeMaterialInstance, jboolean enable) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
instance->setColorWrite(enable);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetDepthWrite(JNIEnv*,
jclass, jlong nativeMaterialInstance, jboolean enable) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
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*,
jclass, jlong nativeMaterialInstance, jboolean enable) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
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,
jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
return env->NewStringUTF(instance->getName());
}
extern "C"
JNIEXPORT jlong JNICALL
Java_com_google_android_filament_MaterialInstance_nGetMaterial(JNIEnv* env, jclass,
jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
return (jlong) instance->getMaterial();
}
extern "C"
JNIEXPORT jlong JNICALL
Java_com_google_android_filament_MaterialInstance_nDuplicate(JNIEnv* env, jclass clazz,
jlong otherNativeMaterialInstance, jstring name) {
MaterialInstance* other = (MaterialInstance*) otherNativeMaterialInstance;
const char *cstr = nullptr;
if (name != nullptr) {
cstr = env->GetStringUTFChars(name, nullptr);
}
MaterialInstance* mi = MaterialInstance::duplicate(other, cstr);
if (name != nullptr) {
env->ReleaseStringUTFChars(name, cstr);
}
return (jlong)mi;
}
@@ -0,0 +1,114 @@
/*
* Copyright (C) 2021 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.
*/
#include <jni.h>
#include <functional>
#include <stdlib.h>
#include <string.h>
#include <filament/MorphTargetBuffer.h>
#include "common/CallbackUtils.h"
#include "common/NioUtils.h"
using namespace filament;
using namespace backend;
extern "C"
JNIEXPORT jlong JNICALL
Java_com_google_android_filament_MorphTargetBuffer_nCreateBuilder(JNIEnv*, jclass) {
return (jlong) new MorphTargetBuffer::Builder();
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MorphTargetBuffer_nDestroyBuilder(JNIEnv*, jclass,
jlong nativeBuilder) {
MorphTargetBuffer::Builder* builder = (MorphTargetBuffer::Builder *) nativeBuilder;
delete builder;
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MorphTargetBuffer_nBuilderVertexCount(JNIEnv*, jclass,
jlong nativeBuilder, jint vertexCount) {
MorphTargetBuffer::Builder* builder = (MorphTargetBuffer::Builder *) nativeBuilder;
builder->vertexCount((size_t) vertexCount);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MorphTargetBuffer_nBuilderCount(JNIEnv*, jclass,
jlong nativeBuilder, jint count) {
MorphTargetBuffer::Builder* builder = (MorphTargetBuffer::Builder *) nativeBuilder;
builder->count((size_t) count);
}
extern "C"
JNIEXPORT jlong JNICALL
Java_com_google_android_filament_MorphTargetBuffer_nBuilderBuild(JNIEnv*, jclass,
jlong nativeBuilder, jlong nativeEngine) {
MorphTargetBuffer::Builder* builder = (MorphTargetBuffer::Builder *) nativeBuilder;
Engine *engine = (Engine *) nativeEngine;
return (jlong) builder->build(*engine);
}
// ------------------------------------------------------------------------------------------------
extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_MorphTargetBuffer_nSetPositionsAt(JNIEnv* env, jclass,
jlong nativeObject, jlong nativeEngine,
jint targetIndex, jfloatArray positions, jint count) {
MorphTargetBuffer *morphTargetBuffer = (MorphTargetBuffer *) nativeObject;
Engine *engine = (Engine *) nativeEngine;
jfloat* data = env->GetFloatArrayElements(positions, NULL);
morphTargetBuffer->setPositionsAt(*engine, targetIndex,
(math::float4*) data, size_t(count));
env->ReleaseFloatArrayElements(positions, data, JNI_ABORT);
return 0;
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_MorphTargetBuffer_nSetTangentsAt(JNIEnv* env, jclass,
jlong nativeObject, jlong nativeEngine,
jint targetIndex, jshortArray tangents, jint count) {
MorphTargetBuffer *morphTargetBuffer = (MorphTargetBuffer *) nativeObject;
Engine *engine = (Engine *) nativeEngine;
jshort* data = env->GetShortArrayElements(tangents, NULL);
morphTargetBuffer->setTangentsAt(*engine, targetIndex,
(math::short4*) data, size_t(count));
env->ReleaseShortArrayElements(tangents, data, JNI_ABORT);
return 0;
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_MorphTargetBuffer_nGetVertexCount(JNIEnv*, jclass,
jlong nativeObject) {
MorphTargetBuffer *morphTargetBuffer = (MorphTargetBuffer *) nativeObject;
return (jint)morphTargetBuffer->getVertexCount();
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_MorphTargetBuffer_nGetCount(JNIEnv*, jclass,
jlong nativeObject) {
MorphTargetBuffer *morphTargetBuffer = (MorphTargetBuffer *) nativeObject;
return (jint)morphTargetBuffer->getCount();
}
@@ -39,7 +39,7 @@ Java_com_google_android_filament_RenderTarget_nDestroyBuilder(JNIEnv *env, jclas
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderTarget_nBuilderTexture(JNIEnv *env, jclass type,
jlong nativeBuilder, jlong attachment, jlong nativeTexture) {
jlong nativeBuilder, jint attachment, jlong nativeTexture) {
RenderTarget::Builder* builder = (RenderTarget::Builder*) nativeBuilder;
Texture* texture = (Texture*) nativeTexture;
builder->texture(RenderTarget::AttachmentPoint(attachment), texture);
@@ -47,14 +47,14 @@ Java_com_google_android_filament_RenderTarget_nBuilderTexture(JNIEnv *env, jclas
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderTarget_nBuilderMipLevel(JNIEnv *env, jclass type,
jlong nativeBuilder, jlong attachment, jint level) {
jlong nativeBuilder, jint attachment, jint level) {
RenderTarget::Builder* builder = (RenderTarget::Builder*) nativeBuilder;
builder->mipLevel(RenderTarget::AttachmentPoint(attachment), level);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderTarget_nBuilderFace(JNIEnv *env, jclass type,
jlong nativeBuilder, jlong attachment, jint face) {
jlong nativeBuilder, jint attachment, jint face) {
RenderTarget::Builder* builder = (RenderTarget::Builder*) nativeBuilder;
RenderTarget::CubemapFace cubeface = (RenderTarget::CubemapFace) face;
builder->face(RenderTarget::AttachmentPoint(attachment), cubeface);
@@ -62,7 +62,7 @@ Java_com_google_android_filament_RenderTarget_nBuilderFace(JNIEnv *env, jclass t
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderTarget_nBuilderLayer(JNIEnv *env, jclass type,
jlong nativeBuilder, jlong attachment, jint layer) {
jlong nativeBuilder, jint attachment, jint layer) {
RenderTarget::Builder* builder = (RenderTarget::Builder*) nativeBuilder;
builder->layer(RenderTarget::AttachmentPoint(attachment), layer);
}
@@ -77,7 +77,21 @@ Java_com_google_android_filament_RenderTarget_nBuilderBuild(JNIEnv *env, jclass
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_RenderTarget_nGetMipLevel(JNIEnv *env, jclass type,
jlong nativeTarget, jlong attachment) {
jlong nativeTarget, jint attachment) {
RenderTarget* target = (RenderTarget*) nativeTarget;
return (jint) target->getMipLevel(RenderTarget::AttachmentPoint(attachment));
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_RenderTarget_nGetFace(JNIEnv *env, jclass type,
long nativeTarget, int attachment) {
RenderTarget* target = (RenderTarget*) nativeTarget;
return (jint) target->getFace(RenderTarget::AttachmentPoint(attachment));
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_RenderTarget_nGetLayer(JNIEnv *env, jclass type,
long nativeTarget, int attachment) {
RenderTarget* target = (RenderTarget*) nativeTarget;
return (jint) target->getLayer(RenderTarget::AttachmentPoint(attachment));
}
@@ -14,10 +14,13 @@
* limitations under the License.
*/
#include <jni.h>
#include <filament/RenderableManager.h>
#include <filament/MaterialInstance.h>
#include <utils/Entity.h>
#include "common/NioUtils.h"
using namespace filament;
@@ -117,6 +120,14 @@ Java_com_google_android_filament_RenderableManager_nBuilderBlendOrder(JNIEnv*, j
builder->blendOrder((size_t) index, (uint16_t) blendOrder);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderGlobalBlendOrderEnabled(JNIEnv*, jclass,
jlong nativeBuilder, jint index, jboolean enabled) {
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
builder->globalBlendOrderEnabled((size_t) index, (bool) enabled);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderBoundingBox(JNIEnv*, jclass,
jlong nativeBuilder, jfloat cx, jfloat cy, jfloat cz, jfloat ex, jfloat ey, jfloat ez) {
@@ -160,6 +171,21 @@ Java_com_google_android_filament_RenderableManager_nBuilderReceiveShadows(JNIEnv
builder->receiveShadows(enabled);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderScreenSpaceContactShadows(JNIEnv*, jclass,
jlong nativeBuilder, jboolean enabled) {
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
builder->screenSpaceContactShadows(enabled);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderSkinningBuffer(JNIEnv*, jclass,
jlong nativeBuilder, jlong nativeSkinningBuffer, jint boneCount, jint offset) {
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
SkinningBuffer *skinningBuffer = (SkinningBuffer *) nativeSkinningBuffer;
builder->skinning(skinningBuffer, boneCount, offset);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderSkinning(JNIEnv*, jclass,
jlong nativeBuilder, jint boneCount) {
@@ -167,6 +193,13 @@ Java_com_google_android_filament_RenderableManager_nBuilderSkinning(JNIEnv*, jcl
builder->skinning((size_t)boneCount);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nEnableSkinningBuffers(JNIEnv*, jclass,
jlong nativeBuilder, jboolean enabled) {
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
builder->enableSkinningBuffers(enabled);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderSkinningBones(JNIEnv* env, jclass,
jlong nativeBuilder, jint boneCount, jobject bones, jint remaining) {
@@ -182,7 +215,45 @@ Java_com_google_android_filament_RenderableManager_nBuilderSkinningBones(JNIEnv*
return 0;
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderMorphing(JNIEnv*, jclass,
jlong nativeBuilder, jint targetCount) {
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
builder->morphing(targetCount);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderSetMorphTargetBufferAt(JNIEnv*, jclass,
jlong nativeBuilder, int level, int primitiveIndex, jlong nativeMorphTargetBuffer,
int offset, int count) {
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
MorphTargetBuffer *morphTargetBuffer = (MorphTargetBuffer *) nativeMorphTargetBuffer;
builder->morphing(level, primitiveIndex, morphTargetBuffer, offset, count);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderLightChannel(JNIEnv*, jclass,
jlong nativeBuilder, jint channel, jboolean enable) {
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
builder->lightChannel(channel, (bool)enable);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nBuilderInstances(JNIEnv*, jclass,
jlong nativeBuilder, jint instanceCount) {
RenderableManager::Builder *builder = (RenderableManager::Builder *) nativeBuilder;
builder->instances(instanceCount);
}
// ------------------------------------------------------------------------------------------------
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetSkinningBuffer(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jlong nativeSkinningBuffer, jint count, jint offset) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
SkinningBuffer *sb = (SkinningBuffer *) nativeSkinningBuffer;
rm->setSkinningBuffer(i, sb, count, offset);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_RenderableManager_nSetBonesAsMatrices(JNIEnv* env, jclass,
@@ -218,6 +289,33 @@ Java_com_google_android_filament_RenderableManager_nSetBonesAsQuaternions(JNIEnv
return 0;
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetMorphWeights(JNIEnv* env, jclass,
jlong nativeRenderableManager, jint instance, jfloatArray weights, jint offset) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
jfloat* vec = env->GetFloatArrayElements(weights, NULL);
jsize count = env->GetArrayLength(weights);
rm->setMorphWeights((RenderableManager::Instance)instance, vec, count, offset);
env->ReleaseFloatArrayElements(weights, vec, JNI_ABORT);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetMorphTargetBufferAt(JNIEnv*,
jclass, jlong nativeRenderableManager, jint i, int level, jint primitiveIndex,
jlong nativeMorphTargetBuffer, jint offset, jint count) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
MorphTargetBuffer *morphTargetBuffer = (MorphTargetBuffer *) nativeMorphTargetBuffer;
rm->setMorphTargetBufferAt((RenderableManager::Instance) i, (uint8_t) level,
(size_t) primitiveIndex, morphTargetBuffer, (size_t) offset, (size_t) count);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_RenderableManager_nGetMorphTargetCount(JNIEnv* env, jclass,
jlong nativeRenderableManager, jint instance) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
return rm->getMorphTargetCount((RenderableManager::Instance)instance);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetAxisAlignedBoundingBox(JNIEnv*,
jclass, jlong nativeRenderableManager, jint i, jfloat cx, jfloat cy, jfloat cz,
@@ -241,6 +339,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_nSetCulling(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jboolean enabled) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
rm->setCulling((RenderableManager::Instance) i, enabled);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetCastShadows(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jboolean enabled) {
@@ -255,6 +360,13 @@ Java_com_google_android_filament_RenderableManager_nSetReceiveShadows(JNIEnv*, j
rm->setReceiveShadows((RenderableManager::Instance) i, enabled);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetScreenSpaceContactShadows(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jboolean enabled) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
rm->setScreenSpaceContactShadows((RenderableManager::Instance) i, enabled);
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_RenderableManager_nIsShadowCaster(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i) {
@@ -299,21 +411,13 @@ Java_com_google_android_filament_RenderableManager_nSetMaterialInstanceAt(JNIEnv
materialInstance);
}
extern "C" JNIEXPORT long JNICALL
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_RenderableManager_nGetMaterialInstanceAt(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jint primitiveIndex) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
return (long) rm->getMaterialInstanceAt((RenderableManager::Instance) i, (size_t) primitiveIndex);
}
extern "C" JNIEXPORT long JNICALL
Java_com_google_android_filament_RenderableManager_nGetMaterialAt(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jint primitiveIndex) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
MaterialInstance *mi = rm->getMaterialInstanceAt((RenderableManager::Instance) i, (size_t) primitiveIndex);
return (long) mi->getMaterial();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetGeometryAt__JIIIJJII(JNIEnv*,
jclass, jlong nativeRenderableManager, jint i, jint primitiveIndex, jint primitiveType,
@@ -326,15 +430,6 @@ Java_com_google_android_filament_RenderableManager_nSetGeometryAt__JIIIJJII(JNIE
(size_t) offset, (size_t) count);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetGeometryAt__JIIIII(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jint primitiveIndex, jint primitiveType, jint offset,
jint count) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
rm->setGeometryAt((RenderableManager::Instance) i, (size_t) primitiveIndex,
(RenderableManager::PrimitiveType) primitiveType, (size_t) offset, (size_t) count);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetBlendOrderAt(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jint primitiveIndex, jint blendOrder) {
@@ -343,6 +438,14 @@ Java_com_google_android_filament_RenderableManager_nSetBlendOrderAt(JNIEnv*, jcl
(uint16_t) blendOrder);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetGlobalBlendOrderEnabledAt(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jint primitiveIndex, jboolean enabled) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
rm->setGlobalBlendOrderEnabledAt((RenderableManager::Instance) i, (size_t) primitiveIndex,
(bool) enabled);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_RenderableManager_nGetEnabledAttributesAt(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jint primitiveIndex) {
@@ -350,3 +453,17 @@ Java_com_google_android_filament_RenderableManager_nGetEnabledAttributesAt(JNIEn
AttributeBitset enabled = rm->getEnabledAttributesAt((RenderableManager::Instance) i, (size_t) primitiveIndex);
return enabled.getValue();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_RenderableManager_nSetLightChannel(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jint channel, jboolean enable) {
RenderableManager *rm = (RenderableManager *) nativeRenderableManager;
rm->setLightChannel((RenderableManager::Instance) i, channel, (bool)enable);
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_RenderableManager_nGetLightChannel(JNIEnv*, jclass,
jlong nativeRenderableManager, jint i, jint channel) {
RenderableManager const *rm = (RenderableManager const *) nativeRenderableManager;
return rm->getLightChannel((RenderableManager::Instance) i, channel);
}
@@ -30,10 +30,10 @@ using namespace backend;
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Renderer_nBeginFrame(JNIEnv *, jclass, jlong nativeRenderer,
jlong nativeSwapChain) {
jlong nativeSwapChain, jlong frameTimeNanos) {
Renderer *renderer = (Renderer *) nativeRenderer;
SwapChain *swapChain = (SwapChain *) nativeSwapChain;
return (jboolean) renderer->beginFrame(swapChain);
return (jboolean) renderer->beginFrame(swapChain, uint64_t(frameTimeNanos));
}
extern "C" JNIEXPORT void JNICALL
@@ -50,6 +50,14 @@ Java_com_google_android_filament_Renderer_nRender(JNIEnv *, jclass, jlong native
renderer->render(view);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Renderer_nRenderStandaloneView(JNIEnv *, jclass, jlong nativeRenderer,
jlong nativeView) {
Renderer *renderer = (Renderer *) nativeRenderer;
View *view = (View *) nativeView;
renderer->renderStandaloneView(view);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Renderer_nCopyFrame(JNIEnv *, jclass, jlong nativeRenderer,
jlong nativeDstSwapChain,
@@ -89,7 +97,8 @@ Java_com_google_android_filament_Renderer_nReadPixels(JNIEnv *env, jclass,
PixelBufferDescriptor desc(buffer, sizeInBytes, (backend::PixelDataFormat) format,
(backend::PixelDataType) type, (uint8_t) alignment, (uint32_t) left, (uint32_t) top,
(uint32_t) stride, &JniBufferCallback::invoke, callback);
(uint32_t) stride,
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
renderer->readPixels(uint32_t(xoffset), uint32_t(yoffset), uint32_t(width), uint32_t(height),
std::move(desc));
@@ -97,6 +106,43 @@ Java_com_google_android_filament_Renderer_nReadPixels(JNIEnv *env, jclass,
return 0;
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Renderer_nReadPixelsEx(JNIEnv *env, jclass,
jlong nativeRenderer, jlong nativeEngine, jlong nativeRenderTarget,
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) {
Renderer *renderer = (Renderer *) nativeRenderer;
Engine *engine = (Engine *) nativeEngine;
RenderTarget *renderTarget = (RenderTarget *) nativeRenderTarget;
stride = stride ? stride : width;
size_t sizeInBytes = PixelBufferDescriptor::computeDataSize(
(PixelDataFormat) format, (PixelDataType) type,
(size_t) stride, (size_t) (height + top), (size_t) alignment);
AutoBuffer nioBuffer(env, storage, 0);
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
// BufferOverflowException
return -1;
}
void *buffer = nioBuffer.getData();
auto *callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
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);
renderer->readPixels(renderTarget,
uint32_t(xoffset), uint32_t(yoffset), uint32_t(width), uint32_t(height),
std::move(desc));
return 0;
}
extern "C" JNIEXPORT jdouble JNICALL
Java_com_google_android_filament_Renderer_nGetUserTime(JNIEnv*, jclass, jlong nativeRenderer) {
Renderer *renderer = (Renderer *) nativeRenderer;
@@ -108,3 +154,36 @@ Java_com_google_android_filament_Renderer_nResetUserTime(JNIEnv*, jclass, jlong
Renderer *renderer = (Renderer *) nativeRenderer;
renderer->resetUserTime();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Renderer_nSetDisplayInfo(JNIEnv*, jclass, jlong nativeRenderer, jfloat refreshRate) {
Renderer *renderer = (Renderer *) nativeRenderer;
renderer->setDisplayInfo({ .refreshRate = refreshRate });
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Renderer_nSetFrameRateOptions(JNIEnv*, jclass,
jlong nativeRenderer, jfloat interval, jfloat headRoomRatio, jfloat scaleRate, jint history) {
Renderer *renderer = (Renderer *) nativeRenderer;
renderer->setFrameRateOptions({ .headRoomRatio = headRoomRatio,
.scaleRate = scaleRate,
.history = (uint8_t)history,
.interval = (uint8_t)interval });
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Renderer_nSetClearOptions(JNIEnv *, jclass ,
jlong nativeRenderer, jfloat r, jfloat g, jfloat b, jfloat a,
jboolean clear, jboolean discard) {
Renderer *renderer = (Renderer *) nativeRenderer;
renderer->setClearOptions({ .clearColor = {r, g, b, a},
.clear = (bool) clear,
.discard = (bool) discard});
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Renderer_nSetPresentationTime(JNIEnv *, jclass ,
jlong nativeRenderer, jlong monotonicClockNanos) {
Renderer *renderer = (Renderer *) nativeRenderer;
renderer->setPresentationTime(monotonicClockNanos);
}
@@ -18,6 +18,8 @@
#include <filament/Scene.h>
#include <utils/Entity.h>
using namespace filament;
using namespace utils;
@@ -60,6 +62,15 @@ Java_com_google_android_filament_Scene_nRemove(JNIEnv *env, jclass type, jlong n
scene->remove((Entity&) entity);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Scene_nRemoveEntities(JNIEnv *env, jclass type, jlong nativeScene,
jintArray entities) {
Scene* scene = (Scene*) nativeScene;
Entity* nativeEntities = (Entity*) env->GetIntArrayElements(entities, nullptr);
scene->removeEntities(nativeEntities, env->GetArrayLength(entities));
env->ReleaseIntArrayElements(entities, (jint*) nativeEntities, JNI_ABORT);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Scene_nGetRenderableCount(JNIEnv *env, jclass type,
jlong nativeScene) {
@@ -0,0 +1,116 @@
/*
* Copyright (C) 2021 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.
*/
#include <jni.h>
#include <functional>
#include <stdlib.h>
#include <string.h>
#include <filament/SkinningBuffer.h>
#include "common/CallbackUtils.h"
#include "common/NioUtils.h"
using namespace filament;
using namespace backend;
extern "C"
JNIEXPORT jlong JNICALL
Java_com_google_android_filament_SkinningBuffer_nCreateBuilder(JNIEnv*, jclass) {
return (jlong) new SkinningBuffer::Builder();
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_SkinningBuffer_nDestroyBuilder(JNIEnv*, jclass,
jlong nativeBuilder) {
SkinningBuffer::Builder* builder = (SkinningBuffer::Builder *) nativeBuilder;
delete builder;
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_SkinningBuffer_nBuilderBoneCount(JNIEnv*, jclass,
jlong nativeBuilder, jint boneCount) {
SkinningBuffer::Builder* builder = (SkinningBuffer::Builder *) nativeBuilder;
builder->boneCount((uint32_t)boneCount);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_SkinningBuffer_nBuilderInitialize(JNIEnv*, jclass,
jlong nativeBuilder, jboolean initialize) {
SkinningBuffer::Builder* builder = (SkinningBuffer::Builder *) nativeBuilder;
builder->initialize((bool)initialize);
}
extern "C"
JNIEXPORT jlong JNICALL
Java_com_google_android_filament_SkinningBuffer_nBuilderBuild(JNIEnv*, jclass,
jlong nativeBuilder, jlong nativeEngine) {
SkinningBuffer::Builder* builder = (SkinningBuffer::Builder *) nativeBuilder;
Engine *engine = (Engine *) nativeEngine;
return (jlong) builder->build(*engine);
}
// ------------------------------------------------------------------------------------------------
extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_SkinningBuffer_nSetBonesAsMatrices(JNIEnv* env, jclass,
jlong nativeSkinningBuffer, jlong nativeEngine, jobject matrices, jint remaining, jint boneCount,
jint offset) {
SkinningBuffer *skinningBuffer = (SkinningBuffer *) nativeSkinningBuffer;
Engine *engine = (Engine *) nativeEngine;
AutoBuffer nioBuffer(env, matrices, boneCount * 16);
void* data = nioBuffer.getData();
size_t sizeInBytes = nioBuffer.getSize();
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
// BufferOverflowException
return -1;
}
skinningBuffer->setBones(*engine,
static_cast<filament::math::mat4f const *>(data), (size_t)boneCount, (size_t)offset);
return 0;
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_SkinningBuffer_nSetBonesAsQuaternions(JNIEnv* env, jclass,
jlong nativeSkinningBuffer, jlong nativeEngine, jobject quaternions, jint remaining,
jint boneCount, jint offset) {
SkinningBuffer *skinningBuffer = (SkinningBuffer *) nativeSkinningBuffer;
Engine *engine = (Engine *) nativeEngine;
AutoBuffer nioBuffer(env, quaternions, boneCount * 8);
void* data = nioBuffer.getData();
size_t sizeInBytes = nioBuffer.getSize();
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
// BufferOverflowException
return -1;
}
skinningBuffer->setBones(*engine,
static_cast<RenderableManager::Bone const *>(data), (size_t)boneCount, (size_t)offset);
return 0;
}
extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_SkinningBuffer_nGetBoneCount(JNIEnv*, jclass,
jlong nativeSkinningBuffer) {
SkinningBuffer *skinningBuffer = (SkinningBuffer *) nativeSkinningBuffer;
return (jint)skinningBuffer->getBoneCount();
}
@@ -18,6 +18,8 @@
#include <filament/Skybox.h>
#include <math/vec4.h>
using namespace filament;
extern "C" JNIEXPORT jlong JNICALL
@@ -47,6 +49,20 @@ Java_com_google_android_filament_Skybox_nBuilderShowSun(JNIEnv *env, jclass type
builder->showSun(show);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Skybox_nBuilderIntensity(JNIEnv *env, jclass clazz,
jlong nativeSkyBoxBuilder, jfloat intensity) {
Skybox::Builder *builder = (Skybox::Builder *) nativeSkyBoxBuilder;
builder->intensity(intensity);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Skybox_nBuilderColor(JNIEnv *, jclass,
jlong nativeSkyBoxBuilder, jfloat r, jfloat g, jfloat b, jfloat a) {
Skybox::Builder *builder = (Skybox::Builder *) nativeSkyBoxBuilder;
builder->color({r, g, b, a});
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Skybox_nBuilderBuild(JNIEnv *env, jclass type,
jlong nativeSkyBoxBuilder, jlong nativeEngine) {
@@ -68,3 +84,25 @@ Java_com_google_android_filament_Skybox_nGetLayerMask(JNIEnv *env, jclass type,
Skybox *skybox = (Skybox *) nativeSkybox;
return static_cast<jint>(skybox->getLayerMask());
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_Skybox_nGetIntensity(JNIEnv *env, jclass clazz,
jlong nativeSkybox) {
Skybox *skybox = (Skybox *) nativeSkybox;
return static_cast<jint>(skybox->getIntensity());
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Skybox_nSetColor(JNIEnv *, jclass,
jlong nativeSkybox, jfloat r, jfloat g, jfloat b, jfloat a) {
Skybox *skybox = (Skybox *) nativeSkybox;
skybox->setColor({r, g, b, a});
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Skybox_nGetTexture(JNIEnv* env, jclass,
jlong nativeSkybox) {
Skybox *skybox = (Skybox *) nativeSkybox;
Texture const *tex = skybox->getTexture();
return (jlong) tex;
}
@@ -24,6 +24,25 @@
#include "common/NioUtils.h"
#include "common/CallbackUtils.h"
#ifdef __ANDROID__
#if __has_include(<android/hardware_buffer_jni.h>)
#include <android/hardware_buffer_jni.h>
#else
struct AHardwareBuffer;
typedef struct AHardwareBuffer AHardwareBuffer;
#endif
#include <android/log.h>
#include <dlfcn.h>
using PFN_FROMHARDWAREBUFFER = AHardwareBuffer* (*)(JNIEnv*, jobject);
static PFN_FROMHARDWAREBUFFER AHardwareBuffer_fromHardwareBuffer_fn = nullptr;
static bool sHardwareBufferSupported = true;
#endif
using namespace filament;
using namespace backend;
@@ -79,13 +98,6 @@ Java_com_google_android_filament_Stream_nBuilderStreamSource(JNIEnv* env,
builder->setStreamSource(env, streamSource);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Stream_nBuilderStream(JNIEnv*, jclass,
jlong nativeStreamBuilder, jlong externalTextureId) {
StreamBuilder* builder = (StreamBuilder*) nativeStreamBuilder;
builder->builder()->stream(externalTextureId);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Stream_nBuilderWidth(JNIEnv*, jclass,
jlong nativeStreamBuilder, jint width) {
@@ -108,10 +120,10 @@ Java_com_google_android_filament_Stream_nBuilderBuild(JNIEnv*, jclass,
return (jlong) builder->builder()->build(*engine);
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Stream_nIsNative(JNIEnv*, jclass, jlong nativeStream) {
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Stream_nGetStreamType(JNIEnv*, jclass, jlong nativeStream) {
Stream* stream = (Stream*) nativeStream;
return (jboolean) stream->isNativeStream();
return (jint) stream->getStreamType();
}
extern "C" JNIEXPORT void JNICALL
@@ -121,42 +133,50 @@ Java_com_google_android_filament_Stream_nSetDimensions(JNIEnv*, jclass, jlong na
stream->setDimensions((uint32_t) width, (uint32_t) height);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Stream_nReadPixels(JNIEnv *env, jclass,
jlong nativeStream, jlong nativeEngine,
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) {
Stream *stream = (Stream *) nativeStream;
Engine *engine = (Engine *) nativeEngine;
stride = stride ? stride : width;
size_t sizeInBytes = PixelBufferDescriptor::computeDataSize(
(PixelDataFormat) format, (PixelDataType) type,
(size_t) stride, (size_t) (height + top), (size_t) alignment);
AutoBuffer nioBuffer(env, storage, 0);
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
// BufferOverflowException
return -1;
}
void *buffer = nioBuffer.getData();
auto *callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
PixelBufferDescriptor desc(buffer, sizeInBytes, (backend::PixelDataFormat) format,
(backend::PixelDataType) type, (uint8_t) alignment, (uint32_t) left, (uint32_t) top,
(uint32_t) stride, &JniBufferCallback::invoke, callback);
stream->readPixels(uint32_t(xoffset), uint32_t(yoffset), uint32_t(width), uint32_t(height),
std::move(desc));
return 0;
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Stream_nGetTimestamp(JNIEnv*, jclass, jlong nativeStream) {
Stream *stream = (Stream *) nativeStream;
return stream->getTimestamp();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Stream_nSetAcquiredImage(JNIEnv* env, jclass, jlong nativeStream,
jlong nativeEngine, jobject hwbuffer, jobject handler, jobject runnable) {
Engine* engine = (Engine*) nativeEngine;
Stream* stream = (Stream*) nativeStream;
#ifdef __ANDROID__
// This function is not available before NDK 15 or before Android 8.
if (UTILS_UNLIKELY(!AHardwareBuffer_fromHardwareBuffer_fn)) {
if (!sHardwareBufferSupported) {
return;
}
AHardwareBuffer_fromHardwareBuffer_fn = (PFN_FROMHARDWAREBUFFER) dlsym(RTLD_DEFAULT, "AHardwareBuffer_fromHardwareBuffer");
if (!AHardwareBuffer_fromHardwareBuffer_fn) {
__android_log_print(ANDROID_LOG_WARN, "Filament", "AHardwareBuffer_fromHardwareBuffer is not available.");
sHardwareBufferSupported = false;
return;
}
}
AHardwareBuffer* nativeBuffer = AHardwareBuffer_fromHardwareBuffer_fn(env, hwbuffer);
if (!nativeBuffer) {
__android_log_print(ANDROID_LOG_INFO, "Filament", "Unable to obtain native HardwareBuffer.");
return;
}
auto* callback = JniImageCallback::make(engine, env, handler, runnable, (long) nativeBuffer);
#else
// TODO: for non-Android platforms, it is unclear how to go from "jobject" to "void*"
// For now this code is reserved for future use.
auto* callback = JniImageCallback::make(engine, env, handler, runnable, 0);
void* nativeBuffer = nullptr;
#endif
stream->setAcquiredImage((void*) nativeBuffer,
callback->getHandler(), &JniImageCallback::postToJavaAndDestroy, callback);
}
@@ -0,0 +1,170 @@
/*
* Copyright (C) 2020 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.
*/
#include <jni.h>
#include <geometry/SurfaceOrientation.h>
#include "common/NioUtils.h"
#include <algorithm>
using namespace filament;
using namespace filament::geometry;
using namespace filament::math;
namespace {
struct JniWrapper {
SurfaceOrientation::Builder* builder;
AutoBuffer* normals;
AutoBuffer* tangents;
AutoBuffer* uvs;
AutoBuffer* positions;
AutoBuffer* triangles16;
AutoBuffer* triangles32;
};
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_SurfaceOrientation_nCreateBuilder(JNIEnv* env, jclass) {
JniWrapper* wrapper = new JniWrapper();
wrapper->builder = new SurfaceOrientation::Builder();
return (jlong) wrapper;
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nDestroyBuilder(JNIEnv* env, jclass,
jlong nativeBuilder) {
auto wrapper = (JniWrapper*) nativeBuilder;
delete wrapper->builder;
delete wrapper->normals;
delete wrapper->tangents;
delete wrapper->uvs;
delete wrapper->positions;
delete wrapper->triangles16;
delete wrapper->triangles32;
delete wrapper;
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nBuilderVertexCount(JNIEnv* env, jclass,
jlong nativeBuilder, int vertexCount) {
auto wrapper = (JniWrapper *) nativeBuilder;
wrapper->builder->vertexCount(vertexCount);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nBuilderTriangleCount(JNIEnv* env, jclass,
jlong nativeBuilder, int triangleCount) {
auto wrapper = (JniWrapper *) nativeBuilder;
wrapper->builder->triangleCount(triangleCount);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nBuilderNormals(JNIEnv* env, jclass,
jlong nativeBuilder, jobject javaBuffer, jint remaining, int stride) {
auto wrapper = (JniWrapper *) nativeBuilder;
AutoBuffer* buffer = wrapper->normals = new AutoBuffer(env, javaBuffer, remaining);
wrapper->builder->normals((const float3 *) buffer->getData(), stride);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nBuilderTangents(JNIEnv* env, jclass,
jlong nativeBuilder, jobject javaBuffer, jint remaining, int stride) {
auto wrapper = (JniWrapper *) nativeBuilder;
AutoBuffer* buffer = wrapper->tangents = new AutoBuffer(env, javaBuffer, remaining);
wrapper->builder->tangents((const float4 *) buffer->getData(), stride);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nBuilderUVs(JNIEnv* env, jclass,
jlong nativeBuilder, jobject javaBuffer, int remaining, int stride) {
auto wrapper = (JniWrapper *) nativeBuilder;
AutoBuffer* buffer = wrapper->uvs = new AutoBuffer(env, javaBuffer, remaining);
wrapper->builder->uvs((const float2 *) buffer->getData(), stride);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nBuilderPositions(JNIEnv* env, jclass,
jlong nativeBuilder, jobject javaBuffer, int remaining, int stride) {
auto wrapper = (JniWrapper *) nativeBuilder;
AutoBuffer* buffer = wrapper->positions = new AutoBuffer(env, javaBuffer, remaining);
wrapper->builder->positions((const float3 *) buffer->getData(), stride);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nBuilderTriangles16(JNIEnv* env, jclass,
jlong nativeBuilder, jobject javaBuffer, int remaining) {
auto wrapper = (JniWrapper *) nativeBuilder;
AutoBuffer* buffer = wrapper->triangles16 = new AutoBuffer(env, javaBuffer, remaining);
wrapper->builder->triangles((const ushort3 *) buffer->getData());
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nBuilderTriangles32(JNIEnv* env, jclass,
jlong nativeBuilder, jobject javaBuffer, int remaining) {
auto wrapper = (JniWrapper *) nativeBuilder;
AutoBuffer* buffer = wrapper->triangles32 = new AutoBuffer(env, javaBuffer, remaining);
wrapper->builder->triangles((const uint3 *) buffer->getData());
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_SurfaceOrientation_nBuilderBuild(JNIEnv* env, jclass,
jlong nativeBuilder) {
auto wrapper = (JniWrapper *) nativeBuilder;
return (jlong) wrapper->builder->build();
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_SurfaceOrientation_nGetVertexCount(JNIEnv* env, jclass,
jlong nativeObject) {
SurfaceOrientation* helper = (SurfaceOrientation*) nativeObject;
return helper->getVertexCount();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nGetQuatsAsFloat(JNIEnv* env, jclass,
jlong nativeObject, jobject javaBuffer, int remaining) {
SurfaceOrientation* helper = (SurfaceOrientation*) nativeObject;
AutoBuffer buffer(env, javaBuffer, remaining);
size_t requestedCount = std::min(buffer.getSize() / sizeof(float4), helper->getVertexCount());
helper->getQuats((quatf*) buffer.getData(), requestedCount);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nGetQuatsAsHalf(JNIEnv* env, jclass,
jlong nativeObject, jobject javaBuffer, int remaining) {
SurfaceOrientation* helper = (SurfaceOrientation*) nativeObject;
AutoBuffer buffer(env, javaBuffer, remaining);
size_t requestedCount = std::min(buffer.getSize() / sizeof(quath), helper->getVertexCount());
helper->getQuats((quath*) buffer.getData(), requestedCount);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nGetQuatsAsShort(JNIEnv* env, jclass,
jlong nativeObject, jobject javaBuffer, int remaining) {
SurfaceOrientation* helper = (SurfaceOrientation*) nativeObject;
AutoBuffer buffer(env, javaBuffer, remaining);
size_t requestedCount = std::min(buffer.getSize() / sizeof(short4), helper->getVertexCount());
helper->getQuats((short4*) buffer.getData(), requestedCount);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SurfaceOrientation_nDestroy(JNIEnv* env, jclass,
jlong nativeSurfaceOrientation) {
SurfaceOrientation* helper = (SurfaceOrientation*) nativeSurfaceOrientation;
delete helper;
}
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2020 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.
*/
#include <jni.h>
#include <filament/SwapChain.h>
#include "common/CallbackUtils.h"
using namespace filament;
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_SwapChain_nSetFrameCompletedCallback(JNIEnv* env, jclass,
jlong nativeSwapChain, jobject handler, jobject runnable) {
SwapChain* swapChain = (SwapChain*) nativeSwapChain;
auto *callback = JniCallback::make(env, handler, runnable);
swapChain->setFrameCompletedCallback([](void* user) {
JniCallback* callback = (JniCallback*)user;
JniCallback::postToJavaAndDestroy(callback);
}, callback);
}
+156 -68
View File
@@ -19,7 +19,7 @@
#include <algorithm>
#include <functional>
#ifdef ANDROID
#ifdef __ANDROID__
#include <android/bitmap.h>
#endif
@@ -31,15 +31,18 @@
#include "common/CallbackUtils.h"
#include "common/NioUtils.h"
#include "private/backend/VirtualMachineEnv.h"
using namespace filament;
using namespace backend;
static size_t getTextureDataSize(const Texture *texture, size_t level,
Texture::Format format, Texture::Type type, size_t stride, size_t alignment) {
static size_t getTextureDataSize(const Texture *texture,
size_t level, Texture::Format format, Texture::Type type,
size_t stride, size_t height, size_t alignment) {
// Zero stride implies tight row-to-row packing.
stride = stride == 0 ? texture->getWidth(level) : std::max(size_t(1), stride >> level);
return Texture::computeTextureDataSize(format, type,
stride, texture->getHeight(level), alignment);
stride = stride == 0 ? texture->getWidth(level) : std::max(size_t(1), stride >> level);
height = height == 0 ? texture->getHeight(level) : std::max(size_t(1), height >> level);
return Texture::computeTextureDataSize(format, type, stride, height, alignment);
}
extern "C" JNIEXPORT jboolean JNICALL
@@ -50,6 +53,13 @@ Java_com_google_android_filament_Texture_nIsTextureFormatSupported(JNIEnv*, jcla
(Texture::InternalFormat) internalFormat);
}
extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Texture_nIsTextureSwizzleSupported(JNIEnv*, jclass,
jlong nativeEngine) {
Engine *engine = (Engine *) nativeEngine;
return (jboolean) Texture::isTextureSwizzleSupported(*engine);
}
// Texture::Builder...
extern "C" JNIEXPORT jlong JNICALL
@@ -113,6 +123,21 @@ Java_com_google_android_filament_Texture_nBuilderUsage(JNIEnv*, jclass,
builder->usage((Texture::Usage) flags);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_Texture_nBuilderSwizzle(JNIEnv *, jclass ,
jlong nativeBuilder, jint r, jint g, jint b, jint a) {
Texture::Builder *builder = (Texture::Builder *) nativeBuilder;
builder->swizzle(
(Texture::Swizzle)r, (Texture::Swizzle)g, (Texture::Swizzle)b, (Texture::Swizzle)a);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_Texture_nBuilderImportTexture(JNIEnv*, jclass, jlong nativeBuilder, jlong id) {
Texture::Builder *builder = (Texture::Builder *) nativeBuilder;
builder->import((intptr_t)id);
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Texture_nBuilderBuild(JNIEnv*, jclass,
jlong nativeBuilder, jlong nativeEngine) {
@@ -164,20 +189,22 @@ Java_com_google_android_filament_Texture_nGetInternalFormat(JNIEnv*, jclass,
}
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,
Java_com_google_android_filament_Texture_nSetImage3D(JNIEnv* env, jclass, jlong nativeTexture,
jlong nativeEngine, jint level,
jint xoffset, jint yoffset, jint zoffset,
jint width, jint height, jint depth,
jobject storage, jint remaining,
jint left, jint bottom, jint type, jint alignment,
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) alignment);
(Texture::Type) type, (size_t) stride, (size_t) height, (size_t) alignment) * depth;
AutoBuffer nioBuffer(env, storage, 0);
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
if (sizeInBytes > (size_t(remaining) << nioBuffer.getShift())) {
// BufferOverflowException
return -1;
}
@@ -186,21 +213,25 @@ Java_com_google_android_filament_Texture_nSetImage(JNIEnv* env, jclass, jlong na
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) bottom,
(uint32_t) stride, &JniBufferCallback::invoke, callback);
(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));
texture->setImage(*engine, (size_t) level,
(uint32_t) xoffset, (uint32_t) yoffset, (uint32_t) zoffset,
(uint32_t) width, (uint32_t) height, (uint32_t) depth,
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 left, jint bottom, jint type, jint alignment,
jint compressedSizeInBytes, jint compressedFormat,
Java_com_google_android_filament_Texture_nSetImage3DCompressed(JNIEnv *env, jclass,
jlong nativeTexture, jlong nativeEngine, jint level,
jint xoffset, jint yoffset, jint zoffset,
jint width, jint height, jint depth,
jobject storage, jint remaining,
jint, jint, jint, jint, jint compressedSizeInBytes, jint compressedFormat,
jobject handler, jobject runnable) {
Texture *texture = (Texture *) nativeTexture;
Engine *engine = (Engine *) nativeEngine;
@@ -208,7 +239,7 @@ Java_com_google_android_filament_Texture_nSetImageCompressed(JNIEnv *env, jclass
size_t sizeInBytes = (size_t) compressedSizeInBytes;
AutoBuffer nioBuffer(env, storage, 0);
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
if (sizeInBytes > (size_t(remaining) << nioBuffer.getShift())) {
// BufferOverflowException
return -1;
}
@@ -218,10 +249,12 @@ Java_com_google_android_filament_Texture_nSetImageCompressed(JNIEnv *env, jclass
Texture::PixelBufferDescriptor desc(buffer, sizeInBytes,
(backend::CompressedPixelDataType) compressedFormat, (uint32_t) compressedSizeInBytes,
&JniBufferCallback::invoke, callback);
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));
texture->setImage(*engine, (size_t) level,
(uint32_t) xoffset, (uint32_t) yoffset, (uint32_t) zoffset,
(uint32_t) width, (uint32_t) height, (uint32_t) depth,
std::move(desc));
return 0;
}
@@ -229,22 +262,22 @@ Java_com_google_android_filament_Texture_nSetImageCompressed(JNIEnv *env, jclass
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Texture_nSetImageCubemap(JNIEnv *env, jclass,
jlong nativeTexture, jlong nativeEngine, jint level, jobject storage, jint remaining,
jint left, jint bottom, jint type, jint alignment, jint stride, jint format,
jint left, jint top, jint type, jint alignment, jint stride, jint format,
jintArray faceOffsetsInBytes_,
jobject handler, jobject runnable) {
Texture *texture = (Texture *) nativeTexture;
Engine *engine = (Engine *) nativeEngine;
jint *faceOffsetsInBytes = env->GetIntArrayElements(faceOffsetsInBytes_, NULL);
jint *faceOffsetsInBytes = env->GetIntArrayElements(faceOffsetsInBytes_, nullptr);
Texture::FaceOffsets faceOffsets;
std::copy_n(faceOffsetsInBytes, 6, faceOffsets.offsets);
env->ReleaseIntArrayElements(faceOffsetsInBytes_, faceOffsetsInBytes, JNI_ABORT);
size_t sizeInBytes = 6 * getTextureDataSize(texture, (size_t) level, (Texture::Format) format,
(Texture::Type) type, (size_t) stride, (size_t) alignment);
(Texture::Type) type, (size_t) stride, 0, (size_t) alignment);
AutoBuffer nioBuffer(env, storage, 0);
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
if (sizeInBytes > (size_t(remaining) << nioBuffer.getShift())) {
// BufferOverflowException
return -1;
}
@@ -253,10 +286,14 @@ Java_com_google_android_filament_Texture_nSetImageCubemap(JNIEnv *env, jclass,
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) bottom,
(uint32_t) stride, &JniBufferCallback::invoke, callback);
(backend::PixelDataType) type, (uint8_t) alignment, (uint32_t) left, (uint32_t) top,
(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;
}
@@ -264,14 +301,14 @@ Java_com_google_android_filament_Texture_nSetImageCubemap(JNIEnv *env, jclass,
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_Texture_nSetImageCubemapCompressed(JNIEnv *env, jclass,
jlong nativeTexture, jlong nativeEngine, jint level, jobject storage, jint remaining,
jint left, jint bottom, jint type, jint alignment,
jint left, jint top, jint type, jint alignment,
jint compressedSizeInBytes, jint compressedFormat, jintArray faceOffsetsInBytes_,
jobject handler, jobject runnable) {
Texture *texture = (Texture *) nativeTexture;
Engine *engine = (Engine *) nativeEngine;
jint *faceOffsetsInBytes = env->GetIntArrayElements(faceOffsetsInBytes_, NULL);
jint *faceOffsetsInBytes = env->GetIntArrayElements(faceOffsetsInBytes_, nullptr);
Texture::FaceOffsets faceOffsets;
std::copy_n(faceOffsetsInBytes, 6, faceOffsets.offsets);
env->ReleaseIntArrayElements(faceOffsetsInBytes_, faceOffsetsInBytes, JNI_ABORT);
@@ -279,7 +316,7 @@ Java_com_google_android_filament_Texture_nSetImageCubemapCompressed(JNIEnv *env,
size_t sizeInBytes = 6 * (size_t) compressedSizeInBytes;
AutoBuffer nioBuffer(env, storage, 0);
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
if (sizeInBytes > (size_t(remaining) << nioBuffer.getShift())) {
// BufferOverflowException
return -1;
}
@@ -289,9 +326,12 @@ Java_com_google_android_filament_Texture_nSetImageCubemapCompressed(JNIEnv *env,
Texture::PixelBufferDescriptor desc(buffer, sizeInBytes,
(backend::CompressedPixelDataType) compressedFormat, (uint32_t) compressedSizeInBytes,
&JniBufferCallback::invoke, callback);
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;
}
@@ -340,28 +380,29 @@ Java_com_google_android_filament_Texture_nGeneratePrefilterMipmap(JNIEnv *env, j
Texture *texture = (Texture *) nativeTexture;
Engine *engine = (Engine *) nativeEngine;
jint *faceOffsetsInBytes = env->GetIntArrayElements(faceOffsetsInBytes_, NULL);
jint *faceOffsetsInBytes = env->GetIntArrayElements(faceOffsetsInBytes_, nullptr);
Texture::FaceOffsets faceOffsets;
std::copy_n(faceOffsetsInBytes, 6, faceOffsets.offsets);
env->ReleaseIntArrayElements(faceOffsetsInBytes_, faceOffsetsInBytes, JNI_ABORT);
stride = stride ? stride : width;
size_t sizeInBytes = 6 *
Texture::computeTextureDataSize((Texture::Format) format, (Texture::Type) type,
(size_t) stride, (size_t) height, (size_t) alignment);
Texture::computeTextureDataSize((Texture::Format) format, (Texture::Type) type,
(size_t) stride, (size_t) height, (size_t) alignment);
AutoBuffer nioBuffer(env, storage, 0);
if (sizeInBytes > (remaining << nioBuffer.getShift())) {
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));
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)0, (uint32_t)0,
(uint32_t) stride, &JniBufferCallback::invoke, callback);
(backend::PixelDataType) type, (uint8_t) alignment,
(uint32_t) left, (uint32_t) top, (uint32_t) stride,
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
Texture::PrefilterOptions options;
options.sampleCount = sampleCount;
@@ -375,7 +416,7 @@ Java_com_google_android_filament_Texture_nGeneratePrefilterMipmap(JNIEnv *env, j
// ANDROID SPECIFIC BITS
////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef ANDROID
#ifdef __ANDROID__
#define BITMAP_CONFIG_ALPHA_8 0
#define BITMAP_CONFIG_RGB_565 1
@@ -384,32 +425,37 @@ Java_com_google_android_filament_Texture_nGeneratePrefilterMipmap(JNIEnv *env, j
#define BITMAP_CONFIG_RGBA_F16 4
#define BITMAP_CONFIG_HARDWARE 5
class AutoBitmap {
public:
class AutoBitmap : public JniCallback {
private:
AutoBitmap(JNIEnv* env, jobject bitmap) noexcept
: mEnv(env)
, mBitmap(env->NewGlobalRef(bitmap))
{
: JniCallback(),
mBitmap(env->NewGlobalRef(bitmap)) {
if (mBitmap) {
AndroidBitmap_getInfo(mEnv, mBitmap, &mInfo);
AndroidBitmap_lockPixels(mEnv, mBitmap, &mData);
AndroidBitmap_getInfo(env, mBitmap, &mInfo);
AndroidBitmap_lockPixels(env, mBitmap, &mData);
}
}
~AutoBitmap() noexcept {
AutoBitmap(JNIEnv* env, jobject bitmap, jobject handler, jobject runnable) noexcept
: JniCallback(env, handler, runnable),
mBitmap(env->NewGlobalRef(bitmap)) {
if (mBitmap) {
AndroidBitmap_unlockPixels(mEnv, mBitmap);
mEnv->DeleteGlobalRef(mBitmap);
AndroidBitmap_getInfo(env, mBitmap, &mInfo);
AndroidBitmap_lockPixels(env, mBitmap, &mData);
}
}
AutoBitmap(AutoBitmap &&rhs) noexcept {
mEnv = rhs.mEnv;
std::swap(mData, rhs.mData);
std::swap(mBitmap, rhs.mBitmap);
std::swap(mInfo, rhs.mInfo);
void release(JNIEnv* env) {
if (mBitmap) {
AndroidBitmap_unlockPixels(env, mBitmap);
env->DeleteGlobalRef(mBitmap);
}
}
~AutoBitmap() override = default;
public:
void* getData() const noexcept {
return mData;
}
@@ -430,26 +476,45 @@ public:
PixelDataType getType(int format) const noexcept {
switch (format) {
case BITMAP_CONFIG_RGB_565: return PixelDataType::USHORT_565;
case BITMAP_CONFIG_RGBA_F16: return PixelDataType::HALF;
default: return PixelDataType::UBYTE;
}
}
static void invoke(void* buffer, size_t n, void* user) {
AutoBitmap* data = reinterpret_cast<AutoBitmap*>(user);
data->~AutoBitmap();
// create a AutoBitmap
static AutoBitmap* make(JNIEnv* env, jobject bitmap, jobject handler, jobject runnable) {
return new AutoBitmap(env, bitmap, handler, runnable);
}
static AutoBitmap* make(Engine* engine, JNIEnv* env, jobject bitmap) {
void* that = engine->streamAlloc(sizeof(AutoBitmap), alignof(AutoBitmap));
return new (that) AutoBitmap(env, bitmap);
// execute the callback on the java thread and destroy ourselves
static void invoke(void*, size_t, void* user) {
auto* autoBitmap = reinterpret_cast<AutoBitmap*>(user);
JNIEnv* env = filament::VirtualMachineEnv::get().getEnvironment();
releaseCallbackJni(env, autoBitmap->mCallbackUtils, autoBitmap->mHandler, autoBitmap->mCallback);
autoBitmap->release(env);
delete autoBitmap;
}
// create a AutoBitmap without a handler
static AutoBitmap* make(JNIEnv* env, jobject bitmap) {
return new AutoBitmap(env, bitmap);
}
// just destroy ourselves
static void invokeNoCallback(void*, size_t, void* user) {
auto* autoBitmap = reinterpret_cast<AutoBitmap*>(user);
JNIEnv* env = filament::VirtualMachineEnv::get().getEnvironment();
autoBitmap->release(env);
delete autoBitmap;
}
private:
JNIEnv* mEnv;
void* mData = nullptr;
jobject mBitmap = nullptr;
AndroidBitmapInfo mInfo;
jobject mHandler = nullptr;
jobject mCallback = nullptr;
AndroidBitmapInfo mInfo{};
};
extern "C"
@@ -460,14 +525,37 @@ Java_com_google_android_filament_android_TextureHelper_nSetBitmap(JNIEnv* env, j
Texture* texture = (Texture*) nativeTexture;
Engine *engine = (Engine *) nativeEngine;
auto* autoBitmap = AutoBitmap::make(engine, env, bitmap);
auto* autoBitmap = AutoBitmap::make(env, bitmap);
Texture::PixelBufferDescriptor desc(
autoBitmap->getData(),
autoBitmap->getSizeInBytes(),
autoBitmap->getFormat(format),
autoBitmap->getType(format),
&AutoBitmap::invoke, autoBitmap);
&AutoBitmap::invokeNoCallback, autoBitmap);
texture->setImage(*engine, (size_t) level,
(uint32_t) xoffset, (uint32_t) yoffset,
(uint32_t) width, (uint32_t) height,
std::move(desc));
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_android_TextureHelper_nSetBitmapWithCallback(JNIEnv* env, jclass,
jlong nativeTexture, jlong nativeEngine, jint level, jint xoffset, jint yoffset,
jint width, jint height, jobject bitmap, jint format, jobject handler, jobject runnable) {
Texture* texture = (Texture*) nativeTexture;
Engine *engine = (Engine *) nativeEngine;
auto* autoBitmap = AutoBitmap::make(env, bitmap, handler, runnable);
Texture::PixelBufferDescriptor desc(
autoBitmap->getData(),
autoBitmap->getSizeInBytes(),
autoBitmap->getFormat(format),
autoBitmap->getType(format),
autoBitmap->getHandler(), &AutoBitmap::invoke, autoBitmap);
texture->setImage(*engine, (size_t) level,
(uint32_t) xoffset, (uint32_t) yoffset,
@@ -0,0 +1,98 @@
/*
* Copyright (C) 2021 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.
*/
#include <jni.h>
#include <filament/ToneMapper.h>
using namespace filament;
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ToneMapper_nDestroyToneMapper(JNIEnv *env, jclass clazz,
jlong toneMapper_) {
ToneMapper* toneMapper = (ToneMapper*) toneMapper_;
delete toneMapper;
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_ToneMapper_nCreateLinearToneMapper(JNIEnv*, jclass) {
return (jlong) new LinearToneMapper();
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_ToneMapper_nCreateACESToneMapper(JNIEnv*, jclass) {
return (jlong) new ACESToneMapper();
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_ToneMapper_nCreateACESLegacyToneMapper(JNIEnv*, jclass) {
return (jlong) new ACESLegacyToneMapper();
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_ToneMapper_nCreateFilmicToneMapper(JNIEnv*, jclass) {
return (jlong) new FilmicToneMapper();
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_ToneMapper_nCreateGenericToneMapper(JNIEnv*, jclass,
jfloat contrast, jfloat midGrayIn, jfloat midGrayOut, jfloat hdrMax) {
return (jlong) new GenericToneMapper(contrast, midGrayIn, midGrayOut, hdrMax);
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_ToneMapper_nGenericGetContrast(JNIEnv*, jclass, jlong nativeObject) {
return ((GenericToneMapper*) nativeObject)->getContrast();
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_ToneMapper_nGenericGetMidGrayIn(JNIEnv*, jclass, jlong nativeObject) {
return ((GenericToneMapper*) nativeObject)->getMidGrayIn();
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_ToneMapper_nGenericGetMidGrayOut(JNIEnv*, jclass, jlong nativeObject) {
return ((GenericToneMapper*) nativeObject)->getMidGrayOut();
}
extern "C" JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_ToneMapper_nGenericGetHdrMax(JNIEnv*, jclass, jlong nativeObject) {
return ((GenericToneMapper*) nativeObject)->getHdrMax();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ToneMapper_nGenericSetContrast(JNIEnv*, jclass,
jlong nativeObject, jfloat contrast) {
((GenericToneMapper*) nativeObject)->setContrast(contrast);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ToneMapper_nGenericSetMidGrayIn(JNIEnv*, jclass,
jlong nativeObject, jfloat midGrayIn) {
((GenericToneMapper*) nativeObject)->setMidGrayIn(midGrayIn);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ToneMapper_nGenericSetMidGrayOut(JNIEnv*, jclass,
jlong nativeObject, jfloat midGrayOut) {
((GenericToneMapper*) nativeObject)->setMidGrayOut(midGrayOut);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_ToneMapper_nGenericSetHdrMax(JNIEnv*, jclass,
jlong nativeObject, jfloat hdrMax) {
((GenericToneMapper*) nativeObject)->setHdrMax(hdrMax);
}
@@ -17,9 +17,12 @@
#include <jni.h>
#include <utils/Entity.h>
#include <filament/TransformManager.h>
#include <utils/Entity.h>
#include <math/mat4.h>
using namespace utils;
using namespace filament;
@@ -67,6 +70,23 @@ Java_com_google_android_filament_TransformManager_nCreateArray(JNIEnv* env,
return tm->getInstance(entity);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_TransformManager_nCreateArrayFp64(JNIEnv* env,
jclass, jlong nativeTransformManager, jint entity_, jint parent,
jdoubleArray localTransform_) {
TransformManager* tm = (TransformManager*) nativeTransformManager;
Entity& entity = *reinterpret_cast<Entity*>(&entity_);
if (localTransform_) {
jdouble *localTransform = env->GetDoubleArrayElements(localTransform_, NULL);
tm->create(entity, (TransformManager::Instance) parent,
*reinterpret_cast<const filament::math::mat4 *>(localTransform));
env->ReleaseDoubleArrayElements(localTransform_, localTransform, JNI_ABORT);
} else {
tm->create(entity, (TransformManager::Instance) parent);
}
return tm->getInstance(entity);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_TransformManager_nDestroy(JNIEnv*, jclass,
jlong nativeTransformManager, jint entity_) {
@@ -83,6 +103,13 @@ Java_com_google_android_filament_TransformManager_nSetParent(JNIEnv*, jclass,
(TransformManager::Instance) newParent);
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_TransformManager_nGetParent(JNIEnv*, jclass,
jlong nativeTransformManager, jint i) {
TransformManager* tm = (TransformManager*) nativeTransformManager;
return tm->getParent((TransformManager::Instance) i).getId();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_TransformManager_nSetTransform(JNIEnv* env,
jclass, jlong nativeTransformManager, jint i,
@@ -94,6 +121,17 @@ Java_com_google_android_filament_TransformManager_nSetTransform(JNIEnv* env,
env->ReleaseFloatArrayElements(localTransform_, localTransform, JNI_ABORT);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_TransformManager_nSetTransformFp64(JNIEnv* env,
jclass, jlong nativeTransformManager, jint i,
jdoubleArray localTransform_) {
TransformManager* tm = (TransformManager*) nativeTransformManager;
jdouble *localTransform = env->GetDoubleArrayElements(localTransform_, NULL);
tm->setTransform((TransformManager::Instance) i,
*reinterpret_cast<const filament::math::mat4 *>(localTransform));
env->ReleaseDoubleArrayElements(localTransform_, localTransform, JNI_ABORT);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_TransformManager_nGetTransform(JNIEnv* env,
jclass, jlong nativeTransformManager, jint i,
@@ -105,6 +143,17 @@ Java_com_google_android_filament_TransformManager_nGetTransform(JNIEnv* env,
env->ReleaseFloatArrayElements(outLocalTransform_, outLocalTransform, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_TransformManager_nGetTransformFp64(JNIEnv* env,
jclass, jlong nativeTransformManager, jint i,
jdoubleArray outLocalTransform_) {
TransformManager* tm = (TransformManager*) nativeTransformManager;
jdouble *outLocalTransform = env->GetDoubleArrayElements(outLocalTransform_, NULL);
*reinterpret_cast<filament::math::mat4 *>(outLocalTransform) = tm->getTransformAccurate(
(TransformManager::Instance) i);
env->ReleaseDoubleArrayElements(outLocalTransform_, outLocalTransform, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_TransformManager_nGetWorldTransform(JNIEnv* env,
jclass, jlong nativeTransformManager, jint i,
@@ -116,6 +165,17 @@ Java_com_google_android_filament_TransformManager_nGetWorldTransform(JNIEnv* env
env->ReleaseFloatArrayElements(outWorldTransform_, outWorldTransform, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_TransformManager_nGetWorldTransformFp64(JNIEnv* env,
jclass, jlong nativeTransformManager, jint i,
jdoubleArray outWorldTransform_) {
TransformManager* tm = (TransformManager*) nativeTransformManager;
jdouble *outWorldTransform = env->GetDoubleArrayElements(outWorldTransform_, NULL);
*reinterpret_cast<filament::math::mat4 *>(outWorldTransform) = tm->getWorldTransformAccurate(
(TransformManager::Instance) i);
env->ReleaseDoubleArrayElements(outWorldTransform_, outWorldTransform, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_TransformManager_nOpenLocalTransformTransaction(
JNIEnv*, jclass, jlong nativeTransformManager) {
@@ -129,3 +189,19 @@ Java_com_google_android_filament_TransformManager_nCommitLocalTransformTransacti
TransformManager* tm = (TransformManager*) nativeTransformManager;
tm->commitLocalTransformTransaction();
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_TransformManager_nSetAccurateTranslationsEnabled(JNIEnv*,
jclass, jlong nativeTransformManager, jboolean enable) {
TransformManager* tm = (TransformManager*) nativeTransformManager;
tm->setAccurateTranslationsEnabled((bool)enable);
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_TransformManager_nIsAccurateTranslationsEnabled(JNIEnv*,
jclass, jlong nativeTransformManager) {
TransformManager* tm = (TransformManager*) nativeTransformManager;
return (jboolean)tm->isAccurateTranslationsEnabled();
}
@@ -32,33 +32,40 @@ using namespace filament::math;
using namespace backend;
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_VertexBuffer_nCreateBuilder(JNIEnv *env, jclass type) {
Java_com_google_android_filament_VertexBuffer_nCreateBuilder(JNIEnv*, jclass) {
return (jlong) new VertexBuffer::Builder();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_VertexBuffer_nDestroyBuilder(JNIEnv *env, jclass type,
Java_com_google_android_filament_VertexBuffer_nDestroyBuilder(JNIEnv*, jclass,
jlong nativeBuilder) {
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
delete builder;
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_VertexBuffer_nBuilderVertexCount(JNIEnv *env, jclass type,
Java_com_google_android_filament_VertexBuffer_nBuilderVertexCount(JNIEnv*, jclass,
jlong nativeBuilder, jint vertexCount) {
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
builder->vertexCount((uint32_t) vertexCount);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_VertexBuffer_nBuilderBufferCount(JNIEnv *env, jclass type,
Java_com_google_android_filament_VertexBuffer_nBuilderEnableBufferObjects(JNIEnv*, jclass,
jlong nativeBuilder, jboolean enabled) {
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
builder->enableBufferObjects(enabled);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_VertexBuffer_nBuilderBufferCount(JNIEnv*, jclass,
jlong nativeBuilder, jint bufferCount) {
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
builder->bufferCount((uint8_t) bufferCount);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_VertexBuffer_nBuilderAttribute(JNIEnv *env, jclass type,
Java_com_google_android_filament_VertexBuffer_nBuilderAttribute(JNIEnv*, jclass,
jlong nativeBuilder, jint attribute, jint bufferIndex, jint attributeType, jint byteOffset,
jint byteStride) {
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
@@ -68,14 +75,14 @@ Java_com_google_android_filament_VertexBuffer_nBuilderAttribute(JNIEnv *env, jcl
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_VertexBuffer_nBuilderNormalized(JNIEnv *env, jclass type,
Java_com_google_android_filament_VertexBuffer_nBuilderNormalized(JNIEnv*, jclass,
jlong nativeBuilder, jint attribute, jboolean normalized) {
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
builder->normalized((VertexAttribute) attribute, normalized);
}
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_VertexBuffer_nBuilderBuild(JNIEnv *env, jclass type,
Java_com_google_android_filament_VertexBuffer_nBuilderBuild(JNIEnv*, jclass,
jlong nativeBuilder, jlong nativeEngine) {
VertexBuffer::Builder* builder = (VertexBuffer::Builder *) nativeBuilder;
Engine *engine = (Engine *) nativeEngine;
@@ -83,14 +90,14 @@ Java_com_google_android_filament_VertexBuffer_nBuilderBuild(JNIEnv *env, jclass
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_VertexBuffer_nGetVertexCount(JNIEnv *env, jclass type,
Java_com_google_android_filament_VertexBuffer_nGetVertexCount(JNIEnv*, jclass,
jlong nativeVertexBuffer) {
VertexBuffer *vertexBuffer = (VertexBuffer *) nativeVertexBuffer;
return (jint) vertexBuffer->getVertexCount();
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_VertexBuffer_nSetBufferAt(JNIEnv *env, jclass type,
Java_com_google_android_filament_VertexBuffer_nSetBufferAt(JNIEnv *env, jclass,
jlong nativeVertexBuffer, jlong nativeEngine, jint bufferIndex,
jobject buffer, jint remaining,
jint destOffsetInBytes, jint count, jobject handler, jobject runnable) {
@@ -107,7 +114,8 @@ Java_com_google_android_filament_VertexBuffer_nSetBufferAt(JNIEnv *env, jclass t
auto* callback = JniBufferCallback::make(engine, env, handler, runnable, std::move(nioBuffer));
BufferDescriptor desc(data, sizeInBytes, &JniBufferCallback::invoke, callback);
BufferDescriptor desc(data, sizeInBytes,
callback->getHandler(), &JniBufferCallback::postToJavaAndDestroy, callback);
vertexBuffer->setBufferAt(*engine, (uint8_t) bufferIndex, std::move(desc),
(uint32_t) destOffsetInBytes);
@@ -116,41 +124,10 @@ Java_com_google_android_filament_VertexBuffer_nSetBufferAt(JNIEnv *env, jclass t
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_VertexBuffer_nPopulateTangentQuaternions(JNIEnv *env,
jclass type, jint quatType, jint quatCount, jobject outBuffer, jint outRemaining,
jint outStride, jobject normals, jint normalsRemaining, jint normalsStride,
jobject tangents, jint tangentsRemaining, jint tangentsStride) {
AutoBuffer outNioBuffer(env, outBuffer, outRemaining, true);
void* outData = outNioBuffer.getData();
AutoBuffer normalsNioBuffer(env, normals, normalsRemaining);
auto normalsData = (const float3*) normalsNioBuffer.getData();
if (tangents) {
AutoBuffer tangentsNioBuffer(env, tangents, tangentsRemaining);
auto tangentsData = (const float4*) tangentsNioBuffer.getData();
VertexBuffer::populateTangentQuaternions({
.quatType = (VertexBuffer::QuatType) quatType,
.quatCount = (size_t) quatCount,
.outBuffer = outData,
.outStride = (size_t) outStride,
.normals = normalsData,
.normalsStride = (size_t) normalsStride,
.tangents = tangentsData,
.tangentsStride = (size_t) tangentsStride
});
return;
}
VertexBuffer::populateTangentQuaternions({
.quatType = (VertexBuffer::QuatType) quatType,
.quatCount = (size_t) quatCount,
.outBuffer = outData,
.outStride = (size_t) outStride,
.normals = normalsData,
.normalsStride = (size_t) normalsStride,
.tangents = nullptr,
.tangentsStride = 0
});
Java_com_google_android_filament_VertexBuffer_nSetBufferObjectAt(JNIEnv*, jclass,
jlong nativeVertexBuffer, jlong nativeEngine, jint bufferIndex, jlong nativeBufferObject) {
VertexBuffer *vertexBuffer = (VertexBuffer *) nativeVertexBuffer;
Engine *engine = (Engine *) nativeEngine;
BufferObject *bufferObject = (BufferObject *) nativeBufferObject;
vertexBuffer->setBufferObjectAt(*engine, (uint8_t) bufferIndex, bufferObject);
}
+320 -82
View File
@@ -16,13 +16,18 @@
#include <jni.h>
#include <filament/Color.h>
#include <filament/View.h>
#include <filament/Viewport.h>
#include "common/CallbackUtils.h"
#include "private/backend/VirtualMachineEnv.h"
using namespace filament;
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetName(JNIEnv* env, jclass,
jlong nativeView, jstring name_) {
Java_com_google_android_filament_View_nSetName(JNIEnv* env, jclass, jlong nativeView, jstring name_) {
View* view = (View*) nativeView;
const char* name = env->GetStringUTFChars(name_, 0);
view->setName(name);
@@ -30,8 +35,7 @@ Java_com_google_android_filament_View_nSetName(JNIEnv* env, jclass,
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetScene(JNIEnv*, jclass,
jlong nativeView, jlong nativeScene) {
Java_com_google_android_filament_View_nSetScene(JNIEnv*, jclass, jlong nativeView, jlong nativeScene) {
View* view = (View*) nativeView;
Scene* scene = (Scene*) nativeScene;
view->setScene(scene);
@@ -45,6 +49,14 @@ Java_com_google_android_filament_View_nSetCamera(JNIEnv*, jclass,
view->setCamera(camera);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetColorGrading(JNIEnv*, jclass,
jlong nativeView, jlong nativeColorGrading) {
View* view = (View*) nativeView;
ColorGrading* colorGrading = (ColorGrading*) nativeColorGrading;
view->setColorGrading(colorGrading);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetViewport(JNIEnv*, jclass,
jlong nativeView, jint left, jint bottom, jint width, jint height) {
@@ -53,45 +65,15 @@ Java_com_google_android_filament_View_nSetViewport(JNIEnv*, jclass,
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetClearColor(JNIEnv*, jclass,
jlong nativeView,
jfloat linearR, jfloat linearG, jfloat linearB, jfloat linearA) {
View* view = (View*) nativeView;
view->setClearColor({linearR, linearG, linearB, linearA});
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nGetClearColor(JNIEnv* env, jclass,
jlong nativeView, jfloatArray out_) {
View* view = (View*) nativeView;
jfloat* out = env->GetFloatArrayElements(out_, NULL);
auto linearColor = view->getClearColor();
out[0] = linearColor[0];
out[1] = linearColor[1];
out[2] = linearColor[2];
out[3] = linearColor[3];
env->ReleaseFloatArrayElements(out_, out, 0);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetClearTargets(JNIEnv*, jclass,
jlong nativeView, jboolean color, jboolean depth, jboolean stencil) {
View* view = (View*) nativeView;
view->setClearTargets(color, depth, stencil);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetVisibleLayers(JNIEnv*, jclass,
jlong nativeView, jint select, jint value) {
Java_com_google_android_filament_View_nSetVisibleLayers(JNIEnv*, jclass, jlong nativeView, jint select, jint value) {
View* view = (View*) nativeView;
view->setVisibleLayers((uint8_t) select, (uint8_t) value);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetShadowsEnabled(JNIEnv*, jclass,
jlong nativeView, jboolean enabled) {
Java_com_google_android_filament_View_nSetShadowingEnabled(JNIEnv*, jclass, jlong nativeView, jboolean enabled) {
View* view = (View*) nativeView;
view->setShadowsEnabled(enabled);
view->setShadowingEnabled(enabled);
}
extern "C" JNIEXPORT void JNICALL
@@ -102,50 +84,37 @@ Java_com_google_android_filament_View_nSetRenderTarget(JNIEnv*, jclass,
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetSampleCount(JNIEnv*, jclass,
jlong nativeView, jint count) {
Java_com_google_android_filament_View_nSetSampleCount(JNIEnv*, jclass, jlong nativeView, jint count) {
View* view = (View*) nativeView;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
view->setSampleCount((uint8_t) count);
#pragma clang diagnostic pop
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_View_nGetSampleCount(JNIEnv*, jclass,
jlong nativeView) {
Java_com_google_android_filament_View_nGetSampleCount(JNIEnv*, jclass, jlong nativeView) {
View* view = (View*) nativeView;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return view->getSampleCount();
#pragma clang diagnostic pop
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetAntiAliasing(JNIEnv*, jclass,
jlong nativeView, jint type) {
Java_com_google_android_filament_View_nSetAntiAliasing(JNIEnv*, jclass, jlong nativeView, jint type) {
View* view = (View*) nativeView;
view->setAntiAliasing(View::AntiAliasing(type));
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_View_nGetAntiAliasing(JNIEnv*, jclass,
jlong nativeView) {
Java_com_google_android_filament_View_nGetAntiAliasing(JNIEnv*, jclass, jlong nativeView) {
View* view = (View*) nativeView;
return (jint) view->getAntiAliasing();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetToneMapping(JNIEnv*, jclass,
jlong nativeView, jint type) {
View* view = (View*) nativeView;
view->setToneMapping(View::ToneMapping(type));
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_View_nGetToneMapping(JNIEnv*, jclass,
jlong nativeView) {
View* view = (View*) nativeView;
return (jint) view->getToneMapping();
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetDithering(JNIEnv*, jclass,
jlong nativeView, jint dithering) {
Java_com_google_android_filament_View_nSetDithering(JNIEnv*, jclass, jlong nativeView, jint dithering) {
View* view = (View*) nativeView;
view->setDithering((View::Dithering) dithering);
}
@@ -158,23 +127,49 @@ Java_com_google_android_filament_View_nGetDithering(JNIEnv*, jclass,
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetDynamicResolutionOptions(JNIEnv*,
jclass, jlong nativeView, jboolean enabled, jboolean homogeneousScaling,
jfloat targetFrameTimeMilli, jfloat headRoomRatio, jfloat scaleRate,
jfloat minScale, jfloat maxScale, jint history) {
View* view = (View*) nativeView;
Java_com_google_android_filament_View_nSetDynamicResolutionOptions(JNIEnv*, jclass, jlong nativeView,
jboolean enabled, jboolean homogeneousScaling,
jfloat minScale, jfloat maxScale, jfloat sharpness, jint quality) {
View* view = (View*)nativeView;
View::DynamicResolutionOptions options;
options.enabled = enabled;
options.homogeneousScaling = homogeneousScaling;
options.targetFrameTimeMilli = targetFrameTimeMilli;
options.headRoomRatio = headRoomRatio;
options.scaleRate = scaleRate;
options.minScale = filament::math::float2{minScale};
options.maxScale = filament::math::float2{maxScale};
options.history = (uint8_t) history;
options.minScale = filament::math::float2{ minScale };
options.maxScale = filament::math::float2{ maxScale };
options.sharpness = sharpness;
options.quality = (View::QualityLevel)quality;
view->setDynamicResolutionOptions(options);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetShadowType(JNIEnv*, jclass, jlong nativeView, jint type) {
View* view = (View*) nativeView;
view->setShadowType((View::ShadowType) type);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetVsmShadowOptions(JNIEnv*, jclass, jlong nativeView,
jint anisotropy, jboolean mipmapping, jfloat minVarianceScale,
jfloat lightBleedReduction) {
View* view = (View*) nativeView;
View::VsmShadowOptions options;
options.anisotropy = (uint8_t)anisotropy;
options.mipmapping = (bool)mipmapping;
options.minVarianceScale = minVarianceScale;
options.lightBleedReduction = lightBleedReduction;
view->setVsmShadowOptions(options);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetSoftShadowOptions(JNIEnv*, jclass, jlong nativeView,
jfloat penumbraScale, jfloat penumbraRatioScale) {
View* view = (View*) nativeView;
View::SoftShadowOptions options;
options.penumbraScale = penumbraScale;
options.penumbraRatioScale = penumbraRatioScale;
view->setSoftShadowOptions(options);
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetRenderQuality(JNIEnv*, jclass,
@@ -192,13 +187,6 @@ Java_com_google_android_filament_View_nSetDynamicLightingOptions(JNIEnv*,
view->setDynamicLightingOptions(zLightNear, zLightFar);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetDepthPrepass(JNIEnv*,
jclass, jlong nativeView, jint value) {
View* view = (View*) nativeView;
view->setDepthPrepass(View::DepthPrepass(value));
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetPostProcessingEnabled(JNIEnv*,
jclass, jlong nativeView, jboolean enabled) {
@@ -230,19 +218,269 @@ Java_com_google_android_filament_View_nIsFrontFaceWindingInverted(JNIEnv*,
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetAmbientOcclusion(JNIEnv*, jclass, jlong nativeView, jint ordinal) {
View* view = (View*) nativeView;
view->setAmbientOcclusion((View::AmbientOcclusion)ordinal);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
view->setAmbientOcclusion((View::AmbientOcclusion) ordinal);
#pragma clang diagnostic pop
}
extern "C" JNIEXPORT jint JNICALL
Java_com_google_android_filament_View_nGetAmbientOcclusion(JNIEnv*, jclass, jlong nativeView) {
View* view = (View*) nativeView;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return (jint)view->getAmbientOcclusion();
#pragma clang diagnostic pop
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetAmbientOcclusionOptions(JNIEnv*, jclass,
jlong nativeView, jfloat radius, jfloat bias, jfloat power, jfloat resolution) {
jlong nativeView, jfloat radius, jfloat bias, jfloat power, jfloat resolution, jfloat intensity,
jfloat bilateralThreshold,
jint quality, jint lowPassFilter, jint upsampling, jboolean enabled, jboolean bentNormals,
jfloat minHorizonAngleRad) {
View* view = (View*) nativeView;
View::AmbientOcclusionOptions options = { .radius = radius, .bias = bias, .power = power, .resolution = resolution};
View::AmbientOcclusionOptions options = view->getAmbientOcclusionOptions();
options.radius = radius;
options.power = power;
options.bias = bias;
options.resolution = resolution;
options.intensity = intensity;
options.bilateralThreshold = bilateralThreshold;
options.quality = (View::QualityLevel)quality;
options.lowPassFilter = (View::QualityLevel)lowPassFilter;
options.upsampling = (View::QualityLevel)upsampling;
options.enabled = (bool)enabled;
options.bentNormals = (bool)bentNormals;
options.minHorizonAngleRad = minHorizonAngleRad;
view->setAmbientOcclusionOptions(options);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetSSCTOptions(JNIEnv *, jclass, jlong nativeView,
jfloat ssctLightConeRad, jfloat ssctShadowDistance, jfloat ssctContactDistanceMax,
jfloat ssctIntensity, jfloat ssctLightDirX, jfloat ssctLightDirY, jfloat ssctLightDirZ,
jfloat ssctDepthBias, jfloat ssctDepthSlopeBias, jint ssctSampleCount,
jint ssctRayCount, jboolean ssctEnabled) {
View* view = (View*) nativeView;
View::AmbientOcclusionOptions options = view->getAmbientOcclusionOptions();
options.ssct.lightConeRad = ssctLightConeRad;
options.ssct.shadowDistance = ssctShadowDistance;
options.ssct.contactDistanceMax = ssctContactDistanceMax;
options.ssct.intensity = ssctIntensity;
options.ssct.lightDirection = math::float3{ ssctLightDirX, ssctLightDirY, ssctLightDirZ };
options.ssct.depthBias = ssctDepthBias;
options.ssct.depthSlopeBias = ssctDepthSlopeBias;
options.ssct.sampleCount = (uint8_t)ssctSampleCount;
options.ssct.rayCount = (uint8_t)ssctRayCount;
options.ssct.enabled = (bool)ssctEnabled;
view->setAmbientOcclusionOptions(options);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetBloomOptions(JNIEnv*, jclass,
jlong nativeView, jlong nativeTexture,
jfloat dirtStrength, jfloat strength, jint resolution, jfloat anamorphism, jint levels,
jint blendMode, jboolean threshold, jboolean enabled, jfloat highlight,
jboolean lensFlare, jboolean starburst, jfloat chromaticAberration, jint ghostCount,
jfloat ghostSpacing, jfloat ghostThreshold, jfloat haloThickness, jfloat haloRadius,
jfloat haloThreshold) {
View* view = (View*) nativeView;
Texture* dirt = (Texture*) nativeTexture;
View::BloomOptions options = {
.dirt = dirt,
.dirtStrength = dirtStrength,
.strength = strength,
.resolution = (uint32_t)resolution,
.anamorphism = anamorphism,
.levels = (uint8_t)levels,
.blendMode = (View::BloomOptions::BlendMode)blendMode,
.threshold = (bool)threshold,
.enabled = (bool)enabled,
.highlight = highlight,
.lensFlare = (bool)lensFlare,
.starburst = (bool)starburst,
.chromaticAberration = chromaticAberration,
.ghostCount = (uint8_t)ghostCount,
.ghostSpacing = ghostSpacing,
.ghostThreshold = ghostThreshold,
.haloThickness = haloThickness,
.haloRadius = haloRadius,
.haloThreshold = haloThreshold
};
view->setBloomOptions(options);
}
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 inScatteringSize, jboolean fogColorFromIbl, jboolean enabled) {
View* view = (View*) nativeView;
View::FogOptions options = {
.distance = distance,
.maximumOpacity = maximumOpacity,
.height = height,
.heightFalloff = heightFalloff,
.color = math::float3{r, g, b},
.density = density,
.inScatteringStart = inScatteringStart,
.inScatteringSize = inScatteringSize,
.fogColorFromIbl = (bool)fogColorFromIbl,
.enabled = (bool)enabled
};
view->setFogOptions(options);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetBlendMode(JNIEnv *, jclass , jlong nativeView, jint blendMode) {
View* view = (View*) nativeView;
view->setBlendMode((View::BlendMode)blendMode);
}
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetDepthOfFieldOptions(JNIEnv *, jclass,
jlong nativeView, jfloat cocScale, jfloat maxApertureDiameter, jboolean enabled, jint filter,
jboolean nativeResolution, jint foregroundRingCount, jint backgroundRingCount, jint fastGatherRingCount,
jint maxForegroundCOC, jint maxBackgroundCOC) {
View* view = (View*) nativeView;
View::DepthOfFieldOptions::Filter eFilter{};
if (filter == 1) {
// View::DepthOfFieldOptions::Filter::MEDIAN value is actually 2
eFilter = View::DepthOfFieldOptions::Filter::MEDIAN;
}
view->setDepthOfFieldOptions({.cocScale = cocScale,
.maxApertureDiameter = maxApertureDiameter, .enabled = (bool)enabled, .filter = eFilter,
.nativeResolution = (bool)nativeResolution,
.foregroundRingCount = (uint8_t)foregroundRingCount,
.backgroundRingCount = (uint8_t)backgroundRingCount,
.fastGatherRingCount = (uint8_t)fastGatherRingCount,
.maxForegroundCOC = (uint8_t)maxForegroundCOC,
.maxBackgroundCOC = (uint8_t)maxBackgroundCOC,
});
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetVignetteOptions(JNIEnv*, jclass, jlong nativeView, jfloat midPoint, jfloat roundness,
jfloat feather, jfloat r, jfloat g, jfloat b, jfloat a, jboolean enabled) {
View* view = (View*) nativeView;
view->setVignetteOptions({.midPoint = midPoint, .roundness = roundness, .feather = feather,
.color = LinearColorA{r, g, b, a}, .enabled = (bool)enabled});
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetMultiSampleAntiAliasingOptions(JNIEnv* env, jclass clazz,
jlong nativeView, jboolean enabled, jint sampleCount, jboolean customResolve) {
View* view = (View*) nativeView;
view->setMultiSampleAntiAliasingOptions({
.enabled = (bool)enabled,
.sampleCount = (uint8_t)sampleCount,
.customResolve = (bool)customResolve});
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetTemporalAntiAliasingOptions(JNIEnv *, jclass,
jlong nativeView, jfloat feedback, jfloat filterWidth, jboolean enabled) {
View* view = (View*) nativeView;
view->setTemporalAntiAliasingOptions({
.filterWidth = filterWidth, .feedback = feedback, .enabled = (bool) enabled});
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetScreenSpaceReflectionsOptions(JNIEnv*, jclass,
jlong nativeView, jfloat thickness, jfloat bias, jfloat maxDistance, jfloat stride, jboolean enabled) {
View* view = (View*) nativeView;
view->setScreenSpaceReflectionsOptions({.thickness = thickness, .bias = bias,
.maxDistance = maxDistance, .stride = stride, .enabled = (bool) enabled
});
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_View_nIsShadowingEnabled(JNIEnv *, jclass, jlong nativeView) {
View* view = (View*) nativeView;
return (jboolean)view->isShadowingEnabled();
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetScreenSpaceRefractionEnabled(JNIEnv *, jclass,
jlong nativeView, jboolean enabled) {
View* view = (View*) nativeView;
view->setScreenSpaceRefractionEnabled((bool)enabled);
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_View_nIsScreenSpaceRefractionEnabled(JNIEnv *, jclass,
jlong nativeView) {
View* view = (View*) nativeView;
return (jboolean)view->isScreenSpaceRefractionEnabled();
}
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nPick(JNIEnv* env, jclass,
jlong nativeView,
jint x, jint y, jobject handler, jobject internalCallback) {
// jniState will be initialized the first time this method is called
static const struct JniState {
jclass internalOnPickCallbackClass;
jfieldID renderableFieldId;
jfieldID depthFieldId;
jfieldID fragCoordXFieldId;
jfieldID fragCoordYFieldId;
jfieldID fragCoordZFieldId;
explicit JniState(JNIEnv* env) noexcept {
internalOnPickCallbackClass = env->FindClass("com/google/android/filament/View$InternalOnPickCallback");
renderableFieldId = env->GetFieldID(internalOnPickCallbackClass, "mRenderable", "I");
depthFieldId = env->GetFieldID(internalOnPickCallbackClass, "mDepth", "F");
fragCoordXFieldId = env->GetFieldID(internalOnPickCallbackClass, "mFragCoordsX", "F");
fragCoordYFieldId = env->GetFieldID(internalOnPickCallbackClass, "mFragCoordsY", "F");
fragCoordZFieldId = env->GetFieldID(internalOnPickCallbackClass, "mFragCoordsZ", "F");
}
} jniState(env);
View* view = (View*) nativeView;
JniCallback *callback = JniCallback::make(env, handler, internalCallback);
view->pick(x, y, [callback](View::PickingQueryResult const& result) {
// this is executed on the backend/service thread
jobject obj = callback->getCallbackObject();
JNIEnv* env = filament::VirtualMachineEnv::get().getEnvironment();
env->SetIntField(obj, jniState.renderableFieldId, (jint)result.renderable.getId());
env->SetFloatField(obj, jniState.depthFieldId, result.depth);
env->SetFloatField(obj, jniState.fragCoordXFieldId, result.fragCoords.x);
env->SetFloatField(obj, jniState.fragCoordYFieldId, result.fragCoords.y);
env->SetFloatField(obj, jniState.fragCoordZFieldId, result.fragCoords.z);
JniCallback::postToJavaAndDestroy(callback);
}, 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,
jlong nativeView, jboolean enabled) {
View* view = (View*) nativeView;
view->setGuardBandOptions({ .enabled = (bool)enabled });
}
@@ -1,62 +0,0 @@
/*
* Copyright (C) 2018 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.
*/
#include <stdio.h>
#include <jawt.h>
#include <darwin/jawt_md.h>
#include <filament/Engine.h>
#include "JAWTUtils.h"
#import <Cocoa/Cocoa.h>
#pragma clang diagnostic push
#pragma ide diagnostic ignored "NotReleasedValue"
extern "C" {
void *getNativeWindow(JNIEnv *env, jclass klass, jobject surface) {
void *win = nullptr;
JAWT_DrawingSurface *ds = nullptr;
JAWT_DrawingSurfaceInfo *dsi = nullptr;
if (!acquireDrawingSurface(env, surface, &ds, &dsi)) {
return win;
}
NSObject<JAWT_SurfaceLayers>* jawldsip = (NSObject<JAWT_SurfaceLayers>*)dsi->platformInfo;
// Use jawt_DrawingSurfaceInfo.bounds for frame dimension.
NSView *view = [[NSView alloc] initWithFrame:
NSMakeRect(dsi->bounds.x, dsi->bounds.y, dsi->bounds.width, dsi->bounds.height)];
view.wantsLayer = true;
[jawldsip setLayer:view.layer];
win = (void*) view;
releaseDrawingSurface(ds, dsi);
return win;
}
jlong createNativeSurface(jint width, jint height) {
NSView *view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, width, height)];
view.wantsLayer = true;
return (jlong) view;
}
void destroyNativeSurface(jlong surface) {
NSView *view = reinterpret_cast<NSView*>(surface);
[view release];
}
}
#pragma clang diagnostic pop
@@ -1,109 +0,0 @@
/*
* Copyright (C) 2018 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.
*/
#include "JAWTUtils.h"
#include <vector>
static std::vector<int> jawtVersions = {
0x00010003,
0x00010004,
0x00010007,
0x00010009,
};
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wuninitialized"
bool acquireDrawingSurface(JNIEnv* env, jobject surface,
JAWT_DrawingSurface** ods, JAWT_DrawingSurfaceInfo** odsi) {
JAWT awt;
JAWT_DrawingSurface* ds = nullptr;
JAWT_DrawingSurfaceInfo* dsi = nullptr;
// Search for a valid AWT
jboolean foundJawt = JNI_FALSE;
for (int jawtVersion : jawtVersions) {
awt.version = jawtVersion;
foundJawt = JAWT_GetAWT(env, &awt);
if (foundJawt == JNI_TRUE) {
#ifndef NDEBUG
printf("Found valid AWT v%08x.\n", jawtVersion);
#endif
break;
} else {
#ifndef NDEBUG
printf("AWT v%08x not present.\n", jawtVersion);
#endif
}
}
#ifndef NDEBUG
fflush(stdout);
#endif
if (foundJawt == JNI_FALSE) {
printf("AWT Not found\n");
fflush(stdout);
return false;
}
// Get the drawing surface
ds = awt.GetDrawingSurface(env, surface);
if (ds == nullptr) {
#ifndef NDEBUG
printf("NULL drawing surface\n");
fflush(stdout);
#endif
return false;
}
// Lock the drawing
jint lock = ds->Lock(ds);
if ((lock & JAWT_LOCK_ERROR) != 0) {
#ifndef NDEBUG
printf("Error locking surface\n");
fflush(stdout);
#endif
awt.FreeDrawingSurface(ds);
return false;
}
// Get the drawing surface info
dsi = ds->GetDrawingSurfaceInfo(ds);
if (dsi == nullptr) {
#ifndef NDEBUG
printf("Error getting surface info\n");
fflush(stdout);
#endif
ds->Unlock(ds);
awt.FreeDrawingSurface(ds);
return false;
}
*odsi = dsi;
*ods = ds;
return true;
}
#pragma clang diagnostic pop
void releaseDrawingSurface(JAWT_DrawingSurface* ds, JAWT_DrawingSurfaceInfo* dsi) {
// Free the drawing surface info
ds->FreeDrawingSurfaceInfo(dsi);
// Unlock the drawing surface
ds->Unlock(ds);
}
@@ -1,23 +0,0 @@
/*
* Copyright (C) 2018 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.
*/
#include <jawt.h>
extern "C" {
bool acquireDrawingSurface(JNIEnv* env, jobject surface, JAWT_DrawingSurface** ods,
JAWT_DrawingSurfaceInfo** odsi);
void releaseDrawingSurface(JAWT_DrawingSurface* ds, JAWT_DrawingSurfaceInfo* dsi);
}
@@ -1,90 +0,0 @@
/*
* Copyright (C) 2018 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.
*/
#include <stdio.h>
#include <jawt.h>
#include <linux/jawt_md.h>
#include "JAWTUtils.h"
#include<GL/glx.h>
extern "C" {
void *getNativeWindow(JNIEnv* env, jclass, jobject surface) {
void* win = nullptr;
JAWT_DrawingSurface* ds = nullptr;
JAWT_DrawingSurfaceInfo* dsi = nullptr;
if (!acquireDrawingSurface(env, surface, &ds, &dsi)) {
return win;
}
JAWT_X11DrawingSurfaceInfo* dsi_x11 = (JAWT_X11DrawingSurfaceInfo*) dsi->platformInfo;
win = (void*) dsi_x11->drawable;
releaseDrawingSurface(ds, dsi);
return win;
}
jlong createNativeSurface(jint width, jint height) {
Display* display = XOpenDisplay(nullptr);
int screen = DefaultScreen(display);
Window window = 0;
#ifndef NDEBUG
int major, minor;
glXQueryVersion(display, &major, &minor);
printf("Using GLX v%d.%d\n", major, minor); fflush(stdout);
#endif
static int visualAttributess[] = {
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DOUBLEBUFFER, True,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
GLX_DEPTH_SIZE, 24,
None
};
int numConfigs = 0;
GLXFBConfig* configs = glXChooseFBConfig( display, screen, visualAttributess, &numConfigs);
if (numConfigs == 0) {
printf("Unable to find a suitable Framebuffer Configuration.\n"); fflush(stdout);
return 0;
}
int pbufferAttributes[] = {
GLX_PBUFFER_WIDTH, width,
GLX_PBUFFER_HEIGHT, height,
None
};
window = glXCreatePbuffer( display, configs[0], pbufferAttributes );
XFree(configs);
// Make sure pbuffer creation has not been buffered in the event queue (we need it NOW).
XFlush(display);
// Camouflage the pbuffer as a window which are both XID anyway.
return (jlong) window;
}
void destroyNativeSurface(jlong surface) {
const char* displayName = nullptr;
Display* display = XOpenDisplay(displayName);
GLXPbuffer pBuffer = (GLXPbuffer)surface;
glXDestroyPbuffer(display, pBuffer);
}
}
@@ -1,67 +0,0 @@
/*
* Copyright (C) 2018 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.
*/
#include <stdio.h>
#include <jawt.h>
#include <win32/jawt_md.h>
#include <windows.h>
#include <utils/unwindows.h>
#include "JAWTUtils.h"
#include <filament/Engine.h>
extern "C" {
void* getNativeWindow(JNIEnv* env, jclass, jobject surface) {
JAWT_DrawingSurface* ds = nullptr;
JAWT_DrawingSurfaceInfo* dsi = nullptr;
if (!acquireDrawingSurface(env, surface, &ds, &dsi)) {
return nullptr;
}
JAWT_Win32DrawingSurfaceInfo* dsi_win32 = (JAWT_Win32DrawingSurfaceInfo*) dsi->platformInfo;
HWND hWnd = dsi_win32->hwnd;
releaseDrawingSurface(ds, dsi);
return (void*) hWnd;
}
jlong createNativeSurface(jint width, jint height) {
// We need to adjust the window size so the "client area" matches width and height requested.
// Otherwise, the window itself will be of dimension width-height but the "client area" and the
// resulting surface will be smaller than requested.
RECT dimension = {0, 0, width, height};
AdjustWindowRect(&dimension, WS_OVERLAPPEDWINDOW, FALSE);
width = dimension.right - dimension.left;
height = dimension.bottom - dimension.top;
HWND window = CreateWindowA("STATIC", "dummy", 0, 0, 0, width, height, NULL, NULL, NULL, NULL);
SetWindowLong(window, GWL_STYLE, 0); //remove all window styles
return (jlong) window;
}
void destroyNativeSurface(jlong surface) {
HWND window = (HWND) surface;
DestroyWindow(window);
}
}
@@ -19,8 +19,10 @@ package com.google.android.filament;
import android.graphics.SurfaceTexture;
import android.opengl.EGL14;
import android.opengl.EGLContext;
import android.os.Build;
import android.util.Log;
import android.view.Surface;
import java.lang.reflect.Method;
final class AndroidPlatform extends Platform {
private static final String LOG_TAG = "Filament";
@@ -59,6 +61,20 @@ final class AndroidPlatform extends Platform {
@Override
long getSharedContextNativeHandle(Object sharedContext) {
return ((EGLContext) sharedContext).getNativeHandle();
if (Build.VERSION.SDK_INT >= 21) {
return AndroidPlatform21.getSharedContextNativeHandle(sharedContext);
} else {
try {
//noinspection JavaReflectionMemberAccess
Method method = EGLContext.class.getDeclaredMethod("getHandle");
Integer handle = (Integer) method.invoke(sharedContext);
//noinspection ConstantConditions
return handle.longValue();
} catch (Exception e) {
Log.d(LOG_TAG, "Could not access shared context's native handle", e);
}
// Should not happen
return 0;
}
}
}
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2019 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;
import android.opengl.EGLContext;
final class AndroidPlatform21 {
static long getSharedContextNativeHandle(Object sharedContext) {
return ((EGLContext) sharedContext).getNativeHandle();
}
}
@@ -0,0 +1,130 @@
/*
* Copyright (C) 2019 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;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Size;
final class Asserts {
private Asserts() {
}
@NonNull @Size(min = 9)
static float[] assertMat3f(@Nullable float[] out) {
if (out == null) out = new float[9];
else if (out.length < 9) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 9");
}
return out;
}
static void assertMat3fIn(@NonNull @Size(min = 9) float[] in) {
if (in.length < 9) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 9");
}
}
@NonNull @Size(min = 16)
static double[] assertMat4d(@Nullable double[] out) {
if (out == null) out = new double[16];
else if (out.length < 16) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
}
return out;
}
static void assertMat4dIn(@NonNull @Size(min = 16) double[] in) {
if (in.length < 16) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
}
}
@NonNull @Size(min = 16)
static float[] assertMat4f(@Nullable float[] out) {
if (out == null) out = new float[16];
else if (out.length < 16) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
}
return out;
}
@NonNull @Size(min = 16)
static double[] assertMat4(@Nullable double[] out) {
if (out == null) out = new double[16];
else if (out.length < 16) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
}
return out;
}
static void assertMat4fIn(@NonNull @Size(min = 16) float[] in) {
if (in.length < 16) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
}
}
static void assertMat4In(@NonNull @Size(min = 16) double[] in) {
if (in.length < 16) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 16");
}
}
@NonNull @Size(min = 3)
static float[] assertFloat3(@Nullable float[] out) {
if (out == null) out = new float[3];
else if (out.length < 3) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 3");
}
return out;
}
static void assertFloat3In(@NonNull float[] out) {
if (out.length < 3) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 3");
}
}
@NonNull @Size(min = 4)
static float[] assertFloat4(@Nullable float[] out) {
if (out == null) out = new float[4];
else if (out.length < 4) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 4");
}
return out;
}
static void assertFloat4In(@NonNull float[] out) {
if (out.length < 4) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 4");
}
}
static double[] assertDouble4(@Nullable double[] out) {
if (out == null) out = new double[4];
else if (out.length < 4) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 4");
}
return out;
}
static void assertDouble4In(@NonNull double[] in) {
if (in.length < 4) {
throw new ArrayIndexOutOfBoundsException("Array length must be at least 4");
}
}
}
@@ -16,15 +16,28 @@
package com.google.android.filament;
import android.support.annotation.NonNull;
import android.support.annotation.Size;
import androidx.annotation.NonNull;
import androidx.annotation.Size;
/**
* An axis-aligned 3D box represented by its center and half-extent.
*
* The half-extent is a vector representing the distance from the center to the edge of the box in
* each dimension. For example, a box of size 2 units in X, 4 units in Y, and 10 units in Z would
* have a half-extent of (1, 2, 5).
*/
public class Box {
private final float[] mCenter = new float[3];
private final float[] mHalfExtent = new float[3];
/**
* Default-initializes the 3D box to have a center and half-extent of (0,0,0).
*/
public Box() { }
/**
* Initializes the 3D box from its center and half-extent.
*/
public Box(float centerX, float centerY, float centerZ,
float halfExtentX, float halfExtentY, float halfExtentZ) {
mCenter[0] = centerX;
@@ -35,6 +48,13 @@ public class Box {
mHalfExtent[2] = halfExtentZ;
}
/**
* Initializes the 3D box from its center and half-extent.
*
* @param center a float array with XYZ coordinates representing the center of the box
* @param halfExtent a float array with XYZ coordinates representing half the size of the box in
* each dimension
*/
public Box(@NonNull @Size(min = 3) float[] center, @NonNull @Size(min = 3) float[] halfExtent) {
mCenter[0] = center[0];
mCenter[1] = center[1];
@@ -44,21 +64,37 @@ public class Box {
mHalfExtent[2] = halfExtent[2];
}
/**
* Sets the center of of the 3D box.
*/
public void setCenter(float centerX, float centerY, float centerZ) {
mCenter[0] = centerX;
mCenter[1] = centerY;
mCenter[2] = centerZ;
}
/**
* Sets the half-extent of the 3D box.
*/
public void setHalfExtent(float halfExtentX, float halfExtentY, float halfExtentZ) {
mHalfExtent[0] = halfExtentX;
mHalfExtent[1] = halfExtentY;
mHalfExtent[2] = halfExtentZ;
}
/**
* Returns the center of the 3D box.
*
* @return an XYZ float array of size 3
*/
@NonNull @Size(min = 3)
public float[] getCenter() { return mCenter; }
/**
* Returns the half-extent from the center of the 3D box.
*
* @return an XYZ float array of size 3
*/
@NonNull @Size(min = 3)
public float[] getHalfExtent() { return mHalfExtent; }
}
@@ -0,0 +1,210 @@
/*
* Copyright (C) 2021 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;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.nio.Buffer;
import java.nio.BufferOverflowException;
/**
* A generic GPU buffer containing data.
*
* Usage of this BufferObject is optional. For simple use cases it is not necessary. It is useful
* only when you need to share data between multiple VertexBuffer instances. It also allows you to
* efficiently swap-out the buffers in VertexBuffer.
*
* NOTE: For now this is only used for vertex data, but in the future we may use it for other things
* (e.g. compute).
*
* @see VertexBuffer
*/
public class BufferObject {
private long mNativeObject;
private BufferObject(long nativeBufferObject) {
mNativeObject = nativeBufferObject;
}
public static class Builder {
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
// Keep to finalize native resources
private final BuilderFinalizer mFinalizer;
private final long mNativeBuilder;
public enum BindingType {
VERTEX,
}
public Builder() {
mNativeBuilder = nCreateBuilder();
mFinalizer = new BuilderFinalizer(mNativeBuilder);
}
/**
* Size of the buffer in bytes.
*
* @param byteCount Maximum number of bytes the BufferObject can hold.
* @return A reference to this Builder for chaining calls.
*/
@NonNull
public Builder size(@IntRange(from = 1) int byteCount) {
nBuilderSize(mNativeBuilder, byteCount);
return this;
}
/**
* The binding type for this buffer object. (defaults to VERTEX)
*
* @param bindingType Distinguishes between SSBO, VBO, etc. For now this must be VERTEX.
* @return A reference to this Builder for chaining calls.
*/
@NonNull
public Builder bindingType(@NonNull BindingType bindingType) {
nBuilderBindingType(mNativeBuilder, bindingType.ordinal());
return this;
}
/**
* Creates and returns the <code>BufferObject</code> object. After creation, the buffer
* is uninitialized. Use {@link #setBuffer} to initialize the <code>BufferObject</code>.
*
* @param engine reference to the {@link Engine} to associate this <code>BufferObject</code>
* with
*
* @return the newly created <code>BufferObject</code> object
*
* @exception IllegalStateException if the BufferObject could not be created
*
* @see #setBuffer
*/
@NonNull
public BufferObject build(@NonNull Engine engine) {
long nativeBufferObject = nBuilderBuild(mNativeBuilder, engine.getNativeObject());
if (nativeBufferObject == 0)
throw new IllegalStateException("Couldn't create BufferObject");
return new BufferObject(nativeBufferObject);
}
private static class BuilderFinalizer {
private final long mNativeObject;
BuilderFinalizer(long nativeObject) {
mNativeObject = nativeObject;
}
@Override
public void finalize() {
try {
super.finalize();
} catch (Throwable t) { // Ignore
} finally {
nDestroyBuilder(mNativeObject);
}
}
}
}
/**
* Returns the size of this <code>BufferObject</code> in elements.
*
* @return the number of bytes the <code>BufferObject</code> holds
*/
@IntRange(from = 0)
public int getByteCount() {
return nGetByteCount(getNativeObject());
}
/**
* Asynchronously copy-initializes this <code>BufferObject</code> from the data provided.
*
* @param engine reference to the {@link Engine} to associate this
* <code>BufferObject</code> with
* @param buffer a CPU-side {@link Buffer} with the data used to initialize the
* <code>BufferObject</code>.
*/
public void setBuffer(@NonNull Engine engine, @NonNull Buffer buffer) {
setBuffer(engine, buffer, 0, 0, null, null);
}
/**
* Asynchronously copy-initializes a region of this <code>BufferObject</code> from the data
* provided.
*
* @param engine reference to the {@link Engine} to associate this
* <code>BufferObject</code> with
* @param buffer a CPU-side {@link Buffer} with the data used to initialize the
* <code>BufferObject</code>.
* @param destOffsetInBytes offset in <i>bytes</i> into the <code>BufferObject</code>
* @param count number of bytes to consume, defaults to
* <code>buffer.remaining()</code>
*/
public void setBuffer(@NonNull Engine engine, @NonNull Buffer buffer,
@IntRange(from = 0) int destOffsetInBytes, @IntRange(from = 0) int count) {
setBuffer(engine, buffer, destOffsetInBytes, count, null, null);
}
/**
* Asynchronously copy-initializes a region of this <code>BufferObject</code> from the data
* provided.
*
* @param engine reference to the {@link Engine} to associate this
* <code>BufferObject</code> with
* @param buffer a CPU-side {@link Buffer} with the data used to initialize the
* <code>BufferObject</code>.
* @param destOffsetInBytes offset in <i>bytes</i> into the <code>BufferObject</code>
* @param count number of bytes to consume, defaults to
* <code>buffer.remaining()</code>
* @param handler an {@link java.util.concurrent.Executor Executor}. On Android this
* can also be a {@link android.os.Handler Handler}.
* @param callback a callback executed by <code>handler</code> when <code>buffer</code>
* is no longer needed.
*/
public void setBuffer(@NonNull Engine engine, @NonNull Buffer buffer,
@IntRange(from = 0) int destOffsetInBytes, @IntRange(from = 0) int count,
@Nullable Object handler, @Nullable Runnable callback) {
int result = nSetBuffer(getNativeObject(), engine.getNativeObject(), buffer, buffer.remaining(),
destOffsetInBytes, count == 0 ? buffer.remaining() : count, handler, callback);
if (result < 0) {
throw new BufferOverflowException();
}
}
public long getNativeObject() {
if (mNativeObject == 0) {
throw new IllegalStateException("Calling method on destroyed BufferObject");
}
return mNativeObject;
}
void clearNativeObject() {
mNativeObject = 0;
}
private static native long nCreateBuilder();
private static native void nDestroyBuilder(long nativeBuilder);
private static native void nBuilderSize(long nativeBuilder, int byteCount);
private static native void nBuilderBindingType(long nativeBuilder, int bindingType);
private static native long nBuilderBuild(long nativeBuilder, long nativeEngine);
private static native int nGetByteCount(long nativeBufferObject);
private static native int nSetBuffer(long nativeBufferObject, long nativeEngine,
Buffer buffer, int remaining,
int destOffsetInBytes, int count, Object handler, Runnable callback);
}

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