• 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
3
Question by ben · Dec 23, 2010 at 04:20 AM · highlight

highlight only the border of an object

iam new to unity....... i would like to know how can i highlight just the borders of an object

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
4

Answer by cupsster · Jan 14, 2011 at 08:21 PM

Shader "Outlined Diffuse" { Properties { _Color ("Main Color", Color) = (.5,.5,.5,1) _OutlineColor ("Outline Color", Color) = (0,1,0,1) _Outline ("Outline width", Range (0.002, 0.03)) = 0.01 _MainTex ("Base (RGBA)", 2D) = "white" { } //Not needed //_ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal } }

SubShader { Tags {"Queue"="Transparent" "RenderType"="Transparent"}

   //Minor switch 
   //UsePass "Toon/Basic/BASE" 

   CGPROGRAM
     #pragma surface surf Lambert

     sampler2D _MainTex;
     float4 _Color;

     struct Input {
         float2 uv_MainTex;
     };

     void surf (Input IN, inout SurfaceOutput o) {
         half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
         o.Albedo = c.rgb;
         o.Alpha = c.a;
     }
     ENDCG

   Pass 
   { 
      Name "OUTLINE" 
      Tags { "LightMode" = "Always" } 

      Blend SrcAlpha OneMinusSrcAlpha

      CGPROGRAM 

pragma exclude_renderers gles

pragma exclude_renderers xbox360 #pragma vertex vert

      struct appdata { 
          float4 vertex; 
          float3 normal; 
      }; 

      struct v2f { 
         float4 pos : POSITION; 
         float4 color : COLOR; 
         float fog : FOGC; 
      }; 
      uniform float _Outline; 
      uniform float4 _OutlineColor; 

      v2f vert(appdata v) { 
         v2f o; 
         o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 
         float3 norm = mul ((float3x3)UNITY_MATRIX_MV, v.normal); 
         norm.x *= UNITY_MATRIX_P[0][0]; 
         norm.y *= UNITY_MATRIX_P[1][1]; 
         o.pos.xy += norm.xy * o.pos.z * _Outline; 

         o.fog = o.pos.z; 
         o.color = _OutlineColor; 
         return o; 
      } 

      ENDCG 

      Cull Front
      ZWrite On
      ColorMask RGBA
      Blend SrcAlpha OneMinusSrcAlpha
      //? -Note: I don't remember why I put a "?" here 
      SetTexture [_MainTex] { combine primary } 
   } 

}

Fallback "Diffuse" }

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
avatar image
3

Answer by ina · Dec 23, 2010 at 04:22 AM

Try using the ToonShading.unityPackage

Comment
Add comment · Show 3 · 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 ben · Dec 23, 2010 at 06:26 AM 0
Share

thanks dear............... done it

avatar image papamck · Apr 05, 2012 at 09:03 AM 0
Share

how to use C# to activate it? I am working on mouseover show outline

avatar image Garitzar · Apr 10, 2014 at 07:36 PM 0
Share

@papamck If you for example are using Toon/Basic Outline as the shader you can change it´s properties by

 renderer.material.setColor("nameOfTheParameter", Color.somecolor);

(this is if you have a script on the same object that has the shader)

Example: I want to change the "Outline Color" at runtime, if you press "edit" in the inspecor you can find that the name of "Outline Color" property is called _OutlineColor, so to change it to a red color write

 renderar.material.setColor("_OutlineColor", Color.red);

Notice: saving the material and using your own Colors ( i.e. new Color(r.b.g.a) ) can cuase problems so try use Color.comecolor :D

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

highlight object color 3 Answers

How to highlight a GameObject in the Scene view from an Inspector script? 1 Answer

Synchronized text with voice like karaoke 1 Answer

Highlighting Objects Behind Other Objects 0 Answers

Lighted Toon with Highlight 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