Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Math/BiasShader"
  2. {
  3.     Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.     }
  7.     SubShader
  8.     {
  9.         // No culling or depth
  10.         Cull Off ZWrite Off ZTest Always
  11.  
  12.         Pass
  13.         {
  14.             CGPROGRAM
  15.             #pragma vertex vert
  16.             #pragma fragment frag
  17.             #pragma target 5.0
  18.            
  19.             #include "UnityCG.cginc"
  20.  
  21.             struct appdata
  22.             {
  23.                 float4 vertex : POSITION;
  24.                 float2 uv : TEXCOORD0;
  25.             };
  26.  
  27.             struct v2f
  28.             {
  29.                 float2 uv : TEXCOORD0;
  30.                 float4 vertex : SV_POSITION;
  31.             };
  32.  
  33.             v2f vert (appdata v)
  34.             {
  35.                 v2f o;
  36.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  37.                 o.uv = v.uv;
  38.                 return o;
  39.             }
  40.            
  41.             sampler2D _MainTex;
  42.             float4 _MainTex_TexelSize;
  43.            
  44.             float toFloat(float4 color)
  45.             {
  46.                 int red = color.r * 255.0;
  47.                 int green = color.g * 255.0;
  48.                 int blue = color.b * 255.0;
  49.                 int alpha = color.a * 255.0;
  50.                 int intVal = (red << 0) | (green << 8) | (blue << 16) | (alpha << 24);
  51.                 return asfloat(intVal)  ;
  52.             }
  53.             float4 toColor(float value)
  54.             {
  55.                 int intVal = asint(value);
  56.                 int red = (intVal >> 0) & 0xff;
  57.                 int green = (intVal >> 8) & 0xff;
  58.                 int blue = (intVal >> 16) & 0xff;
  59.                 int alpha = (intVal >> 24) & 0xff;
  60.                 return float4(red / 255.0, green / 255.0, blue / 255.0, alpha / 255.0);
  61.             }
  62.  
  63.             float4 frag(v2f i) : SV_Target
  64.             {
  65.                     return tex2D(_MainTex, i.uv);
  66.                 float2 pixelUV = i.uv*_MainTex_TexelSize.zw;
  67.                 if (pixelUV.x < _MainTex_TexelSize.z - 1)
  68.                 {
  69.                     return tex2D(_MainTex, i.uv);
  70.                 }
  71.                 else
  72.                 {
  73.                     return toColor(1.0);
  74.                 }
  75.             }
  76.             ENDCG
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement