Beispiel #1
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;
        }
Beispiel #2
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
            };
        }