Beispiel #1
0
        void DrawPuffRing(bool inside, CommandBuffer buffer)
        {
            /* Skip rendering puff rings */
            if (!inside)
            {
                Vector3 sz;
                if (Nebula.Zone.Shape is ZoneEllipsoid)
                {
                    sz = ((ZoneEllipsoid)Nebula.Zone.Shape).Size / 2; //we want radius instead of diameter
                }
                else if (Nebula.Zone.Shape is ZoneSphere)
                {
                    sz = new Vector3(((ZoneSphere)Nebula.Zone.Shape).Radius);
                }
                else
                {
                    return;
                }
                var bitRadius = Nebula.ExteriorBitRadius * (1 + Nebula.ExteriorBitRandomVariation);
                var szR       = Math.Max(sz.X, Math.Max(sz.Y, sz.Z));
                var sph       = new BoundingSphere(Nebula.Zone.Position, (szR + bitRadius) * 1.2f);
                if (camera.Frustum.Contains(sph) == ContainmentType.Disjoint)
                {
                    return;
                }
            }
            /* Actually Render */
            var       sd      = 1 - MathHelper.Clamp(Nebula.Zone.Shape.ScaledDistance(camera.Position), 0f, 1f);
            var       factor  = MathHelper.Clamp(sd / Nebula.Zone.EdgeFraction, 0, 1);
            int       idx     = GetPuffsIdx();
            string    lastTex = null;
            Texture2D tex     = null;
            var       sh      = GetPuffShader();

            _puffringsh.SetView(camera);
            _puffringsh.SetViewProjection(camera);
            for (int i = 0; i < Exterior.Count; i++)
            {
                var p = Exterior[i];
                if (p.Texture == null)
                {
                    lastTex = null;
                    tex     = resman.NullTexture;
                }
                else if (lastTex != p.Texture)
                {
                    tex     = (Texture2D)resman.FindTexture(p.Texture);
                    lastTex = p.Texture;
                }
                buffer.AddCommand(sh, puffSetup, puffCleanup, Matrix4x4.Identity,
                                  new RenderUserData()
                {
                    Texture = tex, Float = factor
                }, sysr.StaticBillboards.VertexBuffer,
                                  PrimitiveTypes.TriangleList, idx, 2, true, inside ? SortLayers.NEBULA_INSIDE : SortLayers.NEBULA_NORMAL,
                                  RenderHelpers.GetZ(camera.Position, p.Position));
                idx += 6;
            }
        }
Beispiel #2
0
 public Texture2D GetSplashScreen()
 {
     if (!resource.TextureExists("__startupscreen_1280.tga"))
     {
         resource.AddTexture(
             "__startupscreen_1280.tga",
             Compatibility.VFS.GetPath(fldata.Freelancer.DataPath + "INTERFACE/INTRO/IMAGES/startupscreen_1280.tga")
             );
     }
     return((Texture2D)resource.FindTexture("__startupscreen_1280.tga"));
 }
        public SystemRenderer(ICamera camera, GameDataManager data, ResourceManager rescache, Game game)
        {
            this.camera      = camera;
            AsteroidFields   = new List <AsteroidFieldRenderer>();
            Nebulae          = new List <NebulaRenderer>();
            StarSphereModels = new IDrawable[0];
            Polyline         = new PolylineRender(commands);
            cache            = rescache;
            rstate           = cache.Game.RenderState;
            this.game        = game;
            gconfig          = game.GetService <GameConfig>();
            billboards       = game.GetService <Billboards>();
            resman           = game.GetService <ResourceManager>();
            nebulae          = game.GetService <NebulaVertices>();
            dot           = (Texture2D)rescache.FindTexture(ResourceManager.WhiteTextureName);
            DebugRenderer = new PhysicsDebugRenderer();

            if (GLExtensions.Features430)
            {
                pointLightBuffer = new ShaderStorageBuffer(MAX_POINTS * (16 * sizeof(float)));
                if (pointLightCull == null)
                {
                    pointLightCull = new ComputeShader(Resources.LoadString("LibreLancer.Shaders.lightingcull.glcompute"));
                }
            }
        }
Beispiel #4
0
 public void End()
 {
     if (!begun)
     {
         throw new InvalidOperationException();
     }
     begun = false;
     if (code_beam == null || code_beam.IsDisposed)
     {
         code_beam = (Texture2D)res.FindTexture("code_beam");
     }
     bufferSpear.EndStreaming(vertexCountSpear);
     bufferBolt.EndStreaming(vertexCountBolt);
     if (vertexCountSpear > 0)
     {
         commands.AddCommand(shader.Shader, SetupShader, EnableCull, commands.WorldBuffer.Identity, new RenderUserData(),
                             bufferSpear,
                             PrimitiveTypes.TriangleList, 0, spearCount * (spearIndices.Length / 3), true, SortLayers.OBJECT);
         spearCount       = 0;
         vertexCountSpear = 0;
     }
     if (boltCount > 0)
     {
         commands.AddCommand(shader.Shader, SetupShader, EnableCull, commands.WorldBuffer.Identity, new RenderUserData(),
                             bufferBolt,
                             PrimitiveTypes.TriangleList, 0, boltCount * (boltIndices.Length / 3), true, SortLayers.OBJECT);
         vertexCountBolt = 0;
         boltCount       = 0;
     }
 }
		void DrawPuffRing(bool inside)
		{
            /* Skip rendering puff rings */
            if(!inside) {
                Vector3 sz;
                if (Nebula.Zone.Shape is ZoneEllipsoid)
                    sz = ((ZoneEllipsoid)Nebula.Zone.Shape).Size / 2; //we want radius instead of diameter
                else if (Nebula.Zone.Shape is ZoneSphere)
                    sz = new Vector3(((ZoneSphere)Nebula.Zone.Shape).Radius);
                else
                    return;
                var bitRadius = Nebula.ExteriorBitRadius * (1 + Nebula.ExteriorBitRandomVariation);
                var szR = Math.Max(sz.X, Math.Max(sz.Y, sz.Z));
                var sph = new BoundingSphere(Nebula.Zone.Position, (szR + bitRadius) * 1.2f);
                if (camera.Frustum.Contains(sph) == ContainmentType.Disjoint)
                    return;
            }
            /* Actually Render */
			var sd = 1 - MathHelper.Clamp(Nebula.Zone.Shape.ScaledDistance(camera.Position), 0f, 1f);
			var factor = MathHelper.Clamp(sd / Nebula.Zone.EdgeFraction, 0, 1);

			for (int i = 0; i < Exterior.Count; i++)
			{
				var p = Exterior[i];
				var tex = resman.FindTexture(p.Shape.Texture);
				billboards.DrawCustomShader(
					GetPuffShader(billboards),
					_setupPuffDelegate,
					new RenderUserData() { Texture = tex, Color = Nebula.FogColor, Float = factor },
					p.Position,
					p.Size,
					Nebula.ExteriorColor,
					new Vector2(p.Shape.Dimensions.X, p.Shape.Dimensions.Y),
					new Vector2(p.Shape.Dimensions.X + p.Shape.Dimensions.Width, p.Shape.Dimensions.Y),
					new Vector2(p.Shape.Dimensions.X, p.Shape.Dimensions.Y + p.Shape.Dimensions.Height),
					new Vector2(p.Shape.Dimensions.X + p.Shape.Dimensions.Width, p.Shape.Dimensions.Y + p.Shape.Dimensions.Height),
					0,
					inside ? SortLayers.NEBULA_INSIDE : SortLayers.NEBULA_NORMAL
				);
			}
		}
Beispiel #6
0
        public void Draw(Renderer2D renderer, Mouse m)
        {
            var pos = new Vector2(m.X, m.Y) - (Hotspot * Scale);
            var dst = new Rectangle(
                (int)pos.X, (int)pos.Y,
                (int)(Dimensions.Width * Scale), (int)(Dimensions.Height * Scale)
                );

            renderer.Draw(
                (Texture2D)Resources.FindTexture(Texture),
                Dimensions,
                dst,
                Color,
                BlendMode.Additive
                );
        }
        public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
        {
            var code_beam = (Texture2D)res.FindTexture("code_beam");

            code_beam.SetWrapModeS(WrapMode.ClampToEdge);
            code_beam.SetWrapModeT(WrapMode.ClampToEdge);
            for (int i = 0; i < renderCount; i++)
            {
                var p = toRender[i];
                if (p.Data.Munition.ConstEffect_Beam != null)
                {
                    var     beam = p.Data.Munition.ConstEffect_Beam;
                    Vector2 tl, tr, bl, br;
                    CoordsFromTexture(beam.HeadTexture, out tl, out tr, out bl, out br);
                    billboards.Draw(
                        code_beam,
                        p.Position,
                        new Vector2(beam.HeadWidth, beam.HeadWidth),
                        beam.CoreColor,
                        tl, tr, bl, br,
                        0,
                        SortLayers.OBJECT,
                        BlendMode.Additive
                        );
                    CoordsFromTexture(beam.TrailTexture, out tl, out tr, out bl, out br);
                }
                else if (p.Data.Munition.ConstEffect_Bolt != null)
                {
                    //bolt
                    var     bolt = p.Data.Munition.ConstEffect_Bolt;
                    Vector2 tl, tr, bl, br;
                    CoordsFromTexture(bolt.HeadTexture, out tl, out tr, out bl, out br);
                    billboards.Draw(
                        code_beam,
                        p.Position,
                        new Vector2(bolt.HeadWidth, bolt.HeadWidth),
                        bolt.CoreColor,
                        tl, tr, bl, br,
                        0,
                        SortLayers.OBJECT,
                        BlendMode.Additive
                        );
                }
            }
        }
Beispiel #8
0
        public void Draw(Renderer2D renderer, Mouse m, double globalTime)
        {
            //var pos = new Vector2(m.X, m.Y) - (Hotspot * Scale);
            var dst = new Rectangle(
                (int)m.X, (int)m.Y,
                (int)(Dimensions.Width * Scale), (int)(Dimensions.Height * Scale)
                );
            var angle = MathHelper.WrapF((float)globalTime * Spin, -MathF.PI, MathF.PI);
            var hp    = new Vector2((int)(Hotspot.X * Scale), (int)(Hotspot.Y * Scale));

            renderer.DrawRotated(
                (Texture2D)Resources.FindTexture(Texture),
                Dimensions,
                dst,
                hp,
                Color,
                BlendMode.Additive,
                angle
                );
            renderer.FillRectangle(new Rectangle(m.X, m.Y, 1, 1), Color4.Red);
        }
Beispiel #9
0
        public SystemRenderer(ICamera camera, LegacyGameData data, ResourceManager rescache, FreelancerGame game)
        {
            this.camera      = camera;
            World            = Matrix4.Identity;
            Objects          = new List <ObjectRenderer>();
            AsteroidFields   = new List <AsteroidFieldRenderer>();
            Nebulae          = new List <NebulaRenderer>();
            StarSphereModels = new IDrawable[0];
            Polyline         = new PolylineRender(commands);
            cache            = rescache;
            rstate           = cache.Game.RenderState;
            this.game        = game;
            dot           = (Texture2D)rescache.FindTexture(ResourceManager.WhiteTextureName);
            DebugRenderer = new PhysicsDebugRenderer();

            if (GLExtensions.Features430)
            {
                pointLightBuffer = new ShaderStorageBuffer(MAX_POINTS * (16 * sizeof(float)));
                if (pointLightCull != null)
                {
                    pointLightCull = new ComputeShader(Resources.LoadString("LibreLancer.Shaders.lightingcull.glcompute"));
                }
            }
        }
Beispiel #10
0
 public void End()
 {
     if (code_beam == null || code_beam.IsDisposed)
     {
         code_beam = (Texture2D)res.FindTexture("code_beam");
     }
     bufferSpear.EndStreaming(vertexCountSpear);
     bufferBolt.EndStreaming(vertexCountBolt);
     if (vertexCountSpear > 0)
     {
         commands.AddCommand(shader.Shader, SetupShader, EnableCull, commands.WorldBuffer.Identity, new RenderUserData(),
                             bufferSpear,
                             PrimitiveTypes.TriangleList, 0, vertexCountSpear, true, SortLayers.OBJECT);
         vertexCountSpear = 0;
     }
     if (boltCount > 0)
     {
         commands.AddCommand(shader.Shader, SetupShader, EnableCull, commands.WorldBuffer.Identity, new RenderUserData(),
                             bufferBolt,
                             PrimitiveTypes.TriangleList, 0, boltCount * 20, true, SortLayers.OBJECT);
         vertexCountBolt = 0;
         boltCount       = 0;
     }
 }
Beispiel #11
0
        public void Draw(ResourceManager res, SystemLighting lighting, CommandBuffer buffer, NebulaRenderer nr)
        {
            //Null check
            if (_camera == null)
            {
                return;
            }
            //Asteroids!
            if (VectorMath.DistanceSquared(cameraPos, field.Zone.Position) <= renderDistSq)
            {
                float fadeNear = field.FillDist * 0.9f;
                float fadeFar  = field.FillDist;
                if (field.Cube.Count > 0)
                {
                    if (cubeCount == -1)
                    {
                        return;
                    }
                    for (int i = 0; i < cubeDrawCalls.Count; i++)
                    {
                        cubeDrawCalls[i].Material.Update(_camera);
                    }
                    var lt = RenderHelpers.ApplyLights(lighting, 0, cameraPos, field.FillDist, nr);
                    while (!_asteroidsCalculated)
                    {
                    }
                    for (int j = 0; j < cubeCount; j++)
                    {
                        var center = cubes[j].pos;
                        var z      = RenderHelpers.GetZ(cameraPos, center);
                        for (int i = 0; i < cubeDrawCalls.Count; i++)
                        {
                            var dc = cubeDrawCalls[i];
                            if (VectorMath.DistanceSquared(center, cameraPos) < (fadeNear * fadeNear))
                            { //TODO: Accurately determine whether or not a cube has fading
                            }
                            buffer.AddCommandFade(
                                dc.Material.Render,
                                cubes[j].tr,
                                lt,
                                cube_vbo,
                                PrimitiveTypes.TriangleList,
                                dc.StartIndex,
                                dc.Count / 3,
                                SortLayers.OBJECT,
                                new Vector2(fadeNear, fadeFar),
                                z
                                );
                        }
                    }
                }
                if (field.BillboardCount != -1 || false)
                {
                    var cameraLights = RenderHelpers.ApplyLights(lighting, 0, cameraPos, 1, nr);
                    if (billboardTex == null || billboardTex.IsDisposed)
                    {
                        billboardTex = (Texture2D)res.FindTexture(field.BillboardShape.Texture);
                    }

                    for (int i = 0; i < astbillboards.Length; i++)
                    {
                        if (!astbillboards [i].Inited)
                        {
                            astbillboards [i].Spawn(this);
                        }
                        var d = VectorMath.DistanceSquared(cameraPos, astbillboards [i].Position);
                        if (d < (field.BillboardDistance * field.BillboardDistance) || d > (field.FillDist * field.FillDist))
                        {
                            astbillboards [i].Spawn(this);
                        }
                        if (astbillboards [i].Visible)
                        {
                            var alpha  = 1f;
                            var coords = billboardCoords [astbillboards [i].Texture];
                            sys.Game.Billboards.DrawTri(
                                billboardTex,
                                astbillboards [i].Position,
                                astbillboards[i].Size,
                                new Color4(field.BillboardTint * cameraLights.Ambient.Rgb, alpha),
                                coords[0], coords[2], coords[1],
                                0,
                                SortLayers.OBJECT
                                );
                        }
                    }
                }
            }

            //Band is last
            if (renderBand)
            {
                if (!_camera.Frustum.Intersects(new BoundingSphere(field.Zone.Position, lightingRadius)))
                {
                    return;
                }
                var tex = (Texture2D)res.FindTexture(field.Band.Shape);
                for (int i = 0; i < SIDES; i++)
                {
                    var p      = bandCylinder.GetSidePosition(i);
                    var zcoord = RenderHelpers.GetZ(bandTransform, cameraPos, p);
                    p = bandTransform.Transform(p);
                    var lt = RenderHelpers.ApplyLights(lighting, 0, p, lightingRadius, nr);
                    if (lt.FogMode != FogModes.Linear || VectorMath.DistanceSquared(cameraPos, p) <= (lightingRadius + lt.FogRange.Y) * (lightingRadius + lt.FogRange.Y))
                    {
                        buffer.AddCommand(
                            bandShader.Shader,
                            bandShaderDelegate,
                            bandShaderCleanup,
                            bandTransform,
                            lt,
                            new RenderUserData()
                        {
                            Float   = field.Band.TextureAspect,
                            Color   = field.Band.ColorShift,
                            Camera  = _camera,
                            Texture = tex,
                            Matrix2 = bandNormal
                        },
                            bandCylinder.VertexBuffer,
                            PrimitiveTypes.TriangleList,
                            0,
                            i * 6,
                            2,
                            true,
                            SortLayers.OBJECT,
                            zcoord
                            );
                    }
                }
            }
        }
        public void Draw(ResourceManager res, SystemLighting lighting, CommandBuffer buffer, NebulaRenderer nr)
        {
            //Null check
            if (_camera == null)
            {
                return;
            }
            //Asteroids!
            if (Vector3.DistanceSquared(cameraPos, field.Zone.Position) <= renderDistSq)
            {
                float fadeNear = field.FillDist - 100f;
                float fadeFar  = field.FillDist;
                if (field.Cube.Count > 0)
                {
                    if (cubeCount == -1)
                    {
                        return;
                    }
                    asteroidsTask.Wait();
                    for (int i = 0; i < cubeDrawCalls.Count; i++)
                    {
                        cubeDrawCalls[i].Material.Update(_camera);
                    }
                    var lt = RenderHelpers.ApplyLights(lighting, 0, cameraPos, field.FillDist, nr);

                    if (lt.FogMode == FogModes.Linear)
                    {
                        lastFog = lt.FogRange.Y;
                    }
                    else
                    {
                        lastFog = float.MaxValue;
                    }
                    int fadeCount = 0;
                    int regCount  = 0;
                    for (int j = 0; j < cubeCount; j++)
                    {
                        var center = cubes[j].pos;
                        var z      = RenderHelpers.GetZ(cameraPos, center);
                        for (int i = 0; i < cubeDrawCalls.Count; i++)
                        {
                            var dc = cubeDrawCalls[i];
                            if ((Vector3.Distance(center, cameraPos) + cubeRadius) < fadeNear)
                            {
                                buffer.AddCommand(
                                    dc.Material.Render,
                                    null,
                                    buffer.WorldBuffer.SubmitMatrix(ref cubes[j].tr),
                                    lt,
                                    cube_vbo,
                                    PrimitiveTypes.TriangleList,
                                    0,
                                    dc.StartIndex,
                                    dc.Count / 3,
                                    SortLayers.OBJECT
                                    );
                                regCount++;
                            }
                            else
                            {
                                buffer.AddCommandFade(
                                    dc.Material.Render,
                                    buffer.WorldBuffer.SubmitMatrix(ref cubes[j].tr),
                                    lt,
                                    cube_vbo,
                                    PrimitiveTypes.TriangleList,
                                    dc.StartIndex,
                                    dc.Count / 3,
                                    SortLayers.OBJECT,
                                    new Vector2(fadeNear, fadeFar),
                                    z
                                    );
                                fadeCount++;
                            }
                        }
                    }
                }
                if (field.BillboardCount != -1)
                {
                    var cameraLights = RenderHelpers.ApplyLights(lighting, 0, cameraPos, 1, nr);
                    if (billboardTex == null || billboardTex.IsDisposed)
                    {
                        billboardTex = (Texture2D)res.FindTexture(field.BillboardShape.Texture);
                    }
                    billboardTask.Wait();
                    for (int i = 0; i < billboardCount; i++)
                    {
                        var alpha = BillboardAlpha(Vector3.Distance(calculatedBillboards[i].Position, cameraPos));
                        if (alpha <= 0)
                        {
                            continue;
                        }
                        var coords = billboardCoords [calculatedBillboards [i].Texture];
                        sys.Billboards.DrawTri(
                            billboardTex,
                            calculatedBillboards [i].Position,
                            calculatedBillboards[i].Size,
                            new Color4(field.BillboardTint * cameraLights.Ambient, alpha),
                            coords[0], coords[2], coords[1],
                            0,
                            SortLayers.OBJECT
                            );
                    }
                }
            }
            //Band is last
            if (renderBand)
            {
                if (!_camera.Frustum.Intersects(new BoundingSphere(field.Zone.Position, lightingRadius)))
                {
                    return;
                }
                var tex        = (Texture2D)res.FindTexture(field.Band.Shape);
                var bandHandle = buffer.WorldBuffer.SubmitMatrix(ref bandTransform);
                for (int i = 0; i < SIDES; i++)
                {
                    var p      = bandCylinder.GetSidePosition(i);
                    var zcoord = RenderHelpers.GetZ(bandTransform, cameraPos, p);
                    p = Vector3.Transform(p, bandTransform);
                    var lt = RenderHelpers.ApplyLights(lighting, 0, p, lightingRadius, nr);
                    if (lt.FogMode != FogModes.Linear || Vector3.DistanceSquared(cameraPos, p) <= (lightingRadius + lt.FogRange.Y) * (lightingRadius + lt.FogRange.Y))
                    {
                        buffer.AddCommand(
                            bandShader.Shader,
                            bandShaderDelegate,
                            bandShaderCleanup,
                            bandHandle,
                            lt,
                            new RenderUserData()
                        {
                            Float   = field.Band.TextureAspect,
                            Color   = field.Band.ColorShift,
                            Camera  = _camera,
                            Texture = tex,
                        },
                            bandCylinder.VertexBuffer,
                            PrimitiveTypes.TriangleList,
                            0,
                            i * 6,
                            2,
                            true,
                            SortLayers.OBJECT,
                            zcoord
                            );
                    }
                }
            }
        }