Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed GLES2 transparency order #28520

Merged
merged 1 commit into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/gles2/rasterizer_scene_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2845,7 +2845,7 @@ void RasterizerSceneGLES2::render_scene(const Transform &p_cam_transform, const
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

render_list.sort_by_depth(true);
render_list.sort_by_reverse_depth_and_priority(true);

_render_render_list(&render_list.elements[render_list.max_elements - render_list.alpha_element_count], render_list.alpha_element_count, cam_transform, p_cam_projection, p_shadow_atlas, env, env_radiance_tex, 0.0, 0.0, reverse_cull, true, false);

Expand Down
26 changes: 25 additions & 1 deletion drivers/gles2/rasterizer_scene_gles2.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ class RasterizerSceneGLES2 : public RasterizerScene {
enum {
MAX_LIGHTS = 255,
MAX_REFLECTION_PROBES = 255,
DEFAULT_MAX_ELEMENTS = 65536
DEFAULT_MAX_ELEMENTS = 65536,
SORT_KEY_PRIORITY_SHIFT = 56
};

int max_elements;
Expand Down Expand Up @@ -598,6 +599,29 @@ class RasterizerSceneGLES2 : public RasterizerScene {
}
}

struct SortByReverseDepthAndPriority {

_FORCE_INLINE_ bool operator()(const Element *A, const Element *B) const {
uint32_t layer_A = uint32_t(A->sort_key >> SORT_KEY_PRIORITY_SHIFT);
uint32_t layer_B = uint32_t(B->sort_key >> SORT_KEY_PRIORITY_SHIFT);
if (layer_A == layer_B) {
return A->instance->depth > B->instance->depth;
} else {
return layer_A < layer_B;
}
}
};

void sort_by_reverse_depth_and_priority(bool p_alpha) { //used for alpha

SortArray<Element *, SortByReverseDepthAndPriority> sorter;
if (p_alpha) {
sorter.sort(&elements[max_elements - alpha_element_count], alpha_element_count);
} else {
sorter.sort(elements, element_count);
}
}

// element adding and stuff

_FORCE_INLINE_ Element *add_element() {
Expand Down