Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ATMEthan · Jan 21, 2015 at 03:56 PM · shaderimage-effectspost effectsedge detection

Is it possible to adjust 'stroke' of Edge Detection post image effect?

Hi Unity Community,

I was curious to know if it is possible to reduce the 'stroke'/ thickness of the lines drawn when using the post image effect Edge Detection.

I'd assume I would have to do this somewhere in the Edge Detection shader. I've been messing around with it for a while now but I am not a shader guru and even the syntax of the shader language still confuses me a bit. Although ever minute spent testing if this or that works I start to understand more of the shader language and syntax.

Any help is much appreciated!!

-Ethan

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ATMEthan · Jan 21, 2015 at 05:17 PM

Ok, so I did some digging and I figured something out...

In the edge detection script there are different modes of edge detection. I am using Roberts Cross Depth Normals b/c it gives the best result and matches the 3D model in MAX the best. Now before I really didn't look at the modes different names but I now noticed there is a Sobel Depth Thin mode. So I went into the shader and look at the differences between Roberts and Sobels Thin. The return variable is calculated differently which makes sense b/c one calculates a thinner edge and one calculates a thicker edge. So all I did was change the calculation in the roberts method to the calculation of the Sobels thin method and it worked the stroke of my edges were halved. Here are the two original methods and my method.

Roberts original vert method:

     v2f vertRobert( appdata_img v ) 
     {
         v2f o;
         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
         
         float2 uv = v.texcoord.xy;
         o.uv[0] = uv;
         
         #if UNITY_UV_STARTS_AT_TOP
         if (_MainTex_TexelSize.y < 0)
             uv.y = 1-uv.y;
         #endif
                 
         // calc coord for the X pattern
         // maybe nicer TODO for the future: 'rotated triangles'
 //thick
         o.uv[1] = uv + _MainTex_TexelSize.xy * half2(1,1) * _SampleDistance;
         o.uv[2] = uv + _MainTex_TexelSize.xy * half2(-1,-1) * _SampleDistance;
         o.uv[3] = uv + _MainTex_TexelSize.xy * half2(-1,1) * _SampleDistance;
         o.uv[4] = uv + _MainTex_TexelSize.xy * half2(1,-1) * _SampleDistance;
         return o;
     }

Here is sobels thin original vert method:

     v2f vertThin( appdata_img v )
     {
         v2f o;
         o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
         
         float2 uv = v.texcoord.xy;
         o.uv[0] = uv;
         
         #if UNITY_UV_STARTS_AT_TOP
         if (_MainTex_TexelSize.y < 0)
             uv.y = 1-uv.y;
         #endif
         
         o.uv[1] = uv;
         o.uv[4] = uv;
                 
         // offsets for two additional samples
         o.uv[2] = uv + float2(-_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance;
         o.uv[3] = uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance;
         
         return o;
     }

And now here is my mixed method(which is basically the above method):

     v2f vertRobert( appdata_img v ) 
     {
         v2f o;
         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
         
         float2 uv = v.texcoord.xy;
         o.uv[0] = uv;
         
         #if UNITY_UV_STARTS_AT_TOP
         if (_MainTex_TexelSize.y < 0)
             uv.y = 1-uv.y;
         #endif
                 
         // calc coord for the X pattern
         // maybe nicer TODO for the future: 'rotated triangles'
 //thick
 //        o.uv[1] = uv + _MainTex_TexelSize.xy * half2(1,1) * _SampleDistance;
 //        o.uv[2] = uv + _MainTex_TexelSize.xy * half2(-1,-1) * _SampleDistance;
 //        o.uv[3] = uv + _MainTex_TexelSize.xy * half2(-1,1) * _SampleDistance;
 //        o.uv[4] = uv + _MainTex_TexelSize.xy * half2(1,-1) * _SampleDistance;
 //thin        
         o.uv[1] = uv;
         o.uv[4] = uv;
                 
         // offsets for two additional samples
         o.uv[2] = uv + float2(-_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance;
         o.uv[3] = uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y) * _SampleDistance;
         return o;
     } 

Now as great as this is I'm not satisfied. It would be sweet if on the shader there could be a sliderbar that dictates the stroke thickness. So I will not accept this as an answer but in the end it does achieve what I originally asked.

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 ATMEthan · Jan 21, 2015 at 05:20 PM 0
Share

Correction, the sliderbar would have to be on the EdgeDetection Script b/c there is no material associated with this shader. Unless I'm wrong...

avatar image ATMEthan · Jan 21, 2015 at 05:23 PM 0
Share

Also in the EdgeDetection shader ins$$anonymous$$d of editting ther vertRobert method you can jsut change the Subshader pass that uses vertRobert and fragRobert as seen below.

 Subshader {
  Pass {
       ZTest Always Cull Off ZWrite Off
       Fog { $$anonymous$$ode off }      
 
       CGPROGRA$$anonymous$$
       #pragma vertex vertThin
       #pragma fragment fragThin
       ENDCG
   }
  Pass {
       ZTest Always Cull Off ZWrite Off
       Fog { $$anonymous$$ode off }      
 
       CGPROGRA$$anonymous$$
       //#pragma vertex vertRobert - original
       #pragma vertex vertThin 
       #pragma fragment fragRobert
       ENDCG
   }
  Pass {
       ZTest Always Cull Off ZWrite Off
       Fog { $$anonymous$$ode off }   
 
       CGPROGRA$$anonymous$$
       #pragma target 3.0   
       #pragma vertex vertD
       #pragma fragment fragDCheap
       ENDCG
   }
  Pass {
       ZTest Always Cull Off ZWrite Off
       Fog { $$anonymous$$ode off }   
 
       CGPROGRA$$anonymous$$
       #pragma target 3.0   
       #pragma vertex vertD
       #pragma fragment fragD
       ENDCG
   }
  Pass {
       ZTest Always Cull Off ZWrite Off
       Fog { $$anonymous$$ode off }   
 
       CGPROGRA$$anonymous$$
       #pragma target 3.0   
       #pragma vertex vertLum
       #pragma fragment fragLum
       ENDCG
   }
 }

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

25 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

Related Questions

Image-Effect Shading the GUI? 1 Answer

How would I grab the lighting pass in a post process shader for deferred lighting? 0 Answers

Shader Forge post effect yields a black screen 0 Answers

Edge shading/detection tutorial that works in Unity 2020.1.3? 0 Answers

Fade object transparency evenly from the edge inward 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