Skip to content

Commit

Permalink
Clean up and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kink3d committed Jan 28, 2020
1 parent 32db8bf commit be2665f
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 86 deletions.
10 changes: 5 additions & 5 deletions Editor/LitGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ public override void DrawSurfaceInputs(MaterialEditor materialEditor)
materialEditor.TexturePropertyWithHDRColor(Labels.Emission, m_EmissionMapProp,
m_EmissionColorProp, false);

// If texture was assigned and color was black set color to white
var brightness = m_EmissionColorProp.colorValue.maxColorComponent;
if (m_EmissionMapProp.textureValue != null && !hadEmissionTexture && brightness <= 0f)
m_EmissionColorProp.colorValue = Color.white;

// Anisotropy
materialEditor.ShaderProperty(m_EnableAnisotropyProp, Labels.EnableAnisotropy);
if (m_EnableAnisotropyProp.floatValue == 1.0)
Expand All @@ -206,11 +211,6 @@ public override void DrawSurfaceInputs(MaterialEditor materialEditor)
materialEditor.TexturePropertySingleLine(Labels.Direction, m_DirectionMapProp);
}

// If texture was assigned and color was black set color to white
var brightness = m_EmissionColorProp.colorValue.maxColorComponent;
if (m_EmissionMapProp.textureValue != null && !hadEmissionTexture && brightness <= 0f)
m_EmissionColorProp.colorValue = Color.white;

// Clear Coat
materialEditor.ShaderProperty(m_EnableClearCoatProp, Labels.EnableClearCoat);
if (m_EnableClearCoatProp.floatValue == 1.0)
Expand Down
14 changes: 9 additions & 5 deletions Editor/ToonLitGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ struct PropertyNames
#region GUI
public override void GetProperties(MaterialProperty[] properties)
{
// Draw LitGUI
// Generate a LitGUI instance
// This is sealed but shares most properties
m_LitGui = new LitGUI();
m_LitGui.GetProperties(properties);

Expand All @@ -55,17 +56,18 @@ public override void GetProperties(MaterialProperty[] properties)

public override void DrawSurfaceInputs(MaterialEditor materialEditor)
{
// Draw LitGUI
// Draw LitGUI SurfaceInputs
// These are the same
m_LitGui.DrawSurfaceInputs(materialEditor);
}

public override void DrawCustom(MaterialEditor materialEditor)
{
// Surface Inputs
// Stylization Options
var stylizationOptions = EditorGUILayout.BeginFoldoutHeaderGroup(m_StylizationOptionsFoldout, Labels.StylizationOptions);
if(stylizationOptions)
{
// Toon Reflection
// Toon Reflections
materialEditor.ShaderProperty(m_EnableToonReflectionsProp, Labels.EnableToonReflections);
if (m_EnableToonReflectionsProp.floatValue == 1.0)
{
Expand All @@ -87,9 +89,11 @@ public override void DrawCustom(MaterialEditor materialEditor)
#region Keywords
public override void SetMaterialKeywords(Material material)
{
// Draw LitGUI
// Set LitGUI keywords
// These are mostly the same
m_LitGui.SetMaterialKeywords(material);

// Toon Reflections
material.SetKeyword("_TOON_REFLECTIONS", material.GetFloat(PropertyNames.EnableToonReflections) == 1.0f);
}
#endregion
Expand Down
4 changes: 1 addition & 3 deletions Editor/kTools.Shading.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"name": "kTools.Shading.Editor",
"references": [
"GUID:9e705d6a72d9a354b810376671ddb3ac"
],
"references": [],
"includePlatforms": [
"Editor"
],
Expand Down
37 changes: 14 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
# Toon Shading
![alt text][logo]
# kShading
### Shading models for Unity’s Universal Render Pipeline.

[logo]: https://cdna.artstation.com/p/assets/images/images/007/124/644/large/matt-dean-screenshot01.jpg?1503872324 "Demo Scene"
![alt text](https://github.com/Kink3d/kShading/wiki/Images/Home00.png?raw=true)
*An example of a scene using Lit Toon shading.*

A collection of "Toon" shaders based on a stepped PBR approximation.
kShading is a package of shaders for Unity's Universal Render Pipeline. It includes:
- **Lit:** A physically based shader that supports all default Universal surface properties as well as anisotropy, clear coat, sub-surface scattering and transmission.
- **Toon Lit:** A cel style shader that supports all features of the **Lit** shader but uses a stepped physical approximation BSDF.

Toon Standard Shader:
- Custom "Toon" cel style BRDF
- Specular / Smoothness
- Energy conservation approximation
- Wrap based transmission approximation
- Custom ShaderGUI
Refer to the [Wiki](https://github.com/Kink3d/kShading/wiki/Home) for more information.

Toon Water Shader:
- Uses same BRDF as above
- Voronoi based procedural waves
- Depth buffer to world position intersection for wave crests
- Approximated transmission and refraction
- Planar reflection
- Buoyancy calculation
## Instructions
- Open your project manifest file (`MyProject/Packages/manifest.json`).
- Add `"com.kink3d.shading": "https://github.com/Kink3d/kShading.git"` to the `dependencies` list.
- Open or focus on Unity Editor to resolve packages.

Contains:
- Toon Standard shader
- Toon Water shader
- Buoyancy controller
- Demo scene
- Source assets
## Requirements
- Unity 2019.3.0f3 or higher.
8 changes: 0 additions & 8 deletions Runtime.meta

This file was deleted.

29 changes: 0 additions & 29 deletions Runtime/kTools.Shading.Runtime.asmdef

This file was deleted.

7 changes: 0 additions & 7 deletions Runtime/kTools.Shading.Runtime.asmdef.meta

This file was deleted.

7 changes: 6 additions & 1 deletion ShaderLibrary/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ half DirectSpecularAnisotropic(float NoH, half LoH2, float3 halfDir,

// Anisotropic GGX Distribution multiplied by combined approximation of Visibility and Fresnel
// V * F = 1.0 / ( LoH^2 * (roughness + 0.5) )
half d = D_GGXAniso(ToH, BoH, NoH, roughnessT, roughnessB);
// If roughness is 0, returns (NdotH == 1 ? 1 : 0).
// That is, it returns 1 for perfect mirror reflection, and 0 otherwise.
half a2 = roughnessT * roughnessB;
half3 v = half3(roughnessB * ToH, roughnessT * BoH, a2 * NoH);
half s = dot(v, v);
half d = SafeDiv(a2 * a2 * a2, s * s);
return d * (LoH2 * (perceptualRoughness + 0.5) * 4.0);
}

Expand Down
7 changes: 4 additions & 3 deletions ShaderLibrary/ToonLighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// -------------------------------------
// Includes
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"

// -------------------------------------
Expand Down Expand Up @@ -62,7 +63,6 @@ half DirectSpecularAnisotropicToon(float NoH, half LoH2, float3 halfDir,
// V * F = 1.0 / ( LoH^2 * (roughness + 0.5) )
// If roughness is 0, returns (NdotH == 1 ? 1 : 0).
// That is, it returns 1 for perfect mirror reflection, and 0 otherwise.
// half d = D_GGXAniso(ToH, BoH, NoH, roughnessT, roughnessB);
half a2 = roughnessT * roughnessB;
half3 v = half3(roughnessB * ToH, roughnessT * BoH, a2 * NoH);
half s = dot(v, v);
Expand Down Expand Up @@ -121,8 +121,9 @@ half3 RadianceToon(half3 normalWS, half3 lightDirectionWS, half3 lightColor, hal
half NdotL = ceil(saturate(dot(normalWS, lightDirectionWS)));

#ifdef _SUBSURFACE
half NdotLWrap = saturate((dot(normalWS, lightDirectionWS) + subsurfaceColor) / ((1 + subsurfaceColor) * (1 + subsurfaceColor)));
return lightColor * (lightAttenuation * lerp(NdotLWrap * subsurfaceColor, NdotLWrap, NdotL));
half subsurfaceLuminance = Luminance(subsurfaceColor);
half NdotLWrap = ceil(saturate((dot(normalWS, lightDirectionWS) + subsurfaceLuminance) / ((1 + subsurfaceLuminance) * (1 + subsurfaceLuminance))));
return lightColor * (lightAttenuation * lerp(NdotLWrap * subsurfaceColor, lerp(NdotLWrap * subsurfaceColor, NdotLWrap, 1 - subsurfaceLuminance), NdotL));
#else
return lightColor * (lightAttenuation * NdotL);
#endif
Expand Down
3 changes: 1 addition & 2 deletions Tests/Editor/kTools.Shading.Editor.Tests.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"name": "kTools.Shading.Editor.Tests",
"references": [
"GUID:27619889b8ba8c24980f49ee34dbb44a",
"GUID:0acc523941302664db1f4e527237feb3",
"GUID:9e705d6a72d9a354b810376671ddb3ac"
"GUID:0acc523941302664db1f4e527237feb3"
],
"includePlatforms": [
"Editor"
Expand Down

0 comments on commit be2665f

Please sign in to comment.