Welcome, Guest.
Username: Password: Remember me

TOPIC: Proper depth buffer handling in Citra

Proper depth buffer handling in Citra 4 weeks 2 days ago #1

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
The administrator has disabled public write access.

Proper depth buffer handling in Citra 4 weeks 23 hours ago #2

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! [ Click to expand ]


After that, define new preprocessor definition in Reshade UI
RESHADE_DEPTH_INPUT_IS_CITRA 1
Last Edit: 4 weeks 23 hours ago by Fu-Bama.
The administrator has disabled public write access.
The following user(s) said Thank You: goCHIEFgo

Proper depth buffer handling in Citra 4 weeks 7 hours ago #3

You're a life saver! I'll try this out ASAP :)
The administrator has disabled public write access.

Proper depth buffer handling in Citra 2 weeks 5 days ago #4

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°.
The administrator has disabled public write access.

Proper depth buffer handling in Citra 2 weeks 1 day ago #5

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.
The administrator has disabled public write access.