Skip to content

Commit e9da614

Browse files
committed
Fixed Bugs & Joypad in Android
================================ -resolved many graphical glitches with multiple lights in GLES2 render -fixes and WIP apk expansion -joystick support for Android by Ariel
1 parent 77a15e2 commit e9da614

File tree

8 files changed

+359
-14
lines changed

8 files changed

+359
-14
lines changed

drivers/gles2/rasterizer_gles2.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4239,9 +4239,10 @@ void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceD
42394239
LightInstance *li=light_instance_owner.get( liptr[i] );
42404240
if (!li || li->last_pass!=scene_pass) //lit by light not in visible scene
42414241
continue;
4242-
uint8_t light_type=li->base->type;
4243-
if (li->base->shadow_enabled)
4242+
uint8_t light_type=li->base->type|0x40; //penalty to ensure directionals always go first
4243+
if (li->base->shadow_enabled) {
42444244
light_type|=0x8;
4245+
}
42454246
uint16_t sort_key =li->sort_key;
42464247

42474248
RenderList::Element *ec;
@@ -4598,7 +4599,7 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
45984599
material_shader.set_uniform(MaterialShaderGLES2::FOG_COLOR_END,Vector3(col_end.r,col_end.g,col_end.b));
45994600
}
46004601

4601-
material_shader.set_uniform(MaterialShaderGLES2::CONST_LIGHT_MULT,p_no_const_light?0.0:1.0);
4602+
46024603
//material_shader.set_uniform(MaterialShaderGLES2::TIME,Math::fmod(last_time,300.0));
46034604
//if uses TIME - draw_next_frame=true
46044605

@@ -5668,7 +5669,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
56685669
case VS::MATERIAL_BLEND_MODE_ADD: {
56695670

56705671
glBlendEquation(GL_FUNC_ADD);
5671-
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
5672+
glBlendFunc(p_alpha_pass?GL_SRC_ALPHA:GL_ONE,GL_ONE);
56725673

56735674
} break;
56745675
case VS::MATERIAL_BLEND_MODE_SUB: {
@@ -5833,7 +5834,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
58335834
}
58345835

58355836
material_shader.set_uniform(MaterialShaderGLES2::NORMAL_MULT, e->mirror?-1.0:1.0);
5836-
5837+
material_shader.set_uniform(MaterialShaderGLES2::CONST_LIGHT_MULT,additive?0.0:1.0);
58375838

58385839

58395840
_render(e->geometry, material, skeleton,e->owner,e->instance->transform);
@@ -6097,6 +6098,9 @@ void RasterizerGLES2::_draw_tex_bg() {
60976098
glDepthMask(GL_TRUE);
60986099
glEnable(GL_DEPTH_TEST);
60996100
glDisable(GL_CULL_FACE);
6101+
glDisable(GL_BLEND);
6102+
glColorMask(1,1,1,1);
6103+
61006104

61016105
RID texture;
61026106

@@ -6132,6 +6136,7 @@ void RasterizerGLES2::_draw_tex_bg() {
61326136

61336137
copy_shader.set_conditional(CopyShaderGLES2::USE_CUSTOM_ALPHA,true);
61346138

6139+
61356140
copy_shader.bind();
61366141

61376142
if (current_env->bg_mode==VS::ENV_BG_TEXTURE || current_env->bg_mode==VS::ENV_BG_TEXTURE_RGBE) {
@@ -6350,6 +6355,7 @@ void RasterizerGLES2::end_scene() {
63506355
_render_list_forward(&opaque_render_list,camera_transform,camera_transform_inverse,camera_projection,false,fragment_lighting);
63516356

63526357
if (draw_tex_background) {
6358+
63536359
//most 3D vendors recommend drawing a texture bg or skybox here,
63546360
//after opaque geometry has been drawn
63556361
//so the zbuffer can get rid of most pixels

drivers/gles2/shaders/material.glsl

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,19 @@ LIGHT_SHADER_CODE
10601060
light+=specular * light_specular * pow( eye_light, specular_exp );
10611061
}
10621062
#endif
1063-
diffuse.rgb = ambient_light *diffuse.rgb + light * attenuation * shadow_attenuation;
1063+
diffuse.rgb = const_light_mult * ambient_light *diffuse.rgb + light * attenuation * shadow_attenuation;
1064+
1065+
#ifdef USE_FOG
1066+
1067+
diffuse.rgb = mix(diffuse.rgb,fog_interp.rgb,fog_interp.a);
1068+
1069+
# if defined(LIGHT_TYPE_OMNI) || defined (LIGHT_TYPE_SPOT)
1070+
diffuse.rgb = mix(mix(vec3(0.0),diffuse.rgb,attenuation),diffuse.rgb,const_light_mult);
1071+
# endif
1072+
1073+
1074+
#endif
1075+
10641076

10651077
}
10661078

@@ -1084,16 +1096,27 @@ LIGHT_SHADER_CODE
10841096

10851097
#ifdef USE_VERTEX_LIGHTING
10861098

1087-
vec3 ambient = ambient_light*diffuse.rgb;
1099+
vec3 ambient = const_light_mult*ambient_light*diffuse.rgb;
10881100
# if defined(LIGHT_TYPE_OMNI) || defined (LIGHT_TYPE_SPOT)
10891101
ambient*=diffuse_interp.a; //attenuation affects ambient too
1102+
10901103
# endif
10911104

10921105
// diffuse.rgb=(diffuse.rgb * diffuse_interp.rgb + specular * specular_interp)*shadow_attenuation + ambient;
10931106
// diffuse.rgb+=emission * const_light_mult;
10941107
diffuse.rgb=(diffuse.rgb * diffuse_interp.rgb + specular * specular_interp)*shadow_attenuation + ambient;
10951108
diffuse.rgb+=emission * const_light_mult;
10961109

1110+
#ifdef USE_FOG
1111+
1112+
diffuse.rgb = mix(diffuse.rgb,fog_interp.rgb,fog_interp.a);
1113+
1114+
# if defined(LIGHT_TYPE_OMNI) || defined (LIGHT_TYPE_SPOT)
1115+
diffuse.rgb = mix(mix(vec3(0.0),diffuse.rgb,diffuse_interp.a),diffuse.rgb,const_light_mult);
1116+
# endif
1117+
1118+
#endif
1119+
10971120
#endif
10981121

10991122

@@ -1120,10 +1143,7 @@ LIGHT_SHADER_CODE
11201143

11211144
#else
11221145

1123-
#ifdef USE_FOG
11241146

1125-
diffuse.rgb = mix(diffuse.rgb,fog_interp.rgb,fog_interp.a);
1126-
#endif
11271147

11281148
#ifdef USE_GLOW
11291149

platform/android/java/src/com/android/godot/Godot.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ private void initializeGodot() {
498498

499499
@Override public void onBackPressed() {
500500

501+
System.out.printf("** BACK REQUEST!\n");
501502
GodotLib.quit();
502503
}
503504

platform/android/java/src/com/android/godot/GodotLib.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class GodotLib {
5252
public static native void touch(int what,int pointer,int howmany, int[] arr);
5353
public static native void accelerometer(float x, float y, float z);
5454
public static native void key(int p_scancode, int p_unicode_char, boolean p_pressed);
55+
public static native void joybutton(int p_device, int p_but, boolean p_pressed);
56+
public static native void joyaxis(int p_device, int p_axis, float p_value);
5557
public static native void focusin();
5658
public static native void focusout();
5759
public static native void audio();

0 commit comments

Comments
 (0)