Ejemplo n.º 1
0
        protected override void OnDrawToSwapchainImage(VKImage image)
        {
            base.OnDrawToSwapchainImage(image);

            CommandBuffer[image].Submit(true);

            MeshRenderer.Draw(image, Tick);

            ParticleRenderer.Draw(image, Tick);

            TextRenderer.Draw(image, Tick);
        }
Ejemplo n.º 2
0
        private void DrawLightMap(GraphicsDevice device, Scene scene, Camera camera)
        {
            int    i                   = 0;
            int    l                   = 0;
            float  distance            = 0;
            Matrix viewProjection      = camera.view * camera.projection;
            Matrix invViewProjection   = Matrix.Invert(viewProjection);
            Matrix worldViewProjection = Matrix.Identity;
            Light  light               = null;

            _lightingFX.Parameters["NormalTexture"].SetValue(_normalRT);
            _lightingFX.Parameters["DepthTexture"].SetValue(_depthRT);
            _lightingFX.Parameters["InvViewProjection"].SetValue(invViewProjection);
            _lightingFX.Parameters["Viewport"].SetValue(_viewport);

            device.SetRenderTarget(_lightRT);
            device.Clear(Color.Black);
            device.BlendState        = BlendState.Additive;
            device.DepthStencilState = DepthStencilState.None;

            for (i = 0, l = scene.lights.Count; i < l; i++)
            {
                light = scene.lights[i];

                if (light.Backing != LightRenderMode.RealTime)
                {
                    worldViewProjection = (Matrix.CreateScale(light.Range) * light.Transform.world) * viewProjection;
                    _lightingFX.Parameters["WorldViewProjection"].SetValue(worldViewProjection);
                    _lightingFX.Parameters["LightColor"].SetValue(light.color);
                    _lightingFX.Parameters["LightAttenuation"].SetValue(light.FallOf);
                    _lightingFX.Parameters["LightPosition"].SetValue(light.Transform.Position);
                    _lightingFX.Parameters["LightRange"].SetValue(light.Range);
                    _lightingFX.Parameters["LightIntensity"].SetValue(light.Intensity);

                    distance = Vector3.Distance(camera.Transform.Position, light.Transform.Position);

                    if (distance < light.Range)
                    {
                        device.RasterizerState = RasterizerState.CullClockwise;
                    }

                    _lightingFX.CurrentTechnique.Passes[0].Apply();
                    _lightMesh.Draw(device);

                    device.RasterizerState = RasterizerState.CullCounterClockwise;
                }
            }

            device.BlendState        = BlendState.Opaque;
            device.DepthStencilState = DepthStencilState.Default;
            device.SetRenderTarget(null);
        }
Ejemplo n.º 3
0
        private void Glview_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            if (glview == null)
            {
                return;
            }

            ViewContext.VerifyContext(glview);
            ViewContext.Context.MakeCurrent(glview.WindowInfo);

            GL.Viewport(0, 0, glview.Width, glview.Height);
            GL.ClearColor(0.1f, 0.1f, 0.1f, 1);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Clear(ClearBufferMask.DepthBufferBit);

            camera.Aspect = (float)glview.Width / (float)glview.Height;

            Matrix4 proj;

            if (previewCameraMode == PreviewCameraMode.Orthographic)
            {
                proj = camera.Orthographic;
            }
            else
            {
                proj = camera.Perspective;
            }

            CheckMaterials();

            if (previewType == PreviewGeometryType.Cube)
            {
                if (cube != null)
                {
                    cube.CameraPosition = camera.EyePosition;
                    cube.IrradianceMap  = HdriManager.Irradiance;
                    cube.PrefilterMap   = HdriManager.Prefiltered;
                    cube.Projection     = proj;
                    cube.Model          = previewObject.WorldMatrix;
                    cube.View           = camera.View;
                    cube.LightColor     = lightColor;
                    cube.LightPosition  = lightPosition;
                    cube.Draw();
                }
            }
            else if (previewType == PreviewGeometryType.Sphere)
            {
                if (sphere != null)
                {
                    sphere.CameraPosition = camera.EyePosition;
                    sphere.IrradianceMap  = HdriManager.Irradiance;
                    sphere.PrefilterMap   = HdriManager.Prefiltered;
                    sphere.Projection     = proj;
                    sphere.Model          = previewObject.WorldMatrix;
                    sphere.View           = camera.View;
                    sphere.LightColor     = lightColor;
                    sphere.LightPosition  = lightPosition;
                    sphere.Draw();
                }
            }
            else if (previewType == PreviewGeometryType.Cylinder)
            {
                if (cylinder != null)
                {
                    cylinder.CameraPosition = camera.EyePosition;
                    cylinder.IrradianceMap  = HdriManager.Irradiance;
                    cylinder.PrefilterMap   = HdriManager.Prefiltered;
                    cylinder.Projection     = proj;
                    cylinder.Model          = previewObject.WorldMatrix;
                    cylinder.View           = camera.View;
                    cylinder.LightColor     = lightColor;
                    cylinder.LightPosition  = lightPosition;
                    cylinder.Draw();
                }
            }
            else if (previewType == PreviewGeometryType.Plane)
            {
                if (plane != null)
                {
                    plane.CameraPosition = camera.EyePosition;
                    plane.IrradianceMap  = HdriManager.Irradiance;
                    plane.PrefilterMap   = HdriManager.Prefiltered;
                    plane.Projection     = proj;
                    plane.Model          = previewObject.WorldMatrix;
                    plane.View           = camera.View;
                    plane.LightColor     = lightColor;
                    plane.LightPosition  = lightPosition;
                    plane.Draw();
                }
            }
            else if (previewType == PreviewGeometryType.RoundedCube)
            {
                if (cubeRounded != null)
                {
                    cubeRounded.CameraPosition = camera.EyePosition;
                    cubeRounded.IrradianceMap  = HdriManager.Irradiance;
                    cubeRounded.PrefilterMap   = HdriManager.Prefiltered;
                    cubeRounded.Projection     = proj;
                    cubeRounded.Model          = previewObject.WorldMatrix;
                    cubeRounded.View           = camera.View;
                    cubeRounded.LightColor     = lightColor;
                    cubeRounded.LightPosition  = lightPosition;
                    cubeRounded.Draw();
                }
            }

            glview.SwapBuffers();
        }
Ejemplo n.º 4
0
        private void Glview_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            if (glview == null)
            {
                return;
            }

            ViewContext.VerifyContext(glview);
            ViewContext.Context.MakeCurrent(glview.WindowInfo);

            GL.Viewport(0, 0, glview.Width, glview.Height);
            GL.ClearColor(0.1f, 0.1f, 0.1f, 1);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Clear(ClearBufferMask.DepthBufferBit);

            float wratio = (float)glview.Width / (float)glview.Height;

            if (previewCameraMode == PreviewCameraMode.Orthographic)
            {
                proj = Matrix4.CreateOrthographic(Math.Max(1, cameraTranslation.Z), Math.Max(1, cameraTranslation.Z / wratio), 0.03f, 1000f);
            }
            else
            {
                proj = Matrix4.CreatePerspectiveFieldOfView(40 * (float)(Math.PI / 180.0f), (float)glview.Width / (float)glview.Height, 0.03f, 1000f);
            }

            Matrix4 view = Matrix4.CreateFromQuaternion(rotation) * Matrix4.CreateTranslation(-cameraTranslation);
            Vector3 pos  = Vector3.Normalize((view * new Vector4(0, 0, 1, 1)).Xyz) * cameraTranslation.Z;

            CheckMaterials();

            if (previewType == PreviewGeometryType.Cube)
            {
                if (cube != null)
                {
                    cube.CameraPosition = pos;
                    cube.IrradianceMap  = irradiance;
                    cube.PrefilterMap   = prefiltered;
                    cube.Projection     = proj;
                    cube.Model          = TK.Matrix4.CreateTranslation(objectTranslation);
                    cube.View           = view;
                    cube.LightColor     = lightColor;
                    cube.LightPosition  = lightPosition;
                    cube.Draw();
                }
            }
            else if (previewType == PreviewGeometryType.Sphere)
            {
                if (sphere != null)
                {
                    sphere.CameraPosition = pos;
                    sphere.IrradianceMap  = irradiance;
                    sphere.PrefilterMap   = prefiltered;
                    sphere.Projection     = proj;
                    sphere.Model          = TK.Matrix4.CreateTranslation(objectTranslation);
                    sphere.View           = view;
                    sphere.LightColor     = lightColor;
                    sphere.LightPosition  = lightPosition;
                    sphere.Draw();
                }
            }
            else if (previewType == PreviewGeometryType.Cylinder)
            {
                if (cylinder != null)
                {
                    cylinder.CameraPosition = pos;
                    cylinder.IrradianceMap  = irradiance;
                    cylinder.PrefilterMap   = prefiltered;
                    cylinder.Projection     = proj;
                    cylinder.Model          = TK.Matrix4.CreateTranslation(objectTranslation);
                    cylinder.View           = view;
                    cylinder.LightColor     = lightColor;
                    cylinder.LightPosition  = lightPosition;
                    cylinder.Draw();
                }
            }
            else if (previewType == PreviewGeometryType.Plane)
            {
                if (plane != null)
                {
                    plane.CameraPosition = pos;
                    plane.IrradianceMap  = irradiance;
                    plane.PrefilterMap   = prefiltered;
                    plane.Projection     = proj;
                    plane.Model          = TK.Matrix4.CreateTranslation(objectTranslation);
                    plane.View           = view;
                    plane.LightColor     = lightColor;
                    plane.LightPosition  = lightPosition;
                    plane.Draw();
                }
            }
            else if (previewType == PreviewGeometryType.RoundedCube)
            {
                if (cubeRounded != null)
                {
                    cubeRounded.CameraPosition = pos;
                    cubeRounded.IrradianceMap  = irradiance;
                    cubeRounded.PrefilterMap   = prefiltered;
                    cubeRounded.Projection     = proj;
                    cubeRounded.Model          = TK.Matrix4.CreateTranslation(objectTranslation);
                    cubeRounded.View           = view;
                    cubeRounded.LightColor     = lightColor;
                    cubeRounded.LightPosition  = lightPosition;
                    cubeRounded.Draw();
                }
            }

            glview.SwapBuffers();
        }