Jump to content
  • Advertisement
Sign in to follow this  
DapperDave

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

This topic is 691 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Edited by DapperDave

Share this post


Link to post
Share on other sites
Advertisement

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.

Edited by DapperDave

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Edited by phil_t

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

@[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.

Edited by Infinisearch

Share this post


Link to post
Share on other sites
@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.

Edited by phil_t

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!