Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Dec 09, 2014 at 03:34 PM by unimechanic for the following reason:

Duplicate Question

avatar image
0
Question by barbe63 · Dec 02, 2014 at 09:43 PM · shadertransparencyshadowtoon

Adding transparency to a shadow

Hello.

My project currently involve custom shader that i found on internet (I know nothing about shaders). It's a toon shader with transparency (my ragdolls need to fade out). It is working fine but the shadow is keeping it's opacity while the body is vanishing.

Please can someone tell me what I should add to those codes?

 Shader "Toon/Basic Alpha" { Properties { _Color ("Main Color", Color) = (.5,.5,.5,1) _MainTex ("Base (RGB)", 2D) = "white" {} _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal } }
 
     SubShader {
     Tags {"Queue"="Transparent" "RenderType"="Transparent"} 
     Pass {
     Name "BASE"
     Blend SrcAlpha OneMinusSrcAlpha 
      
     CGPROGRAM
     #pragma vertex vert
     #pragma fragment frag
     #pragma fragmentoption ARB_precision_hint_fastest
      
     #include "UnityCG.cginc"
      
     sampler2D _MainTex;
     samplerCUBE _ToonShade;
     float4 _MainTex_ST;
     float4 _Color;
      
     struct appdata {
     float4 vertex : POSITION;
     float2 texcoord : TEXCOORD0;
     float3 normal : NORMAL;
     };
      
     struct v2f {
     float4 pos : POSITION;
     float2 texcoord : TEXCOORD0;
     float3 cubenormal : TEXCOORD1;
     };
      
     v2f vert (appdata v) {
     v2f o;
     o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
     o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
     o.cubenormal = mul (UNITY_MATRIX_MV, float4(v.normal,0));
     return o;
     }
      
     float4 frag (v2f i) : COLOR {
     float4 col = _Color * tex2D(_MainTex, i.texcoord);
     float4 cube = texCUBE(_ToonShade, i.cubenormal);
     return float4(2.0f * cube.rgb * col.rgb, col.a);
     }
     ENDCG
     }
     }
      
     SubShader {
     Tags {"Queue"="Transparent" "RenderType"="Transparent"} 
     Pass {
     Name "BASE"       
     Blend SrcAlpha OneMinusSrcAlpha 
     SetTexture [_MainTex] {
     constantColor [_Color]
     Combine texture * constant
     }
     SetTexture [_ToonShade] {
     combine texture * previous DOUBLE, previous
     }
     }
     }
      
     Fallback "VertexLit"
 
 } 
 

and

 Shader "Toon/Basic Outline Alpha" { Properties { _Color ("Main Color", Color) = (.5,.5,.5,1) _OutlineColor ("Outline Color", Color) = (0,0,0,1) _Outline ("Outline width", Range (.002, 0.03)) = .005 _MainTex ("Base (RGB)", 2D) = "white" { } _ToonShade ("ToonShader Cubemap(RGB)", CUBE) = "" { Texgen CubeNormal } }
 
     CGINCLUDE
     #include "UnityCG.cginc"
      
     struct appdata {
     float4 vertex : POSITION;
     float3 normal : NORMAL;
     };
      
     struct v2f {
     float4 pos : POSITION;
     float4 color : COLOR;
     };
      
     uniform float4 _Color; 
     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_IT_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.color = float4(_OutlineColor.rgb, _Color.a); 
     return o;
     }
     ENDCG
      
     SubShader {
     Tags {"Queue"="Transparent" "RenderType"="Transparent"} 
     UsePass "Toon/Basic Alpha/BASE"
     Pass {
     Name "OUTLINE"
     Tags { "LightMode" = "Always" }
     Cull Front
     ZWrite On
     ColorMask RGB
     Blend SrcAlpha OneMinusSrcAlpha
      
     CGPROGRAM
     #pragma vertex vert
     #pragma fragment frag
     half4 frag(v2f i) :COLOR { return i.color; }
     ENDCG
     }
     }
     SubShader {
     Tags {"Queue"="Transparent" "RenderType"="Transparent"} 
     UsePass "Toon/Basic Alpha/BASE"
     Pass {
     Name "OUTLINE"
     Tags { "LightMode" = "Always" }
     Cull Front
     ZWrite On
     ColorMask RGB
     Blend SrcAlpha OneMinusSrcAlpha
      
     CGPROGRAM
     #pragma vertex vert
     #pragma exclude_renderers gles xbox360 ps3
     ENDCG
     SetTexture [_MainTex] { combine primary }
     }
     }
     Fallback "Toon/Basic Alpha"
     }


Comment
Add comment · Show 3
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 _dns_ · Dec 04, 2014 at 06:05 PM 0
Share

Hi, if you are talking about the shadow an object produces on the ground or walls: it's the shader of the ground/wall that needs to be modified as it's this/those one that receive the shadow and attenuate their color to display it. There may be other ways, the suggestion to post that in the forums is a good idea :)

avatar image barbe63 · Dec 04, 2014 at 06:44 PM 0
Share

Thanks for this input, I've already seen that thread but as far as i understood it's for having an opaque shadow on a transparent object. (but as my english is quite limited I may have misunderstood it) I already have that but i need it to be transparent as well.

avatar image barbe63 · Dec 05, 2014 at 12:34 AM 0
Share

Ok thanks, I posted it here, hoping it's where you ment.

1 Reply

  • Sort: 
avatar image
0

Answer by unimechanic · Dec 09, 2014 at 03:34 PM

http://forum.unity3d.com/threads/adding-transparency-to-shadow.283908/

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

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

GameObject not receiving shadows 0 Answers

Glitchy shadow lines: Toon Lighted (screenshot) 0 Answers

Semi-Transparent Shader that casts and receives shadows 0 Answers

Combine Basic Shadow Shader and Transparency Shader in Unity 0 Answers

(SOLVED) How to bake lightmaps with transparent cutout shader ? 2 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