[SOLVED] Glitches using the pixelshader and drawing textures onto a quad.

I’m using the pixelshader to lookup a texture and the color so it can be drawn onto a quad (multiple quads in this case to make the world dynamic). This works extremely well, however there are a few issues.

The first one consists of oddly placed lines appearing. Now I’m fairly sure that this is because of the texture, so tried using mipmaps (pre-generated by MonoGame Content tool) but it only made it ten times worse. I also tried messing around MipMapBiasLevels but to be honest the mipmaps looked bad and it didn’t solve it either. So is there any way of fixing this without changing the texture?
SOLUTION: I figured out that this is inevitable. Using custom mipmaps solves this.

The second one is what I believe an actual glitch or something. I have no idea what is happening, but it only happens this extreme when looking at it from above.
SOLUTION: After scrolling around the map I also noticed black lines appearing. After a while I figured those originated from the ColorMap (a texture where a specific color is looked up in). The reason why those lines appeared was because of the shader sampling the wrong color (it needs to sample the exact pixel specified) due to floating point inaccuracies, my guess. So now is each color inside the ColorMap 3x3 instead of 1, so inaccurate sampling will still make it sample the correct color, and so far I haven’t seen any abnormalities.

EDIT: after a while I wanted to check what difference it made in performance when using GraphicsDevice.DrawPrimitives (with index and vertex buffers) versus GraphicsDevice.DrawUserPrimitives (which sends the data to the GPU everytime). I’m not sure why I went with the Index and Vertexbuffer approach considering the “chunks” are simply 1 quad with 128x128 tiles drawn onto them, but the performance was roughly 2 times worse than DrawUserPrimitives. Even though I used the Dynamic type of it. But still setting the vertex and index buffer for just one quad is probably ridiculous.
However I forgot to tell that I switched to DrawUserPrimitives and kind of forgot about it. Coincidentally, the weird glitch below disappeared (or more precise, I couldn’t find it anymore) and I focused on the weird black lines. When I did the benchtesting they came back so apparently the vertex/index buffers are causing them.

Less extreme but still visible. The black lines appear to originate from it and go vertically and horizontally across the screen.

1 Like

I was just typing a response when you edited the post :stuck_out_tongue: Nice to see you resolved the issues! :slight_smile:

Good luck with the game! Is the map procedurally generated?

Thank you very much for showing interest in helping me out.

Yes, the gameworld is procedurally generated using SimplexNoise. I’m using both elevation and moisture to determine the type of tile. Right now you can clearly distinguish the biomes (eg jungle is lightgreen), but my idea is to have it gradually transition between them.
This of course should be possible with the help of the ColorMap I was talking about earlier. So instead of a color for each biome I should be able to use the elevation and moisture values to calculate the ColorID for in the ColorMap. Basically the same what the ColorMap in minecraft does for grass and foliage.

1 Like

Sounds cool! Please do keep us in the loop :wink:

1 Like