Description
Describe the project you are working on
Retro FPS game.
Describe the problem or limitation you are having in your project
I have some water with transparency, and with the current way that alpha sorting works results in a lot of strange behavior with transparent sprites near water. Even if I have the water broken up into multiple meshes to help with the sorting, often times stuff just draws in the wrong order.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
When sorting alpha meshes, I'd like for there to be an option for a mesh to alpha sort based on a plane normal instead of just a single point. For example, if I have a large water mesh, other meshes that are on the same side of the plane defined by the water mesh normal that the camera is on would be rendered in front of the water, and objects that are on the side of the plane that the camera is not on would be rendered behind the water.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
The sorting is handled in render_forward_clustered.cpp and .h (Or rasterizer_scene_gles3 for compatibility).
struct SortByReverseDepthAndPriority {
_FORCE_INLINE_ bool operator()(const GeometryInstanceSurfaceDataCache *A, const GeometryInstanceSurfaceDataCache *B) const {
return (A->sort.priority == B->sort.priority) ? (A->owner->depth > B->owner->depth) : (A->sort.priority < B->sort.priority);
}
};
This could be modified to something like:
if (A->sort.priority == B->sort.priority) {
if (A->owner->use_plane_sorting) {
if (B->owner->use_plane_sorting) {
return A->owner->depth > B->owner->depth;
}
return A->owner->plane.is_point_over(B->owner->transform.origin) && !camera_is_over; // Should probably cache the center for using AABB center.
if (B->owner->use_plane_sorting) {
return B->owner->plane.is_point_over(A->owner->transform.origin) && camera_is_over;
}
}
return A->sort.priority < B->sort.priority;
Down side is it would make the sort more expensive with all the extra checks. Not sure if there's a more optimal way to do it.
If this enhancement will not be used often, can it be worked around with a few lines of script?
I don't think it would be performant to work around in script, but you could potentially set a different sort priority for stuff below the water, the water, and stuff above the water.
Is there a reason why this should be core and not an add-on in the asset library?
Alpha sorting is a core engine feature.