Esempio n. 1
0
        public override string GetDefaultValue(GenerationMode generationMode)
        {
            var matOwner = owner as AbstractMaterialNode;

            if (matOwner == null)
            {
                throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
            }

            if (generationMode.IsPreview())
            {
                return(GradientUtil.GetGradientForPreview(matOwner.GetVariableNameForSlot(id)));
            }

            return(ConcreteSlotValueAsVariable());
        }
Esempio n. 2
0
        public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode mode)
        {
            // preview is always generating a full shader, even when previewing within a subgraph
            bool isGeneratingSubgraph = owner.isSubGraph && (mode != GenerationMode.Preview);

            switch (property.propertyType)
            {
            case PropertyType.Boolean:
                sb.AppendLine($"$precision {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.Float:
                sb.AppendLine($"$precision {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.Vector2:
                sb.AppendLine($"$precision2 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.Vector3:
                sb.AppendLine($"$precision3 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.Vector4:
                sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.Color:
                switch (property.sgVersion)
                {
                case 0:
                case 2:
                    sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                    break;

                case 1:
                case 3:
                    //Exposed color properties get put into the correct space automagikally by Unity UNLESS tagged as HDR, then they just get passed in as is.
                    //for consistency with other places in the editor, we assume HDR colors are in linear space, and correct for gamma space here
                    if ((property as ColorShaderProperty).colorMode == ColorMode.HDR)
                    {
                        sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = IsGammaSpace() ? LinearToSRGB({property.GetHLSLVariableName(isGeneratingSubgraph, mode)}) : {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                    }
                    else
                    {
                        sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                    }
                    break;

                default:
                    throw new Exception($"Unknown Color Property Version on property {property.displayName}");
                }
                break;

            case PropertyType.Matrix2:
                sb.AppendLine($"$precision2x2 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.Matrix3:
                sb.AppendLine($"$precision3x3 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.Matrix4:
                sb.AppendLine($"$precision4x4 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.Texture2D:
                sb.AppendLine($"UnityTexture2D {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.Texture3D:
                sb.AppendLine($"UnityTexture3D {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.Texture2DArray:
                sb.AppendLine($"UnityTexture2DArray {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.Cubemap:
                sb.AppendLine($"UnityTextureCube {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.SamplerState:
                sb.AppendLine($"UnitySamplerState {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                break;

            case PropertyType.Gradient:
                if (mode == GenerationMode.Preview)
                {
                    sb.AppendLine($"Gradient {GetVariableNameForSlot(OutputSlotId)} = {GradientUtil.GetGradientForPreview(property.GetHLSLVariableName(isGeneratingSubgraph, mode))};");
                }
                else
                {
                    sb.AppendLine($"Gradient {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
                }
                break;
            }

            if (property.isConnectionTestable)
            {
                // If in a subgraph, the value will be read from a function parameter.
                // If generating preview mode code, we always inline the value, according to code gen requirements.
                // The parent graph always sets the explicit value to be passed to a subgraph function.
                sb.AppendLine("bool {0} = {1};", GetConnectionStateVariableNameForSlot(OutputSlotId), (mode == GenerationMode.Preview || !isGeneratingSubgraph) ? (IsSlotConnected(OutputSlotId) ? "true" : "false") : property.GetConnectionStateHLSLVariableName());
            }
        }
Esempio n. 3
0
        public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
        {
            switch (property.propertyType)
            {
            case PropertyType.Boolean:
                sb.AppendLine($"$precision {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Float:
                sb.AppendLine($"$precision {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Vector2:
                sb.AppendLine($"$precision2 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Vector3:
                sb.AppendLine($"$precision3 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Vector4:
                sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Color:
                switch (property.sgVersion)
                {
                case 0:
                    sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                    break;

                case 1:
                    //Exposed color properties get put into the correct space automagikally by Unity UNLESS tagged as HDR, then they just get passed in as is.
                    //for consistency with other places in the editor, we assume HDR colors are in linear space, and correct for gamma space here
                    if ((property as ColorShaderProperty).colorMode == ColorMode.HDR)
                    {
                        sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = IsGammaSpace() ? LinearToSRGB({property.referenceName}) : {property.referenceName};");
                    }
                    else
                    {
                        sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                    }
                    break;

                default:
                    throw new Exception($"Unknown Color Property Version on property {property.displayName}");
                }
                break;

            case PropertyType.Matrix2:
                sb.AppendLine($"$precision2x2 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Matrix3:
                sb.AppendLine($"$precision3x3 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Matrix4:
                sb.AppendLine($"$precision4x4 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.SamplerState:
                sb.AppendLine($"SamplerState {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Gradient:
                if (generationMode == GenerationMode.Preview)
                {
                    sb.AppendLine($"Gradient {GetVariableNameForSlot(OutputSlotId)} = {GradientUtil.GetGradientForPreview(property.referenceName)};");
                }
                else
                {
                    sb.AppendLine($"Gradient {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                }
                break;
            }
        }
Esempio n. 4
0
        public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
        {
            // preview is always generating a full shader, even when previewing within a subgraph
            bool isGeneratingSubgraph = owner.isSubGraph && (generationMode != GenerationMode.Preview);

            switch (property.propertyType)
            {
            case PropertyType.Boolean:
                sb.AppendLine($"$precision {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.Float:
                sb.AppendLine($"$precision {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.Vector2:
                sb.AppendLine($"$precision2 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.Vector3:
                sb.AppendLine($"$precision3 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.Vector4:
                sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.Color:
                switch (property.sgVersion)
                {
                case 0:
                case 2:
                    sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                    break;

                case 1:
                case 3:
                    //Exposed color properties get put into the correct space automagikally by Unity UNLESS tagged as HDR, then they just get passed in as is.
                    //for consistency with other places in the editor, we assume HDR colors are in linear space, and correct for gamma space here
                    if ((property as ColorShaderProperty).colorMode == ColorMode.HDR)
                    {
                        sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = IsGammaSpace() ? LinearToSRGB({property.GetHLSLVariableName(isGeneratingSubgraph)}) : {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                    }
                    else
                    {
                        sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                    }
                    break;

                default:
                    throw new Exception($"Unknown Color Property Version on property {property.displayName}");
                }
                break;

            case PropertyType.Matrix2:
                sb.AppendLine($"$precision2x2 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.Matrix3:
                sb.AppendLine($"$precision3x3 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.Matrix4:
                sb.AppendLine($"$precision4x4 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.Texture2D:
                sb.AppendLine($"UnityTexture2D {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.Texture3D:
                sb.AppendLine($"UnityTexture3D {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.Texture2DArray:
                sb.AppendLine($"UnityTexture2DArray {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.Cubemap:
                sb.AppendLine($"UnityTextureCube {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.SamplerState:
                sb.AppendLine($"UnitySamplerState {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                break;

            case PropertyType.Gradient:
                if (generationMode == GenerationMode.Preview)
                {
                    sb.AppendLine($"Gradient {GetVariableNameForSlot(OutputSlotId)} = {GradientUtil.GetGradientForPreview(property.GetHLSLVariableName(isGeneratingSubgraph))};");
                }
                else
                {
                    sb.AppendLine($"Gradient {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph)};");
                }
                break;
            }
        }
Esempio n. 5
0
 public void GenerateNodeCode(ShaderStringBuilder sb, GraphContext graphContext, GenerationMode generationMode)
 {
     if (generationMode.IsPreview())
     {
         sb.AppendLine("Gradient {0} = {1};", GetVariableNameForSlot(outputSlotId), GradientUtil.GetGradientForPreview(GetVariableNameForNode()));
     }
     else
     {
         sb.AppendLine("Gradient {0} = {1}", GetVariableNameForSlot(outputSlotId), GradientUtil.GetGradientValue(gradient, ";"));
     }
 }
Esempio n. 6
0
        public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
        {
            var property = owner.properties.FirstOrDefault(x => x.guid == propertyGuid);

            if (property == null)
            {
                return;
            }

            switch (property.propertyType)
            {
            case PropertyType.Boolean:
                sb.AppendLine($"$precision {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Vector1:
                sb.AppendLine($"$precision {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Vector2:
                sb.AppendLine($"$precision2 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Vector3:
                sb.AppendLine($"$precision3 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Vector4:
                sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Color:
                sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Matrix2:
                sb.AppendLine($"$precision2x2 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Matrix3:
                sb.AppendLine($"$precision3x3 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Matrix4:
                sb.AppendLine($"$precision4x4 {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.SamplerState:
                sb.AppendLine($"SamplerState {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                break;

            case PropertyType.Gradient:
                if (generationMode == GenerationMode.Preview)
                {
                    sb.AppendLine($"Gradient {GetVariableNameForSlot(OutputSlotId)} = {GradientUtil.GetGradientForPreview(property.referenceName)};");
                }
                else
                {
                    sb.AppendLine($"Gradient {GetVariableNameForSlot(OutputSlotId)} = {property.referenceName};");
                }
                break;
            }
        }