Esempio n. 1
0
        private Node ParseMultiplicative()
        {
            var lNode = this.ParseUnary();

            while (this.AreMoreTokens)
            {
                if (this.currentToken.Equals(TokenType.Symbol, "*"))
                {
                    this.ReadNextToken();
                    lNode = new MultiplyNode(lNode, this.ParseUnary());
                }
                else if (this.currentToken.Equals(TokenType.Symbol, "/"))
                {
                    this.ReadNextToken();
                    lNode = new DivideNode(lNode, this.ParseUnary());
                }
                else if (this.currentToken.Equals(TokenType.Symbol, "%"))
                {
                    this.ReadNextToken();
                    lNode = new ModulusNode(lNode, this.ParseUnary());
                }
                else
                {
                    break;
                }
            }

            return(lNode);
        }
Esempio n. 2
0
        public override NodeViewModel CreateModel()
        {
            CombinerNode result = null;

            switch (combineType)
            {
            case CombinerType.Add:
                result = new AddNode();
                break;

            case CombinerType.Max:
                result = new MaxNode();
                break;

            case CombinerType.Min:
                result = new MinNode();
                break;

            case CombinerType.Multiply:
                result = new MultiplyNode();
                break;

            case CombinerType.Power:
                result = new PowerNode();
                break;
            }

            result.Name     = name;
            result.Position = pos;

            return(result);
        }
Esempio n. 3
0
 public object Visit(MultiplyNode node)
 {
     return(this.Calculate(node.Value1, node.Value2,
                           (v1, v2) => v1 * v2,
                           (v1, v2) => v1 * v2,
                           (v1, v2, ex) =>
                           throw new InvalidOperationException($"[{v1 ?? "(null)"} * {v2 ?? "(null)"}] failed!", ex)));
 }
        public void MultiplyNode()
        {
            int
                val1   = 10,
                val2   = 20,
                result = val1 * val2;
            var node   = new MultiplyNode(new ConstantNode(val1), new ConstantNode(val2));

            Assert.AreEqual(node.Value, result);
        }
Esempio n. 5
0
        public SpritePS()
        {
            Name             = "SpritePS";
            Type             = ShaderType.Pixel;
            KeyPart          = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.DiffuseMap);
            FeatureLevel     = FeatureLevel.PS_4_0_Level_9_1;
            EnableSeparators = true;
            var inputStruct = SpriteVS.VSOut;

            inputStruct.Name = "input";

            InputStruct  = inputStruct;
            OutputStruct = Struct.PixelShaderOutput;
            Struct   cbMaterial = ConstantBuffer.CBMaterial;
            Struct   material   = (Struct)cbMaterial[Param.Struct.Material];
            Variable tDiffuse   = Texture.Diffuse;
            Variable sDiffuse   = Sampler.MinMagMipLinearWrap;

            Add(cbMaterial);
            Add(sDiffuse);
            Add(tDiffuse);

            TextureSampleNode nTexSample = new TextureSampleNode
            {
                Coordinates = new ReferenceNode {
                    Value = InputStruct[Param.SemanticVariables.Texture]
                },
                Texture   = tDiffuse,
                Sampler   = sDiffuse,
                IsVerbose = true,
                Output    = new Vector()
                {
                    Name = "cDiffuse", Type = Shaders.Type.Float4
                }
            };

            MultiplyNode nMultiply = new MultiplyNode
            {
                Input1 = nTexSample,
                Input2 = new ReferenceNode {
                    Value = material[Param.Material.Diffuse]
                },
                Output = new Vector {
                    Name = "cFinal", Type = Shaders.Type.Float4
                }
            };

            Result = new PSOutputNode
            {
                FinalColor = nMultiply,
                Output     = OutputStruct
            };
        }
Esempio n. 6
0
        public DomainId <IAstNode> CreateMultiplicationOperation(
            string definition,
            DomainId <ICalculationNode> leftExpression,
            DomainId <ICalculationNode> rightExpression)
        {
            var multiplicationNode = new MultiplyNode(
                m_ids.Next,
                definition,
                leftExpression,
                rightExpression);

            return(DomainItemRegistration <IMultiplyNode>(multiplicationNode));
        }
Esempio n. 7
0
        void Term(out QueryNode node)
        {
            QueryNode term;

            Factor(out term);
            node = term;
            while (la.kind == 11 || la.kind == 12)
            {
                MulOp();
                node = new MultiplyNode();
                node.Add(term);
                Factor(out term);
                node.Add(term);
            }
        }
Esempio n. 8
0
        private object Visit(MultiplyNode node)
        {
            dynamic left  = Visit(node.Left);
            dynamic right = Visit(node.Right);

            try
            {
                return(left * right);
            }
            catch (Exception error)
            {
                ReportError(error);
                return(null);
            }
        }
Esempio n. 9
0
        public SkyboxPS()
        {
            Name             = "SkyboxPS";
            Type             = ShaderType.Pixel;
            KeyPart          = new TechniqueKey(ps: PixelShaderFlags.Diffuse);
            FeatureLevel     = FeatureLevel.PS_4_0_Level_9_1;
            EnableSeparators = true;
            var inputStruct = SkyboxVS.VSOutput;

            inputStruct.Name = "input";

            InputStruct  = inputStruct;
            OutputStruct = Struct.PixelShaderOutput;

            Struct cbMaterial = Structs.ConstantBuffer.CBMaterial;
            Struct material   = (Struct)cbMaterial[Param.Struct.Material];

            Add(cbMaterial);

            Texture tDiffuse        = Texture.CubeMap;
            Sampler sDiffuseSampler = Sampler.MinMagMipLinearWrap;

            Add(tDiffuse);
            Add(sDiffuseSampler);
            TextureSampleNode textureSample = new TextureSampleNode
            {
                Coordinates = new ReferenceNode {
                    Value = InputStruct[Param.SemanticVariables.Texture]
                },
                Texture = tDiffuse,
                Sampler = sDiffuseSampler
            };
            MultiplyNode multiply = new MultiplyNode
            {
                Input1 = textureSample,
                Input2 = new ReferenceNode {
                    Value = material[Param.Material.Diffuse]
                }
            };

            Result = new PSOutputNode
            {
                FinalColor = multiply,
                Output     = OutputStruct
            };
        }
        protected override AbstractMaterialNode CreateNode(ShaderGraphBuilder builder, MaterialExpressionMultiply unrealNode)
        {
            var node = new MultiplyNode()
            {
                previewExpanded = !unrealNode.Collapsed
            };

            if (unrealNode.A == null)
            {
                node.FindInputSlot <DynamicValueMaterialSlot>(0).value = new Matrix4x4(new Vector4(unrealNode.ConstA, 0), Vector4.zero, Vector4.zero, Vector4.zero);
            }

            if (unrealNode.B == null)
            {
                node.FindInputSlot <DynamicValueMaterialSlot>(1).value = new Matrix4x4(new Vector4(unrealNode.ConstB, 0), Vector4.zero, Vector4.zero, Vector4.zero);
            }

            return(node);
        }
Esempio n. 11
0
        private bool TryTerm(ParserContext context, out IAstNode instr)
        {
            IAstNode value2;

            if (context.Stream.Consume <IAstNode>(TryFactor, context, out var currInstr))
            {
                instr = currInstr;

                while (!context.Stream.Eof)
                {
                    if (context.Stream.Consume(TokenTypes.Times))
                    {
                        if (!context.Stream.Consume <IAstNode>(TryFactor, context, out value2))
                        {
                            throw new ParserException("Syntax error: expected factor", context.Stream);
                        }

                        currInstr = new MultiplyNode(currInstr, value2);
                        instr     = currInstr;
                    }
                    else if (context.Stream.Consume(TokenTypes.Divide))
                    {
                        if (!context.Stream.Consume <IAstNode>(TryFactor, context, out value2))
                        {
                            throw new ParserException("Syntax error: expected factor", context.Stream);
                        }

                        currInstr = new DivideNode(currInstr, value2);
                        instr     = currInstr;
                    }
                    else
                    {
                        return(true);
                    }
                }

                return(true);
            }

            instr = null;
            return(false);
        }
Esempio n. 12
0
        private static void TestExpTree()
        {
            AddNode <Real> root = new AddNode <Real>();

            MultiplyNode <Real> c1 = new MultiplyNode <Real>();
            SubtractNode <Real> c2 = new SubtractNode <Real>();
            DivideNode <Real>   c3 = new DivideNode <Real>();

            root.LeftChild  = c1;
            root.RightChild = c2;

            c1.LeftChild  = new ConstantNode <Real>(2);
            c1.RightChild = c3;

            c2.LeftChild  = new ConstantNode <Real>(7);
            c2.RightChild = new ConstantNode <Real>(4);

            c3.LeftChild  = new ConstantNode <Real>(8);
            c3.RightChild = new ConstantNode <Real>(16);

            Console.WriteLine(root.ToString() + " = " + root.Evaluate());
        }
Esempio n. 13
0
        private AstNode Term()
        {
            // TERM = FACTOR (MULTIPLY | DIVIDE FACTOR)*

            var node = Factor();

            var ops = new[] { Tokens.Multiply, Tokens.Divide };

            while (ops.Contains(_currentToken.Type))
            {
                var token = _currentToken;
                Eat(token.Type);
                if (token.Type == Tokens.Multiply)
                {
                    node = new MultiplyNode(node, Factor());
                }
                else if (token.Type == Tokens.Divide)
                {
                    node = new DivideNode(node, Factor());
                }
            }

            return(node);
        }
Esempio n. 14
0
        private Node ParseMultiplicative()
        {
            var lNode = this.ParseUnary();

            while (this.AreMoreTokens)
            {
                if (this.currentToken.Equals(TokenType.Symbol, "*"))
                {
                    this.ReadNextToken();
                    lNode = new MultiplyNode(lNode, this.ParseUnary());
                }
                else if (this.currentToken.Equals(TokenType.Symbol, "/"))
                {
                    this.ReadNextToken();
                    lNode = new DivideNode(lNode, this.ParseUnary());
                }
                else if (this.currentToken.Equals(TokenType.Symbol, "%"))
                {
                    this.ReadNextToken();
                    lNode = new ModulusNode(lNode, this.ParseUnary());
                }
                else
                {
                    break;
                }
            }

            return lNode;
        }
Esempio n. 15
0
 public abstract T Visit(MultiplyNode node);
Esempio n. 16
0
        public WireframeVS()
        {
            Name             = "WireframeVS";
            Type             = ShaderType.Vertex;
            KeyPart          = new TechniqueKey(vs: VertexShaderFlags.Position | VertexShaderFlags.Normal | VertexShaderFlags.TextureUV | VertexShaderFlags.Barycentric);
            FeatureLevel     = FeatureLevel.VS_4_0_Level_9_1;
            EnableSeparators = true;
            InputStruct      = VertexPositionNormalBarycentric;
            OutputStruct     = VertexPositionTextureIntensityBarycentricOut;

            ConstantBuffer cbFrame    = CBPerFrame;
            ConstantBuffer cbInstance = CBPerInstance;

            Add(cbFrame);
            Add(cbInstance);

            IVariable position       = InputStruct[Param.SemanticVariables.ObjectPosition];
            IVariable lightDirection = cbFrame[Param.Vectors.LightDirection];
            IVariable normal         = InputStruct[Param.SemanticVariables.Normal];
            IVariable texture        = InputStruct[Param.SemanticVariables.Texture];
            IVariable barycentric    = InputStruct[Param.SemanticVariables.Barycentric];

            CastNode nV3toV4 = new CastNode
            {
                Input = new SwizzleNode {
                    Input = new ReferenceNode {
                        Value = position
                    }, Swizzle = new[] { Swizzle.X, Swizzle.Y, Swizzle.Z, Swizzle.Null }
                },
                Output = new Vector {
                    Type = Shaders.Type.Float4, Name = "vPosition"
                },
                Mask      = new[] { "0", "0", "0", "1" },
                IsVerbose = true
            };

            MatrixMultiplyNode mulPosWVP = new MatrixMultiplyNode
            {
                Input1 = nV3toV4,
                Input2 = MatrixMultiplyNode.WorldViewProjection,
                Output = new Vector()
                {
                    Type = Shaders.Type.Float4, Name = "vClipPosition"
                },
                IsVerbose = true
            };

            MultiplyNode perspectiveCorrection = new MultiplyNode()
            {
                Input1 = new ReferenceNode()
                {
                    Value = barycentric
                },
                Input2 = new SwizzleNode()
                {
                    Input   = mulPosWVP,
                    Swizzle = new Swizzle[] { Swizzle.W, }
                }
            };

            BinaryFunctionNode dotLightNormal = new BinaryFunctionNode
            {
                Input1 = new ReferenceNode {
                    Value = lightDirection
                },
                Input2 = new ReferenceNode {
                    Value = normal
                },
                Function = HlslIntrinsics.Dot
            };

            BinaryFunctionNode maxIntensity = new BinaryFunctionNode
            {
                Input1 = dotLightNormal,
                Input2 = new ScalarNode()
                {
                    Value = 0.3f
                },
                Function = HlslIntrinsics.Max
            };

            CustomOutputNode outputNode = new CustomOutputNode()
            {
                Output = OutputStruct
            };

            outputNode.RegisterField(Vector.ClipPosition, mulPosWVP, Shaders.Type.Float4);
            outputNode.RegisterField(Param.SemanticVariables.Intensity, Semantics.Intensity, maxIntensity, Shaders.Type.Float3);
            outputNode.RegisterField(Vector.TextureUV, new ReferenceNode {
                Value = texture
            }, Shaders.Type.Float2);
            outputNode.RegisterField(Param.SemanticVariables.Barycentric, Semantics.Barycentric, perspectiveCorrection, Shaders.Type.Float3);

            Result = outputNode;
        }
Esempio n. 17
0
        private bool TryValue(ParserContext context, out IAstNode instr)
        {
            instr = null;

            if (context.Stream.Consume(TokenTypes.Identity, out var value))
            {
                if (context.Stream.Consume(TokenTypes.LeftParentheses))
                {
                    // We have parentheses = must be a function
                    if (!context.Stream.Consume <List <IAstNode> >(TryParameters, context, out var parameters))
                    {
                        throw new ParserException("Syntax error", context.Stream);
                    }
                    if (!context.Stream.Consume(TokenTypes.RightParentheses))
                    {
                        throw new ParserException("Syntax error, expected )", context.Stream);
                    }

                    var functionName = value.ToString();

                    // Validate that the function exists
                    var matchingFunctions = context.ValidFunctions.Where(i =>
                                                                         i.Name.Equals(functionName, StringComparison.InvariantCultureIgnoreCase)).ToList();
                    if (!matchingFunctions.Any())
                    {
                        throw new ParserException($"Unknown function: {functionName}", context.Stream);
                    }

                    // Validate that we have a function that has the same number of parameters
                    // as was entered in the script
                    if (matchingFunctions.All(i => i.Parameters.Count != parameters.Count))
                    {
                        var errMsg = new StringBuilder();
                        errMsg.AppendLine("Invalid number of parameters");
                        errMsg.AppendLine("Supported: ");
                        foreach (var func in matchingFunctions)
                        {
                            errMsg.AppendLine(
                                $"  * {func.Name}({string.Join(",", func.Parameters.Select(i => i.Name))})");
                        }
                        throw new ParserException(errMsg.ToString(), context.Stream);
                    }

                    instr = new FunctionNode(functionName, parameters);


                    return(true);
                }

                // Missing parentheses = must be a bound variable.
                instr = new VariableNode(value?.ToString());
                return(true);
            }

            if (context.Stream.Consume(TokenTypes.String, out value))
            {
                if (value == null)
                {
                    instr = new ValueNode(null);
                }
                else
                {
                    instr = new ValueNode(Regex.Unescape(value.ToString()));
                }
                return(true);
            }

            if (context.Stream.Consume(TokenTypes.Integer, out value) ||
                context.Stream.Consume(TokenTypes.Decimal, out value) ||
                context.Stream.Consume(TokenTypes.Char, out value))
            {
                instr = new ValueNode(value);
                return(true);
            }

            if (context.Stream.Consume(TokenTypes.LeftParentheses))
            {
                if (!context.Stream.Consume <IAstNode>(TryStatement, context, out instr))
                {
                    throw new ParserException("Syntax error", context.Stream);
                }

                if (!context.Stream.Consume(TokenTypes.RightParentheses))
                {
                    throw new ParserException("Syntax error, expected )", context.Stream);
                }

                return(true);
            }

            if (context.Stream.Consume(TokenTypes.Plus))
            {
                if (!context.Stream.Consume <IAstNode>(TryFactor, context, out instr))
                {
                    throw new ParserException("Syntax error", context.Stream);
                }
                return(true);
            }

            if (context.Stream.Consume(TokenTypes.Minus))
            {
                if (!context.Stream.Consume <IAstNode>(TryFactor, context, out var factor))
                {
                    throw new ParserException("Syntax error", context.Stream);
                }
                instr = new MultiplyNode(new ValueNode(-1), factor);
                return(true);
            }

            if (context.Stream.Consume(TokenTypes.Null))
            {
                instr = new ValueNode(null);
                return(true);
            }

            if (context.Stream.Consume(TokenTypes.True))
            {
                instr = new BoolValueNode(true);
                return(true);
            }

            if (context.Stream.Consume(TokenTypes.False))
            {
                instr = new BoolValueNode(false);
                return(true);
            }

            return(false);
        }
Esempio n. 18
0
        public BloomCombinePS()
        {
            Name             = "BloomCombinePS";
            Type             = ShaderType.Pixel;
            KeyPart          = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.DiffuseMap);
            FeatureLevel     = FeatureLevel.PS_4_0_Level_9_1;
            EnableSeparators = true;
            var inputStruct = SpriteVS.VSOut;

            inputStruct.Name = "input";

            InputStruct  = inputStruct;
            OutputStruct = Struct.PixelShaderOutput;
            Texture tDiffuse = Texture.Diffuse;
            Texture tBloom   = new Texture()
            {
                Name = "tBloom", Type = Shaders.Type.Texture2D
            };
            Sampler sLinearWrap = Sampler.MinMagMipLinearWrap;
            var     cbFrame     = CBFrame;

            var blurParams = (Struct)cbFrame[0];

            Add(sLinearWrap);
            Add(tDiffuse);
            Add(tBloom);
            Add(cbFrame);

            TextureSampleNode nTexSample = new TextureSampleNode
            {
                Coordinates = new ReferenceNode {
                    Value = InputStruct[Param.SemanticVariables.Texture]
                },
                Texture   = tDiffuse,
                Sampler   = sLinearWrap,
                IsVerbose = true,
                Output    = new Vector {
                    Name = "cDiffuse", Type = Shaders.Type.Float4
                },
            };

            TextureSampleNode nBloomSample = new TextureSampleNode
            {
                Coordinates = new ReferenceNode {
                    Value = InputStruct[Param.SemanticVariables.Texture]
                },
                Texture   = tBloom,
                Sampler   = sLinearWrap,
                IsVerbose = true,
                Output    = new Vector {
                    Name = "cBloom", Type = Shaders.Type.Float4
                }
            };

            var mAdjustSaturation = new AdjustSaturation();

            FunctionNode nAdjustBloomSaturation = new FunctionNode()
            {
                Inputs = new List <INode>()
                {
                    nBloomSample,
                    new ReferenceNode()
                    {
                        Value = blurParams[Param.Floats.BloomSaturation]
                    }
                },
                Method     = mAdjustSaturation,
                ReturnType = Shaders.Type.Float4
            };

            FunctionNode nAdjustBaseSaturation = new FunctionNode()
            {
                Inputs = new List <INode>()
                {
                    nTexSample,
                    new ReferenceNode()
                    {
                        Value = blurParams[Param.Floats.BloomBaseSaturation]
                    }
                },
                Method     = mAdjustSaturation,
                ReturnType = Shaders.Type.Float4
            };

            MultiplyNode nMulBloom = new MultiplyNode()
            {
                Input1 = nAdjustBloomSaturation,
                Input2 = new ReferenceNode()
                {
                    Value = blurParams[Param.Floats.BloomIntensity]
                },
                Output    = nBloomSample.Output,
                IsVerbose = true,
                Declare   = false
            };
            MultiplyNode nMulBase = new MultiplyNode()
            {
                Input1 = nAdjustBaseSaturation,
                Input2 = new ReferenceNode()
                {
                    Value = blurParams[Param.Floats.BloomBaseIntensity]
                },
                Output    = nTexSample.Output,
                IsVerbose = true,
                Declare   = false
            };

            MultiplyNode nDarken = new MultiplyNode()
            {
                Input1 = nMulBase,
                Input2 = new SubtractionNode()
                {
                    Input1 = new ScalarNode()
                    {
                        Value = 1
                    },
                    Input2 = new UnaryFunctionNode()
                    {
                        Input1 = nMulBloom, Function = HlslIntrinsics.Saturate
                    },
                    Parenthesize = true
                },
                Output         = nTexSample.Output,
                IsVerbose      = true,
                Declare        = false,
                AssignToInput1 = true
            };

            Result = new PSOutputNode
            {
                FinalColor = new AdditionNode()
                {
                    Input1 = nDarken, Input2 = nMulBloom
                },
                Output = OutputStruct
            };
        }
Esempio n. 19
0
 public double CalcMultiplyNode(MultiplyNode node)
 {
     return((double)(node.NodeA.value * node.NodeB.value));
 }
Esempio n. 20
0
    // $ANTLR start "multiplicativeExpression"
    // JavaScript.g:309:1: multiplicativeExpression : unaryExpression ( ( LT )* ( ( '*' | '/' | '%' ) ( LT )* unaryExpression ) )* ;
    public JavaScriptParser.multiplicativeExpression_return multiplicativeExpression() // throws RecognitionException [1]
    {   
        JavaScriptParser.multiplicativeExpression_return retval = new JavaScriptParser.multiplicativeExpression_return();
        retval.Start = input.LT(1);

        object root_0 = null;

        IToken LT362 = null;
        IToken char_literal363 = null;
        IToken char_literal364 = null;
        IToken char_literal365 = null;
        IToken LT366 = null;
        JavaScriptParser.unaryExpression_return unaryExpression361 = default(JavaScriptParser.unaryExpression_return);

        JavaScriptParser.unaryExpression_return unaryExpression367 = default(JavaScriptParser.unaryExpression_return);


        object LT362_tree=null;
        object char_literal363_tree=null;
        object char_literal364_tree=null;
        object char_literal365_tree=null;
        object LT366_tree=null;

        try 
    	{
            // JavaScript.g:310:2: ( unaryExpression ( ( LT )* ( ( '*' | '/' | '%' ) ( LT )* unaryExpression ) )* )
            // JavaScript.g:310:4: unaryExpression ( ( LT )* ( ( '*' | '/' | '%' ) ( LT )* unaryExpression ) )*
            {
            	root_0 = (object)adaptor.GetNilNode();

            	PushFollow(FOLLOW_unaryExpression_in_multiplicativeExpression2787);
            	unaryExpression361 = unaryExpression();
            	state.followingStackPointer--;
            	if (state.failed) return retval;
            	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression361.Tree);
            	// JavaScript.g:310:20: ( ( LT )* ( ( '*' | '/' | '%' ) ( LT )* unaryExpression ) )*
            	do 
            	{
            	    int alt191 = 2;
            	    alt191 = dfa191.Predict(input);
            	    switch (alt191) 
            		{
            			case 1 :
            			    // JavaScript.g:310:21: ( LT )* ( ( '*' | '/' | '%' ) ( LT )* unaryExpression )
            			    {
            			    	// JavaScript.g:310:23: ( LT )*
            			    	do 
            			    	{
            			    	    int alt188 = 2;
            			    	    int LA188_0 = input.LA(1);

            			    	    if ( (LA188_0 == LT) )
            			    	    {
            			    	        alt188 = 1;
            			    	    }


            			    	    switch (alt188) 
            			    		{
            			    			case 1 :
            			    			    // JavaScript.g:310:23: LT
            			    			    {
            			    			    	LT362=(IToken)Match(input,LT,FOLLOW_LT_in_multiplicativeExpression2790); if (state.failed) return retval;

            			    			    }
            			    			    break;

            			    			default:
            			    			    goto loop188;
            			    	    }
            			    	} while (true);

            			    	loop188:
            			    		;	// Stops C# compiler whining that label 'loop188' has no statements

            			    	// JavaScript.g:310:25: ( ( '*' | '/' | '%' ) ( LT )* unaryExpression )
            			    	// JavaScript.g:310:26: ( '*' | '/' | '%' ) ( LT )* unaryExpression
            			    	{
            			    		// JavaScript.g:310:26: ( '*' | '/' | '%' )
            			    		int alt189 = 3;
            			    		switch ( input.LA(1) ) 
            			    		{
            			    		case 101:
            			    			{
            			    		    alt189 = 1;
            			    		    }
            			    		    break;
            			    		case 102:
            			    			{
            			    		    alt189 = 2;
            			    		    }
            			    		    break;
            			    		case 103:
            			    			{
            			    		    alt189 = 3;
            			    		    }
            			    		    break;
            			    			default:
            			    			    if ( state.backtracking > 0 ) {state.failed = true; return retval;}
            			    			    NoViableAltException nvae_d189s0 =
            			    			        new NoViableAltException("", 189, 0, input);

            			    			    throw nvae_d189s0;
            			    		}

            			    		switch (alt189) 
            			    		{
            			    		    case 1 :
            			    		        // JavaScript.g:310:27: '*'
            			    		        {
            			    		        	char_literal363=(IToken)Match(input,101,FOLLOW_101_in_multiplicativeExpression2795); if (state.failed) return retval;
            			    		        	if ( state.backtracking == 0 )
            			    		        	{char_literal363_tree = new MultiplyNode(char_literal363) ;
            			    		        		root_0 = (object)adaptor.BecomeRoot(char_literal363_tree, root_0);
            			    		        	}

            			    		        }
            			    		        break;
            			    		    case 2 :
            			    		        // JavaScript.g:310:48: '/'
            			    		        {
            			    		        	char_literal364=(IToken)Match(input,102,FOLLOW_102_in_multiplicativeExpression2803); if (state.failed) return retval;
            			    		        	if ( state.backtracking == 0 )
            			    		        	{char_literal364_tree = new DivideNode(char_literal364) ;
            			    		        		root_0 = (object)adaptor.BecomeRoot(char_literal364_tree, root_0);
            			    		        	}

            			    		        }
            			    		        break;
            			    		    case 3 :
            			    		        // JavaScript.g:310:67: '%'
            			    		        {
            			    		        	char_literal365=(IToken)Match(input,103,FOLLOW_103_in_multiplicativeExpression2811); if (state.failed) return retval;
            			    		        	if ( state.backtracking == 0 )
            			    		        	{char_literal365_tree = new ModuloNode(char_literal365) ;
            			    		        		root_0 = (object)adaptor.BecomeRoot(char_literal365_tree, root_0);
            			    		        	}

            			    		        }
            			    		        break;

            			    		}

            			    		// JavaScript.g:310:87: ( LT )*
            			    		do 
            			    		{
            			    		    int alt190 = 2;
            			    		    int LA190_0 = input.LA(1);

            			    		    if ( (LA190_0 == LT) )
            			    		    {
            			    		        alt190 = 1;
            			    		    }


            			    		    switch (alt190) 
            			    			{
            			    				case 1 :
            			    				    // JavaScript.g:310:87: LT
            			    				    {
            			    				    	LT366=(IToken)Match(input,LT,FOLLOW_LT_in_multiplicativeExpression2818); if (state.failed) return retval;

            			    				    }
            			    				    break;

            			    				default:
            			    				    goto loop190;
            			    		    }
            			    		} while (true);

            			    		loop190:
            			    			;	// Stops C# compiler whining that label 'loop190' has no statements

            			    		PushFollow(FOLLOW_unaryExpression_in_multiplicativeExpression2822);
            			    		unaryExpression367 = unaryExpression();
            			    		state.followingStackPointer--;
            			    		if (state.failed) return retval;
            			    		if ( state.backtracking == 0 ) adaptor.AddChild(root_0, unaryExpression367.Tree);

            			    	}


            			    }
            			    break;

            			default:
            			    goto loop191;
            	    }
            	} while (true);

            	loop191:
            		;	// Stops C# compiler whining that label 'loop191' has no statements


            }

            retval.Stop = input.LT(-1);

            if ( (state.backtracking==0) )
            {	retval.Tree = (object)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);}
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
    	// Conversion of the second argument necessary, but harmless
    	retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);

        }
        finally 
    	{
        }
        return retval;
    }
Esempio n. 21
0
        public WireframePS()
        {
            Name             = "WireframePS";
            Type             = ShaderType.Pixel;
            KeyPart          = new TechniqueKey(ps: PixelShaderFlags.Diffuse, sm: ShaderModel.SM_4_0_Level_9_3);
            FeatureLevel     = FeatureLevel.PS_4_0_Level_9_3;
            EnableSeparators = true;
            var inputStruct = WireframeVS.VertexPositionTextureIntensityBarycentricOut;

            inputStruct.Name = "input";
            InputStruct      = inputStruct;
            OutputStruct     = Struct.PixelShaderOutput;
            Structs.ConstantBuffer cbInstance = ConstantBuffer.CBMaterial;

            Struct material = (Struct)cbInstance[Param.Struct.Material];

            Add(cbInstance);

            IVariable position    = InputStruct[Param.SemanticVariables.ObjectPosition];
            IVariable diffuse     = material[Param.Material.Diffuse];
            IVariable specular    = material[Param.Material.Specular];
            IVariable intensity   = InputStruct[Param.SemanticVariables.Intensity];
            IVariable texture     = InputStruct[Param.SemanticVariables.Texture];
            IVariable barycentric = InputStruct[Param.SemanticVariables.Barycentric];

            //2
            UnaryFunctionNode fWidth = new UnaryFunctionNode
            {
                Input1 = new ReferenceNode()
                {
                    Value = barycentric
                },
                Function = HlslIntrinsics.Fwidth,
                Output   = new Vector()
                {
                    Type = Shaders.Type.Float3, Name = "d"
                },
                IsVerbose = true
            };

            //TrinaryFunctionNode smoothstep = new TrinaryFunctionNode()
            //{
            //    Input1 = new ConstantNode() {Value = new[] {0f, 0f, 0f}},
            //    Input2 = new MultiplyNode() {Input1 = new ScalarNode() {Value = 1.5f}, Input2 = fWidth},
            //    Input3 = new ReferenceNode() {Value = barycentric},
            //    Function = HLSLIntrinsics.Smoothstep,
            //    IsVerbose = true,
            //    Output = new Vector() {  Type = Shaders.Type.Float3, Name = "a3"}
            //};

            TrinaryFunctionNode smoothstep = new TrinaryFunctionNode()
            {
                Input1 = fWidth,
                Input2 = new MultiplyNode()
                {
                    Input1 = new ScalarNode()
                    {
                        Value = 3f
                    }, Input2 = fWidth
                },
                Input3 = new ReferenceNode()
                {
                    Value = barycentric
                },
                Function  = HlslIntrinsics.Smoothstep,
                IsVerbose = true,
                Output    = new Vector()
                {
                    Type = Shaders.Type.Float3, Name = "a3"
                }
            };

            BinaryFunctionNode minDistanceXY = new BinaryFunctionNode()
            {
                Input1 = new SwizzleNode
                {
                    Input   = smoothstep,
                    Swizzle = new[] { Swizzle.X }
                },
                Input2 = new SwizzleNode
                {
                    Input   = smoothstep,
                    Swizzle = new[] { Swizzle.Y }
                },
                Function = HlslIntrinsics.Min,
            };
            BinaryFunctionNode edgeIntensity = new BinaryFunctionNode()
            {
                Input1 = minDistanceXY,
                Input2 = new SwizzleNode
                {
                    Input   = smoothstep,
                    Swizzle = new[] { Swizzle.Z }
                },
                Function = HlslIntrinsics.Min,
                Output   = new Vector()
                {
                    Type = Shaders.Type.Float, Name = "minDistance"
                },
                IsVerbose = true
            };

            MultiplyNode objectDiffuse = new MultiplyNode()
            {
                Input1 = new ReferenceNode()
                {
                    Value = diffuse
                },
                Input2 = new CastNode
                {
                    Input = new SwizzleNode
                    {
                        Input = new ReferenceNode {
                            Value = intensity
                        },
                        Swizzle = new[] { Swizzle.X, Swizzle.Y, Swizzle.Z, Swizzle.Null }
                    },
                    Mask   = new[] { "0", "0", "0", "1" },
                    Output = new Vector()
                    {
                        Type = Shaders.Type.Float4, Name = "intensity4"
                    }
                },
                Output = new Vector()
                {
                    Type = Shaders.Type.Float4, Name = "diffuse"
                },
                IsVerbose = true
            };

            TrinaryFunctionNode finalColor = new TrinaryFunctionNode()
            {
                Input1 = new ReferenceNode()
                {
                    Value = specular
                },
                Input2   = objectDiffuse,
                Input3   = edgeIntensity,
                Function = HlslIntrinsics.Lerp
            };

            Result = new PSOutputNode
            {
                FinalColor = finalColor,
                Output     = OutputStruct
            };
        }