Weird Texture2D Bug?

I have a 960x540 image. It’s a row of black pixels followed by a row of transparent pixels then a row of black pixels followed by a row of transparent pixels etc… Basically, it starts with a row of black pixels and alternates between that and a row of transparent pixels. That’s all there is to it. Anyway, when I draw this image using spriteBatch to a 960x540 RenderTarget 2D at some point the spacing between the rows gets messed up. A pattern is formed and every 40 pixels or so two of the black rows appear next to each other. I’ve recreated the images multiple times and this still happens with every version. I’ve also triple-checked the size of the RenderTarget2D, the size of the image, the size of the draw Rectangle for the image supplied to SpriteBatch etc… I’m sort of at a loss…

you do use point filtering i assume?

I have SamplerState set to PointClamp.

You can try this shader.

You have to load it and use it in spritebatch.begin(… , effect, …); If you need more help i can write it down more accurately

Texture2D tex;

float4 PixelShaderFunction(float4 position : SV_POSITION) : COLOR
 return tex.Load(int3(position.xy, 0));

 pass P0
 PixelShader = compile ps_4_0 PixelShaderFunction();

that said, it is highly highly unusual for spritebatch not to draw the stuff you expect it to draw. I use stuff like you describe all the time.

I appreciate that, dude! I know how to implement shaders though. However, I’m trying to avoid using any in this project. I can’t fathom why this is happening…

Yeah, I’ve never experienced anything like this before either. I just recreated the image from scratch again, loaded it into project, and same result… Thanks for your help.

@mikehaggar so all you do is draw a texture to a same size RenderTarget and then draw that to the backbuffer? Or are there some other steps?

@mikehaggar Could you zip up the sample project and make it available for us to test with?

@Jjagg @KonajuGames

Ok, so I figured some more things out with this… kind of interesting. If I draw the 960x540 striped image (1px rows alternating black and transparent) it displays correctly. If I draw the image with position Vector2.Zero to a 1080p backbuffer and run it with IsFullScreen = true it displays correctly. If I do the same but set IsFullScreen = false, I get the banding issue every 20 or rows. However, if I click and drag the window to a new position then it fixes itself and the issue is gone. So… that seems to be the culprit. I’ve tweaked my other GraphicsDeviceManager settings (GraphicsProfile, SynchronizeWithVerticalRetrace) and they do not seem to be impacted this behavior on my machine. I would love to be able to fix this if anyone has any insight.

You should be able to reproduce this quite easily (assuming it’s not something unique to my hardware). I was just using basic spriteBatch.Draw(texture, position, drawRec, Color.White) calls.

Could be initial viewport dimensions when windowed are not the exact size of the window client area. It does sound like a scaling issue rather than a texture issue.

Yeah, I agree. Is there anything that I can do to avoid this? I also enabled ToggleFullScreen and I get all kinds of issues when toggling between a windowed 960x540 output and full screen. Going to and from full screen moves other applications that I have up (I’m on dual monitors). The image in full screen is also completely ruined. Not only do I get the aforementioned banding, but it looks like the scaling is wrong. It should be a simple 200% scale (I’m on a 1080p monitor), but the pixels are warped and different sizes etc… I am planning a PC release for this title and I definitely can’t release it with these issues. I also don’t think I can leave out a full screen toggle as an option…