- Home /
Distort shader not showing sprites
Hi Guys,
I'm trying to implement a distort / refraction shader. Everything works fine, expect that it doesn't render my sprites (2d spriterenderers). As seen in this image:  Standing half in and half outside of the shader.
Standing half in and half outside of the shader.
Here is the shader code i'm using:
     Shader "Dvornik/Distort" {
     Properties {
         _Refraction ("Refraction", Range (0.00, 100.0)) = 1.0
         _DistortTex ("Base (RGB)", 2D) = "white" {}
     }
     
     SubShader 
     {    
         Tags { "RenderType"="Transparent" "Queue"="Overlay" }
         LOD 100
         
         GrabPass 
         { 
             
         }
         
     CGPROGRAM
     #pragma exclude_renderers gles
     
     #pragma surface surf NoLighting
     #pragma vertex vert
     
     fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
         {
             fixed4 c;
             c.rgb = s.Albedo; 
             c.a = s.Alpha;
             return c;
         }
     
     sampler2D _GrabTexture : register(s0);
     sampler2D _DistortTex : register(s2);
     float _Refraction;
     
     float4 _GrabTexture_TexelSize;
     
     struct Input {
         float2 uv_DistortTex;
         float3 color;
         float3 worldRefl; 
         float4 screenPos;
         INTERNAL_DATA
     };
     
     void vert (inout appdata_full v, out Input o) {
       UNITY_INITIALIZE_OUTPUT(Input,o);
       o.color = v.color;
     }
     
     void surf (Input IN, inout SurfaceOutput o) 
     {
         float4 distort = tex2D(_DistortTex, IN.uv_DistortTex) * IN.color.r;
         float2 offset = distort.rgb * _Refraction * _GrabTexture_TexelSize.xy;
         
         // project the coordinates to be within 0 and 1
         IN.screenPos.xy = IN.screenPos.xy / IN.screenPos.w;
         
         // check if _GrabTexture texels are inverted on the y-axis
         if (_GrabTexture_TexelSize.y < 0)
             IN.screenPos.y = 1-IN.screenPos.y;
             
         IN.screenPos.xy = offset * IN.screenPos.z + IN.screenPos.xy;
     
         float4 refrColor = tex2D(_GrabTexture, IN.screenPos.xy); //tex2Dproj(_GrabTexture, IN.screenPos);
         o.Alpha = distort.a;
         o.Emission = refrColor.rgb;
        
     }
     ENDCG
     }
     FallBack "Diffuse"
     }
These are the settings for my spriterenderer: 
Really hope someone can help me out!
Thanks in advance, Erik
Answer by Jessespike · Aug 26, 2015 at 08:58 PM
Are your sprites visible if you set the SortingLayer to Default, and Order to 0? Try making your distort object into a SpriteRenderer and adjust it's sorting. Any luck?
Answer by Erik-Sombroek · Aug 28, 2015 at 09:26 PM
@Jessespike, Thanks worked! I added a spriterenderer with my distort material + set its sorting layer to the highest layer possible. Your the best, Erik
I converted @Jessespike's comment to an answer. You might consider marking his as the best answer and changing yours to a comment.
Your answer
 
 
             Follow this Question
Related Questions
Allow 2D sprite to receive light from any direction and show on both sides 0 Answers
My shader doesn't work if I use the same material for multiple objects with the same texture. 1 Answer
Outline set of tiled sprites 0 Answers
Is it possible to have multiple stencil reference values in one shader? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                