gonetz / GLideN64

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

Request- option to copy depth buffer to main frame buffer #1548

Closed Nerrel closed 5 years ago

Nerrel commented 7 years ago

Certain shaders and effects require depth buffer access to work. It's possible to make the depth buffer available for enhancement programs like Reshade to use in GlideN64's current 2.0 release by disabling framebuffer emulation, but this is a major downgrade to the emulation quality. Worse still, Gonetz stated (in issue #1496) that the depth buffer will no longer be available in future versions even if fb emulation is disabled due to recent changes to the plugin.

In that same issue Gonetz said it would be possible to fix with a dedicated option, so I wanted to make this its own issue to see if anyone can take it up:

"Currently, color buffer from FBO is copied to main frame buffer and displayed on screen. FBO has depth buffer as well, but it is not copied to main depth buffer, it would be waste of GPU resources. If you need depth buffer for external shaders library, it also can be copied. As I said, it is relatively simple, but I loaded with other tasks and can't take this one atm. May be somebody else will do it. Necessary steps:

add config option to enable depth buffer copy
add support for this option for mupen64plus and zilmar specs.
modify FrameBufferList::renderBuffer() that it will render not only color buffer but depth buffer too."

I'm working on a texture pack and had been intending to include ambient occlusion via Reshade as part of the mod; people have shown a lot of interest in using the effect, so I'd appreciate it if someone could add this option so that it would remain possible to use this enhancement in future GlideN64 versions. It would also be really great to be able to use this effect without having to disable fb emulation. Thanks

Boulotaur2024 commented 5 years ago

Any kind of depth dependant effect : SSAO obviously, depth of field, ssr (sub surface scattering -although very gimmicky)... SBS 3D... SMAA too!

Nerrel commented 5 years ago

The thanks go to you and Gonetz, Boulotaur2024, I didn't do any work!

By the way Gonetz, does the latest WIP release have the same depth modifications that you shared here in that July 1st build?

gonetz commented 5 years ago

does the latest WIP release have the same depth modifications that you shared here in that July 1st build?

No. I'm working on "proper" implementation of depth copy feature. It turns to be tricky. Video interface emulation part is complex by itself, and push depth information through all the pipeline with every possible scenario is not trivial.

gonetz commented 5 years ago

@Boulotaur2024 Is it possible to force Reshade to look for depth information only in the main depth buffer and nowhere else? I need to pass depth information to main depth buffer using triangle drawing, not with glBlitFramebuffer. I implemented it, but result is very unstable. Sometimes it works, sometimes depth image applied upside down, sometimes it is missing at all - and I get all three scenarios with the same plugin's build! I run emulator twice and results are different. I switch between different save states and results are different. I can't understand, is this instability a my bug or is it a result of Reshade's decisions about depth buffer source.

And another issue. I'm trying to run your build of Reshade on a notebook with GeForce 1050 and integrated Intel graphics. GeForce is used by default for 3D applications. Emulators usually work fine with it, but just hang or crash when Reshade is used. I have to run emulators with Reshade on Intel graphics, which works slower but without crash. Is there any way to fix the issue with secondary graphics adapter?

Update: I sorted out the first issue. The second is still troubles me.

gonetz commented 5 years ago

I was too optimistic when I thought that I fixed unstable behavior of GLideN64+Reshade. It seems to be hardware dependent. I made "proper" depth copy implementation. Sources are in https://github.com/gonetz/GLideN64/tree/depth_copy_2 branch. Binaries are here: https://drive.google.com/file/d/1U623nWgD6C-Fi4_qST743Pmh6_JMN1F2/view?usp=sharing It supposed to work with all scenarios. But it works well only on Intel card for me. I still can't test it on GeForce. On my Radeon, mupen64plus works mostly ok, but Project64 version always selects wrong depth source, as if I run Public Release 4.0 I use triangle draw to pass both color and depth. TexrectColorAndDepthCopy shader is used here, see src\Graphics\OpenGLContext\GLSL\glsl_SpecialShadersFactory.cpp Depth is fetched from depth texture: gl_FragDepth = texture2D(uTex1, vTexCoord0).r If I remove this line from the shader, mupen64plus works the same as Project64 It seems that Reshade (I use build from https://reshade.me/forum/general-discussion/5442-release-misc-emulators-with-depth-buffer-access) still don't want to take data from the main depth buffer, if it is not copied here with glBlitFramebuffer.

crosire commented 5 years ago

Need to activate the "Force default depth buffer" checkbox on the OpenGL tab for ReShade to always use the main depth buffer.

Boulotaur2024 commented 5 years ago

Crosire, I was assuming he did check the "Force default depth buffer" already. But maybe not : )

I can confirm it's working fine here (once the above checkbox is checked) with your latest binaries on Geforce GTX660 (ok I only tested Super Mario). EDIT : tested with Majora, Banjoo and many more games, I see no issues at all in Pj64 (on NVIDIA at least)

Capture

SSAO definitly looks sweet. Not gimmicky... I cannot test with Radeon now (I have one but it's not plugged)

About the Geforce Mobile issues, I guess it's a "vanilla" Reshade issue (not 100% sure but...) Timing is not great, I'm leaving tomorrow for 2 weeks in Thailand and I have so many things to prepare :)

Gonetz, you might want to debug Reshade yourself with the appropriate hardware. Pretty sure it's going to crash quick with a OpenGL error 502, pointing at the right line to look at. But you are a veteran coder, why am I even saying that :)

Again, thanks a lot for the work done. Not too many emu devs have complied so far. I love your work. I envy you for being independant worker. And I love n64 too :p

Nerrel commented 5 years ago

I tested out the new depth build with Boulotaur2024's ReShade and it worked for me as well (AMD card). The only issue I had was that depth effects didn't work after switching to fullscreen, but I fixed it by unchecking and then rechecking the "force default depth buffer" setting.

gonetz commented 5 years ago

Thanks for replies! Yes, I somehow managed to use "vanilla" Reshade version, which lacks OpenGL tab. I switched to Boulotaur2024's build, activated the "Force default depth buffer" checkbox and got the same result as Nerrel has with his AMD card. That is I need to recheck that option each time OpenGL context re-created: when I load savestates, change plugin's options in configuration panel or switch to fullscreen.

So, my fix actually works. I prepared new WIP build (#2037) to test. Now depth copy is controlled by corresponding plugin setting. Please test that everything works as expected. If it is so, this task is finally resolved.

One more request to Reshade experts: please give me your config for MXAO. This effect is too subtle when I use it with defaults, so I don't see much use of it.

Nerrel commented 5 years ago

This is the config I use. If it doesn't load, you can at least open it and view the values: https://drive.google.com/open?id=1dYTlJ7ilZ5to43kVY21-lcifQjq-4Jhi

The two important settings are sample radius and AO amount. The radius determines how much of the environment the shading will be applied to (lower settings will only apply to corners, high settings will apply shading to all surfaces). I keep the amount somewhat low so the effect doesn't draw attention to itself.

What you should see with it on is that areas where light would be blocked in real life will be darkened. Here's a brief video of the effect, you can see that the corners, walls behind the plants, and the area under the sofa get shaded in as opposed to the lighting being evenly bright in those areas.

I also included the path tracing shader at the end, which does the same thing but in a much more accurate way. It also does global illumination, so it bounces light from light sources around to all the surfaces it should be hitting. You can really see that at the lotto shop where the lights actually illuminate the room.

https://youtu.be/YtAtzHqLaa8

The effects don't suit every game, but I think they work really well for the N64 Zeldas.

Boulotaur2024 commented 5 years ago

I switched to Boulotaur2024's build, activated the "Force default depth buffer" checkbox and got the same result as Nerrel has with his AMD card. That is I need to recheck that option each time OpenGL context re-created: when I load savestates, change plugin's options in configuration panel or switch to fullscreen.

Weird. I really understand what you mean by losing the config once switching to fullscreen but I cannot reproduce the issue on my NVIDIA GTX 660 neither when switching to fullscreen/windowed nor when loading save states...

(Yes I tried your latest WIP)

AMD issue only ?

I'm out. I fly off tomorrow morning. I won't touch a computer for 3 weeks. Good for my sanity :D See you :p

DonelBueno commented 5 years ago

Do you think path tracing or other kind of ray tracing technique will work with playable performance on a GTX 1070 on Project64?

Nerrel commented 5 years ago

DonelBueno, the path tracing shader can be configured for different quality levels (I think it's the ray amount setting). I get full speed at 1440p on a Vega 56 with a few small drops when the ray amount bar is set halfway full, which is still decent quality. I'm guessing you could easily do 1080p on a 1070 with similar settings.

It's unfortunately still a $20 alpha supporter reward but it's supposed to be dropping to $5 very soon, which will allow more people to test it. It's also fairly unoptimized, so the performance will get much better by the time it gets a public release.

DonelBueno commented 5 years ago

@Nerrel I didn't know it is for supporters only. Well, I guess I will wait for the drop to $5.

gonetz commented 5 years ago

AMD issue only ?

"Force default depth buffer" works ok on GeForce for you and on Intel graphics for me. Nerrel and me have the same issue with it on AMD cards. So yes, it seems to be AMD specific.

oddMLan commented 5 years ago

Curse you AMD, for making sucky OpenGL drivers :/

gonetz commented 5 years ago

This is the config I use.

Thanks!

Curse you AMD, for making sucky OpenGL drivers :/

I have no problems with AMD OpenGL drivers most of the time, but this problem is really annoying.

gonetz commented 5 years ago

Here's a brief video of the effect

Thanks, I see it now. Btw, your channel is really good! I wish I could make such cool videos.

oddMLan commented 5 years ago

I have no problems with AMD OpenGL drivers most of the time, but this problem is really annoying.

It's more common than you think. PCSX2 is incredibly slow with the OpenGL backend on AMD cards due to AMD driver issues. CEMU has the same issue as well. N64 Style Depth doesn't work on the newest AMD drivers (19.xx onwards). It used to work on older versions and they took out support for the extension for no seemingly no reason.

gonetz commented 5 years ago

@Nerrel can we close that task?

Nerrel commented 5 years ago

Yes, thanks again for putting the time into solving this