Giter Club home page Giter Club logo

urp-toon-shader's Introduction

Toon Shader for Unity URP

A toon shader compatible with the Universal Render Pipeline.

โš ๏ธ The repository is no longer actively maintained.

๐Ÿ†• The techniques from this project are the foundation of Toon RP, a custom Scripable Render Pipeline designed for stylized rendering.

Unity Version

Developed and verified with Unity 2021.3.0f1 LTS and URP package v12.1.6.

Main

Table of Contents

Toon Shader Capabilities

Toon Icon

Surface

  • Opaque/Transparent with blending modes:
    • Alpha/Premultiply/Additive/Multiply
  • Alpha Clipping
  • Culling
    • Back/Front/Off

Color

  • 2 or 3-step ramp with configurable thresholds and smoothness
  • Ramp textures
  • Normal Maps
  • Main light
  • Additional lights
    • per-vertex or per-pixel, depending on URP settings
    • optional specular highlights
    • shadows
  • Casting and receiving shadows
  • Configurable shadow color (both in multiplicative and "pure" modes)
  • Emission
  • Rim lighting (Fresnel effect) and specular highlights with HDR color support (e.g. for bloom)
  • Anisotropic specular (e.g. for hair)
  • Environment reflections and Reflection Probes
  • Fog
  • SSAO
  • Environment Lighting
  • Baked lights and shadows
    • Dynamically receive via light probes
    • Contribute to bake process ("meta" pass)
  • Vertex Color
  • Screen-Space Shadows

Performance

  • SRP Batcher compatibility
  • GPU Instancing

Only Forward rendering path is supported.

Toon Shader (Lite) Capabilities

Toon Lite Icon

Color

  • 2-step ramp with configurable threshold and smoothness
  • Main light (per-vertex or per-pixel)
  • Casting shadows
  • Configurable shadow color
  • Fog
  • Vertex Color

Performance

  • SRP Batcher compatibility
  • GPU Instancing

Only Forward rendering path is supported.

Inverted Hull Outline

A simple and performant outline shader. Renders outlines of objects on certain layers via a Renderer Feature.

Inverted Hull Outline

See the Outline Wiki page for details.

Installation

For the latest version (Unity compatibility is specified here):

Option 1

  • Open Package Manager through Window/Package Manager
  • Click "+" and choose "Add package from git URL..."
  • Insert the URL:
https://github.com/Delt06/urp-toon-shader.git?path=Packages/com.deltation.toon-shader

Option 2

Add the following line to Packages/manifest.json:

"com.deltation.toon-shader": "https://github.com/Delt06/urp-toon-shader.git?path=Packages/com.deltation.toon-shader",

Specific Unity Version

If you want to explicitly specify a Unity version, you should use a URL of the following form:

https://github.com/Delt06/urp-toon-shader.git?path=Packages/com.deltation.toon-shader#<UNITY-VERSION>

where <UNITY-VERSION> may be either of the following:

  • 2021.3
  • 2020.3

By default, the shader is updated only for LTS versions of Unity.

Getting Started

Documentation

Examples

Bundled
  • Forest Demo
  • Toony Tiny City Demo
  • Anime Character: Arisa
  • warrior
  • fur
Released Games

Used Assets

urp-toon-shader's People

Contributors

delt06 avatar

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  avatar  avatar  avatar

urp-toon-shader's Issues

Custom Shader Creator

  • Creates a new shader from the template (original Toon Shader)
  • Make ToonShaderEditor automatically draw all properties with [CustomProperty] attribute
    • In the top most section called "Custom"
    • See shader.GetPropertyAttributes
  • Add fields for hook values. Put this hooks code into the shader.
    • Mark places with comments
  • Support all hooks
  • Extra attributes
  • Property type dropdown and values helper

Normals smoothing utility

A custom importer or editor utility to write smoothed normals to a separate channel (like uv1).
This is needed to improve outlines of sharp objects.
Outline shader should have a toggle to enable reading normals from a different channel.

When done, should be documented in wiki.

How to get transparency using the Inverted Hull Outline for a specific object

Hello, so I have this situation, where I want to make objects that are between the player and the camera transparent. I managed to achieve this for objects without outlines:

transparent platform

However, objects with the inverted hull outline look like this:

nontransparent outline platform

Even if I manage to completely fade out the object, the outline remains opaque:

object hidden but outline isn't

Is there a way to achieve transparency with a specific object's outline?

Unity 2023: Shader does not work in build mode.

I understand this repo isn't maintained or verified beyond 2021, but I figured I'd leave this here in case anyone else runs into this while trying to use a more modern version of unity.

Attempting to use these shaders in 2023.2.6f1 works in the editor, but fails during runtime: the shaders will appear pink.

After some debugging, I found this was because of the RenderPipeline tag defined:

  • It is currently defined as UniversalRenderPipeline
  • It should be UniversalPipeline

This one is really Unity's fault in the first place:
https://forum.unity.com/threads/renderpipeline-tag-changed.1468196/

Older versions of unity <2022 wouldn't actually respect this tag, and some of the documentation had it listed incorrectly.

For anyone looking for a quick workaround, you can create a "CustomToonShader" and edit the shader tags directly in the hlsl file generated from it.

Feature: Camera bias for Hull displacement

one main issue with Hull outlines is the gap it creates between the displaced verts and the underlaying mesh.
can we introduce some sort of dot product bias that multiplies the vert distance by the view direction?

in theory this would reduce any depth bleeding from neighbors

Lightweight shader

  • Base Color + Texture sampling
  • Main lights (vertex)
  • Shadow casting
  • Double ramp
  • Fog
  • GPU Instancing

Having trouble getting this to work on Android

Hi, I love the way the toon shader looks on PC, but the same settings I'm using in the editor and PC do not come out the same way on Android mobile devices.

Here's a comparison, Android:
Screenshot_20230703_215235_Sphere Guider

vs Editor:
Screenshot 2023-07-03 215212

I know that it's definitely caused by the URP renderer because turning renderer features off disables them on Android, but I've tried changing settings and nothing actually seems to work. So if there's any approach you can think of, don't hesitate to let me know.

WebGL 2.0 Support

Looking to upgrade our outline shader and have been unable to find one that works,
is there a potential caveat or setting required to make this work with WebGL 2.0?

EDITOR:
(our original, URP Toon A, URP Toon B)
image

WebGL:
image

end goal is to get it to work in WebGL and then fix the scale/push of the mesh based on a Fresnel

Long distance shadow artifact

image

Probably, need to apply shadow fade (based on world-space position) to shadow attenuation:

Light light = GetMainLight(shadow_coord);
light.shadowAttenuation = lerp(light.shadowAttenuation, 1, GetShadowFade(i.position_ws));

Note: 1 is for the absence of baked shadow

Vertex colours should be gamma corrected

When vertex colours are enabled, they should be gamma corrected before use as otherwise they will appear much lighter than they should.

I've quickly hacked a fix on my own fork if anyone wishes to use it.

Spotlight Compatabilty

Hi - I see the project is no longer maintained, but hoping someone still might see this. I have a scene with 4 directional lights and 4 spotlights. The directional lights are Mixed - Baked Indirect and the Spotlights are Realtime. I cannot get objects shaded by the toon shader to interact with the Spotlights at all. I've tried all sorts of combinations of modes and settings, but no luck.

Anyone have thoughts? I'm super new to lighting with URP.

Reflections

Two parameters

  • How much to reflect (metallic)
  • How crisp should the reflections be (smoothness)

Support skybox and reflection probes

Has anyone got this to work well with Probuilder?

Hi, been using the tool for a while, I started using Probuilder, but the issue is that the outline is broken apart.
image

Okay, so you just smooth the normals to fix it, right? Well, you can't use the smoothing utility in the toon shader because you can't input a probuilder mesh. So I use the smoothing tool in Probuilder...

image

Now that fixes the outline issue, but the faces look all weird. And changing the UV in the UV editor does nothing!

Has anyone got the outliner to work nice using Probuilder without messing up mesh faces?

I like the Smoothing tool that the shader uses because it doesn't alter the faces.

Dependencies aren't pulled with the package

In Unity 2022.2.4f1 I installed the package from git via the package manager, which should under normal circumstances pull the required dependencies into the project. However, with the urp toon shader package, I'm getting the following error:

Library\PackageCache\com.deltation.toon-shader@231de54\Assets\DELTation\ToonShader\Editor\NormalsSmoothing\NormalsSmoothingUtility.cs(2,7): error CS0246: The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?)

It leads me to believe the urp toon shader package doesn't define all the packages it actually depends on, as manually installing the "Test Framework" package from Unity's package repo gets rid of the problem.

Opaque material appears black and glitched (background repeats over it when i move the camera) But transparent works.

I'm having a trouble where a opaque material appears completely black:
image

And it glitches when i move the camera:
image

Doing that weird thing where it copies the border/background all over it.
The lite shader works, but i really needed the full one with a normal map. Also, when i set it to transparent it works:
image

I get no errors in the console, i've tried closing and opening the project, reimporting everything, nothing works.

I have unity 2021.3.8f1 and URP 12.1.7. This is probably something in my end, but i would appreciate some help if you know what could be causing this. Thank you!

Unity 2021 support

  • Implement support for the URP version of Unity 2021 on a separate branch
    • Additional Lights Shadows
    • Fix per-vertex additional lights
    • Fix DepthNormals SSAO mode
    • Fix errors in ShaderCompilation scenes (benchmark)
    • Fix ShaderCompilation BenchmarkWindow
    • Fix Toon Shader (Lite) not receiving shadows
    • Screen Space Shadows
      • image
    • Fix specular
      • image
    • Check all existing features for correctness
    • Rebake baked scene
    • Remove TCP2
    • find keywords for benchmark, run benchmark, update README
  • Add Unity version policy (i.e. corresponding branching scheme) to README

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.