/// <summary> /// Perform the operation between two floats on CPU /// </summary> /// <param name="leftValue">The value of the left child.</param> /// <param name="rightValue">The value of the right child.</param> /// <param name="operand">The operation between the two values.</param> /// <returns>The new float</returns> public static float MixFloat(float leftValue, float rightValue, MaterialBinaryOperand operand) { switch (operand) { case MaterialBinaryOperand.Add: return(leftValue + rightValue); case MaterialBinaryOperand.Average: return(0.5f * (leftValue + rightValue)); case MaterialBinaryOperand.Divide: return(leftValue / rightValue); case MaterialBinaryOperand.Multiply: return(leftValue * rightValue); case MaterialBinaryOperand.None: case MaterialBinaryOperand.Opaque: return(leftValue); case MaterialBinaryOperand.Subtract: return(leftValue - rightValue); default: throw new ArgumentOutOfRangeException("Operand not supported between two floats"); } }
/// <summary> /// Perform the operation between two float4 on CPU /// </summary> /// <param name="leftValue">The value of the left child.</param> /// <param name="rightValue">The value of the right child.</param> /// <param name="operand">The operation between the two values.</param> /// <returns>The new float4</returns> public static Vector4 MixFloat4(Vector4 leftValue, Vector4 rightValue, MaterialBinaryOperand operand) { switch (operand) { case MaterialBinaryOperand.Add: return(Add(leftValue, rightValue)); case MaterialBinaryOperand.Average: return(Average(leftValue, rightValue)); case MaterialBinaryOperand.Color: return(Color(leftValue, rightValue)); case MaterialBinaryOperand.ColorBurn: return(ColorBurn(leftValue, rightValue)); case MaterialBinaryOperand.ColorDodge: return(ColorDodge(leftValue, rightValue)); case MaterialBinaryOperand.Darken: return(Darken(leftValue, rightValue)); case MaterialBinaryOperand.Desaturate: return(Desaturate(leftValue, rightValue)); case MaterialBinaryOperand.Difference: return(Difference(leftValue, rightValue)); case MaterialBinaryOperand.Divide: return(Divide(leftValue, rightValue)); case MaterialBinaryOperand.Exclusion: return(Exclusion(leftValue, rightValue)); case MaterialBinaryOperand.HardLight: return(HardLight(leftValue, rightValue)); case MaterialBinaryOperand.HardMix: return(HardMix(leftValue, rightValue)); case MaterialBinaryOperand.Hue: return(Hue(leftValue, rightValue)); case MaterialBinaryOperand.Illuminate: return(Illuminate(leftValue, rightValue)); case MaterialBinaryOperand.In: return(In(leftValue, rightValue)); case MaterialBinaryOperand.Lighten: return(Lighten(leftValue, rightValue)); case MaterialBinaryOperand.LinearBurn: return(LinearBurn(leftValue, rightValue)); case MaterialBinaryOperand.LinearDodge: return(LinearDodge(leftValue, rightValue)); case MaterialBinaryOperand.Mask: return(Mask(leftValue, rightValue)); case MaterialBinaryOperand.Multiply: return(Multiply(leftValue, rightValue)); case MaterialBinaryOperand.None: return(None(leftValue, rightValue)); case MaterialBinaryOperand.Opaque: return(Opaque(leftValue, rightValue)); case MaterialBinaryOperand.Out: return(Out(leftValue, rightValue)); case MaterialBinaryOperand.Over: return(Over(leftValue, rightValue)); case MaterialBinaryOperand.Overlay: return(Overlay(leftValue, rightValue)); case MaterialBinaryOperand.PinLight: return(PinLight(leftValue, rightValue)); case MaterialBinaryOperand.Saturate: return(Saturate(leftValue, rightValue)); case MaterialBinaryOperand.Saturation: return(Saturation(leftValue, rightValue)); case MaterialBinaryOperand.Screen: return(Screen(leftValue, rightValue)); case MaterialBinaryOperand.SoftLight: return(SoftLight(leftValue, rightValue)); case MaterialBinaryOperand.Subtract: return(Subtract(leftValue, rightValue)); case MaterialBinaryOperand.SubstituteAlpha: return(SubstituteAlpha(leftValue, rightValue)); default: throw new ArgumentOutOfRangeException("operand"); } }
/// <summary> /// Initializes a new instance of the <see cref="MaterialBinaryNode"/> class. /// </summary> /// <param name="leftChild">The left child.</param> /// <param name="rightChild">The right child.</param> /// <param name="materialBinaryOperand">The material binary operand.</param> public MaterialBinaryNode(IMaterialNode leftChild, IMaterialNode rightChild, MaterialBinaryOperand materialBinaryOperand) { LeftChild = leftChild; RightChild = rightChild; Operand = materialBinaryOperand; }
/// <summary> /// Perform the operation between two colors on CPU /// </summary> /// <param name="leftValue">The value of the left child.</param> /// <param name="rightValue">The value of the right child.</param> /// <param name="operand">The operation between the two values.</param> /// <returns>The new Color</returns> public static Color4 MixColor(Color4 leftValue, Color4 rightValue, MaterialBinaryOperand operand) { Vector4 res = MixFloat4(leftValue.ToVector4(), rightValue.ToVector4(), operand); return(new Color4(res)); }
/// <summary> /// Get the name of the ShaderClassSource corresponding to the operation /// </summary> /// <param name="materialBinaryOperand">The operand.</param> /// <returns>The name of the ShaderClassSource.</returns> private static string GetCorrespondingShaderSourceName(MaterialBinaryOperand materialBinaryOperand) { switch (materialBinaryOperand) { case MaterialBinaryOperand.Add: return("ComputeColorAdd3ds"); //TODO: change this (ComputeColorAdd?) case MaterialBinaryOperand.Average: return("ComputeColorAverage"); case MaterialBinaryOperand.Color: return("ComputeColorColor"); case MaterialBinaryOperand.ColorBurn: return("ComputeColorColorBurn"); case MaterialBinaryOperand.ColorDodge: return("ComputeColorColorDodge"); case MaterialBinaryOperand.Darken: return("ComputeColorDarken3ds"); //"ComputeColorDarkenMaya" //TODO: change this case MaterialBinaryOperand.Desaturate: return("ComputeColorDesaturate"); case MaterialBinaryOperand.Difference: return("ComputeColorDifference3ds"); //"ComputeColorDifferenceMaya" //TODO: change this case MaterialBinaryOperand.Divide: return("ComputeColorDivide"); case MaterialBinaryOperand.Exclusion: return("ComputeColorExclusion"); case MaterialBinaryOperand.HardLight: return("ComputeColorHardLight"); case MaterialBinaryOperand.HardMix: return("ComputeColorHardMix"); case MaterialBinaryOperand.Hue: return("ComputeColorHue"); case MaterialBinaryOperand.Illuminate: return("ComputeColorIlluminate"); case MaterialBinaryOperand.In: return("ComputeColorIn"); case MaterialBinaryOperand.Lighten: return("ComputeColorLighten3ds"); //"ComputeColorLightenMaya" //TODO: change this case MaterialBinaryOperand.LinearBurn: return("ComputeColorLinearBurn"); case MaterialBinaryOperand.LinearDodge: return("ComputeColorLinearDodge"); case MaterialBinaryOperand.Mask: return("ComputeColorMask"); case MaterialBinaryOperand.Multiply: return("ComputeColorMultiply"); //return "ComputeColorMultiply3ds"; //"ComputeColorMultiplyMaya" //TODO: change this case MaterialBinaryOperand.None: return("ComputeColorNone"); case MaterialBinaryOperand.Opaque: return("ComputeColorOpaque"); case MaterialBinaryOperand.Out: return("ComputeColorOut"); case MaterialBinaryOperand.Over: return("ComputeColorOver3ds"); //TODO: change this to "ComputeColorLerpAlpha" case MaterialBinaryOperand.Overlay: return("ComputeColorOverlay3ds"); //"ComputeColorOverlayMaya" //TODO: change this case MaterialBinaryOperand.PinLight: return("ComputeColorPinLight"); case MaterialBinaryOperand.Saturate: return("ComputeColorSaturate"); case MaterialBinaryOperand.Saturation: return("ComputeColorSaturation"); case MaterialBinaryOperand.Screen: return("ComputeColorScreen"); case MaterialBinaryOperand.SoftLight: return("ComputeColorSoftLight"); case MaterialBinaryOperand.Subtract: return("ComputeColorSubtract3ds"); //"ComputeColorOverlayMaya" //TODO: change this case MaterialBinaryOperand.SubstituteAlpha: return("ComputeColorSubstituteAlpha"); default: throw new ArgumentOutOfRangeException("materialBinaryOperand"); } }