1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-17 14:11:06 +00:00

Add material debanding for use in Mobile rendering method.

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
This commit is contained in:
Allen Pestaluky
2022-03-07 18:29:40 +01:00
parent 9a5d6d1049
commit bd9d1bf070
20 changed files with 85 additions and 14 deletions

View File

@@ -2225,6 +2225,28 @@ void main() {
frag_color = out_color;
if (sc_use_material_debanding()) {
// From https://alex.vlachos.com/graphics/Alex_Vlachos_Advanced_VR_Rendering_GDC2015.pdf
// and https://www.shadertoy.com/view/MslGR8 (5th one starting from the bottom)
// NOTE: `gl_FragCoord` is in pixels (i.e. not normalized UV).
// This dithering must be applied after encoding changes (linear/nonlinear) have been applied
// as the final step before quantization from floating point to integer values.
// Iestyn's RGB dither (7 asm instructions) from Portal 2 X360, slightly modified for VR.
// Removed the time component to avoid passing time into this shader.
// This dither offset was chosen because it meshes nicely with the no-offset dither that
// is used for Viewport debanding.
const vec2 dither_offset = vec2(0.535, 8.715);
vec3 dither = vec3(dot(vec2(171.0, 231.0), gl_FragCoord.xy + dither_offset));
dither.rgb = fract(dither.rgb / vec3(103.0, 71.0, 97.0));
// Subtract 0.5 to avoid slightly brightening the whole viewport.
// Use a dither strength of 100% rather than the 37.5% suggested by the original source.
// Assume that this shader always writes to a 10-bit buffer, so divide by 1023 to align
// to 10-bit quantization.
frag_color.rgb += (dither.rgb - 0.5) / 1023.0;
}
#endif //MODE_MULTIPLE_RENDER_TARGETS
#endif //MODE_RENDER_DEPTH

View File

@@ -116,34 +116,38 @@ bool sc_use_lightmap_bicubic_filter() {
return ((sc_packed_0() >> 10) & 1U) != 0;
}
bool sc_multimesh() {
bool sc_use_material_debanding() {
return ((sc_packed_0() >> 11) & 1U) != 0;
}
bool sc_multimesh_format_2d() {
bool sc_multimesh() {
return ((sc_packed_0() >> 12) & 1U) != 0;
}
bool sc_multimesh_has_color() {
bool sc_multimesh_format_2d() {
return ((sc_packed_0() >> 13) & 1U) != 0;
}
bool sc_multimesh_has_custom_data() {
bool sc_multimesh_has_color() {
return ((sc_packed_0() >> 14) & 1U) != 0;
}
bool sc_scene_use_ambient_cubemap() {
bool sc_multimesh_has_custom_data() {
return ((sc_packed_0() >> 15) & 1U) != 0;
}
bool sc_scene_use_reflection_cubemap() {
bool sc_scene_use_ambient_cubemap() {
return ((sc_packed_0() >> 16) & 1U) != 0;
}
bool sc_scene_roughness_limiter_enabled() {
bool sc_scene_use_reflection_cubemap() {
return ((sc_packed_0() >> 17) & 1U) != 0;
}
bool sc_scene_roughness_limiter_enabled() {
return ((sc_packed_0() >> 18) & 1U) != 0;
}
uint sc_soft_shadow_samples() {
return (sc_packed_0() >> 20) & 63U;
}