private void Update(EvaluationContext context) { var hue = (Hue.GetValue(context) % 1) * 360f; // + Saturation.GetValue(context); var sat = Saturation.GetValue(context); // + Saturation.GetValue(context); var brightness = Brightness.GetValue(context); // + Saturation.GetValue(context); float fSatR = 1; float fSatG = 1; float fSatB = 1; if (hue < 120.0f) { fSatR = (120.0f - hue) / 60.0f; fSatG = hue / 60.0f; fSatB = 0.0f; } else if (hue < 240.0f) { fSatR = 0.0f; fSatG = (240.0f - hue) / 60.0f; fSatB = (hue - 120.0f) / 60.0f; } else { fSatR = (hue - 240.0f) / 60.0f; fSatG = 0.0f; fSatB = (360.0f - hue) / 60.0f; } fSatR = (fSatR < 1.0f) ? fSatR : 1.0f; fSatG = (fSatG < 1.0f) ? fSatG : 1.0f; fSatB = (fSatB < 1.0f) ? fSatB : 1.0f; var fTmpR = 2.0f * sat * fSatR + (1.0f - sat); var fTmpG = 2.0f * sat * fSatG + (1.0f - sat); var fTmpB = 2.0f * sat * fSatB + (1.0f - sat); float fR, fG, fB; if (brightness < 0.5f) { fR = brightness * fTmpR; fG = brightness * fTmpG; fB = brightness * fTmpB; } else { fR = (1.0f - brightness) * fTmpR + 2.0f * brightness - 1.0f; fG = (1.0f - brightness) * fTmpG + 2.0f * brightness - 1.0f; fB = (1.0f - brightness) * fTmpB + 2.0f * brightness - 1.0f; } // // Color.Value.X = brightness; // Color.Value.Y = fG; // Color.Value.Z = fB; Color.Value = new Vector4(fR, fG, fB, Alpha.GetValue(context)); //Color.Value = new Vector4(hue, sat, brightness, Alpha.GetValue(context)); }
protected override MutableObject Mutate(MutableObject mutable) { foreach (var entry in Scope.GetEntries(mutable)) { var hue = Hue.GetValue(entry); var saturation = Saturation.GetValue(entry); var value = Value.GetValue(entry); ColorTarget.SetValue(ColorUtility.HsvtoRgb(hue, saturation, value), entry); } return(mutable); }
public override IEnumerator ReceivePayload(VisualPayload payload) { foreach (var entry in BitStream.GetEntries(payload.Data)) { var bitstream = BitStream.GetValue(entry); var saturation = Saturation.GetValue(entry); var value = Value.GetValue(entry); var bitsToSample = BitsToSample.GetValue(entry); var hue = bitstream.ReadInt(bitsToSample) / Mathf.Pow(2f, bitsToSample); var newColor = ColorUtility.HsvtoRgb(hue, saturation, value); ColorTarget.SetValue(newColor, entry); } var iterator = Router.TransmitAll(payload); while (iterator.MoveNext()) { yield return(null); } }