mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Fog calculation should use camera position instead of entity's head position, fixes #191. (Thanks goodlyay)
This commit is contained in:
parent
3aca306645
commit
b352f1c7c9
@ -131,8 +131,6 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void SetFogStart( float value ) {
|
public override void SetFogStart( float value ) {
|
||||||
if( value == fogStart ) return;
|
|
||||||
fogStart = value;
|
|
||||||
device.SetRenderState( RenderState.FogStart, value );
|
device.SetRenderState( RenderState.FogStart, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,13 +81,13 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float lastFogStart = -1, lastFogEnd = -1, lastFogDensity = -1;
|
float lastFogEnd = -1, lastFogDensity = -1;
|
||||||
public override void SetFogDensity( float value ) {
|
public override void SetFogDensity( float value ) {
|
||||||
FogParam( FogParameter.FogDensity, value, ref lastFogDensity );
|
FogParam( FogParameter.FogDensity, value, ref lastFogDensity );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetFogStart( float value ) {
|
public override void SetFogStart( float value ) {
|
||||||
FogParam( FogParameter.FogStart, value, ref lastFogStart );
|
GL.Fogf( FogParameter.FogStart, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetFogEnd( float value ) {
|
public override void SetFogEnd( float value ) {
|
||||||
@ -95,10 +95,9 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void FogParam( FogParameter param, float value, ref float last ) {
|
static void FogParam( FogParameter param, float value, ref float last ) {
|
||||||
if( value != last ) {
|
if( value == last ) return;
|
||||||
GL.Fogf( param, value );
|
GL.Fogf( param, value );
|
||||||
last = value;
|
last = value;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Fog lastFogMode = (Fog)999;
|
Fog lastFogMode = (Fog)999;
|
||||||
|
@ -56,6 +56,13 @@ namespace ClassicalSharp {
|
|||||||
other.Max.X <= Max.X && other.Max.Y <= Max.Y && other.Max.Z <= Max.Z;
|
other.Max.X <= Max.X && other.Max.Y <= Max.Y && other.Max.Z <= Max.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Determines whether this bounding box entirely contains
|
||||||
|
/// the coordinates on all axes. </summary>
|
||||||
|
public bool Contains( Vector3 P ) {
|
||||||
|
return P.X >= Min.X && P.Y >= Min.Y && P.Z >= Min.Z &&
|
||||||
|
P.X <= Max.X && P.Y <= Max.Y && P.Z <= Max.Z;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Determines whether this bounding box intersects
|
/// <summary> Determines whether this bounding box intersects
|
||||||
/// the given bounding box on the X axis. </summary>
|
/// the given bounding box on the X axis. </summary>
|
||||||
public bool XIntersects( BoundingBox box ) {
|
public bool XIntersects( BoundingBox box ) {
|
||||||
|
@ -37,14 +37,14 @@ namespace ClassicalSharp.Renderers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RenderClouds( deltaTime );
|
RenderClouds( deltaTime );
|
||||||
ResetFog();
|
UpdateFog();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void EnvVariableChanged( object sender, EnvVarEventArgs e ) {
|
protected override void EnvVariableChanged( object sender, EnvVarEventArgs e ) {
|
||||||
if( e.Var == EnvVar.SkyColour ) {
|
if( e.Var == EnvVar.SkyColour ) {
|
||||||
ResetSky();
|
ResetSky();
|
||||||
} else if( e.Var == EnvVar.FogColour ) {
|
} else if( e.Var == EnvVar.FogColour ) {
|
||||||
ResetFog();
|
UpdateFog();
|
||||||
} else if( e.Var == EnvVar.CloudsColour ) {
|
} else if( e.Var == EnvVar.CloudsColour ) {
|
||||||
ResetClouds();
|
ResetClouds();
|
||||||
} else if( e.Var == EnvVar.CloudsLevel ) {
|
} else if( e.Var == EnvVar.CloudsLevel ) {
|
||||||
@ -55,6 +55,7 @@ namespace ClassicalSharp.Renderers {
|
|||||||
|
|
||||||
public override void Init( Game game ) {
|
public override void Init( Game game ) {
|
||||||
base.Init( game );
|
base.Init( game );
|
||||||
|
graphics.SetFogStart( 0 );
|
||||||
graphics.Fog = true;
|
graphics.Fog = true;
|
||||||
ResetAllEnv( null, null );
|
ResetAllEnv( null, null );
|
||||||
game.Events.ViewDistanceChanged += ResetAllEnv;
|
game.Events.ViewDistanceChanged += ResetAllEnv;
|
||||||
@ -73,7 +74,7 @@ namespace ClassicalSharp.Renderers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ResetAllEnv( object sender, EventArgs e ) {
|
void ResetAllEnv( object sender, EventArgs e ) {
|
||||||
ResetFog();
|
UpdateFog();
|
||||||
ResetSky();
|
ResetSky();
|
||||||
ResetClouds();
|
ResetClouds();
|
||||||
}
|
}
|
||||||
@ -116,30 +117,27 @@ namespace ClassicalSharp.Renderers {
|
|||||||
return blend;
|
return blend;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetFog() {
|
void UpdateFog() {
|
||||||
if( map.IsNotLoaded ) return;
|
if( map.IsNotLoaded ) return;
|
||||||
FastColour adjFogCol = FastColour.White;
|
FastColour adjFogCol = FastColour.White;
|
||||||
BlockInfo info = game.BlockInfo;
|
BlockInfo info = game.BlockInfo;
|
||||||
BoundingBox pBounds = game.LocalPlayer.CollisionBounds;
|
|
||||||
|
|
||||||
Vector3I headCoords = Vector3I.Floor( game.LocalPlayer.EyePosition );
|
Vector3 pos = game.CurrentCameraPos;
|
||||||
Vector3 pos = (Vector3)headCoords;
|
Vector3I coords = Vector3I.Floor( pos );
|
||||||
byte headBlock = game.World.SafeGetBlock( headCoords );
|
byte block = game.World.SafeGetBlock( coords );
|
||||||
BoundingBox blockBB = new BoundingBox( pos + game.BlockInfo.MinBB[headBlock],
|
BoundingBox blockBB = new BoundingBox(
|
||||||
pos + game.BlockInfo.MaxBB[headBlock] );
|
(Vector3)coords + info.MinBB[block],
|
||||||
BoundingBox localBB = game.LocalPlayer.CollisionBounds;
|
(Vector3)coords + info.MaxBB[block] );
|
||||||
bool intersecting = blockBB.Intersects( localBB );
|
|
||||||
|
|
||||||
if( intersecting && info.FogDensity[headBlock] != 0 ) {
|
if( blockBB.Contains( pos ) && info.FogDensity[block] != 0 ) {
|
||||||
graphics.SetFogMode( Fog.Exp );
|
graphics.SetFogMode( Fog.Exp );
|
||||||
graphics.SetFogDensity( info.FogDensity[headBlock] );
|
graphics.SetFogDensity( info.FogDensity[block] );
|
||||||
adjFogCol = info.FogColour[headBlock];
|
adjFogCol = info.FogColour[block];
|
||||||
} else {
|
} else {
|
||||||
// Blend fog and sky together
|
// Blend fog and sky together
|
||||||
float blend = (float)BlendFactor( game.ViewDistance );
|
float blend = (float)BlendFactor( game.ViewDistance );
|
||||||
adjFogCol = FastColour.Lerp( map.FogCol, map.SkyCol, blend );
|
adjFogCol = FastColour.Lerp( map.FogCol, map.SkyCol, blend );
|
||||||
graphics.SetFogMode( Fog.Linear );
|
graphics.SetFogMode( Fog.Linear );
|
||||||
graphics.SetFogStart( 0 );
|
|
||||||
graphics.SetFogEnd( game.ViewDistance );
|
graphics.SetFogEnd( game.ViewDistance );
|
||||||
}
|
}
|
||||||
graphics.ClearColour( adjFogCol );
|
graphics.ClearColour( adjFogCol );
|
||||||
@ -173,7 +171,7 @@ namespace ClassicalSharp.Renderers {
|
|||||||
extent = Utils.AdjViewDist( extent );
|
extent = Utils.AdjViewDist( extent );
|
||||||
int x1 = -extent, x2 = map.Width + extent;
|
int x1 = -extent, x2 = map.Width + extent;
|
||||||
int z1 = -extent, z2 = map.Length + extent;
|
int z1 = -extent, z2 = map.Length + extent;
|
||||||
skyVertices = Utils.CountVertices( x2 - x1, z2 - z1, axisSize );
|
skyVertices = Utils.CountVertices( x2 - x1, z2 - z1, axisSize );
|
||||||
|
|
||||||
VertexP3fC4b[] vertices = new VertexP3fC4b[skyVertices];
|
VertexP3fC4b[] vertices = new VertexP3fC4b[skyVertices];
|
||||||
int height = Math.Max( map.Height + 2 + 6, map.CloudHeight + 6);
|
int height = Math.Max( map.Height + 2 + 6, map.CloudHeight + 6);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user