-Many GLES2 optimizations

-Android export fixes (use ETC if GLES2 backend in use)
-revert to thekla atlas because xatlas is not working well
This commit is contained in:
Juan Linietsky 2018-09-30 23:10:18 -03:00
parent 80d6bb7193
commit c24277a520
6 changed files with 185 additions and 44 deletions

View File

@ -54,6 +54,8 @@ GLuint RasterizerStorageGLES2::system_fbo = 0;
#define _EXT_TEXTURE_CUBE_MAP_SEAMLESS 0x884F #define _EXT_TEXTURE_CUBE_MAP_SEAMLESS 0x884F
#define _DEPTH_COMPONENT24_OES 0x81A6
void RasterizerStorageGLES2::bind_quad_array() const { void RasterizerStorageGLES2::bind_quad_array() const {
glBindBuffer(GL_ARRAY_BUFFER, resources.quadie); glBindBuffer(GL_ARRAY_BUFFER, resources.quadie);
glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0); glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0);
@ -3915,7 +3917,7 @@ void RasterizerStorageGLES2::_render_target_allocate(RenderTarget *rt) {
glGenRenderbuffers(1, &rt->depth); glGenRenderbuffers(1, &rt->depth);
glBindRenderbuffer(GL_RENDERBUFFER, rt->depth); glBindRenderbuffer(GL_RENDERBUFFER, rt->depth);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, rt->width, rt->height); glRenderbufferStorage(GL_RENDERBUFFER, _DEPTH_COMPONENT24_OES, rt->width, rt->height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rt->depth);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

View File

@ -15,6 +15,7 @@ precision highp int;
#define M_PI 3.14159265359 #define M_PI 3.14159265359
// //
// attributes // attributes
// //
@ -1214,14 +1215,17 @@ LIGHT_SHADER_CODE
#ifdef USE_SHADOW #ifdef USE_SHADOW
#define SAMPLE_SHADOW_TEXEL(p_shadow, p_pos, p_depth) step(p_depth, texture2D(p_shadow, p_pos).r) #define SAMPLE_SHADOW_TEXEL(p_shadow, p_pos, p_depth) step(p_depth, texture2D(p_shadow, p_pos).r)
#define SAMPLE_SHADOW_TEXEL_PROJ(p_shadow, p_pos) step(p_pos.z, texture2DProj(p_shadow, p_pos).r)
float sample_shadow( float sample_shadow(
highp sampler2D shadow, highp sampler2D shadow,highp vec4 spos) {
highp vec2 pos,
highp float depth) {
#ifdef SHADOW_MODE_PCF_13 #ifdef SHADOW_MODE_PCF_13
spos.xyz/=spos.w;
vec2 pos = spos.xy;
float depth = spos.z;
float avg = SAMPLE_SHADOW_TEXEL(shadow, pos, depth); float avg = SAMPLE_SHADOW_TEXEL(shadow, pos, depth);
avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(shadow_pixel_size.x, 0.0), depth); avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(shadow_pixel_size.x, 0.0), depth);
avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(-shadow_pixel_size.x, 0.0), depth); avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(-shadow_pixel_size.x, 0.0), depth);
@ -1240,6 +1244,10 @@ float sample_shadow(
#ifdef SHADOW_MODE_PCF_5 #ifdef SHADOW_MODE_PCF_5
spos.xyz/=spos.w;
vec2 pos = spos.xy;
float depth = spos.z;
float avg = SAMPLE_SHADOW_TEXEL(shadow, pos, depth); float avg = SAMPLE_SHADOW_TEXEL(shadow, pos, depth);
avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(shadow_pixel_size.x, 0.0), depth); avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(shadow_pixel_size.x, 0.0), depth);
avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(-shadow_pixel_size.x, 0.0), depth); avg += SAMPLE_SHADOW_TEXEL(shadow, pos + vec2(-shadow_pixel_size.x, 0.0), depth);
@ -1251,7 +1259,7 @@ float sample_shadow(
#if !defined(SHADOW_MODE_PCF_5) || !defined(SHADOW_MODE_PCF_13) #if !defined(SHADOW_MODE_PCF_5) || !defined(SHADOW_MODE_PCF_13)
return SAMPLE_SHADOW_TEXEL(shadow, pos, depth); return SAMPLE_SHADOW_TEXEL_PROJ(shadow, spos);
#endif #endif
} }
@ -1321,8 +1329,8 @@ FRAGMENT_SHADER_CODE
normalmap.xy = normalmap.xy * 2.0 - 1.0; normalmap.xy = normalmap.xy * 2.0 - 1.0;
normalmap.z = sqrt(max(0.0, 1.0 - dot(normalmap.xy, normalmap.xy))); normalmap.z = sqrt(max(0.0, 1.0 - dot(normalmap.xy, normalmap.xy)));
// normal = normalize(mix(normal_interp, tangent * normalmap.x + binormal * normalmap.y + normal * normalmap.z, normaldepth)) * side; normal = normalize(mix(normal_interp, tangent * normalmap.x + binormal * normalmap.y + normal * normalmap.z, normaldepth)) * side;
normal = normalmap; //normal = normalmap;
#endif #endif
normal = normalize(normal); normal = normalize(normal);
@ -1493,10 +1501,10 @@ FRAGMENT_SHADER_CODE
#ifdef USE_SHADOW #ifdef USE_SHADOW
{ {
highp vec3 splane = shadow_coord.xyz; highp vec4 splane = shadow_coord;
float shadow_len = length(splane); float shadow_len = length(splane.xyz);
splane = normalize(splane); splane = normalize(splane.xyz);
vec4 clamp_rect = light_clamp; vec4 clamp_rect = light_clamp;
@ -1513,8 +1521,9 @@ FRAGMENT_SHADER_CODE
splane.z = shadow_len / light_range; splane.z = shadow_len / light_range;
splane.xy = clamp_rect.xy + splane.xy * clamp_rect.zw; splane.xy = clamp_rect.xy + splane.xy * clamp_rect.zw;
splane.w = 1.0;
float shadow = sample_shadow(light_shadow_atlas, splane.xy, splane.z); float shadow = sample_shadow(light_shadow_atlas, splane);
light_att *= shadow; light_att *= shadow;
} }
@ -1531,6 +1540,126 @@ FRAGMENT_SHADER_CODE
float depth_z = -vertex.z; float depth_z = -vertex.z;
#ifdef USE_SHADOW #ifdef USE_SHADOW
#ifdef USE_VERTEX_LIGHTING
//compute shadows in a mobile friendly way
#ifdef LIGHT_USE_PSSM4
//take advantage of prefetch
float shadow1 = sample_shadow(light_directional_shadow, shadow_coord);
float shadow2 = sample_shadow(light_directional_shadow, shadow_coord2);
float shadow3 = sample_shadow(light_directional_shadow, shadow_coord3);
float shadow4 = sample_shadow(light_directional_shadow, shadow_coord4);
if (depth_z < light_split_offsets.w) {
float pssm_fade = 0.0;
float shadow_att = 1.0;
#ifdef LIGHT_USE_PSSM_BLEND
float shadow_att2 = 1.0;
float pssm_blend = 0.0;
bool use_blend = true;
#endif
if (depth_z < light_split_offsets.y) {
if (depth_z < light_split_offsets.x) {
shadow_att = shadow1;
#ifdef LIGHT_USE_PSSM_BLEND
shadow_att2 = shadow2;
pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
#endif
} else {
shadow_att = shadow2;
#ifdef LIGHT_USE_PSSM_BLEND
shadow_att2 = shadow3;
pssm_blend = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
#endif
}
} else {
if (depth_z < light_split_offsets.z) {
shadow_att = shadow3;
#if defined(LIGHT_USE_PSSM_BLEND)
shadow_att2 = shadow4;
pssm_blend = smoothstep(light_split_offsets.y, light_split_offsets.z, depth_z);
#endif
} else {
shadow_att = shadow4;
pssm_fade = smoothstep(light_split_offsets.z, light_split_offsets.w, depth_z);
#if defined(LIGHT_USE_PSSM_BLEND)
use_blend = false;
#endif
}
}
#if defined(LIGHT_USE_PSSM_BLEND)
if (use_blend) {
shadow_att = mix(shadow_att, shadow_att2, pssm_blend);
}
#endif
light_att *= shadow_att;
}
#endif //LIGHT_USE_PSSM4
#ifdef LIGHT_USE_PSSM2
//take advantage of prefetch
float shadow1 = sample_shadow(light_directional_shadow, shadow_coord);
float shadow2 = sample_shadow(light_directional_shadow, shadow_coord2);
if (depth_z < light_split_offsets.y) {
float shadow_att = 1.0;
float pssm_fade = 0.0;
#ifdef LIGHT_USE_PSSM_BLEND
float shadow_att2 = 1.0;
float pssm_blend = 0.0;
bool use_blend = true;
#endif
if (depth_z < light_split_offsets.x) {
float pssm_fade = 0.0;
shadow_att = shadow1;
#ifdef LIGHT_USE_PSSM_BLEND
shadow_att2 = shadow2;
pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
#endif
} else {
shadow_att = shadow2;
pssm_fade = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
#ifdef LIGHT_USE_PSSM_BLEND
use_blend = false;
#endif
}
#ifdef LIGHT_USE_PSSM_BLEND
if (use_blend) {
shadow_att = mix(shadow_att, shadow_att2, pssm_blend);
}
#endif
light_att *= shadow_att;
}
#endif //LIGHT_USE_PSSM2
#if !defined(LIGHT_USE_PSSM4) && !defined(LIGHT_USE_PSSM2)
light_att *= sample_shadow(light_directional_shadow, shadow_coord);
#endif //orthogonal
#else //fragment version of pssm
{ {
#ifdef LIGHT_USE_PSSM4 #ifdef LIGHT_USE_PSSM4
if (depth_z < light_split_offsets.w) { if (depth_z < light_split_offsets.w) {
@ -1540,34 +1669,32 @@ FRAGMENT_SHADER_CODE
if (depth_z < light_split_offsets.x) { if (depth_z < light_split_offsets.x) {
#endif //pssm2 #endif //pssm2
vec3 pssm_coord; highp vec4 pssm_coord;
float pssm_fade = 0.0; float pssm_fade = 0.0;
#ifdef LIGHT_USE_PSSM_BLEND #ifdef LIGHT_USE_PSSM_BLEND
float pssm_blend; float pssm_blend;
vec3 pssm_coord2; highp vec4 pssm_coord2;
bool use_blend = true; bool use_blend = true;
#endif #endif
#ifdef LIGHT_USE_PSSM4 #ifdef LIGHT_USE_PSSM4
if (depth_z < light_split_offsets.y) {
if (depth_z < light_split_offsets.x) {
highp vec4 splane = shadow_coord;
pssm_coord = splane.xyz / splane.w;
#ifdef LIGHT_USE_PSSM_BLEND
splane = shadow_coord2; if (depth_z < light_split_offsets.y) {
pssm_coord2 = splane.xyz / splane.w; if (depth_z < light_split_offsets.x) {
pssm_coord = shadow_coord;
#ifdef LIGHT_USE_PSSM_BLEND
pssm_coord2 = shadow_coord2;
pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z); pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
#endif #endif
} else { } else {
highp vec4 splane = shadow_coord2; pssm_coord = shadow_coord2;
pssm_coord = splane.xyz / splane.w;
#ifdef LIGHT_USE_PSSM_BLEND #ifdef LIGHT_USE_PSSM_BLEND
splane = shadow_coord3; pssm_coord2 = shadow_coord3;
pssm_coord2 = splane.xyz / splane.w;
pssm_blend = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z); pssm_blend = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
#endif #endif
@ -1575,19 +1702,16 @@ FRAGMENT_SHADER_CODE
} else { } else {
if (depth_z < light_split_offsets.z) { if (depth_z < light_split_offsets.z) {
highp vec4 splane = shadow_coord3; pssm_coord = shadow_coord3;
pssm_coord = splane.xyz / splane.w;
#if defined(LIGHT_USE_PSSM_BLEND) #if defined(LIGHT_USE_PSSM_BLEND)
splane = shadow_coord4; pssm_coord2 = shadow_coord4;
pssm_coord2 = splane.xyz / splane.w;
pssm_blend = smoothstep(light_split_offsets.y, light_split_offsets.z, depth_z); pssm_blend = smoothstep(light_split_offsets.y, light_split_offsets.z, depth_z);
#endif #endif
} else { } else {
highp vec4 splane = shadow_coord4; pssm_coord = shadow_coord4;
pssm_coord = splane.xyz / splane.w;
pssm_fade = smoothstep(light_split_offsets.z, light_split_offsets.w, depth_z); pssm_fade = smoothstep(light_split_offsets.z, light_split_offsets.w, depth_z);
#if defined(LIGHT_USE_PSSM_BLEND) #if defined(LIGHT_USE_PSSM_BLEND)
@ -1601,17 +1725,15 @@ FRAGMENT_SHADER_CODE
#ifdef LIGHT_USE_PSSM2 #ifdef LIGHT_USE_PSSM2
if (depth_z < light_split_offsets.x) { if (depth_z < light_split_offsets.x) {
highp vec4 splane = shadow_coord; pssm_coord = shadow_coord;
pssm_coord = splane.xyz / splane.w;
#ifdef LIGHT_USE_PSSM_BLEND #ifdef LIGHT_USE_PSSM_BLEND
splane = shadow_coord2; pssm_coord2 = shadow_coord2;
pssm_coord2 = splane.xyz / splane.w;
pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z); pssm_blend = smoothstep(0.0, light_split_offsets.x, depth_z);
#endif #endif
} else { } else {
highp vec4 splane = shadow_coord2;
pssm_coord = splane.xyz / splane.w; pssm_coord = shadow_coord2;
pssm_fade = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z); pssm_fade = smoothstep(light_split_offsets.x, light_split_offsets.y, depth_z);
#ifdef LIGHT_USE_PSSM_BLEND #ifdef LIGHT_USE_PSSM_BLEND
use_blend = false; use_blend = false;
@ -1622,22 +1744,23 @@ FRAGMENT_SHADER_CODE
#if !defined(LIGHT_USE_PSSM4) && !defined(LIGHT_USE_PSSM2) #if !defined(LIGHT_USE_PSSM4) && !defined(LIGHT_USE_PSSM2)
{ {
highp vec4 splane = shadow_coord; pssm_coord = shadow_coord;
pssm_coord = splane.xyz / splane.w;
} }
#endif #endif
float shadow = sample_shadow(light_directional_shadow, pssm_coord.xy, pssm_coord.z); float shadow = sample_shadow(light_directional_shadow, pssm_coord);
#ifdef LIGHT_USE_PSSM_BLEND #ifdef LIGHT_USE_PSSM_BLEND
if (use_blend) { if (use_blend) {
shadow = mix(shadow, sample_shadow(light_directional_shadow, pssm_coord2.xy, pssm_coord2.z), pssm_blend); shadow = mix(shadow, sample_shadow(light_directional_shadow, pssm_coord2), pssm_blend);
} }
#endif #endif
light_att *= shadow; light_att *= shadow;
} }
} }
#endif //use vertex lighting
#endif //use shadow #endif //use shadow
#endif #endif

View File

@ -35,3 +35,14 @@ highp vec4 texel2DFetch(highp sampler2D tex, ivec2 size, ivec2 coord) {
return texture2DLod(tex, vec2(x_coord, y_coord), 0.0); return texture2DLod(tex, vec2(x_coord, y_coord), 0.0);
} }
#ifndef USE_GLES_OVER_GL
highp mat4 transpose(highp mat4 src) {
return mat4(
vec4( src[0].x, src[1].x, src[2].x, src[3].x ),
vec4( src[0].y, src[1].y, src[2].y, src[3].y ),
vec4( src[0].z, src[1].z, src[2].z, src[3].z ),
vec4( src[0].w, src[1].w, src[2].w, src[3].w )
);
}
#endif

View File

@ -1,6 +1,5 @@
def can_build(env, platform): def can_build(env, platform):
#return (env['tools'] and platform not in ["android", "ios"]) return (env['tools'] and platform not in ["android", "ios"])
return False
def configure(env): def configure(env):
pass pass

View File

@ -1,5 +1,6 @@
def can_build(env, platform): def can_build(env, platform):
return (env['tools'] and platform not in ["android", "ios"]) return False #xatlas is buggy
#return (env['tools'] and platform not in ["android", "ios"])
def configure(env): def configure(env):
pass pass

View File

@ -1054,7 +1054,12 @@ public:
if (api == 0) if (api == 0)
r_features->push_back("etc"); r_features->push_back("etc");
else*/ else*/
r_features->push_back("etc2"); String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name");
if (driver == "GLES2") {
r_features->push_back("etc");
} else {
r_features->push_back("etc2");
}
Vector<String> abis = get_enabled_abis(p_preset); Vector<String> abis = get_enabled_abis(p_preset);
for (int i = 0; i < abis.size(); ++i) { for (int i = 0; i < abis.size(); ++i) {