private void DrawFov(IEye eye)
        {
            using var _ = DebugGroup(nameof(DrawFov));

            PrepareDepthDraw(_fovRenderTarget);

            if (eye.DrawFov)
            {
                // Calculate maximum distance for the projection based on screen size.
                var screenSizeCut = ScreenSize / EyeManager.PIXELSPERMETER;
                var maxDist       = (float)Math.Max(screenSizeCut.X, screenSizeCut.Y);

                // FOV is rendered twice.
                // Once with back face culling like regular lighting.
                // Then once with front face culling for the final FOV pass (so you see "into" walls).
                GL.CullFace(CullFaceMode.Back);

                DrawOcclusionDepth(eye.Position.Position, _fovRenderTarget.Size.X, maxDist, 0, out _fovProjection);

                GL.CullFace(CullFaceMode.Front);

                DrawOcclusionDepth(eye.Position.Position, _fovRenderTarget.Size.X, maxDist, 1, out _fovProjection);
            }

            FinalizeDepthDraw();
        }
 public void Cleanup(IEye eye)
 {
     eye.Rotation      = -LerpTo ?? Angle.Zero;
     LerpStartRotation = eye.Rotation;
     LerpTo            = null;
     Accumulator       = 0;
 }
Beispiel #3
0
        public TriangleScene(IEye eye, DisplayMode desctopDisplayMode)
            : base(eye, desctopDisplayMode)
        {
            var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText));
            var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText));
            shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, null, pixelShader);

            var vertexData = new[]
                {
                    new Vertex(-0.7f, -0.7f, Color4.Red),
                    new Vertex(0.0f, 0.7f, Color4.Yellow),
                    new Vertex(0.7f, -0.7f, Color4.Green)
                };

            vertexBuffer = Device.Create.Buffer(new BufferDescription
            {
                SizeInBytes = vertexData.Length * Vertex.SizeInBytes,
                Usage = Usage.Immutable,
                BindFlags = BindFlags.VertexBuffer
            }, new SubresourceData(vertexData));

            vertexLayout = Device.Create.VertexLayout(vertexShader, new[]
                {
                    new VertexLayoutElement(ExplicitFormat.R32G32B32A32_FLOAT, 0, 0),
                    new VertexLayoutElement(ExplicitFormat.R32G32B32A32_FLOAT, 0, 16)
                });
        }
Beispiel #4
0
 public MetaScene(IEye eye, DisplayMode desctopDisplayMode)
 {
     this.eye = eye;
     this.desctopDisplayMode = desctopDisplayMode;
     var swapChain = eye.Device.PrimarySwapChain;
     window = swapChain.Window;
     eye.NewFrame += NewFrame;
 }
Beispiel #5
0
 static IScene CreateScene(string sceneName, IEye eye)
 {
     switch (sceneName)
     {
         case "Earthlit Night": return new EarthlitNightScene(eye);
         default: throw new ArgumentOutOfRangeException("sceneName");
     }
 }
Beispiel #6
0
 protected Scene(IEye eye, DisplayMode desctopDisplayMode)
 {
     Eye = eye;
     Adapter = eye.Device.Adapter;
     Device = eye.Device;
     DesctopDisplayMode = desctopDisplayMode;
     ImmediateContext = Device.ImmediateContext;
     SwapChain = Device.PrimarySwapChain;
     Window = SwapChain.Window;
     Keyboard = Window.Input.Keyboard;
     Mouse = Window.Input.Mouse;
 }
        private void DrawFov(Box2 worldBounds, IEye eye)
        {
            var screenSizeCut = ScreenSize / EyeManager.PIXELSPERMETER;
            var maxDist       = (float)Math.Max(screenSizeCut.X, screenSizeCut.Y);

            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Lequal);
            GL.DepthMask(true);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, _fovRenderTarget.ObjectHandle.Handle);
            GL.ClearDepth(1);
            GL.ClearColor(maxDist, maxDist, maxDist, 1);
            GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit);

            GL.BindVertexArray(_occlusionVao.Handle);

            _fovCalculationProgram.Use();

            var lightMatrix = Matrix4.CreateTranslation(-eye.Position.X, -eye.Position.Y, 0);

            _fovCalculationProgram.SetUniform("lightMatrix", lightMatrix, false);

            var baseProj =
                Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(90), 1, maxDist / 1000,
                                                     maxDist * 1.1f);

            const int step = ShadowMapSize / 4;

            for (var i = 0; i < 4; i++)
            {
                var orientation = i switch
                {
                    0 => new Quaternion(-0.707f, 0, 0, 0.707f),
                    1 => new Quaternion(0.5f, -0.5f, -0.5f, -0.5f),
                    2 => new Quaternion(0, 0.707f, 0.707f, 0),
                    3 => new Quaternion(-0.5f, -0.5f, -0.5f, 0.5f),
                    _ => default
                };

                var rotMatrix = Matrix4.Rotate(orientation);
                var proj      = rotMatrix * baseProj;

                _fovCalculationProgram.SetUniform("projectionMatrix", proj, false);
                GL.Viewport(step * i, 0, step, 1);

                GL.DrawElements(BeginMode.TriangleStrip, _occlusionDataLength, DrawElementsType.UnsignedShort, 0);
            }

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.Disable(EnableCap.DepthTest);
        }
Beispiel #8
0
        public CloudRenderer(IEye eye, IMatrixProvider <Matrix4, Vector4> viewMatrix, IMatrixProvider <Matrix4, Vector4> projectionMatrix,
                             IAssetProvider resource)
        {
            _eye              = eye;
            _viewMatrix       = viewMatrix;
            _projectionMatrix = projectionMatrix;
            using var stream  = resource[AssetType.Texture, "minecraft:environment/clouds.png"].OpenRead();
            var cloudData = new Image(stream).Data;

            for (var y = 0; y < 256; y++)
            {
                for (var x = 0; x < 256; x++)
                {
                    var l = y << 10 | x << 2;
                    var r = cloudData[l];
                    var g = cloudData[l | 0b01];
Beispiel #9
0
        public MainWindow()
        {
            _resource = new VanillaResource();
            _eye      = new Eye
            {
                DepthFar = 1024F,
            };
            _viewTransformProvider       = _eye.GetViewTransformProvider();
            _projectionTransformProvider = _eye.GetPerspectiveTransformProvider();
            _eyeInput  = this.CreatePointerAxisInput(.5F, true).CreateSmoothAxisInput();
            _moveInput = this.CreateKeyAxisInput(Keys.D, Keys.Space, Keys.S, Keys.A, Keys.LeftShift, Keys.W, true).CreateScaledAxisInput(10F).CreateSmoothAxisInput();
            _world     = new EmptyWorld
            {
                ChunkProvider = (x, z) => new EmptyChunk {
                    X = x, Z = z, World = _world
                }
            };
            _world.FillFast(0, 0, 0, 256, 0, 256, "bedrock");
            _world.FillFast(0, 1, 0, 256, 10, 256, "iron_block");
            _world.FillFast(0, 11, 0, 256, 11, 256, "diamond_block");

            _world.Fill(15, 12, 14, 16, 13, 17, "gold_block");
            _world.Fill(3, 12, 3, 5, 13, 5, "gold_block");


            _playerObject = new() { OriginalAABB = new Box3d(-.5D, -.5D, -.5D, .5D, .5D, .5D), GravityScale = 1D, Position = (0D, 15D, 0) };
            _floorObject  = new BlockCollisionObject(_world);

            _boxRenderer = new(_viewTransformProvider, _projectionTransformProvider) { Color = Color4.Blue };

            /*_cameraMotivatorRenderer = new CameraMotivatorRenderer(_eye)
             * {
             *  RotationInput = _eyeInput,
             *  PositionInput = _moveInput,
             *  MovementSpeed = 1F,
             *  Type = CameraType.Fps,
             *  Controlable = true
             * };*/
            this.AddCompletedRenderer(new CloudRenderer(_eye, _viewTransformProvider, _projectionTransformProvider, _resource));
            this.AddCompletedRenderer(new WorldRenderer(_world, () => _atlases, _viewTransformProvider, _projectionTransformProvider)
            {
                Camera = _eye, AutoSetCenterChunk = true
            });
            this.AddRenderObject(_boxRenderer);
            PointerGrabbed = true;
        }
Beispiel #10
0
 private void DrawFov(Box2 worldBounds, IEye eye)
 {
     /*
      * GL.Enable(EnableCap.DepthTest);
      * GL.DepthFunc(DepthFunction.Lequal);
      * GL.DepthMask(true);
      *
      * GL.BindFramebuffer(FramebufferTarget.Framebuffer, _fovFbo.Handle);
      * GL.ClearDepth(1);
      * GL.Clear(ClearBufferMask.DepthBufferBit);
      *
      * GL.BindVertexArray(_occlusionVao.Handle);
      *
      * _fovCalculationProgram.Use();
      *
      * var lightMatrix = Matrix4.CreateTranslation(-eye.Position.X, -eye.Position.Y, 0);
      * _fovCalculationProgram.SetUniform("lightMatrix", lightMatrix, false);
      *
      * var baseProj = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(90), 1, 0.1f, 11);
      *
      * const int step = ShadowMapSize / 4;
      *
      * for (var i = 0; i < 4; i++)
      * {
      *  var up = new Vector3(0, 0, -1);
      *  var forward = i switch
      *  {
      *      0 => new Vector3(0, 1, 0),
      *      1 => new Vector3(1, 0, 0),
      *      2 => new Vector3(0, -1, 0),
      *      3 => new Vector3(-1, 0, 0)
      *  };
      *  var orientation = Quaternion.LookRotation(ref forward, ref up);
      *
      *  var proj = Matrix4.Rotate(orientation) * baseProj;
      *
      *  _fovCalculationProgram.SetUniform("projectionMatrix", proj, false);
      *  GL.Viewport(step * i, 0, step, 1);
      *
      *  GL.DrawElements(BeginMode.TriangleStrip, _occlusionDataLength, DrawElementsType.UnsignedShort, 0);
      * }
      *
      * GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
      * GL.Disable(EnableCap.DepthTest);
      */
 }
Beispiel #11
0
        public EarthlitNightScene(IEye eye)
        {
            this.eye = eye;
            device = eye.Device;
            swapChain = device.PrimarySwapChain;

            stars = new Stars(device, StarCount);

            var meshFactory = new MeshFactory(device, Handedness.Right, Winding.Clockwise);
            var earthMesh = meshFactory.CreateSphere(false, 1.0f, 36);
            earthVertexBuffer = earthMesh.Vertices.Buffer;
            earthIndexBuffer = earthMesh.Indices.Buffer;

            var formatInfo = eye.Adapters[0].GetSupportedFormats(FormatSupport.RenderTarget | FormatSupport.Texture2D | FormatSupport.TextureCube)
                .First(x => x.ColorBits == 24 && x.AlphaBits == 8 && x.ColorFormatType == FormatElementType.UNORM);
            starsProxyTexture = device.Create.Texture2D(new Texture2DDescription
            {
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                Usage = Usage.Default,
                Width = SkyboxSize,
                Height = SkyboxSize,
                ArraySize = 1,
                MipLevels = 1,
                FormatID = formatInfo.ID
            });

            skyboxTexture = device.Create.Texture2D(new Texture2DDescription
            {
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                Usage = Usage.Default,
                Width = SkyboxSize,
                Height = SkyboxSize,
                ArraySize = 6,
                MipLevels = TextureHelper.MipLevels(SkyboxSize, SkyboxSize, 1),
                FormatID = formatInfo.ID,
                MiscFlags = MiscFlags.TextureCube | MiscFlags.GenerateMips
            });

            var textureLoader = new TextureLoader(device);

            earthTexture = textureLoader.Load("../Textures/BasicTest.png");
        }
Beispiel #12
0
        public RenderToTextureScene(IEye eye, DisplayMode desctopDisplayMode)
            : base(eye, desctopDisplayMode)
        {
            var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText));
            var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText));
            shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, null, pixelShader);

            var meshFactory = new MeshFactory(Device, Handedness.Right, Winding.Clockwise);
            cubeMesh = meshFactory.CreateCube(2.0f);

            vertexLayout = Device.Create.VertexLayout(vertexShader, new[]
            {
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 0),
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 12),
                new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 24)
            });

            transformBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = Transform.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            cameraVertexBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = CameraVertex.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            lightBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = Light.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });

            var renderTargetFormats = Eye.Adapters[0]
                .GetSupportedFormats(FormatSupport.Texture2D | FormatSupport.RenderTarget | FormatSupport.MipAutogen)
                .Where(fi => fi.ColorBits <= 24);
            if (!renderTargetFormats.Any()) throw new NotSupportedException("Render target textures are not supported.");
            var renderTargetFormatInfo = renderTargetFormats
                .OrderByDescending(fi => fi.ColorBits)
                .ThenBy(fi => fi.TotalBits)
                .First();

            var renderTargetTexture = Device.Create.Texture2D(new Texture2DDescription
            {
                Width = TargetSize,
                Height = TargetSize,
                MipLevels = TextureHelper.MipLevels(TargetSize, TargetSize, 1),
                ArraySize = 1,
                FormatID = renderTargetFormatInfo.ID,
                Sampling = Sampling.NoMultisampling,
                Usage = Usage.Default,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                MiscFlags = MiscFlags.GenerateMips,
                ExtraFlags = ExtraFlags.None
            });
            targetRtv = renderTargetTexture.ViewAsRenderTarget(renderTargetFormatInfo.ID, 0);
            targetSrv = renderTargetTexture.ViewAsShaderResource(renderTargetFormatInfo.ID, 0, renderTargetTexture.MipLevels);

            var dsFormats = Eye.Adapters[0].GetSupportedFormats(FormatSupport.Texture2D | FormatSupport.DepthStencil);
            var dsFormatInfo = dsFormats
                .OrderBy(fi => (fi.ColorBits == 24 && fi.AlphaBits == 8) ? 0 : 1)
                .ThenByDescending(fi => fi.ColorBits)
                .ThenBy(fi => fi.TotalBits)
                .First();

            var depthStencilTexture = Device.Create.Texture2D(new Texture2DDescription
            {
                Width = TargetSize,
                Height = TargetSize,
                MipLevels = 1,
                ArraySize = 1,
                FormatID = dsFormatInfo.ID,
                Sampling = Sampling.NoMultisampling,
                Usage = Usage.Default,
                BindFlags = BindFlags.DepthStencil,
                MiscFlags = MiscFlags.None,
                ExtraFlags = ExtraFlags.None
            });
            targetDsv = depthStencilTexture.ViewAsDepthStencil(dsFormatInfo.ID, DepthStencilViewFlags.None, 0);

            var textureLoader = new TextureLoader(Device);

            var diffuseTexture = textureLoader.Load("../Textures/DiffuseTest.png");
            diffuseView = diffuseTexture.ViewAsShaderResource(diffuseTexture.FormatID, 0, diffuseTexture.MipLevels);

            samplerState = Device.Create.SamplerState(SamplerDescription.Anisotropic);
            depthStencilState = Device.Create.DepthStencilState(DepthStencilDescription.Enabled);
        }
 public PerspectiveTransformProvider(IEye eye)
 {
     Eye = eye;
 }
Beispiel #14
0
 public ClearScreenScene(IEye eye, DisplayMode desctopDisplayMode)
     : base(eye, desctopDisplayMode)
 {
 }
        private void DrawLightsAndFov(Box2 worldBounds, IEye eye)
        {
            if (!_lightManager.Enabled)
            {
                return;
            }

            var map = eye.Position.MapId;

            var(lights, expandedBounds) = GetLightsToRender(map, worldBounds);

            UpdateOcclusionGeometry(map, expandedBounds, eye.Position.Position);

            DrawFov(eye);

            var shadowMatrices = new Matrix4[lights.Count];

            using (DebugGroup("Draw shadow depth"))
            {
                PrepareDepthDraw(_shadowRenderTarget);
                GL.CullFace(CullFaceMode.Back);

                if (_lightManager.DrawShadows)
                {
                    for (var i = 0; i < lights.Count; i++)
                    {
                        var(light, lightPos) = lights[i];

                        DrawOcclusionDepth(lightPos, ShadowMapSize, light.Radius, i, out shadowMatrices[i]);
                    }
                }

                FinalizeDepthDraw();
            }

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, _lightRenderTarget.ObjectHandle.Handle);
            GLClearColor(Color.FromSrgb(AmbientLightColor));
            GL.Clear(ClearBufferMask.ColorBufferBit);

            var(lightW, lightH) = GetLightMapSize();
            GL.Viewport(0, 0, lightW, lightH);

            var lightShader = _loadedShaders[_lightShaderHandle].Program;

            lightShader.Use();

            SetTexture(TextureUnit.Texture1, ShadowTexture);
            lightShader.SetUniformTextureMaybe("shadowMap", TextureUnit.Texture1);

            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.One);

            var     lastRange = float.NaN;
            var     lastPower = float.NaN;
            var     lastColor = new Color(float.NaN, float.NaN, float.NaN, float.NaN);
            Texture lastMask  = null;

            for (var i = 0; i < lights.Count; i++)
            {
                var(component, lightPos) = lights[i];
                var transform = component.Owner.Transform;

                var circle = new Circle(lightPos, component.Radius);

                if (!circle.Intersects(worldBounds))
                {
                    continue;
                }

                Texture mask     = null;
                var     rotation = Angle.Zero;
                if (component.Mask != null)
                {
                    mask     = component.Mask;
                    rotation = component.Rotation;

                    if (component.MaskAutoRotate)
                    {
                        rotation += transform.WorldRotation;
                    }
                }

                var maskTexture = mask ?? Texture.White;
                if (lastMask != maskTexture)
                {
                    SetTexture(TextureUnit.Texture0, maskTexture);
                    lastMask = maskTexture;
                    lightShader.SetUniformTextureMaybe(UniIMainTexture, TextureUnit.Texture0);
                }

                if (!FloatMath.CloseTo(lastRange, component.Radius))
                {
                    lastRange = component.Radius;
                    lightShader.SetUniformMaybe("lightRange", lastRange);
                }

                if (!FloatMath.CloseTo(lastPower, component.Energy))
                {
                    lastPower = component.Energy;
                    lightShader.SetUniformMaybe("lightPower", lastPower);
                }

                if (lastColor != component.Color)
                {
                    lastColor = component.Color;
                    lightShader.SetUniformMaybe("lightColor", lastColor);
                }

                lightShader.SetUniformMaybe("lightCenter", lightPos);
                lightShader.SetUniformMaybe("lightIndex", (i + 0.5f) / ShadowTexture.Height);
                lightShader.SetUniformMaybe("shadowMatrix", shadowMatrices[i], false);

                var offset = new Vector2(component.Radius, component.Radius);

                Matrix3 matrix;
                if (mask == null)
                {
                    matrix = Matrix3.Identity;
                }
                else
                {
                    // Only apply rotation if a mask is said, because else it doesn't matter.
                    matrix = Matrix3.CreateRotation(rotation);
                }

                (matrix.R0C2, matrix.R1C2) = lightPos;

                _drawQuad(-offset, offset, matrix, lightShader);
            }

            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            ApplyLightingFovToBuffer(eye);

            BlurOntoWalls(eye);

            MergeWallLayer();

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.Viewport(0, 0, ScreenSize.X, ScreenSize.Y);

            _lightingReady = true;
        }
Beispiel #16
0
        public CubeScene(IEye eye, DisplayMode desctopDisplayMode)
            : base(eye, desctopDisplayMode)
        {
            var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText));
            var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText));
            shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, null, pixelShader);

            var meshFactory = new MeshFactory(Device, Handedness.Right, Winding.Clockwise);
            cubeMesh = meshFactory.CreateCube(2.0f);

            vertexLayout = Device.Create.VertexLayout(vertexShader, new[]
            {
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 0),
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 12),
                new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 24)
            });

            transformBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = Transform.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            cameraVertexBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = CameraVertex.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            cameraPixelBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = CameraPixel.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });
            lightBuffer = Device.Create.Buffer(
                new BufferDescription { SizeInBytes = Light.SizeInBytes, BindFlags = BindFlags.UniformBuffer, Usage = Usage.Dynamic });

            var textureLoader = new TextureLoader(Device);

            var diffuseTexture = textureLoader.Load("../Textures/DiffuseTest.png");
            diffuseView = diffuseTexture.ViewAsShaderResource(diffuseTexture.FormatID, 0, diffuseTexture.MipLevels);

            var specularTexture = textureLoader.Load("../Textures/SpecularTest.png");
            specualrView = specularTexture.ViewAsShaderResource(specularTexture.FormatID, 0, specularTexture.MipLevels);

            samplerState = Device.Create.SamplerState(SamplerDescription.Default);
            depthStencilState = Device.Create.DepthStencilState(DepthStencilDescription.Enabled);
        }
Beispiel #17
0
        public ColorfulSpaceScene(IEye eye, DisplayMode desctopDisplayMode)
            : base(eye, desctopDisplayMode)
        {
            var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText));
            var geometryShader = Device.Create.GeometryShader(ShaderParser.Parse(GeometryShaderText));
            var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText));
            shaderCombination = Device.Create.ShaderCombination(vertexShader, null, null, geometryShader, pixelShader);

            var vertexData = new Vertex[ParticleCount];
            for (int i = 0; i < vertexData.Length; i++)
                vertexData[i] = new Vertex((float)i / ParticleCount);

            vertexBuffer = Device.Create.Buffer(new BufferDescription
            {
                Usage = Usage.Immutable,
                SizeInBytes = ParticleCount * Vertex.SizeInBytes,
                BindFlags = BindFlags.VertexBuffer,
                ExtraFlags = ExtraFlags.Points
            }, new SubresourceData(vertexData));

            vertexLayout = Device.Create.VertexLayout(vertexShader, new[]
            {
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 0),
                new VertexLayoutElement(ExplicitFormat.R32G32B32_FLOAT, 0, 12)
            });

            timeBuffer = Device.Create.Buffer(new BufferDescription
            {
                Usage = Usage.Dynamic,
                SizeInBytes = Time.SizeInBytes,
                BindFlags = BindFlags.UniformBuffer
            });

            cameraBuffer = Device.Create.Buffer(new BufferDescription
            {
                Usage = Usage.Dynamic,
                SizeInBytes = Camera.SizeInBytes,
                BindFlags = BindFlags.UniformBuffer
            });

            blendState = Device.Create.BlendState(BlendDescription.Additive);
        }
Beispiel #18
0
 public IdleState(IEye gameObject)
 {
 }
Beispiel #19
0
 public CurrentEyeChangedEvent(IEye?oldEye, IEye newEye)
 {
     Old = oldEye;
     New = newEye;
 }
        public CurveTesselationScene(IEye eye, DisplayMode desctopDisplayMode)
            : base(eye, desctopDisplayMode)
        {
            var vertexShader = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText));
            var hullShader = Device.Create.HullShader(ShaderParser.Parse(HullShaderText));
            var domainShader = Device.Create.DomainShader(ShaderParser.Parse(DomainShaderTet));
            var pixelShader = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText));
            shaderCombination = Device.Create.ShaderCombination(vertexShader, hullShader, domainShader, null, pixelShader);

            vertexBuffer = Device.Create.Buffer(new BufferDescription
            {
                SizeInBytes = 12 * Vertex.SizeInBytes,
                Usage = Usage.Immutable,
                BindFlags = BindFlags.VertexBuffer,
            }, new SubresourceData(new[]
            {
                new Vertex(-1f, 1/3f), new Vertex(4f, 1f), new Vertex(-4f, 1f), new Vertex(1f, 1/3f),
                new Vertex(-1f, -1/3f), new Vertex(4f, 1/3f), new Vertex(-4f, 1/3f), new Vertex(1f, -1/3f),
                new Vertex(-1f, -1f), new Vertex(4f, -1/3f), new Vertex(-4f, -1/3f), new Vertex(1f, -1f)
            }));

            vertexLayout = Device.Create.VertexLayout(vertexShader, new[]
            {
                new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 0)
            });

            tessFactorBuffer = Device.Create.Buffer(new BufferDescription
            {
                SizeInBytes = TessFactor.SizeInBytes,
                Usage = Usage.Dynamic,
                BindFlags = BindFlags.UniformBuffer
            });
        }
Beispiel #21
0
 public static IPerspectiveTransformProvider GetPerspectiveTransformProvider(this IEye eye)
 {
     return(new PerspectiveTransformProvider(eye));
 }
Beispiel #22
0
        public FullscreenQuadScene(IEye eye, DisplayMode desctopDisplayMode)
            : base(eye, desctopDisplayMode)
        {
            var vs = Device.Create.VertexShader(ShaderParser.Parse(VertexShaderText));
            var ps = Device.Create.PixelShader(ShaderParser.Parse(PixelShaderText));
            shaders = Device.Create.ShaderCombination(vs, null, null, null, ps);

            vertexLayout = Device.Create.VertexLayout(vs, new[]
            {
                new VertexLayoutElement(ExplicitFormat.R32G32_FLOAT, 0, 0),
                new VertexLayoutElement(ExplicitFormat.R32G32B32A32_FLOAT, 0, 8)
            });

            vertexBuffer = Device.Create.Buffer(new BufferDescription
            {
                BindFlags = BindFlags.VertexBuffer,
                Usage = Usage.Immutable,
                SizeInBytes = 4 * Vertex.SizeInBytes
            }, new SubresourceData(new[]
            {
                new Vertex(-1, -1, -1, -1,  1,  1),
                new Vertex( 1, -1,  1, -1,  1,  1),
                new Vertex( 1,  1,  1,  1,  0,  0),
                new Vertex(-1,  1, -1,  1,  0,  0)
            }));

            indexBuffer = Device.Create.Buffer(new BufferDescription
            {
                BindFlags = BindFlags.IndexBuffer,
                Usage = Usage.Immutable,
                ExtraFlags = ExtraFlags.SixteenBitIndices,
                SizeInBytes = 6 * sizeof(ushort)
            }, new SubresourceData(new ushort[]
            {
                0, 1, 2,
                0, 2, 3
            }));
        }
Beispiel #23
0
 public AllertState(IEye eye)
 {
     this.eye = eye;
 }
        private void DrawLightsAndFov(Box2 worldBounds, IEye eye)
        {
            if (!_lightManager.Enabled)
            {
                return;
            }

            UpdateOcclusionGeometry(eye.Position.MapId);

            DrawFov(worldBounds, eye);

            var map = _eyeManager.CurrentMap;

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, LightRenderTarget.ObjectHandle.Handle);
            var converted = Color.FromSrgb(new Color(0.1f, 0.1f, 0.1f));

            GL.ClearColor(converted.R, converted.G, converted.B, 1);
            GL.Clear(ClearBufferMask.ColorBufferBit);

            var(lightW, lightH) = GetLightMapSize();
            GL.Viewport(0, 0, lightW, lightH);

            _lightShader.Use();

            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.One);

            var     lastRange = float.NaN;
            var     lastPower = float.NaN;
            var     lastColor = new Color(float.NaN, float.NaN, float.NaN, float.NaN);
            Texture lastMask  = null;

            foreach (var component in _componentManager.GetAllComponents <PointLightComponent>())
            {
                if (!component.Enabled || component.Owner.Transform.MapID != map)
                {
                    continue;
                }

                var transform = component.Owner.Transform;
                var lightPos  = transform.WorldMatrix.Transform(component.Offset);

                var lightBounds = Box2.CenteredAround(lightPos, Vector2.One * component.Radius * 2);

                if (!lightBounds.Intersects(worldBounds))
                {
                    continue;
                }

                Texture mask     = null;
                var     rotation = Angle.Zero;
                if (component.Mask != null)
                {
                    mask     = component.Mask;
                    rotation = component.Rotation;

                    if (component.MaskAutoRotate)
                    {
                        rotation += transform.WorldRotation;
                    }
                }

                var maskTexture = mask ?? Texture.White;
                if (lastMask != maskTexture)
                {
                    var maskHandle = _loadedTextures[((ClydeTexture)maskTexture).TextureId].OpenGLObject;
                    GL.ActiveTexture(TextureUnit.Texture0);
                    GL.BindTexture(TextureTarget.Texture2D, maskHandle.Handle);
                    lastMask = maskTexture;
                    _lightShader.SetUniformTexture("lightMask", TextureUnit.Texture0);
                }

                if (!FloatMath.CloseTo(lastRange, component.Radius))
                {
                    lastRange = component.Radius;
                    _lightShader.SetUniform("lightRange", lastRange);
                }

                if (!FloatMath.CloseTo(lastPower, component.Energy))
                {
                    lastPower = component.Energy;
                    _lightShader.SetUniform("lightPower", lastPower);
                }

                if (lastColor != component.Color)
                {
                    lastColor = component.Color;
                    _lightShader.SetUniform("lightColor", lastColor);
                }

                _lightShader.SetUniform("lightCenter", lightPos);

                var offset = new Vector2(component.Radius, component.Radius);

                Matrix3 matrix;
                if (mask == null)
                {
                    matrix = Matrix3.Identity;
                }
                else
                {
                    // Only apply rotation if a mask is said, because else it doesn't matter.
                    matrix = Matrix3.CreateRotation(rotation);
                }

                (matrix.R0C2, matrix.R1C2) = lightPos;

                _drawQuad(-offset, offset, ref matrix, _lightShader);
            }

            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.Viewport(0, 0, ScreenSize.X, ScreenSize.Y);

            _lightingReady = true;
        }