SlideShare ist ein Scribd-Unternehmen logo
1 von 58
Downloaden Sie, um offline zu lesen
Learn how to create
stylised shading with
Shader Graph
Ciro Continisio - Lead Evangelist, EMEA
Who am I
3
Ciro Continisio
Lead Evangelist, EMEA
Focus: Games, more advanced uses of Unity
Past:
— Developer of my own games
— Certification tester at EA
@CiroContns
In this presentation
4
— How to get light and shading information through custom
HLSL code in Shader Graph
— Use that to create a custom toon shader
— Tips to improve your production workflow
Shader Graph
5
Shader Graph
6
Available as part of the SRPs
— Visual shader editor
— Node-based
— Instant feedback
— Now out of Preview
www.unity3d.com/shader-graph
7
What if we don’t want a
realistic rendering style?
8
9
Sayonara Wild Hearts Overland Circuit Superstars
“Stylised” look
10
— Something that doesn’t necessarily look real
– Altering the surface response to shadows and lighting
– Added abstract details (e.g. an outline)
— Exaggerating or removing details
– To direct the viewer’s attention
– To make the game easier to read
– To still look cool on less powerful hardware
Recreating a toon shader in
Shader Graph
11
12
The Legend of Zelda: Breath of the Wild
Step 1:
Getting light and shadow
information from the pipeline
13
Custom Function Node
14
— Supports custom HLSL
– Inside the node
– From an external .hlsl file
Getting main light information
1
2
3
4
5
6
7
8
#if SHADERGRAPH_PREVIEW
Direction = half3(0.5, 0.5, 0);
Color = 1;
#else
Light light = GetMainLight();
Direction = light.direction;
Color = light.color;
#endif
15
(this code will be shared at the end of the presentation)
Lambert lighting model
1
2
3
4
5
half3 LightingLambert(half3 lightColor, half3 lightDir, half3 normal)
{
half NdotL = saturate(dot(normal, lightDir));
return lightColor * NdotL;
}
16
Code from:
com.unity.render-pipelines.universal@version/ShaderLibrary/Lighting.hlsl
Dot product (of two vectors)
17
A
0.80.50-1
B
1
2
3
4
5
half3 LightingLambert(half3 lightColor, half3 lightDir, half3 normal)
{
half NdotL = saturate(dot(normal, lightDir));
return lightColor * NdotL;
}
18
Lambert lighting model
19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
void MainLight_half(float3 WorldPos, out half3 Direction, out half3 Color, out half DistanceAtten, out half ShadowAtten)
{
#if SHADERGRAPH_PREVIEW
Direction = half3(0.5, 0.5, 0);
Color = 1;
DistanceAtten = 1;
ShadowAtten = 1;
#else
#if SHADOWS_SCREEN
half4 clipPos = TransformWorldToHClip(WorldPos);
half4 shadowCoord = ComputeScreenPos(clipPos);
#else
half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
#endif
Light mainLight = GetMainLight(shadowCoord);
Direction = mainLight.direction;
Color = mainLight.color;
DistanceAtten = mainLight.distanceAttenuation;
#if !defined(_MAIN_LIGHT_SHADOWS) || defined(_RECEIVE_SHADOWS_OFF)
ShadowAtten = 1.0h;
#endif
#if SHADOWS_SCREEN
ShadowAtten = SampleScreenSpaceShadowmap(shadowCoord);
#else
ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
half shadowStrength = GetMainLightShadowStrength();
ShadowAtten = SampleShadowmap(shadowCoord, TEXTURE2D_ARGS(_MainLightShadowmapTexture,
sampler_MainLightShadowmapTexture),
shadowSamplingData, shadowStrength, false);
#endif
#endif
}
20
(will share later)
File mode
21
Link to an HLSL file external to the
graph
— Catch syntax errors
— Syntax highlighting
Lambert lighting with shadows
22
Lambert lighting with shadows
23
Put the Custom Function node in a Sub-Graph
24
#unitytips
Lambert lighting with shadows
25
0
0
0 to 1
-1 to 0
Visualise your values!
26
#unitytips
Visualise your values!
27
#unitytips
Calculating a simple specular
1
2
3
4
5
6
7
8
9
10
11
12
void DirectSpecular_half(half3 Specular, half Smoothness, half3 Direction, half3 Color, half3 WorldNormal,
half3 WorldView, out half3 Out)
{
#if SHADERGRAPH_PREVIEW
Out = 0;
#else
Smoothness = exp2(10 * Smoothness + 1);
WorldNormal = normalize(WorldNormal);
WorldView = SafeNormalize(WorldView);
Out = LightingSpecular(Color, Direction, WorldNormal, WorldView, half4(Specular, 0), Smoothness);
#endif
}
28
(will share the code later)
Calculating a simple specular
1
2
3
4
5
6
7
8
9
half3 LightingSpecular(half3 lightColor, half3 lightDir, half3 normal, half3 viewDir, half4 specular, half
smoothness)
{
float3 halfVec = SafeNormalize(float3(lightDir) + float3(viewDir));
half NdotH = saturate(dot(normal, halfVec));
half modifier = pow(NdotH, smoothness);
half3 specularReflection = specular.rgb * modifier;
return lightColor * specularReflection;
}
29
Code from:
com.unity.render-pipelines.universal@version/ShaderLibrary/Lighting.hlsl
The position of a specular effect
30
31
32
33
Lambert model with Specular
34
35
There’s more…
— Get information from Ambient lighting or GI
— Get information on additional lights in the scene (point lights)
There’s a blog post out about this: bit.ly/CustomLightingSG
Step 2:
Achieving the cartoon look
36
The final graph
38
1: Lighting and shadows
— Hard transition from light to shadows
– Only 2 colours (1 transition)
— Never really reaching full white or full black
39
Step operation
.25 .5 .750 1
Original
40
Gradient (or “ramp”) shading
0 1
0 1
Original
Ramp shaded
The hard transition on light and shadows
41
Occlusion
texture
Not the
final value
Light info from Custom Function node
Using gradients
42
Fixed mode Blend used as Fixed
#unitytips
Pre-processing textures
43
#unitytips
Pre-processing textures
44
#unitytips
2: The painted specular
45
— Specular appears as if painted with a brush
— Other materials (e.g. hair) have a more classic
“blob” specular
Creating the paint dabs
46
Using them as specular
47
3: The backlight halo
48
Gives an appreciation of the colour of the model
even when it should be actually dark
— When point of view is completely opposite the
light source, contours are lit
The backlight halo
50
4: The side shine
51
Helps to read the silhouette
— Bright thin light on the side of the model,
where light is coming from
— Often the brightest spot, reaching almost
white
Light Direction
The side shine
53
The graph
54
Base lighting
Ramp lighting
Final result
Dabs specular
Backlight rim
Side shine
The final graph
Base lighting
Ramp lighting
Dabs specular
Backlight rim
Side shine
Final result
56
Want to learn more?
Tutorial:
Introduction to Shader Graph
Tutorial:
Shader Graph: Color Node
Project:
Make a Flag Move with
Shader Graph
Subscribe now for a 3-month free trial at
unity.com/learn-premium with code: UNITECPH19
*Learn Premium is included in Unity Plus and Pro licenses. Just sign in with your Unity ID.
Questions?
bit.ly/BotWToonShader
Ciro Continisio - Lead Evangelist, EMEA
@CiroContns
#UniteCopenhagen #Unity3d

Weitere ähnliche Inhalte

Was ist angesagt?

Lighting Shading by John Hable
Lighting Shading by John HableLighting Shading by John Hable
Lighting Shading by John Hable
Naughty Dog
 
Unity3D로 풀3D web mmorpg 만들기
Unity3D로 풀3D web mmorpg 만들기Unity3D로 풀3D web mmorpg 만들기
Unity3D로 풀3D web mmorpg 만들기
JP Jung
 

Was ist angesagt? (20)

Level Design Challenges & Solutions - Mirror's Edge
Level Design Challenges & Solutions - Mirror's EdgeLevel Design Challenges & Solutions - Mirror's Edge
Level Design Challenges & Solutions - Mirror's Edge
 
Lighting Shading by John Hable
Lighting Shading by John HableLighting Shading by John Hable
Lighting Shading by John Hable
 
Shiny PC Graphics in Battlefield 3
Shiny PC Graphics in Battlefield 3Shiny PC Graphics in Battlefield 3
Shiny PC Graphics in Battlefield 3
 
The Rendering Technology of Killzone 2
The Rendering Technology of Killzone 2The Rendering Technology of Killzone 2
The Rendering Technology of Killzone 2
 
LOD and Culling Systems That Scale - Unite LA
LOD and Culling Systems That Scale  - Unite LALOD and Culling Systems That Scale  - Unite LA
LOD and Culling Systems That Scale - Unite LA
 
Practical Occlusion Culling in Killzone 3
Practical Occlusion Culling in Killzone 3Practical Occlusion Culling in Killzone 3
Practical Occlusion Culling in Killzone 3
 
Rendering Battlefield 4 with Mantle
Rendering Battlefield 4 with MantleRendering Battlefield 4 with Mantle
Rendering Battlefield 4 with Mantle
 
Secrets of CryENGINE 3 Graphics Technology
Secrets of CryENGINE 3 Graphics TechnologySecrets of CryENGINE 3 Graphics Technology
Secrets of CryENGINE 3 Graphics Technology
 
NVIDIA OpenGL and Vulkan Support for 2017
NVIDIA OpenGL and Vulkan Support for 2017NVIDIA OpenGL and Vulkan Support for 2017
NVIDIA OpenGL and Vulkan Support for 2017
 
【CEDEC2018】Scriptable Render Pipelineを使ってみよう
【CEDEC2018】Scriptable Render Pipelineを使ってみよう【CEDEC2018】Scriptable Render Pipelineを使ってみよう
【CEDEC2018】Scriptable Render Pipelineを使ってみよう
 
Physically Based Sky, Atmosphere and Cloud Rendering in Frostbite
Physically Based Sky, Atmosphere and Cloud Rendering in FrostbitePhysically Based Sky, Atmosphere and Cloud Rendering in Frostbite
Physically Based Sky, Atmosphere and Cloud Rendering in Frostbite
 
FrameGraph: Extensible Rendering Architecture in Frostbite
FrameGraph: Extensible Rendering Architecture in FrostbiteFrameGraph: Extensible Rendering Architecture in Frostbite
FrameGraph: Extensible Rendering Architecture in Frostbite
 
DirectX 11 Rendering in Battlefield 3
DirectX 11 Rendering in Battlefield 3DirectX 11 Rendering in Battlefield 3
DirectX 11 Rendering in Battlefield 3
 
Progressive Lightmapper: An Introduction to Lightmapping in Unity
Progressive Lightmapper: An Introduction to Lightmapping in UnityProgressive Lightmapper: An Introduction to Lightmapping in Unity
Progressive Lightmapper: An Introduction to Lightmapping in Unity
 
HDR Theory and practicce (JP)
HDR Theory and practicce (JP)HDR Theory and practicce (JP)
HDR Theory and practicce (JP)
 
The Unique Lighting of Mirror's Edge
The Unique Lighting of Mirror's EdgeThe Unique Lighting of Mirror's Edge
The Unique Lighting of Mirror's Edge
 
Unity3D로 풀3D web mmorpg 만들기
Unity3D로 풀3D web mmorpg 만들기Unity3D로 풀3D web mmorpg 만들기
Unity3D로 풀3D web mmorpg 만들기
 
Volumetric Lighting for Many Lights in Lords of the Fallen
Volumetric Lighting for Many Lights in Lords of the FallenVolumetric Lighting for Many Lights in Lords of the Fallen
Volumetric Lighting for Many Lights in Lords of the Fallen
 
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
Optimize your game with the Profile Analyzer - Unite Copenhagen 2019
 
Screen Space Reflections in The Surge
Screen Space Reflections in The SurgeScreen Space Reflections in The Surge
Screen Space Reflections in The Surge
 

Ähnlich wie Learn how to do stylized shading with Shader Graph – Unite Copenhagen 2019

A Bizarre Way to do Real-Time Lighting
A Bizarre Way to do Real-Time LightingA Bizarre Way to do Real-Time Lighting
A Bizarre Way to do Real-Time Lighting
Steven Tovey
 
Presentation authoring step_by_step_booklet
Presentation authoring step_by_step_bookletPresentation authoring step_by_step_booklet
Presentation authoring step_by_step_booklet
Emaax Amjad
 
Presentation authoring step_by_step_booklet
Presentation authoring step_by_step_bookletPresentation authoring step_by_step_booklet
Presentation authoring step_by_step_booklet
Emaax Amjad
 
Minimalism photorealism 3d interior
Minimalism photorealism 3d interiorMinimalism photorealism 3d interior
Minimalism photorealism 3d interior
Guning Deng
 

Ähnlich wie Learn how to do stylized shading with Shader Graph – Unite Copenhagen 2019 (20)

Rendering basics
Rendering basicsRendering basics
Rendering basics
 
GDC 2018 Level Design Workshop - How To Light A Level - slides.pdf
GDC 2018 Level Design Workshop - How To Light A Level - slides.pdfGDC 2018 Level Design Workshop - How To Light A Level - slides.pdf
GDC 2018 Level Design Workshop - How To Light A Level - slides.pdf
 
Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019Custom SRP and graphics workflows - Unite Copenhagen 2019
Custom SRP and graphics workflows - Unite Copenhagen 2019
 
Clean architecture for shaders unite2019
Clean architecture for shaders unite2019Clean architecture for shaders unite2019
Clean architecture for shaders unite2019
 
Develop2012 deferred sanchez_stachowiak
Develop2012 deferred sanchez_stachowiakDevelop2012 deferred sanchez_stachowiak
Develop2012 deferred sanchez_stachowiak
 
Lighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
Lighting & Shading in OpenGL Non-Photorealistic Rendering.pptLighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
Lighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
 
Applying your Convolutional Neural Networks
Applying your Convolutional Neural NetworksApplying your Convolutional Neural Networks
Applying your Convolutional Neural Networks
 
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
 
A Bizarre Way to do Real-Time Lighting
A Bizarre Way to do Real-Time LightingA Bizarre Way to do Real-Time Lighting
A Bizarre Way to do Real-Time Lighting
 
esapro_2_manual_en.pdf
esapro_2_manual_en.pdfesapro_2_manual_en.pdf
esapro_2_manual_en.pdf
 
What's new in Shader Graph: ready for production – Unite Copenhagen 2019
What's new in Shader Graph: ready for production – Unite Copenhagen 2019What's new in Shader Graph: ready for production – Unite Copenhagen 2019
What's new in Shader Graph: ready for production – Unite Copenhagen 2019
 
Programmers guide
Programmers guideProgrammers guide
Programmers guide
 
Advanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APIAdvanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics API
 
student 3d max
student 3d maxstudent 3d max
student 3d max
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 
OpenGL basics
OpenGL basicsOpenGL basics
OpenGL basics
 
The Next Generation of PhyreEngine
The Next Generation of PhyreEngineThe Next Generation of PhyreEngine
The Next Generation of PhyreEngine
 
Presentation authoring step_by_step_booklet
Presentation authoring step_by_step_bookletPresentation authoring step_by_step_booklet
Presentation authoring step_by_step_booklet
 
Presentation authoring step_by_step_booklet
Presentation authoring step_by_step_bookletPresentation authoring step_by_step_booklet
Presentation authoring step_by_step_booklet
 
Minimalism photorealism 3d interior
Minimalism photorealism 3d interiorMinimalism photorealism 3d interior
Minimalism photorealism 3d interior
 

Mehr von Unity Technologies

Mehr von Unity Technologies (20)

Build Immersive Worlds in Virtual Reality
Build Immersive Worlds  in Virtual RealityBuild Immersive Worlds  in Virtual Reality
Build Immersive Worlds in Virtual Reality
 
Augmenting reality: Bring digital objects into the real world
Augmenting reality: Bring digital objects into the real worldAugmenting reality: Bring digital objects into the real world
Augmenting reality: Bring digital objects into the real world
 
Let’s get real: An introduction to AR, VR, MR, XR and more
Let’s get real: An introduction to AR, VR, MR, XR and moreLet’s get real: An introduction to AR, VR, MR, XR and more
Let’s get real: An introduction to AR, VR, MR, XR and more
 
Using synthetic data for computer vision model training
Using synthetic data for computer vision model trainingUsing synthetic data for computer vision model training
Using synthetic data for computer vision model training
 
The Tipping Point: How Virtual Experiences Are Transforming Global Industries
The Tipping Point: How Virtual Experiences Are Transforming Global IndustriesThe Tipping Point: How Virtual Experiences Are Transforming Global Industries
The Tipping Point: How Virtual Experiences Are Transforming Global Industries
 
Unity Roadmap 2020: Live games
Unity Roadmap 2020: Live games Unity Roadmap 2020: Live games
Unity Roadmap 2020: Live games
 
Unity Roadmap 2020: Core Engine & Creator Tools
Unity Roadmap 2020: Core Engine & Creator ToolsUnity Roadmap 2020: Core Engine & Creator Tools
Unity Roadmap 2020: Core Engine & Creator Tools
 
How ABB shapes the future of industry with Microsoft HoloLens and Unity - Uni...
How ABB shapes the future of industry with Microsoft HoloLens and Unity - Uni...How ABB shapes the future of industry with Microsoft HoloLens and Unity - Uni...
How ABB shapes the future of industry with Microsoft HoloLens and Unity - Uni...
 
Unity XR platform has a new architecture – Unite Copenhagen 2019
Unity XR platform has a new architecture – Unite Copenhagen 2019Unity XR platform has a new architecture – Unite Copenhagen 2019
Unity XR platform has a new architecture – Unite Copenhagen 2019
 
Turn Revit Models into real-time 3D experiences
Turn Revit Models into real-time 3D experiencesTurn Revit Models into real-time 3D experiences
Turn Revit Models into real-time 3D experiences
 
How Daimler uses mobile mixed realities for training and sales - Unite Copenh...
How Daimler uses mobile mixed realities for training and sales - Unite Copenh...How Daimler uses mobile mixed realities for training and sales - Unite Copenh...
How Daimler uses mobile mixed realities for training and sales - Unite Copenh...
 
How Volvo embraced real-time 3D and shook up the auto industry- Unite Copenha...
How Volvo embraced real-time 3D and shook up the auto industry- Unite Copenha...How Volvo embraced real-time 3D and shook up the auto industry- Unite Copenha...
How Volvo embraced real-time 3D and shook up the auto industry- Unite Copenha...
 
QA your code: The new Unity Test Framework – Unite Copenhagen 2019
QA your code: The new Unity Test Framework – Unite Copenhagen 2019QA your code: The new Unity Test Framework – Unite Copenhagen 2019
QA your code: The new Unity Test Framework – Unite Copenhagen 2019
 
Engineering.com webinar: Real-time 3D and digital twins: The power of a virtu...
Engineering.com webinar: Real-time 3D and digital twins: The power of a virtu...Engineering.com webinar: Real-time 3D and digital twins: The power of a virtu...
Engineering.com webinar: Real-time 3D and digital twins: The power of a virtu...
 
Supplying scalable VR training applications with Innoactive - Unite Copenhage...
Supplying scalable VR training applications with Innoactive - Unite Copenhage...Supplying scalable VR training applications with Innoactive - Unite Copenhage...
Supplying scalable VR training applications with Innoactive - Unite Copenhage...
 
XR and real-time 3D in automotive digital marketing strategies | Visionaries ...
XR and real-time 3D in automotive digital marketing strategies | Visionaries ...XR and real-time 3D in automotive digital marketing strategies | Visionaries ...
XR and real-time 3D in automotive digital marketing strategies | Visionaries ...
 
Real-time CG animation in Unity: unpacking the Sherman project - Unite Copenh...
Real-time CG animation in Unity: unpacking the Sherman project - Unite Copenh...Real-time CG animation in Unity: unpacking the Sherman project - Unite Copenh...
Real-time CG animation in Unity: unpacking the Sherman project - Unite Copenh...
 
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
 
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
 
How to Improve Visual Rendering Quality in VR - Unite Copenhagen 2019
How to Improve Visual Rendering Quality in VR - Unite Copenhagen 2019How to Improve Visual Rendering Quality in VR - Unite Copenhagen 2019
How to Improve Visual Rendering Quality in VR - Unite Copenhagen 2019
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Learn how to do stylized shading with Shader Graph – Unite Copenhagen 2019

  • 1.
  • 2. Learn how to create stylised shading with Shader Graph Ciro Continisio - Lead Evangelist, EMEA
  • 3. Who am I 3 Ciro Continisio Lead Evangelist, EMEA Focus: Games, more advanced uses of Unity Past: — Developer of my own games — Certification tester at EA @CiroContns
  • 4. In this presentation 4 — How to get light and shading information through custom HLSL code in Shader Graph — Use that to create a custom toon shader — Tips to improve your production workflow
  • 6. Shader Graph 6 Available as part of the SRPs — Visual shader editor — Node-based — Instant feedback — Now out of Preview www.unity3d.com/shader-graph
  • 7. 7
  • 8. What if we don’t want a realistic rendering style? 8
  • 9. 9 Sayonara Wild Hearts Overland Circuit Superstars
  • 10. “Stylised” look 10 — Something that doesn’t necessarily look real – Altering the surface response to shadows and lighting – Added abstract details (e.g. an outline) — Exaggerating or removing details – To direct the viewer’s attention – To make the game easier to read – To still look cool on less powerful hardware
  • 11. Recreating a toon shader in Shader Graph 11
  • 12. 12 The Legend of Zelda: Breath of the Wild
  • 13. Step 1: Getting light and shadow information from the pipeline 13
  • 14. Custom Function Node 14 — Supports custom HLSL – Inside the node – From an external .hlsl file
  • 15. Getting main light information 1 2 3 4 5 6 7 8 #if SHADERGRAPH_PREVIEW Direction = half3(0.5, 0.5, 0); Color = 1; #else Light light = GetMainLight(); Direction = light.direction; Color = light.color; #endif 15 (this code will be shared at the end of the presentation)
  • 16. Lambert lighting model 1 2 3 4 5 half3 LightingLambert(half3 lightColor, half3 lightDir, half3 normal) { half NdotL = saturate(dot(normal, lightDir)); return lightColor * NdotL; } 16 Code from: com.unity.render-pipelines.universal@version/ShaderLibrary/Lighting.hlsl
  • 17. Dot product (of two vectors) 17 A 0.80.50-1 B
  • 18. 1 2 3 4 5 half3 LightingLambert(half3 lightColor, half3 lightDir, half3 normal) { half NdotL = saturate(dot(normal, lightDir)); return lightColor * NdotL; } 18
  • 20. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 void MainLight_half(float3 WorldPos, out half3 Direction, out half3 Color, out half DistanceAtten, out half ShadowAtten) { #if SHADERGRAPH_PREVIEW Direction = half3(0.5, 0.5, 0); Color = 1; DistanceAtten = 1; ShadowAtten = 1; #else #if SHADOWS_SCREEN half4 clipPos = TransformWorldToHClip(WorldPos); half4 shadowCoord = ComputeScreenPos(clipPos); #else half4 shadowCoord = TransformWorldToShadowCoord(WorldPos); #endif Light mainLight = GetMainLight(shadowCoord); Direction = mainLight.direction; Color = mainLight.color; DistanceAtten = mainLight.distanceAttenuation; #if !defined(_MAIN_LIGHT_SHADOWS) || defined(_RECEIVE_SHADOWS_OFF) ShadowAtten = 1.0h; #endif #if SHADOWS_SCREEN ShadowAtten = SampleScreenSpaceShadowmap(shadowCoord); #else ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData(); half shadowStrength = GetMainLightShadowStrength(); ShadowAtten = SampleShadowmap(shadowCoord, TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_MainLightShadowmapTexture), shadowSamplingData, shadowStrength, false); #endif #endif } 20 (will share later)
  • 21. File mode 21 Link to an HLSL file external to the graph — Catch syntax errors — Syntax highlighting
  • 22. Lambert lighting with shadows 22
  • 23. Lambert lighting with shadows 23
  • 24. Put the Custom Function node in a Sub-Graph 24 #unitytips
  • 25. Lambert lighting with shadows 25 0 0 0 to 1 -1 to 0
  • 28. Calculating a simple specular 1 2 3 4 5 6 7 8 9 10 11 12 void DirectSpecular_half(half3 Specular, half Smoothness, half3 Direction, half3 Color, half3 WorldNormal, half3 WorldView, out half3 Out) { #if SHADERGRAPH_PREVIEW Out = 0; #else Smoothness = exp2(10 * Smoothness + 1); WorldNormal = normalize(WorldNormal); WorldView = SafeNormalize(WorldView); Out = LightingSpecular(Color, Direction, WorldNormal, WorldView, half4(Specular, 0), Smoothness); #endif } 28 (will share the code later)
  • 29. Calculating a simple specular 1 2 3 4 5 6 7 8 9 half3 LightingSpecular(half3 lightColor, half3 lightDir, half3 normal, half3 viewDir, half4 specular, half smoothness) { float3 halfVec = SafeNormalize(float3(lightDir) + float3(viewDir)); half NdotH = saturate(dot(normal, halfVec)); half modifier = pow(NdotH, smoothness); half3 specularReflection = specular.rgb * modifier; return lightColor * specularReflection; } 29 Code from: com.unity.render-pipelines.universal@version/ShaderLibrary/Lighting.hlsl
  • 30. The position of a specular effect 30
  • 31. 31
  • 32. 32
  • 33. 33
  • 34. Lambert model with Specular 34
  • 35. 35 There’s more… — Get information from Ambient lighting or GI — Get information on additional lights in the scene (point lights) There’s a blog post out about this: bit.ly/CustomLightingSG
  • 36. Step 2: Achieving the cartoon look 36
  • 38. 38 1: Lighting and shadows — Hard transition from light to shadows – Only 2 colours (1 transition) — Never really reaching full white or full black
  • 39. 39 Step operation .25 .5 .750 1 Original
  • 40. 40 Gradient (or “ramp”) shading 0 1 0 1 Original Ramp shaded
  • 41. The hard transition on light and shadows 41 Occlusion texture Not the final value Light info from Custom Function node
  • 42. Using gradients 42 Fixed mode Blend used as Fixed #unitytips
  • 45. 2: The painted specular 45 — Specular appears as if painted with a brush — Other materials (e.g. hair) have a more classic “blob” specular
  • 47. Using them as specular 47
  • 48. 3: The backlight halo 48 Gives an appreciation of the colour of the model even when it should be actually dark — When point of view is completely opposite the light source, contours are lit
  • 49.
  • 51. 4: The side shine 51 Helps to read the silhouette — Bright thin light on the side of the model, where light is coming from — Often the brightest spot, reaching almost white
  • 54. The graph 54 Base lighting Ramp lighting Final result Dabs specular Backlight rim Side shine
  • 55. The final graph Base lighting Ramp lighting Dabs specular Backlight rim Side shine Final result
  • 56. 56
  • 57. Want to learn more? Tutorial: Introduction to Shader Graph Tutorial: Shader Graph: Color Node Project: Make a Flag Move with Shader Graph Subscribe now for a 3-month free trial at unity.com/learn-premium with code: UNITECPH19 *Learn Premium is included in Unity Plus and Pro licenses. Just sign in with your Unity ID.
  • 58. Questions? bit.ly/BotWToonShader Ciro Continisio - Lead Evangelist, EMEA @CiroContns #UniteCopenhagen #Unity3d