コード例 #1
0
        public BasicEffect(GraphicsDevice graphicsDevice)
            : base(graphicsDevice)
        {
            var technique = new EffectTechnique("Basic");

            ThreadingHelper.BlockOnUIThread(() => {
                Shader[] shaders = new Shader[]
                {
                    new Shader(ShaderType.VertexShader, vertexShader),
                    new Shader(ShaderType.FragmentShader, pixelShader)
                };

                foreach (Shader shader in shaders)
                {
                    shader.Compile();
                }
                EffectPass pass = new EffectPass("Basic");
                pass.AttachShaders(shaders);
                pass.BindAttribute(VertexElementUsage.Color, "color");
                pass.BindAttribute(VertexElementUsage.TextureCoordinate, "textureCoordinate");
                pass.BindAttribute(VertexElementUsage.Position, "position");
                pass.Link();



                technique.Passes.Add(pass);
                Techniques.Add(technique);
            });
            CurrentTechnique = technique;


            Initialize();

            World = View = Projection = Matrix.Identity;
        }
コード例 #2
0
ファイル: EffectProcessor.cs プロジェクト: marsat02/engenious
        public override EffectContent Process(EffectContent input, string filename, ContentProcessorContext context)
        {
            try
            {
                //Passthrough and verification
                foreach (var technique in input.Techniques)
                {
                    foreach (var pass in technique.Passes)
                    {
                        engenious.Graphics.EffectPass compiledPass = new engenious.Graphics.EffectPass(pass.Name);

                        foreach (var shader in pass.Shaders)
                        {
                            try
                            {
                                var tmp = new Shader(shader.Key, System.IO.File.ReadAllText(shader.Value));
                                tmp.Compile();
                                compiledPass.AttachShader(tmp);
                            }
                            catch (Exception ex)
                            {
                                PreprocessMessage(context, shader.Value, ex.Message, BuildMessageEventArgs.BuildMessageType.Error);
                            }
                        }

                        compiledPass.Link();
                        compiledPass.Apply();
                        foreach (var attr in pass.Attributes)
                        {
                            compiledPass.BindAttribute(attr.Key, attr.Value);
                        }
                    }
                }
                return(input);
            }
            catch (Exception ex)
            {
                PreprocessMessage(context, System.IO.Path.GetFileName(filename), ex.Message, BuildMessageEventArgs.BuildMessageType.Error);
            }
            return(null);
        }