Page 1 of 1

Multisample causes model skin wraparound

Posted: Mon Apr 03, 2017 23:43
by Enjay
I'm just putting this here to see if anything can be done about it. If it needs a bug report, I'll do it but I suspect it's just a rounding error or some such that people will just have to be aware of.

With Multisample on the OpenGL preferences at any setting other than "off" some models of a particular type show unwanted artefacts. The attached file should show it.
(319.14 KiB) Downloaded 32 times
Picture of the map:

The model uses planes to make the leaves/branches of a tree. The skin is UV mapped to the model so that the planes use most of the space available. With multisampling on though, it looks like the skin is wrapping around and the bottom edge of the skin (the trunk of the tree) is being mapped to the top of the plane. Hard to explain. Here, have a picture.


As you can see, the top of the frame for the plane is very close to the top of the graphic, but it isn't right at the top (although it is less than a pixel I think) as you can see here.


In some models, I have also noticed a similar effect on the sides (basically the same setup but the trunk graphic is at the side rather than at the bottom of the image). In that case, you get vertical artefacts beyond the branches rather than horizontal ones above the tree.

I noticed this when playing my Burghead mod. You can see the star-shaped artefacts above some of the trees and vertical ones beside the tall pine tree on the right.


It is fixable from the modder's side. If I move the UV mapping around so that there are a couple of pixels between where the mesh is and the edge of the skin graphic, the issue goes away but, clearly, there are models "in the wild" where this issue can manifest. While messing around with a few models by other people and models from other games, I've found quite a few occasions where this crops up. I plan on doing a bug-fix release of Burghead before too long so I've already addressed all the models there.

So, is it something that can be addressed engine-side or is it just something for modders to be aware of?

Re: Multisample causes model skin wraparound

Posted: Tue Apr 04, 2017 1:55
by dpJudas
This is somewhat complicated to explain, but what is happening is that the fragment shader is sampling slightly outside a triangle. With multisampling a fragment shader only runs once for a full pixel, but then the pixel coverage decides which of the samples gets the value outputted by the shader. There is a GLSL keyword called centroid that can reduce this problem. A detailed description of what that keyword changes can be found in this article.

However, this just one way you can get into trouble with a skin that doesn't properly apply margins around edges of faces. Linear filtering reads from a 2x2 block of texels in the texture, which again could leave artifacts. And last there's mipmaps, which are downscaled versions of the texture. If the margin is too low they too will get colors bleeding in from neighbors.

In short: GZDoom could probably do a little more to reduce the chance of this happening, but no method fully removes it unless the skin texture is using appropriately large margins, especially with mipmaps enabled.

Re: Multisample causes model skin wraparound

Posted: Tue Apr 04, 2017 9:44
by Enjay
Thanks for the information. I basically thought that something along those lines was happening but without the full technical explanation/knowledge. My take-away from this is that models should be made with much better margins. I'd sort of been coming to that conclusion anyway and I can see the problems of not doing that even on more usual-styled models. An awful lot of the early Quake II fan-made models suffered horribly from poor margins with their skins/uv mapping.

However, there are quite a few models out there where this is already a problem and if things could be improved from the GZDoom side too then that would be good. I know that with a few of my own models, I had noticed basically the same problem in older versions of GZDoom where I'd put the UV map too close to the edge of the skin. So, I adjusted it to work with GZDoom as it was at the time but now the additional options in GZDoom mean that some of these models weren't adjusted enough to eliminate the problem when the newer options are enabled.

Re: Multisample causes model skin wraparound

Posted: Tue Apr 04, 2017 10:31
by _mental_
I don't want to disappoint you but in game development this case is considered purely an asset issue and not technical (i.e. engine) one.

Re: Multisample causes model skin wraparound

Posted: Tue Apr 04, 2017 23:42
by Enjay
Fair enough. At least I'm properly aware of it now so I can avoid it in any models that I make and know to keep an eye out for it when using resources from other sources.

Thanks for your help. :)

Re: Multisample causes model skin wraparound

Posted: Wed Apr 05, 2017 12:39
by Graf Zahl
Normally a model skin texture should be set to 'clamp to edge' - I am not sure why it doesn't seem to be. Will have to check.