[Release] Misc. emulators with depth buffer access

  • Boulotaur2024
  • Topic Author
More
4 years 10 months ago - 4 years 8 months ago #1 by Boulotaur2024 [Release] Misc. emulators with depth buffer access was created by Boulotaur2024


Soul Calibur with Marty McFly's Ground Truth AO implementation running in Redream... Now imagine DOA boobs...

This is an attempt at making *every* OpenGL emulator outputting 3D compatible with depth buffer related effects (SSAO, DOF...) in Reshade.
It is focused on OpenGL, as most emulators use that backend (I realize my work could become obsolete really fast once emu devs move to Vulkan but that's another story).
Right now all my code is stored in a separate repository (see my signature) but I fully intend to make a pull request to master at some point.
You'll find instructions below for every supported emulator.

32 bits (compatible with Pcsx2, glideN64) mega.nz/#!vcsiDI6A!AkGWkVRQkJEelOYa7quAOI1cOxHfU-HuDBcS1CnVrTI
64 bits (compatible with Redream, Ppsspp, Dolphin...) mega.nz/#!zUch0ABA!fnOJcjZrjH52LEKpIximPoWMm46QA7e7gBDSwMVdTMw


Redream : brillant Dreamcast emu (imho). Yes it is payware but I think it *has* a future and everything feels smooth about it

Instructions :
  • Install latest Redream
  • Install Reshade as you would normally do
  • Download and replace your existing Reshade opengl32.dll at the root of your Redream directory with the 64 bits dll provided above
  • Run the emulator once to make sure Reshade is working at all and close it
  • Make sure to grab Marty qUINT shaders
  • Run Redream - press "Home" key to toggle Reshade UI and select "redream" in the "Hacks for custom apps" dropdownlist (Opengl tab)
  • In ReShade.ini, create or replace the line starting with PreprocessorDefinitions by this line :
PreprocessorDefinitions=RESHADE_DEPTH_LINEARIZATION_FAR_PLANE=1000.0,RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN=1,RESHADE_DEPTH_INPUT_IS_REVERSED=1,RESHADE_DEPTH_INPUT_IS_LOGARITHMIC=1

Issues :
  • Do not ALT + ENTER too much if you have AMD card, the runtime gets lost in the mix...
  • It (the depth buffer texture) doesn't adapt to different aspect ratios so for now you have to keep the aspect ratio to "stretched"
Last edit: 4 years 8 months ago by Boulotaur2024.
The following user(s) said Thank You: Wicked Sick, Pondural, Nerd, acknowledge, Uncle Crassius, Ryukou36, Nerrel, PureEvilWindom, Siggs

Please Log in or Create an account to join the conversation.

  • Boulotaur2024
  • Topic Author
More
4 years 10 months ago - 4 years 8 months ago #2 by Boulotaur2024 Replied by Boulotaur2024 on topic [Release] Redream with depth buffer access


Pcsx2 : Compatibility is okayish, some games refuse to show depth (ask the devs, nothing I can do to help).
Be prepared for some tweaking. Please read carefully the instructions over here :
reshade.me/forum/general-discussion/5391...-depth-buffer-access




PPSSPP : The same dll (64 bits) also works nicely with PPSSPP :
  • Run the 64 bits executable PPSSPPWindows64.exe
  • Use the OpenGL Renderer
  • Run ppsspp - press "Home" key to toggle Reshade UI and select "ppsspp" in the "Hacks for custom apps" dropdownlist (Opengl tab)



Citra : Citra is also somewhat working. For 8x native resolution enter in Reshade.ini :

[OPENGL]
AppWidth=3200
ForceMainDepthBuffer=0
IsUpscaled=1
AppHeight=1920
AppMode=1
AppName=none
AltDetection=1
What's funny is that the depth buffer is flipped/rotated at 90 degrees.
If you are interested in getting Reshade working with Citra, ask the devs if they can add an extra texture with the rotated depth buffer.
I had a quick look at their source code and they have a function named "DrawSingleScreenRotated" that would do the job

EDIT : A feature request has been opened (thanx otherman) but I don't think this is going to happen... and he explained in a clear manner why. Which I can understand.


Cemu : Cemu work already with default Reshade but only if you fullscreen to native monitor res (ie. 1080p)
With this mod you can upscale to any res.
Run Cemu - press "Home" key to toggle Reshade UI and select "cemu" in the "Hacks for custom apps" dropdownlist (Opengl tab)
Last edit: 4 years 8 months ago by Boulotaur2024.
The following user(s) said Thank You: acknowledge

Please Log in or Create an account to join the conversation.

  • Nerrel
More
4 years 9 months ago #3 by Nerrel Replied by Nerrel on topic [Release] Redream with depth buffer access
I don't want to derail your thread, but I've been trying to get depth effects working with GlideN64 for over a year and wanted to ask if you have any advice based on your experience with these emulators. ReShade gets depth information from the wrong buffer and ends up misaligned by a small amount:


It also applies one frame too soon, which the developer of GlideN64 says is due to the incorrect buffer being chosen "N64 games allocate at least two color buffers for double-buffering. One buffer is being rendered, other is displayed." It's basically choosing the newly rendered buffer instead of the one that displays a few vertical interrupts later. It needs to use the depth buffer instead.

I'm not sure if an OpenGL mod for buffer selection (like what Thalixte did for D3D) would work or if it's possible to do something like what you've done and use a custom ReShade version that gets depth data from the correct location. The developer of GlideN64 wants to help, he just doesn't know what needs to be done on his end to make ReShade work.

If you could share any speculation or advice I'd appreciate it!

Please Log in or Create an account to join the conversation.

  • Boulotaur2024
  • Topic Author
More
4 years 9 months ago - 4 years 8 months ago #4 by Boulotaur2024 Replied by Boulotaur2024 on topic [Release] Redream with depth buffer access
Nerrel, happy to see you.

But no, unfortunately I have no idea what's going on about that "1 frame too soon" issue (might be 3 more frames btw due to triple buffering...).
I don't have much time these days (wedding and [strike]rat race[/strike] work).

In case you haven't seen I talked about the same problem in PCSX2 here
And here is another example of it in PPSSPP :


  • The fact the depth buffer is misaligned if the camera is static is *not* an issue. It probably needs resizing somewhere.
  • The fact the depth buffer is misaligned once in motion (see above) is a big problem, for which I have no solution so far.
  • Both D3D11 and OpenGL are affected by that issue
  • Both AMD and NVIDIA
I guess "double buffering" (or triple buffering) is a good hint that could explain a few things...
I tried various things but no luck so far.
I have to go to work now -_-

Crosire, any idea ?


ethereal_intellect wrote: Nice :) does it work with ps1 emulators or retroarch like in this old video? I don't really have the time to test right now but i'll get to it eventually :P


Beetle-PSX does not really have z-buffer. What you see on video is an "experimental Z-buffer" that never got released.
And the best I got right now debugging through it is this (Resident Evil, lol) .
So no, no depth buffer for Ps1, until iCatButler decides to implement one (that was never present in the original hardware, btw)

EDIT : same for ePSXe 2.05. I just tried this morning and it produces "flat" depth around the vertices. No usable depth because the ps1 did not have a z-buffer.
Last edit: 4 years 8 months ago by Boulotaur2024.

Please Log in or Create an account to join the conversation.

  • ethereal_intellect
More
4 years 9 months ago - 4 years 9 months ago #5 by ethereal_intellect Replied by ethereal_intellect on topic [Release] Misc. emulators with depth buffer access
Nice :) does it work with ps1 emulators or retroarch like in this old video? I don't really have the time to test right now but i'll get to it eventually :P
Last edit: 4 years 9 months ago by ethereal_intellect.

Please Log in or Create an account to join the conversation.

  • crosire
More
4 years 9 months ago #6 by crosire Replied by crosire on topic [Release] Misc. emulators with depth buffer access
There is an explanation for this here: github.com/gonetz/GLideN64/issues/1548#issuecomment-505553877 . Different emulator, but reason is likely the same.

TLDR: Emulator does manual render-ahead of frames because emulator reasons (normal GL apps/games don't generaly do that). ReShade selects last depth buffer that was drawn into (because emulator currently renders a frame it will show later in the future), but emulator displays an older frame. Result: ReShade gets color data from old frame (the one being displayed), but depth data from future frame (the one being rendered ahead of time).
The following user(s) said Thank You: Nerrel

Please Log in or Create an account to join the conversation.

  • Silveraga
More
4 years 9 months ago #7 by Silveraga Replied by Silveraga on topic [Release] Redream with depth buffer access
How can i use CEMU with depth buffer access? I don't seem to be able to get it ... Thanks !

Please Log in or Create an account to join the conversation.

  • Nerrel
More
4 years 9 months ago #8 by Nerrel Replied by Nerrel on topic [Release] Misc. emulators with depth buffer access
Thanks for the help with GlideN64 on Github, Boulotaur2024 and Crosire. Will a modified version of ReShade always be required to take advantage of the depth information GlideN64 is now providing? Or could the default releases be made compatible in the future? I'm not entirely sure how much Boulotaur2024 had to alter on the ReShade side to get GlideN64 to function.

Please Log in or Create an account to join the conversation.

  • crosire
More
4 years 9 months ago #9 by crosire Replied by crosire on topic [Release] Misc. emulators with depth buffer access
It's pretty simple, so I'll add a setting for it when I have the time.
The following user(s) said Thank You: acknowledge, Nerrel

Please Log in or Create an account to join the conversation.

  • Nerrel
More
4 years 9 months ago #10 by Nerrel Replied by Nerrel on topic [Release] Misc. emulators with depth buffer access
Thank you, the only problem with the current ReShade dll is that the RT shader won't function if it's active when a game is run; the screen will be black at startup and if the effect is disabled and re-enabled during gameplay I get something like the image below. The game visuals freeze on the frame that was displayed when RT was turned out, but the RT shading and lighting are still in motion. You can see the shading for Link running to the right near the actual Link's head:


It works as long as the effect is disabled at startup, then only turned on after ReShade has loaded. On the other hand, MXAO seems to work even if it's enabled at startup, there are no issues there.

Please Log in or Create an account to join the conversation.

  • Boulotaur2024
  • Topic Author
More
4 years 9 months ago - 4 years 8 months ago #11 by Boulotaur2024 Replied by Boulotaur2024 on topic [Release] Misc. emulators with depth buffer access

Nerrel wrote: ...

We solved that one remaining issue (refer to the GitHub thread above).
There's a little bit more involved than reading from FBO 0.
Again, refer to the github thread, everything is explained (binary and code changes included).
Last edit: 4 years 8 months ago by Boulotaur2024.
The following user(s) said Thank You: Nerd, acknowledge

Please Log in or Create an account to join the conversation.

  • Boulotaur2024
  • Topic Author
More
4 years 8 months ago - 4 years 8 months ago #12 by Boulotaur2024 Replied by Boulotaur2024 on topic [Release] Misc. emulators with depth buffer access


Tags : Dolphin, Reshade, SSAO, MXAO, DOF, MartyMcFly's RT shader

Dolphin now is working and I'm really happy about it !
It was a lot of work mostly to get the depth buffer rendering properly aligned with the backbuffer rectangle.
I had to add and handle an extra pass PS_ResizeDepth for that reason.

Instructions :
  • Install latest Dolphin
  • Install Reshade as you would normally do
  • Download and replace your existing Reshade opengl32.dll at the root of your Dolphin directory with the 64 bits DLL in the first post of this thread:
  • In Dolphin, please select OpenGL renderer and activate Immediately present XFB in OpenGL Graphics Configuration -> Hacks to prevent depth buffer flickering (has to be activated per game, I think)
  • Download and replace modified qUINT shaders HERE : I added an extra pass to handle misalignment issues
  • Run Dolphin again and select "dolphin" in the "Hacks for custom apps" dropdownlist - in the Opengl tab in Reshade :
  • In ReShade.ini, create (or replace) the following line :
[GENERAL]
PreprocessorDefinitions=RESHADE_DEPTH_LINEARIZATION_FAR_PLANE=1000.0,RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN=0,RESHADE_DEPTH_INPUT_IS_REVERSED=0,RESHADE_DEPTH_INPUT_IS_LOGARITHMIC=0

Notes for MartyMcFly's RT shader :

As I obviously cannot redistribute MartyMcFly's RT shader. Here is what you have to do to fix alignment issue :
  • (You should have downloaded my modified qUINT shaders - see above)
  • Open qUINT_rt.fx and replace "linear_depth" by "linear_depth_resized" throughout the shader file
  • Add the following new pass :
void PS_ResizeDepth(in VSOUT v, out float4 color : SV_Target0)
{
	color = tex2D(qUINT::sDepthBufferTex, v.uv).x;
}
  • And call it this way, at the end of the shader file (it has to be the first pass)
pass
{
	VertexShader = PostProcessVS;
	PixelShader = PS_ResizeDepth;
	RenderTarget = qUINT::DepthBufferTexResized;
}
Last edit: 4 years 8 months ago by Boulotaur2024.
The following user(s) said Thank You: Wicked Sick, Qsimil, Drakonas, drowhunter

Please Log in or Create an account to join the conversation.

  • Marty McFly
More
4 years 8 months ago - 4 years 8 months ago #13 by Marty McFly Replied by Marty McFly on topic [Release] Misc. emulators with depth buffer access
I can't quite follow what you did with the resizing? You render to a separate texture with no UV scaling, then it's in RG32F format (why?), and then read from it, again unscaled, using the x component only. From my point of view this seems pretty pointless, but you obviously put some thought into it, that's why I'm asking :huh: If I know what's going on, I can make this an official feature :cheer:
Last edit: 4 years 8 months ago by Marty McFly.

Please Log in or Create an account to join the conversation.

  • Boulotaur2024
  • Topic Author
More
4 years 8 months ago - 4 years 8 months ago #14 by Boulotaur2024 Replied by Boulotaur2024 on topic [Release] Misc. emulators with depth buffer access
Pascal, j'improvise du mieux que je peux.
I'm doing whatever I can to make the depth buffer perfectly aligned with the backbuffer dimensions.
Otherwise I'm getting this (with the default mxao) :

That's right, the depth buffer only covers 2/3 of the screen height (sometimes the width too -depending on the game)
So I tried every trick in the book (glBlitFrarmebuffer with modified dimensions works but with a huge loss in quality since it is destructive) and the best way I could come up with perfectly aligned dimensions and good output quality was through shaders -even though I wish I didn't have to mess with shader files- by adding a "PS_ResizeDepth" pass that resize the depth to fill up the whole height and to fix the issue above.
Wait, no. The resizing part is actually done on the CPU side (c++ code), I added some specific code to fix the viewport height at the moment that "PS_ResizeDepth" is processed.

RG32F format ? Yeah, honestly I picked the first texture format that seemed to not have banding too much (RG16F had banding to my untrained eyes)
UV scaling ? Mmmh I'm not as knowledgeable as you, you know your stuff for sure, I don't even know what it means :p

If you have some spare time you might want to help with this.Try the dll with the default mxao shader : you'll observe the same thing I show in the pic above but you may very well come up with a better solution ;)
Last edit: 4 years 8 months ago by Boulotaur2024.

Please Log in or Create an account to join the conversation.

  • Niko of Death
More
4 years 8 months ago #15 by Niko of Death Replied by Niko of Death on topic [Release] Misc. emulators with depth buffer access
Is this still working with the latest PCSX2 build? I'm trying to use it with games that did work on the old DX11 build to no avail on the latest nightly. I have an AMD card if it matters.

Please Log in or Create an account to join the conversation.

  • WicketW
More
4 years 8 months ago #16 by WicketW Replied by WicketW on topic [Release] Misc. emulators with depth buffer access
I don't know if this is new news but reshade works with RPCS3 now in OpenGL. I get a crash when exiting and the game I'm playing glitches out when hooked but I do get depth buffer access. It'd be great if someone would look into what's causing the crashes and if the depth buffer implementation can be improved.

Please Log in or Create an account to join the conversation.

  • Boulotaur2024
  • Topic Author
More
4 years 8 months ago - 4 years 8 months ago #17 by Boulotaur2024 Replied by Boulotaur2024 on topic [Release] Misc. emulators with depth buffer access

Niko of Death wrote: Is this still working with the latest PCSX2 build? I'm trying to use it with games that did work on the old DX11 build to no avail on the latest nightly. I have an AMD card if it matters.

No, I removed every trace of D3D11 code path because it was poorly implemented, it was just meant as a POC.
Stick to OpenGL even if I know you're AMD user (I am one too - I feel your pain)


WicketW wrote: I don't know if this is new news but reshade works with RPCS3 now in OpenGL. I get a crash when exiting and the game I'm playing glitches out when hooked but I do get depth buffer access. It'd be great if someone would look into what's causing the crashes and if the depth buffer implementation can be improved.

Thanks for the heads up, I totally forgot about rpcs3.
Will try tomorrow. I never used it. Not sure my CPU can handle it but we'll see.

EDIT :



Yeah it works, I get a crash too when I exit rpcs3. Not much of a big problem anyways (somehow the hook for glDeleteTextures fails and crashes... I have no idea why...)

The depth buffer doesn't render too well , there's something like a grid pattern... I tried many things but to no avail. It's beta software anyway (though very good)
EDIT : might have something to do with MSAA used internally in some games

You can see I added a few options in the new OpenGL pane that Crosire created last week. It should be easier to configure
Also added a few tooltips to make it even easier. Imgui is sooo cool ;p
Last edit: 4 years 8 months ago by Boulotaur2024.

Please Log in or Create an account to join the conversation.

  • Niko of Death
More
4 years 8 months ago #18 by Niko of Death Replied by Niko of Death on topic [Release] Misc. emulators with depth buffer access

Boulotaur2024 wrote:

Niko of Death wrote: Is this still working with the latest PCSX2 build? I'm trying to use it with games that did work on the old DX11 build to no avail on the latest nightly. I have an AMD card if it matters.

No, I removed every trace of D3D11 code path because it was poorly implemented, it was just meant as a POC.
Stick to OpenGL even if I know you're AMD user (I am one too - I feel your pain)


WicketW wrote: I don't know if this is new news but reshade works with RPCS3 now in OpenGL. I get a crash when exiting and the game I'm playing glitches out when hooked but I do get depth buffer access. It'd be great if someone would look into what's causing the crashes and if the depth buffer implementation can be improved.

Thanks for the heads up, I totally forgot about rpcs3.
Will try tomorrow. I never used it. Not sure my CPU can handle it but we'll see.

EDIT :



Yeah it works, I get a crash too when I exit rpcs3. Not much of a big problem anyways (somehow the hook for glDeleteTextures fails and crashes... I have no idea why...)

The depth buffer doesn't render too well , there's something like a grid pattern... I tried many things but to no avail. It's beta software anyway (though very good)
EDIT : might have something to do with MSAA used internally in some games

You can see I added a few options in the new OpenGL pane that Crosire created last week. It should be easier to configure
Also added a few tooltips to make it even easier. Imgui is sooo cool ;p


This was using OpenGL. Will try with new build in a bit though.

Please Log in or Create an account to join the conversation.

  • otherman
More
4 years 8 months ago - 4 years 8 months ago #19 by otherman Replied by otherman on topic [Release] Redream with depth buffer access

Boulotaur2024 wrote: Citra : Citra is also somewhat working. For 8x native resolution enter :

[EMULATORS]
EMUHeight=1920
EMUMode=1
EMUName=pcsx2
EMUWidth=3200
What's funny is that the depth buffer is flipped/rotated at 90 degrees.
If you are interested in getting Reshade working with Citra, ask the devs if they can add an extra texture with the rotated depth buffer.
I had a quick look at their source code and they have a function named "DrawSingleScreenRotated" that would do the job


I opened a feature request here , please follow it.

Meanwhile, in dolphin shaders not seam to have any effect; suggestions?
Last edit: 4 years 8 months ago by otherman.

Please Log in or Create an account to join the conversation.

  • Drakonas
More
4 years 8 months ago - 4 years 8 months ago #20 by Drakonas Replied by Drakonas on topic [Release] Misc. emulators with depth buffer access
Hi Boulotaur,
I've been trying to get Dolphin to work. I've checked your instructions over like 5 times, and double checked all the code edits in my qUINT_rt.fx shader.
I get these errors when Reshade loads:
C:\Dolphin-I\reshade-shaders\Shaders\qUINT_rt.fx(389, 41): error X3018: invalid subscript 'texcoord'
C:\Dolphin-I\reshade-shaders\Shaders\qUINT_rt.fx(389, 49): error X3000: syntax error: unexpected ')'

I'm aware that GLSL is sometimes particular about abnormal whitespace, so I made sure there are no tabs and just spaces in the file.

I'm not sure what else to do. Any ideas? Has the code been updated to prevent this?

otherman wrote: Meanwhile, in dolphin shaders not seam to have any effect; suggestions?

I had this issue, but I found out I wasn't editing the shader files like the instructions further up in this thread say to do. You have to use the modified qUINT shaders and modify the RT shader with the proposed code edits. But as you can see from above, I can't get that to successfully compiled due to an invalid subscript error.
Last edit: 4 years 8 months ago by Drakonas.

Please Log in or Create an account to join the conversation.

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.