Example #1
0
    private void RenderDepthMap()
    {
        GraphicsDevice device = GraphicsDevice.Instance;

        device.SetBlendState(NoBlend);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOn);
        device.SetVertexLayout(VertexLayout);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader0);

        device.SetPrimitiveTopology(GraphicsModel.Topology);
        device.SetVertexBuffer(GraphicsModel.VertexPositions, 0);
        device.SetVertexBuffer(GraphicsModel.VertexNormals, 1);
        device.SetIndexBuffer(GraphicsModel.VertexIndices);

        var world            = this.Owner.Get <TransformComponent>().Matrix;
        var viewing_light    = Entity.Find("light").Get <TransformComponent>().Matrix.Inverse;
        var projection_light = Entity.Find("projector_light").Get <ProjectorComponent>().ProjectionMatrix;

        VertexShader.SetConstantBuffer(world * viewing_light * projection_light, 0);
        VertexShader.SetConstantBuffer(world * viewing_light * projection_light, 1);
        PixelShader0.SetConstantBuffer(world, 0);
        PixelShader0.SetConstantBuffer(Color, 1);

        device.DrawIndexed(GraphicsModel.VertexIndices.Count);
    }
Example #2
0
    void Render()
    {
        GraphicsDevice device = GraphicsDevice.Instance;

        device.SetBlendState(NoBlend);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOn);
        device.SetVertexLayout(VertexLayout);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);

        device.SetPrimitiveTopology(GraphicsModel.Topology);
        device.SetVertexBuffer(GraphicsModel.VertexPositions, 0);
        device.SetVertexBuffer(GraphicsModel.VertexNormals, 1);
        device.SetVertexBuffer(GraphicsModel.VertexTextureCoords, 2);

        var world            = this.Owner.Get <TransformComponent>().Matrix;
        var viewing          = Entity.Find("camera").Get <CameraComponent>().ViewingMatrix;
        var projection       = Entity.Find("projector").Get <ProjectorComponent>().ProjectionMatrix;
        var viewing_light    = Entity.Find("light").Get <TransformComponent>().Matrix.Inverse;
        var projection_light = Entity.Find("projector_light").Get <ProjectorComponent>().ProjectionMatrix;
        var light_direction  = -Entity.Find("light").Get <TransformComponent>().Forward;

        VertexShader.SetConstantBuffer(world * viewing * projection, 0);
        VertexShader.SetConstantBuffer(world * viewing_light * projection_light, 1);
        PixelShader.SetConstantBuffer(world, 0);
        PixelShader.SetConstantBuffer(new Vector4(light_direction, 0), 2);
        PixelShader.SetTexture(GraphicsModel.Texture, 0);
        PixelShader.SetTexture(Program.DepthMap, 1);

        device.Draw(4);
    }
Example #3
0
    private void TranslucentRender()
    {
        GraphicsDeviceContext device = GraphicsDeviceContext.Instance;

        device.SetBlendState(Addition);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOnWriteOff);
        device.SetVertexBuffer(VertexPositionsBuffer, 0);
        device.SetVertexBuffer(VertexTexcoordsBuffer, 1);
        device.SetIndexBuffer(IndexBuffer);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);

        PixelShader.SetSamplerState(Wrap, 0);
        PixelShader.SetTexture(Texture, 0);

        if (this.Power > 0.9f)
        {
            var physics   = this.Owner.Get <PhysicsComponent>();
            var transform = this.Owner.Get <TransformComponent>();
            var angular   = new Vector4(physics.AngularVelocity, 0) * transform.Matrix.Inverse;

            {
                var       offsetPosition = this.OffsetPosition;
                Matrix4x3 adjustment     = new Matrix4x3();
                adjustment.Identity();
                adjustment.Translate(offsetPosition);
                adjustment.RotateX(clamp((-angular.X * 2 + angular.Z * 0.5f) * 5, -0.2f, 0.2f));
                adjustment.Scale(normal(1.7f, 0.1f), normal(1.7f, 0.1f), normal(3.8f, 0.1f) * (this.Power - 0.9f) / 0.1f);

                VertexShader.SetConstantBuffer(adjustment * WVPMatrix, 0);
                device.DrawIndexed(IndexBuffer.Count);
            }

            if (this.OffsetPosition.X != 0)
            {
                var offsetPosition = this.OffsetPosition;
                offsetPosition.X *= -1;

                Matrix4x3 adjustment = new Matrix4x3();
                adjustment.Identity();
                adjustment.Translate(offsetPosition + new Vector3(0, 0, 0.5f));
                adjustment.RotateX(clamp((-angular.X * 2 - angular.Z * 0.5f) * 5, -0.2f, 0.2f));
                adjustment.Scale(normal(1.7f, 0.1f), normal(1.7f, 0.1f), normal(3.8f, 0.1f) * (this.Power - 0.9f) / 0.1f);

                VertexShader.SetConstantBuffer(adjustment * WVPMatrix, 0);
                device.DrawIndexed(IndexBuffer.Count);
            }
        }
    }
Example #4
0
    protected override void ReceiveMessage(object message, object argument)
    {
        base.ReceiveMessage(message, argument);

        switch (message as string)
        {
        case RenderMessage:
        {
            Matrix4x4 world      = new Matrix4x4(this.Owner.Get <TransformComponent>().Matrix);
            Matrix4x4 viewing    = new Matrix4x4(Entity.Find("camera").Get <CameraComponent>().ViewingMatrix);
            Matrix4x4 projection = Entity.Find("projector").Get <ProjectorComponent>().ProjectionMatrix;

            GraphicsDevice device = GraphicsDevice.Instance;
            device.SetBlendState(NoBlend);
            device.SetRasterizerState(CullingOn);
            device.SetDepthStencilState(ZTestOn);
            device.SetVertexLayout(VertexLayout);
            device.SetPrimitiveTopology(GraphicsModel.Topology);
            device.SetVertexShader(VertexShader);
            device.SetPixelShader(PixelShader);

            device.SetVertexBuffer(GraphicsModel.VertexPositions, 0);
            device.SetIndexBuffer(GraphicsModel.VertexIndices);

            PixelShader.SetSamplerState(Wrap, 0);
            VertexShader.SetConstantBuffer(world * viewing * projection, 0);

            device.DrawIndexed(GraphicsModel.VertexIndices.Count);
        }
        break;

        default:
            break;
        }
    }
    private void TranslucentRender()
    {
        GraphicsDeviceContext device = GraphicsDeviceContext.Instance;

        device.SetBlendState(Addition);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOnWriteOff);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);

        device.SetVertexBuffer(VertexPositions, 0);
        device.SetVertexBuffer(VertexTextureCoords, 1);

        var world  = new Matrix4x3().Identity();
        var camera = Entity.Find("camera").Get <TransformComponent>();
        var time   = this.Owner.Get <LimitedLifeTimeComponent>().CountTime;
        var scale  = sin(time * PI) * 6;
        var alpha  = sin(time * PI) * 0.4f;

        world.Translate(Transform.Position);
        world.RotateY(atan2(camera.Forward.X, camera.Forward.Z));
        world.Scale(0.5f * scale, scale, 1);
        VertexShader.SetConstantBuffer(world * ViewingMatrix * ProjectionMatrix, 0);
        PixelShader.SetConstantBuffer(new Color(alpha, alpha, alpha), 0);

        PixelShader.SetSamplerState(Wrap, 0);
        PixelShader.SetTexture(Texture, 0);

        device.Draw(4);
    }
Example #6
0
    private void Render()
    {
        GraphicsDevice device = GraphicsDevice.Instance;

        device.SetBlendState(NoBlend);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOn);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);

        PixelShader.SetSamplerState(Wrap, 0);
        PixelShader.SetTexture(GraphicsModel.Texture, 0);

        {
            VertexShader.SetConstantBuffer(WVPMatrix, 0);
            PixelShader.SetConstantBuffer(WorldMatrix, 0);
            PixelShader.SetConstantBuffer(new Vector4(Entity.Find("light").Get <TransformComponent>().Forward, 0), 1);

            device.SetVertexBuffer(GraphicsModel.VertexPositions, 0);
            device.SetVertexBuffer(GraphicsModel.VertexNormals, 1);
            device.SetVertexBuffer(GraphicsModel.VertexTextureCoords, 2);
            device.SetIndexBuffer(GraphicsModel.VertexIndices);
            device.DrawIndexed(GraphicsModel.VertexIndices.Count);
        }
    }
Example #7
0
    void Render()
    {
        //viewing.Invert();
        //viewing.Position = new Vector3(0, 0, 0);
        //viewing.Invert();

        GraphicsDevice device = GraphicsDevice.Instance;

        device.SetBlendState(NoBlend);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOff);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);

        device.SetVertexBuffer(VertexBuffer, 0);
        device.SetIndexBuffer(IndexBuffer);

        PixelShader.SetSamplerState(Wrap, 0);
        PixelShader.SetTextureArray(Texture, 0);
        VertexShader.SetConstantBuffer(WVPMatrix, 0);

        device.DrawIndexed(IndexBuffer.Count);
    }
    private void Render()
    {
        VertexShader.SetConstantBuffer(ViewingMatrix * ProjectionMatrix, 0);
        VertexShader.SetConstantBuffer(new Vector4[] { new Vector4(Transform.Position, 1), new Vector4(Transform.Position - Transform.Forward * BulletSpeed, 1) }, 1);

        GraphicsDevice device = GraphicsDevice.Instance;

        device.SetBlendState(Addition);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOnWriteOff);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(PrimitiveTopology.LineList);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);
        device.SetVertexBuffer(VertexPositions, 0);
        device.Draw(2);
    }
    void TransparentRender()
    {
        GraphicsDeviceContext device = GraphicsDeviceContext.Instance;

        device.SetBlendState(Addition);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOnWriteOff);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);

        var position   = this.Owner.Get <TransformComponent>().Position;
        var viewing    = ViewingMatrix;
        var projection = ProjectionMatrix;

        for (int i = 0; i < InstanceCount; i++)
        {
            var instance = Instances[i];

            var world = new Matrix4x3().Identity();
            world.Translate((position + instance.Position) * viewing);
            world.Scale(instance.Scale);

            InstanceWVPs[i] = world * projection;
            var a = (1.0f - Time) * 0.1f;
            InstanceColors[i] = new Color(a, a, a, a);
        }

        device.SetVertexBuffer(GraphicsModel.VertexPositions, 0);
        device.SetVertexBuffer(GraphicsModel.VertexTextureCoords, 1);
        VertexShader.SetConstantBuffer(InstanceWVPs, 0);
        VertexShader.SetConstantBuffer(InstanceColors, 1);

        PixelShader.SetSamplerState(Wrap, 0);
        PixelShader.SetTexture(Textures[(int)(Time * TextureCount)], 0);

        device.DrawInstanced(4, InstanceCount);
    }
    void TransparentRender()
    {
        GraphicsDeviceContext device = GraphicsDeviceContext.Instance;

        device.SetBlendState(Addition);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOnWriteOff);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);

        var viewing    = ViewingMatrix;
        var projection = ProjectionMatrix;

        int k = 0;

        foreach (var instance in Instances)
        {
            Vector3 position = instance.Position;
            float   x        = instance.Time;
            float   scale    = clamp(-3 * sin(x) * log(x), 0, 1) * 10 + 5;
            float   alpha    = clamp(sin(square(1.2f - x)), 0, 1) * 0.2f;

            var world = new Matrix4x3().Identity();
            world.Translate(position * ViewingMatrix);
            world.Scale(scale);

            InstanceWVPs[k]   = world * ProjectionMatrix;
            InstanceColors[k] = new Color(alpha, alpha, alpha, instance.Time);

            k++;
        }

        device.SetVertexBuffer(GraphicsModel.VertexPositions, 0);
        device.SetVertexBuffer(GraphicsModel.VertexTextureCoords, 1);
        VertexShader.SetConstantBuffer(InstanceWVPs, 0);

        PixelShader.SetSamplerState(Wrap, 0);
        PixelShader.SetTextureArray(Textures, 0);
        PixelShader.SetConstantBuffer(InstanceColors, 0);

        device.DrawInstanced(4, InstanceCount);
    }
Example #11
0
    private void Render()
    {
        var world = new Matrix4x3().Identity();

        world.Translate(Transform.Position * ViewingMatrix);
        world.Scale(0.5f * sin(this.Owner.Get <LimitedLifeTimeComponent>().CountTime) * PI);

        VertexShader.SetConstantBuffer(world * ProjectionMatrix, 0);
        PixelShader.SetTexture(GraphicsModel.Texture, 0);
        PixelShader.SetConstantBuffer(new Color(1, 1, 1, 1 - this.Owner.Get <LimitedLifeTimeComponent>().CountTime), 0);

        GraphicsDevice device = GraphicsDevice.Instance;

        device.SetBlendState(Addition);
        device.SetRasterizerState(CullingOff);
        device.SetDepthStencilState(ZTestOnWriteOff);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(GraphicsModel.Topology);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);
        device.SetVertexBuffer(GraphicsModel.VertexPositions, 0);
        device.SetVertexBuffer(GraphicsModel.VertexTextureCoords, 1);
        device.Draw(4);
    }
Example #12
0
    void Render()
    {
        GraphicsDeviceContext device = GraphicsDeviceContext.Instance;

        device.SetBlendState(this.Opacity == 0 ? NoBlend : AlphaBlend);
        device.SetRasterizerState(CullingOn);
        device.SetDepthStencilState(this.Opacity == 0 ? ZTestOn : ZTestOnWriteOff);
        device.SetVertexLayout(VertexLayout);
        device.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
        device.SetVertexShader(VertexShader);
        device.SetPixelShader(PixelShader);

        PixelShader.SetSamplerState(Wrap, 0);
        PixelShader.SetTexture(Texture, 0);
        PixelShader.SetTexture(NormalMapTexture, 1);

        PixelShader.SetConstantBuffer(new Vector4(Entity.Find("camera").Get <TransformComponent>().Position, 1), 2);
        PixelShader.SetConstantBuffer(new Vector4(Entity.Find("light").Get <TransformComponent>().Forward, 0), 3);
        PixelShader.SetConstantBuffer(new Color(1, 1, 1, 1.0f - this.Opacity), 4);

        {
            VertexShader.SetConstantBuffer(WVPMatrix, 0);
            PixelShader.SetConstantBuffer(WorldMatrix, 0);
            PixelShader.SetConstantBuffer(WorldMatrix.Inverse, 1);

            device.SetVertexBuffer(this.Body.VertexPositions, 0);
            device.SetVertexBuffer(this.Body.VertexNormals, 1);
            device.SetVertexBuffer(this.Body.VertexTextureCoords, 2);
            device.SetVertexBuffer(this.Body.VertexTangents, 3);
            device.SetVertexBuffer(this.Body.VertexBinormals, 4);
            device.SetIndexBuffer(this.Body.VertexIndices);
            device.DrawIndexed(this.Body.VertexIndices.Count);
        }

        var angular = new Vector4(Physics.AngularVelocity, 0) * Transform.Matrix.Inverse;

        if (this.LeftCanard != null)
        {
            Matrix4x4 move       = new Matrix4x4().Identity().Translate(this.CanardPos);
            Matrix4x4 rot        = new Matrix4x4().Identity().RotateX(clamp(angular.X * 10, -0.3f, 0.3f));
            Matrix4x4 adjustment = move.Inverse * rot * move;

            VertexShader.SetConstantBuffer(adjustment * WVPMatrix, 0);
            PixelShader.SetConstantBuffer(adjustment * WorldMatrix, 0);
            PixelShader.SetConstantBuffer((adjustment * WorldMatrix).Inverse, 1);

            device.SetVertexBuffer(this.LeftCanard.VertexPositions, 0);
            device.SetVertexBuffer(this.LeftCanard.VertexNormals, 1);
            device.SetVertexBuffer(this.LeftCanard.VertexTextureCoords, 2);
            device.SetVertexBuffer(this.LeftCanard.VertexTangents, 3);
            device.SetVertexBuffer(this.LeftCanard.VertexBinormals, 4);
            device.SetIndexBuffer(this.LeftCanard.VertexIndices);
            device.DrawIndexed(this.LeftCanard.VertexIndices.Count);
        }

        if (this.RightCanard != null)
        {
            Matrix4x4 move       = new Matrix4x4().Identity().Translate(reverseX(this.CanardPos));
            Matrix4x4 rot        = new Matrix4x4().Identity().RotateX(clamp(angular.X * 10, -0.3f, 0.3f));
            Matrix4x4 adjustment = move.Inverse * rot * move;

            VertexShader.SetConstantBuffer(adjustment * WVPMatrix, 0);
            PixelShader.SetConstantBuffer(adjustment * WorldMatrix, 0);
            PixelShader.SetConstantBuffer((adjustment * WorldMatrix).Inverse, 1);

            device.SetVertexBuffer(this.RightCanard.VertexPositions, 0);
            device.SetVertexBuffer(this.RightCanard.VertexNormals, 1);
            device.SetVertexBuffer(this.RightCanard.VertexTextureCoords, 2);
            device.SetVertexBuffer(this.RightCanard.VertexTangents, 3);
            device.SetVertexBuffer(this.RightCanard.VertexBinormals, 4);
            device.SetIndexBuffer(this.RightCanard.VertexIndices);
            device.DrawIndexed(this.RightCanard.VertexIndices.Count);
        }

        if (this.LeftElevator != null)
        {
            Matrix4x4 move       = new Matrix4x4().Identity().Translate(this.ElevatorPos);
            Matrix4x4 rot        = new Matrix4x4().Identity().RotateX(clamp((-angular.X * 2 + angular.Z * 0.5f) * 10, -0.3f, 0.3f));
            Matrix4x4 adjustment = move.Inverse * rot * move;

            VertexShader.SetConstantBuffer(adjustment * WVPMatrix, 0);
            PixelShader.SetConstantBuffer(adjustment * WorldMatrix, 0);
            PixelShader.SetConstantBuffer((adjustment * WorldMatrix).Inverse, 1);

            device.SetVertexBuffer(this.LeftElevator.VertexPositions, 0);
            device.SetVertexBuffer(this.LeftElevator.VertexNormals, 1);
            device.SetVertexBuffer(this.LeftElevator.VertexTextureCoords, 2);
            device.SetVertexBuffer(this.LeftElevator.VertexTangents, 3);
            device.SetVertexBuffer(this.LeftElevator.VertexBinormals, 4);
            device.SetIndexBuffer(this.LeftElevator.VertexIndices);
            device.DrawIndexed(this.LeftElevator.VertexIndices.Count);
        }

        if (this.RightElevator != null)
        {
            Matrix4x4 move       = new Matrix4x4().Identity().Translate(reverseX(this.ElevatorPos));
            Matrix4x4 rot        = new Matrix4x4().Identity().RotateX(clamp((-angular.X * 2 - angular.Z * 0.5f) * 10, -0.3f, 0.3f));
            Matrix4x4 adjustment = move.Inverse * rot * move;

            VertexShader.SetConstantBuffer(adjustment * WVPMatrix, 0);
            PixelShader.SetConstantBuffer(adjustment * WorldMatrix, 0);
            PixelShader.SetConstantBuffer((adjustment * WorldMatrix).Inverse, 1);

            device.SetVertexBuffer(this.RightElevator.VertexPositions, 0);
            device.SetVertexBuffer(this.RightElevator.VertexNormals, 1);
            device.SetVertexBuffer(this.RightElevator.VertexTextureCoords, 2);
            device.SetVertexBuffer(this.RightElevator.VertexTangents, 3);
            device.SetVertexBuffer(this.RightElevator.VertexBinormals, 4);
            device.SetIndexBuffer(this.RightElevator.VertexIndices);
            device.DrawIndexed(this.RightElevator.VertexIndices.Count);
        }

        #region ミサイル更新
        for (int i = 0; i < 8; i++)
        {
            if (this.Weapons[i].MissileEntity != null)
            {
                Entity e = this.Weapons[i].MissileEntity;
                e.Get <TransformComponent>().Matrix = Transform.Matrix;
                e.Get <TransformComponent>().Matrix.Translate(this.Weapons[i].WeaponPos);
                e.Get <PhysicsComponent>().Velocity     = Physics.Velocity;
                e.Get <MissileComponent>().TargetEntity = (this.Owner.Has <AIComponent>()) ? this.Owner.Get <AIComponent>().TargetEntity : null;
            }
        }
        #endregion
    }