public void DrawBuffer(CommandBuffer buffer, VMeshData data, ushort startVertex, Matrix4 world, Lighting light, MaterialAnimCollection mc) { if (Material == null) { return; } if (lastmc != mc) { if (mc != null) { mc.Anims.TryGetValue(Material.Name, out ma); lastmc = mc; } else { ma = null; } } float z = 0; if (Material.Render.IsTransparent) { z = RenderHelpers.GetZ(world, Material.Render.Camera.Position, CalculateAvg(data, startVertex)); } buffer.AddCommand( Material.Render, ma, world, light, data.VertexBuffer, PrimitiveTypes.TriangleList, startVertex + StartVertex, TriangleStart, primitiveCount, SortLayers.OBJECT, z ); }
public void DrawBuffer(CommandBuffer buffer, Matrix4 world, ref Lighting lighting, Material overrideMat = null) { if (SideMaterials.Length < 6) { return; } if (ready) { for (int i = 0; i < SideMaterials.Length; i++) { if (SideMaterials[i] != null && !SideMaterials[i].Loaded) { SideMaterials[i].Loaded = false; } } for (int i = 0; i < 6; i++) { int start, count; Vector3 pos; sphere.GetDrawParameters(faces[i], out start, out count, out pos); if (SideMaterials[i] == null) { SideMaterials[i] = library.FindMaterial(CrcTool.FLModelCrc(sideMaterialNames[i])); } var mat = SideMaterials[i] ?? defaultMaterial; mat = overrideMat ?? mat; mat.Render.Camera = _camera; var transform = Matrix4.CreateScale(Radius) * world; buffer.AddCommand( mat.Render, null, transform, lighting, sphere.VertexBuffer, PrimitiveTypes.TriangleList, 0, start, count, SortLayers.OBJECT ); } //Draw atmosphere if (SideMaterials.Length > 6 && overrideMat == null) { if (SideMaterials[6] == null) { SideMaterials[6] = library.FindMaterial(CrcTool.FLModelCrc(sideMaterialNames[6])); if (SideMaterials[6] == null) { return; } } var mat = (AtmosphereMaterial)SideMaterials[6].Render; var transform = Matrix4.CreateScale(Radius * mat.Scale) * world; for (int i = 0; i < 6; i++) { int start, count; Vector3 pos; sphere.GetDrawParameters(faces[i], out start, out count, out pos); SideMaterials[6].Render.Camera = _camera; buffer.AddCommand( SideMaterials[6].Render, null, transform, lighting, sphere.VertexBuffer, PrimitiveTypes.TriangleList, 0, start, count, SortLayers.OBJECT, RenderHelpers.GetZ(transform, _camera.Position, pos) ); } } } else { throw new Exception(); } }
public void DrawBeamApp(PolylineRender poly, float globalTime, NodeReference reference, ParticleEffectInstance instance, ref Matrix4x4 transform, float sparam) { //get particles! var beam = instance.Beams[reference.BeamIndex]; if (beam.ParticleCount < 2) { beam.ParticleCount = 0; return; } AgeComparer.Instance.Particles = instance.Pool.Particles; Array.Sort(beam.ParticleIndices, 0, beam.ParticleCount, AgeComparer.Instance); //draw var node_tr = GetAttachment(reference, transform); Texture2D tex; Vector2 tl, tr, bl, br; var res = instance.Resources; TextureHandler.Update(Texture, res); var frame = GetFrame(globalTime, sparam, ref instance.Pool.Particles[beam.ParticleIndices[0]]); int index = (int) Math.Floor((TextureHandler.FrameCount - 1) * frame) * 4; tl = TextureHandler.Coordinates[index]; tr = TextureHandler.Coordinates[index + 1]; bl = TextureHandler.Coordinates[index + 2]; br = TextureHandler.Coordinates[index + 3]; //Sorting hack kinda var z = RenderHelpers.GetZ(instance.Pool.Camera.Position, Vector3.Transform(Vector3.Zero, node_tr)); for (int j = 0; j < 2; j++) //two planes { poly.StartLine(TextureHandler.Texture ?? res.WhiteTexture, BlendInfo); bool odd = true; Vector3 dir = Vector3.Zero; for (int i = 0; i < beam.ParticleCount; i++) { var pos = Vector3.Transform(instance.Pool.Particles[beam.ParticleIndices[i]].Position, node_tr); if (i + 1 < beam.ParticleCount) { var pos2 = Vector3.Transform(instance.Pool.Particles[beam.ParticleIndices[i + 1]].Position, node_tr); var forward = (pos2 - pos).Normalized(); var toCamera = (instance.Pool.Camera.Position - pos).Normalized(); var up = Vector3.Cross(toCamera, forward); up.Normalize(); dir = up; if (j == 1) { //Broken? Doesn't show up var right = Vector3.Cross(up, forward).Normalized(); dir = right; } } var time = instance.Pool.Particles[beam.ParticleIndices[i]].TimeAlive / instance.Pool.Particles[beam.ParticleIndices[i]].LifeSpan; var w = Width.GetValue(sparam, time); poly.AddPoint( pos + (dir * w / 2), pos - (dir * w / 2), odd ? tl : bl, odd ? tr : br, new Color4( Color.GetValue(sparam, time), Alpha.GetValue(sparam, time) ) ); odd = !odd; } poly.FinishLine(z); } beam.ParticleCount = 0; }
public unsafe void DrawBeamApp(PolylineRender poly, LineBuffer points, float globalTime, NodeReference reference, ParticleEffectInstance instance, ResourceManager res, Billboards billboards, ref Matrix4 transform, float sparam) { //TODO: Cross-plane not showing //TODO: In some cases particles are going backwards? (Broken emitter or LineBuffer) //TODO: See if z sorting can be better for Polyline //TODO: Implement FLBeamAppearance properties if (points.Count() < 2) { return; } //Get only active indices, alloc on stack for 0 GC pressure //int* indices = stackalloc int[512]; var indices = new int[512]; var particles = new Particle[512]; for (int i = 0; i < 512; i++) { indices[i] = -1; } int ptCount = 0; for (int i = 0; i < points.Count(); i++) { if (points[i].Active) { indices[ptCount++] = points[i].ParticleIndex; } } if (ptCount < 2) { return; } for (int i = 0; i < ptCount; i++) { particles[i] = instance.Particles[indices[i]]; } for (int i = 1; i < ptCount; i++) { if (particles[i - 1].TimeAlive > particles[i].TimeAlive) { Console.WriteLine("bad order"); } } var node_tr = GetAttachment(reference, transform); Texture2D tex; Vector2 tl, tr, bl, br; HandleTexture(res, globalTime, sparam, ref instance.Particles[indices[0]], out tex, out tl, out tr, out bl, out br); //Sorting hack kinda var z = RenderHelpers.GetZ(billboards.Camera.Position, node_tr.Transform(Vector3.Zero)); for (int j = 0; j < 2; j++) //two planes { poly.StartLine(tex, BlendInfo); bool odd = true; Vector3 dir = Vector3.Zero; for (int i = 0; i < ptCount; i++) { var pos = node_tr.Transform(instance.Particles[indices[i]].Position); if (i + 1 < ptCount) { var pos2 = node_tr.Transform(instance.Particles[indices[i + 1]].Position); var forward = (pos2 - pos).Normalized(); var toCamera = (billboards.Camera.Position - pos).Normalized(); var up = Vector3.Cross(toCamera, forward); up.Normalize(); dir = up; if (j == 1) { //Broken? Doesn't show up var right = Vector3.Cross(up, forward).Normalized(); dir = right; } } var time = instance.Particles[indices[i]].TimeAlive / instance.Particles[indices[i]].LifeSpan; var w = Width.GetValue(sparam, time); poly.AddPoint( pos + (dir * w / 2), pos - (dir * w / 2), odd ? tl : bl, odd ? tr : br, new Color4( Color.GetValue(sparam, time), Alpha.GetValue(sparam, time) ) ); odd = !odd; } poly.FinishLine(z); } }