private static bool ImplicitConversionExists(ConcreteSlotValueType from, ConcreteSlotValueType to) { if (from == to) { return(true); } var fromCount = SlotValueHelper.GetChannelCount(from); var toCount = SlotValueHelper.GetChannelCount(to); // can convert from v1 vectors :) if (from == ConcreteSlotValueType.Vector1 && toCount > 0) { return(true); } if (toCount == 0) { return(false); } if (toCount <= fromCount) { return(true); } return(false); }
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) { var inputValue = GetSlotValue(InputSlotId, generationMode); var inputSlot = FindInputSlot <MaterialSlot>(InputSlotId); var numInputChannels = 0; if (inputSlot != null) { numInputChannels = SlotValueHelper.GetChannelCount(inputSlot.concreteValueType); if (numInputChannels > 4) { numInputChannels = 0; } if (!owner.GetEdges(inputSlot.slotReference).Any()) { numInputChannels = 0; } } for (var i = 0; i < 4; i++) { var outputFormat = numInputChannels == 1 ? inputValue : string.Format("{0}[{1}]", inputValue, i); var outputValue = i >= numInputChannels ? "0" : outputFormat; visitor.AddShaderChunk(string.Format("{0} {1} = {2};", precision, GetVariableNameForSlot(s_OutputSlots[i]), outputValue), true); } }
void ValidateChannelCount() { int channelCount = SlotValueHelper.GetChannelCount(FindSlot <MaterialSlot>(InputSlotId).concreteValueType); if (channelMask >= 1 << channelCount) { channelMask = -1; } }
protected override string ConcreteSlotValueAsVariable() { var channelCount = SlotValueHelper.GetChannelCount(concreteValueType); string values = NodeUtils.FloatToShaderValue(value.m00); if (channelCount == 1) return values; for (var i = 1; i < channelCount; i++) values += ", " + NodeUtils.FloatToShaderValue(value.GetRow(0)[i]); return string.Format("$precision{0}({1})", channelCount, values); }
public override void ValidateNode() { base.ValidateNode(); var inputValueType = FindInputSlot <MaterialSlot>(InputSlotId).concreteValueType; var InputValueSize = SlotValueHelper.GetChannelCount(inputValueType); if (!ValidateMaskInput(InputValueSize)) { owner.AddValidationError(objectId, "Invalid mask for a Vector" + InputValueSize + " input.", ShaderCompilerMessageSeverity.Error); } }
public void GenerateNodeFunction(FunctionRegistry registry, GraphContext graphContext, GenerationMode generationMode) { ValidateChannelCount(); registry.ProvideFunction(GetFunctionName(), s => { int channelCount = SlotValueHelper.GetChannelCount(FindSlot <MaterialSlot>(InputSlotId).concreteValueType); s.AppendLine(GetFunctionPrototype("In", "Out")); using (s.BlockScope()) { if (channelMask == 0) { s.AppendLine("Out = 0;"); } else if (channelMask == -1) { s.AppendLine("Out = In;"); } else { bool red = (channelMask & 1) != 0; bool green = (channelMask & 2) != 0; bool blue = (channelMask & 4) != 0; bool alpha = (channelMask & 8) != 0; switch (channelCount) { case 1: s.AppendLine("Out = In.r;"); break; case 2: s.AppendLine(string.Format("Out = {0}2({1}, {2});", precision, red ? "In.r" : "0", green ? "In.g" : "0")); break; case 3: s.AppendLine(string.Format("Out = {0}3({1}, {2}, {3});", precision, red ? "In.r" : "0", green ? "In.g" : "0", blue ? "In.b" : "0")); break; case 4: s.AppendLine(string.Format("Out = {0}4({1}, {2}, {3}, {4});", precision, red ? "In.r" : "0", green ? "In.g" : "0", blue ? "In.b" : "0", alpha ? "In.a" : "0")); break; default: throw new ArgumentOutOfRangeException(); } } } }); }
protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision) { var channelCount = SlotValueHelper.GetChannelCount(concreteValueType); string values = NodeUtils.FloatToShaderValue(value.x); if (channelCount == 1) { return(values); } for (var i = 1; i < channelCount; i++) { values += ", " + value[i]; } return(string.Format("{0}{1}({2})", precision, channelCount, values)); }
public static bool ImplicitConversionExists(ConcreteSlotValueType from, ConcreteSlotValueType to) { if (from == to) { return(true); } var fromCount = SlotValueHelper.GetChannelCount(from); var toCount = SlotValueHelper.GetChannelCount(to); if (toCount > 0 && fromCount > 0) { return(true); } return(false); }
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode) { var outputSlotType = FindOutputSlot <MaterialSlot>(OutputSlotId).concreteValueType.ToShaderString(); var outputName = GetVariableNameForSlot(OutputSlotId); var inputValue = GetSlotValue(InputSlotId, generationMode); var inputValueType = FindInputSlot <MaterialSlot>(InputSlotId).concreteValueType; var InputValueSize = SlotValueHelper.GetChannelCount(inputValueType); if (!ValidateMaskInput(InputValueSize)) { sb.AppendLine(string.Format("{0} {1} = 0;", outputSlotType, outputName)); } else { sb.AppendLine("{0} {1} = {2}.{3};", outputSlotType, outputName, inputValue, convertedMask); } }
void ValidateChannelCount() { var channelCount = SlotValueHelper.GetChannelCount(FindInputSlot <MaterialSlot>(InputSlotId).concreteValueType); if ((int)redChannel >= channelCount) { redChannel = TextureChannel.Red; } if ((int)greenChannel >= channelCount) { greenChannel = TextureChannel.Red; } if ((int)blueChannel >= channelCount) { blueChannel = TextureChannel.Red; } if ((int)alphaChannel >= channelCount) { alphaChannel = TextureChannel.Red; } }
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode) { var inputValue = GetSlotValue(InputSlotId, generationMode); var inputSlot = FindInputSlot <MaterialSlot>(InputSlotId); var numInputChannels = 0; if (inputSlot != null) { numInputChannels = SlotValueHelper.GetChannelCount(inputSlot.concreteValueType); if (numInputChannels > 4) { numInputChannels = 0; } } for (var i = 0; i < 4; i++) { var outputFormat = numInputChannels == 1 ? inputValue : string.Format("{0}[{1}]", inputValue, i); var outputValue = i >= numInputChannels ? "0" : outputFormat; sb.AppendLine(string.Format("$precision {0} = {1};", GetVariableNameForSlot(s_OutputSlots[i]), outputValue)); } }