Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Grainy result from warping shader

Discussion in 'Shaders' started by MGijs, Mar 1, 2016.

  1. MGijs

    MGijs

    Joined:
    Oct 29, 2015
    Posts:
    10
    Hello,

    I used to blend and warp my camera using two maps, one blend map and one warp map. This was working without any problems.
    Recently we started using a new method which should warp and blend using only one texture file. I've changed my shader but the result im getting is very grainy.

    The original file is a DDS file and i've converted it into a PNG to get it working with Unity, is this where it goes wrong? Any thoughts?

    Grainy result:


    Warpsample:


    Code (CSharp):
    1. v2f vert(appdata v)
    2.     {
    3.         v2f o;
    4.         o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    5.         o.texcoord = float2(v.texcoord.x, 1 - v.texcoord.y);
    6.         return o;
    7.     }
    8.  
    9.     float4 frag(v2f i) : COLOR
    10.     {
    11.         float4 warpsample = tex2D(_Warp, i.texcoord);
    12.         float4 color = tex2D(_MainTex, warpsample.xy)* pow(warpsample.z, 1.0 / 2.2);
    13.  
    14.         return warpsample;
    15.     }
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    9,268
    What format is the warp texture in Unity? You might try setting it to uncompressed. It also looks like the warp texture itself might be noisy; try blurring it in a graphics program, and some blurs have a threshold if you want to keep hard edges from being blurred.
     
  3. MGijs

    MGijs

    Joined:
    Oct 29, 2015
    Posts:
    10
    The original file is a DDS with a RGBAfloating point for each channel but when I load this into Unity I can't use it (turns black) I tried using a PSD of the file but this only works for 8bit/channel which gives the same result.
     
  4. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Uncompressed will help here, 16bit PNG. You might be better off trying to find the source image that made the DDS file though.

    Also ensure that you've set it to bypass sRGB sampling in it's texture options.

    This isn't the sRGB color ramp (it's just a close approximation).
    Code (csharp):
    1. float4 color = tex2D(_MainTex, warpsample.xy)* pow(warpsample.z, 1.0/2.2);
    If you set it to bypass sRGB, you can remove this.


    I suspect ensuring that the image you're warping has mipmaps will also help with the end look.
     
unityunity