# Texture transparency problem with P3D for Doom clone

**URL:** <https://discourse.processing.org/t/texture-transparency-problem-with-p3d-for-doom-clone/641>\
**Category:** Coding Questions\
**Created:** [June 2, 2018, 3:43pm UTC](https://discourse.processing.org/t/texture-transparency-problem-with-p3d-for-doom-clone/641 "2018-06-02T15:43:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luxregina](https://avatars.discourse-cdn.com/v4/letter/l/ecc23a/32.png) [@luxregina](https://discourse.processing.org/u/luxregina)\
**Post date:** [June 2, 2018, 3:43pm UTC](https://discourse.processing.org/t/texture-transparency-problem-with-p3d-for-doom-clone/641/1 "2018-06-02T15:43:29Z")

</div>

Hello everyone!

I’m currently coding a “Doom” clone, using P3D. I’m not using any external library.  
I’m having a weird artifact that happens when I’m using a masked texture. I’ve tried several methods to fix it, but to no avail :(. DISABLE\_DEPTH\_MASK suppresses the artifact, but then my sprite get sorted all wrong.

If anyone can point me in the right direction, I would really appreciate it! I’m so close to having a functional engine!  
(disregard the “doom” face and soldier sprites, of course, they are just temporary assets I’m using…)

 ![question1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/320ee52a1c726ba3b0e2fda1fac7e8b17d9a73fa.png)  
As you can see, eventhough the mask is working (see the feet of the soldier) it’s leaving a huge black (background color) artifact behind.

---

<div class="post-metadata">

**Author:** ![luxregina](https://avatars.discourse-cdn.com/v4/letter/l/ecc23a/32.png) [@luxregina](https://discourse.processing.org/u/luxregina)\
**Post date:** [June 2, 2018, 4:28pm UTC](https://discourse.processing.org/t/texture-transparency-problem-with-p3d-for-doom-clone/641/2 "2018-06-02T16:28:08Z")

</div>

![question2](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/1X/4134fa95dd7bdb307f57f887d469b119b8f513ee.png)  
Weirdly, when I walk around on the flip side, the artifact isn’t as bad (although still present)

---

<div class="post-metadata">

**Author:** ![dan850](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dan850](https://discourse.processing.org/u/dan850)\
**Post date:** [June 4, 2018, 6:00pm UTC](https://discourse.processing.org/t/texture-transparency-problem-with-p3d-for-doom-clone/641/3 "2018-06-04T18:00:57Z")

</div>

Hi @luxregina first off, awesome project! Just from these screenshots alone I can tell you work really hard on this. Your issue seems to be a common problem [https://forum.processing.org/two/discussion/26119/how-to-stop-edge-artifacts-when-using-a-spritesheet-textureatlas](https://forum.processing.org/two/discussion/26119/how-to-stop-edge-artifacts-when-using-a-spritesheet-textureatlas) can you post a sample of your code? particularly where the mask texture is used

---

<div class="post-metadata">

**Author:** ![luxregina](https://avatars.discourse-cdn.com/v4/letter/l/ecc23a/32.png) [@luxregina](https://discourse.processing.org/u/luxregina)\
**Post date:** [June 6, 2018, 8:43pm UTC](https://discourse.processing.org/t/texture-transparency-problem-with-p3d-for-doom-clone/641/4 "2018-06-06T20:43:31Z")

</div>

This is the bit of code that draws my enemy : I’ve also rendered a video with the bug that can be viewed here \> [https://youtu.be/AI0y671POLo](https://youtu.be/AI0y671POLo) - thanks in advance!!! 🙂

```auto
void drawItem(String type) {
    if (type == "pHealth") {
      lightFalloff(0.0001, 0.0001, 0.0001);
      if (lightsOn)pointLight(255, 0, 0, 0, 0, 0);
      drawCube(pHealth);
    }
    if (type == "crate") {
      drawCube(crate);
    }
    if (type == "enemy") {
      lightFalloff(0.0001, 0.0001, 0.0001);
      if (lightsOn)pointLight(180, 255, 0, 0, 0, 0);
      //blendMode(SCREEN);
      //hint(DISABLE_DEPTH_MASK);
      pushMatrix();
      rotateY(x);
      beginShape();
      texture(enemy);      
      //println(x);
      // +Z "front" face
      vertex(-64, -64, 0, 0, 0);
      vertex( 64, -64, 0, 64, 0);
      vertex( 64, 64, 0, 64, 64);
      vertex(-64, 64, 0, 0, 64);
      endShape();
      popMatrix();
      //hint(ENABLE_DEPTH_MASK);
      //blendMode(BLEND);
    }
  }

```

I’m using a PNG that should be transparent - I’ve also tried to mask it by using 🙂

```auto
enemy = loadImage("enemy.png");
  enemy.mask(loadImage("enemy_mask.png"));

```

but to no avail… I should specify I’m using Processing 2.2.1

---

<div class="post-metadata">

**Author:** ![Carmine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/carmine/32/480_2.png) [@Carmine](https://discourse.processing.org/u/Carmine)\
**Post date:** [June 26, 2018, 12:06am UTC](https://discourse.processing.org/t/texture-transparency-problem-with-p3d-for-doom-clone/641/5 "2018-06-26T00:06:55Z")

</div>

@luxregina Are you using Raycasting to render this or using 3D objects?

---

<div class="post-metadata">

**Author:** ![Stephcraft](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stephcraft/32/22024_2.png) [@Stephcraft](https://discourse.processing.org/u/Stephcraft)\
**Post date:** [June 26, 2018, 1:53am UTC](https://discourse.processing.org/t/texture-transparency-problem-with-p3d-for-doom-clone/641/6 "2018-06-26T01:53:08Z")

</div>

Woooow ! Awesome project @luxregina 😃 ! I think I know what is the solution to your problem :

`hint(ENABLE_DEPTH_SORT);`

here is an exemple showing the difference between `ENABLE_DEPTH_SORT` and `DISABLE_DEPTH_SORT`

```auto
 // Depth sorting example by Jakub Valtar 
// https://github.com/JakubValtar

void setup() {
  size(640, 720, P3D);
  colorMode(HSB, 100, 100, 100, 100);
    
  frameRate(60);
}
 
void draw() {    
    //beginRaw(PDF, "output" + frameCount + ".pdf");
    
  if (!mousePressed) {
    hint(ENABLE_DEPTH_SORT);
  } else {
    hint(DISABLE_DEPTH_SORT);
  }
    
  noStroke();
  
  background(0);
 
  translate(width/2, height/2, -300);
  scale(2);
    
  int rot = frameCount;

  rotateZ(radians(90));
  rotateX(radians(rot/60.0f * 10));
  rotateY(radians(rot/60.0f * 30));
 
  blendMode(ADD);
    
  for (int i = 0; i < 100; i++) {
    fill(map(i % 10, 0, 10, 0, 100), 100, 100, 30);
 
    beginShape(TRIANGLES);
    vertex(200, 50, -50);
    vertex(100, 100, 50);
    vertex(100, 0, 20);
    endShape();
 
    rotateY(radians(270.0f/100));
  }
    
  //endRaw();
  
  if (frameCount % 30 == 0) println(frameRate);
}

```

Dont worry about `blendMode(ADD)`, its just to make it look better, you dont need it.

GG again for you project, I really like it 😃 !
