Search Unity

Resolved Planar reflection mipmap bias

Discussion in 'Shaders' started by od3098, May 4, 2022.

  1. od3098

    od3098

    Joined:
    Apr 29, 2015
    Posts:
    56
    Hey there.
    I am tryin to use mipmap bias as smoothness value to blur my reflection render texture.
    The problem is when camera moves, the mipmap has some kind of moving antialiases:

    ezgif.com-gif-maker.gif

    I also have tested this with realtime reflection probe on the right cube. Chanding smoothness on standard material does not have this issue.
    My approach to render reflection is to have another camera to render from correct position related to the active camera and do a render to texture and assign the result to shader and modify smoothness in shader as mipmap bias value.
    Any advice you could give would be much appreciated.
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,795
    The only way I have managed to make something like this stable enough, is to manually generate the mips yourself, using some sort of higher quality downscale and blur shader, and then it is stabler than this.
     
    hippocoder likes this.
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    If the reflection camera is orthogonal, you could implement some kind of stable fit, so long as the angle didn't change. But assuming you want to change the rotation often, it will need a better blur, possibly even temporal, though that would introduce some Unreal-like smearing a lot of people don't like (me included hehe).
     
  4. od3098

    od3098

    Joined:
    Apr 29, 2015
    Posts:
    56
    Yes, much better with gaussian blur.
    Now I can use ~10% of screen size instead of using mipmap.
    But need to check in WebGL for performance.
    Thanks guys.
    gaussian bur.gif

    in case anyone needs the GaussianBlur custom function I've used in amplify shader editor:
    Code (CSharp):
    1. // Gaussian blur
    2. vec4 Color = texture2D( _Texture, uv);
    3. float Pi = 6.28318530718;//pi * 2
    4. for (float d = 0.0; d < Pi; d+=Pi/float(Directions))
    5. {
    6.     for (float i = 1.0/float(Quality); i <= 1.0; i+=1.0/float(Quality))
    7.     {
    8.         Color += tex2D( _Texture, uv+vec2(cos(d),sin(d))*radius*i);
    9.     }
    10. }
    11. Color /= float(Quality)*float(Directions)+1.0;
    12. return Color;
     
    bgolus likes this.
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    od3098 likes this.