• 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 StigC · Oct 17, 2017 at 10:08 AM · 2dshaderhideholesee through

See-through hole/hide away walls in a 2D environment (via shader)?

Hi there,

While searching for an answer to my own question, I ran into this post from 2013. I can't for the love of Jessy get his solution working, nor find similar answers online.

Anyone who can help?

alt text

I've made a material with the shader, then added that material to a spriterenderer in my world. That sprite is supposed to be following the player around, hoping to see through walls when he walks by them. In the case of the picture above, I've placed the sprite in front of a wall, hoping it'd hide the wall away and reveal the floor.

Jessy's Shader:

  Shader "Hole Thing" {
  
  Properties {
      _Center ("Hole Center", Vector) = (.5, .5, 0 , 0)
      _Radius ("Hole Radius", Float) = .25
      _Shape ("Hole Shape", Float) = .25
      _MainTex ("Main Texture", 2D) = ""
  }
  
  SubShader {
      Tags {"Queue" = "Transparent"}
      Blend SrcAlpha OneMinusSrcAlpha
      Pass {
          CGPROGRAM
          struct appdata {
              float4 position : POSITION;
              half2 texCoord : TEXCOORD;
          }; 
          
          struct v2f {
              float4 position_clip : SV_POSITION;
              half2 position_uv : TEXCOORD;
          };
          
          #pragma vertex vert
          uniform half4 _MainTex_ST;
          v2f vert(appdata i) {
              v2f o;
              o.position_clip = mul(UNITY_MATRIX_MVP, i.position);
              o.position_uv = _MainTex_ST.xy * i.texCoord + _MainTex_ST.zw;
              return o;
          }
          
          #pragma fragment frag
          uniform sampler2D _MainTex;
          uniform half2 _Center;
          half _Radius, _Shape;
          fixed4 frag(v2f i) : COLOR {        
              fixed4 fragColor = tex2D(_MainTex, i.position_uv);
              half hole = min(distance(i.position_uv, _Center) / _Radius, 1.);
              fragColor.a *= pow(hole, _Shape);
              return fragColor;
          }
          ENDCG
      }
  }
  
  }

How do you set this kinda thing up correctly? Any help would be appreciated!

Thanks

help.png (265.8 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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

173 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cutting hole from player character to camera through multiple sprites with edge blending 0 Answers

See-through hole via shaders on a 2D plane 2 Answers

2d Shader: How to show camera view on a sprite? 1 Answer

Shader for mesh to project onto sprite? 0 Answers

Ambient Light not working with some objects 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges