Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shader working in 5.1 but not in 5.3

Discussion in 'Shaders' started by MGijs, Feb 11, 2016.

  1. MGijs

    MGijs

    Joined:
    Oct 29, 2015
    Posts:
    10
    Hello,

    I have a shader that warps the view using a warp map, all of this was working fine in unity 5.1 but i recently updated towards 5.3. Now my shader is no longer working but it gives me no errors any ideas?

    Code (CSharp):
    1. Shader "Hidden/WarpShader" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "" {}
    4.         _Warp ("WarpTexture", 2D) = "white" {}
    5.         _Blend ("BlendTexture", 2D) = "blend" {}
    6.     }
    7.  
    8.     // Shader code pasted into all further CGPROGRAM blocks
    9.     CGINCLUDE
    10.  
    11.     #include "UnityCG.cginc"
    12.  
    13.     sampler2D _MainTex : register(s0);
    14.     sampler2D _Warp : register(s1);
    15.     sampler2D _Blend: register(s2);
    16.  
    17.     float4 frag(float2 iTexCoord : TEXCOORD0) : COLOR
    18.     {
    19.         // todo: remove temp variable
    20.         float2 tempTex;
    21.         tempTex.x = (iTexCoord.x + 1.0f)/2.0f;
    22.         tempTex.y = (iTexCoord.y + 1.0f)/2.0f;
    23.      
    24.         float4 warpsample = tex2D(_Warp, tempTex);
    25.         float4 blendsample = tex2D(_Blend, tempTex);
    26.      
    27.         float2 samplepos;
    28.      
    29.         samplepos.x = warpsample.r + ((warpsample.g) / 256.0f);
    30.         samplepos.y = warpsample.b + ((warpsample.a) / 256.0f);
    31.      
    32.         samplepos.x = samplepos.x * 2.0f - 0.5f;
    33.         samplepos.y = samplepos.y * 2.0f - 0.5f;
    34.      
    35.         float4 color = tex2D(_MainTex, samplepos) * (1.0f - blendsample.a);
    36.         return color;
    37.     }
    38.  
    39.     float4 vert(float4 v:POSITION) : SV_POSITION
    40.     {
    41.         return mul(UNITY_MATRIX_MVP, v);
    42.     }
    43.  
    44.     ENDCG
    45.  
    46. Subshader {
    47. Pass {
    48.       CGPROGRAM
    49.       #pragma vertex vert
    50.       #pragma fragment frag
    51.       ENDCG
    52.   }
    53.  
    54. }
    55.  
    56. Fallback off
    57.  
    58. } // shader
    59.  

    UPDATE:
    Fixed by replacing the vert with the following code:

    Code (CSharp):
    1.  
    2.     v2f vert(appdata v)
    3.     {
    4.         v2f o;
    5.         o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    6.         o.texcoord = float2(v.texcoord.x, 1 - v.texcoord.y);
    7.         return o;
    8.     }
    9.  
     
    Last edited: Feb 11, 2016