コード例 #1
0
    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);
    }
コード例 #2
0
    private void Update()
    {
        var world = this.Owner.Get <TransformComponent>().Matrix;

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

            if (1 < instance.Time)
            {
                instance.Time       = 0;
                instance.CountSpeed = uniform(0.05f, 0.1f);

                float r  = normal(15, 5) + 15;
                float t  = uniform(0, PI2);
                float z  = normal(70, 20);
                float dx = normal(0.5f, 0.2f);
                float dz = normal(20, 5);

                Matrix4x3 adjustment = new Matrix4x3().Identity();
                adjustment.RotateZ(t);
                adjustment.Translate(0, -r, z);
                adjustment.Scale(dx, 0, dz);
                instance.Matrix = adjustment * world;
            }
        }
    }
コード例 #3
0
ファイル: JetComponent.cs プロジェクト: s059ff/ZephyrEngine
    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);
            }
        }
    }
コード例 #4
0
    private void TranslucentRender()
    {
        GraphicsDeviceContext device = GraphicsDeviceContext.Instance;

        device.SetBlendState(AlphaBlend);
        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);

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

        InstanceAlphas.Lock(Accessibility.DynamicWriteOnly);
        InstanceWVPs.Lock(Accessibility.DynamicWriteOnly);

        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) * 15 + 10;
            float   alpha    = clamp(sin(square(1.2f - x)), 0, 1) * 0.5f;

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

            InstanceWVPs.Write(k, world * ProjectionMatrix);
            InstanceAlphas.Write(k, alpha);

            k++;
        }

        InstanceAlphas.Unlock();
        InstanceWVPs.Unlock();

        device.SetInstanceBuffer(InstanceAlphas, 2);
        device.SetInstanceBuffer(InstanceWVPs, 3);

        device.DrawInstanced(4, Instances.Count);
    }
コード例 #5
0
    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);
    }
コード例 #6
0
ファイル: CloudComponent.cs プロジェクト: s059ff/ZephyrEngine
    void TransparentRender()
    {
        GraphicsDevice device = GraphicsDevice.Instance;

        device.SetBlendState(AlphaBlend);
        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);

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

        InstanceWVPs.Lock(Accessibility.DynamicWriteOnly);

        var eye = Entity.Find("camera").Get <TransformComponent>().Position;

        for (int i = 0; i < Instances.Length; i++)
        {
            var     instance = Instances[i];
            Vector3 position = instance.Position;
            float   scale    = instance.Scale;

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

            InstanceWVPs.Write(i, world * ProjectionMatrix);
        }

        InstanceWVPs.Unlock();

        device.SetInstanceBuffer(InstanceWVPs, 2);

        device.DrawInstanced(4, Instances.Length);
    }
コード例 #7
0
    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);
    }
コード例 #8
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);
    }
コード例 #9
0
    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);

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

        InstanceColors.Lock(Accessibility.DynamicWriteOnly);
        InstanceWVPs.Lock(Accessibility.DynamicWriteOnly);

        var viewing    = Entity.Find("camera").Get <CameraComponent>().ViewingMatrix;
        var projection = Entity.Find("projector").Get <ProjectorComponent>().ProjectionMatrix;
        var eye        = Entity.Find("camera").Get <TransformComponent>().Position;

        int     k         = 0;
        Vector3 position2 = Nodes.First.Value.Position;

        foreach (var node in Nodes)
        {
            Vector3 position1 = node.Position;

            if (k > 0)
            {
                Vector3 vz = position2 - position1;
                vz.Normalize();

                Vector3 vy = Vector3.Outer(vz, position1 - eye);
                vy.Normalize();
                Vector3   vx     = Vector3.Outer(vy, vz);
                Matrix4x3 matrix = new Matrix4x3().Identity();
                matrix.M11 = vx.X; matrix.M12 = vx.Y; matrix.M13 = vx.Z;
                matrix.M21 = vy.X; matrix.M22 = vy.Y; matrix.M23 = vy.Z;
                matrix.M31 = vz.X; matrix.M32 = vz.Y; matrix.M33 = vz.Z;

                var world = new Matrix4x3().Identity();
                world.Translate(position1);
                world.Transform(matrix);
                world.Scale(1, 2, (position1 - position2).Magnitude);

                InstanceWVPs.Write(k, world * viewing * projection);

                //float alpha = clamp(exp(-square(node.Time - 0.5f) / 0.075f), 0, 1) * 0.75f;
                float alpha = clamp(sin((1 - node.Time) * PI) - 0.05f, 0, 1) * (1 - node.Time);
                //float alpha = 1.0f - node.Time;
                InstanceColors.Write(k, new Color(alpha, alpha, alpha));
            }
            k++;
            position2 = position1;
        }

        InstanceColors.Unlock();
        InstanceWVPs.Unlock();

        device.SetInstanceBuffer(InstanceColors, 2);
        device.SetInstanceBuffer(InstanceWVPs, 3);

        device.DrawInstanced(4, Nodes.Count - 1);
    }