Commit Graph

109 Commits

Author SHA1 Message Date
Mathias Agopian
10f4632c88 small math::mat3f to GL mat3 optimizations 2025-09-18 12:15:56 -07:00
Mathias Agopian
4c91d48ed3 Revert "use fmin/fmax for floating-point"
This reverts commit a032190b24.
2025-09-04 00:08:30 -07:00
Mathias Agopian
a032190b24 use fmin/fmax for floating-point
On ARM this generates the fmin/fmax instruction, which avoids
branches.
2025-09-03 22:30:09 -07:00
KeremTAN
83967fdb1b std type trait specialization of is_arithmetic and is_floating_type removed 2025-04-25 12:14:26 -07:00
KeremTAN
b88c2d80a4 Fix Clang 20 compile error: invalid std type trait specializations 2025-04-25 12:14:26 -07:00
Rasmus Munk Larsen
3c941863dc Revert change to pow. 2025-04-23 16:25:46 -07:00
Rasmus Munk Larsen
57e2007aaf Fix typo again. 2025-04-23 16:25:46 -07:00
Rasmus Munk Larsen
f88f0607c7 Fix typo. 2025-04-23 16:25:46 -07:00
Rasmus Munk Larsen
91b98964cc Optimize pow and slerp for quaternions by using the identies
sin(acos(x)) = sqrt(1-x^2)
  cos(acos(x)) = x.
2025-04-23 16:25:46 -07:00
Mathias Agopian
bef849b0e3 large code cleanup (#8364)
* Remove redundant qualifiers in filament public headers

* remove redundant qualifiers in filament implementation

* remove redundant qualifiers in libutils public headers

* remove redundant qualifier for libutils implementation

* remove redundant qualifiers for libmath

* use is_same_v<> instead of is_same<>

* bring back Builder::name()

we keep Builder::name() on all object, and forward to the MixIn class
that does the implementation, so that we have correct documentation, and
better IDE completion.

* add missing const parameters in filament's implementation

* various source cleanup

- missing includes
- missing const
- C cast style
- superfluous inline keyword
2025-01-17 17:50:16 -08:00
Mathias Agopian
a27260b87f lazy initialization of the ShadowMap cache in ShadowMapManager
This reduces resource utilisation for Views that never need shadows.
It saves a UBO, two Entities and about 10KB memory. We also lazily
allocate the debugging DataSource, which saves about 10K per View
in debug builds.

Overall this change makes "simple" Views less than 4KB heavy down from
about 24KB (debug, 14KB release).

The main changes:
- ShadowMapManager is now allocated lazily
- the ShadowMap cache object is also allocated lazily
- debug DataSource is allocated lazily
- ShadowMaps are prepared/initialized with a Builder, which makes it
  clearer that some APIs are only for preparing the ShadowMap cache.
2024-02-12 14:32:50 -08:00
Ben Doherty
cbc3bb3326 Fix mix-precision quaternion conversions (#7339) 2023-11-08 12:38:57 -08:00
Mathias Agopian
1b0db0fca2 fix a couple shadow stability bugs
- shadows are now stable (in stable mode) when an IBL rotation is
  used.

- fix the shadow transform option which didn't work when an IBL rotation
  was used

- also use the x-axis as a reference for the "up" direction when
  computing the light space matrix so that we don't fall into the
  degenerate case when the light points straight down, which is a
  common case

FIXES=[299310624]
2023-10-17 12:26:43 -07:00
Mathias Agopian
14263efbea fix mixed-precision quaternion math
We follow the same rules as C++, e.g. float * double -> double
2023-10-16 10:52:36 -07:00
Mathias Agopian
d02231dce9 fix build most recent emscripten build 2023-09-21 13:02:35 -07:00
Mathias Agopian
6fd5d45295 fix shadow stability when eye is far from world origin
in stable mode the scale was ever so slightly varying with the 
camera position, because it was calculated from the camera frustum in
world-space, this variation was amplified when the camera is far from 
the origin, which eventually caused the modulo needed for snapping the
shadowmap projection to widely vary, leading to the instability.

We now calculate the camera frustum sphere in view space, which is
guaranteed to be constant. If "shadow caster mode" is chosen, we 
quantize the scale a little bit so it stays constant.

The snapping code itself has been cleaned.
2023-09-08 11:19:19 -07:00
Mathias Agopian
e0a37de1ba cleanup 2023-09-07 00:09:02 -07:00
Jacob Su
8d7743ce67 Bug: fix underscores literal operators c++ compatible error. (#7136) 2023-09-05 10:03:51 -07:00
Jacob Su
aa6e94a128 Fix Mat cofactor UT error on Mac M2 chip machine. 2023-08-18 10:28:51 -07:00
Mathias Agopian
1c7293db8d fix fuzzyEqual
- the return value was inverted
- fuzzyEqual could generate alignment faults
- move it out of mat4 and mat2 because it was
  only used in one place.
2023-08-16 10:40:13 -07:00
Ben Doherty
6558448eae Add support for supplying instance local transforms (#6762)
Clients can now supply a local transform for each GPU instance.
2023-05-01 18:00:27 -04:00
Mathias Agopian
4503ad1e34 fix -ffast-math and -fno-finite-math-only
- remove -ffast-math in place where it didn't seem too useful
- added -fno-finite-math-only everywhere we use -ffast-math so that
  isinf/isnan work.
2023-03-30 16:15:42 -07:00
Mathias Agopian
6ec5fd86fa rework how we set the viewport for shadows
The viewport is now entirely handled by ShadowMap, that is, we're no
longer setting a viewport in the renderpass, instead the ShadowMap
uses a post projection transform to achieve the same effect.
This will become useful when store shadow maps in an Atlas.
2022-11-10 15:15:43 -08:00
gaborvalasek
39cb238065 Fix MSVC warnings (#5926)
* Fix warning C4146: unary minus operator applied to unsigned type, result still unsigned

* Fix warning C4068: unknown pragma 'nounroll'

* Fix warning C4068: unknown pragma 'unroll'

* Fix warning C4068: unknown pragma 'clang'

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

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

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

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

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

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

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

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

* Revert unary minus for non-MSVC compilers

* Add macro for enabling warnings temporarily

* Get rid of UTILS_HAS_CXX17

* Revisit warning related macros

Co-authored-by: Levente Koncz <levente.koncz@shapr3d.com>
2022-08-24 11:41:10 -07:00
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
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
daemyung jang
1969186fe1 Compute the rotation between two vectors (#5288)
Co-authored-by: Mathias Agopian <pixelflinger@gmail.com>
2022-03-10 10:42:44 -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
7b5cac6d4f Do not include <algorithm> unless necessary. 2022-01-19 13:11:04 -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
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
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
Romain Guy
f804c9e346 Switch white balance to CAT16 and add gamut mapping code (#4457) 2021-08-05 12:44:49 -07:00
Mathias Agopian
3b59dff577 fix some build warnings 2021-05-24 13:25:11 -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
Mathias Agopian
cc13420e31 add missing includes
Should fix #3633
2021-03-15 22:45:31 -07: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
Mathias Agopian
af82aaa0fc remove unused code that causes warnings 2021-01-15 14:38:01 -08: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
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
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
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
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
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
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
Pixelflinger
68f0ab6312 Implement ACES tone mapping
this leverages the new LUT based tone mapping
2020-05-26 23:46:37 -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
Ben Doherty
acc36e8d9b Deprecating Clang on Windows in CMakeLists (#2243) 2020-03-13 12:33:02 -07: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