Fix selection outline writing to depth buffer when it should not be.

This commit is contained in:
UnknownShadow200 2016-07-07 22:59:52 +10:00
parent 7236028106
commit 1dd58bf874
6 changed files with 45 additions and 36 deletions

View file

@ -334,8 +334,10 @@ namespace ClassicalSharp {
MapRenderer.Render( delta );
MapBordersRenderer.RenderSides( delta );
if( SelectedPos.Valid && !HideGui )
Picking.Render( delta, SelectedPos );
if( SelectedPos.Valid && !HideGui ) {
Picking.UpdateState( SelectedPos );
Picking.Render( delta );
}
// Render water over translucent blocks when underwater for proper alpha blending
Vector3 pos = LocalPlayer.Position;
@ -348,6 +350,11 @@ namespace ClassicalSharp {
MapRenderer.RenderTranslucent( delta );
}
// Need to render again over top of translucent block, as the selection outline
// is drawn without writing to the depth buffer
if( SelectedPos.Valid && !HideGui && BlockInfo.IsTranslucent[SelectedPos.Block] )
Picking.Render( delta );
Entities.DrawShadows();
SelectionManager.Render( delta );
Entities.RenderHoveredNames( Graphics, delta, t );

View file

@ -29,7 +29,7 @@ namespace ClassicalSharp {
public CpeBlockFace BlockFace;
/// <summary> Block type of this selected block. </summary>
public byte BlockType;
public byte Block;
/// <summary> Mark this as having a selected block, and
/// calculates the closest block face of the selected position. </summary>
@ -39,7 +39,7 @@ namespace ClassicalSharp {
Max = max;
BlockPos = new Vector3I( x, y, z );
Valid = true;
BlockType = block;
Block = block;
IntersectPoint = intersect;
Vector3I normal = Vector3I.Zero;
@ -58,7 +58,7 @@ namespace ClassicalSharp {
Valid = false;
BlockPos = TranslatedPos = Vector3I.MinusOne;
BlockFace = (CpeBlockFace)255;
BlockType = 0;
Block = 0;
}
void TestAxis( float dAxis, ref float dist, Vector3I nAxis, ref Vector3I normal,

View file

@ -25,8 +25,7 @@ namespace ClassicalSharp.Selections {
}
public void Render( double delta ) {
if( !game.ShowAxisLines )
return;
if( !game.ShowAxisLines ) return;
if( vertices == null ) {
vertices = new VertexP3fC4b[12];
vb = game.Graphics.CreateDynamicVb( VertexFormat.P3fC4b, vertices.Length );

View file

@ -7,13 +7,13 @@ namespace ClassicalSharp.Renderers {
public sealed class PickedPosRenderer : IGameComponent {
IGraphicsApi graphics;
IGraphicsApi api;
Game game;
int vb;
public void Init( Game game ) {
graphics = game.Graphics;
vb = graphics.CreateDynamicVb( VertexFormat.P3fC4b, verticesCount );
api = game.Graphics;
vb = api.CreateDynamicVb( VertexFormat.P3fC4b, verticesCount );
this.game = game;
}
@ -21,7 +21,7 @@ namespace ClassicalSharp.Renderers {
public void Reset( Game game ) { }
public void OnNewMap( Game game ) { }
public void OnNewMapLoaded( Game game ) { }
public void Dispose() { graphics.DeleteDynamicVb( vb ); }
public void Dispose() { api.DeleteDynamicVb( vb ); }
FastColour col = new FastColour( 0, 0, 0, 102 );
int index;
@ -49,12 +49,14 @@ namespace ClassicalSharp.Renderers {
DrawLines( p1, p2, size );
}
public void Render( double delta, PickedPos pickedPos ) {
UpdateState( pickedPos );
graphics.AlphaBlending = true;
graphics.SetBatchFormat( VertexFormat.P3fC4b );
graphics.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, vertices, index, index * 6 / 4 );
graphics.AlphaBlending = false;
public void Render( double delta ) {
api.AlphaBlending = true;
api.DepthWrite = false;
api.SetBatchFormat( VertexFormat.P3fC4b );
api.UpdateDynamicIndexedVb( DrawMode.Triangles, vb, vertices, index, index * 6 / 4 );
api.AlphaBlending = false;
api.DepthWrite = true;
}
void DrawLines( Vector3 p1, Vector3 p2, float size ) {

View file

@ -62,7 +62,7 @@ namespace ClassicalSharp.TexturePack {
/// <summary> Runs through all animations and if necessary updates the terrain atlas. </summary>
public unsafe void Tick( double delta ) {
if( useLavaAnim ) DrawAnimation( null, 30, 16 );
if( useLavaAnim ) DrawAnimation( null, 30, LavaAnimation.Size );
if( animations.Count == 0 ) return;
if( animsBuffer == null ) {

View file

@ -7,10 +7,10 @@ using ClassicalSharp;
namespace ClassicalSharp {
public unsafe class LavaAnimation {
public const int size = 16;
float[] flameHeat = new float[size * size];
float[] potHeat = new float[size * size];
float[] soupHeat = new float[size * size];
public const int Size = 16;
float[] flameHeat = new float[Size * Size];
float[] potHeat = new float[Size * Size];
float[] soupHeat = new float[Size * Size];
JavaRandom rnd = null;
public unsafe void Tick( int* output ) {
@ -21,16 +21,16 @@ namespace ClassicalSharp {
}
void Step() {
int index = 0;
for( int y = 0; y < size; y++ )
for( int x = 0; x < size; x++ )
int i = 0;
for( int y = 0; y < Size; y++ )
for( int x = 0; x < Size; x++ )
{
float localSoupHeat = 0;
int xOffset = (int)(1.2 * Math.Sin( y * 22.5 * Utils.Deg2Rad ));
int yOffset = (int)(1.2 * Math.Sin( x * 22.5 * Utils.Deg2Rad ));
for( int i = 0; i < 9; i++ ) {
int xx = x + (i % 3 - 1) + xOffset;
int yy = y + (i / 3 - 1) + yOffset;
for( int j = 0; j < 9; j++ ) {
int xx = x + (j % 3 - 1) + xOffset;
int yy = y + (j / 3 - 1) + yOffset;
localSoupHeat += soupHeat[Index( xx, yy )];
}
@ -38,22 +38,23 @@ namespace ClassicalSharp {
potHeat[Index( x, y )] + potHeat[Index( x, y + 1 )] +
potHeat[Index( x + 1, y )] + potHeat[Index( x + 1, y + 1 )];
soupHeat[index] = localSoupHeat / 10 + localPotHeat / 4 * 0.8f;
potHeat[index] += flameHeat[index] * 0.01f;
if( potHeat[index] < 0 ) potHeat[index] = 0;
flameHeat[index] -= 0.06f;
soupHeat[i] = localSoupHeat / 10 + localPotHeat / 4 * 0.8f;
potHeat[i] += flameHeat[i] * 0.01f;
if( potHeat[i] < 0 ) potHeat[i] = 0;
flameHeat[i] -= 0.06f;
if( rnd.NextFloat() <= 0.005f )
flameHeat[index] = 1.5f;
index++;
flameHeat[i] = 1.5f;
i++;
}
}
void Output( int* ptr ) {
int index = 0;
for( int i = 0; i < soupHeat.Length; i++) {
float col = 2 * soupHeat[i];
Utils.Clamp( ref col, 0, 1 );
col = col < 0 ? 0 : col;
col = col > 1 ? 1 : col;
float r = col * 100 + 155;
float g = col * col * 255;
float b = col * col * col * col * 128;