Commit Graph

225 Commits

Author SHA1 Message Date
Ben Doherty
07ddd52dcf Add getVertexIndex API for vertex shaders (#3493) 2021-02-04 12:40:21 -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
a3412c4f45 Remove shadow cascade visualization from unlit variants (#3455) 2021-01-26 11:20:54 -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
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
Ben Doherty
0bec65701a VSM: render both shadow casters and receivers (#3147) 2020-10-05 17:03:10 -06:00
Pixelflinger
8b3caeffb9 ssct: decouple shadow distance from sample count 2020-10-01 10:20:38 -07:00
Ben Doherty
4af0cdfd4d Use light space Z as VSM depth metric (#3131) 2020-09-30 12:31:03 -06: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
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
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
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
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
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
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
84f0e97c78 apply the material clip-space transform to the depth 2020-08-31 11:59:52 -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
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
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
Ben Doherty
3e5d9fa0b4 Add VSM shader changes (#2971) 2020-08-19 10:56:48 -07:00
Romain Guy
29a33ef215 Fix formatting error 2020-08-18 10:29:44 -07:00
Ben Doherty
d14e29d4d3 Audit material variants (#2948) 2020-08-13 10:58:27 -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
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
Philip Rideout
2c114a9a9f Add mask smoothing to the unlit path. 2020-07-30 15:14:46 -07:00
Pixelflinger
ea5e8c2d14 fix refraction roughness when specular AA is active 2020-07-29 16:36:24 -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
Ben Doherty
b0c11c17e9 Add outputs block to material definition (#2823) 2020-07-20 16:48:00 -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
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
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
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
Pixelflinger
0d652d61f8 fix typo causing textureGather to always be used 2020-05-26 17:59:01 -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
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
Ben Doherty
3c42ace496 Fix, don't sample from cascades without visible shadows (#2501) 2020-05-07 16:50:34 -07:00
Ben Doherty
4701945c87 Add rudimentary cascading shadow map support (#2482) 2020-05-06 17:20:04 -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
3bd1afedbd compute bitangeant in fragment shader
This saves 4 varying components.
Fixes #2092
2020-05-01 14:41:03 -07:00
Pixelflinger
dc5c48de33 fix a couple missing 'highp' qualifiers 2020-05-01 10:14:44 -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
Romain Guy
038cecd8e2 Fix emissive 2020-04-17 18:46:16 -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