How do I prevent 2D sprites from "cutting" through 3D shapes?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Template for a basketball game with a 3D aspect (illusion of 3D)
  • Here's a screenshot example of my issue with the problem circled:

    Based on the 3D documentation and best practices, I believe I have properly setup my layers, but my understanding is that this shouldn't be an issue for 2D objects in the first place. 3D objects with transparency and 3D objects with no transparency need to be in separate layers. I have all 2D effects on a separate layer as well:

    This issue is generally not that big a deal outside of sprites that I scale up and that have large areas of semi-transparency.

    I should also note that I have tried moving the "2d Effects" layer (where the sprites are located) both above and below the opaque/transparent layers to no effect. Some of the 2D sprites use additive blending as well.

  • Here's another example of the same issue, the dagger stuck in the player's billboard sprite is clipping the player with it's transparency:

    This only seems to happen when the sprite is closer to the camera than the object it is clipping through, which makes some sense since Draw Order is set to Camera Distance for these layers.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That’s caused by the drawing order of images with transparency. Ideally polygons are drawn back to front, and construct generally tries to do that. The issue is just sorting the polygons won’t always work. I guess intersecting polygons is a common case that can’t be solved by sorting.

    One possible solution is to use a discard shader on problem sprites. What it does is not draw the transparent parts so stuff behind it is shown even if the order isn’t ideal. The only con is it would be a hard jump from transparent to not which may or may not look good in your project. Someone made one, but I don’t recall where. I think someone also made a dithered semi transparency effect too. Makes me wonder if you could render at double resolution and smooth resize it down to half resolution to get rid of dithering and hard edges.

    Another idea is to somehow control the sorting yourself to see if you can improve things. Fiddle with zorder and zelevation perhaps? In previous tests it wasn’t straightforward to override it. For example getting the walls to be drawn before the transparent stuff would help with the first artifact. For the second drawing the sword after the character would kind of help but I imagine the sword would get the clipping then.

    With the exception of intersecting polygons and cases where there’s a cyclic loop (ex: A in front of B, B in front of C, C in front of A) then doing a topological sort instead of a distance sort can help. But it’s probably not worth the effort here.

    Another idea is to split the objects into smaller ones. Or maybe dynamically split the intersecting polygons. An algorithm like BSP does that and likely would solve it. But again probably not worth the effort here and it would be rather heavy.

    Leveraging the gpu to solve it per pixel is another idea. Intuitively each pixel would be a list of colors and zdepths which would then be sorted. One algorithm called depth peeling supposedly does that semi efficiently. But that sort of thing is lower level than what’s really possible with construct’s renderer.

  • Urgh, was really hoping this wasn't just a quirk of 3D in Construct and that I was missing something.

    I think I'm just going to design around the issue for the time being. I did find what I think is the effect you were mentioning but it states it must be the only effect in use on the object which is a no-go for me.

    The main gameplay issue I had with this was that large attacks at the default Z Elevation would obfuscate too much of the enemies underneath me when it didn't render the transparency. I can solve this by adding a value to the attacks that lets me customize the Z elevation and spawn them lower, so more of the enemy is seen. It might not look great all the time, but it shouldn't impact gameplay much at least.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)