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.
- 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
* 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>
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.
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.
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...
- 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.
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)
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.
- 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.
* 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
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.
- 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
- 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)
- 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)
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.
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
- 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.
- 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.
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.
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.