Odd Graphical Artifacting in flat 3D image? Can you solve this mystery?

Started by
9 comments, last by DapperDave 7 years, 2 months ago

I have a 2D game (C#, XNA) that uses a 3D effect. Below you can see a battle against 3 pigs. These pigs look 2D but they are actually drawn using 3D quads. This is so I can invoke a tilting effect (when they get hit, they tilt back as if they are wooden cut outs).

I have noticed recently that when they are drawn in the neutral position, there is a strange and

inconsistent graphical artifacting bug that occurs sometimes. What’s odd is that, after many experiments, I’ve found that the artifacting is related to WHERE the pigs are drawn on the spritesheet.

In the below image, you can see where each pig comes from within the spritesheet. The first pig has a lot of artifacting around the feet, the second not so much, and the third one is perfect. These pigs are the same in every way except where they are drawn from the spritesheet (which is 1024x1024 png). So far I the artifacting appears more severe when a the sprite rect is close to an edge, but I’m not entirely sure.

Strange huh? I fear that this isn’t something that I will solve and the best solution I have is to just draw these pigs using the regular spritebatch while they are in the neutral position and switch them back to 3D when they are tilting. But I thought it was worth posting here in case any obvious solution jumps out to anyone.

Here is the most relevant code (removed are the many functions that handle the tilt effect).

(I kept the below images in their native resolution, which is very small and difficult to see the artifacting I’m referring to. But I didn’t want to create additional confusion by scaling them for visibility.)

Image is on pasteboard.co

Update: Here I replaced the pigs with checkerboard (black and white 1px with green outline issues) and the issue becomes clearer. You can see a triangle where things are getting stretched here. Again, the third grid is perfect just like the third pig was perfect and the issue somehow relates to where images are placed on the png. And any idea you come up with would have to explain this difference.

checkerboard on pasteboard.co

Advertisement

Wild guess -you don't have borders around individual sprites in the sprite sheet.

-potential energy is easily made kinetic-

Wild guess -you don't have borders around individual sprites in the sprite sheet.

There is at least 1px of padding between the pigs and the rect borders.

Those artifacts look like texel/pixel coordinate inaccuracy.

Possibly something like what this page describes: https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690(v=vs.85).aspx

Don't edit in new things you find out put it in a new post, otherwise people will miss it.

Anyway your checkerboard pattern is indeed strange but I have no clue what it might be... driver/hardware bug? Try it on a different machine with a different video card see if the same thing happens. Hopefully someone else has better insight into this then I do.

-potential energy is easily made kinetic-

What do your texture coords look like for your quads? Are you taking into account the half pixel offset ? If not, you're likely sampling from the exact border between texels in your texture, which could go either way depending on floating point accuracy.

What do your texture coords look like for your quads? Are you taking into account the half pixel offset ? If not, you're likely sampling from the exact border between texels in your texture, which could go either way depending on floating point accuracy.

Yes. That isn't the issue. Coincidentally the person behind the website you linked to there has already looked at my issue. Small world!

Ok, well it looks very much like the type of artifact you would have if you were sampling from texel boundaries.

What happens if you change the sample mode to linear instead of point? Does the artifact mostly go away? If so, then that's a strong clue that the issue has something to do with sampling near texel boundaries, whatever the root cause may be.

@[member='phil_t'],@[member='Nypyren'], Did you guys see the second picture he edited into his original post? The one with the checkerboard pattern? The whole sprite isn't affected, only about a third of one triangle so I figured it wasn't a coordinate problem. Just looking for some second opinions.

-potential energy is easily made kinetic-

@phil_t,@Nypyren, Did you guys see the second picture he edited into his original post? The one with the checkerboard pattern? The whole sprite isn't affected, only about a third of one triangle so I figured it wasn't a coordinate problem. Just looking for some second opinions

Yes, I saw it - in fact that's what made me think it was a texture sampling coordinate issue. Those are interpolated per pixel by some floating point calculations, so it wouldn't be uncommon to have artifacts that affect only a portion of a triangle.

This topic is closed to new replies.

Advertisement