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 Natsu_k · Jan 14, 2015 at 04:05 AM · shaderdeferreddeferred renderingedge detection

Edge Detection with Deferred Rendering?

Hi guys

I'm using the TriangleDepthNormals Edge Detection camera post effect. However last night I modified my shaders in my project to utilize deferred rendering, which yields very nice results for edge detection in a short range.

Unfortunately, my ground, which is just a flat plane has it's edge detection messed up at a distance (at the length of a default unity plane). The solution I'm hoping for is one of three:

  1. Is it possible to have the edge detection cutoff after a specified distance?

  2. Is it possible to have edge detection behave with deferred rendering?

  3. Is it possible to use layers to exclude the ground from the edge detection?

I've been looking around for a solution but haven't much luck at finding any information relating edge detection to deferred randering.

Also something to note is most of the models I'm using do not like using normals to calculate edges, so I'm relying heavily on the depth detection.

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
Best Answer

Answer by Natsu_k · Jan 15, 2015 at 01:34 PM

I ended up experimenting and changing how the EdgeDetectNormals shader functions. I saw that it would draw a line if either the depth or the normal where over the threshold. I changed it so that both the normal and the depth had to be over the threshold to draw a line; it's produced much nicer effects.

FROM:

 inline half CheckSame (half2 centerNormal, float centerDepth, half4 theSample)
     {
         // difference in normals
         // do not bother decoding normals - there's no need here
         half2 diff = abs(centerNormal - theSample.xy) * _Sensitivity.y;
         half isSameNormal = (diff.x + diff.y) * _Sensitivity.y < 0.1;
         // difference in depth
         float sampleDepth = DecodeFloatRG (theSample.zw);
         float zdiff = abs(centerDepth-sampleDepth);
         // scale the required threshold by the distance
         half isSameDepth = zdiff * _Sensitivity.x < 0.09 * centerDepth;
 
         // return:
         // 1 - if normals and depth are similar enough
         // 0 - otherwise
         
         return isSameNormal * isSameDepth;
     }    


TO:

 inline half CheckSame (half2 centerNormal, float centerDepth, half4 theSample)
     {
         // difference in normals
         // do not bother decoding normals - there's no need here
         half2 diff = abs(centerNormal - theSample.xy) * _Sensitivity.y;
         half isSameNormal = (diff.x + diff.y) * _Sensitivity.y < 0.1;
         // difference in depth
         float sampleDepth = DecodeFloatRG (theSample.zw);
         float zdiff = abs(centerDepth-sampleDepth);
         // scale the required threshold by the distance
         half isSameDepth = zdiff * _Sensitivity.x < 0.09 * centerDepth;
 
         // return:
         // 1 - if normals and depth are similar enough
         // 0 - otherwise
         
         return saturate(isSameNormal + isSameDepth);
     }    


It works, but there still might yet be some unforeseen effects that I may encounter later on.

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

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

exclude_path:deferred causes see through? 0 Answers

How to Get Nice Thick Toon-Like Outlines On Non-Smooth Geometry? 1 Answer

Is it possible to avoid writing to certain g-buffers? 1 Answer

orthographic camera with deferred lighting 2 Answers

Custom water shader and SSR 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