• 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 Le-Capitaine · Sep 21, 2014 at 06:59 AM · shaderscg

Shaders and the people who love them

Right, so, uh...

 Shader "Custom/Redline" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _Ramp ("Ramp Texture", 2D) = "white" {}
         _SpecRamp ("Specular Ramp", 2D) = "white" {}
         _Outline ("Outline", Range(0,1)) = 0.4
         _OutlineColor ("Outline Color", Color) = (0,0,0,1)
         _Shininess ("Shininess", Range(0,10)) = 0.1
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         UsePass "Toon/Basic/BASE"
         Pass {
             Name "LIGHTING"
             Tags { "LightMode" = "Always" }
             Cull Off
             ZWrite On
             ColorMask RGB
             Blend SrcAlpha OneMinusSrcAlpha
             
             CGPROGRAM
             #pragma lighting LightingToon
         
             sampler2D _MainTex;
             sampler2D _Ramp;
             sampler2D _SpecRamp;
             float _Shininess;
             
             half4 LightingToon(SurfaceOutput s, half3 lightDir, half atten ) {
                        half4 c;
                     half NdotL = dot(s.Normal, lightDir);
                     NdotL = tex2D(_Ramp, float2(NdotL, 0.5));
                     
                     half NdotLSpec = dot(s.Normal, lightDir);
                     NdotLSpec = tex2D(_SpecRamp, float2(NdotLSpec, 0.5));
          
                     c.rgb = (s.Albedo * _LightColor0.rgb * NdotL * (atten * 2)) + (NdotLSpec * _Shininess);
                     c.a = s.Alpha;
                     return c;
                 }
             ENDCG
            }
         UsePass "Toon/Basic Outline/OUTLINE"
     }
     FallBack "Diffuse"
 }

This is meant to be a toon shader with two ramps, one for basic lighting and one for specularity. It won't work -- the entire textured surface consists of black and in fact, getting the entire thing down to this:

 Shader "Custom/Redline" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _Ramp ("Ramp Texture", 2D) = "white" {}
         _SpecRamp ("Specular Ramp", 2D) = "white" {}
         _Outline ("Outline", Range(0,1)) = 0.4
     _OutlineColor ("Outline Color", Color) = (0,0,0,1)
         _Shininess ("Shininess", Range(0,10)) = 0.1
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         UsePass "Toon/Basic/BASE"
         UsePass "Toon/Basic Outline/OUTLINE"
     }
     FallBack "Diffuse"
 }

that is, a straight copy of the standard Lighted Outline shader, throws the exact same result. Is something obvious flying over my head again?

Comment
Add comment · Show 6
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 zharik86 · Sep 21, 2014 at 07:13 AM 0
Share

Do you have shaders which specified as UsePass: "Toon/Basic/BASE" and "Toon/Basic Outline/OUTLINE"?

avatar image Le-Capitaine · Sep 21, 2014 at 07:19 AM 0
Share

I do have those standard assets loaded, and the outline does in fact work.

avatar image zharik86 · Sep 21, 2014 at 07:24 AM 0
Share

I don't know, I can absolutely lagged behind life, but, for example, in Unity 4.1.2 which I use, such shaders with standard aren't present. I think to you it is necessary to remove these UsePass and to add your shader other basic function a little.

avatar image zharik86 · Sep 21, 2014 at 07:35 AM 0
Share

For shaders see answers.unity3d.com/questions/737760/how-can-i-get-transparency-into-the-unity-toon-lig.html

avatar image tanoshimi · Sep 21, 2014 at 07:58 AM 1
Share

First rule of shader development is to get rid of the Fallback, to make sure what you're seeing is the shader you're editing and not the fallback. Does that make a difference?

Show more comments

1 Reply

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

Answer by Le-Capitaine · Sep 21, 2014 at 09:41 AM

Finally solved it. Here's the code if that interests anybody.

     Shader "Custom/Redline" {
         Properties {
             _MainTex ("Base (RGB)", 2D) = "white" {}
             _Color ("Color", Color) = (1,1,1,1)
             _Ramp ("Ramp Texture", 2D) = "white" {}
             _SpecRamp ("Specular Ramp", 2D) = "white" {}
             _Outline ("Outline", Range(.002, 0.03)) = .03
             _OutlineColor ("Outline Color", Color) = (0,0,0,1)
             _Shininess ("Shininess", Range(0,10)) = 0.1
         }
         SubShader {
             Tags { "RenderType"="Opaque" }
             
             CGPROGRAM
             #include "UnityCG.cginc"
             #pragma surface surf Toon noambient
             
             sampler2D _MainTex;
             float4 _Color;
             sampler2D _Ramp;
             sampler2D _SpecRamp;
             float _Shininess;
             
             struct Input {
                 float2 uv_MainTex : TEXCOORD0;
             };
             
             void surf (Input IN, inout SurfaceOutput o) {
                 half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
                 o.Albedo = c.rgb;
                 o.Alpha = c.a;
             }    
             
             half4 LightingToon (SurfaceOutput s, half3 lightDir, half atten ) {
             
                 #ifndef USING_DIRECTIONAL_LIGHT
                 lightDir = normalize(lightDir);
                 #endif
                 
                    half4 c;
                 half NdotL = dot(s.Normal, lightDir);
                 NdotL = tex2D(_Ramp, float2(NdotL, 0.5));
                     
                 half NdotLSpec = dot(s.Normal, lightDir);
                 NdotLSpec = tex2D(_SpecRamp, float2(NdotLSpec, 0.5));
          
                 c.rgb = (s.Albedo * NdotL) + (NdotLSpec * _Shininess);
                 c.a = s.Alpha;
                 return c;
             }
             ENDCG
             UsePass "Toon/Basic Outline/OUTLINE"
         }
         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

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

24 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

Related Questions

Accessing shadow texture in shader 2 Answers

Texture not mapped to UV CG shader 1 Answer

Weird shader error X5204 - read of uninitialized components 1 Answer

Porting from ShaderToy(GLSL) to shaderlab(HLSL/CG) unity not giving me the desired result. 2 Answers

Separate texture coordinates in 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