Windows 3D alpha value?

Discussion in 'Legacy GameMaker Community Tech Support' started by Steve Gal, Mar 15, 2019.

  1. Steve Gal

    Steve Gal Member

    Joined:
    Jul 25, 2016
    Posts:
    18
    Hello.

    So I recently wanted to try the d3d functions for a map screen only as the game I am working on has a lot of different layers of mapping. I managed to get very far really quick since what I need is really basic.

    I am using "d3d_draw_floor" just to draw simple flat textures on different height levels, so far so good.
    I even got the draw_set_alpha_test function so they work as intended.

    The issue starts when I wanted to introduce alpha changes depending on what layer of the map you are looking for, only showing the layer you are focusing on as full alpha, and the one below and above at lets say 50% alpha.
    Is this even possible? When I set draw alpha, or image alpha for those objects they just disappear or have no effect.

    Is there any way to alter a textures alpha outside of 0, and 1? any way to make them only semi transparent?
    Thank you in advance.
     
  2. kraifpatrik

    kraifpatrik Member

    Joined:
    Jun 23, 2016
    Posts:
    121
    Hey man! So the reason why this happens is that in 3D you have a thing that is a called a z-buffer. What the z-buffer does is that it stores the distance from the camera to objects that you draw (for each pixel) and when you draw something, the distances are compared to what already is in the z-buffer and based on the z-buffer compare function the pixels are either kept or discarded. This is why objects do not overlap each other incorrectly independently on the order in which you draw them (or you can achieve a different result when messing with the functions etc). So what happens with the partially transparent pixels is that they still write to the z-buffer as if they were fully opaque, so they still do discard stuff that's drawed behind them. So the way to fix this could be (from the top of my head) disabling zwrite and ztest and drawing the layers in the correct order (from the once in the distance to the closests ones). Good luck mate!
     
    TheSnidr likes this.
  3. Steve Gal

    Steve Gal Member

    Joined:
    Jul 25, 2016
    Posts:
    18
    Thanks, that sounds way more work than worth, since I would have to order about 250 different objects on 10 different layers and still have a perspective projection, I think I'm better off using transforms to create fake 2d in 2d instead.
     
  4. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,112
    If your camera's orientation doesn't change, you only need to order your instances once.

    Also keep in mind that only images that are semi-transparent need to be depth sorted. Everything that is either 0 or 100% alpha will be correctly handled by the zbuffer even if it is drawn out of order.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice