Jitter-free Pixel Art Scaling in MonoGame
Вставка
- Опубліковано 10 лют 2025
- This video is in response to a question asked by a user in the MonoGame subreddit. They were looking for a way to do the Jitter-free pixel art scaling in GoDot from the video by @uheartbeast at • Jitter-free Pixel Art ... but in MonoGame.
So here is the video showing it working in MonoGame while I ramble on about it, as I tend to do.
You can find the source in the GitHub repo at github.com/Ari...
Hey, OP here :) Did everything step by step as you mentioned in the video. It works like a charm, thank you so so much!
That's great! I've been trying to use shaders in Monogame for the first time and this is concisely enough for me to take as reference. Thank you!
Awesome, glad I could be of help. If you have any questions, remember MonoGame has a discord if you use that (discord.gg/monogame) or you can always ask on the community forums (community.monogame.net)
I tried to add this shader to my project, but found I already use a BasicEffect for projection and view matrix. Can I somehow add two different effects?
When using the SpriteBatch, you can only apply a single effect to a batched call.
If you want to apply both the BasicEffect and this effect you have a couple of options.
1. You could render to a RenderTarget2D in one batch using the BasicEffect, then render the RenderTarget2D to the backbuffer using the effect from this video
or
2. You can create a new effect that combines the BasicEffect and the code from this effect. You can find the BasicEffect in the MonoGame GitHub repo. Doing this, you would need to make use of applying multiple passes in the shader, one to go through the passes for the original BasicEffect part and a final pass for the jitter free shader part.
Of the two, the first one is probably the simplest to implement. There may be other ways of achieving this, but these are the only two I can think of off the top of my head at the moment.
@@aristurtledev Thanks for answer!!
I noticed you don't use PointClamp when using the shader? Does the shader replace the need for point clamping?
Sorry, I forgot to include this in the video.
In the original video that this was translated from, they mention in Godot that you have to turn filtering off. In MonoGame, this is essentially the same as not using SamplerState.PointClamp and the shader acts as a replacement. If you use this in combination with SamplerState.PointClamp, then the result will not work.
@@aristurtledev Cool thanks!
Very cool! Funny enough I was thinking these days about using this system (I made a port of this shader for Unity) in MonoGame!
Can this be used for every texture using a RenderTarget2D?
It can be used for any Texture2D that you apply effects to. RenderTarget2D inherits from Texture2D, so yea, you can apply it to that as well.