Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Koropokuruh · Dec 02, 2016 at 11:59 AM · shadershader programmingdeferred renderingtoonshadingcellshading

My Deferred Cell Shading is not working

I've changed the deferred rendering shader in unity back in version 5.3 based on this tutorial: http://www.gamasutra.com/blogs/DavidLeon/20150702/247602/NextGen_Cel_Shading_in_Unity_5.php

It worked like a charm and my game had the look I was aiming for. But once I've updated to version 5.5 the shader simply stopped working. I've found out it has to do with Unity 5.5 ignoring any light.ndotl variables in the shaders :

"The ndotl variable value in UnityLight is now calculated on the fly and any value written into the variable is ignored."

My game should look like this :alt text But now it Looks like this: alt text

Is there anyway I can achieve this look again?

I've tried and can't find a way to change the Internal-DefferedShading to achieve the look I once had.

captura-de-tela-2016-12-01-180425.jpg (304.7 kB)
captura-de-tela-2016-12-01-180153.jpg (251.8 kB)
Comment
Add comment · Show 2
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 tanoshimi · Dec 02, 2016 at 12:00 PM 0
Share

Why not just carry on using 5.4 then?

avatar image Koropokuruh tanoshimi · Dec 02, 2016 at 05:14 PM 0
Share

In this project I might. But this will probably be carried over to unity 6,7,8,9... At one point I'll have to update. The way it is, we can't manipulate light behaviour in Unity's PBS. I've been trying to make this in a shader rather than in the Internal-DeferredShading and can't make a non-forward rendering custom lighting effect.

1 Reply

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

Answer by Koropokuruh · Jan 29, 2017 at 01:03 PM

Fixed! Now the Light.NDotl is calculated in CGINC files...

Comment
Add comment · Show 7 · 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 LukeAPEX · Jan 31, 2017 at 08:54 PM 0
Share

Hi I'm having the exact same issue as you. Did you make a copy of UnityCG.cginc and add the change to the ndotl section of the file? I tried that and it crash unity every time it tries to render in the editor.

This is how I change my file but it just crash unity every time:


    // NdotL
        float4 ndotl = 0;
        ndotl += toLightX * normal.x;
        ndotl += toLightY * normal.y;
        ndotl += toLightZ * normal.z;
        // correct NdotL
        float4 corr = rsqrt(lengthSq);
        ndotl = max (float4(0,0,0,0), ndotl * corr);
        // cel shading
        if (ndotl <= 0.0F)
            ndotl = 0F;
        else
            ndotl = 1F;

Can you please let me know exactly how you solve this. Thanks!

avatar image Koropokuruh LukeAPEX · Jan 31, 2017 at 09:13 PM 0
Share

I've altered the UnityStandardBRDF.cginc file. created a new method (so I can have more than 1 lighting option in the engine):

 //copied from BRDF2_Unity_PBS and added :
 //if (nl <= 0.0f) nl = 0.0f;
 //else if (nl <= 0.9f) nl = 0.8f;
 //else nl = 1.0f;
 //to create a toon lighting effect without the need of a ramp texture

The code is too big to put here... But I've called it BRDF_Unity_Toon This way you can have the option to normal unity pbr lighting or a toon cel shaded lighting.

After that I've made a shader and added this line: #define UNITY_BRDF_PBS BRDF_Unity_Toon so now it will use the toon lighting method I've created in UnityStandardBRDF.cginc

avatar image Cereal_Killa · Feb 04, 2017 at 03:29 PM 0
Share

@koropokuruh Any chance you can post a link to your code? I've been trying to get this working again (was working perfectly in an older version with no toon ramp) with the standard deferred shader.

avatar image Koropokuruh Cereal_Killa · Feb 08, 2017 at 02:03 AM 1
Share

Well I'll tell what I did, there's no need to post my code here.

1)I've made a copy of [program files]\Unity\Editor\Data\CGIncludes\UnityStandardBRDF.cginc

2)I've opened UnityStandardBRDF.cginc and looked for BRDF2_Unity_PBS function

3)copied everything in the function and pasted as a new function below BRDF3_Unity_PBS function

4)I've renamed it as BRDF_Unity_Toon

5)Below the line "half nl = saturate(dot(normal, light.dir));" I've added

 if (nl <= 0.0f) nl = 0.0f;
 else if (nl <= 0.9f) nl = 0.8f;
 else nl = 1.0f;

6)Saved and replaced the original unity CGINC file (make a backup!!!)

7)Opened unity default deferred shading shader and changed the #define line with below

 #define UNITY_BRDF_PBS BRDF_Unity_Toon

8)Save the file as "Toon-DeferredShading" and put it in unity graphics option.

avatar image LukeAPEX Koropokuruh · Feb 08, 2017 at 08:25 AM 0
Share

Thank you!!! This did the trick. Seriously thank you for taking the time to explain that. I've never really done anything with shaders before so it's confusing to me.

One thing that i had to play with was where to put that #define line. I ended up sticking it right below the first CGPROGRA$$anonymous$$ line and that got it working.

Thanks again.

avatar image LukeAPEX · Feb 05, 2017 at 12:52 AM 0
Share

Yeah I still haven't resolved the issue, even after trying the methods details here: The bottom answer

It still causes unity to crash anytime I try to use a modified .cginc file.

avatar image Koropokuruh LukeAPEX · Feb 08, 2017 at 02:05 AM 0
Share

the problem with that answer is that all of you projects will have that lighting, the solution I gave above gives me the option to use toon shading or not.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is it possible to avoid writing to certain g-buffers? 1 Answer

Cel Shading Possible In Unity Free Version? 2 Answers

Cel/Toon shading with multiple light sources on mobile 2 Answers

Weird lighting with cel shader 1 Answer

How come edititng "_Glossiness" through script doesn't work? 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