applying filtering to the output buffer
Monkey Targets Forums/Desktop/applying filtering to the output buffer
| ||
I'm trying to find a fast way to apply filtering to the output buffer. Only way I can think of is using ReadPixels for each frame and then applying some kind of smoothing algorithm to the pixels array. But it would be pretty slow I guess. MOJO_IMAGE_FILTERING doesn't work well for me because it causes a lot of artefacts and I'm cutting my sprites from spritesheets. |
| ||
To avoid artefacts you just need to use a suitable power of 2 (depending on how much scaling you are going to do) and align your sprites top and left to such boundaries in your layout process. For MSAA oversampling try the following: #GLFW_WINDOW_SAMPLES=4 |
| ||
Should be noted that is for GLFW3 target only. |
| ||
Soap, Thanks for the links, looks interesting. I hope it will help. skid, I've already have a lot of sprites which are not suitable power of 2, and I want to use scaling to fit user's desktop resolution. #GLFW_WINDOW_SAMPLES doesn't show any results (don't know why) |
| ||
Apologies, I think I am on pre-release version of GLFW3. Also, I am not sure about what you mean by not suitable? I am talking about leaving a gap on the sheet, not scaling the source. For my first game in Monkey I think I ended up using 3 sheets of 2048x2048 with 16 as my alignment factor which allowed me to scale up to 2.5x all sprites without artefacts / mip smears. For sprites bigger than say 128x128 there is little point in adding them to the atlas / sprites sheets as the fill rate / drawing time is always going to be many orders of magnitude bigger than the time saved by reducing texture state changes. The only other issue is if GLFW is not using pre-multiplied alpha blending. If it is not then transparent pixels on your sprite sheet need to still contain RGB of solid neighbours as those channels will still contribute to blending when filtering is taking place causing blackish borders etc along edges. |
| ||
skid, Thanks for explanation! I forgot to tell that I want to allow user to turn on filtering without reloading the game. Just to make an option for switching filtering on air. It seems like MOJO FILTERING can't be switched during the game. |
| ||
My game originally runs in 320x240, 60 fps and I'm using Matrix for scaling. I found out that if I grab not scaled game buffer (Scale 1,1) with ReadPixels (obviously it doesn't work well for 60 fps) and then will write those pixels into an image, it can be scaled to any resolution without artefacts or sprite bleeding. That's exactly what I need. And then I think it will be possible to apply filtering to that image and turn it off in realtime with some Mojo hacking, I found in this thread: http://www.monkey-x.com/Community/posts.php?topic=993 If only Mojo has a fast and easy method to copy render buffer into an image, like in Blitz3D (it has awesome CopyRect command). For now it seems like it's only possible with gles20 module, but it's pretty complicated for me. |
| ||
If only Mojo has a fast and easy method to copy render buffer into an image... Join the club! ;) |