示例#1
0
        private void SetupLight(RendererMetadata metadata, LightData data)
        {
            var light = data.Light;

            if (material != null)
            {
                Matrix  view      = metadata.Get <Matrix>("view").Value;
                Vector3 direction = light.Direction;
                Vector3.TransformNormal(ref direction, ref view, out direction);

                var shadowsEnabled = light.ShadowResolution > 0;

                material.Parameters["Direction"].SetValue(direction);
                material.Parameters["Colour"].SetValue(light.Colour);
                material.Parameters["EnableShadows"].SetValue(shadowsEnabled);

                if (shadowsEnabled)
                {
                    material.Parameters["ShadowProjection"].SetValue(metadata.Get <Matrix>("inverseview").Value *data.View *data.Projection);
                    material.Parameters["ShadowMapSize"].SetValue(new Vector2(light.ShadowResolution, light.ShadowResolution));
                    material.Parameters["ShadowMap"].SetValue(data.ShadowMap);
                    material.Parameters["LightFarClip"].SetValue(data.FarClip);
                    material.Parameters["LightNearPlane"].SetValue(data.NearClip);
                }
            }
        }
示例#2
0
文件: View.cs 项目: sachgits/Myre
        /*
         * public Property<Camera> Camera { get; private set; }
         * public Property<Viewport> Viewport { get; private set; }
         *
         * public View(
         *  Property<Camera> camera,
         *  Property<Viewport> viewport)
         * {
         *  this.Camera = camera;
         *  this.Viewport = viewport;
         * }
         */

        public void SetMetadata(RendererMetadata metadata)
        {
            metadata.Set("activeview", this);
            metadata.Set("resolution", new Vector2(viewport.Value.Width, viewport.Value.Height));
            metadata.Set("viewport", viewport.Value);
            camera.Value.SetMetadata(metadata);
        }
示例#3
0
 private void DrawGeometryLights(List <LightData> lights, RendererMetadata metadata, GraphicsDevice device)
 {
     foreach (var light in lights)
     {
         SetupLight(metadata, geometryLightingMaterial, light);
         DrawGeomery(geometryLightingMaterial, metadata, device);
     }
 }
示例#4
0
        public Renderer(IKernel kernel, GraphicsDevice device, IServiceProvider services)
        {
            _kernel = kernel;
            _device = device;
            _data = new RendererMetadata();
            _settings = new RendererSettings(this);
            _viewResults = new Queue<RenderPlan.Output>();
            _spriteBatch = new SpriteBatch(device);

            Content.Initialise(kernel.Get<ContentManager>(), services);
        }
示例#5
0
        public Renderer(IKernel kernel, GraphicsDevice device, IServiceProvider services)
        {
            this.kernel = kernel;
            this.device = device;
            this.data = new RendererMetadata();
            this.settings = new RendererSettings(this);
            this.viewResults = new Queue<RenderPlan.Output>();
            this.quad = new Quad(device);
            this.spriteBatch = new SpriteBatch(device);

            Content.Initialise(services);
        }
示例#6
0
        private void DrawGeomery(Material material, RendererMetadata metadata, GraphicsDevice device)
        {
            var part = geometry.Meshes[0].MeshParts[0];

            foreach (var pass in material.Begin(metadata))
            {
                pass.Apply();

                device.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                             part.VertexOffset, 0, part.NumVertices, part.StartIndex, part.PrimitiveCount);
            }
        }
示例#7
0
文件: Renderer.cs 项目: sachgits/Myre
        public Renderer(IKernel kernel, GraphicsDevice device, IServiceProvider services)
        {
            this.kernel      = kernel;
            this.device      = device;
            this.data        = new RendererMetadata();
            this.settings    = new RendererSettings(this);
            this.viewResults = new Queue <RenderPlan.Output>();
            this.quad        = new Quad(device);
            this.spriteBatch = new SpriteBatch(device);

            Content.Initialise(services);
        }
        private void SetupLight(RendererMetadata metadata, Material material, PointLight light)
        {
            if (material != null)
            {
                Vector3 position = Vector3.Transform(light.Position, metadata.Get <Matrix>("view").Value);
                material.Parameters["LightPosition"].SetValue(position);
                material.Parameters["Colour"].SetValue(light.Colour);
                material.Parameters["Range"].SetValue(light.Range);
            }

            var world = Matrix.CreateScale(light.Range / geometry.Meshes[0].BoundingSphere.Radius)
                        * Matrix.CreateTranslation(light.Position);

            metadata.Set <Matrix>("world", world);
            Matrix.Multiply(ref world, ref metadata.Get <Matrix>("view").Value, out metadata.Get <Matrix>("worldview").Value);
            Matrix.Multiply(ref metadata.Get <Matrix>("worldview").Value, ref metadata.Get <Matrix>("projection").Value, out metadata.Get <Matrix>("worldviewprojection").Value);
        }
示例#9
0
        private void SetupLight(RendererMetadata metadata, Material material, LightData data)
        {
            var light = data.Light;

            if (material != null)
            {
                Matrix  view      = metadata.Get <Matrix>("view").Value;
                Vector3 position  = light.Position;
                Vector3 direction = light.Direction;
                Vector3.Transform(ref position, ref view, out position);
                Vector3.TransformNormal(ref direction, ref view, out direction);
                float angle = (float)Math.Cos(light.Angle / 2);

                if (light.Mask != null || light.ShadowResolution > 0)
                {
                    var inverseView             = metadata.Get <Matrix>("inverseview").Value;
                    var cameraToLightProjection = inverseView * data.View * data.Projection;
                    material.Parameters["CameraViewToLightProjection"].SetValue(cameraToLightProjection);
                }

                material.Parameters["LightPosition"].SetValue(position);
                material.Parameters["LightDirection"].SetValue(-direction);
                material.Parameters["Angle"].SetValue(angle);
                material.Parameters["Range"].SetValue(light.Range);
                material.Parameters["Colour"].SetValue(light.Colour);
                material.Parameters["EnableProjectiveTexturing"].SetValue(light.Mask != null);
                material.Parameters["Mask"].SetValue(light.Mask);
                material.Parameters["EnableShadows"].SetValue(light.ShadowResolution > 0);
                material.Parameters["ShadowMapSize"].SetValue(new Vector2(light.ShadowResolution, light.ShadowResolution));
                material.Parameters["ShadowMap"].SetValue(data.ShadowMap);
                material.Parameters["LightFarClip"].SetValue(light.Range);

                var nearPlane = new Plane(light.Direction, Vector3.Dot(light.Direction, light.Position));
                nearPlane.Normalize();
                nearPlane = Plane.Transform(nearPlane, view);
                material.Parameters["LightNearPlane"].SetValue(new Vector4(nearPlane.Normal, nearPlane.D));
            }

            var world = Matrix.CreateScale(light.Range / geometry.Meshes[0].BoundingSphere.Radius)
                        * Matrix.CreateTranslation(light.Position);

            metadata.Set <Matrix>("world", world);
            Matrix.Multiply(ref world, ref metadata.Get <Matrix>("view").Value, out metadata.Get <Matrix>("worldview").Value);
            Matrix.Multiply(ref metadata.Get <Matrix>("worldview").Value, ref metadata.Get <Matrix>("projection").Value, out metadata.Get <Matrix>("worldviewprojection").Value);
        }
示例#10
0
        public LayerRenderer(TElement adornedElement, TModel model) : base(adornedElement)
        {
            this.Metadata = new RendererMetadata();

            this.Model   = model;
            this.Element = adornedElement;

            // 렌더러 설정
            this.Model.Binder.SetRenderer(this);

            this.RendererChildren = new List <IRenderer>();

            // 이름 설정
            var attr = model.GetAttribute <DesignElementAttribute>();

            if (attr != null)
            {
                displayTypeName = attr.DisplayName;
            }

            // Binder
            this.GetBinderHost().Released += LayerRenderer_Released;
        }
示例#11
0
 protected abstract void SetEffectParameters(Material e, RendererMetadata metadata);
示例#12
0
        public void Draw(RendererMetadata data)
        {
            Debug.Assert(Description.Texture != null, "Particle systems must be initialised before they can be drawn.");
            //Debug.WriteLine(string.Format("retired: {0}, active: {1}, new: {2}, free: {3}", finished, active, newlyCreated, free));

            if (dirty)
            {
                InitialiseBuffer();
            }

            if (newlyCreated != free)
            {
                AddNewParticlesToVertexBuffer();
            }

            if (vertices.IsContentLost)
            {
                vertices.SetData(particles);
            }

            // If there are any active particles, draw them now!
            if (active != free)
            {
                device.BlendState        = Description.BlendState;
                device.DepthStencilState = DepthStencilState.DepthRead;

                // Set an effect parameter describing the viewport size. This is
                // needed to convert particle sizes into screen space point sizes.
                viewportScaleParameter.SetValue(new Vector2(0.5f / data.Get <Viewport>("viewport").Value.AspectRatio, -0.5f));

                // Set an effect parameter describing the current time. All the vertex
                // shader particle animation is keyed off this value.
                currentTimeParameter.SetValue(time);

                data.Set <Matrix>("world", Transform);

                // Set the particle vertex and index buffer.
                device.SetVertexBuffer(vertices);
                device.Indices = indices;

                SelectParticleType();

                // Activate the particle effect.
                foreach (EffectPass pass in material.Begin(data))
                {
                    pass.Apply();

                    // work arround for bug in xna 4.0
                    device.SamplerStates[0] = SamplerState.PointClamp;
                    device.SamplerStates[1] = SamplerState.PointClamp;
                    device.SamplerStates[2] = SamplerState.PointClamp;

                    if (active < free)
                    {
                        // If the active particles are all in one consecutive range,
                        // we can draw them all in a single call.
                        device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                     active * 4, (free - active) * 4,
                                                     active * 6, (free - active) * 2);
                    }
                    else
                    {
                        // If the active particle range wraps past the end of the queue
                        // back to the start, we must split them over two draw calls.
                        device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                     active * 4, (Capacity - active) * 4,
                                                     active * 6, (Capacity - active) * 2);

                        if (free > 0)
                        {
                            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                         0, free * 4,
                                                         0, free * 2);
                        }
                    }
                }

                // Reset some of the renderstates that we changed,
                // so as not to mess up any other subsequent drawing.
                device.DepthStencilState = DepthStencilState.Default;
                device.BlendState        = BlendState.AlphaBlend;
            }

            frameCounter++;
        }
示例#13
0
        public void Draw(RendererMetadata data)
        {
            Debug.Assert(Description.Texture != null, "Particle systems must be initialised before they can be drawn.");
            //Debug.WriteLine(string.Format("retired: {0}, active: {1}, new: {2}, free: {3}", finished, active, newlyCreated, free));

            if (dirty)
                InitialiseBuffer();

            if (newlyCreated != free)
                AddNewParticlesToVertexBuffer();

            if (vertices.IsContentLost)
                vertices.SetData(particles);

            // If there are any active particles, draw them now!
            if (active != free)
            {
                device.BlendState = Description.BlendState;
                device.DepthStencilState = DepthStencilState.DepthRead;

                // Set an effect parameter describing the viewport size. This is
                // needed to convert particle sizes into screen space point sizes.
                viewportScaleParameter.SetValue(new Vector2(0.5f / data.Get<Viewport>("viewport").Value.AspectRatio, -0.5f));

                // Set an effect parameter describing the current time. All the vertex
                // shader particle animation is keyed off this value.
                currentTimeParameter.SetValue(time);

                data.Set<Matrix>("world", Transform);

                // Set the particle vertex and index buffer.
                device.SetVertexBuffer(vertices);
                device.Indices = indices;

                SelectParticleType();

                // Activate the particle effect.
                foreach (EffectPass pass in material.Begin(data))
                {
                    pass.Apply();

                    // work arround for bug in xna 4.0
                    device.SamplerStates[0] = SamplerState.PointClamp;
                    device.SamplerStates[1] = SamplerState.PointClamp;
                    device.SamplerStates[2] = SamplerState.PointClamp;

                    if (active < free)
                    {
                        // If the active particles are all in one consecutive range,
                        // we can draw them all in a single call.
                        device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                     active * 4, (free - active) * 4,
                                                     active * 6, (free - active) * 2);
                    }
                    else
                    {
                        // If the active particle range wraps past the end of the queue
                        // back to the start, we must split them over two draw calls.
                        device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                     active * 4, (Capacity - active) * 4,
                                                     active * 6, (Capacity - active) * 2);

                        if (free > 0)
                        {
                            device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
                                                         0, free * 4,
                                                         0, free * 2);
                        }
                    }
                }

                // Reset some of the renderstates that we changed,
                // so as not to mess up any other subsequent drawing.
                device.DepthStencilState = DepthStencilState.Default;
                device.BlendState = BlendState.AlphaBlend;
            }

            frameCounter++;
        }