Ejemplo n.º 1
0
        public FullScreenQuadVS()
        {
            Name             = "FullScreenQuadVS";
            Type             = ShaderType.Vertex;
            FeatureLevel     = FeatureLevel.VS_4_0_Level_9_1;
            KeyPart          = new TechniqueKey(vs: VertexShaderFlags.Position | VertexShaderFlags.TextureUV | VertexShaderFlags.Normal);
            EnableSeparators = true;
            InputStruct      = Struct.VertexPositionNormalTexture;
            OutputStruct     = SpriteVS.VSOut;

            Structs.ConstantBuffer cbStatic = SpriteVS.CBStatic;
            Add(cbStatic);

            DeclarationNode nClip = ClipSpaceTransformNode.FullScreenNode(InputStruct, cbStatic[Param.Vectors.ViewportSize]);

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

            outputNode.RegisterField(Vector.ClipPosition, nClip, Shaders.Type.Float4);
            outputNode.RegisterField(Vector.TextureUV, new ReferenceNode {
                Value = InputStruct[Param.SemanticVariables.Texture]
            }, Shaders.Type.Float2);

            Result = outputNode;
        }
Ejemplo n.º 2
0
        public SpriteVS()
        {
            Name             = "SpriteVS";
            Type             = ShaderType.Vertex;
            FeatureLevel     = FeatureLevel.VS_4_0_Level_9_1;
            KeyPart          = new TechniqueKey(vs: VertexShaderFlags.Position | VertexShaderFlags.TextureUV | VertexShaderFlags.Normal);
            EnableSeparators = true;
            InputStruct      = Struct.VertexPositionNormalTexture;
            OutputStruct     = VSOut;

            Structs.ConstantBuffer cbStatic   = CBStatic;
            Structs.ConstantBuffer cbInstance = CBPerInstance;
            Add(cbStatic);
            Add(cbInstance);

            ClipSpaceTransformNode cstNode = new ClipSpaceTransformNode
            {
                Position = new ReferenceNode {
                    Value = InputStruct[Param.SemanticVariables.ObjectPosition]
                },
                InstancePosition = cbInstance[Param.Vectors.SpritePosition],
                Size             = cbInstance[Param.Vectors.SpriteSize],
                ScreenSize       = cbStatic[Param.Vectors.ViewportSize]
            };

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

            outputNode.RegisterField(Vector.ClipPosition, cstNode, Shaders.Type.Float4);
            outputNode.RegisterField(Vector.TextureUV, new ReferenceNode {
                Value = InputStruct[Param.SemanticVariables.Texture]
            }, Shaders.Type.Float2);

            Result = outputNode;
        }
Ejemplo n.º 3
0
        public PhongShadowsPS()
        {
            Name         = "PhongShadowsPS";
            FeatureLevel = FeatureLevel.PS_5_0;
            KeyPart      = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.Specular | PixelShaderFlags.Shadows | PixelShaderFlags.ShadowMap, sm: FromFeatureLevel(FeatureLevel));
            Clear();
            PhongLightingNode nPhongLighting = (PhongLightingNode)((PSOutputNode)Result).FinalColor;
            var inputStruct = PhongShadowsVS.VSOut;

            inputStruct.Name = "input";
            InputStruct      = inputStruct;

            Structs.ConstantBuffer cbStatic = CBStatic;
            Structs.ConstantBuffer cbFrame  = CBFrame;
            Texture tShadow        = Texture.ShadowMap;
            Sampler sShadowSampler = Sampler.MinMagMiLinearMirrorLessEqual;

            sShadowSampler.Name = "sShadowMap";

            Add(tShadow);
            Add(sShadowSampler);
            Add(cbStatic);
            Add(cbFrame);

            TextureSampleNode nShadowMapSampler = new TextureSampleNode
            {
                Coordinates = new ReferenceNode {
                    Value = inputStruct[Param.SemanticVariables.ShadowProjection]
                },
                Texture   = tShadow,
                Sampler   = sShadowSampler,
                IsVerbose = false,
            };

            nPhongLighting.ShadowMapSample = nShadowMapSampler;
            nPhongLighting.Shadows         = true;
        }
Ejemplo n.º 4
0
        public PhongInstanceVS()
        {
            Name             = "PhongInstanceVS";
            Type             = ShaderType.Vertex;
            KeyPart          = new TechniqueKey(vs: VertexShaderFlags.Position | VertexShaderFlags.Normal | VertexShaderFlags.TextureUV | VertexShaderFlags.InstanceWorld);
            FeatureLevel     = FeatureLevel.VS_4_0_Level_9_3;
            EnableSeparators = true;
            var instanceStruct = Struct.VertexPositionNormalTexture;

            instanceStruct.Add(Matrix.EntityInstanceWorld);

            InputStruct  = instanceStruct;
            OutputStruct = Struct.VertexPositionNormalTextureOut;

            Structs.ConstantBuffer cbFrame = ConstantBuffer.CBPerFrame;
            Add(cbFrame);

            IVariable position = InputStruct[Param.SemanticVariables.ObjectPosition];
            IVariable normal   = InputStruct[Param.SemanticVariables.Normal];
            IVariable texture  = InputStruct[Param.SemanticVariables.Texture];

            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
            };

            ReferenceNode mWorld = new ReferenceNode
            {
                Value  = InputStruct[Param.SemanticVariables.InstanceWorld],
                Output = new Matrix {
                    Type = Shaders.Type.Matrix, Name = "mWorld",
                },
                IsVerbose = true
            };

            MatrixMultiplyNode m1m2 = new MatrixMultiplyNode
            {
                Input1 = mWorld,
                Input2 = new ReferenceNode {
                    Value = Matrix.CameraView
                },
            };

            MatrixMultiplyNode mulWVP = new MatrixMultiplyNode
            {
                Input1 = m1m2,
                Input2 = new ReferenceNode {
                    Value = Matrix.CameraProjection
                },
                IsVerbose = true
            };

            MatrixMultiplyNode mulPosWVP = new MatrixMultiplyNode
            {
                Input1 = nV3toV4,
                Input2 = mulWVP,
            };

            MatrixMultiplyNode mulWP = new MatrixMultiplyNode
            {
                Input1 = nV3toV4,
                Input2 = mWorld,
            };

            MatrixMultiplyNode mulNormal = new MatrixMultiplyNode
            {
                Input1 = new ReferenceNode {
                    Value = normal
                },
                Input2 = CastNode.CastWorldFloat3x3((Matrix)mWorld.Output, "mWorld3x3")
            };

            Result = new PhongVSOutputNode
            {
                Position      = mulPosWVP,
                WorldPosition = mulWP,
                Normal        = mulNormal,
                Texture       = new ReferenceNode {
                    Value = texture
                },
                Output = OutputStruct
            };
        }
Ejemplo n.º 5
0
        public PhongVS()
        {
            Name             = "PhongVS";
            Type             = ShaderType.Vertex;
            KeyPart          = new TechniqueKey(vs: VertexShaderFlags.Position | VertexShaderFlags.Normal | VertexShaderFlags.TextureUV);
            FeatureLevel     = FeatureLevel.VS_4_0_Level_9_1;
            EnableSeparators = true;
            InputStruct      = Struct.VertexPositionNormalTexture;
            OutputStruct     = Struct.VertexPositionNormalTextureOut;

            Structs.ConstantBuffer cbFrame    = ConstantBuffer.CBPerFrame;
            Structs.ConstantBuffer cbInstance = CBPerInstance;
            Add(cbFrame);
            Add(cbInstance);

            IVariable position = InputStruct[Param.SemanticVariables.ObjectPosition];
            IVariable normal   = InputStruct[Param.SemanticVariables.Normal];
            IVariable texture  = InputStruct[Param.SemanticVariables.Texture];


            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,
            };

            MatrixMultiplyNode mulWP = new MatrixMultiplyNode
            {
                Input1 = nV3toV4,
                Input2 = new ReferenceNode {
                    Value = Matrix.EntityWorld
                },
            };

            MatrixMultiplyNode mulNormal = new MatrixMultiplyNode
            {
                Input1 = new ReferenceNode {
                    Value = normal
                },
                Input2 = CastNode.WorldInverseTransposeFloat3x3
            };

            Result = new PhongVSOutputNode
            {
                Position      = mulPosWVP,
                WorldPosition = mulWP,
                Normal        = mulNormal,
                Texture       = new ReferenceNode {
                    Value = texture
                },
                Output = OutputStruct
            };
        }
Ejemplo n.º 6
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
            };
        }
Ejemplo n.º 7
0
        public PhongPS()
        {
            Name             = "PhongPS";
            Type             = ShaderType.Pixel;
            KeyPart          = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.Specular);
            FeatureLevel     = FeatureLevel.PS_4_0_Level_9_1;
            EnableSeparators = true;
            var input = Struct.VertexPositionNormalTextureOut;

            input.Name   = "input";
            InputStruct  = input;
            OutputStruct = Struct.PixelShaderOutput;

            Structs.ConstantBuffer cbStatic   = CBLight;
            Structs.ConstantBuffer cbFrame    = CBFrame;
            Structs.ConstantBuffer cbInstance = ConstantBuffer.CBMaterial;

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

            Add(cbStatic);
            Add(cbFrame);
            Add(cbInstance);

            CastNode vWorldPos = new CastNode
            {
                Input = new SwizzleNode {
                    Input = new ReferenceNode {
                        Value = InputStruct[Param.SemanticVariables.WorldPosition]
                    }
                    , Swizzle = new[] { Swizzle.X, Swizzle.Y, Swizzle.Z }
                },
                Output = new Vector {
                    Type = Shaders.Type.Float3, Name = "vWorldPos",
                },
                IsVerbose = true
            };

            SubtractionNode vLightDirection = new SubtractionNode
            {
                Input1 = new ReferenceNode {
                    Value = pointLight[Param.Light.Position]
                },
                Input2 = vWorldPos,
            };

            SubtractionNode vViewDirection = new SubtractionNode
            {
                Input1 = new ReferenceNode {
                    Value = cbFrame[Param.Vectors.CameraPosition]
                },
                Input2 = vWorldPos,
            };

            ReferenceNode nNormal = new ReferenceNode {
                Value = InputStruct[Param.SemanticVariables.Normal]
            };

            UnaryFunctionNode normalizeNormal = new UnaryFunctionNode
            {
                Input1   = nNormal,
                Function = HlslIntrinsics.Normalize,
                Output   = new Vector {
                    Type = nNormal.Output.Type, Name = "vNormal"
                },
                IsVerbose = true,
            };

            UnaryFunctionNode normalizeViewDirection = new UnaryFunctionNode
            {
                Input1   = vViewDirection,
                Function = HlslIntrinsics.Normalize,
                Output   = new Vector {
                    Type = vViewDirection.Output.Type, Name = "vViewDirection"
                },
                IsVerbose = true,
            };

            UnaryFunctionNode normalizeLightDirection = new UnaryFunctionNode
            {
                Input1   = vLightDirection,
                Function = HlslIntrinsics.Normalize,
                Output   = new Vector {
                    Type = vLightDirection.Output.Type, Name = "vLightDirection"
                },
                IsVerbose = true,
            };

            InvertNode vLightDirectionInv = new InvertNode
            {
                Input = normalizeLightDirection,
                //Output = new Vector { Type = Shaders.Type.Float3, Name = "vLightDirection" },
            };

            PhongLightingNode nPhongLighting = new PhongLightingNode
            {
                Light = new ReferenceNode {
                    Value = pointLight
                },
                Material = new ReferenceNode {
                    Value = material
                },
                ViewDirection  = normalizeViewDirection,
                Normal         = normalizeNormal,
                LightDirection = vLightDirectionInv,
                Specular       = true,
            };

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