Shader sampling rendertexture leaves artifacts

Hi, I’m using Nez and I’m trying to make a distortion shader using textures.

Currently I’m drawing sprites onto a separate rendertexture (to sample in a distortion shader later), using a shader which samples that rendertexture so it can draw textures onto it with an overlay “blend” function (I think it’s impossible to use an actual blend function for what I’m doing).

The problem is that it leaves square artifacts where textures overlap:

This is the HLSL code I’m using:

And this the renderer code I’m using:

Apologies for the bad formatting, and thank you very much if you can help :slight_smile:

Heya,

I don’t see any fault with the code right away. But if two textures overlap the blend mode will also come into play. What is your GraphicsDevice’s BlendState set to? And are you using textures with pre-multiplied alpha or not?

Hi thanks for responding,

I think all the textures are using alpha blend (Nez uses Materials which have BlendStates so I’m not 100% sure about the GraphicsDevice itself), but trying with Additive, AlphaBlend, NonPremultiplied and Opaque blendstates all of them have artifacts.

Also just to add to earlier, this is the other kind of issue it gets when rendering.

Update:

The following lines of code (thanks to here: https://stackoverflow.com/a/9546003) fix the first artifact issue:

1 Like