#Marching Squares Shader Line Artifacts

1 messages · Page 1 of 1 (latest)

iron lynx
#

I'm implementing the marching squares algorithm in HLSL. I get these odd artifacts that I can't seem to get rid of. I'm happy to share the code, though it's a bit large.

It's not related to sampling the texture, so it's got to be with how I calculate the grid cells.
I've tried adding a bit of bias so each cell only deals with its own top and left border but still getting the artifacts.

#

I have this debug mode that tells me which cell is in which case of the algorithm, and you can see the artifacts there too.

tight plover
#

Looks like the artifacts you get when there's a jump in the UV coordinates when using the regular texture sampling function - as that calculates the mipmap to sample from based on the difference between the UVs across those pixels (aka partial screenspace derivatives, like when using ddx/ddy functions)

Disabling mipmaps on the texture would help confirm. And if that does fix it that's a potential solution if you don't need mipmaps.

#

Though if the result can be seen from afar, you might want to instead swap the sample function out for the "Grad" version, allowing you specify the derivatives, to still take advantage of mipmaps.
Assuming srp macros, SAMPLE_TEXTURE2D_GRAD(Texture, sampler_Texture, UV, ddx(DerivativeUV), ddy(DerivativeUV));, where DerivativeUV are continuous coordinates without jumps, like the original TEXCOORD0 input.