diff options
author | Alexander Hartmann <alex.hart.278@gmail.com> | 2024-01-19 00:07:28 +0100 |
---|---|---|
committer | Alexander Hartmann <alex.hart.278@gmail.com> | 2024-02-22 00:24:08 +0100 |
commit | e17cecf54a4e98ede77e87a08d33742463bddca5 (patch) | |
tree | 4097e76f2b4d4a3f6e0c645d218cfb04c436cd6c /drivers/gles3/shaders | |
parent | 16d61427cab3a8e43f0a9a8ee724fc176b6433c6 (diff) | |
download | redot-engine-e17cecf54a4e98ede77e87a08d33742463bddca5.tar.gz |
Fix Compatibility Rendering (GLES3) on old and low budget devices.
Co-Authored-By: joined72 <19651914+joined72@users.noreply.github.com>
Diffstat (limited to 'drivers/gles3/shaders')
-rw-r--r-- | drivers/gles3/shaders/canvas.glsl | 43 | ||||
-rw-r--r-- | drivers/gles3/shaders/scene.glsl | 5 |
2 files changed, 35 insertions, 13 deletions
diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 80e28cf9fc..8da7d7dc80 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -187,8 +187,31 @@ void main() { #endif // !USE_INSTANCING #else // !USE_ATTRIBUTES - vec2 vertex_base_arr[6] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0), vec2(0.0, 0.0), vec2(1.0, 1.0)); - vec2 vertex_base = vertex_base_arr[gl_VertexID % 6]; + + // crash on Adreno 320/330 + //vec2 vertex_base_arr[6] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0), vec2(0.0, 0.0), vec2(1.0, 1.0)); + //vec2 vertex_base = vertex_base_arr[gl_VertexID % 6]; + //----------------------------------------- + // ID | 0 | 1 | 2 | 3 | 4 | 5 | + //----------------------------------------- + // X | 0.0 | 0.0 | 1.0 | 1.0 | 0.0 | 1.0 | + // Y | 0.0 | 1.0 | 1.0 | 0.0 | 0.0 | 1.0 | + //----------------------------------------- + // no crash or freeze on all Adreno 3xx with 'if / else if' and slightly faster! + int vertex_id = gl_VertexID % 6; + vec2 vertex_base; + if (vertex_id == 0) + vertex_base = vec2(0.0, 0.0); + else if (vertex_id == 1) + vertex_base = vec2(0.0, 1.0); + else if (vertex_id == 2) + vertex_base = vec2(1.0, 1.0); + else if (vertex_id == 3) + vertex_base = vec2(1.0, 0.0); + else if (vertex_id == 4) + vertex_base = vec2(0.0, 0.0); + else if (vertex_id == 5) + vertex_base = vec2(1.0, 1.0); vec2 uv = read_draw_data_src_rect.xy + abs(read_draw_data_src_rect.zw) * ((read_draw_data_flags & FLAGS_TRANSPOSE_RECT) != uint(0) ? vertex_base.yx : vertex_base.xy); vec4 color = read_draw_data_modulation; @@ -475,16 +498,12 @@ vec4 light_shadow_compute(uint light_base, vec4 light_color, vec4 shadow_uv void light_blend_compute(uint light_base, vec4 light_color, inout vec3 color) { uint blend_mode = light_array[light_base].flags & LIGHT_FLAGS_BLEND_MASK; - switch (blend_mode) { - case LIGHT_FLAGS_BLEND_MODE_ADD: { - color.rgb += light_color.rgb * light_color.a; - } break; - case LIGHT_FLAGS_BLEND_MODE_SUB: { - color.rgb -= light_color.rgb * light_color.a; - } break; - case LIGHT_FLAGS_BLEND_MODE_MIX: { - color.rgb = mix(color.rgb, light_color.rgb, light_color.a); - } break; + if (blend_mode == LIGHT_FLAGS_BLEND_MODE_ADD) { + color.rgb += light_color.rgb * light_color.a; + } else if (blend_mode == LIGHT_FLAGS_BLEND_MODE_SUB) { + color.rgb -= light_color.rgb * light_color.a; + } else if (blend_mode == LIGHT_FLAGS_BLEND_MODE_MIX) { + color.rgb = mix(color.rgb, light_color.rgb, light_color.a); } } diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 27c292d163..a6db90c3f5 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -1200,7 +1200,10 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 f vec3 spot_dir = spot_lights[idx].direction; float scos = max(dot(-normalize(light_rel_vec), spot_dir), spot_lights[idx].cone_angle); float spot_rim = max(0.0001, (1.0 - scos) / (1.0 - spot_lights[idx].cone_angle)); - spot_attenuation *= 1.0 - pow(spot_rim, spot_lights[idx].cone_attenuation); + + mediump float cone_attenuation = spot_lights[idx].cone_attenuation; + spot_attenuation *= 1.0 - pow(spot_rim, cone_attenuation); + vec3 color = spot_lights[idx].color; float size_A = 0.0; |