mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-25 18:42:08 -05:00
Client: Use better fog colour when in fast render mode.
This commit is contained in:
parent
67f98eb825
commit
2ca63e97d1
4 changed files with 60 additions and 45 deletions
|
@ -3,13 +3,13 @@ using System;
|
|||
using ClassicalSharp.Events;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
using ClassicalSharp.Map;
|
||||
using OpenTK;
|
||||
|
||||
namespace ClassicalSharp.Renderers {
|
||||
|
||||
public abstract class EnvRenderer : IGameComponent {
|
||||
|
||||
protected World map;
|
||||
protected Game game;
|
||||
protected Game game;
|
||||
protected IGraphicsApi graphics;
|
||||
|
||||
public virtual void Init( Game game ) {
|
||||
|
@ -21,7 +21,7 @@ namespace ClassicalSharp.Renderers {
|
|||
|
||||
public virtual void UseLegacyMode( bool legacy ) { }
|
||||
|
||||
public void Ready( Game game ) { }
|
||||
public void Ready( Game game ) { }
|
||||
public virtual void Reset( Game game ) { OnNewMap( game ); }
|
||||
|
||||
public abstract void OnNewMap( Game game );
|
||||
|
@ -35,5 +35,36 @@ namespace ClassicalSharp.Renderers {
|
|||
public abstract void Render( double deltaTime );
|
||||
|
||||
protected abstract void EnvVariableChanged( object sender, EnvVarEventArgs e );
|
||||
|
||||
|
||||
protected byte BlockOn( out float fogDensity, out FastColour fogCol ) {
|
||||
BlockInfo info = game.BlockInfo;
|
||||
Vector3 pos = game.CurrentCameraPos;
|
||||
Vector3I coords = Vector3I.Floor( pos );
|
||||
|
||||
byte block = game.World.SafeGetBlock( coords );
|
||||
AABB blockBB = new AABB(
|
||||
(Vector3)coords + info.MinBB[block],
|
||||
(Vector3)coords + info.MaxBB[block] );
|
||||
|
||||
if( blockBB.Contains( pos ) && info.FogDensity[block] != 0 ) {
|
||||
fogDensity = info.FogDensity[block];
|
||||
fogCol = info.FogColour[block];
|
||||
} else {
|
||||
fogDensity = 0;
|
||||
// Blend fog and sky together
|
||||
float blend = (float)BlendFactor( game.ViewDistance );
|
||||
fogCol = FastColour.Lerp( map.Env.FogCol, map.Env.SkyCol, blend );
|
||||
}
|
||||
return block;
|
||||
}
|
||||
|
||||
double BlendFactor( int x ) {
|
||||
//return -0.05 + 0.22 * Math.Log( Math.Pow( x, 0.25 ) );
|
||||
double blend = -0.13 + 0.28 * Math.Log( Math.Pow( x, 0.25 ) );
|
||||
if( blend < 0 ) blend = 0;
|
||||
if( blend > 1 ) blend = 1;
|
||||
return blend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -192,17 +192,23 @@ namespace ClassicalSharp.Renderers {
|
|||
int col = fullColEdge ? FastColour.WhitePacked : map.Env.Sun;
|
||||
for( int i = 0; i < rects.Length; i++ ) {
|
||||
Rectangle r = rects[i];
|
||||
DrawY( r.X, r.Y, r.X + r.Width, r.Y + r.Height, y, axisSize, col, -0.1f/16, YOffset( block ), ref v );
|
||||
DrawY( r.X, r.Y, r.X + r.Width, r.Y + r.Height, y, axisSize, col,
|
||||
HorOffset( block ), YOffset( block ), ref v );
|
||||
}
|
||||
edgesVb = graphics.CreateVb( ptr, VertexFormat.P3fT2fC4b, edgesVertices );
|
||||
}
|
||||
|
||||
float HorOffset( byte block ) {
|
||||
BlockInfo info = game.BlockInfo;
|
||||
if( info.IsLiquid( block ) ) return -0.1f/16;
|
||||
if( info.IsTranslucent[block] && info.Collide[block] != CollideType.Solid ) return 0.1f/16;
|
||||
return 0;
|
||||
}
|
||||
|
||||
float YOffset( byte block ) {
|
||||
BlockInfo info = game.BlockInfo;
|
||||
if( info.IsLiquid( block ) )
|
||||
return -1.5f/16;
|
||||
if( info.IsTranslucent[block] && info.Collide[block] != CollideType.Solid )
|
||||
return -0.1f/16;
|
||||
if( info.IsLiquid( block ) ) return -1.5f/16;
|
||||
if( info.IsTranslucent[block] && info.Collide[block] != CollideType.Solid ) return -0.1f/16;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,19 +15,15 @@ namespace ClassicalSharp.Renderers {
|
|||
}
|
||||
|
||||
public override void Render( double deltaTime ) {
|
||||
graphics.ClearColour( map.Env.SkyCol );
|
||||
if( map.IsNotLoaded ) return;
|
||||
FastColour fogCol = FastColour.White;
|
||||
float fogDensity = 0;
|
||||
byte block = BlockOn( out fogDensity, out fogCol );
|
||||
graphics.ClearColour( fogCol );
|
||||
}
|
||||
|
||||
public override void OnNewMap( Game game ) { }
|
||||
|
||||
public override void OnNewMapLoaded( Game game ) {
|
||||
graphics.ClearColour( map.Env.SkyCol );
|
||||
}
|
||||
|
||||
protected override void EnvVariableChanged( object sender, EnvVarEventArgs e ) {
|
||||
if( e.Var == EnvVar.SkyColour ) {
|
||||
graphics.ClearColour( map.Env.SkyCol );
|
||||
}
|
||||
}
|
||||
public override void OnNewMap( Game game ) { }
|
||||
public override void OnNewMapLoaded( Game game ) { }
|
||||
protected override void EnvVariableChanged( object sender, EnvVarEventArgs e ) { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,39 +114,21 @@ namespace ClassicalSharp.Renderers {
|
|||
graphics.SetMatrixMode( MatrixType.Modelview );
|
||||
}
|
||||
|
||||
double BlendFactor( int x ) {
|
||||
//return -0.05 + 0.22 * Math.Log( Math.Pow( x, 0.25 ) );
|
||||
double blend = -0.13 + 0.28 * Math.Log( Math.Pow( x, 0.25 ) );
|
||||
if( blend < 0 ) blend = 0;
|
||||
if( blend > 1 ) blend = 1;
|
||||
return blend;
|
||||
}
|
||||
|
||||
void UpdateFog() {
|
||||
if( map.IsNotLoaded ) return;
|
||||
FastColour adjFogCol = FastColour.White;
|
||||
BlockInfo info = game.BlockInfo;
|
||||
FastColour fogCol = FastColour.White;
|
||||
float fogDensity = 0;
|
||||
byte block = BlockOn( out fogDensity, out fogCol );
|
||||
|
||||
Vector3 pos = game.CurrentCameraPos;
|
||||
Vector3I coords = Vector3I.Floor( pos );
|
||||
byte block = game.World.SafeGetBlock( coords );
|
||||
AABB blockBB = new AABB(
|
||||
(Vector3)coords + info.MinBB[block],
|
||||
(Vector3)coords + info.MaxBB[block] );
|
||||
|
||||
if( blockBB.Contains( pos ) && info.FogDensity[block] != 0 ) {
|
||||
if( fogDensity != 0 ) {
|
||||
graphics.SetFogMode( Fog.Exp );
|
||||
graphics.SetFogDensity( info.FogDensity[block] );
|
||||
adjFogCol = info.FogColour[block];
|
||||
graphics.SetFogDensity( fogDensity );
|
||||
} else {
|
||||
// Blend fog and sky together
|
||||
float blend = (float)BlendFactor( game.ViewDistance );
|
||||
adjFogCol = FastColour.Lerp( map.Env.FogCol, map.Env.SkyCol, blend );
|
||||
graphics.SetFogMode( Fog.Linear );
|
||||
graphics.SetFogEnd( game.ViewDistance );
|
||||
}
|
||||
graphics.ClearColour( adjFogCol );
|
||||
graphics.SetFogColour( adjFogCol );
|
||||
graphics.ClearColour( fogCol );
|
||||
graphics.SetFogColour( fogCol );
|
||||
}
|
||||
|
||||
void ResetClouds() {
|
||||
|
|
Loading…
Add table
Reference in a new issue