public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
 {
     if (Model != null)
     {
         Model.Update(camera, TimeSpan.FromSeconds(sysr.Game.TotalTime), sysr.ResourceManager);
         foreach (var part in Model.AllParts)
         {
             if (part.Mesh == null)
             {
                 continue;
             }
             if (!part.Active)
             {
                 continue;
             }
             var w      = part.LocalTransform * World;
             var center = Vector3.Transform(part.Mesh.Center, w);
             var lvl    = GetLevel(part, center, camera.Position);
             if (lvl == -1)
             {
                 continue;
             }
             var lighting = RenderHelpers.ApplyLights(lights, LightGroup, center, part.GetRadius(), nr,
                                                      LitAmbient, LitDynamic, NoFog);
             var r = part.GetRadius() + lighting.FogRange.Y;
             if (lighting.FogMode != FogModes.Linear ||
                 Vector3.DistanceSquared(camera.Position, center) <= (r * r))
             {
                 part.Mesh.DrawBuffer(lvl, sysr.ResourceManager, commands, w, ref lighting, Model.MaterialAnims);
             }
         }
     }
 }
Exemplo n.º 2
0
        public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
        {
            if (sysr == null)
            {
                return;
            }
            float z = RenderHelpers.GetZ(Matrix4.Identity, camera.Position, pos);

            if (z > 900000)             // Reduce artefacts from fast Z-sort calculation. This'll probably cause issues somewhere else
            {
                z = 900000;
            }
            var dist_scale = nr != null ? nr.Nebula.SunBurnthroughScale : 1;             // TODO: Modify this based on nebula burn-through.
            var alpha      = nr != null ? nr.Nebula.SunBurnthroughIntensity : 1;
            var glow_scale = dist_scale * Sun.GlowScale;

            if (Sun.CenterSprite != null)
            {
                var center_scale = dist_scale * Sun.CenterScale;
                DrawRadial(
                    (Texture2D)sysr.Game.ResourceManager.FindTexture(Sun.CenterSprite),
                    new Vector3(pos),
                    new Vector2(Sun.Radius, Sun.Radius) * center_scale,
                    new Color4(Sun.CenterColorInner, 1),
                    new Color4(Sun.CenterColorOuter, alpha),
                    0,
                    z
                    );
            }
            DrawRadial(
                (Texture2D)sysr.Game.ResourceManager.FindTexture(Sun.GlowSprite),
                new Vector3(pos),
                new Vector2(Sun.Radius, Sun.Radius) * glow_scale,
                new Color4(Sun.GlowColorInner, 0),
                new Color4(Sun.GlowColorOuter, alpha),
                0,
                z + 108f
                );
            if (Sun.SpinesSprite != null && nr == null)
            {
                double current_angle = 0;
                double delta_angle   = (2 * Math.PI) / Sun.Spines.Count;
                var    spinetex      = (Texture2D)sysr.Game.ResourceManager.FindTexture(Sun.SpinesSprite);
                for (int i = 0; i < Sun.Spines.Count; i++)
                {
                    var s = Sun.Spines[i];
                    current_angle += delta_angle;
                    DrawSpine(
                        spinetex,
                        pos,
                        new Vector2(Sun.Radius, Sun.Radius) * Sun.SpinesScale * new Vector2(s.WidthScale / s.LengthScale, s.LengthScale),
                        s.InnerColor,
                        s.OuterColor,
                        s.Alpha,
                        (float)current_angle,
                        z + 1112f + (2f * i)
                        );
                }
            }
        }
Exemplo n.º 3
0
 public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
 {
     if (fx == null)
     {
         return;
     }
     fx.Draw(tr, SParam);
 }
Exemplo n.º 4
0
 public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
 {
     dist = VectorMath.DistanceSquared(pos, camera.Position);
     if (Active && dist < (20000 * 20000))
     {
         fx.Draw(sys.Polyline, sys.Game.Billboards, sys.DebugRenderer, tr, SParam);
     }
 }
Exemplo n.º 5
0
 public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
 {
     if (fx == null)
     {
         return;
     }
     fx.Draw(sys.Polyline, sys.Billboards, sys.DebugRenderer, tr, SParam);
 }
 public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
 {
     for (int i = 0; i < renderCount; i++)
     {
         var p = toRender[i];
         if (p.Data.Munition.ConstEffect_Spear != null)
         {
             beams.AddBeamSpear(p.Position, p.Normal.Normalized(), p.Data.Munition.ConstEffect_Spear);
         }
         if (p.Data.Munition.ConstEffect_Bolt != null)
         {
             beams.AddBeamBolt(p.Position, p.Normal.Normalized(), p.Data.Munition.ConstEffect_Bolt);
         }
     }
 }
Exemplo n.º 7
0
 public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
 {
     if (sys == null)
     {
         return;
     }
     if (frameStart)
     {
         sys.Game.ResourceManager.TryGetShape("bulb", out bulbshape);
         bulbtex = (Texture2D)sys.Game.ResourceManager.FindTexture(bulbshape.Texture);
         sys.Game.ResourceManager.TryGetShape("shine", out shineshape);
         shinetex   = (Texture2D)sys.Game.ResourceManager.FindTexture(shineshape.Texture);
         frameStart = false;
     }
     if (VectorMath.DistanceSquared(camera.Position, pos) > CULL)
     {
         return;
     }
     if (camera.Frustum.Intersects(new BoundingSphere(pos, 100)))
     {
         sys.Game.Billboards.Draw(
             shinetex,
             pos,
             new Vector2(equip.GlowSize) * 2,
             new Color4(colorGlow, 1f),
             new Vector2(shineshape.Dimensions.X, shineshape.Dimensions.Y),
             new Vector2(shineshape.Dimensions.X + shineshape.Dimensions.Width, shineshape.Dimensions.Y),
             new Vector2(shineshape.Dimensions.X, shineshape.Dimensions.Y + shineshape.Dimensions.Height),
             new Vector2(shineshape.Dimensions.X + shineshape.Dimensions.Width, shineshape.Dimensions.Y + shineshape.Dimensions.Height),
             0,
             SortLayers.LIGHT_SHINE,
             BlendMode.Additive
             );
         sys.Game.Billboards.Draw(
             bulbtex,
             pos,
             new Vector2(equip.BulbSize) * 2,
             new Color4(colorBulb, 1),
             new Vector2(bulbshape.Dimensions.X, bulbshape.Dimensions.Y),
             new Vector2(bulbshape.Dimensions.X + bulbshape.Dimensions.Width, bulbshape.Dimensions.Y),
             new Vector2(bulbshape.Dimensions.X, bulbshape.Dimensions.Y + bulbshape.Dimensions.Height),
             new Vector2(bulbshape.Dimensions.X + bulbshape.Dimensions.Width, bulbshape.Dimensions.Y + bulbshape.Dimensions.Height),
             0,
             SortLayers.LIGHT_BULB,
             BlendMode.Additive
             );
     }
 }
Exemplo n.º 8
0
        public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
        {
            Body.Update(camera, TimeSpan.Zero, TimeSpan.Zero);
            var bhps = Body.GetHardpoints().Where((arg) => arg.Hp.Name.ToLowerInvariant() == "hp_head").First();

            Body.DrawBuffer(commands, transform, Lighting.Empty);
            Head.Update(camera, TimeSpan.Zero, TimeSpan.Zero);
            Head.DrawBuffer(commands, bhps.GetTransform(transform), Lighting.Empty);
            var hhps = Head.GetHardpoints().ToArray();

            LeftHand.Update(camera, TimeSpan.Zero, TimeSpan.Zero);
            var lhhps = LeftHand.GetHardpoints().ToArray();

            RightHand.Update(camera, TimeSpan.Zero, TimeSpan.Zero);
            var rhhps = RightHand.GetHardpoints().ToArray();
        }
Exemplo n.º 9
0
        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
                        );
                }
            }
        }
Exemplo n.º 10
0
 public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
 {
     for (int i = 0; i < renderCount; i++)
     {
         var p        = toRender[i];
         var currDist = (p.Position - p.Start).Length();
         if (p.Data.Munition.ConstEffect_Spear != null)
         {
             beams.AddBeamSpear(p.Position, p.Normal.Normalized(), p.Data.Munition.ConstEffect_Spear, currDist);
         }
         if (p.Data.Munition.ConstEffect_Bolt != null)
         {
             beams.AddBeamBolt(p.Position, p.Normal.Normalized(), p.Data.Munition.ConstEffect_Bolt, currDist);
         }
         if (p.Effect != null)
         {
             p.Effect.Draw(Matrix4x4.CreateTranslation(p.Position), 0);
         }
     }
 }
Exemplo n.º 11
0
 public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
 {
     if (frameStart)
     {
         sys.ResourceManager.TryGetShape("bulb", out bulbshape);
         bulbtex = (Texture2D)sys.ResourceManager.FindTexture(bulbshape.Texture);
         sys.ResourceManager.TryGetShape("shine", out shineshape);
         shinetex   = (Texture2D)sys.ResourceManager.FindTexture(shineshape.Texture);
         frameStart = false;
     }
     if (bulbtex == null || shinetex == null)
     {
         return;
     }
     sys.Billboards.Draw(
         shinetex,
         pos,
         new Vector2(equip.GlowSize) * 2,
         new Color4(colorGlow, 1f),
         new Vector2(shineshape.Dimensions.X, shineshape.Dimensions.Y),
         new Vector2(shineshape.Dimensions.X + shineshape.Dimensions.Width, shineshape.Dimensions.Y),
         new Vector2(shineshape.Dimensions.X, shineshape.Dimensions.Y + shineshape.Dimensions.Height),
         new Vector2(shineshape.Dimensions.X + shineshape.Dimensions.Width, shineshape.Dimensions.Y + shineshape.Dimensions.Height),
         0,
         SortLayers.LIGHT_SHINE,
         BlendMode.Additive
         );
     sys.Billboards.Draw(
         bulbtex,
         pos,
         new Vector2(equip.BulbSize) * 2,
         new Color4(colorBulb, 1),
         new Vector2(bulbshape.Dimensions.X, bulbshape.Dimensions.Y),
         new Vector2(bulbshape.Dimensions.X + bulbshape.Dimensions.Width, bulbshape.Dimensions.Y),
         new Vector2(bulbshape.Dimensions.X, bulbshape.Dimensions.Y + bulbshape.Dimensions.Height),
         new Vector2(bulbshape.Dimensions.X + bulbshape.Dimensions.Width, bulbshape.Dimensions.Y + bulbshape.Dimensions.Height),
         0,
         SortLayers.LIGHT_BULB,
         BlendMode.Additive
         );
 }
Exemplo n.º 12
0
        public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
        {
            Skeleton.GetTransforms(transform,
                                   out var headTransform,
                                   out var leftTransform,
                                   out var rightTransform
                                   );
            Skeleton.UploadBoneData(commands.BonesBuffer);
            var lighting = RenderHelpers.ApplyLights(
                lights, LightGroup,
                Vector3.Transform(Vector3.Zero, transform), RADIUS, nr,
                LitAmbient, LitDynamic, NoFog
                );

            Skeleton.Body.SetSkinning(Skeleton.BodySkinning);
            Skeleton.Body.Update(camera, 0.0, 0.0);
            Skeleton.Body.DrawBuffer(commands, transform, ref lighting);
            if (Skeleton.Head != null)
            {
                Skeleton.Head.SetSkinning(Skeleton.HeadSkinning);
                Skeleton.Head.Update(camera, 0.0, 0.0);
                Skeleton.Head.DrawBuffer(commands, headTransform, ref lighting);
            }
            if (Skeleton.LeftHand != null)
            {
                Skeleton.LeftHand.SetSkinning(Skeleton.LeftHandSkinning);
                Skeleton.LeftHand.Update(camera, 0.0, 0.0);
                Skeleton.LeftHand.DrawBuffer(commands, leftTransform, ref lighting);
            }
            if (Skeleton.RightHand != null)
            {
                Skeleton.RightHand.SetSkinning(Skeleton.RightHandSkinning);
                Skeleton.RightHand.Update(camera, 0.0, 0.0);
                Skeleton.RightHand.DrawBuffer(commands, rightTransform, ref lighting);
            }
        }
Exemplo n.º 13
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
                            );
                    }
                }
            }
        }
Exemplo n.º 14
0
        void LoadSystem(StarSystem system)
        {
            starSystem = system;

            if (StarSphereModels != null)
            {
                StarSphereModels = new CmpFile[0];
            }

            if (AsteroidFields != null)
            {
                foreach (var f in AsteroidFields)
                {
                    f.Dispose();
                }
            }

            cache.ClearTextures();

            //Load new system
            starSystem = system;

            List <IDrawable> starSphereRenderData = new List <IDrawable>();

            if (system.StarsBasic != null)
            {
                starSphereRenderData.Add(system.StarsBasic);
            }

            if (system.StarsComplex != null)
            {
                starSphereRenderData.Add(system.StarsComplex);
            }

            if (system.StarsNebula != null)
            {
                starSphereRenderData.Add(system.StarsNebula);
            }

            StarSphereModels = starSphereRenderData.ToArray();

            AsteroidFields = new List <AsteroidFieldRenderer>();
            if (system.AsteroidFields != null)
            {
                foreach (var a in system.AsteroidFields)
                {
                    AsteroidFields.Add(new AsteroidFieldRenderer(a, this));
                }
            }

            Nebulae = new List <NebulaRenderer>();
            if (system.Nebulae != null)
            {
                foreach (var n in system.Nebulae)
                {
                    Nebulae.Add(new NebulaRenderer(n, camera, Game));
                }
            }

            SystemLighting         = new SystemLighting();
            SystemLighting.Ambient = system.AmbientColor;
            foreach (var lt in system.LightSources)
            {
                SystemLighting.Lights.Add(new DynamicLight()
                {
                    Light = lt
                });
            }
        }
Exemplo n.º 15
0
        public static Lighting ApplyLights(SystemLighting src, int lightGroup, Vector3 c, float r, NebulaRenderer nebula, bool lambient = true, bool ldynamic = true, bool nofog = false)
        {
            var lights = Lighting.Create();

            lights.Ambient        = lambient ? src.Ambient : Color4.Black;
            lights.NumberOfTilesX = src.NumberOfTilesX;
            if (nofog)
            {
                lights.FogMode = FogModes.None;
            }
            else
            {
                lights.FogMode    = src.FogMode;
                lights.FogDensity = src.FogDensity;
                lights.FogColor   = src.FogColor;
                lights.FogRange   = src.FogRange;
            }
            int lc = 0;

            if (ldynamic)
            {
                lights.Lights.SourceLighting = src;
                for (int i = 0; i < src.Lights.Count; i++)
                {
                    if (src.Lights[i].LightGroup != lightGroup)
                    {
                        continue;
                    }
                    if (!src.Lights[i].Active)
                    {
                        continue;
                    }
                    var l  = src.Lights[i].Light;
                    var r2 = r + l.Range;
                    //l.Kind > 0 - test if not directional
                    if (l.Kind > 0 && VectorMath.DistanceSquared(l.Position, c) > (r2 * r2))
                    {
                        continue;
                    }
                    //Advanced spotlight cull
                    if ((l.Kind == LightKind.Spotlight) && SpotlightTest(ref l, c, r))
                    {
                        continue;
                    }
                    if ((lc + 1) > MAX_LIGHTS)
                    {
                        throw new Exception("Too many lights!");
                    }
                    lc++;
                    lights.Lights.SourceEnabled[i] = true;
                }
            }
            if (nebula != null)
            {
                Color4?     ambient;
                bool        fogenabled;
                Vector2     fogrange;
                Color4      fogcolor;
                RenderLight?lightning;
                nebula.GetLighting(out fogenabled, out ambient, out fogrange, out fogcolor, out lightning);
                if (ambient != null)
                {
                    lights.Ambient = ambient.Value;
                }
                if (fogenabled)
                {
                    lights.FogMode  = FogModes.Linear;
                    lights.FogColor = fogcolor;
                    lights.FogRange = fogrange;
                }
                if (lightning != null && src.NumberOfTilesX == -1)
                {
                    if ((lc + 1) > MAX_LIGHTS)
                    {
                        throw new Exception("Too many lights!");
                    }
                    lights.Lights.Nebula0     = lightning.Value;
                    lights.Lights.NebulaCount = 1;
                }
            }
            return(lights);
        }
Exemplo n.º 16
0
        public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
        {
            if (sysr == null || vertices == null)
            {
                return;
            }
            float z = RenderHelpers.GetZ(Matrix4x4.Identity, camera.Position, pos);

            if (z > 900000) // Reduce artefacts from fast Z-sort calculation. This'll probably cause issues somewhere else
            {
                z = 900000;
            }
            var dist_scale = nr != null ? nr.Nebula.SunBurnthroughScale : 1;
            var alpha      = nr != null ? nr.Nebula.SunBurnthroughIntensity : 1;

            if (radialShader == null)
            {
                radialShader = ShaderCache.Get("sun.vs", "sun_radial.frag");
                radialTex0   = radialShader.Shader.GetLocation("tex0");
                radialSize   = radialShader.Shader.GetLocation("SizeMultiplier");
                radialAlpha  = radialShader.Shader.GetLocation("outerAlpha");
            }
            if (spineShader == null)
            {
                spineShader = ShaderCache.Get("sun.vs", "sun_spine.frag");
                spineTex0   = spineShader.Shader.GetLocation("tex0");
                spineSize   = spineShader.Shader.GetLocation("SizeMultiplier");
            }
            radialShader.SetViewProjection(camera);
            radialShader.SetView(camera);
            spineShader.SetViewProjection(camera);
            spineShader.SetView(camera);

            int idx = sysr.StaticBillboards.DoVertices(ref ID, vertices);

            if (Sun.CenterSprite != null)
            {
                //draw center
                var cr = (Texture2D)sysr.ResourceManager.FindTexture(Sun.CenterSprite);
                commands.AddCommand(radialShader.Shader, RadialSetup, Cleanup, commands.WorldBuffer.Identity,
                                    new RenderUserData()
                {
                    Float = 0, Color = new Color4(dist_scale, alpha, 0, 0), Texture = cr
                }, sysr.StaticBillboards.VertexBuffer, PrimitiveTypes.TriangleList,
                                    idx, 2, true, SortLayers.SUN, z);
                //next
                idx += 6;
            }
            //draw glow
            var gr = (Texture2D)sysr.ResourceManager.FindTexture(Sun.GlowSprite);

            commands.AddCommand(radialShader.Shader, RadialSetup, Cleanup, commands.WorldBuffer.Identity,
                                new RenderUserData()
            {
                Float = 1, Color = new Color4(dist_scale, alpha, 0, 0), Texture = gr
            }, sysr.StaticBillboards.VertexBuffer, PrimitiveTypes.TriangleList,
                                idx, 2, true, SortLayers.SUN, z + 108f);
            //next
            idx += 6;
            //draw spines
            if (Sun.SpinesSprite != null && nr == null)
            {
                var spinetex = (Texture2D)sysr.ResourceManager.FindTexture(Sun.SpinesSprite);
                commands.AddCommand(spineShader.Shader, SpineSetup, Cleanup, commands.WorldBuffer.Identity,
                                    new RenderUserData()
                {
                    Texture = spinetex
                }, sysr.StaticBillboards.VertexBuffer, PrimitiveTypes.TriangleList,
                                    idx, 2 * Sun.Spines.Count, true, SortLayers.SUN, z + 1112f);
            }
        }
Exemplo n.º 17
0
 public abstract void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr);
Exemplo n.º 18
0
        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
                            );
                    }
                }
            }
        }
Exemplo n.º 19
0
 public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
 {
     Init();
     if (Dfm != null)
     {
         Dfm.Update(camera, TimeSpan.Zero, TimeSpan.FromSeconds(sysr.Game.TotalTime));
         var center = VectorMath.Transform(Vector3.Zero, World);
         //var lighting = RenderHelpers.ApplyLights(lights, LightGroup, center, 20, nr, LitAmbient, LitDynamic, NoFog);
         Dfm.DrawBuffer(commands, World, ref Lighting.Empty);
     }
     if (Model != null)
     {
         if (Model.Levels.Length > 0)
         {
             Model.Update(camera, TimeSpan.Zero, TimeSpan.FromSeconds(sysr.Game.TotalTime));
             var center = VectorMath.Transform(Model.Levels[0].Center, World);
             var lvl    = GetLevel(Model, center, camera.Position);
             if (lvl == null)
             {
                 return;
             }
             var lighting = RenderHelpers.ApplyLights(lights, LightGroup, center, Model.Levels[0].Radius, nr, LitAmbient, LitDynamic, NoFog);
             var r        = Model.Levels [0].Radius + lighting.FogRange.Y;
             if (lighting.FogMode != FogModes.Linear || VectorMath.DistanceSquared(camera.Position, center) <= (r * r))
             {
                 Model.DrawBufferLevel(lvl, commands, World, ref lighting);
             }
         }
     }
     else if (Cmp != null)
     {
         Cmp.Update(camera, TimeSpan.Zero, TimeSpan.FromSeconds(sysr.Game.TotalTime));
         foreach (Part p in Cmp.Parts)
         {
             var     model = p.Model;
             Matrix4 w     = World;
             if (p.Construct != null)
             {
                 w = p.Construct.Transform * World;
             }
             if (model.Levels.Length > 0)
             {
                 var center = VectorMath.Transform(model.Levels[0].Center, w);
                 var lvl    = GetLevel(model, center, camera.Position);
                 if (lvl == null)
                 {
                     continue;
                 }
                 var bsphere = new BoundingSphere(
                     center,
                     model.Levels[0].Radius
                     );
                 if (camera.Frustum.Intersects(bsphere))
                 {
                     var lighting = RenderHelpers.ApplyLights(lights, LightGroup, center, model.Levels[0].Radius, nr, LitAmbient, LitDynamic, NoFog);
                     var r        = model.Levels [0].Radius + lighting.FogRange.Y;
                     if (lighting.FogMode != FogModes.Linear || VectorMath.DistanceSquared(camera.Position, center) <= (r * r))
                     {
                         model.DrawBufferLevel(lvl, commands, w, ref lighting);
                     }
                 }
             }
         }
     }
     else if (CmpParts != null)
     {
         _parentCmp.Update(camera, TimeSpan.Zero, TimeSpan.FromSeconds(sysr.Game.TotalTime));
         foreach (Part p in CmpParts)
         {
             p.Update(camera, TimeSpan.Zero, TimeSpan.FromSeconds(sysr.Game.TotalTime));
             var     model = p.Model;
             Matrix4 w     = World;
             if (p.Construct != null)
             {
                 w = p.Construct.Transform * World;
             }
             if (model.Levels.Length > 0)
             {
                 var center = VectorMath.Transform(model.Levels[0].Center, w);
                 var lvl    = GetLevel(model, center, camera.Position);
                 if (lvl == null)
                 {
                     continue;
                 }
                 var bsphere = new BoundingSphere(
                     center,
                     model.Levels[0].Radius
                     );
                 if (camera.Frustum.Intersects(bsphere))
                 {
                     var lighting = RenderHelpers.ApplyLights(lights, LightGroup, center, model.Levels[0].Radius, nr, LitAmbient, LitDynamic, NoFog);
                     var r        = model.Levels[0].Radius + lighting.FogRange.Y;
                     if (lighting.FogMode != FogModes.Linear || VectorMath.DistanceSquared(camera.Position, center) <= (r * r))
                     {
                         model.DrawBufferLevel(lvl, commands, w, ref lighting);
                     }
                 }
             }
         }
     }
     else if (Sph != null)
     {
         Sph.Update(camera, TimeSpan.Zero, TimeSpan.FromSeconds(sysr.Game.TotalTime));
         var l = RenderHelpers.ApplyLights(lights, LightGroup, pos, Sph.Radius, nr, LitAmbient, LitDynamic, NoFog);
         var r = Sph.Radius + l.FogRange.Y;
         if (l.FogMode != FogModes.Linear || VectorMath.DistanceSquared(camera.Position, pos) <= (r * r))
         {
             Sph.DrawBuffer(commands, World, ref l);
         }
     }
 }
Exemplo n.º 20
0
        void LoadSystem(StarSystem system)
        {
            starSystem = system;

            if (StarSphereModels != null)
            {
                StarSphereModels = new RigidModel[0];
            }

            if (AsteroidFields != null)
            {
                foreach (var f in AsteroidFields)
                {
                    f.Dispose();
                }
            }

            //Load new system
            starSystem = system;

            List <RigidModel> starSphereRenderData = new List <RigidModel>();

            if (system.StarsBasic != null)
            {
                starSphereRenderData.Add((system.StarsBasic as IRigidModelFile).CreateRigidModel(true));
            }

            if (system.StarsComplex != null)
            {
                starSphereRenderData.Add((system.StarsComplex as IRigidModelFile).CreateRigidModel(true));
            }

            if (system.StarsNebula != null)
            {
                starSphereRenderData.Add((system.StarsNebula as IRigidModelFile).CreateRigidModel(true));
            }

            StarSphereModels = starSphereRenderData.ToArray();

            AsteroidFields = new List <AsteroidFieldRenderer>();
            if (system.AsteroidFields != null)
            {
                foreach (var a in system.AsteroidFields)
                {
                    AsteroidFields.Add(new AsteroidFieldRenderer(a, this));
                }
            }

            Nebulae = new List <NebulaRenderer>();
            if (system.Nebulae != null)
            {
                foreach (var n in system.Nebulae)
                {
                    Nebulae.Add(new NebulaRenderer(n, camera, Game, this));
                }
            }

            SystemLighting         = new SystemLighting();
            SystemLighting.Ambient = system.AmbientColor;
            foreach (var lt in system.LightSources)
            {
                SystemLighting.Lights.Add(new DynamicLight()
                {
                    Light = lt
                });
            }
        }