Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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 GamezAtWork · Nov 04, 2010 at 05:23 PM · shadershadowsalphatoonshading

Toon Shader with Shadows AND Alpha? (Unity 2.6)

Well, to start off with, I'm very bad at working with shaders, I'm barely even sure how they work, honestly...

But for my game, we kinda need Toon Shading which are affected by Shadows (Diffuse, I believe its called?) AND Alpha, as some of our characters have see-through textures of sorts, and I REALLY want to make the enemies fade out on death...

Can anyone help me?

Thanks!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by skovacs1 · Nov 04, 2010 at 06:41 PM

This is a post where I had added alpha to the standard toon shader for Unity 3. Adding alpha is not too hard.

Adding shadows (and other lighting) involves changing the shader with a bit more knowledge of what's actually going on. Since the Unity 3 shaders implement lighting very differently than 2.6, I can't really write and test something and be sure it will work for you. Here is a shader from the wiki which does Toon Shadows in Unity 2.x. I would recommend starting there and adding alpha by changing the blend mode and the render queue. I'm not sure, but I believe that objects in the Transparent render queue will not receive shadows, but if you don't put transparent objects in this queue, objects will be drawn in the wrong order.

Since I don't have 2.6, I can't test this, so it is offered with no guarantee that it will work, but I would try something like:

Shader "Toon/AlphaShadowed" { Properties { _Color ("Main Color", Color) = (.5,.5,.5,1) _MainTex ("Base (RGB)", 2D) = "white" {} _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "white" { Texgen CubeNormal } }

 Category {
     SubShader {
         Tags {"Queue"="Transparent" "RenderType"="Transparent"}
         Pass {
             // Fallback case for non-pixel-lit situations.
             Blend SrcAlpha OneMinusSrcAlpha
             Name "BASE"
             Tags {"LightMode" = "VertexOrNone"}
             SetTexture [_MainTex] { constantColor [_Color] Combine texture * constant }
             SetTexture [_ToonShade] { combine texture * previous DOUBLE, previous }
         }
         Pass {
             Blend SrcAlpha OneMinusSrcAlpha
             Name "PPL"
             Tags { "LightMode" = "Pixel" }
             ColorMask RGBA
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             #pragma multi_compile_builtin
             #pragma fragmentoption ARB_fog_exp2
             #pragma fragmentoption ARB_precision_hint_fastest
             #include "UnityCG.cginc"
             #include "AutoLight.cginc"

             struct v2f {
                 V2F_POS_FOG;
                 LIGHTING_COORDS
                 float2  uvA;
                 float3  uvB;
             };

             uniform float4 _MainTex_ST;

             v2f vert (appdata_tan v) {
                 v2f o;
                 PositionFog( v.vertex, o.pos, o.fog );
                 o.uvA = TRANSFORM_TEX(v.texcoord, _MainTex);
                 o.uvB = mul((float3x3)glstate.matrix.invtrans.modelview[0], v.normal );   
                 TRANSFER_VERTEX_TO_FRAGMENT(o);
                 return o;
             }

             uniform sampler2D _MainTex;
             uniform samplerCUBE _ToonShade;
             uniform float4 _Color;

             float4 frag (v2f i) : COLOR {
                 half4 texcol = tex2D( _MainTex, i.uvA ) * _Color;
                 half4 lighting = LIGHT_ATTENUATION(i) * texCUBE(_ToonShade, i.uvB);

                 return half4((texcol * lighting * 2).rgb, texcol.a);
             }
             ENDCG
         }
     }
 }
 Fallback "VertexLit"

}

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 GamezAtWork · Nov 05, 2010 at 08:33 PM 0
Share

Thanks for the contribution!

And for a test, I would say its pretty impressive, because it worked... The only thing is that I apparently forgot I wanted it to have outlines as well... Completely forgot that it ain't naturally under Toon Shading, ugh. So I'm trying to experiment here and there to see whether I can combine the old Toon Shader that Omega created a while back in http://forum.unity3d.com/threads/24668-Toon-Outline-but-with-Diffuse-surface with the one you just created... Trying to see whether I can get your alpha with his shading...

Thanks again!

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

No one has followed this question yet.

Related Questions

Shader with texture with alpha and casting shadows 1 Answer

Shadows with Alpha, fade out shadow. 2 Answers

Toon Shader gets alpha from color, not texture 0 Answers

Fade-In/Out shadows for a specific object 0 Answers

Add Alpha information into the standard toon shader 3 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