Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 jmloversg · Aug 29, 2011 at 03:23 PM · shadertoonshadingcartoon

Hello, I am wondering

Shader "Hidden/EdgeDetectGeometry" { Properties { _MainTex ("Base (RGB)", 2D) = "" {} _Color ("Color", color) = (0,0,0,1) }

 // Shader code pasted into all further CGPROGRAM blocks    
 CGINCLUDE
 
 #include "UnityCG.cginc"
 
 struct v2f {
     float4 pos : POSITION;
     float2 uv[5] : TEXCOORD0;
 };
 
 sampler2D _MainTex;
 uniform half4 _MainTex_TexelSize;
 sampler2D _CameraDepthNormalsTexture;
 
 uniform half4 sensitivity; 
 uniform half4 _BgColor;
 uniform half _BgFade;
 uniform float4 _Color;
 
 inline half CheckSame (half2 centerNormal, float centerDepth, half4 sample)
 {
     // difference in normals
     // do not bother decoding normals - there's no need here
     half2 diff = abs(centerNormal - sample.xy) * sensitivity.y;
     half isSameNormal = (diff.x + diff.y) * sensitivity.y < 0.1;
     // difference in depth
     float sampleDepth = DecodeFloatRG (sample.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;
 }    
         
 v2f vertThin( appdata_img v )
 {
     v2f o;
     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
     


     
     float2 uv = v.texcoord.xy;
     o.uv[0] = uv;
     
     // On D3D when AA is used, the main texture & scene depth texture
     // will come out in different vertical orientations.
     // So flip sampling of depth texture when that is the case (main texture
     // texel size will have negative Y)
     
     #if SHADER_API_D3D9
     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);
     o.uv[3] = uv + float2(+_MainTex_TexelSize.x, -_MainTex_TexelSize.y);
     o.pos.z +=0.1f;
     
     return o;
 }      
 
 
 half4 fragThin (v2f i) : COLOR
 {
     half4 original = tex2D(_MainTex, i.uv[0]);
     
     half4 center = tex2D (_CameraDepthNormalsTexture, i.uv[1]);
     half4 sample1 = tex2D (_CameraDepthNormalsTexture, i.uv[2]);
     half4 sample2 = tex2D (_CameraDepthNormalsTexture, i.uv[3]);
     
     // encoded normal
     half2 centerNormal = center.xy;
     // decoded depth
     float centerDepth = DecodeFloatRG (center.zw);
     
     half edge = 1.0;
     
     edge *= CheckSame(centerNormal, centerDepth, sample1);
     edge *= CheckSame(centerNormal, centerDepth, sample2);
         
     //return edge * lerp(original, _BgColor, _BgFade);
     if(edge > 0)
         return lerp(original, _BgColor, _BgFade);
     else
         return _Color;
 }
 
 ENDCG 
 

Subshader {

Pass {

    ZTest Always
   Cull Back 
   ZWrite On
   Fog { Mode off }      


   CGPROGRAM
   #pragma vertex vertThin
   #pragma fragment fragThin
   ENDCG

}

}

Fallback off

} // shader\

Hello, I used shader in the unity3d. But, I have some wrong this shader just for me. When I used this shader, you can show under the img. 125alt text125

But, I want to make like a under the picture. these two plane show line.

95alt text95

How can i fix this shader. If you can know, let me know plz. Thank for reading. And I'm sorry I can't write English very well.

Comment
Add comment · Show 1
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 Meltdown · Aug 29, 2011 at 03:30 PM 0
Share

Your images are broken, so hard to understand what you are wanting.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by psantoki · May 29, 2014 at 11:09 PM

I'm also working on depth effects in the unity3d.

I can't see your images, but I also have a problem with "lines"

In my case, switching camera.depthTextureMode from Depth to DepthNormals caused the problem, because the unity3d stores Depth in nonlinear floating point and DepthNormals in fixed point format, which immediately breaks down if your far plane is larger than a room. For instance, with a far plane of 1300 meters the smallest delta you're getting is 5 meters.

This wrecks SAO effects, among other things. My present task is to fix this. Which means I'm getting paid to cry at my desk.

alt text


depth is smoother than depthnormals.jpg (88.1 kB)
Comment
Add comment · Show 1 · 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 meat5000 ♦ · May 29, 2014 at 11:23 PM 0
Share

I've accepted your answer on this Well Old QA as its the most informed (and only) answer.

If you find a solution to your problem and care to share, perhaps create a new, more direct question of your own and put the answer in. Up to you, of course.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

View dependant toon outline shader 0 Answers

How hard would it be to produce a cel shaded shader? 1 Answer

How to make shader receive shadows 0 Answers

Toon Shader gets alpha from color, not texture 0 Answers

My toon shader seems to make a black hole. 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