Beispiel #1
0
        public static TechniqueKey GenerateKeyPart(Shader shader)
        {
            VertexShaderFlags vsFlags = VertexShaderFlags.None;
            PixelShaderFlags  psFlags = PixelShaderFlags.None;
            ShaderModel       model   = FromFeatureLevel(shader.FeatureLevel);

            foreach (var property in shader.Result.DescendantNodes
                     .Select(node => node.GetType()
                             .GetProperties(BindingFlags.Public | BindingFlags.Instance)
                             .Where(p => p.PropertyType == typeof(INode))).SelectMany(properties => properties))
            {
                switch (shader.Type)
                {
                case ShaderType.Vertex:
                    vsFlags = property.GetCustomAttributes(true)
                              .OfType <VertexShaderAttribute>()
                              .Aggregate(vsFlags, (current, vsAttribute) => current | vsAttribute.Features);
                    break;

                case ShaderType.Pixel:
                    psFlags = property.GetCustomAttributes(true).OfType <PixelShaderAttribute>()
                              .Aggregate(psFlags, (current, psAttribute) => current | psAttribute.Features);
                    break;
                }
            }

            return(new TechniqueKey(vsFlags, psFlags, sm: model));
        }
Beispiel #2
0
 public void SetTechnique(ShaderCollection shaderCollection, string techniqueKey)
 {
     this.shaderCollection = shaderCollection;
     Content.Store(shaderCollection.Name, shaderCollection);
     cShader = new ShaderComponent {
         AssetName = shaderCollection.Name, Key = techniqueKey
     };
     vsFlags = shaderCollection[techniqueKey].Key.VertexShader;
 }
Beispiel #3
0
 public TechniqueKey(VertexShaderFlags vs = VertexShaderFlags.None, PixelShaderFlags ps = PixelShaderFlags.None, ShaderModel sm = ShaderModel.SM_4_0_Level_9_1,
                     PreferredRasterizerState rasterizerState = PreferredRasterizerState.CullBack, PreferredBlendState blendState = PreferredBlendState.Opaque, PreferredDepthStencilState depthStencilState = PreferredDepthStencilState.Enabled)
     : this()
 {
     VertexShader      = vs;
     PixelShader       = ps;
     ShaderModel       = sm;
     RasterizerState   = rasterizerState;
     BlendState        = blendState;
     DepthStencilState = depthStencilState;
 }
Beispiel #4
0
        public static ModelOperation DetectModelRequirements(VertexShaderFlags flags)
        {
            switch (flags)
            {
            case vsBarycentric:
                return(ModelOperation.CalculateBarycentricCoordinatesAndExcludeEdges);

            case vsDefault:
            default:
                return(ModelOperation.None);
            }
        }
Beispiel #5
0
        internal static TechniqueKey GenerateKeyPartRequirements(Shader shader)
        {
            var vsAttributes = shader.GetType().GetCustomAttributes <VertexShaderAttribute>();
            var psAttributes = shader.GetType().GetCustomAttributes <PixelShaderAttribute>();

            VertexShaderFlags vsFlags = VertexShaderFlags.None;
            PixelShaderFlags  psFlags = PixelShaderFlags.None;
            ShaderModel       model   = FromFeatureLevel(shader.FeatureLevel);

            foreach (var vsAttribute in vsAttributes)
            {
                vsFlags |= vsAttribute.Features;
            }
            foreach (var psAttribute in psAttributes)
            {
                psFlags |= psAttribute.Features;
            }


            return(new TechniqueKey(vsFlags, psFlags, sm: model));
        }
Beispiel #6
0
        private static VertexElement[] CreateElement(VertexShaderFlags flag)
        {
            switch (flag)
            {
            case VertexShaderFlags.Position:
                return(new[] { VertexElement.Position(Format.R32G32B32_Float) });

            case VertexShaderFlags.Normal:
                return(new[] { VertexElement.Normal(Format.R32G32B32_Float) });

            case VertexShaderFlags.TextureUV:
                return(new[] { VertexElement.TextureCoordinate(Format.R32G32_Float) });

            case VertexShaderFlags.TextureUVW:
                return(new[] { VertexElement.TextureCoordinate(Format.R32G32B32_Float) });

            case VertexShaderFlags.Color:
                return(new[] { VertexElement.Color(Format.R32G32B32A32_Float) });

            case VertexShaderFlags.Tangent:
                return(new[] { VertexElement.Tangent(Format.R32G32B32A32_Float) });

            case VertexShaderFlags.Barycentric:
                return(new[] { new VertexElement("BARYCENTRIC", Format.R32G32B32_Float) });

            case VertexShaderFlags.InstanceWorld:
                return(new[]
                {
                    new VertexElement("INSTANCEWORLD", 0, Format.R32G32B32A32_Float),
                    new VertexElement("INSTANCEWORLD", 1, Format.R32G32B32A32_Float),
                    new VertexElement("INSTANCEWORLD", 2, Format.R32G32B32A32_Float),
                    new VertexElement("INSTANCEWORLD", 3, Format.R32G32B32A32_Float),
                });

            default:
                throw new ArgumentOutOfRangeException(string.Format("[{0}]: VertexShaderFlag not valid", flag));
            }
        }
        static TechniqueKey GenerateKey(IEnumerable <ShaderAttributeViewModel> data, ShaderModel selectedShaderModel,
                                        PreferredRasterizerState rasterizerState, PreferredBlendState blendState, PreferredDepthStencilState depthStencilState)
        {
            Contract.Requires <ArgumentNullException>(data != null);
            VertexShaderFlags vsFlags = Graphics.Effects.VertexShaderFlags.None;
            PixelShaderFlags  psFlags = Graphics.Effects.PixelShaderFlags.None;

            foreach (var flagVM in data)
            {
                switch (flagVM.Type)
                {
                case ShaderType.Vertex:
                    vsFlags |= (VertexShaderFlags)Enum.Parse(typeof(VertexShaderFlags), flagVM.Name);
                    break;

                case ShaderType.Pixel:
                    psFlags |= (PixelShaderFlags)Enum.Parse(typeof(PixelShaderFlags), flagVM.Name);
                    break;
                }
            }

            return(new TechniqueKey(vsFlags, psFlags, selectedShaderModel, rasterizerState, blendState, depthStencilState));
        }
Beispiel #8
0
        public VertexInputLayout GenerateVertexInputLayout()
        {
            VertexShaderFlags vsFlags = Key.VertexShader;

            return(VertexInputLayout.New(0, vsFlags.GetUniqueFlags().Cast <VertexShaderFlags>().SelectMany(CreateElement).ToArray()));
        }
Beispiel #9
0
 public bool GetFeatureStatus(VertexShaderFlags feature)
 {
     return(Mapping.Key.Supports(feature));
 }
Beispiel #10
0
 public bool Supports(VertexShaderFlags feature)
 {
     return((VertexShader & feature) == feature);
 }
 public VertexShaderAttribute(VertexShaderFlags vsFeatures)
 {
     Features = vsFeatures;
 }