Beispiel #1
0
        public QuadBuilder CreateQuad(float3 position, float3 rotation, float3 scale, float4 uvs)
        {
            if (_quadIndex == -1)
            {
                _quadIndex = GetNextQuadIndex();
                if (_quadIndex == -1)
                {
                    return(this); // No more quads can be spawned until one is destroyed
                }
            }

            UpdateQuad(_quadIndex, position, rotation, scale)
            .UpdateQuad(_quadIndex, uvs)
            .UpdateQuad(_quadIndex, Color.white);

            var i      = new QuadVert(_quadIndex);
            int tIndex = _quadIndex * 6;

            Triangles[tIndex]     = i.V0;
            Triangles[tIndex + 1] = i.V1;
            Triangles[tIndex + 2] = i.V2;

            Triangles[tIndex + 3] = i.V0;
            Triangles[tIndex + 4] = i.V2;
            Triangles[tIndex + 5] = i.V3;

            _quadIndex = GetNextQuadIndex();

            Dirty = true;
            return(this);
        }
Beispiel #2
0
        public QuadBuilder UpdateQuad(int quadIndex, Color color)
        {
            if (quadIndex > _quadIndexes.Length || quadIndex < 0)
            {
                return(this);
            }

            var i = new QuadVert(quadIndex);

            Colors[i.V0] = color;
            Colors[i.V1] = color;
            Colors[i.V2] = color;
            Colors[i.V3] = color;

            Dirty = true;
            return(this);
        }
Beispiel #3
0
        public QuadBuilder UpdateQuad(int quadIndex, float4 uvs)
        {
            if (quadIndex > _quadIndexes.Length || quadIndex < 0)
            {
                return(this);
            }

            var i = new QuadVert(quadIndex);

            Uvs[i.V0] = new Vector2(uvs.x, uvs.y);
            Uvs[i.V0] = new Vector2(uvs.x, uvs.w);
            Uvs[i.V0] = new Vector2(uvs.z, uvs.w);
            Uvs[i.V0] = new Vector2(uvs.z, uvs.y);

            Dirty = true;
            return(this);
        }
Beispiel #4
0
        public QuadBuilder DestroyQuad(int quadIndex)
        {
            if (quadIndex > _quadIndexes.Length || quadIndex < 0)
            {
                return(this);
            }

            var i = new QuadVert(quadIndex);

            Vertices[i.V0] = Vector3.zero;
            Vertices[i.V1] = Vector3.zero;
            Vertices[i.V2] = Vector3.zero;
            Vertices[i.V3] = Vector3.zero;

            _quadIndexes[quadIndex] = quadIndex;

            Dirty = true;
            return(this);
        }
Beispiel #5
0
        public QuadBuilder UpdateQuad(int quadIndex, float3 position, Quaternion rotation, float3 scale)
        {
            if (quadIndex > _quadIndexes.Length || quadIndex < 0)
            {
                return(this);
            }

            float widthOffset  = scale.x + position.x;
            float heightOffset = scale.y + position.y;

            var i = new QuadVert(quadIndex);

            Vertices[i.V0] = rotation * new Vector3(position.x, position.y, position.z);
            Vertices[i.V1] = rotation * new Vector3(position.x, heightOffset, position.z);
            Vertices[i.V2] = rotation * new Vector3(widthOffset, heightOffset, position.z);
            Vertices[i.V3] = rotation * new Vector3(widthOffset, position.y, position.z);

            Dirty = true;
            return(this);
        }
Beispiel #6
0
        public Atmosphere()
        {
            GraphicsDevice device = Engine.GraphicsContext.Device;

            transmittanceT = RenderTarget2D.New(device, TRANSMITTANCE_W, TRANSMITTANCE_H, PixelFormat.R16G16B16A16.Float);
            irradianceT    = RenderTarget2D.New(device, SKY_W, SKY_H, PixelFormat.R16G16B16A16.Float);
            inscatterT     = RenderTarget3D.New(device, RES_MU_S * RES_NU, RES_MU, RES_R, PixelFormat.R16G16B16A16.Float);
            deltaET        = RenderTarget2D.New(device, SKY_W, SKY_H, PixelFormat.R16G16B16A16.Float);
            deltaSRT       = RenderTarget3D.New(device, RES_MU_S * RES_NU, RES_MU, RES_R, PixelFormat.R16G16B16A16.Float);
            deltaSMT       = RenderTarget3D.New(device, RES_MU_S * RES_NU, RES_MU, RES_R, PixelFormat.R16G16B16A16.Float);
            deltaJT        = RenderTarget3D.New(device, RES_MU_S * RES_NU, RES_MU, RES_R, PixelFormat.R16G16B16A16.Float);

            atmosphere     = EffectLoader.Load(@"World/Atmosphere/Shaders/atmosphere.fx");
            copyInscatter1 = EffectLoader.Load(@"World/Atmosphere/Shaders/copyInscatter1.fx");
            copyInscatterN = EffectLoader.Load(@"World/Atmosphere/Shaders/copyInscatterN.fx");
            copyIrradiance = EffectLoader.Load(@"World/Atmosphere/Shaders/copyIrradiance.fx");
            inscatter1     = EffectLoader.Load(@"World/Atmosphere/Shaders/inscatter1.fx");
            inscatterN     = EffectLoader.Load(@"World/Atmosphere/Shaders/inscatterN.fx");
            inscatterS     = EffectLoader.Load(@"World/Atmosphere/Shaders/inscatterS.fx");
            irradiance1    = EffectLoader.Load(@"World/Atmosphere/Shaders/irradiance1.fx");
            irradianceN    = EffectLoader.Load(@"World/Atmosphere/Shaders/irradianceN.fx");
            transmittance  = EffectLoader.Load(@"World/Atmosphere/Shaders/transmittance.fx");

            QuadVert[] verts = new QuadVert[6]
            {
                new QuadVert(-1, -1, 0),
                new QuadVert(-1, 1, 0),
                new QuadVert(1, 1, 0),
                new QuadVert(1, 1, 0),
                new QuadVert(1, -1, 0),
                new QuadVert(-1, -1, 0)
            };

            vb = SharpDX.Toolkit.Graphics.Buffer.New <QuadVert>(device, verts, BufferFlags.VertexBuffer);

            PreProcess();
        }