Proper depth buffer handling in Citra

  • HenrikoMagnifico
  • Topic Author
More
4 years 5 months ago #1 by HenrikoMagnifico Proper depth buffer handling in Citra was created by HenrikoMagnifico
Hi!

I'm a huge fan of ReShade and would love to be able to use it inside the Citra Nintendo 3DS emulator. At the moment, the depth buffer information sent out by Citra is flipped 90° so most of the ReShade effects don't work properly or at all. Multiple users have contacted the Citra developers but they refuse to implement an option to flip the depth buffer since it's against their moto of "making the emulator as accurate as possible to original hardware". Instead, I put my faith in the developers of ReShade here on ReShade forums. All that's needed would be a toggle in the ReShade menu to "Rotate depth buffer 90°". This feature would really make my day because 3DS games look great in Citra with upscaling but most games really miss some kind of AO or other graphical effects to make them truly enjoyable on the big screen.

Thanks in advance!

Cheers,
Henriko

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

  • Fu-Bama
More
4 years 5 months ago - 4 years 5 months ago #2 by Fu-Bama Replied by Fu-Bama on topic Proper depth buffer handling in Citra
You can add following to the ReShade.fxh, after the preprocessor definitions:
#ifndef RESHADE_DEPTH_INPUT_IS_CITRA
	#define RESHADE_DEPTH_INPUT_IS_CITRA 0
#endif
and this inside the GetLinearizedDepth function, at the beginning:
#if RESHADE_DEPTH_INPUT_IS_CITRA
		float citra_x = texcoord.x;
		texcoord.x = texcoord.y;
		texcoord.y = citra_x;
#endif

...or just grab the whole file:
Warning: Spoiler!


After that, define new preprocessor definition in Reshade UI
RESHADE_DEPTH_INPUT_IS_CITRA 1
Last edit: 4 years 5 months ago by Fu-Bama.
The following user(s) said Thank You: goCHIEFgo

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

  • HenrikoMagnifico
  • Topic Author
More
4 years 5 months ago #3 by HenrikoMagnifico Replied by HenrikoMagnifico on topic Proper depth buffer handling in Citra
You're a life saver! I'll try this out ASAP :)

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

  • goCHIEFgo
More
4 years 5 months ago #4 by goCHIEFgo Replied by goCHIEFgo on topic Proper depth buffer handling in Citra
It sort of worked. But it flipped the wrong direction, from 90° to 180°. And while I can see that change in Displaydepth using global preprocessor definitions, the shaders are stil at the 90° angle. MXAO gives 180° while Quint_MXAO gives me the usual 90°.

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

  • goCHIEFgo
More
4 years 5 months ago #5 by goCHIEFgo Replied by goCHIEFgo on topic Proper depth buffer handling in Citra
So I finally realized I also had to apply this into qUINT_common if I, or anyone else, wants to use this for RTGI or any of Marty's shaders. I also worked out how to get them the right side up, with the following in qUINT_common:

#if RESHADE_DEPTH_INPUT_IS_CITRA
float citra_x = uv.x;
uv.x = uv.y;
uv.y = citra_x;
#endif
#if RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN
uv.x = 1.0 - uv.x;

The shader is still misaligned:

Player character in shader (and the rest) is also stretched by window, and I can make her really small and wide or tall and slim by resizing window:

Here's RTGI's lighting channel for clearer view of how it's misaligned.


Feels like I'm pretty close, but I don't know what more I can do here.
From my very limited understanding, qUINT takes depth position from a different source than the rest (?), where Reshade.fhx has "texcoord.y" qUINT has "uv.y".
Once I apply DEPTH_INPUT_IS_CITRA the shaders are aligned in the right direction, no rotating needed, but is misaligned, shifted to the left, and stretches to the window size.
The "regular" method without applying the above seems to properly size the player character and by that the shader, no stretching by window size, but is also misaligned; shifted to left, as well as turned at a 90° angle. Problem with that is I don't know how to rotate that, only seems you can flip it horizontally or vertically. Maybe someone who actually knows code can rotate it.

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

  • Giodude
More
3 years 8 months ago #6 by Giodude Replied by Giodude on topic Proper depth buffer handling in Citra
Any update on this? Hoping to do the same

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.