Circular Tilt-Shift

  • Essovius
  • Topic Author
More
4 years 9 months ago #1 by Essovius Circular Tilt-Shift was created by Essovius
Hey,

I'm looking for a circular tilt-shift shader that works just like the TiltShift.fx (or better: I don't know if it's possible but maybe could be mixed with CinematicDOF.fx 's bokeh and blur, but not depth. ) I'm sorry if there's already a shader like that. If not, I hope it's possible to make this shader and someone can make it. I'm sure it will help a lot with the games that don't support Reshade's Depth buffer or for other situations.

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

  • brussell
More
4 years 9 months ago - 4 years 9 months ago #2 by brussell Replied by brussell on topic Circular Tilt-Shift
I'm using something like this in my own shaders. Here are some example shots:




You can try this quicky (untested) modified ReShade.fxh, which allows you to use the RESHADE_USE_FAKE_DEPTH preprocessor definition to replace the real depthbuffer with a fake texture.
(Replace the existing one under the Shaders directory)
#pragma once

#if !defined(__RESHADE__) || __RESHADE__ < 30000
    #error "ReShade 3.0+ is required to use this header file"
#endif

#ifndef RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN
    #define RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN 0
#endif
#ifndef RESHADE_DEPTH_INPUT_IS_REVERSED
    #define RESHADE_DEPTH_INPUT_IS_REVERSED 1
#endif
#ifndef RESHADE_DEPTH_INPUT_IS_LOGARITHMIC
    #define RESHADE_DEPTH_INPUT_IS_LOGARITHMIC 0
#endif
#ifndef RESHADE_DEPTH_LINEARIZATION_FAR_PLANE
    #define RESHADE_DEPTH_LINEARIZATION_FAR_PLANE 1000.0
#endif
#ifndef RESHADE_USE_FAKE_DEPTH
    #define RESHADE_USE_FAKE_DEPTH 0
#endif

namespace ReShade
{
    // Global variables
#if defined(__RESHADE_FXC__)
    float GetAspectRatio() { return BUFFER_WIDTH * BUFFER_RCP_HEIGHT; }
    float2 GetPixelSize() { return float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT); }
    float2 GetScreenSize() { return float2(BUFFER_WIDTH, BUFFER_HEIGHT); }
    #define AspectRatio GetAspectRatio()
    #define PixelSize GetPixelSize()
    #define ScreenSize GetScreenSize()
#else
    static const float AspectRatio = BUFFER_WIDTH * BUFFER_RCP_HEIGHT;
    static const float2 PixelSize = float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT);
    static const float2 ScreenSize = float2(BUFFER_WIDTH, BUFFER_HEIGHT);
#endif

    // Global textures and samplers
    texture BackBufferTex : COLOR;
    texture DepthBufferTex : DEPTH;

    sampler BackBuffer { Texture = BackBufferTex; };
    sampler DepthBuffer { Texture = DepthBufferTex; };

#if RESHADE_USE_FAKE_DEPTH
    texture FakeDofTex < source = "dofmask.png"; > {Width = 1024; Height = 1024; Format = R8; };
    sampler FakeDof { Texture = FakeDofTex; };
#endif

    // Helper functions
    float GetLinearizedDepth(float2 texcoord)
    {
#if RESHADE_USE_FAKE_DEPTH
    float depth = tex2Dlod(FakeDof, float4 (texcoord, 0, 0)).x;
#else
    #if RESHADE_DEPTH_INPUT_IS_UPSIDE_DOWN
        texcoord.y = 1.0 - texcoord.y;
    #endif
        float depth = tex2Dlod(DepthBuffer, float4(texcoord, 0, 0)).x;

    #if RESHADE_DEPTH_INPUT_IS_LOGARITHMIC
        const float C = 0.01;
        depth = (exp(depth * log(C + 1.0)) - 1.0) / C;
    #endif
    #if RESHADE_DEPTH_INPUT_IS_REVERSED
        depth = 1.0 - depth;
    #endif
        const float N = 1.0;
        depth /= RESHADE_DEPTH_LINEARIZATION_FAR_PLANE - depth * (RESHADE_DEPTH_LINEARIZATION_FAR_PLANE - N);
#endif
        return depth;
    }
}

// Vertex shader generating a triangle covering the entire screen
void PostProcessVS(in uint id : SV_VertexID, out float4 position : SV_Position, out float2 texcoord : TEXCOORD)
{
    texcoord.x = (id == 2) ? 2.0 : 0.0;
    texcoord.y = (id == 1) ? 2.0 : 0.0;
    position = float4(texcoord * float2(2.0, -2.0) + float2(-1.0, 1.0), 0.0, 1.0);
}

I've uploaded two example dof masks here: www.sendspace.com/filegroup/bh%2BychLryaXGzn3v5fstUQ
Just put the one you want as dofmask.png into the Textures directory.

This should work with every dof shader which uses the GetLinearizedDepth function.

I myself use a function to calculate this kind of fake dof masks, instead of loading external textures, giving me more flexibility.
Last edit: 4 years 9 months ago by brussell.
The following user(s) said Thank You: Essovius, Sami 1999

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

  • Essovius
  • Topic Author
More
4 years 9 months ago #3 by Essovius Replied by Essovius on topic Circular Tilt-Shift
Hi, thank you for your reply. I've tried it but unfortunately couldn't activate it. I'm getting an error when I try to add RESHADE_USE_FAKE_DEPTH = 1 to preprocessor definition.

'FakeDofTex': local variables cannot be textures or samplers

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

  • brussell
More
4 years 9 months ago #4 by brussell Replied by brussell on topic Circular Tilt-Shift
I've edited my post. Should be correct now.
The following user(s) said Thank You: Essovius

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

  • Essovius
  • Topic Author
More
4 years 9 months ago #5 by Essovius Replied by Essovius on topic Circular Tilt-Shift
Yes, it's currently working fine but this is not exactly what I'm looking for. A shader with more customization options would be more useful. For example radius and position customization. Also circular blur curve is not very effective with a png texture and size could be a problem when using DSR or SRWE . Thanks again for sharing it.

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

  • brussell
More
4 years 9 months ago - 4 years 8 months ago #6 by brussell Replied by brussell on topic Circular Tilt-Shift
Well, I had a little time and wrote it in a way that should fit your needs.
Download it from my repository: github.com/brussell1/Shaders/tree/master/FakeDOF
And here is a demonstration video with displaydepth enabled: i.imgur.com/wZCYN5e.mp4

For now, you can change the blur curve and focus radius via the three parameters a, b, c.
As you can see in the video, the FakeDOF parameters show up under the first effect in the list. Can't fix that.
Last edit: 4 years 8 months ago by brussell.
The following user(s) said Thank You: Essovius

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

  • Essovius
  • Topic Author
More
4 years 9 months ago #7 by Essovius Replied by Essovius on topic Circular Tilt-Shift
Thanks so much! Now it's a lot more better. There is only one thing I couldn't figure out how. When I try it with CinematicDOF.fx it blurs inside the center instead of the outside. I think there could be "Invert" option for this situation. (solved it with inverting black and white colors of dofmask.png in older version)

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

  • brussell
More
4 years 9 months ago #8 by brussell Replied by brussell on topic Circular Tilt-Shift
Yeah, I've just added a parameter for this. :)
The following user(s) said Thank You: Essovius

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.