anyway to fix upside down depth buffer
- Kleio420
- Topic Author
Please Log in or Create an account to join the conversation.
- crosire
Please Log in or Create an account to join the conversation.
- Kleio420
- Topic Author
what file is this located in i would like to try and do it myself before asking if anyone could change it for mecrosire wrote: Yeah, just flip the texture coordinates before sampling from it. Shader thing, not related to ReShade itself .
Please Log in or Create an account to join the conversation.
- SpinelessJelly
Please Log in or Create an account to join the conversation.
- crosire
tex2D(depthtex, float2(texcoord.x, 1.0 - texcoord.y))
Please Log in or Create an account to join the conversation.
- Kleio420
- Topic Author
Please Log in or Create an account to join the conversation.
- SpinelessJelly
...
float3 normals(float2 texcoord) // get normal vector from depthmap
{
float deltax = linearlizeDepth(tex2D(RFX_depthColor, float2((texcoord.x + px), 1.0 - texcoord.y)).x) - linearlizeDepth(tex2D(RFX_depthColor, float2((texcoord.x - px), 1.0 - texcoord.y)).x),
deltay = linearlizeDepth(tex2D(RFX_depthColor, float2(texcoord.x, ((1.0 - texcoord.y) + py))).x) - linearlizeDepth(tex2D(RFX_depthColor, float2(texcoord.x, ((1.0 - texcoord.y) - py))).x);
...
Also Matso DOF seems to work correctly by changing ...\ReShade\Common\Util.h to
...
// Depth buffer access
float depth = tex2D(RFX_depthColor, float2(texcoord.x, 1.0 - texcoord.y)).x;
...
Both effects shine through the weapon and HUD but I guess that's the game's problem, not Reshade's. Still haven't managed to flip AO but the indication looks valid, thanks again Crosire.
Please Log in or Create an account to join the conversation.
- Kleio420
- Topic Author
wow thanks this worked at least for the dof, just being able to see where this is applied is super helpful for getting better at understanding the flow of things ty guys very muchSpinelessJelly wrote: Soooo.... I think it worked? I tried this on Ziggurat (Unity engine, opengl32.dll, reshade 0.18.4). Fixed Cel shader by making ...\ReShade\CustomFX\Cel.h look like this
... float3 normals(float2 texcoord) // get normal vector from depthmap { float deltax = linearlizeDepth(tex2D(RFX_depthColor, float2((texcoord.x + px), 1.0 - texcoord.y)).x) - linearlizeDepth(tex2D(RFX_depthColor, float2((texcoord.x - px), 1.0 - texcoord.y)).x), deltay = linearlizeDepth(tex2D(RFX_depthColor, float2(texcoord.x, ((1.0 - texcoord.y) + py))).x) - linearlizeDepth(tex2D(RFX_depthColor, float2(texcoord.x, ((1.0 - texcoord.y) - py))).x); ...
Also Matso DOF seems to work correctly by changing ...\ReShade\Common\Util.h to... // Depth buffer access float depth = tex2D(RFX_depthColor, float2(texcoord.x, 1.0 - texcoord.y)).x; ...
Both effects shine through the weapon and HUD but I guess that's the game's problem, not Reshade's. Still haven't managed to flip AO but the indication looks valid, thanks again Crosire.
i take it for ssao this is what needs changed
float depth = tex2D(RFX_depthColor, texcoord.xy).x;
from looking at it , looks like the entire ssao.h file needs to be changed to work with this
Please Log in or Create an account to join the conversation.
- SpinelessJelly
Please Log in or Create an account to join the conversation.
- Kleio420
- Topic Author
well from my understanding float depth = (varible, float2(texcoord.xy).x; is how every ssao example ive found on the web uses to get the depth if you look at the rest the same layout is used for specific functions which is why i think it needs either a setting to enable a full on global buffer flip in one line of code or editing the entire file to work with it. Since this seems to be hugely a unity engine issue maybe we can get a fix in a framework release. By no means am i saying im correct in what i just typed as im probably wrong hopefully there is enough interest in this to put a fix for itSpinelessJelly wrote: Yes, I tried changing that line but nothing happened (not true, managed to get some error messages). But maybe I got the syntax wrong, I'm pretty clueless code-wise and logic can only get you that far.
Please Log in or Create an account to join the conversation.
- strelokgunslinger
#if (RFX_DisplayDepth == 1)
NAMESPACE_ENTER(RFX)
void DisplayDepth(in float4 position : SV_Position, in float2 texcoord : TEXCOORD0, out float3 color : SV_Target)
{
color.rgb = tex2D(RFX_depthTexColor,texcoord).rgb;
}
technique Depth_Tech < bool enabled = false; int toggle = RFX_DepthToggleKey;>
{
pass
{
VertexShader = RFX_VS_PostProcess;
PixelShader = DisplayDepth;
}
}
NAMESPACE_LEAVE()
#endif
Where do I input ?
tex2D(depthtex, float2(texcoord.x, 1.0 - texcoord.y))
Please Log in or Create an account to join the conversation.
- crosire
There aren't many lines which look similar . Just repalce it there.strelokgunslinger wrote:
... color.rgb = tex2D(RFX_depthTexColor,texcoord).rgb; ...
Where do I input ?
tex2D(depthtex, float2(texcoord.x, 1.0 - texcoord.y))
Please Log in or Create an account to join the conversation.
- biliskner
crosire wrote:
There aren't many lines which look similar . Just repalce it there.strelokgunslinger wrote:
... color.rgb = tex2D(RFX_depthTexColor,texcoord).rgb; ...
Where do I input ?
tex2D(depthtex, float2(texcoord.x, 1.0 - texcoord.y))
Thanks crosire, this helped me alot with fixing my Unity depth buffer inversion
I have zero programming knowledge so I spent the better part of the last 24hrs reading up about HLSL just so I could change my reshade.fx file to try and add a more permanent fix.
What i found was that changing the texcoord values manually for each shader effect was very time consuming and difficult to find the right line.. so my fix was to try and add a toggle in common.cfg
I then change RFX_PS_StoreDepth directly
float RFX_PS_StoreDepth(in float4 position : SV_Position, in float2 texcoord : TEXCOORD0) : SV_Target
{
float depth = tex2D(RFX_depthColor
//#if RFX_DepthUnity == 1
//, float2(texcoord.x, 1.0 - texcoord.y)
//#else
, texcoord
//#endif
).x;
after a few more hours of headache where i messed up my graphics -_- I realised DisplayDepth uses RFX_depthTexColor which is saved.. but CEL and SMAA use RFX_depthColor which i THINK? is read directly from the buffer
Long story short.. i added a few more lines of code to affect anything using RFX_depthTexColor or RFX_depthColor. I hope this helps someone, please feel free to correct me if my code is messed up.
Code additions/changes follow
To common.cfg under Core, added
#define RFX_DepthUnity 1 //[0:1] //-Set this to 1 if your app uses Unity or has inverted depth.
Reshade.fx ln 38
// Global Textures and Samplers
texture RFX_depthBufferTex : DEPTH;
#if RFX_DepthUnity
texture RFX_fixdepthTex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = R32F; };
#endif
texture RFX_depthTex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = R32F; };
texture RFX_backbufferTex : COLOR;
#if RFX_InitialStorage
texture RFX_originalTex { Width = BUFFER_WIDTH; Height = BUFFER_HEIGHT; Format = RGBA8; };
#else
texture RFX_originalTex : COLOR;
#endif
sampler RFX_originaldepthColor { Texture = RFX_depthBufferTex; };
sampler RFX_depthColor {
#if RFX_DepthUnity
Texture = RFX_fixdepthTex;
#else
Texture = RFX_depthBufferTex;
#endif
};
sampler RFX_depthTexColor { Texture = RFX_depthTex; };
#if RFX_DepthUnity
float RFX_PS_FixDepth(in float4 position : SV_Position, in float2 texcoord : TEXCOORD0) : SV_Target
{
return tex2D(RFX_originaldepthColor, float2(texcoord.x, 1.0 - texcoord.y)).x;
}
#endif
Reshade.fx ln95
#if RFX_InitialStorage || RFX_DepthBufferCalc
technique RFX_Setup_Tech < enabled = true; >
{
#if RFX_DepthUnity
pass FixDepth
{
VertexShader = RFX_VS_PostProcess;
PixelShader = RFX_PS_FixDepth;
RenderTarget = RFX_fixdepthTex;
}
#endif
#if RFX_InitialStorage
pass StoreColor
{
VertexShader = RFX_VS_PostProcess;
PixelShader = RFX_PS_StoreColor;
RenderTarget = RFX_originalTex;
}
#endif
#if RFX_DepthBufferCalc
pass StoreDepth
{
VertexShader = RFX_VS_PostProcess;
PixelShader = RFX_PS_StoreDepth;
RenderTarget = RFX_depthTex;
}
#endif
}
#endif
Please Log in or Create an account to join the conversation.
- crosire
The current handling is a little complicated, too many different textures and samplers to keep track of. That should be simplified in the next versions.
Please Log in or Create an account to join the conversation.
- biliskner
Yeah learning about textures and samplers was a massive headache.. keeping track of them was another heh
Please Log in or Create an account to join the conversation.