feat: add SGE files

master
uc-hoba 10 months ago
parent 14c9055028
commit f4efa953a9
  1. 8
      Assets/Plugins.meta
  2. 8
      Assets/Plugins/ShaderGraphEssentials.meta
  3. 87
      Assets/Plugins/ShaderGraphEssentials/ChangeLog.txt
  4. 14
      Assets/Plugins/ShaderGraphEssentials/ChangeLog.txt.meta
  5. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin.meta
  6. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor.meta
  7. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/GettingStarted.meta
  8. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/GettingStarted/Data.meta
  9. BIN
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/GettingStarted/Data/SGE_key_128x128.png
  10. 108
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/GettingStarted/Data/SGE_key_128x128.png.meta
  11. 481
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/GettingStarted/GettingStartedWindow.cs
  12. 18
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/GettingStarted/GettingStartedWindow.cs.meta
  13. 27
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/GettingStarted/SGESettings.cs
  14. 18
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/GettingStarted/SGESettings.cs.meta
  15. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base.meta
  16. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Resources.meta
  17. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Resources/Styles.meta
  18. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Resources/Styles/Controls.meta
  19. 24
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Resources/Styles/Controls/NoiseDimensionEnumControlView.uss
  20. 10
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Resources/Styles/Controls/NoiseDimensionEnumControlView.uss.meta
  21. 24
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Resources/Styles/Controls/NoisePeriodicityEnumControlView.uss
  22. 10
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Resources/Styles/Controls/NoisePeriodicityEnumControlView.uss.meta
  23. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts.meta
  24. 289
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/BakeTextureManager.cs
  25. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/BakeTextureManager.cs.meta
  26. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Controls.meta
  27. 63
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Controls/LabelControl.cs
  28. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Controls/LabelControl.cs.meta
  29. 139
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Controls/NoiseDimensionEnumControl.cs
  30. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Controls/NoiseDimensionEnumControl.cs.meta
  31. 139
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Controls/NoisePeriodicityEnumControl.cs
  32. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Controls/NoisePeriodicityEnumControl.cs.meta
  33. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Nodes.meta
  34. 162
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Nodes/BakeTextureNode.cs
  35. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Nodes/BakeTextureNode.cs.meta
  36. 419
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Nodes/NoiseNode.cs
  37. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Nodes/NoiseNode.cs.meta
  38. 54
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Nodes/NormalFromHeightVectorNode.cs
  39. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Nodes/NormalFromHeightVectorNode.cs.meta
  40. 51
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Nodes/NormalUOffsetNode.cs
  41. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Nodes/NormalUOffsetNode.cs.meta
  42. 51
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Nodes/NormalVOffsetNode.cs
  43. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Nodes/NormalVOffsetNode.cs.meta
  44. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises.meta
  45. 45
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/NoiseBase.cs
  46. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/NoiseBase.cs.meta
  47. 27
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/NoiseCombine.cs
  48. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/NoiseCombine.cs.meta
  49. 60
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/NoiseDimension.cs
  50. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/NoiseDimension.cs.meta
  51. 59
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/NoisePeriodicity.cs
  52. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/NoisePeriodicity.cs.meta
  53. 606
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/NoiseShaderUtils.cs
  54. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/NoiseShaderUtils.cs.meta
  55. 26
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/NoiseType.cs
  56. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/NoiseType.cs.meta
  57. 129
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/PerlinNoise.cs
  58. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/PerlinNoise.cs.meta
  59. 85
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/SimplexNoise.cs
  60. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/SimplexNoise.cs.meta
  61. 101
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/ValueNoise.cs
  62. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_Base/Scripts/Noises/ValueNoise.cs.meta
  63. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP.meta
  64. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Master_Nodes.meta
  65. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Master_Nodes/CustomLit.meta
  66. 36
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Master_Nodes/CustomLit/SGECustomLitMasterNode.cs
  67. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Master_Nodes/CustomLit/SGECustomLitMasterNode.cs.meta
  68. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Master_Nodes/SimpleLit.meta
  69. 36
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Master_Nodes/SimpleLit/SGESimpleLitMasterNode.cs
  70. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Master_Nodes/SimpleLit/SGESimpleLitMasterNode.cs.meta
  71. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Master_Nodes/Unlit.meta
  72. 53
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Master_Nodes/Unlit/SGEUnlitMasterNode.cs
  73. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Master_Nodes/Unlit/SGEUnlitMasterNode.cs.meta
  74. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders.meta
  75. 194
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/CustomLitForwardPass.hlsl
  76. 9
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/CustomLitForwardPass.hlsl.meta
  77. 138
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/CustomLitGBufferPass.hlsl
  78. 7
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/CustomLitGBufferPass.hlsl.meta
  79. 33
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_CustomLightingInternal.hlsl
  80. 9
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_CustomLightingInternal.hlsl.meta
  81. 33
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_CustomLightingInternalFull.hlsl
  82. 10
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_CustomLightingInternalFull.hlsl.meta
  83. 63
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_DefaultCustomLighting.hlsl
  84. 9
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_DefaultCustomLighting.hlsl.meta
  85. 965
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_DefaultCustomLightingGraph.shadergraph
  86. 10
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_DefaultCustomLightingGraph.shadergraph.meta
  87. 72
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_ToonLighting.hlsl
  88. 9
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_ToonLighting.hlsl.meta
  89. 137
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SimpleLitForwardPass.hlsl
  90. 9
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SimpleLitForwardPass.hlsl.meta
  91. 138
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SimpleLitGBufferPass.hlsl
  92. 7
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SimpleLitGBufferPass.hlsl.meta
  93. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Templates.meta
  94. 130
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Templates/PassMesh.template
  95. 7
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Templates/PassMesh.template.meta
  96. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/URPAssemblySpecific.meta
  97. 8
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/URPAssemblySpecific/AssetCallbacks.meta
  98. 76
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/URPAssemblySpecific/AssetCallbacks/CreateSGECustomLitShaderGraph.cs
  99. 11
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/URPAssemblySpecific/AssetCallbacks/CreateSGECustomLitShaderGraph.cs.meta
  100. 47
      Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/URPAssemblySpecific/AssetCallbacks/CreateSGESimpleLitShaderGraph.cs
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: aecdca8e9f9827a4686c85e26b8e3100
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bf3d25e31752a004cb3483acbc45007f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,87 @@
Change Log:
1.0.0 - Initial Release.
1.0.1 - Fixed a bug in SGESimpleLit and SGEUnlit master nodes that made it impossible to work on Mac/Unix systems.
1.0.2 - Uploaded a new 2019.1 compatible version.
- The 2018.3 version is unchanged.
1.0.2b - Fixed an issue with permission which was creating errors on load with a 2019.1 project.
1.0.2c - Turns out the previous fix was working on windows only; so this version add the permission fix on mac.
1.0.3 - Added support up to ShaderGraph 5.13.0.
1.0.4 - 2019.1 - LWRP version now requires ShaderGraph 5.13.0 or newer (if you're on 2018.3 or on HDRP you're fine)
- If you don't want to update to 5.13.0, please contact me.
- Added new Custom Lighting master node (LWRP - 2019.1 only)
- Added new Toon Lighting master node example (LWRP - 2019.1 only)
- In all master nodes, added a "CustomEditor" setting so you can specify custom editor scripts like in regular shaders.
1.0.5 - Updated SimpleLit master node to follow what Unity's been doing on LWRP/SimpleLit shader.
- Removed Glossiness node (it wasn't used)
- Renamed Shininess to Smoothness
Added a new fix for "Internal Errors" that some users were getting when opening ShaderGraphEssentials the first time (and sometimes on later open too).
1.0.6 - Introduced the "Getting Started" window. It's useful to both existing and new users!
- Restructured how file are organized in the plugin. Also moved the entire plugin from Assets/ShaderGraphEssentials to Assets/Plugins/ShaderGraphEssentials. This has been requested by many users as to reduced the visual clutter of the root folder (as the plugin can't be moved at the moment!).
- Move the menu items from SGE to Tools/ShaderGraph Essentials for the same reasons.
1.0.7 - Fixed a bug with the default custom lighting graph, referencing a wrong path (hlsl file).
- Fixed a minor bug that was throwing an GUI error the first time the Getting Started window was opened
- Fixed a bug that blocked the Getting Started window to import the HDRP package or demo scenes
1.0.8 - If you're on Unity 2019.1.3 or newer and using LWRP, then you need to update to LWRP/ShaderGraph 5.16.1 when getting this version.
- Fixed a bug in SimpleLit / CustomLit shaders. The bug was giving errors in editor, but the shader was still working in editor and in builds.
- Fixed the version number in Getting Started window being wrong.
1.0.9 - Only impacts 2019.2; if you're on 2018 or 2019.1 it's not useful to update.
- Add 2019.2 support (require ShaderGraph / SRP 6.9.1 and not 6.9.0 which contains a bug with custom functions and subgraphs). If you update from 2019.1, please delete the ShaderGraph Essentials folder and re-download the new one after upgrade to make sure there're no leftover files.
- Removed some demo shaders that were unused and fixed minor bugs in other demo shaders
1.1.0 - Added new setting in all SGE master nodes: "Update Vertex Position".
- Added new water demo scene and shaders, with vertex displacement and depth-based foam to showcase the new setting
- Red-did the entire SGE asset store page, marketing visuals and added an extensive online doc
1.1.1 - Added support for Unity 2019.3 (2019.3.0b11 and above).
1.1.2 - Fixed a compilation error starting from 2019.3.0f6 (with URP 7.1.8).
- Improving SGE registration. This should solve errors when updating URP or Unity and getting "is inaccessible error". If you still have an issue similar to this, please contact me on the discord server.
- Better support if you have ShaderGraph package locally in your asset folder.
- Typo fix: "Periode" to "Period".
1.1.3 - Only impact 2019.3: Fixed shader compilation error when using SGE master nodes on Android VR.
1.1.4 - Only impact 2019.3: Now supports and requires URP / HDRP 7.2.1.
1.1.5 - Added 2020.1 support.
- 2020.1 only: Completely changed how the plugin integrates with ShaderGraph. It is much more robust, and will be backported to 2019.x later if no issues are found.
- 2020.1 only: Fixed possible NaNs error when using 3D perlin Ridge noise node. Will be backported later.
- 2020.1 only: Renamed all "LWRP" instances to "URP". Will be backported to 2019.3 later.
- 2020.1 only: Fixed all scripts warnings.
1.1.6 - Completely changed how the plugin integrates with ShaderGraph. It is much more robust and future proof!
- Fixed possible NaNs error when using 3D perlin Ridge noise node.
- Fixed all scripts warnings.
1.1.7 - Added 2020.2 support.
1.1.9 - Changes for 2020.2 only (so need to update if you're not on it). Updated version to support URP 10.3.1, which requires Unity 2020.2.4f1 and up.
If you are on 2020.2, please update to this plugin and Unity versions.
1.1.10 - Fixes for 2020.2 / 2020.3 / 2021.1: fixed SGE Graphs settings not being upgrade properly from pre-2020.2 versions.
1.1.11 - Fixed a visual artefact in Simplex noise implementation (all Unity versions).
1.1.12 - Added support for Unity 2021.2. Doesn't change anything if you are on a previous version.
1.1.13 - [2021.2] Fixed SimpleLit and CustomLit shaders not working with Vulkan rendering. Doesn't change anything if you are on a previous version.
1.1.14 - [2021.2] Updated the 2021.2 version from 2021.2.0 to 2021.2.16, as the latest version introduced a breaking change. As such, 2021.2.16 is now needed as minimum version if you're on 2021.2.
1.1.15 - Added support for 2022.1
- [2021.2/3] Fixed Alpha blending mode not working properly with the SimpleLit and CustomLit master nodes.
1.1.16 - Added support for 2022.2, 2022.3 and 2023.1.
1.1.17 - Fixed realtime shadows in 2022.3 and 2023.1

@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: 01906810e0ab0264288634532a607697
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 141671
packageName: ShaderGraph Essentials
packageVersion: 1.1.17
assetPath: Assets/Plugins/ShaderGraphEssentials/ChangeLog.txt
uploadId: 607369

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 13ea453eb7829fa41983a355022348ad
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 89bd8c9a72dfe7e40910f88c408c350e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 73b310222da1fcf4fba1fa91066b58f2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ea6dabab92f8a1841baa2bb3320b840b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,108 @@
fileFormatVersion: 2
guid: 830d6e48d2c197a4aacb6e3da898cc28
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 2
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: 3
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
- serializedVersion: 2
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: 3
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 141671
packageName: ShaderGraph Essentials
packageVersion: 1.1.17
assetPath: Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/GettingStarted/Data/SGE_key_128x128.png
uploadId: 607369

@ -0,0 +1,481 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.WSA;
using Application = UnityEngine.Application;
namespace ShaderGraphEssentials
{
[InitializeOnLoad]
public class GettingStartedWindowShow
{
private const string SettingsPath = "Assets/Plugins/ShaderGraphEssentials/Settings.asset";
static GettingStartedWindowShow()
{
var settings = AssetDatabase.LoadAssetAtPath(SettingsPath, typeof(SGESettings)) as SGESettings;
bool showWindow = !(settings && !settings.OpenGettingStartedWindow);
if (showWindow)
{
EditorApplication.update += OnUpdate;
}
}
private static void OnUpdate()
{
EditorApplication.update -= OnUpdate;
SGESettings newSettings = ScriptableObject.CreateInstance<SGESettings>();
AssetDatabase.CreateAsset(newSettings, SettingsPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
GettingStartedWindow window = (GettingStartedWindow)EditorWindow.GetWindow(typeof(GettingStartedWindow));
window.Show();
}
}
public class GettingStartedWindow : EditorWindow
{
private const string SGEVersion = "1.1.17";
private const string SGEPath = "Assets/Plugins/ShaderGraphEssentials";
private const string SGELogoFileName = "Plugin/Editor/GettingStarted/Data/SGE_key_128x128.png";
private const string ManualFileName = "ShaderGraphEssentials_Documentation.pdf";
private const string ChangeLogName = "ChangeLog.txt";
private const string NoiseScene = BaseDemoPath + "/Scenes/ShaderGraphEssentials_Demo.unity";
private const string SimpleLitScene = URPDemoPath + "/Scenes/ShaderGraphEssentials_Showcase_SimpleLit.unity";
private const string ToonLitScene = URPDemoPath + "/Scenes/ShaderGraphEssentials_Showcase_ToonLit.unity";
private const string WaterScene = URPDemoPath + "/Scenes/ShaderGraphEssentials_Showcase_Water.unity";
private const string DemoFolderPath = "DemoScenes";
private const string BaseDemoPath = "DemoScenes/Demo_Base";
private const string URPDemoPath = "DemoScenes/Demo_URP";
private const string BasePluginPath = "Plugin/Editor/Plugin_Base";
private const string URPPluginPath = "Plugin/Editor/Plugin_URP";
private const string URPPluginPackagePath = "Packages/SGE_URP.unitypackage";
private const string URPDemoPackagePath = "Packages/SGE_URP_Demo.unitypackage";
private const string HDRPPluginPackagePath = "Packages/SGE_HDRP.unitypackage";
private const string HDRPDemoPackagePath = "Packages/SGE_HDRP_Demo.unitypackage";
private GUIStyle _wrapLabelStyle;
private Texture2D _logoTexture;
private bool _hasError;
// various sizes
private const int LogoTextureSize = 128;
private const int Margin = 10;
private const int ButtonHeight = 30;
private const int ButtonWidth = 120;
private const int LargeButtonWidth = 160;
private Vector2 _scrollPosition = Vector2.zero;
private Vector2 _defaultWindowSize = Vector2.zero;
private bool _initialized = false;
[MenuItem("Tools/ShaderGraph Essentials/Getting Started")]
static void Init()
{
// Get existing open window or if none, make a new one:
GettingStartedWindow window = (GettingStartedWindow)EditorWindow.GetWindow(typeof(GettingStartedWindow));
window.Show();
}
private bool GetInternalFile(string pathFromSGE, out string fullPath)
{
fullPath = Path.Combine(SGEPath, pathFromSGE);
if (File.Exists(fullPath))
return true;
Debug.LogError("File " + fullPath + " doesn't exist. Did you move the ShaderGraphEssentials root folder from Assets/ ? Unfortunately this isn't supported yet.");
_hasError = true;
return false;
}
private void Awake()
{
string fullLogoPath;
if (!GetInternalFile(SGELogoFileName, out fullLogoPath))
{
return;
}
_logoTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(fullLogoPath);
}
private bool OpenFileWithDefaultEditor(string path)
{
string fullPath;
if (!GetInternalFile(path, out fullPath))
{
return false;
}
fullPath = Path.GetFullPath(fullPath);
if (!File.Exists(fullPath))
{
Debug.LogError("File " + fullPath + " doesn't exist. Did you move the ShaderGraphEssentials root folder from Assets/ ? Unfortunately this isn't supported yet.");
_hasError = true;
return false;
}
#if UNITY_EDITOR_WIN
System.Diagnostics.Process.Start($@"{fullPath}");
#elif UNITY_EDITOR_OSX
EditorUtility.RevealInFinder($@"{fullPath}");
#endif
return true;
}
private bool CheckForErrors()
{
if (_hasError)
{
GUILayout.Label(
"There was an error constructing this window. Please check your console for errors. If you can't fix it, please don't hesitate to ask for support");
return true;
}
return false;
}
private void InitializeWindow()
{
titleContent.text = "Getting Started";
minSize = new Vector2(250, 400);
_defaultWindowSize = new Vector2(520, 800);
Vector2 initialPosition = 0.5f * (new Vector2(Screen.currentResolution.width, Screen.currentResolution.height) - _defaultWindowSize);
position = new Rect(initialPosition, _defaultWindowSize);
_wrapLabelStyle = new GUIStyle(EditorStyles.label) {wordWrap = true};
}
void OnGUI()
{
if (!_initialized)
{
InitializeWindow();
_initialized = true;
}
if (CheckForErrors()) return;
_scrollPosition = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height), _scrollPosition,
new Rect(0, 0, _defaultWindowSize.x - 10, _defaultWindowSize.y - 10), false, false);
float yOffset = 0;
float defaultXSize = position.width - Margin - Margin;
// Header
GUI.BeginGroup(new Rect(Margin, Margin, defaultXSize, LogoTextureSize));
float xOffset = 0;
GUI.DrawTexture(new Rect(xOffset, 0, LogoTextureSize, LogoTextureSize), _logoTexture);
xOffset += LogoTextureSize + Margin;
GUI.Label(new Rect(xOffset, 0, 100, 30), "Version: " + SGEVersion);
if (GUI.Button(new Rect(xOffset, 30, ButtonWidth, ButtonHeight), "View Changelog"))
{
OpenChangelog();
if (CheckForErrors()) return;
}
if (GUI.Button(new Rect(xOffset, 30 + ButtonHeight + Margin, ButtonWidth, ButtonHeight), "View Manual"))
{
OpenManual();
if (CheckForErrors()) return;
}
xOffset += ButtonWidth + Margin;
if (GUI.Button(new Rect(xOffset, 30, LargeButtonWidth, ButtonHeight), "View Offline Changelog"))
{
OpenFileWithDefaultEditor(ChangeLogName);
if (CheckForErrors()) return;
}
if (GUI.Button(new Rect(xOffset, 30 + ButtonHeight + Margin, LargeButtonWidth, ButtonHeight), "View Offline Manual"))
{
OpenFileWithDefaultEditor(ManualFileName);
if (CheckForErrors()) return;
}
GUI.EndGroup();
yOffset += Margin + LogoTextureSize;
GUI.Label(new Rect(Margin, yOffset + Margin, defaultXSize, 10), "", GUI.skin.horizontalSlider);
yOffset += Margin + Margin;
// Getting started title
yOffset += Margin;
GUI.BeginGroup(new Rect(Margin, yOffset, defaultXSize, 20));
GUI.Label(new Rect(defaultXSize / 2f - 50, 0, 100, 20), "Getting Started", EditorStyles.largeLabel);
GUI.EndGroup();
yOffset += Margin + 20;
// URP
GUI.BeginGroup(new Rect(Margin, yOffset, defaultXSize, 260));
GUI.Label(new Rect(0, 0, defaultXSize, 30), "URP", EditorStyles.boldLabel);
if (GUI.Button(new Rect(0, 30, defaultXSize, ButtonHeight), "Import URP plugin"))
{
ImportURPPlugin();
}
bool isURPImported = IsURPImported();
using (new EditorGUI.DisabledScope(!isURPImported))
{
if (GUI.Button(new Rect(0, ButtonHeight * 2 + Margin, defaultXSize, ButtonHeight), "Import URP Demo scenes"))
{
ImportURPScenes();
}
}
bool areURPScenesImported = AreURPScenesImported();
using (new EditorGUI.DisabledScope(!areURPScenesImported))
{
if (GUI.Button(new Rect(0, ButtonHeight * 3 + Margin * 2, defaultXSize, ButtonHeight), "Open noise scene"))
{
OpenScene(NoiseScene);
}
if (GUI.Button(new Rect(0, ButtonHeight * 4 + Margin * 3, defaultXSize, ButtonHeight), "Open simple lit scene"))
{
OpenScene(SimpleLitScene);
}
if (GUI.Button(new Rect(0, ButtonHeight * 5 + Margin * 4, defaultXSize, ButtonHeight), "Open toon lit scene"))
{
OpenScene(ToonLitScene);
}
if (GUI.Button(new Rect(0, ButtonHeight * 6 + Margin * 5, defaultXSize, ButtonHeight), "Open water scene"))
{
OpenScene(WaterScene);
}
}
GUI.EndGroup();
yOffset += 260;
// HDRP
yOffset += Margin;
GUI.BeginGroup(new Rect(Margin, yOffset, defaultXSize, 140));
GUI.Label(new Rect(0, 0, defaultXSize, 30), "HDRP", EditorStyles.boldLabel);
if (GUI.Button(new Rect(0, 30, defaultXSize, ButtonHeight), "Import HDRP plugin"))
{
ImportHDRPPlugin();
}
bool isHDRPImported = IsHDRPImported();
using (new EditorGUI.DisabledScope(!isHDRPImported))
{
if (GUI.Button(new Rect(0, ButtonHeight * 2 + Margin, defaultXSize, ButtonHeight), "Import HDRP Demo scenes"))
{
ImportHDRPScenes();
}
}
bool areHDRPScenesImported = AreHDRPScenesImported();
using (new EditorGUI.DisabledScope(!areHDRPScenesImported))
{
if (GUI.Button(new Rect(0, ButtonHeight * 3 + Margin * 2, defaultXSize, ButtonHeight), "Open noise scene"))
{
OpenScene(NoiseScene);
}
}
GUI.EndGroup();
yOffset += 140;
// switch URP / HDRP
yOffset += Margin;
GUI.BeginGroup(new Rect(Margin, yOffset, defaultXSize, 90));
GUI.Label(new Rect(0, 0, defaultXSize, 30), "Switch between URP / HDRP", EditorStyles.boldLabel);
GUI.Label(new Rect(0, 30, defaultXSize, 30), "To switch between URP / HDRP, hit the button below and reimport the correct plugin"
, _wrapLabelStyle);
if (GUI.Button(new Rect(0, 60, defaultXSize, ButtonHeight), "Remove plugins and demo scenes"))
{
CleanEverything();
}
GUI.EndGroup();
yOffset += 90;
GUI.Label(new Rect(Margin, yOffset + Margin, defaultXSize, 10), "", GUI.skin.horizontalSlider);
yOffset += Margin + Margin;
// Help title
yOffset += Margin;
GUI.BeginGroup(new Rect(Margin, yOffset, defaultXSize, 30));
GUI.Label(new Rect(defaultXSize / 2f - 15, 0, 100, 20), "Help", EditorStyles.largeLabel);
GUI.EndGroup();
yOffset += Margin + 20;
// Help
GUI.BeginGroup(new Rect(Margin, yOffset, defaultXSize, ButtonHeight));
if (GUI.Button(new Rect(0, 0, defaultXSize / 2 - Margin, ButtonHeight), "Discord"))
{
OpenDiscordHelp();
}
if (GUI.Button(new Rect(defaultXSize / 2 + Margin, 0, defaultXSize / 2 - Margin, ButtonHeight), "Email"))
{
OpenEmailHelp();
}
GUI.EndGroup();
GUI.EndScrollView();
}
private void OpenEmailHelp()
{
Application.OpenURL("mailto:ph.graphics.unity@gmail.com");
}
private void OpenDiscordHelp()
{
Application.OpenURL("https://discord.gg/ksURBah");
}
private void OpenManual()
{
Application.OpenURL("http://assetstore.phbarralis.com/sge/features.html");
}
private void OpenChangelog()
{
Application.OpenURL("http://assetstore.phbarralis.com/sge/changelog.html");
}
private void ImportHDRPScenes()
{
ImportPackage(HDRPDemoPackagePath);
}
private bool AreHDRPScenesImported()
{
return Directory.Exists(Path.Combine(SGEPath, BaseDemoPath));
}
private bool IsHDRPImported()
{
return Directory.Exists(Path.Combine(SGEPath, BasePluginPath));
}
private void ImportHDRPPlugin()
{
ImportPackage(HDRPPluginPackagePath);
}
private void OpenScene(string sceneName)
{
string fullPath;
if (!GetInternalFile(sceneName, out fullPath))
return;
EditorSceneManager.OpenScene(fullPath, OpenSceneMode.Single);
}
private bool AreURPScenesImported()
{
return Directory.Exists(Path.Combine(SGEPath, URPDemoPath));
}
private bool IsURPImported()
{
return Directory.Exists(Path.Combine(SGEPath, URPPluginPath));
}
private void ImportURPScenes()
{
ImportPackage(URPDemoPackagePath);
}
private void ImportURPPlugin()
{
ImportPackage(URPPluginPackagePath);
}
private void ImportPackage(string packagePath)
{
string fullPath;
if (!GetInternalFile(packagePath, out fullPath))
return;
AssetDatabase.ImportPackage(fullPath, true);
}
private void DeleteIfFolderExist(string directoryPath)
{
string fullpath = Path.Combine(SGEPath, directoryPath);
if (Directory.Exists(fullpath))
FileUtil.DeleteFileOrDirectory(fullpath);
}
private void CleanEverything()
{
DeleteIfFolderExist(DemoFolderPath);
DeleteIfFolderExist(BasePluginPath);
DeleteIfFolderExist(URPPluginPath);
AssetDatabase.Refresh();
}
}
}

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 279d2f6664e4af347a537c4f9a9bd000
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 141671
packageName: ShaderGraph Essentials
packageVersion: 1.1.17
assetPath: Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/GettingStarted/GettingStartedWindow.cs
uploadId: 607369

@ -0,0 +1,27 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using UnityEngine;
namespace ShaderGraphEssentials
{
public class SGESettings : ScriptableObject
{
[HideInInspector]
public bool OpenGettingStartedWindow = false;
}
}

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: f261da61669a6ab4bb6571eae406da7e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 141671
packageName: ShaderGraph Essentials
packageVersion: 1.1.17
assetPath: Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/GettingStarted/SGESettings.cs
uploadId: 607369

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ad68d7bf033528d4f9ac90b9c4cb8e30
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e2a68d368e9d9bd4e983b7b3c670977c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 588f9158ddf0fdb4e8d710476f605966
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b01fbbe189ceed1459c201c1c00f079b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,24 @@
NoiseDimensionEnumControlView {
flex-direction: row;
align-items: center;
}
.unity-base-field {
width: 80px;
flex:1;
margin-top: 4px;
margin-bottom: 4px;
}
.unity-base-field__input {
flex:1;
margin-left: 0;
margin-right: 8px;
}
NoiseDimensionEnumControlView > Label {
width: 94px;
-unity-text-align: middle-left;
margin-left: 8px;
margin-right: 8px;
}

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 54d755914ee66e1419d86ef8c20e4cae
ScriptedImporter:
fileIDToRecycleName:
11400000: stylesheet
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}

@ -0,0 +1,24 @@
NoisePeriodicityEnumControlView {
flex-direction: row;
align-items: center;
}
.unity-base-field {
width: 80px;
flex:1;
margin-top: 4px;
margin-bottom: 4px;
}
.unity-base-field__input {
flex:1;
margin-left: 0;
margin-right: 8px;
}
NoisePeriodicityEnumControlView > Label {
width: 94px;
-unity-text-align: middle-left;
margin-left: 8px;
margin-right: 8px;
}

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 10a0af41f9362544e8a5c306f9942438
ScriptedImporter:
fileIDToRecycleName:
11400000: stylesheet
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dea7a28dfc4a37340b641543d816e5b9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,289 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
using UnityEngine.Rendering;
namespace ShaderGraphEssentials
{
class BakeShaderData
{
public BakeTextureNode Node { get; set; }
internal GraphData Graph { get; set; }
public Shader Shader { get; set; }
public string ShaderString { get; set; }
public bool HasError { get; set; }
public string OutputIdName { get; set; }
}
// Most of this class use copy pasted / inspired / modified versions of PreviewManager.cs in Unity's SG.
class BakeTextureManager
{
private const string DefaultPath = "SGE_DefaultBakedTexture.png";
BakeTextureManager()
{
}
internal static void BakeShaderIntoTexture(BakeShaderData shaderData)
{
var node = shaderData.Node;
var renderTexture = new RenderTexture(node.Width, node.Height, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default) { hideFlags = HideFlags.HideAndDontSave };
renderTexture.Create();
// setup mesh
Mesh quadMesh = Resources.GetBuiltinResource(typeof(Mesh), "Quad.fbx") as Mesh;
Material bakeMaterial = new Material(shaderData.Shader);
MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();
// setup camera
GameObject cameraGo = new GameObject();
var camera = cameraGo.AddComponent<Camera>();
camera.cameraType = CameraType.Preview;
camera.enabled = false;
camera.clearFlags = CameraClearFlags.Depth;
camera.fieldOfView = 15;
camera.farClipPlane = 10.0f;
camera.nearClipPlane = 2.0f;
camera.backgroundColor = new Color(49.0f / 255.0f, 49.0f / 255.0f, 49.0f / 255.0f, 1.0f);
camera.renderingPath = RenderingPath.Forward;
camera.useOcclusionCulling = false;
camera.clearFlags = CameraClearFlags.Depth;
camera.transform.position = -Vector3.forward * 2;
camera.transform.rotation = Quaternion.identity;
camera.orthographicSize = 0.5f;
camera.orthographic = true;
camera.targetTexture = renderTexture;
Stack<AbstractMaterialNode> tempNodeWave = new Stack<AbstractMaterialNode>();
HashSet<AbstractMaterialNode > tempAddedToNodeWave = new HashSet<AbstractMaterialNode>();
HashSet<AbstractMaterialNode> nodesToDraw = new HashSet<AbstractMaterialNode>();
// setup material and fill properties from all the previous nodes
var sources = new HashSet<AbstractMaterialNode>
{
node
};
PropagateNodes(sources, PropagationDirection.Upstream, tempNodeWave, tempAddedToNodeWave, nodesToDraw);
PooledList<PreviewProperty> perMaterialPreviewProperties = PooledList<PreviewProperty>.Get();
CollectPreviewProperties(shaderData.Graph, nodesToDraw, perMaterialPreviewProperties, materialPropertyBlock);
AssignPerMaterialPreviewProperties(bakeMaterial, perMaterialPreviewProperties);
// draw the quad into the camera's render texture
Graphics.DrawMesh(quadMesh, Matrix4x4.identity, bakeMaterial, 1, camera, 0, materialPropertyBlock, ShadowCastingMode.Off, false, null, false);
camera.Render();
// get the render texture from GPU to CPU and save it as an asset
Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false);
RenderTexture.active = renderTexture;
texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
texture.Apply();
var textureBytes = texture.EncodeToPNG();
string path = "";
bool textureFound = false;
if (node.OutputTexture != null && AssetDatabase.Contains(node.OutputTexture))
{
try
{
path = AssetDatabase.GetAssetPath(node.OutputTexture);
System.IO.File.WriteAllBytes(path, textureBytes);
AssetDatabase.ImportAsset(path);
textureFound = true;
} catch (Exception e)
{
Debug.LogException(e);
}
}
if (!textureFound)
{
path = Application.dataPath + "/" + DefaultPath;
System.IO.File.WriteAllBytes(path, textureBytes);
path = "Assets/" + DefaultPath;
AssetDatabase.ImportAsset(path);
Debug.LogWarning("No previous baked texture was found so a new one was created at Assets/" + DefaultPath + ". Please rename or move the texture as this specific texture path might be overriden.");
}
node.OutputTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D));
// cleanup
RenderTexture.active = null;
UnityEngine.Object.DestroyImmediate(cameraGo);
UnityEngine.Object.DestroyImmediate(bakeMaterial);
}
static void AssignPerMaterialPreviewProperties(Material mat, List<PreviewProperty> perMaterialPreviewProperties)
{
foreach (var prop in perMaterialPreviewProperties)
{
switch (prop.propType)
{
case PropertyType.VirtualTexture:
// setup the VT textures on the material
bool setAnyTextures = false;
var vt = prop.vtProperty.value;
for (int layer = 0; layer < vt.layers.Count; layer++)
{
var texture = vt.layers[layer].layerTexture?.texture;
int propIndex = mat.shader.FindPropertyIndex(vt.layers[layer].layerRefName);
if (propIndex != -1)
{
mat.SetTexture(vt.layers[layer].layerRefName, texture);
setAnyTextures = true;
}
}
// also put in a request for the VT tiles, since preview rendering does not have feedback enabled
if (setAnyTextures)
{
#if ENABLE_VIRTUALTEXTURES
int stackPropertyId = Shader.PropertyToID(prop.vtProperty.referenceName);
try
{
// Ensure we always request the mip sized 256x256
int width, height;
UnityEngine.Rendering.VirtualTexturing.Streaming.GetTextureStackSize(mat, stackPropertyId, out width, out height);
int textureMip = (int)Math.Max(Mathf.Log(width, 2f), Mathf.Log(height, 2f));
const int baseMip = 8;
int mip = Math.Max(textureMip - baseMip, 0);
UnityEngine.Rendering.VirtualTexturing.Streaming.RequestRegion(mat, stackPropertyId, new Rect(0.0f, 0.0f, 1.0f, 1.0f), mip, UnityEngine.Rendering.VirtualTexturing.System.AllMips);
}
catch (InvalidOperationException)
{
// This gets thrown when the system is in an indeterminate state (like a material with no textures assigned which can obviously never have a texture stack streamed).
// This is valid in this case as we're still authoring the material.
}
#endif // ENABLE_VIRTUALTEXTURES
}
break;
}
}
}
static void CollectPreviewProperties(GraphData m_Graph, IEnumerable<AbstractMaterialNode> nodesToCollect, PooledList<PreviewProperty> perMaterialPreviewProperties,
MaterialPropertyBlock mSharedPreviewPropertyBlock)
{
using (var tempPreviewProps = PooledList<PreviewProperty>.Get())
{
// collect from all of the changed nodes
foreach (var propNode in nodesToCollect)
propNode.CollectPreviewMaterialProperties(tempPreviewProps);
// also grab all graph properties (they are updated every frame)
foreach (var prop in m_Graph.properties)
tempPreviewProps.Add(prop.GetPreviewMaterialProperty());
foreach (var previewProperty in tempPreviewProps)
{
previewProperty.SetValueOnMaterialPropertyBlock(mSharedPreviewPropertyBlock);
// virtual texture assignments must be pushed to the materials themselves (MaterialPropertyBlocks not supported)
if ((previewProperty.propType == PropertyType.VirtualTexture) &&
(previewProperty.vtProperty?.value?.layers != null))
{
perMaterialPreviewProperties.Add(previewProperty);
}
}
}
}
enum PropagationDirection
{
Upstream,
Downstream
}
static void PropagateNodes(HashSet<AbstractMaterialNode> sources, PropagationDirection dir, Stack<AbstractMaterialNode> m_TempNodeWave, HashSet<AbstractMaterialNode> m_TempAddedToNodeWave, HashSet<AbstractMaterialNode> result)
{
Action<AbstractMaterialNode> AddNextLevelNodesToWave =
nextLevelNode =>
{
if (!m_TempAddedToNodeWave.Contains(nextLevelNode))
{
m_TempNodeWave.Push(nextLevelNode);
m_TempAddedToNodeWave.Add(nextLevelNode);
}
};
if (sources.Count > 0)
{
// NodeWave represents the list of nodes we still have to process and add to result
m_TempNodeWave.Clear();
m_TempAddedToNodeWave.Clear();
foreach (var node in sources)
{
m_TempNodeWave.Push(node);
m_TempAddedToNodeWave.Add(node);
}
while (m_TempNodeWave.Count > 0)
{
var node = m_TempNodeWave.Pop();
if (node == null)
continue;
result.Add(node);
// grab connected nodes in propagation direction, add them to the node wave
ForeachConnectedNode(node, dir, AddNextLevelNodesToWave);
}
// clean up any temp data
m_TempNodeWave.Clear();
m_TempAddedToNodeWave.Clear();
}
}
static void ForeachConnectedNode(AbstractMaterialNode node, PropagationDirection dir, Action<AbstractMaterialNode> action)
{
using (var tempEdges = PooledList<IEdge>.Get())
using (var tempSlots = PooledList<MaterialSlot>.Get())
{
// Loop through all nodes that the node feeds into.
if (dir == PropagationDirection.Downstream)
node.GetOutputSlots(tempSlots);
else
node.GetInputSlots(tempSlots);
foreach (var slot in tempSlots)
{
// get the edges out of each slot
tempEdges.Clear(); // and here we serialize another list, ouch!
node.owner.GetEdges(slot.slotReference, tempEdges);
foreach (var edge in tempEdges)
{
// We look at each node we feed into.
var connectedSlot = (dir == PropagationDirection.Downstream) ? edge.inputSlot : edge.outputSlot;
var connectedNode = connectedSlot.node;
action(connectedNode);
}
}
}
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5137c095bd891b840abd2a0f12c5723e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ba6f5b66a775b7a4d8abf1c7007d1890
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,63 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System;
using System.Reflection;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine.UIElements;
namespace ShaderGraphEssentials
{
[AttributeUsage(AttributeTargets.Property)]
class LabelControlAttribute : Attribute, IControlAttribute
{
string m_Label;
public LabelControlAttribute(string label = null)
{
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new LabelControlView(m_Label, node, propertyInfo);
}
}
class LabelControlView : VisualElement
{
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
public LabelControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
if (propertyInfo.PropertyType != typeof(string))
throw new ArgumentException("Property must be of type string", nameof(propertyInfo));
m_Node = node;
m_PropertyInfo = propertyInfo;
label = label ?? propertyInfo.Name;
var labelText = (string) m_PropertyInfo.GetValue(m_Node, null);
if (string.IsNullOrEmpty(label))
Add(new Label { text = labelText });
else
Add(new Label { text = label + ": " + labelText });
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 31d397cf980147445a9e054fd7b13e38
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,139 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace ShaderGraphEssentials
{
[AttributeUsage(AttributeTargets.Property)]
class NoiseDimensionEnumControlAttribute : Attribute, IControlAttribute
{
string m_Label;
int m_SlotId;
public NoiseDimensionEnumControlAttribute(string label = null, int slotId = 0)
{
m_Label = label;
m_SlotId = slotId;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new NoiseDimensionEnumControlView(m_Label, m_SlotId, node, propertyInfo);
}
}
class NoiseDimensionEnumControlView : VisualElement, AbstractMaterialNodeModificationListener
{
NoiseNode m_Node;
PropertyInfo m_PropertyInfo;
int m_SlotId;
PopupField<string> m_PopupField;
string[] m_ValueNames;
NoiseDimension[] m_previousNoiseDimensions = new NoiseDimension[0];
public NoiseDimensionEnumControlView(string label, int slotId, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/NoiseDimensionEnumControlView"));
m_PropertyInfo = propertyInfo;
m_SlotId = slotId;
if (!propertyInfo.PropertyType.IsEnum)
throw new ArgumentException("Property must be an enum.", "propertyInfo");
NoiseNode noiseNode = node as NoiseNode;
if (noiseNode == null)
throw new ArgumentException("NoiseDimensionEnumControl can only be applied on NoiseNode.", "node");
m_Node = noiseNode;
Add(new Label(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)));
m_ValueNames = NoiseDimensionUtils.GetDisplayNames();
CreatePopup();
}
void OnValueChanged(ChangeEvent<string> evt)
{
var index = m_PopupField.index;
var value = (int)m_PropertyInfo.GetValue(m_Node, null);
if (!index.Equals(value))
{
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
m_PropertyInfo.SetValue(m_Node, index, null);
}
CreatePopup();
}
public void OnNodeModified(ModificationScope scope)
{
CreatePopup();
m_PopupField.MarkDirtyRepaint();
}
void CreatePopup()
{
var supportedDimensions = m_Node.Noise.GetSupportedDimensions();
if (m_PopupField != null)
{
if (supportedDimensions.Length == m_previousNoiseDimensions.Length)
{
bool identical = true;
for (int i = 0; i < supportedDimensions.Length; i++)
{
if (supportedDimensions[i] == m_previousNoiseDimensions[i])
continue;
identical = false;
break;
}
if (identical)
return;
}
Remove(m_PopupField);
}
m_previousNoiseDimensions = supportedDimensions;
List<string> popupEntries = new List<string>();
for (int i = 0; i < m_previousNoiseDimensions.Length; i++)
popupEntries.Add(m_ValueNames[i]);
var value = (int)m_PropertyInfo.GetValue(m_Node, null);
if (value >= m_previousNoiseDimensions.Length)
value = 0;
m_PopupField = new PopupField<string>(popupEntries, value);
m_PopupField.RegisterValueChangedCallback(OnValueChanged);
Add(m_PopupField);
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d05d9af0ac1bdb845888d9d4358dcd48
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,139 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEditor.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace ShaderGraphEssentials
{
[AttributeUsage(AttributeTargets.Property)]
class NoisePeriodicityEnumControlAttribute : Attribute, IControlAttribute
{
string m_Label;
int m_SlotId;
public NoisePeriodicityEnumControlAttribute(string label = null, int slotId = 0)
{
m_Label = label;
m_SlotId = slotId;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new NoisePeriodicityEnumControlView(m_Label, m_SlotId, node, propertyInfo);
}
}
class NoisePeriodicityEnumControlView : VisualElement, AbstractMaterialNodeModificationListener
{
NoiseNode m_Node;
PropertyInfo m_PropertyInfo;
int m_SlotId;
PopupField<string> m_PopupField;
string[] m_ValueNames;
NoisePeriodicity[] m_previousNoisePeriodicities = new NoisePeriodicity[0];
public NoisePeriodicityEnumControlView(string label, int slotId, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/NoisePeriodicityEnumControlView"));
m_PropertyInfo = propertyInfo;
m_SlotId = slotId;
if (!propertyInfo.PropertyType.IsEnum)
throw new ArgumentException("Property must be an enum.", "propertyInfo");
NoiseNode noiseNode = node as NoiseNode;
if (noiseNode == null)
throw new ArgumentException("NoisePeriodicityEnumControl can only be applied on NoiseNode.", "node");
m_Node = noiseNode;
Add(new Label(label ?? ObjectNames.NicifyVariableName(propertyInfo.Name)));
m_ValueNames = NoisePeriodicityUtils.GetDisplayNames();
CreatePopup();
}
void OnValueChanged(ChangeEvent<string> evt)
{
var index = m_PopupField.index;
var value = (int)m_PropertyInfo.GetValue(m_Node, null);
if (!index.Equals(value))
{
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
m_PropertyInfo.SetValue(m_Node, index, null);
}
CreatePopup();
}
public void OnNodeModified(ModificationScope scope)
{
CreatePopup();
m_PopupField.MarkDirtyRepaint();
}
void CreatePopup()
{
var supportedPeriodicities = m_Node.Noise.GetSupportedPeriodicities();
if (m_PopupField != null)
{
if (supportedPeriodicities.Length == m_previousNoisePeriodicities.Length)
{
bool identical = true;
for (int i = 0; i < supportedPeriodicities.Length; i++)
{
if (supportedPeriodicities[i] == m_previousNoisePeriodicities[i])
continue;
identical = false;
break;
}
if (identical)
return;
}
Remove(m_PopupField);
}
m_previousNoisePeriodicities = supportedPeriodicities;
List<string> popupEntries = new List<string>();
for (int i = 0; i < m_previousNoisePeriodicities.Length; i++)
popupEntries.Add(m_ValueNames[i]);
var value = (int)m_PropertyInfo.GetValue(m_Node, null);
if (value >= m_previousNoisePeriodicities.Length)
value = 0;
m_PopupField = new PopupField<string>(popupEntries, value);
m_PopupField.RegisterValueChangedCallback(OnValueChanged);
Add(m_PopupField);
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bfd35b78c9062f948b58a867d5dead07
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3b5c559d9c416b44b8c04654489a5a25
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,162 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
using UnityEngine.UIElements;
namespace ShaderGraphEssentials
{
class BakeTextureControlAttribute : Attribute, IControlAttribute
{
VisualElement IControlAttribute.InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
if (!(node is BakeTextureNode))
throw new ArgumentException("Node must inherit from BakeTextureNode.", "node");
return new BakeTextureControlView((BakeTextureNode)node);
}
}
class BakeTextureControlView : VisualElement
{
BakeTextureNode m_Node;
public BakeTextureControlView(BakeTextureNode node)
{
m_Node = node;
Add(new Button(OnBakeTexture) { text = "Bake Texture" });
}
void OnBakeTexture()
{
m_Node.OnBakeTexture();
}
}
[Title("Utility", "Bake Texture")]
class BakeTextureNode : CodeFunctionNode
{
public override bool hasPreview { get { return true; } }
[SerializeField]
private int m_width = 256;
[IntegerControl("Width")]
public int Width
{
get { return m_width; }
set
{
if (m_width == value)
return;
m_width = value;
Dirty(ModificationScope.Node);
}
}
[SerializeField]
private int m_height = 256;
[IntegerControl("Height")]
public int Height
{
get { return m_height; }
set
{
if (m_height == value)
return;
m_height = value;
Dirty(ModificationScope.Node);
}
}
[SerializeField]
private SerializableTexture m_outputTexture = new SerializableTexture();
[TextureControl("Output texture")]
public Texture OutputTexture
{
get { return m_outputTexture.texture; }
set
{
if (m_outputTexture.texture == value)
return;
m_outputTexture.texture = value;
Dirty(ModificationScope.Node);
}
}
[BakeTextureControl]
int controlDummy { get; set; }
public BakeTextureNode()
{
name = "Bake Texture";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("PreviewFunction", BindingFlags.Static | BindingFlags.NonPublic);
}
static string PreviewFunction(
[Slot(0, Binding.None)] DynamicDimensionVector In,
[Slot(1, Binding.None)] out DynamicDimensionVector Out)
{
return
@"
{
Out = In;
}
";
}
internal void OnBakeTexture()
{
var graph = owner;
var wasAsyncAllowed = ShaderUtil.allowAsyncCompilation;
// we don't handle async compilation here, the user is waiting for it anyway
ShaderUtil.allowAsyncCompilation = false;
var generator = new Generator(owner, this, GenerationMode.Preview, $"hidden/preview/{this.GetVariableNameForNode()}", null);
BakeShaderData shaderData = new BakeShaderData();
shaderData.ShaderString = generator.generatedShader; // TODO maybe shader isn't generated yet?
shaderData.Shader = ShaderUtil.CreateShaderAsset(shaderData.ShaderString);
shaderData.Node = this;
shaderData.Graph = graph;
shaderData.HasError = false; // TODO handle shader errors
shaderData.OutputIdName = "Out";
BakeTextureManager.BakeShaderIntoTexture(shaderData);
ShaderUtil.allowAsyncCompilation = wasAsyncAllowed;
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b7dbe737a5cf86a428ad601b0ed7dd02
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,419 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System;
using System.Collections.Generic;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
namespace ShaderGraphEssentials
{
[Title("Procedural", "Noise", "SGE Noise")]
class NoiseNode : AbstractMaterialNode, IGeneratesBodyCode, IGeneratesFunction, IMayRequireMeshUV
{
public override bool hasPreview { get { return true; } }
const int UvSlotId = 0;
const int PeriodSlotId = 1;
const int PersistenceSlotId = 2;
const int LacunaritySlotId = 3;
const int SharpnessSlotId = 5;
const int OutputSlotId = 4;
const string kUvSlotName = "Uv";
const string kPeriodSlotName = "Period";
const string kPersistenceSlotName = "Persistence";
const string kLacunaritySlotName = "Lacunarity";
const string kSharpnessSlotName = "Sharpness";
const string kOutputSlotName = "Out";
public NoiseBase Noise;
[SerializeField]
private NoiseType m_noiseType = NoiseType.Value;
[EnumControl("Type")]
public NoiseType Type
{
get { return m_noiseType; }
set
{
if (m_noiseType == value)
return;
m_noiseType = value;
InitializeNoiseAccordingToType();
Dirty(ModificationScope.Graph);
}
}
[SerializeField]
private NoiseCombine m_noiseCombine = NoiseCombine.Simple;
[EnumControl("Combine")]
public NoiseCombine Combine
{
get { return m_noiseCombine; }
set
{
if (m_noiseCombine == value)
return;
m_noiseCombine = value;
Noise.Combine = value;
UpdateSlots();
Dirty(ModificationScope.Graph);
}
}
[SerializeField]
private NoiseDimension m_noiseDimension = NoiseDimension.D2;
[NoiseDimensionEnumControl("Dimension")]
public NoiseDimension Dimension
{
get
{
return m_noiseDimension;
}
set
{
if (m_noiseDimension == value)
return;
m_noiseDimension = value;
Noise.Dimension = value;
UpdateSlots();
Dirty(ModificationScope.Graph);
}
}
[SerializeField]
private NoisePeriodicity m_noisePeriodicity = NoisePeriodicity.NonPeriodic;
[NoisePeriodicityEnumControl("Periodicity")]
public NoisePeriodicity Periodicity
{
get
{
return m_noisePeriodicity;
}
set
{
if (m_noisePeriodicity == value)
return;
m_noisePeriodicity = value;
Noise.Periodicity = value;
UpdateSlots();
Dirty(ModificationScope.Graph);
}
}
public NoiseNode()
{
name = "SGE Noise";
UpdateNodeAfterDeserialization();
}
private void InitializeNoiseAccordingToType()
{
switch (m_noiseType)
{
case NoiseType.Value:
Noise = new ValueNoise(m_noiseCombine, m_noiseDimension, m_noisePeriodicity);
break;
case NoiseType.Simplex:
Noise = new SimplexNoise(m_noiseCombine, m_noiseDimension, m_noisePeriodicity);
break;
case NoiseType.Perlin:
Noise = new PerlinNoise(m_noiseCombine, m_noiseDimension, m_noisePeriodicity);
break;
default:
throw new ArgumentOutOfRangeException(nameof(m_noiseType), m_noiseType, null);
}
UpdateSlots();
}
private void ValidateNoisePeriodicity()
{
if (Noise == null)
return;
var supported = Noise.GetSupportedPeriodicities();
bool isCurrentPeriodicitySupported = false;
for (int i = 0; i < supported.Length; i++)
{
if (supported[i] == Periodicity)
{
isCurrentPeriodicitySupported = true;
break;
}
}
if (!isCurrentPeriodicitySupported)
Periodicity = supported[0];
}
private void ValidateNoiseDimension()
{
if (Noise == null)
return;
var supported = Noise.GetSupportedDimensions();
bool isCurrentDimensionSupported = false;
for (int i = 0; i < supported.Length; i++)
{
if (supported[i] == Dimension)
{
isCurrentDimensionSupported = true;
break;
}
}
if (!isCurrentDimensionSupported)
Dimension = supported[0];
}
private void UpdateSlots()
{
ValidateNoiseDimension();
ValidateNoisePeriodicity();
var idList = new List<int> { UvSlotId, OutputSlotId };
if (Dimension == NoiseDimension.D2)
AddSlot(new UVMaterialSlot(UvSlotId, kUvSlotName, kUvSlotName, UVChannel.UV0));
else
AddSlot(new DynamicVectorMaterialSlot(UvSlotId, kUvSlotName, kUvSlotName, SlotType.Input, Vector4.zero));
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0.0f));
if (IsNoiseSupported())
{
if (m_noisePeriodicity == NoisePeriodicity.Periodic)
{
AddSlot(new Vector1MaterialSlot(PeriodSlotId, kPeriodSlotName, kPeriodSlotName, SlotType.Input, 1.0f));
idList.Add(PeriodSlotId);
}
if (m_noiseCombine == NoiseCombine.Fractal || m_noiseCombine == NoiseCombine.Turbulence || m_noiseCombine == NoiseCombine.Ridge)
{
AddSlot(new Vector1MaterialSlot(PersistenceSlotId, kPersistenceSlotName, kPersistenceSlotName, SlotType.Input, 0.5f));
idList.Add(PersistenceSlotId);
AddSlot(new Vector1MaterialSlot(LacunaritySlotId, kLacunaritySlotName, kLacunaritySlotName, SlotType.Input, 2.0f));
idList.Add(LacunaritySlotId);
}
if (m_noiseCombine == NoiseCombine.Ridge)
{
AddSlot(new Vector1MaterialSlot(SharpnessSlotId, kSharpnessSlotName, kSharpnessSlotName, SlotType.Input, 1.0f));
idList.Add(SharpnessSlotId);
}
}
RemoveSlotsNameNotMatching(idList, true);
}
public sealed override void UpdateNodeAfterDeserialization()
{
InitializeNoiseAccordingToType();
UpdateSlots();
}
private bool IsNoiseSupported()
{
return Noise == null ? false : Noise.Support();
}
private string GetFunctionName()
{
bool isNoiseSupported = IsNoiseSupported();
if (isNoiseSupported)
{
string functionName = "SGE_Noise";
functionName += "_" + m_noiseType;
functionName += "_" + m_noisePeriodicity;
functionName += "_" + m_noiseCombine;
functionName += "_" + m_noiseDimension;
return functionName;
}
return "SGE_UnsupportedNoise";
}
// generate how a node will be called in code
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
bool isNoiseSupported = IsNoiseSupported();
string inputValue = GetSlotValue(UvSlotId, generationMode);
string outputValue = GetSlotValue(OutputSlotId, generationMode);
sb.AppendLine("{0} {1};", FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType.ToShaderString(ConcretePrecision.Single.ToShaderString()), GetVariableNameForSlot(OutputSlotId));
string functionCall = GetFunctionName() + "(" + inputValue + ", " + outputValue;
if (isNoiseSupported)
{
if (m_noisePeriodicity == NoisePeriodicity.Periodic)
{
string periodValue = GetSlotValue(PeriodSlotId, generationMode);
functionCall += ", " + periodValue;
}
if (m_noiseCombine == NoiseCombine.Fractal || m_noiseCombine == NoiseCombine.Turbulence || m_noiseCombine == NoiseCombine.Ridge)
{
string persistenceValue = GetSlotValue(PersistenceSlotId, generationMode);
string lacunarityValue = GetSlotValue(LacunaritySlotId, generationMode);
functionCall += ", " + persistenceValue + ", " + lacunarityValue;
}
if (m_noiseCombine == NoiseCombine.Ridge)
{
string sharpnessValue = GetSlotValue(SharpnessSlotId, generationMode);
functionCall += ", " + sharpnessValue;
}
}
functionCall += ");";
sb.AppendLine(functionCall);
}
// generate the node's function
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
{
bool isNoiseSupported = IsNoiseSupported();
string functionName = GetFunctionName();
if (isNoiseSupported)
Noise.RegisterFunctions(registry);
registry.ProvideFunction(functionName, s =>
{
var uvSlot = FindInputSlot<MaterialSlot>(UvSlotId);
var outputSlot = FindOutputSlot<MaterialSlot>(OutputSlotId);
if (uvSlot == null)
throw new NullReferenceException("UvSlot null, how is it possible ?");
if (outputSlot == null)
throw new NullReferenceException("outputSlot null, how is it possible ?");
s.Append("void {0}({1} {2}, out {3} {4}",
functionName,
uvSlot.concreteValueType.ToShaderString(ConcretePrecision.Single.ToShaderString()),
kUvSlotName,
outputSlot.concreteValueType.ToShaderString(ConcretePrecision.Single.ToShaderString()),
kOutputSlotName);
if (isNoiseSupported)
{
if (m_noisePeriodicity == NoisePeriodicity.Periodic)
{
var periodSlot = FindInputSlot<MaterialSlot>(PeriodSlotId);
if (periodSlot == null)
throw new NullReferenceException("periodSlot null, how is it possible ?");
s.Append(", {0} {1}",
periodSlot.concreteValueType.ToShaderString(ConcretePrecision.Single.ToShaderString()),
kPeriodSlotName);
}
if (m_noiseCombine == NoiseCombine.Fractal || m_noiseCombine == NoiseCombine.Turbulence || m_noiseCombine == NoiseCombine.Ridge)
{
var persistenceSlot = FindInputSlot<MaterialSlot>(PersistenceSlotId);
var lacunaritySlot = FindInputSlot<MaterialSlot>(LacunaritySlotId);
if (persistenceSlot == null)
throw new NullReferenceException("persistenceSlot null, how is it possible ?");
if (lacunaritySlot == null)
throw new NullReferenceException("lacunaritySlot null, how is it possible ?");
s.Append(", {0} {1}, {2} {3}",
persistenceSlot.concreteValueType.ToShaderString(ConcretePrecision.Single.ToShaderString()),
kPersistenceSlotName,
lacunaritySlot.concreteValueType.ToShaderString(ConcretePrecision.Single.ToShaderString()),
kLacunaritySlotName);
}
if (m_noiseCombine == NoiseCombine.Ridge)
{
var sharpnessSlot = FindInputSlot<MaterialSlot>(SharpnessSlotId);
if (sharpnessSlot == null)
throw new NullReferenceException("sharpnessSlot null, how is it possible ?");
s.Append(", {0} {1}",
sharpnessSlot.concreteValueType.ToShaderString(ConcretePrecision.Single.ToShaderString()),
kSharpnessSlotName);
}
}
s.AppendLine(")");
using (s.BlockScope())
{
if (isNoiseSupported)
{
s.Append("{0} = {1}({2}", kOutputSlotName, Noise.GetNoiseFunctionName(), kUvSlotName);
if (m_noisePeriodicity == NoisePeriodicity.Periodic)
{
s.Append(", pow(2, floor({0}))", kPeriodSlotName);
}
if (m_noiseCombine == NoiseCombine.Fractal || m_noiseCombine == NoiseCombine.Turbulence || m_noiseCombine == NoiseCombine.Ridge)
{
s.Append(", {0}, {1}", kPersistenceSlotName, kLacunaritySlotName);
}
if (m_noiseCombine == NoiseCombine.Ridge)
{
s.Append(", {0}", kSharpnessSlotName);
}
s.Append(")");
if (Noise.NeedRemapTo0_1())
s.Append(" * 0.5 + 0.5");
s.AppendLine(";");
}
else
{
s.AppendLine("{0} = {1};", kOutputSlotName, kUvSlotName);
}
}
});
}
public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability)
{
if (Dimension != NoiseDimension.D2)
return false;
using (var tempSlots = PooledList<MaterialSlot>.Get())
{
GetInputSlots(tempSlots);
foreach (var slot in tempSlots)
{
if (slot.RequiresMeshUV(channel))
return true;
}
return false;
}
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b03f53e47b88fc0479be04d4a28d0cde
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,54 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System.Reflection;
using UnityEditor.ShaderGraph;
using UnityEngine;
[Title("Artistic", "Normal", "Create Normal from Height vector")]
class NormalFromHeightVectorNode : CodeFunctionNode
{
public NormalFromHeightVectorNode()
{
name = "Create Normal from Height vector";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("NormalFromHeightVectorFunction",
BindingFlags.Static | BindingFlags.NonPublic);
}
static string NormalFromHeightVectorFunction(
[Slot(0, Binding.None)] Vector1 Height,
[Slot(1, Binding.None)] Vector1 UOffset,
[Slot(2, Binding.None)] Vector1 VOffset,
[Slot(3, Binding.None, 1f, 1f, 1f, 1f)] Vector1 Strength,
[Slot(4, Binding.None)] out Vector3 Out)
{
Out = Vector3.forward;
return
@"
{
float3 va = float3(1, 0, (UOffset - Height) * Strength);
float3 vb = float3(0, 1, (VOffset - Height) * Strength);
Out = normalize(cross(va, vb));
}
";
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8ae5760f57c1a0144bc20ac7b0704c17
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,51 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System.Reflection;
using UnityEditor.ShaderGraph;
using UnityEngine;
[Title("Artistic", "Normal", "Create Normal U Offset")]
class NormalUOffsetNode : CodeFunctionNode
{
public NormalUOffsetNode()
{
name = "Create Normal U Offset";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("NormalUOffsetFunction",
BindingFlags.Static | BindingFlags.NonPublic);
}
static string NormalUOffsetFunction(
[Slot(0, Binding.MeshUV0)] Vector2 Uv,
[Slot(1, Binding.None, 1f, 1f, 1f, 1f)] Vector1 Offset,
[Slot(2, Binding.None)] out Vector2 Out)
{
Out = Vector2.zero;
return
@"
{
float offset = pow(Offset, 3) * 0.1;
Out = float2(Uv.x + offset, Uv.y);
}
";
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f961cef2bf0bcd34f8b00182eef4458a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,51 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System.Reflection;
using UnityEditor.ShaderGraph;
using UnityEngine;
[Title("Artistic", "Normal", "Create Normal V Offset")]
class NormalVOffsetNode : CodeFunctionNode
{
public NormalVOffsetNode()
{
name = "Create Normal V Offset";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("NormalVOffsetFunction",
BindingFlags.Static | BindingFlags.NonPublic);
}
static string NormalVOffsetFunction(
[Slot(0, Binding.MeshUV0)] Vector2 Uv,
[Slot(1, Binding.None, 1f, 1f, 1f, 1f)] Vector1 Offset,
[Slot(2, Binding.None)] out Vector2 Out)
{
Out = Vector2.zero;
return
@"
{
float offset = pow(Offset, 3) * 0.1;
Out = float2(Uv.x, Uv.y + offset);
}
";
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3dc125d912c9f31479400894ede9a199
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 58e3529e56bdbc042a6cff97fc2d8885
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,45 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using UnityEditor.ShaderGraph;
namespace ShaderGraphEssentials
{
public abstract class NoiseBase
{
public NoiseCombine Combine { get; set; }
public NoiseDimension Dimension { get; set; }
public NoisePeriodicity Periodicity { get; set; }
protected NoiseBase(NoiseCombine combine, NoiseDimension dimension, NoisePeriodicity periodicity)
{
Combine = combine;
Dimension = dimension;
Periodicity = periodicity;
}
public abstract bool Support();
public abstract NoiseDimension[] GetSupportedDimensions();
public abstract NoisePeriodicity[] GetSupportedPeriodicities();
public abstract string GetNoiseFunctionName();
internal abstract void RegisterFunctions(FunctionRegistry registry);
public virtual bool NeedRemapTo0_1()
{
return false;
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e10efe297bc3aea4fbdc8e4147ab0178
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,27 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
namespace ShaderGraphEssentials
{
public enum NoiseCombine
{
Simple,
Fractal,
Turbulence,
Ridge
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 468957cccb71d1a46985d58b77ee6f99
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,60 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
namespace ShaderGraphEssentials
{
public enum NoiseDimension
{
// you can have an enum value start with a figure
D2,
D3
}
public static class NoiseDimensionUtils
{
public static string ToDisplayName(this NoiseDimension dimension)
{
switch (dimension)
{
case NoiseDimension.D2:
return "2D";
case NoiseDimension.D3:
return "3D";
}
return "Unknown Dimension";
}
public static string ToShaderVectorEquivalent(this NoiseDimension dimension)
{
switch (dimension)
{
case NoiseDimension.D2:
return "float2";
case NoiseDimension.D3:
return "float3";
}
return "Unknown Dimension";
}
public static string[] GetDisplayNames()
{
return new[] {NoiseDimension.D2.ToDisplayName(), NoiseDimension.D3.ToDisplayName()};
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d8584ab31558d994b9dfae34a08a8a58
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,59 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
namespace ShaderGraphEssentials
{
public enum NoisePeriodicity
{
NonPeriodic,
Periodic
}
public static class NoisePeriodicityUtils
{
public static string ToDisplayName(this NoisePeriodicity dimension)
{
switch (dimension)
{
case NoisePeriodicity.NonPeriodic:
return "Non periodic";
case NoisePeriodicity.Periodic:
return "Periodic";
}
return "Unknown Periodicity";
}
public static string ToFunctionNameEquivalent(this NoisePeriodicity dimension)
{
switch (dimension)
{
case NoisePeriodicity.NonPeriodic:
return "";
case NoisePeriodicity.Periodic:
return "Periodic";
}
return "Unknown Periodicity";
}
public static string[] GetDisplayNames()
{
return new[] { NoisePeriodicity.NonPeriodic.ToDisplayName(), NoisePeriodicity.Periodic.ToDisplayName() };
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6aaccfec24042f245a20bc72478add18
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,606 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using UnityEditor.ShaderGraph;
namespace ShaderGraphEssentials
{
class ShaderUtils
{
public static void RandomValue2dTo1dFunction(FunctionRegistry registry)
{
registry.ProvideFunction("SGE_RandomValue2dTo1d", s => s.Append(@"
inline float SGE_RandomValue2dTo1d(float2 uv)
{
return frac(sin(dot(uv, float2(12.9898, 78.233)))*43758.5453) * 2.0 - 1.0;
}"));
}
public static void RandomValue2dTo2dFunction(FunctionRegistry registry)
{
registry.ProvideFunction("SGE_RandomValue2dTo2d", s => s.Append(@"
inline float2 SGE_RandomValue2dTo2d(float2 p)
{
// Permutation and hashing used in webgl-nosie goo.gl/pX7HtC
p = p % 289;
float x = (34 * p.x + 1) * p.x % 289 + p.y;
x = (34 * x + 1) * x % 289;
x = frac(x / 41) * 2 - 1;
return normalize(float2(x - floor(x + 0.5), abs(x) - 0.5));
}"));
}
public static string ValueNoiseFunctionName = "SGE_ValueNoise";
public static void ValueNoiseFunction(FunctionRegistry registry)
{
registry.ProvideFunction(ValueNoiseFunctionName, s => s.Append(@"
inline float " + ValueNoiseFunctionName + @"(float2 uv)
{
float2 i = floor(uv);
float2 f = frac(uv);
float2 u = f*f*(3.0-2.0*f);
return lerp(lerp(SGE_RandomValue2dTo1d(i),
SGE_RandomValue2dTo1d(i + float2(1.0, 0.0)), u.x),
lerp(SGE_RandomValue2dTo1d(i + float2(0.0, 1.0)),
SGE_RandomValue2dTo1d(i + float2(1.0, 1.0)), u.x), u.y);
}"));
}
// from https://www.shadertoy.com/view/3d2GRh
// The MIT License
// Copyright © 2019 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
public static string PeriodicValueNoiseFunctionName = "SGE_PeriodicValueNoise";
public static void PeriodicValueNoiseFunction(FunctionRegistry registry)
{
registry.ProvideFunction(PeriodicValueNoiseFunctionName, s => s.Append(@"
inline float " + PeriodicValueNoiseFunctionName + @"(float2 uv, int p)
{
float2 rescaledUv = uv * p;
int2 i = floor(rescaledUv);
float2 f = frac(rescaledUv);
float2 u = f*f*(3.0-2.0*f);
return lerp(lerp(SGE_RandomValue2dTo1d(i &(p - 1)),
SGE_RandomValue2dTo1d((i + int2(1, 0)) &(p - 1)), u.x),
lerp(SGE_RandomValue2dTo1d((i + int2(0, 1)) &(p - 1)),
SGE_RandomValue2dTo1d((i + int2(1, 1)) &(p - 1)), u.x), u.y);
}"));
}
public static string GradientNoiseFunctionName = "SGE_GradientNoise";
public static void GradientNoiseFunction(FunctionRegistry registry)
{
registry.ProvideFunction(GradientNoiseFunctionName, s => s.Append(@"
inline float " + GradientNoiseFunctionName + @"(float2 uv)
{
float2 i = floor(uv);
float2 f = frac(uv);
float2 u = f*f*(3.0-2.0*f);
return lerp(lerp(dot(SGE_RandomValue2dTo2d(i), f),
dot(SGE_RandomValue2dTo2d(i + float2(1.0, 0.0)), f - float2(1.0,0.0)), u.x),
lerp(dot(SGE_RandomValue2dTo2d(i + float2(0.0, 1.0)), f - float2(0.0,1.0)),
dot(SGE_RandomValue2dTo2d(i + float2(1.0, 1.0)), f - float2(1.0,1.0)), u.x), u.y);
}"));
}
public static string SimplexNoiseFunctionName = "SGE_SimplexNoise";
// from https://www.shadertoy.com/view/Msf3WH
// The MIT License
// Copyright © 2013 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
public static void SimplexNoiseFunction(FunctionRegistry registry)
{
registry.ProvideFunction(SimplexNoiseFunctionName, s => s.Append(@"
inline float " + SimplexNoiseFunctionName + @"(float2 uv)
{
const float K1 = 0.366025404; // (sqrt(3) - 1)/ 2;
const float K2 = 0.211324865; // (3 - sqrt(3)) / 6;
float2 i = floor(uv + (uv.x + uv.y) * K1);
float2 a = uv - i + (i.x + i.y) * K2;
float m = step(a.y, a.x);
float2 o = float2(m, 1.0 - m);
float2 b = a - o + K2;
float2 c = a - 1.0 + 2.0 * K2;
float3 h = max(0.5 - float3(dot(a, a), dot(b, b), dot(c, c)), 0.0);
float3 n = h * h * h * h * float3(dot(a, SGE_RandomValue2dTo2d(i + 0.0)),
dot(b, SGE_RandomValue2dTo2d(i + o)),
dot(c, SGE_RandomValue2dTo2d(i + 1.0)));
return dot(n, float3(70.0, 70.0, 70.0));
}"));
}
//
// Noise Shader Library for Unity - https://github.com/keijiro/NoiseShader
//
// Original work (webgl-noise) Copyright (C) 2011 Stefan Gustavson
// Translation and modification was made by Keijiro Takahashi.
//
// This shader is based on the webgl-noise GLSL shader. For further details
// of the original shader, please see the following description from the
// original source code.
//
//
// GLSL textureless classic 2D noise "cnoise",
// with an RSL-style periodic variant "pnoise".
// Author: Stefan Gustavson (stefan.gustavson@liu.se)
// Version: 2011-08-22
//
// Many thanks to Ian McEwan of Ashima Arts for the
// ideas for permutation and gradient selection.
//
// Copyright (c) 2011 Stefan Gustavson. All rights reserved.
// Distributed under the MIT license. See LICENSE file.
// https://github.com/ashima/webgl-noise
public static void PerlinNoiseHelperFunction(FunctionRegistry registry)
{
registry.ProvideFunction("SGE_Mod_F4", s => s.Append(@"
inline float4 SGE_Mod_F4(float4 x, float4 y)
{
return x - y * floor(x / y);
}"));
registry.ProvideFunction("SGE_Mod_F3", s => s.Append(@"
inline float3 SGE_Mod_F3(float3 x, float3 y)
{
return x - y * floor(x / y);
}"));
registry.ProvideFunction("SGE_Mod289_F4", s => s.Append(@"
inline float4 SGE_Mod289_F4(float4 x)
{
return x - floor(x / 289.0) * 289.0;
}"));
registry.ProvideFunction("SGE_Mod289_F3", s => s.Append(@"
inline float3 SGE_Mod289_F3(float3 x)
{
return x - floor(x / 289.0) * 289.0;
}"));
registry.ProvideFunction("SGE_Permute", s => s.Append(@"
inline float4 SGE_Permute(float4 x)
{
return SGE_Mod289_F4(((x*34.0)+1.0)*x);
}"));
registry.ProvideFunction("SGE_TaylorInvSqrt", s => s.Append(@"
inline float4 SGE_TaylorInvSqrt(float4 r)
{
return (float4)1.79284291400159 - r * 0.85373472095314;
}"));
registry.ProvideFunction("SGE_Fade_F2", s => s.Append(@"
inline float2 SGE_Fade_F2(float2 t)
{
return t*t*t*(t*(t*6.0-15.0)+10.0);
}"));
registry.ProvideFunction("SGE_Fade_F3", s => s.Append(@"
inline float3 SGE_Fade_F3(float3 t)
{
return t*t*t*(t*(t*6.0-15.0)+10.0);
}"));
}
public static string PerlinNoiseFunctionName = "SGE_PerlinNoise";
public static void PerlinNoiseFunction(FunctionRegistry registry)
{
PerlinNoiseHelperFunction(registry);
registry.ProvideFunction(PerlinNoiseFunctionName, s => s.Append(@"
inline float " + PerlinNoiseFunctionName + @"(float2 uv)
{
float4 Pi = floor(uv.xyxy) + float4(0.0, 0.0, 1.0, 1.0);
float4 Pf = frac (uv.xyxy) - float4(0.0, 0.0, 1.0, 1.0);
Pi = SGE_Mod289_F4(Pi); // To avoid truncation effects in permutation
float4 ix = Pi.xzxz;
float4 iy = Pi.yyww;
float4 fx = Pf.xzxz;
float4 fy = Pf.yyww;
float4 i = SGE_Permute(SGE_Permute(ix) + iy);
float4 gx = frac(i / 41.0) * 2.0 - 1.0 ;
float4 gy = abs(gx) - 0.5 ;
float4 tx = floor(gx + 0.5);
gx = gx - tx;
float2 g00 = float2(gx.x,gy.x);
float2 g10 = float2(gx.y,gy.y);
float2 g01 = float2(gx.z,gy.z);
float2 g11 = float2(gx.w,gy.w);
float4 norm = SGE_TaylorInvSqrt(float4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
g00 *= norm.x;
g01 *= norm.y;
g10 *= norm.z;
g11 *= norm.w;
float n00 = dot(g00, float2(fx.x, fy.x));
float n10 = dot(g10, float2(fx.y, fy.y));
float n01 = dot(g01, float2(fx.z, fy.z));
float n11 = dot(g11, float2(fx.w, fy.w));
float2 fade_xy = SGE_Fade_F2(Pf.xy);
float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x);
float n_xy = lerp(n_x.x, n_x.y, fade_xy.y);
return 2.3 * n_xy;
}"));
}
public static string PeriodicPerlinNoiseFunctionName = "SGE_PeriodicPerlinNoise";
public static void PeriodicPerlinNoiseFunction(FunctionRegistry registry)
{
PerlinNoiseHelperFunction(registry);
registry.ProvideFunction(PeriodicPerlinNoiseFunctionName, s => s.Append(@"
inline float " + PeriodicPerlinNoiseFunctionName + @"(float2 uv, float2 period)
{
float2 rescaledUv = uv * period;
float4 Pi = floor(rescaledUv.xyxy) + float4(0.0, 0.0, 1.0, 1.0);
float4 Pf = frac (rescaledUv.xyxy) - float4(0.0, 0.0, 1.0, 1.0);
Pi = SGE_Mod_F4(Pi, period.xyxy); // To create noise with explicit period
Pi = SGE_Mod289_F4(Pi); // To avoid truncation effects in permutation
float4 ix = Pi.xzxz;
float4 iy = Pi.yyww;
float4 fx = Pf.xzxz;
float4 fy = Pf.yyww;
float4 i = SGE_Permute(SGE_Permute(ix) + iy);
float4 gx = frac(i / 41.0) * 2.0 - 1.0 ;
float4 gy = abs(gx) - 0.5 ;
float4 tx = floor(gx + 0.5);
gx = gx - tx;
float2 g00 = float2(gx.x,gy.x);
float2 g10 = float2(gx.y,gy.y);
float2 g01 = float2(gx.z,gy.z);
float2 g11 = float2(gx.w,gy.w);
float4 norm = SGE_TaylorInvSqrt(float4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
g00 *= norm.x;
g01 *= norm.y;
g10 *= norm.z;
g11 *= norm.w;
float n00 = dot(g00, float2(fx.x, fy.x));
float n10 = dot(g10, float2(fx.y, fy.y));
float n01 = dot(g01, float2(fx.z, fy.z));
float n11 = dot(g11, float2(fx.w, fy.w));
float2 fade_xy = SGE_Fade_F2(Pf.xy);
float2 n_x = lerp(float2(n00, n01), float2(n10, n11), fade_xy.x);
float n_xy = lerp(n_x.x, n_x.y, fade_xy.y);
return 2.3 * n_xy;
}"));
}
// Copyright (c) 2011 Stefan Gustavson. All rights reserved.
// Distributed under the MIT license. See LICENSE file.
// https://github.com/stegu/webgl-noise
public static string Perlin3DNoiseFunctionName = "SGE_Perlin3DNoise";
public static void Perlin3DNoiseFunction(FunctionRegistry registry)
{
PerlinNoiseHelperFunction(registry);
registry.ProvideFunction(Perlin3DNoiseFunctionName, s => s.Append(@"
inline float " + Perlin3DNoiseFunctionName + @"(float3 uv)
{
float3 Pi0 = floor(uv); // Integer part for indexing
float3 Pi1 = Pi0 + float3(1.0, 1.0, 1.0); // Integer part + 1
Pi0 = SGE_Mod289_F3(Pi0);
Pi1 = SGE_Mod289_F3(Pi1);
float3 Pf0 = frac(uv); // Fractional part for interpolation
float3 Pf1 = Pf0 - float3(1.0, 1.0, 1.0); // Fractional part - 1.0
float4 ix = float4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
float4 iy = float4(Pi0.yy, Pi1.yy);
float4 iz0 = Pi0.zzzz;
float4 iz1 = Pi1.zzzz;
float4 ixy = SGE_Permute(SGE_Permute(ix) + iy);
float4 ixy0 = SGE_Permute(ixy + iz0);
float4 ixy1 = SGE_Permute(ixy + iz1);
float4 gx0 = ixy0 * (1.0 / 7.0);
float4 gy0 = frac(floor(gx0) * (1.0 / 7.0)) - 0.5;
gx0 = frac(gx0);
float4 gz0 = float4(0.5, 0.5, 0.5, 0.5) - abs(gx0) - abs(gy0);
float4 sz0 = step(gz0, float4(0.0, 0.0, 0.0, 0.0));
gx0 -= sz0 * (step(0.0, gx0) - 0.5);
gy0 -= sz0 * (step(0.0, gy0) - 0.5);
float4 gx1 = ixy1 * (1.0 / 7.0);
float4 gy1 = frac(floor(gx1) * (1.0 / 7.0)) - 0.5;
gx1 = frac(gx1);
float4 gz1 = float4(0.5, 0.5, 0.5, 0.5) - abs(gx1) - abs(gy1);
float4 sz1 = step(gz1, float4(0.0, 0.0, 0.0, 0.0));
gx1 -= sz1 * (step(0.0, gx1) - 0.5);
gy1 -= sz1 * (step(0.0, gy1) - 0.5);
float3 g000 = float3(gx0.x,gy0.x,gz0.x);
float3 g100 = float3(gx0.y,gy0.y,gz0.y);
float3 g010 = float3(gx0.z,gy0.z,gz0.z);
float3 g110 = float3(gx0.w,gy0.w,gz0.w);
float3 g001 = float3(gx1.x,gy1.x,gz1.x);
float3 g101 = float3(gx1.y,gy1.y,gz1.y);
float3 g011 = float3(gx1.z,gy1.z,gz1.z);
float3 g111 = float3(gx1.w,gy1.w,gz1.w);
float4 norm0 = SGE_TaylorInvSqrt(float4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
g000 *= norm0.x;
g010 *= norm0.y;
g100 *= norm0.z;
g110 *= norm0.w;
float4 norm1 = SGE_TaylorInvSqrt(float4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
g001 *= norm1.x;
g011 *= norm1.y;
g101 *= norm1.z;
g111 *= norm1.w;
float n000 = dot(g000, Pf0);
float n100 = dot(g100, float3(Pf1.x, Pf0.yz));
float n010 = dot(g010, float3(Pf0.x, Pf1.y, Pf0.z));
float n110 = dot(g110, float3(Pf1.xy, Pf0.z));
float n001 = dot(g001, float3(Pf0.xy, Pf1.z));
float n101 = dot(g101, float3(Pf1.x, Pf0.y, Pf1.z));
float n011 = dot(g011, float3(Pf0.x, Pf1.yz));
float n111 = dot(g111, Pf1);
float3 fade_xyz = SGE_Fade_F3(Pf0);
float4 n_z = lerp(float4(n000, n100, n010, n110), float4(n001, n101, n011, n111), fade_xyz.z);
float2 n_yz = lerp(n_z.xy, n_z.zw, fade_xyz.y);
float n_xyz = lerp(n_yz.x, n_yz.y, fade_xyz.x);
return 2.2 * n_xyz;
}"));
}
public static string PeriodicPerlin3DNoiseFunctionName = "SGE_PeriodicPerlin3DNoise";
public static void PeriodicPerlin3DNoiseFunction(FunctionRegistry registry)
{
PerlinNoiseHelperFunction(registry);
registry.ProvideFunction(PeriodicPerlin3DNoiseFunctionName, s => s.Append(@"
inline float " + PeriodicPerlin3DNoiseFunctionName + @"(float3 uv, float3 period)
{
float3 Pi0 = SGE_Mod_F3(floor(uv), period); // Integer part, modulo period
float3 Pi1 = SGE_Mod_F3(Pi0 + float3(1.0, 1.0, 1.0), period); // Integer part + 1, mod period
Pi0 = SGE_Mod289_F3(Pi0);
Pi1 = SGE_Mod289_F3(Pi1);
float3 Pf0 = frac(uv); // fracional part for interpolation
float3 Pf1 = Pf0 - float3(1.0, 1.0, 1.0); // fracional part - 1.0
float4 ix = float4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
float4 iy = float4(Pi0.yy, Pi1.yy);
float4 iz0 = Pi0.zzzz;
float4 iz1 = Pi1.zzzz;
float4 ixy = SGE_Permute(SGE_Permute(ix) + iy);
float4 ixy0 = SGE_Permute(ixy + iz0);
float4 ixy1 = SGE_Permute(ixy + iz1);
float4 gx0 = ixy0 * (1.0 / 7.0);
float4 gy0 = frac(floor(gx0) * (1.0 / 7.0)) - 0.5;
gx0 = frac(gx0);
float4 gz0 = float4(0.5, 0.5, 0.5, 0.5) - abs(gx0) - abs(gy0);
float4 sz0 = step(gz0, float4(0.0, 0.0, 0.0, 0.0));
gx0 -= sz0 * (step(0.0, gx0) - 0.5);
gy0 -= sz0 * (step(0.0, gy0) - 0.5);
float4 gx1 = ixy1 * (1.0 / 7.0);
float4 gy1 = frac(floor(gx1) * (1.0 / 7.0)) - 0.5;
gx1 = frac(gx1);
float4 gz1 = float4(0.5, 0.5, 0.5, 0.5) - abs(gx1) - abs(gy1);
float4 sz1 = step(gz1, float4(0.0, 0.0, 0.0, 0.0));
gx1 -= sz1 * (step(0.0, gx1) - 0.5);
gy1 -= sz1 * (step(0.0, gy1) - 0.5);
float3 g000 = float3(gx0.x,gy0.x,gz0.x);
float3 g100 = float3(gx0.y,gy0.y,gz0.y);
float3 g010 = float3(gx0.z,gy0.z,gz0.z);
float3 g110 = float3(gx0.w,gy0.w,gz0.w);
float3 g001 = float3(gx1.x,gy1.x,gz1.x);
float3 g101 = float3(gx1.y,gy1.y,gz1.y);
float3 g011 = float3(gx1.z,gy1.z,gz1.z);
float3 g111 = float3(gx1.w,gy1.w,gz1.w);
float4 norm0 = SGE_TaylorInvSqrt(float4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
g000 *= norm0.x;
g010 *= norm0.y;
g100 *= norm0.z;
g110 *= norm0.w;
float4 norm1 = SGE_TaylorInvSqrt(float4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
g001 *= norm1.x;
g011 *= norm1.y;
g101 *= norm1.z;
g111 *= norm1.w;
float n000 = dot(g000, Pf0);
float n100 = dot(g100, float3(Pf1.x, Pf0.yz));
float n010 = dot(g010, float3(Pf0.x, Pf1.y, Pf0.z));
float n110 = dot(g110, float3(Pf1.xy, Pf0.z));
float n001 = dot(g001, float3(Pf0.xy, Pf1.z));
float n101 = dot(g101, float3(Pf1.x, Pf0.y, Pf1.z));
float n011 = dot(g011, float3(Pf0.x, Pf1.yz));
float n111 = dot(g111, Pf1);
float3 fade_xyz = SGE_Fade_F3(Pf0);
float4 n_z = lerp(float4(n000, n100, n010, n110), float4(n001, n101, n011, n111), fade_xyz.z);
float2 n_yz = lerp(n_z.xy, n_z.zw, fade_xyz.y);
float n_xyz = lerp(n_yz.x, n_yz.y, fade_xyz.x);
return 2.2 * n_xyz;
}"));
}
public static string GetFractalFunctionName(string noiseFunctionName)
{
return "SGE_Fractal" + noiseFunctionName;
}
public static void FractalFunction(FunctionRegistry registry, string noiseFunctionName, string dimensionTypeName = "float2")
{
registry.ProvideFunction(GetFractalFunctionName(noiseFunctionName), s => s.Append(@"
inline float " + GetFractalFunctionName(noiseFunctionName) + @"(" + dimensionTypeName + @" uv, float persistence, float lacunarity)
{
float currentPersistence = persistence;
" + dimensionTypeName + @" currentUV = uv;
float ret = 0.0;
for (uint i = 0; i < 4; i++)
{
ret += currentPersistence * " + noiseFunctionName + @"(currentUV);
currentPersistence *= persistence;
currentUV *= lacunarity;
}
return ret;
}"));
}
public static void PeriodicFractalFunction(FunctionRegistry registry, string noiseFunctionName, string dimensionTypeName = "float2")
{
registry.ProvideFunction(GetFractalFunctionName(noiseFunctionName), s => s.Append(@"
inline float " + GetFractalFunctionName(noiseFunctionName) + @"(" + dimensionTypeName + @" uv, int Period, float persistence, float lacunarity)
{
float currentPersistence = persistence;
" + dimensionTypeName + @" currentUV = uv;
float ret = 0.0;
int p = pow(2, Period);
for (uint i = 0; i < 4; i++)
{
ret += currentPersistence * " + noiseFunctionName + @"(currentUV, p);
currentPersistence *= persistence;
currentUV *= lacunarity;
p *= 2;
}
return ret;
}"));
}
public static string GetTurbulenceFunctionName(string noiseFunctionName)
{
return "SGE_Turbulence" + noiseFunctionName;
}
public static void TurbulenceFunction(FunctionRegistry registry, string noiseFunctionName, string dimensionTypeName = "float2")
{
registry.ProvideFunction(GetTurbulenceFunctionName(noiseFunctionName), s => s.Append(@"
inline float " + GetTurbulenceFunctionName(noiseFunctionName) + @"(" + dimensionTypeName + @" uv, float persistence, float lacunarity)
{
float currentPersistence = persistence;
" + dimensionTypeName + @" currentUV = uv;
float ret = 0.0;
for (uint i = 0; i < 4; i++)
{
ret += currentPersistence * abs(" + noiseFunctionName + @"(currentUV));
currentPersistence *= persistence;
currentUV *= lacunarity;
}
return ret;
}"));
}
public static void PeriodicTurbulenceFunction(FunctionRegistry registry, string noiseFunctionName, string dimensionTypeName = "float2")
{
registry.ProvideFunction(GetTurbulenceFunctionName(noiseFunctionName), s => s.Append(@"
inline float " + GetTurbulenceFunctionName(noiseFunctionName) + @"(" + dimensionTypeName + @" uv, int Period, float persistence, float lacunarity)
{
float currentPersistence = persistence;
" + dimensionTypeName + @" currentUV = uv;
float ret = 0.0;
int p = pow(2, Period);
for (uint i = 0; i < 4; i++)
{
ret += currentPersistence * abs(" + noiseFunctionName + @"(currentUV, p));
currentPersistence *= persistence;
currentUV *= lacunarity;
p *= 2;
}
return ret;
}"));
}
public static string GetRidgeFunctionName(string noiseFunctionName)
{
return "SGE_Ridge" + noiseFunctionName;
}
public static void RidgeFunction(FunctionRegistry registry, string noiseFunctionName, string dimensionTypeName = "float2")
{
registry.ProvideFunction(GetRidgeFunctionName(noiseFunctionName), s => s.Append(@"
inline float " + GetRidgeFunctionName(noiseFunctionName) + @"(" + dimensionTypeName + @" uv, float persistence, float lacunarity, float sharpness)
{
float currentPersistence = persistence;
" + dimensionTypeName + @" currentUV = uv;
float ret = 0.0;
for (uint i = 0; i < 4; i++)
{
// create creases
float n = saturate(abs(" + noiseFunctionName + @"(currentUV)));
// invert so creases are at top
n = 1.0 - n + 0.0001f;
// sharpen creases
n = pow(n, sharpness);
ret += currentPersistence * n;
currentPersistence *= persistence;
currentUV *= lacunarity;
}
return ret;
}"));
}
public static void PeriodicRidgeFunction(FunctionRegistry registry, string noiseFunctionName, string dimensionTypeName = "float2")
{
registry.ProvideFunction(GetRidgeFunctionName(noiseFunctionName), s => s.Append(@"
inline float " + GetRidgeFunctionName(noiseFunctionName) + @"(" + dimensionTypeName + @" uv, int Period, float persistence, float lacunarity, float sharpness)
{
float currentPersistence = persistence;
" + dimensionTypeName + @" currentUV = uv;
float ret = 0.0;
int p = pow(2, Period);
for (uint i = 0; i < 4; i++)
{
// create creases
float n = saturate(abs(" + noiseFunctionName + @"(currentUV, p)));
// invert so creases are at top
n = 1.0 - n + 0.0001f;
// sharpen creases
n = pow(n, sharpness);
ret += currentPersistence * n;
currentPersistence *= persistence;
currentUV *= lacunarity;
p *= 2;
}
return ret;
}"));
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 09d3fd444facb7a45b576c88924dfb1d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,26 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
namespace ShaderGraphEssentials
{
public enum NoiseType
{
Value,
Simplex,
Perlin
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4cd8d6f4683cded4b9a027cb00372149
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,129 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System;
using UnityEditor.ShaderGraph;
namespace ShaderGraphEssentials
{
class PerlinNoise : NoiseBase
{
public PerlinNoise(NoiseCombine combine, NoiseDimension dimension, NoisePeriodicity periodicity) : base(combine, dimension, periodicity)
{
}
public override bool Support()
{
return true;
}
public override NoiseDimension[] GetSupportedDimensions()
{
return new[] { NoiseDimension.D2, NoiseDimension.D3 };
}
public override NoisePeriodicity[] GetSupportedPeriodicities()
{
return new[] { NoisePeriodicity.NonPeriodic, NoisePeriodicity.Periodic };
}
public override string GetNoiseFunctionName()
{
switch (Combine)
{
case NoiseCombine.Simple:
return GetSimpleNoiseFunctionName();
case NoiseCombine.Fractal:
return ShaderUtils.GetFractalFunctionName(GetSimpleNoiseFunctionName());
case NoiseCombine.Turbulence:
return ShaderUtils.GetTurbulenceFunctionName(GetSimpleNoiseFunctionName());
case NoiseCombine.Ridge:
return ShaderUtils.GetRidgeFunctionName(GetSimpleNoiseFunctionName());
default:
throw new ArgumentOutOfRangeException();
}
}
// function name of the noise, with the combine if any
private string GetSimpleNoiseFunctionName()
{
switch (Periodicity)
{
case NoisePeriodicity.NonPeriodic:
return Dimension == NoiseDimension.D2 ? ShaderUtils.PerlinNoiseFunctionName : ShaderUtils.Perlin3DNoiseFunctionName;
case NoisePeriodicity.Periodic:
return Dimension == NoiseDimension.D2 ? ShaderUtils.PeriodicPerlinNoiseFunctionName : ShaderUtils.PeriodicPerlin3DNoiseFunctionName;
default:
throw new ArgumentOutOfRangeException();
}
}
internal override void RegisterFunctions(FunctionRegistry registry)
{
switch (Periodicity)
{
case NoisePeriodicity.NonPeriodic:
switch (Dimension)
{
case NoiseDimension.D2:
ShaderUtils.PerlinNoiseFunction(registry);
break;
case NoiseDimension.D3:
ShaderUtils.Perlin3DNoiseFunction(registry);
break;
default:
throw new ArgumentOutOfRangeException();
}
if (Combine == NoiseCombine.Fractal)
ShaderUtils.FractalFunction(registry, GetSimpleNoiseFunctionName(), Dimension.ToShaderVectorEquivalent());
else if (Combine == NoiseCombine.Turbulence)
ShaderUtils.TurbulenceFunction(registry, GetSimpleNoiseFunctionName(), Dimension.ToShaderVectorEquivalent());
else if (Combine == NoiseCombine.Ridge)
ShaderUtils.RidgeFunction(registry, GetSimpleNoiseFunctionName(), Dimension.ToShaderVectorEquivalent());
break;
case NoisePeriodicity.Periodic:
switch (Dimension)
{
case NoiseDimension.D2:
ShaderUtils.PeriodicPerlinNoiseFunction(registry);
break;
case NoiseDimension.D3:
ShaderUtils.PeriodicPerlin3DNoiseFunction(registry);
break;
default:
throw new ArgumentOutOfRangeException();
}
if (Combine == NoiseCombine.Fractal)
ShaderUtils.PeriodicFractalFunction(registry, GetSimpleNoiseFunctionName(), Dimension.ToShaderVectorEquivalent());
else if (Combine == NoiseCombine.Turbulence)
ShaderUtils.PeriodicTurbulenceFunction(registry, GetSimpleNoiseFunctionName(), Dimension.ToShaderVectorEquivalent());
else if (Combine == NoiseCombine.Ridge)
ShaderUtils.PeriodicRidgeFunction(registry, GetSimpleNoiseFunctionName(), Dimension.ToShaderVectorEquivalent());
break;
default:
throw new ArgumentOutOfRangeException();
}
}
public override bool NeedRemapTo0_1()
{
return Combine != NoiseCombine.Turbulence && Combine != NoiseCombine.Ridge;
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 10a8ecb717008aa4c965b032befb38a0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,85 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System;
using UnityEditor.ShaderGraph;
namespace ShaderGraphEssentials
{
class SimplexNoise : NoiseBase
{
public SimplexNoise(NoiseCombine combine, NoiseDimension dimension, NoisePeriodicity periodicity) : base(combine, dimension, periodicity)
{
}
public override bool Support()
{
return Dimension == NoiseDimension.D2 && Periodicity == NoisePeriodicity.NonPeriodic;
}
public override NoiseDimension[] GetSupportedDimensions()
{
return new[] { NoiseDimension.D2 };
}
public override NoisePeriodicity[] GetSupportedPeriodicities()
{
return new[] {NoisePeriodicity.NonPeriodic};
}
public override string GetNoiseFunctionName()
{
switch (Combine)
{
case NoiseCombine.Simple:
return GetSimpleNoiseFunctionName();
case NoiseCombine.Fractal:
return ShaderUtils.GetFractalFunctionName(GetSimpleNoiseFunctionName());
case NoiseCombine.Turbulence:
return ShaderUtils.GetTurbulenceFunctionName(GetSimpleNoiseFunctionName());
case NoiseCombine.Ridge:
return ShaderUtils.GetRidgeFunctionName(GetSimpleNoiseFunctionName());
default:
throw new ArgumentOutOfRangeException();
}
}
// function name of the noise, with the combine if any
private string GetSimpleNoiseFunctionName()
{
return ShaderUtils.SimplexNoiseFunctionName;
}
internal override void RegisterFunctions(FunctionRegistry registry)
{
ShaderUtils.RandomValue2dTo2dFunction(registry);
ShaderUtils.SimplexNoiseFunction(registry);
if (Combine == NoiseCombine.Fractal)
ShaderUtils.FractalFunction(registry, GetSimpleNoiseFunctionName());
else if (Combine == NoiseCombine.Turbulence)
ShaderUtils.TurbulenceFunction(registry, GetSimpleNoiseFunctionName());
else if (Combine == NoiseCombine.Ridge)
ShaderUtils.RidgeFunction(registry, GetSimpleNoiseFunctionName());
}
public override bool NeedRemapTo0_1()
{
return Combine != NoiseCombine.Turbulence && Combine != NoiseCombine.Ridge;
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ae75eec60c9735740a8df0661e9b8398
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,101 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System;
using UnityEditor.ShaderGraph;
namespace ShaderGraphEssentials
{
class ValueNoise : NoiseBase
{
public ValueNoise(NoiseCombine combine, NoiseDimension dimension, NoisePeriodicity periodicity) : base(combine, dimension, periodicity)
{
}
public override bool Support()
{
return Dimension == NoiseDimension.D2;
}
public override NoiseDimension[] GetSupportedDimensions()
{
return new[] {NoiseDimension.D2};
}
public override NoisePeriodicity[] GetSupportedPeriodicities()
{
return new[] { NoisePeriodicity.NonPeriodic, NoisePeriodicity.Periodic };
}
public override string GetNoiseFunctionName()
{
switch (Combine)
{
case NoiseCombine.Simple:
return GetSimpleNoiseFunctionName();
case NoiseCombine.Fractal:
return ShaderUtils.GetFractalFunctionName(GetSimpleNoiseFunctionName());
case NoiseCombine.Turbulence:
return ShaderUtils.GetTurbulenceFunctionName(GetSimpleNoiseFunctionName());
case NoiseCombine.Ridge:
return ShaderUtils.GetRidgeFunctionName(GetSimpleNoiseFunctionName());
default:
throw new ArgumentOutOfRangeException();
}
}
// function name of the noise, with the combine if any
private string GetSimpleNoiseFunctionName()
{
return Periodicity == NoisePeriodicity.NonPeriodic ? ShaderUtils.ValueNoiseFunctionName : ShaderUtils.PeriodicValueNoiseFunctionName;
}
internal override void RegisterFunctions(FunctionRegistry registry)
{
ShaderUtils.RandomValue2dTo1dFunction(registry);
switch (Periodicity)
{
case NoisePeriodicity.NonPeriodic:
ShaderUtils.ValueNoiseFunction(registry);
if (Combine == NoiseCombine.Fractal)
ShaderUtils.FractalFunction(registry, GetSimpleNoiseFunctionName());
else if (Combine == NoiseCombine.Turbulence)
ShaderUtils.TurbulenceFunction(registry, GetSimpleNoiseFunctionName());
else if (Combine == NoiseCombine.Ridge)
ShaderUtils.RidgeFunction(registry, GetSimpleNoiseFunctionName());
break;
case NoisePeriodicity.Periodic:
ShaderUtils.PeriodicValueNoiseFunction(registry);
if (Combine == NoiseCombine.Fractal)
ShaderUtils.PeriodicFractalFunction(registry, GetSimpleNoiseFunctionName());
else if (Combine == NoiseCombine.Turbulence)
ShaderUtils.PeriodicTurbulenceFunction(registry, GetSimpleNoiseFunctionName());
else if (Combine == NoiseCombine.Ridge)
ShaderUtils.PeriodicRidgeFunction(registry, GetSimpleNoiseFunctionName());
break;
default:
throw new ArgumentOutOfRangeException();
}
}
public override bool NeedRemapTo0_1()
{
return Combine != NoiseCombine.Turbulence && Combine != NoiseCombine.Ridge;
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26ddce98423a567458e119ab7d919160
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f6a355c2bd4f8924bac91d0e229365dd
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d281b2ab1eaf7a645b6dcab48b0aeebe
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 65879b152d0758649b06703d79e60cdb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,36 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Legacy;
using RenderQueue = UnityEditor.ShaderGraph.RenderQueue;
namespace ShaderGraphEssentials.Legacy
{
[FormerName("ShaderGraphEssentials.SGECustomLitMasterNode")]
class SGECustomLitMasterNode1 : AbstractMaterialNode, IMasterNode1
{
public RenderType m_renderType;
public RenderQueue m_renderQueue;
public BlendMode m_blendMode;
public CullMode m_cullMode;
public ZWrite m_zwrite;
public ZTest m_ztest;
public NormalDropOffSpace m_NormalDropOffSpace;
public string m_customEditor;
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: be3830ad503e7ab4cbb800382c00ea98
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7ed365abd470c62479184d2f8e2c3879
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,36 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Legacy;
using RenderQueue = UnityEditor.ShaderGraph.RenderQueue;
namespace ShaderGraphEssentials.Legacy
{
[FormerName("ShaderGraphEssentials.SGESimpleLitMasterNode")]
class SGESimpleLitMasterNode1 : AbstractMaterialNode, IMasterNode1
{
public RenderType m_renderType;
public RenderQueue m_renderQueue;
public BlendMode m_blendMode;
public CullMode m_cullMode;
public ZWrite m_zwrite;
public ZTest m_ztest;
public NormalDropOffSpace m_NormalDropOffSpace;
public string m_customEditor;
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8b07f9a0feadeb144b67bc728b12c3a2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bee0e3d65a4bc434db601704c490e8fb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,53 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using UnityEditor.ShaderGraph;
using UnityEditor.ShaderGraph.Legacy;
using RenderQueue = UnityEditor.ShaderGraph.RenderQueue;
namespace ShaderGraphEssentials.Legacy
{
public enum BlendMode
{
Off = 0,
Alpha = 1,
Premultiply = 2,
Additive = 3,
Multiply = 4
}
public enum CullMode
{
Back,
Front,
Off
}
[FormerName("ShaderGraphEssentials.SGEUnlitMasterNode")]
class SGEUnlitMasterNode1 : AbstractMaterialNode, IMasterNode1
{
public RenderType m_renderType;
public RenderQueue m_renderQueue;
public BlendMode m_blendMode;
public CullMode m_cullMode;
public ZWrite m_zwrite;
public ZTest m_ztest;
public string m_customEditor;
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: da3d3f2a8d7d85e449a9c0012d1a5fed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d04914cc1d29a5b4c81c638af78bc0e4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,194 @@
void InitializeInputData(Varyings input, SurfaceDescription surfaceDescription, out InputData inputData)
{
inputData = (InputData)0;
inputData.positionWS = input.positionWS;
#ifdef _NORMALMAP
// IMPORTANT! If we ever support Flip on double sided materials ensure bitangent and tangent are NOT flipped.
float crossSign = (input.tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale();
float3 bitangent = crossSign * cross(input.normalWS.xyz, input.tangentWS.xyz);
inputData.tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
#if _NORMAL_DROPOFF_TS
inputData.normalWS = TransformTangentToWorld(surfaceDescription.NormalTS, inputData.tangentToWorld);
#elif _NORMAL_DROPOFF_OS
inputData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS);
#elif _NORMAL_DROPOFF_WS
inputData.normalWS = surfaceDescription.NormalWS;
#endif
#else
inputData.normalWS = input.normalWS;
#endif
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
inputData.shadowCoord = input.shadowCoord;
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
#endif
inputData.fogCoord = InitializeInputDataFog(float4(input.positionWS, 1.0), input.fogFactorAndVertexLight.x);
inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
#if defined(DYNAMICLIGHTMAP_ON)
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV.xy, input.sh, inputData.normalWS);
#elif !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
inputData.bakedGI = SAMPLE_GI(input.sh,
GetAbsolutePositionWS(inputData.positionWS),
inputData.normalWS,
inputData.viewDirectionWS,
input.positionCS.xy);
#else
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.sh, inputData.normalWS);
#endif
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
#if defined(DEBUG_DISPLAY)
#if defined(DYNAMICLIGHTMAP_ON)
inputData.dynamicLightmapUV = input.dynamicLightmapUV.xy;
#endif
#if defined(LIGHTMAP_ON)
inputData.staticLightmapUV = input.staticLightmapUV;
#else
inputData.vertexSH = input.sh;
#endif
#endif
}
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
output = BuildVaryings(input);
PackedVaryings packedOutput = (PackedVaryings)0;
packedOutput = PackVaryings(output);
return packedOutput;
}
half4 SGE_UniversalFragmentCustom(InputData inputData, SGECustomLightingData data)
{
#if defined(DEBUG_DISPLAY)
half4 debugColor;
if (CanDebugOverrideOutputColor(inputData, surfaceData, debugColor))
{
return debugColor;
}
#endif
uint meshRenderingLayers = GetMeshRenderingLayer();
half4 shadowMask = CalculateShadowMask(inputData);
AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(inputData.normalizedScreenSpaceUV);
Light mainLight = GetMainLight(inputData, shadowMask, aoFactor);
MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, aoFactor);
half3 diffuseColor = inputData.bakedGI;
half3 specularColor = half3(0, 0, 0);
#ifdef _LIGHT_LAYERS
if (IsMatchingLightLayer(mainLight.layerMask, meshRenderingLayers))
#endif
{
diffuseColor = inputData.bakedGI + SGE_DiffuseLightingCustom(mainLight, data);
specularColor = SGE_SpecularLightingCustom(mainLight, inputData.viewDirectionWS, data);
}
#ifdef _ADDITIONAL_LIGHTS
uint pixelLightCount = GetAdditionalLightsCount();
LIGHT_LOOP_BEGIN(pixelLightCount)
Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
{
diffuseColor += SGE_DiffuseLightingCustom(light, data);
specularColor += SGE_SpecularLightingCustom(light, inputData.viewDirectionWS, data);
}
LIGHT_LOOP_END
#endif
#ifdef _ADDITIONAL_LIGHTS_VERTEX
diffuseColor += inputData.vertexLighting;
#endif
half3 finalColor = diffuseColor * data.albedo + data.emission;
#if defined(_SPECGLOSSMAP) || defined(_SPECULAR_COLOR)
finalColor += specularColor;
#endif
return half4(finalColor, data.alpha);
}
void frag(
PackedVaryings packedInput
, out half4 outColor : SV_Target0
#ifdef _WRITE_RENDERING_LAYERS
, out float4 outRenderingLayers : SV_Target1
#endif
)
{
Varyings unpacked = UnpackVaryings(packedInput);
UNITY_SETUP_INSTANCE_ID(unpacked);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
SurfaceDescription surfaceDescription = BuildSurfaceDescription(unpacked);
#if defined(_SURFACE_TYPE_TRANSPARENT)
bool isTransparent = true;
#else
bool isTransparent = false;
#endif
#if defined(_ALPHATEST_ON)
half alpha = AlphaDiscard(surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold);
#elif defined(_SURFACE_TYPE_TRANSPARENT)
half alpha = surfaceDescription.Alpha;
#else
half alpha = half(1.0);
#endif
#if defined(LOD_FADE_CROSSFADE) && USE_UNITY_CROSSFADE
LODFadeCrossFade(unpacked.positionCS);
#endif
InputData inputData;
InitializeInputData(unpacked, surfaceDescription, inputData);
// TODO: Mip debug modes would require this, open question how to do this on ShaderGraph.
//SETUP_DEBUG_TEXTURE_DATA(inputData, unpacked.texCoord1.xy, _MainTex);
half3 normalTS = half3(0, 0, 0);
#if defined(_NORMALMAP) && defined(_NORMAL_DROPOFF_TS)
normalTS = surfaceDescription.NormalTS;
#endif
// SGECustomLightingData remap
SGECustomLightingData data;
data.albedo = surfaceDescription.BaseColor;
data.normal = inputData.normalWS;
data.specular = surfaceDescription.Specular;
data.glossiness = surfaceDescription.Glossiness;
data.smoothness = surfaceDescription.Shininess * 128.0;
data.emission = surfaceDescription.Emission;
data.alpha = alpha;
data.customLightingData1 = surfaceDescription.CustomLightingData1;
data.customLightingData2 = surfaceDescription.CustomLightingData2;
// custom lit style
half4 color = SGE_UniversalFragmentCustom(inputData, data);
color.rgb = MixFog(color.rgb, inputData.fogCoord);
color.a = OutputAlpha(color.a, isTransparent);
outColor = color;
#ifdef _WRITE_RENDERING_LAYERS
uint renderingLayers = GetMeshRenderingLayer();
outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
#endif
}

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 02c6e7a62fa4a1043bfbdfea0d508a7c
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,138 @@
void InitializeInputData(Varyings input, SurfaceDescription surfaceDescription, out InputData inputData)
{
inputData = (InputData)0;
inputData.positionWS = input.positionWS;
inputData.positionCS = input.positionCS;
#ifdef _NORMALMAP
// IMPORTANT! If we ever support Flip on double sided materials ensure bitangent and tangent are NOT flipped.
float crossSign = (input.tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale();
float3 bitangent = crossSign * cross(input.normalWS.xyz, input.tangentWS.xyz);
inputData.tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
#if _NORMAL_DROPOFF_TS
inputData.normalWS = TransformTangentToWorld(surfaceDescription.NormalTS, inputData.tangentToWorld);
#elif _NORMAL_DROPOFF_OS
inputData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS);
#elif _NORMAL_DROPOFF_WS
inputData.normalWS = surfaceDescription.NormalWS;
#endif
#else
inputData.normalWS = input.normalWS;
#endif
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
#if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
#endif
inputData.fogCoord = InitializeInputDataFog(float4(input.positionWS, 1.0), input.fogFactorAndVertexLight.x);
inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
#if defined(DYNAMICLIGHTMAP_ON)
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV.xy, input.sh, inputData.normalWS);
#elif !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
inputData.bakedGI = SAMPLE_GI(input.sh,
GetAbsolutePositionWS(inputData.positionWS),
inputData.normalWS,
inputData.viewDirectionWS,
inputData.positionCS.xy);
#else
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.sh, inputData.normalWS);
#endif
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
#if defined(DEBUG_DISPLAY)
#if defined(DYNAMICLIGHTMAP_ON)
inputData.dynamicLightmapUV = input.dynamicLightmapUV.xy;
#endif
#if defined(LIGHTMAP_ON)
inputData.staticLightmapUV = input.staticLightmapUV;
#else
inputData.vertexSH = input.sh;
#endif
#endif
}
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
output = BuildVaryings(input);
PackedVaryings packedOutput = (PackedVaryings)0;
packedOutput = PackVaryings(output);
return packedOutput;
}
void PatchSimpleLitSurfaceData(SurfaceDescription surfaceDescription, out SurfaceData outSurfaceData)
{
outSurfaceData = (SurfaceData)0;
#if _ALPHATEST_ON
half alpha = surfaceDescription.Alpha;
clip(alpha - surfaceDescription.AlphaClipThreshold);
#elif _SURFACE_TYPE_TRANSPARENT
half alpha = surfaceDescription.Alpha;
#else
half alpha = 1;
#endif
outSurfaceData.alpha = alpha;
outSurfaceData.albedo = surfaceDescription.BaseColor.rgb;
#ifdef _ALPHAPREMULTIPLY_ON
outSurfaceData.albedo *= outSurfaceData.alpha;
#endif
half4 specularSmoothness = half4(surfaceDescription.Specular, surfaceDescription.Shininess * 128.0);
outSurfaceData.metallic = 0.0; // unused
outSurfaceData.specular = specularSmoothness.rgb;
outSurfaceData.smoothness = specularSmoothness.a;
outSurfaceData.normalTS = surfaceDescription.NormalTS;
outSurfaceData.occlusion = 1.0;
outSurfaceData.emission = surfaceDescription.Emission;
}
FragmentOutput frag(PackedVaryings packedInput)
{
Varyings unpacked = UnpackVaryings(packedInput);
UNITY_SETUP_INSTANCE_ID(unpacked);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
SurfaceDescription surfaceDescription = BuildSurfaceDescription(unpacked);
SurfaceData surfaceData;
PatchSimpleLitSurfaceData(surfaceDescription, surfaceData);
#if defined(LOD_FADE_CROSSFADE) && USE_UNITY_CROSSFADE
LODFadeCrossFade(unpacked.positionCS);
#endif
InputData inputData;
InitializeInputData(unpacked, surfaceDescription, inputData);
// TODO: Mip debug modes would require this, open question how to do this on ShaderGraph.
//SETUP_DEBUG_TEXTURE_DATA(inputData, unpacked.uv, _MainTex);
float3 specular = surfaceDescription.Specular;
#ifdef _DBUFFER
ApplyDecal(unpacked.positionCS,
surfaceDescription.BaseColor,
specular,
inputData.normalWS,
1,
surfaceDescription.Occlusion,
surfaceDescription.Smoothness);
#endif
Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, inputData.shadowMask);
MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, inputData.shadowMask);
half4 color = half4(inputData.bakedGI * surfaceData.albedo + surfaceData.emission, surfaceData.alpha);
return SurfaceDataToGbuffer(surfaceData, inputData, color.rgb, kLightingSimpleLit);
}

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 512d43598c2b0804188d603a2937acbb
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,33 @@
#ifndef UNIVERSAL_LIGHTING_INCLUDED
#define UNIVERSAL_LIGHTING_INCLUDED
// necessary otherwise it'll throw en error on the node itself in the graph
// because the node HAS to compile by itself
// so without this, the master node is fine but this node itself won't compile because it doesn't know what "Light" is
struct Light
{
half3 direction;
half3 color;
half distanceAttenuation;
half shadowAttenuation;
uint layerMask;
};
// struct copied from "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Lighting.hlsl"
#endif
#ifndef SGE_CUSTOM_LIGHTING_INTERNAL_INCLUDED
#define SGE_CUSTOM_LIGHTING_INTERNAL_INCLUDED
struct SGECustomLightingData
{
float3 albedo;
float3 normal;
float3 specular;
float glossiness;
float smoothness; // converted from shininess
float3 emission;
float alpha;
float4 customLightingData1; // custom data you can use how you want (pass texture UV, vertex color ...etc)
float4 customLightingData2;
};
#endif

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 88bc0d7c5620cfd42b495c5b08e2a4c3
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,33 @@
#ifndef UNIVERSAL_LIGHTING_INCLUDED
#define UNIVERSAL_LIGHTING_INCLUDED
// necessary otherwise it'll throw en error on the node itself in the graph
// because the node HAS to compile by itself
// so without this, the master node is fine but this node itself won't compile because it doesn't know what "Light" is
struct Light
{
half3 direction;
half3 color;
half distanceAttenuation;
half shadowAttenuation;
uint layerMask;
};
// struct copied from "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/Lighting.hlsl"
#endif
// the only difference with this file and SGE_CustomLightingDataInternal.hlsl
// is that this one doens't #ifdef out the struct below.
// This file is included automatically in the graph using CustomLit
// whereas the SGE_CustomLightingDataInternal.hlsl is only there to get the user-defined custom function to compile.
#define SGE_CUSTOM_LIGHTING_INTERNAL_INCLUDED
struct SGECustomLightingData
{
float3 albedo;
float3 normal;
float3 specular;
float glossiness;
float smoothness; // converted from shininess
float3 emission;
float alpha;
float4 customLightingData1; // custom data you can use how you want (pass texture UV, vertex color ...etc)
float4 customLightingData2;
};

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 63cbeb35240376b4b8f71e4ccfc027a4
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
preprocessorOverride: 0
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,63 @@
#include "Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_CustomLightingInternal.hlsl"
/*
* This is what you can access in the custom functions
struct Light
{
half3 direction;
half3 color;
half distanceAttenuation;
half shadowAttenuation;
uint layerMask;
};
struct SGECustomLightingData
{
float3 albedo;
float3 normal; // world space
float3 specular;
float glossiness;
float smoothness; // automatically converted from shininess
float3 emission;
float alpha;
float4 customLightingData1; // custom data you can use how you want (pass texture UV, properties / uniforms, vertex color ...etc)
float4 customLightingData2;
};
*/
/*
* NOTES:
* Both of SGE_DiffuseLightingCustom and SGE_SpecularLightingCustom functions are called for each pixel light
* The name is hardcoded and very important, don't change it !
* Also, you can't access Uniforms / Properties directly in there,
nor pass it to the custom function node
trying either of this will throw an error
but you can pass it through data.customLightingData1 and use it how you see fit.
(there's an example of this in SGE_ToonLighting.hlsl)
*/
// this will function is called for every light
half3 SGE_DiffuseLightingCustom(Light light, SGECustomLightingData data)
{
float NdotL = saturate(dot(data.normal, light.direction));
return light.color * NdotL * light.distanceAttenuation * light.shadowAttenuation;
}
// this will function is called for every light
half3 SGE_SpecularLightingCustom(Light light, half3 viewDir, SGECustomLightingData data)
{
float3 halfVec = SafeNormalize(light.direction + viewDir);
float NdotH = saturate(dot(data.normal, halfVec));
float modifier = pow(NdotH, data.smoothness);
half3 specularReflection = data.specular * modifier;
return light.color * specularReflection * light.distanceAttenuation * light.shadowAttenuation;
}
// necessary function because at the moment a custom function node NEEDS to output a result in the graph
// otherwise it can be optimized out
// here we don't do anything, so it doesn't matter where you plug this node,
// because the custom lighting function will be called by the master node
void Passthrough_float(float4 In, out float4 Out)
{
Out = In;
}

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: ff58d7bda841877438d1453d66f77790
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,965 @@
{
"m_SGVersion": 2,
"m_Type": "UnityEditor.ShaderGraph.GraphData",
"m_ObjectId": "ed63c6b375e749ffa7267e5d1c22d817",
"m_Properties": [],
"m_Keywords": [],
"m_Nodes": [
{
"m_Id": "7efba297d0b74c8093d51218c6f395ff"
},
{
"m_Id": "a1d3bed2f71e4821a066eb16fb345c3f"
},
{
"m_Id": "cf9f37c16f3c4b809a112290771e909b"
},
{
"m_Id": "fadf2392448a4c6d9ba3d4f0c3686b9c"
},
{
"m_Id": "56729bfb24fb4e2ca951b1ddeb07c3f2"
},
{
"m_Id": "99b4dba4390b4069b70670fafb064690"
},
{
"m_Id": "acee2fabfe6146e9a2d3fdc348ff3c56"
},
{
"m_Id": "91cc7052d79a4ab2be1ade76e4a5dce1"
},
{
"m_Id": "f15775cdc4104f7aa5f3557417344d44"
},
{
"m_Id": "334cac89a1a1416d906a58e7e7e3edc7"
},
{
"m_Id": "dd567d54bd034347a473820fc6d86736"
},
{
"m_Id": "eb4eb88d62ad4999be29d2e49ae8c0f8"
},
{
"m_Id": "96bb2fb4f91942bb9606c4f2d40cb78a"
}
],
"m_GroupDatas": [],
"m_StickyNoteDatas": [
{
"m_Id": "198c71c014be406aaf84152cf667c598"
}
],
"m_Edges": [
{
"m_OutputSlot": {
"m_Node": {
"m_Id": "96bb2fb4f91942bb9606c4f2d40cb78a"
},
"m_SlotId": 0
},
"m_InputSlot": {
"m_Node": {
"m_Id": "eb4eb88d62ad4999be29d2e49ae8c0f8"
},
"m_SlotId": 0
}
},
{
"m_OutputSlot": {
"m_Node": {
"m_Id": "eb4eb88d62ad4999be29d2e49ae8c0f8"
},
"m_SlotId": 1
},
"m_InputSlot": {
"m_Node": {
"m_Id": "fadf2392448a4c6d9ba3d4f0c3686b9c"
},
"m_SlotId": 0
}
}
],
"m_VertexContext": {
"m_Position": {
"x": 0.0,
"y": 0.0
},
"m_Blocks": [
{
"m_Id": "7efba297d0b74c8093d51218c6f395ff"
},
{
"m_Id": "a1d3bed2f71e4821a066eb16fb345c3f"
},
{
"m_Id": "cf9f37c16f3c4b809a112290771e909b"
}
]
},
"m_FragmentContext": {
"m_Position": {
"x": 0.0,
"y": 200.0
},
"m_Blocks": [
{
"m_Id": "fadf2392448a4c6d9ba3d4f0c3686b9c"
},
{
"m_Id": "56729bfb24fb4e2ca951b1ddeb07c3f2"
},
{
"m_Id": "99b4dba4390b4069b70670fafb064690"
},
{
"m_Id": "acee2fabfe6146e9a2d3fdc348ff3c56"
},
{
"m_Id": "91cc7052d79a4ab2be1ade76e4a5dce1"
},
{
"m_Id": "f15775cdc4104f7aa5f3557417344d44"
},
{
"m_Id": "334cac89a1a1416d906a58e7e7e3edc7"
},
{
"m_Id": "dd567d54bd034347a473820fc6d86736"
}
]
},
"m_PreviewData": {
"serializedMesh": {
"m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}",
"m_Guid": ""
}
},
"m_Path": "Shader Graphs",
"m_ConcretePrecision": 0,
"m_OutputNode": {
"m_Id": ""
},
"m_ActiveTargets": [
{
"m_Id": "41bfb34880a24490aa9f630f92947111"
}
]
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.StickyNoteData",
"m_ObjectId": "198c71c014be406aaf84152cf667c598",
"m_Title": "Custom Lighting",
"m_Content": "Input your own color in the custom function node.",
"m_TextSize": 0,
"m_Theme": 0,
"m_Position": {
"serializedVersion": "2",
"x": -606.0,
"y": 85.0,
"width": 200.0,
"height": 100.0
},
"m_Group": {
"m_Id": ""
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.NormalMaterialSlot",
"m_ObjectId": "32073861999f411d875ed672cf22d495",
"m_Id": 0,
"m_DisplayName": "Normal",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Normal",
"m_StageCapability": 1,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_Space": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "334cac89a1a1416d906a58e7e7e3edc7",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.CustomLightingData1",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "44d74a125bc04035ababff9dfef7aa9b"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.CustomLightingData1"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot",
"m_ObjectId": "37e6fe3777ab46b39febcb17b4cf8cee",
"m_Id": 0,
"m_DisplayName": "Base Color",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "BaseColor",
"m_StageCapability": 2,
"m_Value": {
"x": 0.5,
"y": 0.5,
"z": 0.5
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_ColorMode": 0,
"m_DefaultColor": {
"r": 0.5,
"g": 0.5,
"b": 0.5,
"a": 1.0
}
}
{
"m_SGVersion": 0,
"m_Type": "ShaderGraphEssentials.SGEUniversalTarget",
"m_ObjectId": "41bfb34880a24490aa9f630f92947111",
"m_ActiveSubTarget": {
"m_Id": "f4544c958fd04f12890669c1c6416df8"
},
"m_RenderType": 0,
"m_RenderQueue": 1,
"m_BlendMode": 0,
"m_AlphaClip": false,
"m_CullMode": 2,
"m_ZWrite": 0,
"m_ZTest": 0,
"m_CustomEditorGUI": ""
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot",
"m_ObjectId": "41d4ebdb0347493295537c91fadca239",
"m_Id": 0,
"m_DisplayName": "In",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "In",
"m_StageCapability": 3,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.ColorRGBAMaterialSlot",
"m_ObjectId": "44d74a125bc04035ababff9dfef7aa9b",
"m_Id": 0,
"m_DisplayName": "Custom Lighting Data 1",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "CustomLightingData1",
"m_StageCapability": 2,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "4f090433c2c0473ea7f82f52dd28f272",
"m_Id": 0,
"m_DisplayName": "Shininess",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Shininess",
"m_StageCapability": 2,
"m_Value": 0.5,
"m_DefaultValue": 0.5,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "56729bfb24fb4e2ca951b1ddeb07c3f2",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.NormalTS",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "74c8581c218e42f39a7b136a5909a73a"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.NormalTS"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.ColorRGBAMaterialSlot",
"m_ObjectId": "5e43231d43cf43c8b11726d431c9599f",
"m_Id": 0,
"m_DisplayName": "Custom Lighting Data 2",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "CustomLightingData2",
"m_StageCapability": 2,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot",
"m_ObjectId": "6067176e41b94c17bc90dcec5989cc90",
"m_Id": 1,
"m_DisplayName": "Out",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "Out",
"m_StageCapability": 3,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot",
"m_ObjectId": "661dd35371b440999c429205ad2bc785",
"m_Id": 0,
"m_DisplayName": "Emission",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Emission",
"m_StageCapability": 2,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_ColorMode": 1,
"m_DefaultColor": {
"r": 0.0,
"g": 0.0,
"b": 0.0,
"a": 1.0
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.PositionMaterialSlot",
"m_ObjectId": "67c05795a65d45948a77418a30bec828",
"m_Id": 0,
"m_DisplayName": "Position",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Position",
"m_StageCapability": 1,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_Space": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot",
"m_ObjectId": "72b1d677aa644b8db16037e65b02c0ba",
"m_Id": 0,
"m_DisplayName": "Out",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "Out",
"m_StageCapability": 3,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0,
"w": 0.0
},
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.NormalMaterialSlot",
"m_ObjectId": "74c8581c218e42f39a7b136a5909a73a",
"m_Id": 0,
"m_DisplayName": "Normal (Tangent Space)",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "NormalTS",
"m_StageCapability": 2,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_Space": 3
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "7efba297d0b74c8093d51218c6f395ff",
"m_Group": {
"m_Id": ""
},
"m_Name": "VertexDescription.Position",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "67c05795a65d45948a77418a30bec828"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "VertexDescription.Position"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.TangentMaterialSlot",
"m_ObjectId": "84ee1b81a59c46808dc179d24ac2c8ef",
"m_Id": 0,
"m_DisplayName": "Tangent",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Tangent",
"m_StageCapability": 1,
"m_Value": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_Space": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "91cc7052d79a4ab2be1ade76e4a5dce1",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Glossiness",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "c27c68ef6f594ce7896102b6980775f3"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Glossiness"
}
{
"m_SGVersion": 1,
"m_Type": "UnityEditor.ShaderGraph.ColorNode",
"m_ObjectId": "96bb2fb4f91942bb9606c4f2d40cb78a",
"m_Group": {
"m_Id": ""
},
"m_Name": "Color",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -609.0,
"y": 191.0,
"width": 208.0,
"height": 127.0
}
},
"m_Slots": [
{
"m_Id": "72b1d677aa644b8db16037e65b02c0ba"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_Color": {
"color": {
"r": 0.5094339847564697,
"g": 0.5094339847564697,
"b": 0.5094339847564697,
"a": 0.0
},
"mode": 0
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "99b4dba4390b4069b70670fafb064690",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Emission",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "661dd35371b440999c429205ad2bc785"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Emission"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "a1d3bed2f71e4821a066eb16fb345c3f",
"m_Group": {
"m_Id": ""
},
"m_Name": "VertexDescription.Normal",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "32073861999f411d875ed672cf22d495"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "VertexDescription.Normal"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "acee2fabfe6146e9a2d3fdc348ff3c56",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Specular",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "f87e65b98538435aaa6ddda4c9232e61"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Specular"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "c27c68ef6f594ce7896102b6980775f3",
"m_Id": 0,
"m_DisplayName": "Glossiness",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Glossiness",
"m_StageCapability": 2,
"m_Value": 0.5,
"m_DefaultValue": 0.5,
"m_Labels": []
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "cf9f37c16f3c4b809a112290771e909b",
"m_Group": {
"m_Id": ""
},
"m_Name": "VertexDescription.Tangent",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "84ee1b81a59c46808dc179d24ac2c8ef"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "VertexDescription.Tangent"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "dd567d54bd034347a473820fc6d86736",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.CustomLightingData2",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "5e43231d43cf43c8b11726d431c9599f"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.CustomLightingData2"
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.CustomFunctionNode",
"m_ObjectId": "eb4eb88d62ad4999be29d2e49ae8c0f8",
"m_Group": {
"m_Id": ""
},
"m_Name": "Custom Function",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -314.0,
"y": 194.0,
"width": 142.0,
"height": 94.0
}
},
"m_Slots": [
{
"m_Id": "41d4ebdb0347493295537c91fadca239"
},
{
"m_Id": "6067176e41b94c17bc90dcec5989cc90"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": false,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SourceType": 0,
"m_FunctionName": "Passthrough",
"m_FunctionSource": "ff58d7bda841877438d1453d66f77790",
"m_FunctionBody": "Enter function body here..."
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "f15775cdc4104f7aa5f3557417344d44",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.Shininess",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "4f090433c2c0473ea7f82f52dd28f272"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.Shininess"
}
{
"m_SGVersion": 0,
"m_Type": "ShaderGraphEssentials.SGEUniversalCustomLitSubTarget",
"m_ObjectId": "f4544c958fd04f12890669c1c6416df8",
"m_NormalDropOffSpace": 0
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot",
"m_ObjectId": "f87e65b98538435aaa6ddda4c9232e61",
"m_Id": 0,
"m_DisplayName": "Specular Color",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "Specular",
"m_StageCapability": 2,
"m_Value": {
"x": 0.5,
"y": 0.5,
"z": 0.5
},
"m_DefaultValue": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"m_Labels": [],
"m_ColorMode": 0,
"m_DefaultColor": {
"r": 0.5,
"g": 0.5,
"b": 0.5,
"a": 1.0
}
}
{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.BlockNode",
"m_ObjectId": "fadf2392448a4c6d9ba3d4f0c3686b9c",
"m_Group": {
"m_Id": ""
},
"m_Name": "SurfaceDescription.BaseColor",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": 0.0,
"y": 0.0,
"width": 0.0,
"height": 0.0
}
},
"m_Slots": [
{
"m_Id": "37e6fe3777ab46b39febcb17b4cf8cee"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_SerializedDescriptor": "SurfaceDescription.BaseColor"
}

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 823db6a430339504f989cd2b15452ae7
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}

@ -0,0 +1,72 @@
#include "Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_CustomLightingInternal.hlsl"
/*
* This is what you can access in the custom functions
struct Light
{
half3 direction;
half3 color;
half distanceAttenuation;
half shadowAttenuation;
uint layerMask;
};
struct SGECustomLightingData
{
float3 albedo;
float3 normal; // world space
float3 specular;
float glossiness;
float smoothness; // automatically converted from shininess
float3 emission;
float alpha;
float4 customLightingData1; // custom data you can use how you want (pass texture UV, properties / uniforms, vertex color ...etc)
float4 customLightingData2;
};
*/
// this will function is called for every light
half3 SGE_DiffuseLightingCustom(Light light, SGECustomLightingData data)
{
half NdotL = saturate(dot(data.normal, light.direction));
half lightIntensity = smoothstep(0, 0.01, NdotL);
return light.color * lightIntensity * light.distanceAttenuation * light.shadowAttenuation;
}
// this will function is called for every light
// you can't access Uniforms directly in there,
// nor pass it to the custom function node
// trying either of this will throw an error
// but you can pass it through data.customLightingData1 and use it how you see fit here.
half3 SGE_SpecularLightingCustom(Light light, half3 viewDir, SGECustomLightingData data)
{
const float EPSILON = 0.01f;
// compute specular
half NdotL = saturate(dot(data.normal, light.direction));
half lightIntensity = smoothstep(0, EPSILON, NdotL);
float3 halfVec = SafeNormalize(light.direction + viewDir);
float NdotH = saturate(dot(data.normal, halfVec));
float modifier = pow(NdotH * lightIntensity, data.smoothness);
float modifierSmooth = smoothstep(EPSILON * 0.5, EPSILON, modifier);
half3 specularReflection = data.specular * modifierSmooth;
// compute rimlight
// data.customLightingData1: xyz = _RimColor
// data.customLightingData2: x = _RimThreshold, y = _RimAmount
half rimDot = 1 - dot(viewDir, data.normal);
half rimIntensity = rimDot * pow(NdotL, (half)data.customLightingData2.x);
rimIntensity = smoothstep(data.customLightingData2.y - EPSILON, data.customLightingData2.y + EPSILON, rimIntensity);
half3 rim = rimIntensity * data.customLightingData1.xyz;
// I chose to have the rim affected by the light's color, but feel free to improvise!
return light.color * (specularReflection * light.distanceAttenuation * light.shadowAttenuation + rim);
}
// necessary function because at the moment a custom function node NEEDS to output a result in the graph
// otherwise it can be optimized out
// here we don't do anything, so it doesn't matter where you plug this node,
// because the custom lighting function will be called by the master node
void Passthrough_float(float4 In, out float4 Out)
{
Out = In;
}

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3957bbcf7c3a3a748a82a440dcc9ea67
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,137 @@
void InitializeInputData(Varyings input, SurfaceDescription surfaceDescription, out InputData inputData)
{
inputData = (InputData)0;
inputData.positionWS = input.positionWS;
#ifdef _NORMALMAP
// IMPORTANT! If we ever support Flip on double sided materials ensure bitangent and tangent are NOT flipped.
float crossSign = (input.tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale();
float3 bitangent = crossSign * cross(input.normalWS.xyz, input.tangentWS.xyz);
inputData.tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
#if _NORMAL_DROPOFF_TS
inputData.normalWS = TransformTangentToWorld(surfaceDescription.NormalTS, inputData.tangentToWorld);
#elif _NORMAL_DROPOFF_OS
inputData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS);
#elif _NORMAL_DROPOFF_WS
inputData.normalWS = surfaceDescription.NormalWS;
#endif
#else
inputData.normalWS = input.normalWS;
#endif
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
inputData.shadowCoord = input.shadowCoord;
#elif defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
#endif
inputData.fogCoord = InitializeInputDataFog(float4(input.positionWS, 1.0), input.fogFactorAndVertexLight.x);
inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
#if defined(DYNAMICLIGHTMAP_ON)
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV.xy, input.sh, inputData.normalWS);
#elif !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
inputData.bakedGI = SAMPLE_GI(input.sh,
GetAbsolutePositionWS(inputData.positionWS),
inputData.normalWS,
inputData.viewDirectionWS,
input.positionCS.xy);
#else
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.sh, inputData.normalWS);
#endif
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
#if defined(DEBUG_DISPLAY)
#if defined(DYNAMICLIGHTMAP_ON)
inputData.dynamicLightmapUV = input.dynamicLightmapUV.xy;
#endif
#if defined(LIGHTMAP_ON)
inputData.staticLightmapUV = input.staticLightmapUV;
#else
inputData.vertexSH = input.sh;
#endif
#endif
}
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
output = BuildVaryings(input);
PackedVaryings packedOutput = (PackedVaryings)0;
packedOutput = PackVaryings(output);
return packedOutput;
}
void frag(
PackedVaryings packedInput
, out half4 outColor : SV_Target0
#ifdef _WRITE_RENDERING_LAYERS
, out float4 outRenderingLayers : SV_Target1
#endif
)
{
Varyings unpacked = UnpackVaryings(packedInput);
UNITY_SETUP_INSTANCE_ID(unpacked);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
SurfaceDescription surfaceDescription = BuildSurfaceDescription(unpacked);
#if defined(_SURFACE_TYPE_TRANSPARENT)
bool isTransparent = true;
#else
bool isTransparent = false;
#endif
#if defined(_ALPHATEST_ON)
half alpha = AlphaDiscard(surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold);
#elif defined(_SURFACE_TYPE_TRANSPARENT)
half alpha = surfaceDescription.Alpha;
#else
half alpha = half(1.0);
#endif
#if defined(LOD_FADE_CROSSFADE) && USE_UNITY_CROSSFADE
LODFadeCrossFade(unpacked.positionCS);
#endif
InputData inputData;
InitializeInputData(unpacked, surfaceDescription, inputData);
// TODO: Mip debug modes would require this, open question how to do this on ShaderGraph.
//SETUP_DEBUG_TEXTURE_DATA(inputData, unpacked.texCoord1.xy, _MainTex);
half3 normalTS = half3(0, 0, 0);
#if defined(_NORMALMAP) && defined(_NORMAL_DROPOFF_TS)
normalTS = surfaceDescription.NormalTS;
#endif
alpha = saturate(alpha);
half3 baseColor = AlphaModulate(surfaceDescription.BaseColor, alpha);
half4 color = UniversalFragmentBlinnPhong(
inputData,
baseColor,
half4(surfaceDescription.Specular, surfaceDescription.Smoothness),
surfaceDescription.Smoothness,
surfaceDescription.Emission,
alpha,
normalTS);
color.rgb = MixFog(color.rgb, inputData.fogCoord);
color.a = OutputAlpha(color.a, isTransparent);
outColor = color;
#ifdef _WRITE_RENDERING_LAYERS
uint renderingLayers = GetMeshRenderingLayer();
outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
#endif
}

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: fda4d5a52149e5a499b247360d8702fc
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,138 @@
void InitializeInputData(Varyings input, SurfaceDescription surfaceDescription, out InputData inputData)
{
inputData = (InputData)0;
inputData.positionWS = input.positionWS;
inputData.positionCS = input.positionCS;
#ifdef _NORMALMAP
// IMPORTANT! If we ever support Flip on double sided materials ensure bitangent and tangent are NOT flipped.
float crossSign = (input.tangentWS.w > 0.0 ? 1.0 : -1.0) * GetOddNegativeScale();
float3 bitangent = crossSign * cross(input.normalWS.xyz, input.tangentWS.xyz);
inputData.tangentToWorld = half3x3(input.tangentWS.xyz, bitangent.xyz, input.normalWS.xyz);
#if _NORMAL_DROPOFF_TS
inputData.normalWS = TransformTangentToWorld(surfaceDescription.NormalTS, inputData.tangentToWorld);
#elif _NORMAL_DROPOFF_OS
inputData.normalWS = TransformObjectToWorldNormal(surfaceDescription.NormalOS);
#elif _NORMAL_DROPOFF_WS
inputData.normalWS = surfaceDescription.NormalWS;
#endif
#else
inputData.normalWS = input.normalWS;
#endif
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
#if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
#else
inputData.shadowCoord = float4(0, 0, 0, 0);
#endif
inputData.fogCoord = InitializeInputDataFog(float4(input.positionWS, 1.0), input.fogFactorAndVertexLight.x);
inputData.vertexLighting = input.fogFactorAndVertexLight.yzw;
#if defined(DYNAMICLIGHTMAP_ON)
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.dynamicLightmapUV.xy, input.sh, inputData.normalWS);
#elif !defined(LIGHTMAP_ON) && (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
inputData.bakedGI = SAMPLE_GI(input.sh,
GetAbsolutePositionWS(inputData.positionWS),
inputData.normalWS,
inputData.viewDirectionWS,
inputData.positionCS.xy);
#else
inputData.bakedGI = SAMPLE_GI(input.staticLightmapUV, input.sh, inputData.normalWS);
#endif
inputData.normalizedScreenSpaceUV = GetNormalizedScreenSpaceUV(input.positionCS);
inputData.shadowMask = SAMPLE_SHADOWMASK(input.staticLightmapUV);
#if defined(DEBUG_DISPLAY)
#if defined(DYNAMICLIGHTMAP_ON)
inputData.dynamicLightmapUV = input.dynamicLightmapUV.xy;
#endif
#if defined(LIGHTMAP_ON)
inputData.staticLightmapUV = input.staticLightmapUV;
#else
inputData.vertexSH = input.sh;
#endif
#endif
}
PackedVaryings vert(Attributes input)
{
Varyings output = (Varyings)0;
output = BuildVaryings(input);
PackedVaryings packedOutput = (PackedVaryings)0;
packedOutput = PackVaryings(output);
return packedOutput;
}
void PatchSimpleLitSurfaceData(SurfaceDescription surfaceDescription, out SurfaceData outSurfaceData)
{
outSurfaceData = (SurfaceData)0;
#if _ALPHATEST_ON
half alpha = surfaceDescription.Alpha;
clip(alpha - surfaceDescription.AlphaClipThreshold);
#elif _SURFACE_TYPE_TRANSPARENT
half alpha = surfaceDescription.Alpha;
#else
half alpha = 1;
#endif
outSurfaceData.alpha = alpha;
outSurfaceData.albedo = AlphaModulate(surfaceDescription.BaseColor, alpha);;
#ifdef _ALPHAPREMULTIPLY_ON
outSurfaceData.albedo *= outSurfaceData.alpha;
#endif
half4 specularSmoothness = half4(surfaceDescription.Specular, surfaceDescription.Smoothness);
outSurfaceData.metallic = 0.0; // unused
outSurfaceData.specular = specularSmoothness.rgb;
outSurfaceData.smoothness = specularSmoothness.a;
outSurfaceData.normalTS = surfaceDescription.NormalTS;
outSurfaceData.occlusion = 1.0;
outSurfaceData.emission = surfaceDescription.Emission;
}
FragmentOutput frag(PackedVaryings packedInput)
{
Varyings unpacked = UnpackVaryings(packedInput);
UNITY_SETUP_INSTANCE_ID(unpacked);
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
SurfaceDescription surfaceDescription = BuildSurfaceDescription(unpacked);
SurfaceData surfaceData;
PatchSimpleLitSurfaceData(surfaceDescription, surfaceData);
#if defined(LOD_FADE_CROSSFADE) && USE_UNITY_CROSSFADE
LODFadeCrossFade(unpacked.positionCS);
#endif
InputData inputData;
InitializeInputData(unpacked, surfaceDescription, inputData);
// TODO: Mip debug modes would require this, open question how to do this on ShaderGraph.
//SETUP_DEBUG_TEXTURE_DATA(inputData, unpacked.uv, _MainTex);
float3 specular = surfaceDescription.Specular;
#ifdef _DBUFFER
ApplyDecal(unpacked.positionCS,
surfaceDescription.BaseColor,
specular,
inputData.normalWS,
1,
surfaceDescription.Occlusion,
surfaceDescription.Smoothness);
#endif
Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, inputData.shadowMask);
MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, inputData.shadowMask);
half4 color = half4(inputData.bakedGI * surfaceData.albedo + surfaceData.emission, surfaceData.alpha);
return SurfaceDataToGbuffer(surfaceData, inputData, color.rgb, kLightingSimpleLit);
}

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: be0a8589dbc698548aeb21bac1b72c73
ShaderIncludeImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7a5534129ff657d45a4274b7585aa066
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,130 @@
Pass
{
$splice(PassName)
Tags
{
$splice(LightMode)
}
// Render State
$splice(Blending)
$splice(Culling)
$splice(ZTest)
$splice(ZWrite)
$splice(ColorMask)
$splice(Stencil)
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
// Debug
$splice(Debug)
// --------------------------------------------------
// Pass
// Pragmas
$splice(PassPragmas)
// Keywords
$splice(PassKeywords)
$splice(GraphKeywords)
// Defines
$SurfaceType.Transparent: #define _SURFACE_TYPE_TRANSPARENT 1
$AlphaClip: #define _AlphaClip 1
$SpecularColor: #define _SPECULAR_COLOR 1
$Normal: #define _NORMALMAP 1
$BlendMode.Add: #define _BLENDMODE_ADD 1
$BlendMode.Premultiply: #define _ALPHAPREMULTIPLY_ON 1
$features.NormalDropOffTS: #define _NORMAL_DROPOFF_TS 1
$features.NormalDropOffOS: #define _NORMAL_DROPOFF_OS 1
$features.NormalDropOffWS: #define _NORMAL_DROPOFF_WS 1
$Attributes.normalOS: #define ATTRIBUTES_NEED_NORMAL
$Attributes.tangentOS: #define ATTRIBUTES_NEED_TANGENT
$Attributes.uv0: #define ATTRIBUTES_NEED_TEXCOORD0
$Attributes.uv1: #define ATTRIBUTES_NEED_TEXCOORD1
$Attributes.uv2: #define ATTRIBUTES_NEED_TEXCOORD2
$Attributes.uv3: #define ATTRIBUTES_NEED_TEXCOORD3
$Attributes.color: #define ATTRIBUTES_NEED_COLOR
$Varyings.positionWS: #define VARYINGS_NEED_POSITION_WS
$Varyings.positionPredisplacementWS: #define VARYINGS_NEED_POSITIONPREDISPLACEMENT_WS
$Varyings.normalWS: #define VARYINGS_NEED_NORMAL_WS
$Varyings.tangentWS: #define VARYINGS_NEED_TANGENT_WS
$Varyings.texCoord0: #define VARYINGS_NEED_TEXCOORD0
$Varyings.texCoord1: #define VARYINGS_NEED_TEXCOORD1
$Varyings.texCoord2: #define VARYINGS_NEED_TEXCOORD2
$Varyings.texCoord3: #define VARYINGS_NEED_TEXCOORD3
$Varyings.color: #define VARYINGS_NEED_COLOR
$Varyings.viewDirectionWS: #define VARYINGS_NEED_VIEWDIRECTION_WS
$Varyings.bitangentWS: #define VARYINGS_NEED_BITANGENT_WS
$Varyings.screenPosition: #define VARYINGS_NEED_SCREENPOSITION
$Varyings.fogFactorAndVertexLight: #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
$Varyings.cullFace: #define VARYINGS_NEED_CULLFACE
$features.graphVertex: #define FEATURES_GRAPH_VERTEX
$splice(PassInstancing)
$splice(GraphDefines)
$splice(DotsInstancingVars)
// Includes
$splice(CustomInterpolatorPreInclude)
$splice(PassIncludes)
// --------------------------------------------------
// Graph
// Graph Properties
$splice(GraphProperties)
// Graph Includes
$splice(GraphIncludes)
// -- Property used by ScenePickingPass
#ifdef SCENEPICKINGPASS
float4 _SelectionID;
#endif
// -- Properties used by SceneSelectionPass
#ifdef SCENESELECTIONPASS
int _ObjectId;
int _PassValue;
#endif
// Graph Functions
$splice(GraphFunctions)
$splice(CustomInterpolatorPreVertex)
// Graph Vertex
$splice(GraphVertex)
$splice(CustomInterpolatorPreSurface)
// Graph Pixel
$splice(GraphPixel)
// --------------------------------------------------
// Structs and Packing
$splice(CustomInterpolatorPrePacking)
$buildType(Attributes)
$buildType(Varyings)
// --------------------------------------------------
// Build Graph Inputs
$features.graphVertex: $include("BuildVertexDescriptionInputs.template.hlsl")
$features.graphPixel: $include("BuildSurfaceDescriptionInputs.template.hlsl")
// --------------------------------------------------
// Main
$splice(MainInclude)
ENDHLSL
}

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7f48c3f430bfe574a86851f4ba45d6f6
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a66ba68fb8bca1a479afdf340430c9ca
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3651e0c7d29b0bf49a967294422e9d79
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,76 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System;
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
using UnityEditor.ShaderGraph;
using UnityEngine;
namespace ShaderGraphEssentials
{
class CreateSGECustomLitShaderGraph : EndNameEditAction
{
private const string DefaultCustomLightingGraphPath =
"Assets/Plugins/ShaderGraphEssentials/Plugin/Editor/Plugin_URP/Shaders/SGE_DefaultCustomLightingGraph.shadergraph";
[MenuItem("Assets/Create/Shader Graph/ShaderGraphEssentials/SGE CustomLit Shader Graph", false, 303)]
public static void CreateMaterialGraph()
{
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateSGECustomLitShaderGraph>(),
string.Format("New Shader Graph.{0}", ShaderGraphImporter.Extension), null, null);
}
public override void Action(int instanceId, string pathName, string resourceFile)
{
// we try to copy the default already have the custom lighting function node setup
bool success = AssetDatabase.CopyAsset(DefaultCustomLightingGraphPath, pathName);
// if it fails we fallback to the "official" method
if (!success)
{
Debug.LogWarning("ShaderGraphEssentials couldn't create the new custom lit graph by copying the default from " + DefaultCustomLightingGraphPath +
" to " + pathName + ". An empty graph has been created instead, you now have to create the custom lighting function node before it will compile correctly.");
CreateEmptyGraph();
}
AssetDatabase.Refresh();
}
private void CreateEmptyGraph()
{
var target = (SGEUniversalTarget)Activator.CreateInstance(typeof(SGEUniversalTarget));
target.TrySetActiveSubTarget(typeof(SGEUniversalCustomLitSubTarget));
var blockDescriptors = new []
{
BlockFields.VertexDescription.Position,
BlockFields.VertexDescription.Normal,
BlockFields.VertexDescription.Tangent,
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescription.NormalTS,
BlockFields.SurfaceDescription.Specular,
SGEFields.SurfaceDescription.Glossiness,
SGEFields.SurfaceDescription.Shininess,
BlockFields.SurfaceDescription.Emission,
SGEFields.SurfaceDescription.CustomLightingData1,
SGEFields.SurfaceDescription.CustomLightingData2,
};
GraphUtil.CreateNewGraphWithOutputs(new [] {target}, blockDescriptors);
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3168e2865266f4a4fbe1e9f901ea1ca7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -0,0 +1,47 @@
//
// ShaderGraphEssentials for Unity
// (c) 2019 PH Graphics
// Source code may be used and modified for personal or commercial projects.
// Source code may NOT be redistributed or sold.
//
// *** A NOTE ABOUT PIRACY ***
//
// If you got this asset from a pirate site, please consider buying it from the Unity asset store. This asset is only legally available from the Unity Asset Store.
//
// I'm a single indie dev supporting my family by spending hundreds and thousands of hours on this and other assets. It's very offensive, rude and just plain evil to steal when I (and many others) put so much hard work into the software.
//
// Thank you.
//
// *** END NOTE ABOUT PIRACY ***
//
using System;
using UnityEditor;
using UnityEditor.ShaderGraph;
namespace ShaderGraphEssentials
{
static class CreateSGESimpleLitShaderGraph
{
[MenuItem("Assets/Create/Shader Graph/ShaderGraphEssentials/SGE SimpleLit Shader Graph", false, 302)]
public static void CreateSGESimpleLitGraph()
{
var target = (SGEUniversalTarget)Activator.CreateInstance(typeof(SGEUniversalTarget));
target.TrySetActiveSubTarget(typeof(SGEUniversalSimpleLitSubTarget));
var blockDescriptors = new []
{
BlockFields.VertexDescription.Position,
BlockFields.VertexDescription.Normal,
BlockFields.VertexDescription.Tangent,
BlockFields.SurfaceDescription.BaseColor,
BlockFields.SurfaceDescription.NormalTS,
BlockFields.SurfaceDescription.Specular,
BlockFields.SurfaceDescription.Smoothness,
BlockFields.SurfaceDescription.Emission,
};
GraphUtil.CreateNewGraphWithOutputs(new [] {target}, blockDescriptors);
}
}
}

Some files were not shown because too many files have changed in this diff Show More