gonetz / GLideN64

A new generation, open-source graphics plugin for N64 emulators.
Other
770 stars 179 forks source link

S2DEX: all issues listed here please! #1898

Closed olivieryuyu closed 5 years ago

olivieryuyu commented 6 years ago

1896

1897

1870

1869

1695

1619

936

1518

315 (is it ucode issue though?)

329

133

theboy181 commented 5 years ago

@gizmo98 Yes it looks really good! Is this a per game hack? this doesn't seem to make Puyo Puyon Party (J) look any better.

Are there other s2dex games that take advantage of the changes in this fork?

theboy181 commented 5 years ago

One other think is the left eye on the right most hamster is missing an entire row of vertical pixels. in NATIVE mode, and in 2x mode and above there are multiple issues still image

gizmo98 commented 5 years ago

@theboy181 This is no per game hack. I read somewhere texture clamp is on if st values are smaller or equal to texture width and texture height. I enable clamp_to_edge if this condition is met.

The eye of the hamster could be a little bit better. I cannot see lines if i use nativeRes=0 with multisampling =0 or 2: ___________64-013

theboy181 commented 5 years ago

I'm not being nasty here, but there are other issues all over this picture. image

I agree its better, but I bet if you counted the pixels in AL plugin and GLideN64 plugin both using 640x480 output resolution you are going to find some lines of resolution are still missing, and that the pixels are not in the same positions.

gizmo98 commented 5 years ago

@theboy181 Yeah. Higher resolutions still look a little bit weird. But there are no seams anymore. NativeRes=1 looks in my opinion good. Have you found any regressions? I think 2D elements and 2D games are most of the time not supposed to be used with higher resolutions. ___________64-019

Could you test another branch? I modified the bilinear filter a little bit to remove outlines around transparent parts of a texture. Don't use 3-Point filtering. I was not smart enough to modify this filter. https://github.com/gonetz/GLideN64/compare/master...gizmo98:bgclamp4?expand=1

Kirby has no white lines around menu icons if NativeRes > 1. kirby64-010

Hamster 64 start screen has no black lines around the text if NativeRes > 1. ___________64-021

Mario Kart 64 trees have no black outlines. mariokart64-010

Puyo Puyo looks better: puyopuyo4-000 puyopuyo4-003 puyopuyo4-005

Starcraft cursor and message boxes look good (not compared with current master but both things were broken last month) starcraft_64-000 starcraft_64-004 starcraft_64-002

gizmo98 commented 5 years ago

If i compare my current branch with master only mario kart character selection screen looks worse if nativeTexRecs is not enabled.

master vs bgclamp4 branch ___________64-027 ___________64-023 ___________64-029 ___________64-026 kirby64-014 kirby64-012 mariokart64-019 mariokart64-011 nativeTexRecs = True mariokart64-018 mariokart64-013 nativeTexRecs = False mariokart64-024 mariokart64-015 puyopuyo4-010 puyopuyo4-008

starcraft_64-005 starcraft_64-002 starcraft_64-013 starcraft_64-004

Jj0YzL5nvJ commented 5 years ago

Good job @gizmo98

'gonetz/GLideN64@4f302cc7773fa79edd540025f7fd593b00bd1f0c' https://0x0.st/sYhh.png

gizmo98/GLideN64@8fa221752e7d86e5b6a029d3d38b3ceff298985a https://0x0.st/sYhF.png

Unfortunately, the Jinjos of Banjo-Kazooie continue immutables u.u

gizmo98/GLideN64@8fa221752e7d86e5b6a029d3d38b3ceff298985a https://0x0.st/sYhC.png

oddMLan commented 5 years ago

@gizmo98. Everything looks good, but the kirby save selection screen looks worse IMO.

CallistoNTG commented 5 years ago

resident_evil_ii-020 There's a thin red line on the right hand side of inventory elements with bgclamp4.

Some other issues. PD pause menu has fractals. perfect_dark-077 Conker vegetation distorted. conker_bfd-015

gizmo98 commented 5 years ago

@gonetz I rewrote bilinear filtering to have color-bleeding. According to this article another approach is premultiplied alpha: http://www.adriancourreges.com/blog/2017/05/09/beware-of-transparent-pixels/ Is it possible to implement this approach as well? Blender equation needs to be modified.

CallistoNTG commented 5 years ago

@gizmo98 Just so you know, every branch after bgclamp4 looks like this for me. body_harvest-005 There's a decent chance you're aware, but there is a slim chance it only happens on certain GPUs or something like that.

gonetz commented 5 years ago

@gizmo98 Very interesting article, thanks! The idea is nice and clean, but I'm not sure that it can be easily adopted to our case. N64 blending equation generally is not that simple, especially for 2Cycles mode.

oddMLan commented 5 years ago

Maybe the color-bleeding bilinear filter can be implemented as an user setting? Next to the "fix black lines" options. Because while it does help in some places it causes issues in others.

Also I stumbled across this article a while ago... not sure if it helps in this situation. Might be worth a try. https://colececil.io/blog/2017/scaling-pixel-art-without-destroying-it/

theboy181 commented 5 years ago

I just saw this and I wonder if it applies to any of the alignment issues in GLideN64

https://www.supermodel3.com/Forum/viewtopic.php?f=7&t=1585

gizmo98 commented 5 years ago

This sounds familiar. The bgclamp commit adds an combination of GL_CLAMP_TO_EDGE and GL_REPEAT for background textures and should work like the supermodel3 fix. ;-)

I also tried to implement texture bleeding like described there. But as you can see above the result is not perfect atm.

theboy181 commented 5 years ago

@gizmo98 Is there anything different going on with Model 3 fixes? the have an in depth link in the forum post I linked too.

gizmo98 commented 5 years ago

It works a little bit different. Supermodel solution should only work if texture format has 1Bit alpha. I can modify my filter for testing.

theboy181 commented 5 years ago

:)

gizmo98 commented 5 years ago

@theboy181 you can try this branchs bilinear filter with supermodel solution: https://github.com/gonetz/GLideN64/compare/master...gizmo98:betteralpha?expand=1

Conker and Perfect Dark seem to look good at first glance. Puyo Puyon Party looks better as well.

oddMLan commented 5 years ago

Current master: imagen

Your build: imagen

Make sure you delete any shader cache to be able to see it.

gizmo98 commented 5 years ago

This looks really weird. :) But it´s not surprising because n64 has texture formats with 4bit and 8bit alpha values which can produce smooth transitions. Supermodel implementation shouldn‘t be as good for n64.

theboy181 commented 5 years ago

@gizmo98 I am unsure if I compiled correctly, Puyo Puyon Party looked really bad to me, can you share screenshots?

theboy181 commented 5 years ago

image conkers shadow looks rather pixelated now.

gizmo98 commented 5 years ago

@theboy181 All does filters are not perfect. I have another one under https://github.com/gonetz/GLideN64/compare/master...gizmo98:filtertest?expand=1. Puyo Puyon Party looks better in highres but perfect dark looks a little bit blocky. Sprite borders look also blocky (is this good or bad?). Don't know if we should add an option so some games can be played better in highres.

gizmo98 commented 5 years ago

@theboy181 here is another one and it looks really interesting (https://github.com/gonetz/GLideN64/compare/master...gizmo98:filtertest2?expand=1).

___________64-038 conker_bfd-008 conker_bfd-013 f-zero_x_climax-011 kirby64-017 mariokart64-029 mariokart64-031 paper_mario-001 perfect_dark-007 puyopuyo4-019 puyopuyo4-020 yoshi_story-017 yoshi_story-022

theboy181 commented 5 years ago

Interesting, or amazing? These look too good to be true. What is the downfall this time?

theboy181 commented 5 years ago

Zooming in on a few there are still some undesired artifacts, but generally text looks loads better!!

gonetz commented 5 years ago

@gizmo98 Stefan, please explain the idea behind these fixes. Results look cool, but calculations look too complex for such simple thing as bilinear filtering.

theboy181 commented 5 years ago

image

Didnt look the same for me ? Why do you think I would get different results?

theboy181 commented 5 years ago

oh oh.. this is why image

theboy181 commented 5 years ago

The largest problem is the 2d textures get molested (filtered possibly) as small pieces then assembled. This makes them look like they were stitched together. image

This needs to be sorted :)

theboy181 commented 5 years ago

image AL on the RIGHT

theboy181 commented 5 years ago

image AL+ linear filtering on the far left.

gonetz commented 5 years ago

It seems that this issues must be renamed to "Fix bilinear filtering". This discussion is not related to S2DEX issues. Anyway, it is important, lets continue.

Jason, the issue with that filtering of that icon is not a bug in Stefan's code. It is my bug. These textures with hieroglyphs are rendered in COPY mode, which does not use texture filtering. That is, these textures must not be filtered at all, as with AL. I fixed wrong use of texture filtering in a44d5a8960 You may also disable mip-mapping to get the same result.

theboy181 commented 5 years ago

point taken.. moving along.

gonetz commented 5 years ago

Ok, I tried to make my own fix and now I see what Stefan's code does. First, I tried the simplest approach suggested in the article mentioned in https://github.com/gonetz/GLideN64/issues/1898#issuecomment-427563738. The idea is simple. Most, if not all N64 textures intended for bilinear filtering have 1 bit of alpha, that is fully transparent or fully opaque. The problem with color outlines appears when texels with zero alpha have some color. Such texels supposed to be invisible and they are invisible in native resolution. In high resolution these texels are fetched by bilinear filtering and they give that color outline. As the article suggest, we can Use Premultiplied Alpha, that is multiply color of fetched texel by its alpha. It will eliminate color for transparent texels. This approach works, color outlines seems to be removed. Then I realized that this method just replaces color outlines by black ones - transparent texels still participate in bilinear filtering equations, but now as black texels. So, we need to get rid of transparent texels. My idea: if any of texels fetched by bilinear filtering shader has zero alpha - do not use filtering at all. That way we will have sharp edges of filtered textures, which should be much better than outlines. This works better indeed: no color or black outlines: gliden64_quest_64_000

However, this method causes "hot pixel" problem: ppl

Some opaque texels near transparent ones left unfiltered, which makes too sharp difference between them and their filtered neighbors.

We can't use transparent texels and can't use unfiltered texel instead. Thus, we need to replace transparent texels in our equations by somewhat correct. Stefan just replaces transparent texel by neighbor opaque one. It is questionable solution, but the result is surprisingly good: ppl2

Comparison with AL (on the right): stage

It does not work well for 3point filter though.

So, in my opinion, the method is working. It need to be fixed for 3point filtering, if possible. All 'if ' statements need to be replaced by 'step' for performance.

gizmo98 commented 5 years ago

Yeah i use neighbor opaque ones color like supermodel is doing it. This is the so called "color bleeding" implementation of supermodel. Supermodel is doing if (neighbor.a > current.a) current.rgb = neighbor.rgb. I use if (neighbor.a > 0.0f && current.a == 0.0f) current.rgb = neighbor.rgb because i do not want to change color of translucent texels. There were still some black dots in Puyo Puyon Party. I use name.a = smoothstep(0.35,1.0,name.a) "after" bilinear filtering to clamp and smooth alpha transition a little bit. This removes black remnants at higher resolutions in Mario Kart and Puyo Puyon Party.

gonetz commented 5 years ago

Btw, smoothstep is OpenGL 4.0 We probably will need to replace it with its exact formula to keep compatibility with older GL versions.

theboy181 commented 5 years ago

this is going to be a decent victory for GLideN64 if you guys can figure this out.

theboy181 commented 5 years ago

image Were the portraits in the picture above ever sorted in one of your builds @gizmo98

gizmo98 commented 5 years ago

@theboy181 No. These texture are point sampled since https://github.com/gonetz/GLideN64/commit/9f936be57e5c411cebe4291fa72bdbb93ad5e48b so a modified bilinear filter will not do anything here. Olivieryuyu mentioned it could be ucode related because LLE and HLE look the same https://github.com/gonetz/GLideN64/pull/1894#issuecomment-418177122.

gizmo98 commented 5 years ago

@gonetz I replaced name.a = smoothstep(0.35,1.0,name.a) with this piece of code:

name.a = max(0.0, name.a - 0.35) / 0.65;
name.a = clamp(0.0, 1.0, name.a*name.a*name.a*(name.a*(name.a*6.0-15.0)+10.0)); 

It works the same. See also http://www.iquilezles.org/www/articles/texture/texture.htm.

gonetz commented 5 years ago

Ok. Actual formula for smoothstep is simpler: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/smoothstep.xhtml

gizmo98 commented 5 years ago

Ok. Smoothstep from gl4 looks the same:

name.a = clamp((name.a - 0.35) / 0.65, 0.0, 1.0 );
name.a = name.a * name.a * ( 3.0 - 2.0 * name.a );          

Iquilezles version is "smootherstep" -> http://sol.gfxile.net/interpolation/

It makes everything a little bit more smooth ;-) snipimage

gizmo98 commented 5 years ago

Sergey do you think this is ready to be used? I could tidy everything and open a PR. Two extra notes about my current code.

gonetz commented 5 years ago

Stefan, it is almost ready:

CallistoNTG commented 5 years ago

Unfortunately, this does cause some pretty notable issues even in games where it provides a benefit. For example, while it fixes the pink outline on some 2D elements in Body Harvest, it causes the map to look really wrong. Master: body_harvest-008 Branch filtertest3: body_harvest-006

gonetz commented 5 years ago

Serious argument, thanks!

gizmo98 commented 5 years ago

@CallistoNTG Good point. I will check body harvest. Please use filtertest2 because the other branch was just a test.

gizmo98 commented 5 years ago

@gonetz I think i know why this is happening. Color bleeding should only be enabled if uAlphaCompareMode = 1. If i discard alpha == 0 texels 3/4 of the body harvest map disappears. http://fgfc.ddns.net/PerfectGold/SetOtherMode_L.htm