Giter Site home page Giter Site logo

snutihq / toon-shader Goto Github PK

View Code? Open in Web Editor NEW
442.0 11.0 57.0 13.34 MB

A character focused Toon Shader for Unity using Shader Graph.

Home Page: https://www.youtube.com/watch?v=g8eBXCgWwrk

License: MIT License

C# 100.00%
toon-shader shader-graph unity shader lights shadows

toon-shader's Introduction

Awesome Toon Shader

A character focused Toon Shader for Unity using Shader Graph. Using a C# helper script on the object to supply lighting data to the material, making it flexible and programmable. While it's not the most optimised and ideal approach for every scenario, it's a different take on toon shading and passing lighting data.

Improvements, forks and pull requests are welcome. Be sure to check out the tutorial to follow the process of building this shader from scratch.

Tutorial

How to build this shader from scratch:

Awesomeness & Features

  • Supports multiple light sources and types.
  • Adjustable shading bands.
  • Beautiful gloss and Fresnel effects.
  • Shade detection with Raycasting ("faking" reciving shadows on an unlit material).

Drawbacks

  • Not ideal for enviroment shading (In it's current configuration, could be repurposed to work better).
  • Doesn't receive shadows directly, but fakes it by turning light sources off/on, by testing visibility with raycasting.
  • Lighting is relative to the mesh center rather than the mesh surface position. This difference is usually not noticable, apart from when you are standing on top of a light source.

How to use

  1. Apply the AwesomeToonHelper script to your character (On the Game object with the Mesh renderer)
  2. Create a material with the AwesomeToon shader, and set this as the SourceMaterial input on the Awesome Toon Helper component.
  3. On the material set a Shading Gradient to one of the gradients in this repo, or make your own.
  4. Play around!

Material instancing (Sharing material between many characters)

By default the script will take a copy of your material and apply it to the model. Any changes to this copy (instance) will not be retained, this allows many characters to share the same source material and have individual lighting data. If you are making changes to the source material, uncheck instance material temporarily.

Troubleshoot

Error: Could not find Sub Graph...

If the Awesome Toon Sub node is not found in the Awesome Toon shader, delete it and add it back in again, then save.

Everything looks bright and washedout

Depending on the lighting setup of your scene, you might have to delete the "Baked GI" node for things to look right.

Shade detection doesn't work

Raycasts need a mask to work, set it to Default and add other relevant layers to the mark for it to detect if light sources are obstructed.

toon-shader's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

toon-shader's Issues

Interesting Behaviour

First off, very cool. I am still playing with it, but it's looking gorgeous.

I'm not entirely certain about the Ambient node. I was stuck for a while trying to work out why everything was tinted blue (I added an invert color node to test what on earth was happening).

image

You can see that the result in the Add node does not match the final result. Which is very odd in of itself.

I found that if I removed the Ambient light node, everything worked as expected. So I had a bit of a hunt, and found that even though my Environmental Lighting (EL) was set to use the Skybox color, I had been playing with an ambient color a little while back. If I changed the EL to black, it resolved the problem also.

image

So even though I wasn't using the Ambient color in EL, this node still applied it. Why it didn't apply it to the result of the Add node, I do not know. But maybe an option to scale it in here is a solution (a multiply node to reduce the effect of the ambient light?)

image

It's odd that it is applied even though the Ambient light is not being used in the scene, and perhaps there is a way to prevent it from happening, but there are some pretty cool effects you can create by allowing scaling of the ambient lighting (perhaps not intuitive, but fun!)

Error in Graph at Assets/Toon-Shader-master/Awesome Toon/AwesomeToon.shadergraph at node AwesomeToon Sub: Could not find Sub Graph asset with GUID af8ea54a097adc649ac95deb23fbf291

Unity 2020.1.3.f1
URP.

After downloading the as a zip from github and importing into my project I get the following error.

Error in Graph at Assets/Toon-Shader-master/Awesome Toon/AwesomeToon.shadergraph at node AwesomeToon Sub: Could not find Sub Graph asset with GUID af8ea54a097adc649ac95deb23fbf291.
UnityEditor.Experimental.AssetImporters.ScriptedImporter:GenerateAssetData(AssetImportContext)
UnityEditorInternal.InternalEditorUtility:ProjectWindowDrag(HierarchyProperty, Boolean)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

Support for Gloss maps

First off, I'm not very experienced with Unity, so if there's might be an easy solution I'm missing.

I'd like to add support for a Gloss map, or what Unity calls a Metallic/Specular map. I want this so I can define parts of my model as glossy/shiny and parts duller. Think, an knight wearing shiny armour and dull cloth pants.

I'll give it a shot myself, and if I figure it out, I'll submit a PR. Would like some help though

Support for Emissions

Screen Shot 2020-06-27 at 23 47 19

I'm trying to add lights using emissions, but they aren't affecting the toon shader. Please help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.