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
0
Question by unity_ndyFrs-S49NXgw · Mar 24, 2020 at 11:13 AM · shadershader programmingoutlineintersection

Problem with outling intersection using shader programming

I am trying to develop a shader that outlines objects. The issue I am having is that it manipulates the vertex color and cannot be seen from top view. What I want is to have an outline on all objects cut at a specific height of a fixed length,height,width, i.e.: 1cm. I want a shader to be applied either to all objects or only the plane that cuts the objects. I want to see the outline in the TOP view and preferably SIDE view.,


Here is a random perspective view (you can see the outline) alt text


Here is the top view where you cannot see the outline on all shapes. alt text


I am using the Volume Highlight Shader from @Glurth (https://answers.unity.com/questions/1487473/geometry-intersection-shader.html)

 Shader "Unlit/highlightVolume"
 {
     Properties
     {
         _Color("Color", Color) = (1,1,1,.2)
     }
         SubShader
     {     
         Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
         Pass
         {
             Stencil
             {
                 Ref 172
                 Comp Always
                 Pass Replace
                 ZFail Zero
             }
             Blend Zero One
             Cull Front
             ZTest  GEqual
             ZWrite Off
 
         }// end stencil pass
         Pass
         {
             Blend SrcAlpha OneMinusSrcAlpha
             Stencil
             {
                 Ref 172
                 Comp Equal
             }
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             float4 _Color;
             struct appdata
             {
                 float4 vertex : POSITION;
                 float3 normal: NORMAL;
             };
             struct v2f
             {
                 float4 vertex : SV_POSITION;
             };
             v2f vert(appdata v)
             {
                 v2f o;
                 o.vertex = UnityObjectToClipPos(v.vertex);
                 return o;
             }
             fixed4 frag(v2f i) : SV_Target
             {
                 return _Color;
             }
             ENDCG
         }//end color pass
     }
 }

I have also included the Shader that is on top of the objects that are cut at a specific height.

 Shader "Custom/Clip Plane/Surface"
 {
     Properties
     {
         _Color("Color", Color) = (1,1,1,1)
         _MainTex("Main Texture", 2D) = "white" {}
         _PlaneVector("Plane Vector", Vector) = (0,0,0,10)
         _OutlineWidth("Outline Width", Range(0,0.05)) = 0.01
         _OutlineColor("Outline Color", Color) = (0.5,0.5,0.5,1)
     }
 
     SubShader
     {    
     // Drawing actual object
     Pass
     {
         Cull Off // Turn off Face Culling     
             
         CGPROGRAM
         #include "UnityCG.cginc"
         #include "./CustomClipPlaneFunctions.cginc"
         #pragma vertex vert
         #pragma fragment frag
 
         uniform fixed4 _LightColor0;
 
         float4 _Color;
         float4 _MainTex_ST;         // For the Main Tex UV transform
         sampler2D _MainTex;         // Texture used for the line
         float4 _PlaneVector;
         float _DoClip;
 
         struct v2f
         {
             float4 pos      : POSITION;
             float4 col      : COLOR;
             float2 uv       : TEXCOORD0;
             float doclip    : TEXCOORD1;
             float4 worldSpacePos : TEXCOORD2;
         };
 
         float4 _OutlineColor;
         float _OutlineWidth;
 
         v2f vert(appdata_base v)
         {
             v2f o;
 
             o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
 
             // Calculate clip value
             float3 wp = mul(unity_ObjectToWorld, v.vertex).xyz;
 
             o.worldSpacePos = mul(unity_ObjectToWorld, v.vertex);
 
             o.doclip = isClipped(_PlaneVector, wp);     
                 
             // Lighting            
             float4 LightDirection = normalize(_WorldSpaceLightPos0);
             float3 normalDirection = normalize(mul(unity_ObjectToWorld, v.normal).xyz);
             float4 DiffuseLight = saturate(dot(LightDirection, normalDirection)) * _LightColor0;
             o.col = float4(UNITY_LIGHTMODEL_AMBIENT + DiffuseLight);
                     
             o.pos = UnityObjectToClipPos(v.vertex);
 
             return o;
         }
 
         float4 frag(v2f i) : COLOR
         {
             clip(i.doclip);
 
             float4 col = _Color * tex2D(_MainTex, i.uv);
 
             float4 worldPos = ComputeScreenPos(i.pos);
             
             return col * i.col;
             }
             ENDCG
         }         
     }
 }
 


shaderdemo-min.png (507.4 kB)
topshadersmaller.png (394.3 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

190 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 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

Need help with outline shader 0 Answers

someone knows how to create an anisotropic shader? HELP!!! 0 Answers

Shader Problem 0 Answers

calculating 1 Answer

perform action on shader compilation/update 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