Attnam / ivan

Iter Vehemens ad Necem - a continuation of the graphical roguelike by members of http://attnam.com
GNU General Public License v2.0
302 stars 42 forks source link

Pixelated option doesn't work? #428

Open andrewtweber opened 6 years ago

andrewtweber commented 6 years ago

There doesn't seem to be any difference between the pixelated and smooth scaling option.

For both options, when I perform an action, or view my inventory, etc. the background changes to pixelated, but when walking around it appears smooth.

AquariusPower commented 6 years ago

yes, that is a limitation that could be improved. When opening a felist, the background (the dungeon region area) not only becomes pixelated (as dungeon xBRZ gets temporarily disabled to prevent other problems) but also stops animating :( Btw, If it is not implemented in a performant way, it will compromise felist performance.

jakwings commented 6 years ago

xBRZ smooth pictures. I don't know why you would expect pixelated pictures with xBRZ enabled.

jakwings commented 6 years ago

Maybe you want to customize the size of each "pixel"? That option is for scaling quality, not for fun effect. ;-)

AquariusPower commented 6 years ago

the scaling happens in two steps:

there was some complexities during the development, I dont remember well would have to look the code in detail, but the easiest way to solve all the problems fast was to disable xBRZ temporarily, when it is least needed that is during felist, and I kept it like that.

may be now, that the development advanced a lot, if we try to let xBRZ work during felist, may be nothing will look weird? I kept like that because it was working well, but may be that restriction could be disabled, not sure tho :)

andrewtweber commented 6 years ago

Hm, so what is the "pixelated" option supposed to do? If that is meant to disable xBRZ and just use vanilla scaling code, it doesn't do so.

I don't mind it changing to pixelated when necessary for performance reasons. But I was more curious to try the pixelated effect.

AquariusPower commented 6 years ago

ohh... hehe it is about this: https://github.com/Attnam/ivan/issues/357 I understood "pixelated" as "vanilla" and forgot it was an actual option xD despite what you described seems like xBRZ vs vanilla. EDIT: I think also it only works if you select full window scaling 2x or more as it will change how the SDL scaling works, not sure tho.

jakwings commented 6 years ago

Yeah, that option was introduced for #357 . There was no vanilla (or "logical") scaling code before I added that option. By default xBRZ is disabled and nearest-neighbor scaling ("pixelated") is used, so players can enjoy the pixel art — which I consider "vanilla".

I wanted to make xBRZ use linear scaling and remove that option, but this requires restarting the game unless there is a way to dynamically regenerate all textures.

AquariusPower commented 6 years ago

I just tested the smooth option, very nice! I used global scale x2, and all text was smooth. By the way it looks, I could easily call it anti-alias.

make xBRZ use linear scaling

Is there some method from SDL that we could call to stretch x2 using smooth mode?

xBRZ are scalings from x2 to x6.

if there is such method, we could: 1st: "scale less" xBRZ 2nd: scale once smooth x2

ex.: the dungeon scale, if set to x6 could be: 1st: scale xBRZ x3 (maximum auto pixel art, that looks like oil painting, details) 2nd: scale smooth x2 (AA) final result x6

it would ban scales of x3 and x5 tho, unless SDL can smooth using float ratio.

But...

as smooth looks like AA, why not just apply anti-alias to the final xBRZ asked scale and keep the xBRZ asked zoom with max pixel art on the work?

The problem is: is there SDL anti-alias? or some other AA code out there?

EDIT: all the restart required options are just because would make it quite complex code to be dynamically changeable (or that I couldnt just determine an easy way to implement it w/o restarting). A workaround would be to quickly restart the engine like:

it would not take too long, would keep the code simple (as possible) and would be 100% safe (vs crash prone), basically a "icon click and menu" by-pass flow :)

jakwings commented 6 years ago

@AquariusPower "anti-alias" is inaccurate for that SDL function, because the image quality only changes when the scale changes. xBRZ is already one of those algorithms for anti-alias, specially applied to pixel art. So SDL's general scaling can't help much here, it only provides some optimization for different hardwares.

A workaround would be to quickly restart the engine like: ...

We have to check which global variables need updates. Could be lot of work. 😅

AquariusPower commented 6 years ago

"anti-alias" is inaccurate for that SDL function, because the image quality only changes when the scale changes

but, as I remember, AA does this: scale the image ex x2, probably using the smooth mode, and then shrinks it back to fit the original resolution. And the same number of original pixels get their color smoothed by that. Unless I am wrong.

Anyway, I only found SDL AA as option and not as function were we could pass an image and get it modified.

There may probably have some lib out there that does that, and it will improve xBRZ smoothness I think :)

Could be lot of work

there is one option that is worth it tho... The dungeon scale could be another user command called Zoom may be +/- keys. When we increase the perception, in dungeons we can see farer, and if the current zoom is too big it is quite annoying to keep pressing look mode to see if that diamond golem is near or not while you use the whistle near a landmine just to find out it will almost not damage him :>

jakwings commented 6 years ago

but, as I remember, AA does this: scale the image ex x2, probably using the smooth mode, and then shrinks it back to fit the original resolution. And the same number of original pixels get their color smoothed by that. Unless I am wrong.

Oh, right. That's basically how high-dpi adaptation works. Sample code:

void render2x(SDL_Renderer* renderer, SDL_Texture* texture, int x, int y)
{
    int w = 0, h = 0;
    SDL_QueryTexture(texture, NULL, NULL, &w, &h);

    SDL_Rect dst_rect = {x, y, w/2, h/2};  // area for scaling high resolution texture
    SDL_RenderCopy(renderer, texture, NULL, &dst_rect);
    SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
    SDL_RenderDrawRect(renderer, &dst_rect);
}

There might be other ways to achieve the same thing but I'm not a SDL2 master. :P

AquariusPower commented 6 years ago

@atheros any tip? :)

AquariusPower commented 6 years ago

@iology

this https://github.com/Attnam/ivan/pull/434 lets it "apply" xBRZ + smooth scaling (in a sense),

but AA after xBRZ would still be good in case ppl prefer the small text (as that PR is intended for window scale >= 2 what provides big text.

Btw, SDL smooth makes the text feel a bit "out of focus" to me, not sure if it bothers anyone else tho, but I prefer it than pixelated.

So may be better smooth scaling may exist, not sure tho, and not sure it would be as fast as it is now, otherwise it could be a perf problem on itself...

jakwings commented 6 years ago

Btw, SDL smooth makes the text feel a bit "out of focus" to me, not sure if it bothers anyone else tho, but I prefer it than pixelated.

That's why I open #357 :-(-; better provide an option to control font size and font style.

AquariusPower commented 6 years ago

If I am not wrong, u r using 4K monitor right? or was someone else? I guess the smooth looks great in 4K tho. I think a way to "sharpen" it after "smooth" would do the trick, but if compromises performance will not work well. The best may be buy a 4K monitor overall, just wait it lower prices or a refurbished/2ndHand one xD