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
2
Question by chief1234 · Jun 14, 2011 at 01:01 AM · shaderimage-effects

Edge detect color

I'd like to customize the colored edges of the EdgeDetectEffectNormals script that comes with Unity Pro. What do I need to change in the script / shader to make the edges say, yellow, instead of black?

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

Answer by Ricardo Arango · Jun 14, 2011 at 04:17 PM

You have to change a few files to get this working:

In EdgeDetectNormalsShader.shader:

1 Define a property that will be exposed in the editor for you to change the color of the edges:

 _Color ("Color", color) = (0,0,0,0)

2 Comment the following line in FragRobert:

 return edge * lerp(tex2D(_MainTex, i.uv[0].xy), _BgColor, _BgFade);

and add the edge color:

 //return edge * lerp(tex2D(_MainTex, i.uv[0].xy), _BgColor, _BgFade);
 if(edge > 0)
     return lerp(tex2D(_MainTex, i.uv[0].xy), _BgColor, _BgFade);
 else
     return _Color;

3 Repeat the step for FragThin:

 //return edge * lerp(original, _BgColor, _BgFade);
 if(edge > 0)
     return lerp(original, _BgColor, _BgFade);
 else
     return _Color;


In EdgeDetectEffectNormalsEditor.js:

1 Add a Serialized propery for the Color value:

 var edgesColor : SerializedProperty;

2 Assign the reference in OnEnable:

 edgesColor = serObj.FindProperty("edgesColor");

3 Display it in the OnGUI call just after the Background options:

 GUILayout.Label ("Edges Color");
 EditorGUILayout.PropertyField (edgesColor, new GUIContent ("EdgesColor"));


In EdgeDetectEffectNormals.js:

1 Add a variable to hold the color property:

 public var edgesColor : Color = Color.white;

2 Use this variable when OnRenderImage to set the _Color property in the shader:

 var edgeCol : Vector4 = edgesColor;
 edgeDetectMaterial.SetVector ("_Color", edgeCol);
Comment
Add comment · Show 6 · 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 chief1234 · Jun 14, 2011 at 07:18 PM 0
Share

Thanks Ricardo, I followed your great instructions and now I'm getting this error: "The image effect Camera (EdgeDetectEffectNormals) on Camera is not supported on this platform!" $$anonymous$$y platform settings are set to PC and $$anonymous$$ac Standalone and my graphics card is an ATI Radeon HD 5730 - do you what might be wrong?

avatar image greg horn · Jul 09, 2011 at 11:35 AM 0
Share

I get the same error, along with some other errors including this:

Invalid pass number for Graphics.Blit UnityEngine.Graphics:Blit(Texture, RenderTexture, $$anonymous$$aterial, Int32) EdgeDetectEffectNormals:OnRenderImage(RenderTexture, RenderTexture)

Would greatly ppreciate some help on this!

avatar image Gillissie · Oct 17, 2011 at 04:52 PM 1
Share

Ricardo forgot to mention that you have to add this to EdgeDetectNormalsShader.shader in the uniform section:

uniform half4 _Color;

avatar image Highlanderdan · Jan 31, 2013 at 04:09 PM 0
Share

Doubt this is still live, but I had a go at this to no effect. I have the property in the inspector but no update to the shader... Did I miss something?

avatar image TinyTracker · Feb 20, 2014 at 02:00 AM 0
Share

Would be better to just post the code in entirety. I can't even tell if this is still valid. Or what parts are valid and what parts are not and what code this is being built and if that code has changed or not.

Show more comments
avatar image
0

Answer by giulio-pierucci · May 28, 2013 at 11:43 PM

Yes, i'ts alive. I think tha your problem is caused by mode. Applying Ricardo solution, Sobel not get _Color property (Maybe a little old post :) )

You have to add same code to other 2 section:

fragDCheap and fragD

Here the code:

     //return Sobel * lerp(tex2D(_MainTex, i.uv[0].xy), _BgColor, _BgFade);
     if(Sobel > 0)
         return lerp(tex2D(_MainTex, i.uv[0].xy), _BgColor, _BgFade);
     else
         return _Color;
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

7 People are following this question.

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

Related Questions

SSAO: How do I get rid of these artifacts? 0 Answers

Custom Brightness/Contrast shader doesn't work on OpenGL ES 2.0 0 Answers

How to create an imageEffect that blurs each pixel differently? 1 Answer

Make objects monochrome, and when I come closer, they get color 1 Answer

Are multiple Unity Pro "Image Effects" auto-combined into a single (or as few as possible) quad shaders? 1 Answer


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