Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 wedgiebee · Jun 12, 2020 at 06:52 PM · outlinevertex shaderdepth-bufferedge detectionvector graphics

How to make vector displacement shader work with screen space depth-based edge detection image effect?

I'm using Unity's Vector Graphics package and this free Outline asset from the asset store to put outlines around my vector images. I set the shader's "Queue" to "Geometry" and "RenderType" to "Opaque", and I then tweaked the vector shader to do some vertex displacement that makes the vectors look like they're wiggling! Unfortunately, the outline acts as if the vertex displacement isn't happening and draws an outline around what the object would look like if no vertices were being displaced.

alt text

From what I understand, the depth buffer isn't getting properly updated with the displaced vertex positions. I tried writing a custom ShadowCaster pass from stuff I found online, but had no luck getting the outline to change in any way.

Here is my shader code:

 Shader "Unlit/OpaqueJitterVector"
 {
     Properties
     {
         [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
         _Color("Tint", Color) = (1,1,1,1)
         _NoiseTex("Noise Texture", 2D) = "white" {}
         _Intensity("Intensity", Float) = 0.05
         [MaterialToggle] PixelSnap("Pixel snap", Float) = 0
         [HideInInspector] _RendererColor("RendererColor", Color) = (1,1,1,1)
         [HideInInspector] _Flip("Flip", Vector) = (1,1,1,1)
         [PerRendererData] _AlphaTex("External Alpha", 2D) = "white" {}
         [PerRendererData] _EnableExternalAlpha("Enable External Alpha", Float) = 0
     }
 
         SubShader
         {
             Tags
             {
                 "Queue" = "Geometry"
                 "IgnoreProjector" = "True"
                 "RenderType" = "Opaque"
                 "PreviewType" = "Plane"
                 "CanUseSpriteAtlas" = "True"
             }
 
             Cull Off
             Lighting Off
             ZWrite Off
             Blend One OneMinusSrcAlpha
 
             Pass
             {
 
             Tags {"LightMode" = "ForwardBase"}
 
             CGPROGRAM
                 #pragma vertex VectorVert
                 #pragma fragment SpriteFrag
                 #pragma target 2.0
                 #pragma multi_compile_instancing
                 #pragma multi_compile _ PIXELSNAP_ON
                 #pragma multi_compile _ ETC1_EXTERNAL_ALPHA
                 #include "UnitySprites.cginc"
 
                 sampler2D _NoiseTex;
                 float _Intensity;
 
                 v2f VectorVert(appdata_t IN)
                 {
                     v2f OUT;
 
                     UNITY_SETUP_INSTANCE_ID(IN);
                     UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
 
                     OUT.vertex = UnityFlipSprite(IN.vertex, _Flip);
 
                     float interval = 0.15f; // seconds between change
                     float t = floor(_Time.y/interval);
                     t = t % 3; // this is the number of variants
                     t *= 0.1f; // this is necessary because the t's can't all be multiples of 1
                     float4 hi = float4(IN.vertex.x + t, IN.vertex.y + t, 0, 0);
                     half noiseVal = tex2Dlod(_NoiseTex, hi).r;
                     OUT.vertex.x += noiseVal * _Intensity;
 
                     OUT.vertex = UnityObjectToClipPos(OUT.vertex);
                     OUT.texcoord = IN.texcoord;
 
                     #ifdef UNITY_COLORSPACE_GAMMA
                     fixed4 color = IN.color;
                     #else
                     fixed4 color = fixed4(GammaToLinearSpace(IN.color.rgb), IN.color.a);
                     #endif
 
                     OUT.color = color * _Color * _RendererColor;
 
                     #ifdef PIXELSNAP_ON
                     OUT.vertex = UnityPixelSnap(OUT.vertex);
                     #endif
 
                     return OUT;
                 }
             ENDCG
             }
         }
 }

And I can't post the outline code since it's from someone else's asset but here's a link to it. (It's free!)

brokenjitteroutline.gif (51.9 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.

Follow this Question

Answers Answers and Comments

127 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

Related Questions

Outline every edge not only its "silhouette" 0 Answers

Legacy edge detection image effect + post processing not working 1 Answer

Vertex Billboard Shader Depth? 1 Answer

Shader not receiving the normal bias offsets from the lights 0 Answers

How to smooth out jaggedness of Edge Detection? 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