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);
             }
         }
     }
 }
Beispiel #2
0
 void UpdateStarsphere()
 {
     for (int i = 0; i < starSphereObjects.Length; i++)
     {
         Renderer.StarSphereWorlds[i] = starSphereObjects[i].Rotate * Matrix4x4.CreateTranslation(starSphereObjects[i].Translate);
         var ldynamic = (starSphereObjects[i].Entity.ObjectFlags & ThnObjectFlags.LitDynamic) == ThnObjectFlags.LitDynamic;
         var lambient = (starSphereObjects[i].Entity.ObjectFlags & ThnObjectFlags.LitAmbient) == ThnObjectFlags.LitAmbient;
         var nofog = starSphereObjects[i].Entity.NoFog;
         Renderer.StarSphereLightings[i] = RenderHelpers.ApplyLights(Renderer.SystemLighting,
             starSphereObjects[i].Entity.LightGroup, Vector3.Zero, float.MaxValue, null,
             lambient, ldynamic, nofog);
     }
 }
        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);
            }
        }
Beispiel #4
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);
         }
     }
 }
Beispiel #5
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
                            );
                    }
                }
            }
        }