示例#1
0
        public PhongCubeMapPS()
        {
            Name    = "PhongCubeMapPS";
            KeyPart = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.Specular | PixelShaderFlags.CubeMap);

            var input = PhongCubeMapVS.VSOut;

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

            PhongLightingNode nPhongLighting = (PhongLightingNode)((PSOutputNode)Result).FinalColor;

            nPhongLighting.DiffuseMap = true;
            nPhongLighting.CubeMap    = true;

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

            nPhongLighting.DiffuseMapSample = new TextureSampleNode
            {
                Coordinates = new ReferenceNode {
                    Value = InputStruct[Param.SemanticVariables.Texture]
                },
                Texture   = tDiffuse,
                Sampler   = sDiffuseSampler,
                IsVerbose = true
            };
            Add(tDiffuse);
            Add(sDiffuseSampler);
        }
示例#2
0
        public NormalMappingPS()
        {
            Name    = "NormalMappingPS";
            KeyPart = new TechniqueKey(ps: PixelShaderFlags.Diffuse | PixelShaderFlags.DiffuseMap | PixelShaderFlags.Specular | PixelShaderFlags.NormalMap);

            Struct inputStruct = Struct.VertexPositionNormalTextureTangentOut;

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

            PhongLightingNode nPhongLighting  = (PhongLightingNode)((PSOutputNode)Result).FinalColor;
            Texture           tNormal         = Texture.NormalMap;
            Sampler           sDiffuseSampler = Get <Sampler>(Param.Samplers.MinMagMipLinearWrap);

            Add(tNormal);

            TextureSampleNode nNormalMapSample = new TextureSampleNode
            {
                Coordinates = new ReferenceNode {
                    Value = InputStruct[Param.SemanticVariables.Texture]
                },
                Texture   = tNormal,
                Sampler   = sDiffuseSampler,
                IsVerbose = true
            };

            TrinaryFunctionNode nNormalMapping = new TrinaryFunctionNode
            {
                Input1 = nPhongLighting.Normal,
                Input2 = new ReferenceNode {
                    Value = InputStruct[Param.SemanticVariables.Tangent]
                },
                Input3   = nNormalMapSample,
                Function = new NormalMappingMethod(),
                Output   = new Vector {
                    Type = Shaders.Type.Float3, Name = "vNormalTS"
                },
                IsVerbose = true
            };

            nPhongLighting.Normal = nNormalMapping;
        }
示例#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;
        }
示例#4
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
            };
        }