public void Draw(CommandBuffer buffer, ICamera camera, Texture texture, Color4 color, Matrix4x4 world, bool inside) { if (texture == null) { lastIndex = currentIndex; return; } var z = RenderHelpers.GetZ(world, camera.Position, Vector3.Zero); var worldHandle = buffer.WorldBuffer.SubmitMatrix(ref world); buffer.AddCommand( shader, shaderDelegate, resetDelegate, worldHandle, new RenderUserData() { Color = color, Camera = camera, Texture = texture }, vbo, PrimitiveTypes.TriangleList, 0, lastIndex, (currentIndex - lastIndex) / 3, true, inside ? SortLayers.NEBULA_INSIDE : SortLayers.NEBULA_NORMAL, z ); lastIndex = currentIndex; }
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) ); } } }
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); } } } }
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; } }
public void DrawBuffer(int level, ResourceManager res, CommandBuffer buffer, Matrix4x4 world, ref Lighting lights, MaterialAnimCollection mc, Material overrideMat = null) { if (Levels == null || Levels.Length <= level) { return; } var l = Levels[level]; if (l == null) { return; } WorldMatrixHandle wm = buffer.WorldBuffer.SubmitMatrix(ref world); for (int i = 0; i < l.Length; i++) { var dc = l[i]; MaterialAnim ma = null; Material mat = overrideMat; if (mat == null) { mat = dc.GetMaterial(res); if (mat != null) { ma = dc.GetMaterialAnim(mc); } else { mat = res.DefaultMaterial; } } float z = 0; if (mat.Render.IsTransparent) { z = RenderHelpers.GetZ(world, mat.Render.Camera.Position, Center); } WorldMatrixHandle worldHandle = wm; if (dc.HasScale) { Matrix4x4 tr = dc.Scale * world; worldHandle = buffer.WorldBuffer.SubmitMatrix(ref tr); } buffer.AddCommand(mat.Render, ma, worldHandle, lights, dc.Buffer, PrimitiveTypes.TriangleList, dc.BaseVertex, dc.StartIndex, dc.PrimitiveCount, SortLayers.OBJECT, z ); } }
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 void DrawRectAppearance( Texture2D texture, Vector3 Position, Vector2 size, Color4 color, Vector2 topleft, Vector2 topright, Vector2 bottomleft, Vector2 bottomright, Vector3 normal, float angle, int layer, BlendMode blend = BlendMode.Normal ) { var up = normal; var toCamera = (camera.Position - Position).Normalized(); var right = Vector3.Cross(toCamera, up); up.Normalize(); right.Normalize(); rendat[billboardCount] = new RenderData( texture, blend, RenderKind.Basic, (ushort)vertexCountBasic ); //construct points then billboard them? CreateBillboard( Position, size, color, angle, topleft, topright, bottomleft, bottomright, right, up ); var z = RenderHelpers.GetZ(camera.Position, Position); buffer.AddCommand( this, rendat[billboardCount].GetHashCode(), billboardCount, layer, z ); billboardCount++; }
public void DrawPerspective( Texture2D texture, Vector3 Position, Vector2 size, Color4 color, Vector2 topleft, Vector2 topright, Vector2 bottomleft, Vector2 bottomright, Vector3 normal, float angle, int layer, BlendMode blend = BlendMode.Normal ) { var right = Vector3.Cross(normal, Vector3.UnitY); var up = Vector3.Cross(right, normal); up.Normalize(); right.Normalize(); rendat[billboardCount] = new RenderData( texture, blend, (ushort)vertexCount ); CreateBillboard( Position, size, color, angle, topleft, topright, bottomleft, bottomright, right, up ); var z = RenderHelpers.GetZ(camera.Position, Position); buffer.AddCommand( this, rendat[billboardCount].GetHashCode(), billboardCount, layer, z ); billboardCount++; }
public void Draw( Texture2D texture, Vector3 Position, Vector2 size, Color4 color, Vector2 topleft, Vector2 topright, Vector2 bottomleft, Vector2 bottomright, float angle, int layer, BlendMode blend = BlendMode.Normal ) { rendat[billboardCount] = new RenderData( texture, blend, RenderKind.Basic, (ushort)vertexCountBasic ); CreateBillboard( Position, size, color, angle, topleft, topright, bottomleft, bottomright ); var z = RenderHelpers.GetZ(camera.Position, Position); buffer.AddCommand( this, rendat[billboardCount].GetHashCode(), billboardCount, layer, z ); billboardCount++; }
public void DrawTri( Texture2D texture, Vector3 Position, float radius, Color4 color, Vector2 texa, Vector2 texb, Vector2 texc, float angle, int layer, BlendMode blend = BlendMode.Normal ) { rendat[billboardCount] = RenderData.CreateTri( texture, blend, (ushort)vertexCount ); CreateTriBillboard( Position, radius, color, angle, texa, texb, texc, camera.View.GetRight(), camera.View.GetUp() ); var z = RenderHelpers.GetZ(camera.Position, Position); buffer.AddCommand( this, rendat[billboardCount].GetHashCode(), billboardCount, layer, z ); billboardCount++; }
public void DrawCustomShader( Shader shader, ShaderAction setup, RenderUserData userData, Vector3 Position, Vector2 size, Color4 color, Vector2 topleft, Vector2 topright, Vector2 bottomleft, Vector2 bottomright, float angle, int layer, float z = float.NegativeInfinity ) { currentTexture = null; int vc = vertexCount; CreateBillboard( Position, size, color, angle, topleft, topright, bottomleft, bottomright ); buffer.AddCommand( this, shader, setup, userData, vc, layer, float.IsNegativeInfinity(z) ? RenderHelpers.GetZ(Matrix4.Identity, camera.Position, Position) : z ); }
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); } }
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 ); } } } }
public void DrawPerspective( Texture2D texture, Vector3 pos, Matrix4 world, Vector2 size, Color4 color, Vector2 topleft, Vector2 topright, Vector2 bottomleft, Vector2 bottomright, Vector3 normal, float angle, int layer, BlendMode blend = BlendMode.Normal ) { var upref = Vector3.UnitY; if ((Vector3.UnitY - normal).Length < float.Epsilon) { upref = Vector3.UnitZ; } var srcright = Vector3.Cross(normal, upref); var srcup = Vector3.Cross(srcright, normal); srcup.Normalize(); srcright.Normalize(); Vector3 up, right; if (Math.Abs(angle) < float.Epsilon) { up = srcup; right = srcright; } else { var s = (float)Math.Sin(angle); var c = (float)Math.Cos(angle); up = c * srcright - s * srcup; right = s * srcright + c * srcup; } rendat[billboardCount] = new RenderData( texture, blend, RenderKind.Rect, (ushort)vertexCountRect ); // var sz = 0.5f * size; verticesRect[vertexCountRect++] = new VertexPositionColorTexture( VectorMath.Transform( pos - right * sz.X - up * sz.Y, world ), color, bottomleft ); verticesRect[vertexCountRect++] = new VertexPositionColorTexture( VectorMath.Transform( pos + right * sz.X - up * sz.Y, world ), color, topleft ); verticesRect[vertexCountRect++] = new VertexPositionColorTexture( VectorMath.Transform( pos - right * sz.X + up * sz.Y, world ), color, bottomright ); verticesRect[vertexCountRect++] = new VertexPositionColorTexture( VectorMath.Transform( pos + right * sz.X + up * sz.Y, world ), color, topright ); // var z = RenderHelpers.GetZ(camera.Position, pos); buffer.AddCommand( this, rendat[billboardCount].GetHashCode(), billboardCount, layer, z ); billboardCount++; }
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); } }
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); } } }
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 ); } } } }