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…)
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.
6 Likes
Weirdly, when I walk around on the flip side, the artifact isn’t as bad (although still present)
3 Likes
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 can you post a sample of your code? particularly where the mask texture is used
1 Like
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 - thanks in advance!!!
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
enemy = loadImage("enemy.png");
enemy.mask(loadImage("enemy_mask.png"));
but to no avail… I should specify I’m using Processing 2.2.1
1 Like
@luxregina Are you using Raycasting to render this or using 3D objects?
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
// 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 !
1 Like