From 896408a7514b535ca6b1fc745e8fa7c7227ada1c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 6 Sep 2015 18:04:12 +1000 Subject: [PATCH] Particles should use shadow colour when in shadow, fixes #59. --- ClassicalSharp/Entities/Particles/Particle.cs | 2 +- .../Entities/Particles/ParticleManager.cs | 8 ++++---- .../Entities/Particles/TerrainParticle.cs | 14 ++++++++------ ClassicalSharp/GraphicsAPI/VertexFormats.cs | 6 ++++++ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/ClassicalSharp/Entities/Particles/Particle.cs b/ClassicalSharp/Entities/Particles/Particle.cs index d97e15c6f..5fd736ab2 100644 --- a/ClassicalSharp/Entities/Particles/Particle.cs +++ b/ClassicalSharp/Entities/Particles/Particle.cs @@ -13,7 +13,7 @@ namespace ClassicalSharp.Particles { protected Game game; protected Vector3 lastPos, nextPos; - public abstract void Render( double delta, float t, VertexPos3fTex2f[] vertices, ref int index ); + public abstract void Render( double delta, float t, VertexPos3fTex2fCol4b[] vertices, ref int index ); public abstract void Dispose(); diff --git a/ClassicalSharp/Entities/Particles/ParticleManager.cs b/ClassicalSharp/Entities/Particles/ParticleManager.cs index 405bf0636..8e4c3b682 100644 --- a/ClassicalSharp/Entities/Particles/ParticleManager.cs +++ b/ClassicalSharp/Entities/Particles/ParticleManager.cs @@ -15,16 +15,16 @@ namespace ClassicalSharp.Particles { public ParticleManager( Game game ) { this.game = game; graphics = game.Graphics; - vb = graphics.CreateDynamicVb( VertexFormat.Pos3fTex2f, 1000 ); + vb = graphics.CreateDynamicVb( VertexFormat.Pos3fTex2fCol4b, 1000 ); } - VertexPos3fTex2f[] vertices = new VertexPos3fTex2f[0]; + VertexPos3fTex2fCol4b[] vertices = new VertexPos3fTex2fCol4b[0]; public void Render( double delta, float t ) { if( particles.Count == 0 ) return; int count = particles.Count * 6; if( count > vertices.Length ) { - vertices = new VertexPos3fTex2f[count]; + vertices = new VertexPos3fTex2fCol4b[count]; } int index = 0; for( int i = 0; i < particles.Count; i++ ) { @@ -36,7 +36,7 @@ namespace ClassicalSharp.Particles { graphics.AlphaTest = true; count = Math.Min( count, 1000 ); - graphics.BeginVbBatch( VertexFormat.Pos3fTex2f ); + graphics.BeginVbBatch( VertexFormat.Pos3fTex2fCol4b ); graphics.DrawDynamicIndexedVb( DrawMode.Triangles, vb, vertices, count, count * 6 / 4 ); graphics.AlphaTest = false; graphics.Texturing = false; diff --git a/ClassicalSharp/Entities/Particles/TerrainParticle.cs b/ClassicalSharp/Entities/Particles/TerrainParticle.cs index fe120d594..25297aaf5 100644 --- a/ClassicalSharp/Entities/Particles/TerrainParticle.cs +++ b/ClassicalSharp/Entities/Particles/TerrainParticle.cs @@ -13,15 +13,17 @@ namespace ClassicalSharp.Particles { maxY = Position.Y; } - public override void Render( double delta, float t, VertexPos3fTex2f[] vertices, ref int index ) { + public override void Render( double delta, float t, VertexPos3fTex2fCol4b[] vertices, ref int index ) { Position = Vector3.Lerp( lastPos, nextPos, t ); Vector3 p111, p121, p212, p222; TranslatePoints( out p111, out p121, out p212, out p222 ); - - vertices[index++] = new VertexPos3fTex2f( p111, Rectangle.U1, Rectangle.V2 ); - vertices[index++] = new VertexPos3fTex2f( p121, Rectangle.U1, Rectangle.V1 ); - vertices[index++] = new VertexPos3fTex2f( p222, Rectangle.U2, Rectangle.V1 ); - vertices[index++] = new VertexPos3fTex2f( p212, Rectangle.U2, Rectangle.V2 ); + Map map = game.Map; + FastColour col = map.IsLit( Vector3I.Floor( Position ) ) ? map.Sunlight : map.Shadowlight; + + vertices[index++] = new VertexPos3fTex2fCol4b( p111, Rectangle.U1, Rectangle.V2, col ); + vertices[index++] = new VertexPos3fTex2fCol4b( p121, Rectangle.U1, Rectangle.V1, col ); + vertices[index++] = new VertexPos3fTex2fCol4b( p222, Rectangle.U2, Rectangle.V1, col ); + vertices[index++] = new VertexPos3fTex2fCol4b( p212, Rectangle.U2, Rectangle.V2, col ); } public override bool Tick( double delta ) { diff --git a/ClassicalSharp/GraphicsAPI/VertexFormats.cs b/ClassicalSharp/GraphicsAPI/VertexFormats.cs index a556199cd..838c419d7 100644 --- a/ClassicalSharp/GraphicsAPI/VertexFormats.cs +++ b/ClassicalSharp/GraphicsAPI/VertexFormats.cs @@ -62,6 +62,12 @@ namespace ClassicalSharp { R = c.R; G = c.G; B = c.B; A = c.A; } + public VertexPos3fTex2fCol4b( Vector3 p, float u, float v, FastColour c ) { + X = p.X; Y = p.Y; Z = p.Z; + U = u; V = v; + R = c.R; G = c.G; B = c.B; A = c.A; + } + public VertexPos3fTex2fCol4b( float x, float y, float z, float u, float v, Color c ) { X = x; Y = y; Z = z; U = u; V = v;