Skip to content

Commit 01632a8

Browse files
committed
Bug Fixes
-=-=-=-=- -Documentation now shows overridable theme values (though this needs to be documented). -Detect when object transform is flipped and flip normals too. -TileMap can specify bounce and friction for collision. -Removed limit of 4 lights per object -Added is_hovered() to buttons.
1 parent 9773169 commit 01632a8

13 files changed

+301
-46
lines changed

drivers/gles2/rasterizer_gles2.cpp

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4083,7 +4083,6 @@ void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceD
40834083
}
40844084

40854085

4086-
LightInstance *lights[RenderList::MAX_LIGHTS];
40874086

40884087
RenderList *render_list=NULL;
40894088

@@ -4197,26 +4196,36 @@ void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceD
41974196
e->light_type=0x7F; //unshaded is zero
41984197
} else {
41994198

4200-
//setup lights
4201-
uint16_t light_count=0;
4202-
uint16_t sort_key[4];
4203-
uint8_t light_types[4];
4199+
bool duplicate=false;
42044200

4205-
int dlc = MIN(directional_light_count,RenderList::MAX_LIGHTS);;
4206-
light_count=dlc;
42074201

4208-
for(int i=0;i<dlc;i++) {
4209-
sort_key[i]=directional_lights[i]->sort_key;
4210-
light_types[i]=VS::LIGHT_DIRECTIONAL;
4202+
for(int i=0;i<directional_light_count;i++) {
4203+
uint16_t sort_key = directional_lights[i]->sort_key;
4204+
uint8_t light_type = VS::LIGHT_DIRECTIONAL;
42114205
if (directional_lights[i]->base->shadow_enabled) {
4212-
light_types[i]|=0x8;
4206+
light_type|=0x8;
42134207
if (directional_lights[i]->base->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS)
4214-
light_types[i]|=0x10;
4208+
light_type|=0x10;
42154209
else if (directional_lights[i]->base->directional_shadow_mode==VS::LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS)
4216-
light_types[i]|=0x30;
4210+
light_type|=0x30;
42174211

42184212
}
42194213

4214+
RenderList::Element *ec;
4215+
if (duplicate) {
4216+
4217+
ec = render_list->add_element();
4218+
memcpy(ec,e,sizeof(RenderList::Element));
4219+
} else {
4220+
4221+
ec=e;
4222+
duplicate=true;
4223+
}
4224+
4225+
ec->light_type=light_type;
4226+
ec->light=sort_key;
4227+
ec->additive_ptr=&e->additive;
4228+
42204229
}
42214230

42224231

@@ -4227,37 +4236,33 @@ void RasterizerGLES2::_add_geometry( const Geometry* p_geometry, const InstanceD
42274236

42284237
for(int i=0;i<ilc;i++) {
42294238

4230-
if (light_count>=RenderList::MAX_LIGHTS)
4231-
break;
4232-
42334239
LightInstance *li=light_instance_owner.get( liptr[i] );
42344240
if (!li || li->last_pass!=scene_pass) //lit by light not in visible scene
42354241
continue;
4236-
light_types[light_count]=li->base->type;
4242+
uint8_t light_type=li->base->type;
42374243
if (li->base->shadow_enabled)
4238-
light_types[light_count]|=0x8;
4239-
sort_key[light_count++]=li->sort_key;
4240-
4241-
4242-
}
4243-
4244-
for(int i=0;i<light_count;i++) {
4244+
light_type|=0x8;
4245+
uint16_t sort_key =li->sort_key;
42454246

42464247
RenderList::Element *ec;
4247-
if (i>0) {
4248+
if (duplicate) {
42484249

42494250
ec = render_list->add_element();
42504251
memcpy(ec,e,sizeof(RenderList::Element));
42514252
} else {
42524253

4254+
duplicate=true;
42534255
ec=e;
42544256
}
42554257

4256-
ec->light_type=light_types[i];
4257-
ec->light=sort_key[i];
4258+
ec->light_type=light_type;
4259+
ec->light=sort_key;
42584260
ec->additive_ptr=&e->additive;
4261+
42594262
}
42604263

4264+
4265+
42614266
}
42624267

42634268
DEBUG_TEST_ERROR("Add Geometry");
@@ -5548,6 +5553,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
55485553

55495554
bool stores_glow = !shadow && (current_env && current_env->fx_enabled[VS::ENV_FX_GLOW]) && !p_alpha_pass;
55505555

5556+
55515557
bool prev_blend=false;
55525558
glDisable(GL_BLEND);
55535559
for (int i=0;i<p_render_list->element_count;i++) {
@@ -5620,6 +5626,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
56205626
additive=true;
56215627
}
56225628

5629+
56235630
if (stores_glow)
56245631
material_shader.set_conditional(MaterialShaderGLES2::USE_GLOW,!additive);
56255632

@@ -5752,7 +5759,8 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
57525759

57535760
if (i==0 || light!=prev_light || rebind) {
57545761
if (e->light!=0xFFFF) {
5755-
_setup_light(e->light&0x3);
5762+
_setup_light(e->light);
5763+
57565764
}
57575765
}
57585766

@@ -5824,6 +5832,9 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans
58245832
material_shader.set_uniform(MaterialShaderGLES2::WORLD_TRANSFORM, e->instance->transform);
58255833
}
58265834

5835+
material_shader.set_uniform(MaterialShaderGLES2::NORMAL_MULT, e->mirror?-1.0:1.0);
5836+
5837+
58275838

58285839
_render(e->geometry, material, skeleton,e->owner,e->instance->transform);
58295840
DEBUG_TEST_ERROR("Rendering");

drivers/gles2/rasterizer_gles2.h

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,22 @@ class RasterizerGLES2 : public Rasterizer {
781781
bool *additive_ptr;
782782
bool additive;
783783
bool mirror;
784-
uint16_t light;
785-
uint8_t light_type;
786-
uint8_t sort_flags;
784+
union {
785+
#ifdef BIG_ENDIAN_ENABLED
786+
struct {
787+
uint8_t sort_flags;
788+
uint8_t light_type;
789+
uint16_t light;
790+
};
791+
#else
792+
struct {
793+
uint16_t light;
794+
uint8_t light_type;
795+
uint8_t sort_flags;
796+
};
797+
#endif
798+
uint32_t sort_key;
799+
};
787800
};
788801

789802

@@ -896,27 +909,22 @@ class RasterizerGLES2 : public Rasterizer {
896909

897910
_FORCE_INLINE_ bool operator()(const Element* A, const Element* B ) const {
898911

899-
if (A->sort_flags == B->sort_flags) {
900-
if (A->light_type == B->light_type) {
901-
if (A->material->shader_cache == B->material->shader_cache) {
902-
if (A->material == B->material) {
903-
904-
return (A->geometry_cmp < B->geometry_cmp);
905-
} else {
912+
if (A->sort_key == B->sort_key) {
913+
if (A->material->shader_cache == B->material->shader_cache) {
914+
if (A->material == B->material) {
906915

907-
return (A->material < B->material);
908-
}
916+
return (A->geometry_cmp < B->geometry_cmp);
909917
} else {
910918

911-
return (A->material->shader_cache < B->material->shader_cache);
919+
return (A->material < B->material);
912920
}
913921
} else {
914922

915-
return A->light_type < B->light_type;
923+
return (A->material->shader_cache < B->material->shader_cache);
916924
}
917925
} else {
918926

919-
return A->sort_flags < B->sort_flags; //one is null and one is not
927+
return A->sort_key < B->sort_key; //one is null and one is not
920928
}
921929
}
922930
};

drivers/gles2/shaders/material.glsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ attribute vec4 color_attrib; // attrib:3
3131
attribute vec2 uv_attrib; // attrib:4
3232
attribute vec2 uv2_attrib; // attrib:5
3333

34+
uniform float normal_mult;
35+
3436
#ifdef USE_SKELETON
3537
attribute vec4 bone_indices; // attrib:6
3638
attribute vec4 bone_weights; // attrib:7
@@ -232,8 +234,10 @@ void main() {
232234
#endif
233235
highp vec4 vertex_in = vertex_attrib; // vec4(vertex_attrib.xyz * data_attrib.x,1.0);
234236
vec3 normal_in = normal_attrib;
237+
normal_in*=normal_mult;
235238
#if defined(ENABLE_TANGENT_INTERP)
236239
vec3 tangent_in = tangent_attrib.xyz;
240+
tangent_in*=normal_mult;
237241
#endif
238242

239243
#ifdef USE_SKELETON

scene/2d/tile_map.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ Map<TileMap::PosKey,TileMap::Quadrant>::Element *TileMap::_create_quadrant(const
316316
VisualServer::get_singleton()->canvas_item_set_transform( q.canvas_item, xform );
317317
q.static_body=Physics2DServer::get_singleton()->body_create(Physics2DServer::BODY_MODE_STATIC);
318318
Physics2DServer::get_singleton()->body_set_layer_mask(q.static_body,collision_layer);
319+
Physics2DServer::get_singleton()->body_set_param(q.static_body,Physics2DServer::BODY_PARAM_FRICTION,friction);
320+
Physics2DServer::get_singleton()->body_set_param(q.static_body,Physics2DServer::BODY_PARAM_BOUNCE,bounce);
321+
319322
if (is_inside_scene()) {
320323
xform = get_global_transform() * xform;
321324
RID space = get_world_2d()->get_space();
@@ -556,6 +559,38 @@ void TileMap::set_collision_layer_mask(uint32_t p_layer) {
556559
}
557560
}
558561

562+
void TileMap::set_collision_friction(float p_friction) {
563+
564+
friction=p_friction;
565+
for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
566+
567+
Quadrant &q=E->get();
568+
Physics2DServer::get_singleton()->body_set_param(q.static_body,Physics2DServer::BODY_PARAM_FRICTION,p_friction);
569+
}
570+
571+
}
572+
573+
float TileMap::get_collision_friction() const{
574+
575+
return friction;
576+
}
577+
578+
void TileMap::set_collision_bounce(float p_bounce){
579+
580+
bounce=p_bounce;
581+
for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
582+
583+
Quadrant &q=E->get();
584+
Physics2DServer::get_singleton()->body_set_param(q.static_body,Physics2DServer::BODY_PARAM_BOUNCE,p_bounce);
585+
}
586+
587+
}
588+
float TileMap::get_collision_bounce() const{
589+
590+
return bounce;
591+
}
592+
593+
559594
uint32_t TileMap::get_collision_layer_mask() const {
560595

561596
return collision_layer;
@@ -584,6 +619,12 @@ void TileMap::_bind_methods() {
584619
ObjectTypeDB::bind_method(_MD("set_collision_layer_mask","mask"),&TileMap::set_collision_layer_mask);
585620
ObjectTypeDB::bind_method(_MD("get_collision_layer_mask"),&TileMap::get_collision_layer_mask);
586621

622+
ObjectTypeDB::bind_method(_MD("set_collision_friction","value"),&TileMap::set_collision_friction);
623+
ObjectTypeDB::bind_method(_MD("get_collision_friction"),&TileMap::get_collision_friction);
624+
625+
ObjectTypeDB::bind_method(_MD("set_collision_bounce","value"),&TileMap::set_collision_bounce);
626+
ObjectTypeDB::bind_method(_MD("get_collision_bounce"),&TileMap::get_collision_bounce);
627+
587628
ObjectTypeDB::bind_method(_MD("set_cell","x","y","tile","flip_x","flip_y"),&TileMap::set_cell,DEFVAL(false),DEFVAL(false));
588629
ObjectTypeDB::bind_method(_MD("get_cell","x","y"),&TileMap::get_cell);
589630
ObjectTypeDB::bind_method(_MD("is_cell_x_flipped","x","y"),&TileMap::is_cell_x_flipped);
@@ -602,7 +643,9 @@ void TileMap::_bind_methods() {
602643
ADD_PROPERTY( PropertyInfo(Variant::INT,"quadrant_size",PROPERTY_HINT_RANGE,"1,128,1"),_SCS("set_quadrant_size"),_SCS("get_quadrant_size"));
603644
ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"tile_set",PROPERTY_HINT_RESOURCE_TYPE,"TileSet"),_SCS("set_tileset"),_SCS("get_tileset"));
604645
ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"tile_data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_tile_data"),_SCS("_get_tile_data"));
605-
ADD_PROPERTY( PropertyInfo(Variant::INT,"collision_layers",PROPERTY_HINT_ALL_FLAGS),_SCS("set_collision_layer_mask"),_SCS("get_collision_layer_mask"));
646+
ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision/friction",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_collision_friction"),_SCS("get_collision_friction"));
647+
ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision/bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_collision_bounce"),_SCS("get_collision_bounce"));
648+
ADD_PROPERTY( PropertyInfo(Variant::INT,"collision/layers",PROPERTY_HINT_ALL_FLAGS),_SCS("set_collision_layer_mask"),_SCS("get_collision_layer_mask"));
606649

607650
ADD_SIGNAL(MethodInfo("settings_changed"));
608651

@@ -620,6 +663,8 @@ TileMap::TileMap() {
620663
center_x=false;
621664
center_y=false;
622665
collision_layer=1;
666+
friction=1;
667+
bounce=0;
623668

624669
fp_adjust=0.01;
625670
fp_adjust=0.01;

scene/2d/tile_map.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class TileMap : public Node2D {
9898
Rect2 rect_cache;
9999
bool rect_cache_dirty;
100100
float fp_adjust;
101+
float friction;
102+
float bounce;
101103
uint32_t collision_layer;
102104

103105

@@ -149,6 +151,12 @@ class TileMap : public Node2D {
149151
void set_collision_layer_mask(uint32_t p_layer);
150152
uint32_t get_collision_layer_mask() const;
151153

154+
void set_collision_friction(float p_friction);
155+
float get_collision_friction() const;
156+
157+
void set_collision_bounce(float p_bounce);
158+
float get_collision_bounce() const;
159+
152160
void clear();
153161

154162
TileMap();

scene/gui/base_button.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ bool BaseButton::is_pressed() const {
276276
return toggle_mode?status.pressed:status.press_attempt;
277277
}
278278

279+
bool BaseButton::is_hovered() const {
280+
281+
return status.hovering;
282+
}
279283

280284
BaseButton::DrawMode BaseButton::get_draw_mode() const {
281285

@@ -337,6 +341,7 @@ void BaseButton::_bind_methods() {
337341
ObjectTypeDB::bind_method(_MD("_input_event"),&BaseButton::_input_event);
338342
ObjectTypeDB::bind_method(_MD("set_pressed","pressed"),&BaseButton::set_pressed);
339343
ObjectTypeDB::bind_method(_MD("is_pressed"),&BaseButton::is_pressed);
344+
ObjectTypeDB::bind_method(_MD("is_hovered"),&BaseButton::is_hovered);
340345
ObjectTypeDB::bind_method(_MD("set_toggle_mode","enabled"),&BaseButton::set_toggle_mode);
341346
ObjectTypeDB::bind_method(_MD("is_toggle_mode"),&BaseButton::is_toggle_mode);
342347
ObjectTypeDB::bind_method(_MD("set_disabled","disabled"),&BaseButton::set_disabled);

scene/gui/base_button.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class BaseButton : public Control {
8383

8484
bool is_pressed() const; ///< return wether button is pressed (toggled in)
8585
bool is_pressing() const; ///< return wether button is pressed (toggled in)
86+
bool is_hovered() const;
87+
8688
void set_pressed(bool p_pressed); ///only works in toggle mode
8789
void set_toggle_mode(bool p_on);
8890
bool is_toggle_mode() const;

scene/gui/control.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ void Control::_window_input_event(InputEvent p_event) {
10021002

10031003
}
10041004

1005-
p_event.mouse_button.global_x = pos.x;
1005+
p_event.mouse_button.global_x = pos.x;
10061006
p_event.mouse_button.global_y = pos.y;
10071007

10081008
pos = window->focus_inv_xform.xform(pos);

scene/main/scene_main_loop.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class SceneMainLoop;
4545

4646
class Node;
4747
class Viewport;
48+
4849
class SceneMainLoop : public MainLoop {
4950

5051
_THREAD_SAFE_CLASS_

0 commit comments

Comments
 (0)