Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Erik-Sombroek · Aug 26, 2015 at 06:15 PM · shaderspriteshadersspriterendererrefraction

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: alt textStanding 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: alt text

Really hope someone can help me out!

Thanks in advance, Erik

sprites-behind-shader.jpg (10.0 kB)
editor-settings.jpg (18.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dave-Carlile · Aug 28, 2015 at 09:27 PM 0
Share

I converted @Jessespike's comment to an answer. You might consider marking his as the best answer and changing yours to a comment.

avatar image Erik-Sombroek · Aug 29, 2015 at 06:05 AM 0
Share

@Dave Carlile, thanks just did.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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

Shader on 3D model not seen over 2D sprites 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges