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 /
avatar image
0
Question by NateAGeek · Mar 02, 2015 at 03:07 AM · shaderlightingshadowsshadowlightmapping

Toon Shader Working With Multiple Spotlight Shadows (Pro)

Hello all,

I've been working on making this toon shader from scratch. I have manage to get it to look great! However, it can't get shadows from multiple spotlights(it does work with directional), D:

alt text

 Shader "NateAGeek/ToonPostProcesing" {
     Properties { 
         _MainTex ("Post Image", 2D) = "white" {}
         _OutlineColor ("Outline Color", Color) = (1.0, 1.0, 1.0, 1.0)
         _OutlineThickness ("Outline Thickness", Float) = 0.1
         _OutlineThreshold ("Outline Threshold", Float) = 0.1
     }
     SubShader {
         Pass{
         CGPROGRAM
             #pragma vertex vertexShaderMain
             #pragma fragment fragmentShaderMain
             #pragma target 3.0
             #include "UnityCG.cginc"
 
             uniform sampler2D _MainTex;
             uniform float4 _OutlineColor;
             uniform half _OutlineThickness;
             uniform float _OutlineThreshold;
             uniform sampler2D _CameraDepthNormalsTexture;
             
             
             struct vertexInput {
                 float4 vertex : POSITION;
                 float3 normal : NORMAL;
                 float4 texcoord : TEXCOORD0;
             };
             
             struct vertexOutput {
                 float4 position : SV_POSITION;
                 float4 tex : TEXCOORD0;
                 float4 scrPos : TEXCOORD1;
             };
 
             vertexOutput vertexShaderMain(vertexInput input) {
                 vertexOutput output;
                 
                 output.position = mul(UNITY_MATRIX_MVP, input.vertex);
                 output.tex = input.texcoord;
                 output.scrPos = ComputeScreenPos(output.position);
                 
                 return output;
             }
             
             float4 fragmentShaderMain(vertexOutput o) : COLOR{
                 float dx = 1.0/_ScreenParams.x;
                 float dy = 1.0/_ScreenParams.y;
                 
                  float depthValue;
                  float3 normalValue;
                  DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, o.scrPos.xy), depthValue, normalValue);
                  float4 center = log(depthValue) + float4(normalValue, 1);
                  DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, float2(o.scrPos.x, o.scrPos.y + dy + _OutlineThickness*dy)), depthValue, normalValue);
                  float4 top = log(depthValue) + float4(normalValue, 1);
                  DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, float2(o.scrPos.x, (o.scrPos.y - dy) - _OutlineThickness*dy)), depthValue, normalValue);
                  float4 bottom = log(depthValue) + float4(normalValue, 1);
                  DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, float2(o.scrPos.x + dx + _OutlineThickness*dx, o.scrPos.y)), depthValue, normalValue);
                  float4 right = log(depthValue) + float4(normalValue, 1);
                  DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, float2((o.scrPos.x - dx) - _OutlineThickness*dx, o.scrPos.y)), depthValue, normalValue);
                  float4 left = log(depthValue) + float4(normalValue, 1);
                  
                 if(distance(center, bottom) >= _OutlineThreshold || distance(center, top) >= _OutlineThreshold || distance(center, right) >= _OutlineThreshold || distance(center, left) >= _OutlineThreshold){
                     return _OutlineColor;
                 }
                 return tex2D( _MainTex, o.tex.xy);
             }
         
         ENDCG
         }
     } 
     FallBack "Diffuse"
 }
 

I think the issue is with my second pass... Any help or info will help!

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

2 People are following this question.

avatar image avatar image

Related Questions

Jelly Defense like Planet Lighting/Shading? 1 Answer

Strange shadow I didn't expect 1 Answer

Want shadows from a semi-transparent receiver 0 Answers

Toon shader light culling shadow issue 0 Answers

Toon Shader Not Working With Multiple Spotlight Shadows (Pro) 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