Beispiel #1
0
        public void TestPlanarReflection()
        {
            using (OpenFileDialog d = new OpenFileDialog())
            {
                if (d.ShowDialog() == DialogResult.OK)
                {
                    SceneTests.InitializeScene();
                    var content = ContentImporter.Import(SceneManager.Scene, d.FileName);
                    ReflectiveNodeTechnique technique = SceneManager.Scene.EnumerateNodesInPreOrden().Where(x => x.Technique is ReflectiveNodeTechnique).Select(x => (ReflectiveNodeTechnique)x.Technique).FirstOrDefault();
                    Engine.Presenter.Rendering += () =>
                    {
                        var untranformed = Service.Require <RenderQuadEffect>();
                        var sprite       = Service.Require <Sprite>();
                        GraphicDeviceFactory.Device.Ps.SetResource(0, technique.ReflectionTexture);

                        untranformed.U.alpha   = 1;
                        untranformed.Technique = 1;

                        sprite.Begin();
                        sprite.SetTrasform(untranformed, new Rectangle(0, 0, 256, 256), Matrix.Identity);
                        sprite.DrawQuad(untranformed);
                        sprite.End();
                    };
                }
            }
        }
Beispiel #2
0
        public override object Process(Scene scene, Frame node)
        {
            if (scene == null)
            {
                return(null);
            }

            string tag   = node.Tag;
            var    match = _pattern.Match(tag);

            if (!match.Success)
            {
                return(null);
            }

            Frame planeMesh = match.Groups["P"].Success ? scene.FindNode(match.Groups["P"].Value) : node;

            if (planeMesh == null || !(planeMesh.Component is IFrameMesh))
            {
                return(null);
            }

            var   mesh = ((IFrameMesh)planeMesh.Component).Mesh;
            Plane plane;

            if (!mesh.IsPlane(out plane))
            {
                return(null);
            }

            float aspect = (float)GraphicDeviceFactory.Device.BackBuffer.Width / (float)GraphicDeviceFactory.Device.BackBuffer.Height;
            int   width  = GraphicDeviceFactory.Device.BackBuffer.Width;

            if (match.Groups["S"].Success)
            {
                width = int.Parse(match.Groups["S"].Value);
            }
            int height = (int)((float)width / aspect);

            ReflectiveNodeTechnique tech = new ReflectiveNodeTechnique(width, height, plane);

            if (match.Groups["R"].Success)
            {
                if (match.Groups["R"].Value == "l")
                {
                    tech.UseReflection = true;
                    tech.UseRefraction = false;
                }
                else
                {
                    tech.UseReflection = false;
                    tech.UseRefraction = true;
                }
            }
            BindTechnique(scene, node, match, tech);

            return(tech);
        }