comfy
comfy copied to clipboard
Controlling the canvas resolution
Right now all draw_* (draw_circle, draw_line, etc.) functions draws at 1:1 resolution, as in each logical pixel maps to a single physical pixel. This is a problem when you want to achieve a consistent pixelated look.
I know this might not be aligned with comfy's philosophy, but maybe allow the user to specify the resolution/DPI of the canvas directly? This way all drawing functions will automatically have a consistent look.
Right now you can control the window resolution with https://github.com/darthdeus/comfy/blob/master/comfy/examples/custom_config.rs, but unfortunately specifying resolution for the render target is not possible.
It would be possible to do this with a custom post processing shader where you effectively "downscale" back to what your canvas resolution would be, which should give "close enough" results. This should be possible soon, as custom user post processing is a bit buggy but will be fixed probably next week.
The ability to specify render target resolution (which is what I think you're asking for) is a bit more involved, and I don't know if I can just "solve it" off the top of my head, but I'll look into it after the major problems are fixed (maybe a week later). I don't expect this to be too difficult, but it will affect a few things and will need more testing. I'm definitely not opposed to it, imo pixel perfect games are very much in the target market and comfy should be able to support them.
That being said, I don't think the problem is in draw_... working in world units. Right now you could in theory just set main_camera().zoom = 640 and then do draw_sprite(..., splat(32.0), ...) and get a sprite that's exactly 32 pixels on a 640 pixel wide canvas. This won't solve the "downsampling" issue (e.g. having the render resolution be half of the window resolution), but it should make it easier for you to think in terms of pixels.
All this being said, pixel perfect is a complex topic, it's possible I missed something, please do let me know what works/doesn't. While Comfy's philosophy is to remain simple, that doesn't prevent us from allowing more custom behavior when a user desires it. This is also somewhat related to https://github.com/darthdeus/comfy/issues/18.
Thanks, I'm glad to hear that it's in the roadmap. I'm not really looking for a pixel-perfect solution right now (haven't tested how well it performs on that aspect), but pixel-perfect support would definitely be great.
I don't mind a few imperfect pixels here and there for now, but I'm just looking a way to simulate a low resolution canvas scaled up. I think your idea of a downscale filter might work.
But for reference about pixel-perfect struggles, there's this big thread on Godot about it (Godot 4 is currently not capable of performing pixel-perfect scaling): https://github.com/godotengine/godot-proposals/issues/6389. Maybe you might find it useful for implementing it.