123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- using System.Reflection;
- using UnityEditor.ShaderGraph.Drawing.Controls;
- using UnityEngine;
- using UnityEditor.Graphing;
- namespace UnityEditor.ShaderGraph
- {
- [Title("Artistic", "Blend", "Blend")]
- class BlendNode : CodeFunctionNode
- {
- public BlendNode()
- {
- name = "Blend";
- }
- string GetCurrentBlendName()
- {
- return System.Enum.GetName(typeof(BlendMode), m_BlendMode);
- }
- [SerializeField]
- BlendMode m_BlendMode = BlendMode.Overlay;
- [EnumControl("Mode")]
- public BlendMode blendMode
- {
- get { return m_BlendMode; }
- set
- {
- if (m_BlendMode == value)
- return;
- m_BlendMode = value;
- Dirty(ModificationScope.Graph);
- }
- }
- protected override MethodInfo GetFunctionToConvert()
- {
- return GetType().GetMethod(string.Format("Unity_Blend_{0}", GetCurrentBlendName()),
- BindingFlags.Static | BindingFlags.NonPublic);
- }
- static string Unity_Blend_Burn(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = 1.0 - (1.0 - Blend)/(Base + 0.000000000001);
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_Darken(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = min(Blend, Base);
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_Difference(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = abs(Blend - Base);
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_Dodge(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = Base / (1.0 - clamp(Blend, 0.000001, 0.999999));
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_Divide(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = Base / (Blend + 0.000000000001);
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_Exclusion(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = Blend + Base - (2.0 * Blend * Base);
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_HardLight(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- $precision{slot2dimension} result1 = 1.0 - 2.0 * (1.0 - Base) * (1.0 - Blend);
- $precision{slot2dimension} result2 = 2.0 * Base * Blend;
- $precision{slot2dimension} zeroOrOne = step(Blend, 0.5);
- Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_HardMix(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = step(1 - Base, Blend);
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_Lighten(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = max(Blend, Base);
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_LinearBurn(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = Base + Blend - 1.0;
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_LinearDodge(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = Base + Blend;
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_LinearLight(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = Blend < 0.5 ? max(Base + (2 * Blend) - 1, 0) : min(Base + 2 * (Blend - 0.5), 1);
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_LinearLightAddSub(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = Blend + 2.0 * Base - 1.0;
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_Multiply(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = Base * Blend;
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_Negation(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = 1.0 - abs(1.0 - Blend - Base);
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_Screen(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = 1.0 - (1.0 - Blend) * (1.0 - Base);
- Out = lerp(Base, Out, Opacity);
- }";
- }
- static string Unity_Blend_Overlay(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- $precision{slot2dimension} result1 = 1.0 - 2.0 * (1.0 - Base) * (1.0 - Blend);
- $precision{slot2dimension} result2 = 2.0 * Base * Blend;
- $precision{slot2dimension} zeroOrOne = step(Base, 0.5);
- Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
- Out = lerp(Base, Out, Opacity);
- }
- ";
- }
- static string Unity_Blend_PinLight(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- $precision{slot2dimension} check = step (0.5, Blend);
- $precision{slot2dimension} result1 = check * max(2.0 * (Base - 0.5), Blend);
- Out = result1 + (1.0 - check) * min(2.0 * Base, Blend);
- Out = lerp(Base, Out, Opacity);
- }
- ";
- }
- static string Unity_Blend_SoftLight(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- $precision{slot2dimension} result1 = 2.0 * Base * Blend + Base * Base * (1.0 - 2.0 * Blend);
- $precision{slot2dimension} result2 = sqrt(Base) * (2.0 * Blend - 1.0) + 2.0 * Base * (1.0 - Blend);
- $precision{slot2dimension} zeroOrOne = step(0.5, Blend);
- Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
- Out = lerp(Base, Out, Opacity);
- }
- ";
- }
- static string Unity_Blend_VividLight(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Base = clamp(Base, 0.000001, 0.999999);
- $precision{slot2dimension} result1 = 1.0 - (1.0 - Blend) / (2.0 * Base);
- $precision{slot2dimension} result2 = Blend / (2.0 * (1.0 - Base));
- $precision{slot2dimension} zeroOrOne = step(0.5, Base);
- Out = result2 * zeroOrOne + (1 - zeroOrOne) * result1;
- Out = lerp(Base, Out, Opacity);
- }
- ";
- }
- static string Unity_Blend_Subtract(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = Base - Blend;
- Out = lerp(Base, Out, Opacity);
- }
- ";
- }
- static string Unity_Blend_Overwrite(
- [Slot(0, Binding.None)] DynamicDimensionVector Base,
- [Slot(1, Binding.None)] DynamicDimensionVector Blend,
- [Slot(3, Binding.None, 1, 1, 1, 1)] Vector1 Opacity,
- [Slot(2, Binding.None)] out DynamicDimensionVector Out)
- {
- return
- @"
- {
- Out = lerp(Base, Blend, Opacity);
- }";
- }
- }
- }
|