Merge pull request #46896 from lawnjelly/ewok_read_modulate_attribute

Batching - use FINAL_MODULATE_ALIAS in shaders
This commit is contained in:
Rémi Verschelde 2021-03-11 21:11:50 +01:00 committed by GitHub
commit d3dd28ba57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 12 deletions

View file

@ -911,7 +911,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
actions[VS::SHADER_CANVAS_ITEM].renames["INSTANCE_CUSTOM"] = "instance_custom";
actions[VS::SHADER_CANVAS_ITEM].renames["COLOR"] = "color";
actions[VS::SHADER_CANVAS_ITEM].renames["MODULATE"] = "final_modulate";
actions[VS::SHADER_CANVAS_ITEM].renames["MODULATE"] = "final_modulate_alias";
actions[VS::SHADER_CANVAS_ITEM].renames["NORMAL"] = "normal";
actions[VS::SHADER_CANVAS_ITEM].renames["NORMALMAP"] = "normal_map";
actions[VS::SHADER_CANVAS_ITEM].renames["NORMALMAP_DEPTH"] = "normal_depth";

View file

@ -31,6 +31,17 @@ attribute vec2 uv_attrib; // attrib:4
attribute highp vec4 modulate_attrib; // attrib:5
#endif
// Usually, final_modulate is passed as a uniform. However during batching
// If larger fvfs are used, final_modulate is passed as an attribute.
// we need to read from the attribute in custom vertex shader
// rather than the uniform. We do this by specifying final_modulate_alias
// in shaders rather than final_modulate directly.
#ifdef USE_ATTRIB_MODULATE
#define final_modulate_alias modulate_attrib
#else
#define final_modulate_alias final_modulate
#endif
#ifdef USE_ATTRIB_LARGE_VERTEX
// shared with skeleton attributes, not used in batched shader
attribute highp vec2 translate_attrib; // attrib:6
@ -469,6 +480,18 @@ void main() {
normal_used = true;
#endif
// If larger fvfs are used, final_modulate is passed as an attribute.
// we need to read from this in custom fragment shaders or applying in the post step,
// rather than using final_modulate directly.
#if defined(final_modulate_alias)
#undef final_modulate_alias
#endif
#ifdef USE_ATTRIB_MODULATE
#define final_modulate_alias modulate_interp
#else
#define final_modulate_alias final_modulate
#endif
/* clang-format off */
FRAGMENT_SHADER_CODE
@ -481,11 +504,7 @@ FRAGMENT_SHADER_CODE
}
#if !defined(MODULATE_USED)
#ifdef USE_ATTRIB_MODULATE
color *= modulate_interp;
#else
color *= final_modulate;
#endif
color *= final_modulate_alias;
#endif
#ifdef USE_LIGHTING

View file

@ -891,7 +891,7 @@ ShaderCompilerGLES3::ShaderCompilerGLES3() {
actions[VS::SHADER_CANVAS_ITEM].renames["INSTANCE_CUSTOM"] = "instance_custom";
actions[VS::SHADER_CANVAS_ITEM].renames["COLOR"] = "color";
actions[VS::SHADER_CANVAS_ITEM].renames["MODULATE"] = "final_modulate";
actions[VS::SHADER_CANVAS_ITEM].renames["MODULATE"] = "final_modulate_alias";
actions[VS::SHADER_CANVAS_ITEM].renames["NORMAL"] = "normal";
actions[VS::SHADER_CANVAS_ITEM].renames["NORMALMAP"] = "normal_map";
actions[VS::SHADER_CANVAS_ITEM].renames["NORMALMAP_DEPTH"] = "normal_depth";

View file

@ -14,6 +14,17 @@ layout(location = 3) in vec4 color_attrib;
layout(location = 5) in vec4 modulate_attrib; // attrib:5
#endif
// Usually, final_modulate is passed as a uniform. However during batching
// If larger fvfs are used, final_modulate is passed as an attribute.
// we need to read from the attribute in custom vertex shader
// rather than the uniform. We do this by specifying final_modulate_alias
// in shaders rather than final_modulate directly.
#ifdef USE_ATTRIB_MODULATE
#define final_modulate_alias modulate_attrib
#else
#define final_modulate_alias final_modulate
#endif
#ifdef USE_ATTRIB_LARGE_VERTEX
// shared with skeleton attributes, not used in batched shader
layout(location = 6) in vec2 translate_attrib; // attrib:6
@ -567,6 +578,18 @@ void main() {
normal_used = true;
#endif
// If larger fvfs are used, final_modulate is passed as an attribute.
// we need to read from this in custom fragment shaders or applying in the post step,
// rather than using final_modulate directly.
#if defined(final_modulate_alias)
#undef final_modulate_alias
#endif
#ifdef USE_ATTRIB_MODULATE
#define final_modulate_alias modulate_interp
#else
#define final_modulate_alias final_modulate
#endif
/* clang-format off */
FRAGMENT_SHADER_CODE
@ -582,12 +605,8 @@ FRAGMENT_SHADER_CODE
color = vec4(vec3(enc32), 1.0);
#endif
#ifdef USE_ATTRIB_MODULATE
color *= modulate_interp;
#else
#if !defined(MODULATE_USED)
color *= final_modulate;
#endif
color *= final_modulate_alias;
#endif
#ifdef USE_LIGHTING