Created
March 6, 2019 23:29
-
-
Save andybak/117c6f1a891bf4503093a2e35d73a593 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace UnityEditor.VFX.Block | |
{ | |
[VFXInfo(category = "Color")] | |
class ColorBlend : VFXBlock | |
{ | |
public enum BlendMode | |
{ | |
Darken, | |
Multiply, | |
ColorBurn, | |
LinearBurn, | |
Lighten, | |
Screen, | |
ColorDodge, | |
LinearDodge, | |
Overlay, | |
SoftLight, | |
HardLight, | |
VividLight, | |
LinearLight, | |
PinLight, | |
Difference, | |
Exclusion | |
} | |
[SerializeField, VFXSetting, Tooltip("The blend mode to use")] | |
private BlendMode blendMode = BlendMode.Screen; | |
public override string name {get{return "Color Blend";}} | |
public override VFXContextType compatibleContexts {get{return VFXContextType.kInitAndUpdateAndOutput;}} | |
public override VFXDataType compatibleData {get{return VFXDataType.kParticle;}} | |
public class InputProperties | |
{ | |
public Color blendColor; | |
} | |
public override IEnumerable<VFXAttributeInfo> attributes | |
{ | |
get | |
{ | |
yield return new VFXAttributeInfo(VFXAttribute.Color, VFXAttributeMode.ReadWrite); | |
} | |
} | |
public override string source | |
{ | |
get | |
{ | |
switch (blendMode) | |
{ | |
case BlendMode.Darken: | |
return @"color = min(blendColor,color);"; | |
case BlendMode.Multiply: | |
return @"color = blendColor * color;"; | |
case BlendMode.ColorBurn: | |
return @"color = 1.0 - (1.0-blendColor) / color;"; | |
case BlendMode.LinearBurn: | |
return @"color = blendColor + color - 1.0;"; | |
case BlendMode.Lighten: | |
return @"color = max(blendColor,color);"; | |
case BlendMode.Screen: | |
return @"color = 1.0 - (1.0-blendColor) * (1.0-color);"; | |
case BlendMode.ColorDodge: | |
return @"color = blendColor / (1.0-color);"; | |
case BlendMode.LinearDodge: | |
return @"color = blendColor + color;"; | |
case BlendMode.Overlay: | |
return @"color = (blendColor > 0.5) * (1.0 - (1.0-2.0*(blendColor-0.5)) * (1.0-color)) + (blendColor <= 0.5) * ((2.0*blendColor) * color);"; | |
case BlendMode.SoftLight: | |
return @"color = (color > 0.5) * (1.0 - (1.0-blendColor) * (1.0-(color-0.5))) + (color <= 0.5) * (blendColor * (color+0.5));"; | |
case BlendMode.HardLight: | |
return @"color = (color > 0.5) * (1.0 - (1.0-blendColor) * (1.0-2.0*(color-0.5))) + (color <= 0.5) * (blendColor * (2.0*color));"; | |
case BlendMode.VividLight: | |
return @"color = (color > 0.5) * (1.0 - (1.0-blendColor) / (2.0*(color-0.5))) + (color <= 0.5) * (blendColor / (1.0-2.0*color));"; | |
case BlendMode.LinearLight: | |
return @"color = (color > 0.5) * (blendColor + 2.0*(color-0.5)) + (color <= 0.5) * (blendColor + 2.0*color - 1.0);"; | |
case BlendMode.PinLight: | |
return @"color = (color > 0.5) * (max(blendColor,2.0*(color-0.5))) + (color <= 0.5) * (min(blendColor,2.0*color));"; | |
case BlendMode.Difference: | |
return @"color = abs(blendColor - color);"; | |
case BlendMode.Exclusion: | |
return @"color = 0.5 - 2.0*(blendColor-0.5)*(color-0.5);"; | |
default: | |
return ""; | |
} | |
} | |
} | |
} | |
} | |
Awesome, thanks a bunch. I appreciate it.
No worries. Let me know how you get on. I'd love to know more about hacking the internals of VFX graph myself.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Off the top of my head I think you need to use an asmdef to fool Unity into thinking the code is part of the VFX Graph assembly.
I got that trick from peeweek. See if you can work it out based on this repo: https://github.com/peeweek/net.peeweek.vfxgraph-extras