Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
Misc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver-makes-code committed Nov 25, 2023
1 parent d04a7e6 commit ca46842
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 35 deletions.
2 changes: 1 addition & 1 deletion AssetBuilder/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.IO.Compression;
using Tomlyn;

var outputDirectories = new[] {
string[] outputDirectories = {
"Release",
"Debug"
};
Expand Down
10 changes: 3 additions & 7 deletions Client/Content/shaders/simple.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ UnpackedVertex unpack(int packedColor, int packedUV) {
}

float singleInterp(float strength, float baseColor) {
if (baseColor >= 1)
return 1;
if (baseColor <= 0)
return 0;
float squared = baseColor * baseColor;
return squared + (squared - baseColor) * strength;
float min = 0.95 * baseColor * baseColor;
return min + (baseColor - min) * strength;
}

vec3 getColorMultiplier(float strength, vec3 baseColor) {
Expand All @@ -63,5 +59,5 @@ void main() {
UnpackedVertex up = unpack(PackedColor, PackedUV);
fsin_texCoords = up.uv;

fsin_Color = up.color * vec4(getColorMultiplier(AmbientOcclusion, vec3(0.95, 0.95, 1)), 1);
fsin_Color = up.color * vec4(getColorMultiplier(1-AmbientOcclusion, vec3(0.9, 0.9, 1)), 1);
}
2 changes: 1 addition & 1 deletion Client/Rendering/Models/BlockModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Voxel.Client.Rendering.Models;

public class BlockModel {
public BasicVertex[][] SidedVertices = new BasicVertex[7][];
public readonly BasicVertex[][] SidedVertices = new BasicVertex[7][];

public class Builder {
private readonly List<BasicVertex>[] CurrentSideCache = new List<BasicVertex>[7];
Expand Down
2 changes: 1 addition & 1 deletion Client/Rendering/Models/BlockModelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Voxel.Client.Rendering.Models;

public static class BlockModelManager {
private const float BlueTintAmount = 0.95f;
private const float BlueTintAmount = 0.9f;
private const string Suffix = ".json";

private static readonly string Prefix = Path.Combine("models", "block");
Expand Down
11 changes: 1 addition & 10 deletions Client/Rendering/Utils/ColorFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,7 @@ public static vec3 GetColorMultiplier(float strength, vec3 color) {
for (int i = 0; i < 3; i++) {
float currentColor = color[i];

if (currentColor <= 0) {
output[i] = 0;
continue;
}
if (currentColor >= 1) {
output[i] = 1;
continue;
}

float squaredColor = currentColor * currentColor;
float squaredColor = 0.95f * currentColor * currentColor;
output[i] = MathHelper.LerpF(squaredColor, currentColor, strength);
}

Expand Down
10 changes: 5 additions & 5 deletions Client/Rendering/World/ChunkMeshBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,23 @@ public bool Build(ChunkRenderSlot target, ivec3 worldPosition) {
position = worldPosition;

//Simply ignore empty chunks.
if (target.TargetChunk!.IsEmpty)
if (target.targetChunk!.IsEmpty)
return true;

//Copy snapshot of current adjacent chunk storage to a cache.
for (int i = 0; i < DiagonalSelfNeighborPositions.Length; i++) {
var pos = DiagonalSelfNeighborPositions[i] + target.TargetChunk!.ChunkPosition;
var pos = DiagonalSelfNeighborPositions[i] + target.targetChunk!.ChunkPosition;

if (!target.TargetChunk!.World.IsChunkLoadedRaw(pos))
if (!target.targetChunk!.World.IsChunkLoadedRaw(pos))
return false;
}


//TODO - Check if chunks exist BEFORE copying.
for (int i = 0; i < DiagonalSelfNeighborPositions.Length; i++) {
var pos = DiagonalSelfNeighborPositions[i] + target.TargetChunk!.ChunkPosition;
var pos = DiagonalSelfNeighborPositions[i] + target.targetChunk!.ChunkPosition;

if (target.TargetChunk!.World.TryGetChunkRaw(pos, out var c))
if (target.targetChunk!.World.TryGetChunkRaw(pos, out var c))
chunkStorages[i] = c.CopyStorage();
}

Expand Down
17 changes: 8 additions & 9 deletions Client/Rendering/World/ChunkRenderSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,26 @@ public class ChunkRenderSlot : Renderer {

public readonly ivec3 RelativePosition;
private readonly object MeshLock = new();


private ivec3 realPosition;

public uint? lastVersion;
public Chunk? targetChunk { get; private set; }

private ivec3 realPosition;
private ChunkMesh? mesh;

public Chunk? TargetChunk { get; private set; }

public ChunkRenderSlot(VoxelClient client, ivec3 relativePosition) : base(client) {
RelativePosition = relativePosition;
}

public override void Render(double delta) {

//Do nothing if this chunk render slot doesn't have a chunk yet, or if the chunk it does have is empty.
if (TargetChunk == null || TargetChunk.IsEmpty)
if (targetChunk == null || targetChunk.IsEmpty)
return;

//Console.Out.Write(lastVersion);

if (lastVersion != TargetChunk.GetVersion())
if (lastVersion != targetChunk.GetVersion())
Rebuild();

//Store this to prevent race conditions between == null and .render
Expand All @@ -52,7 +51,7 @@ public void Move(ivec3 newCenterPos) {
realPosition = newCenterPos + RelativePosition;

//Should never be null bc this only has 1 callsite that already null checks it
TargetChunk = Client.world!.GetOrCreateChunk(realPosition);
targetChunk = Client.world!.GetOrCreateChunk(realPosition);
lastVersion = null;
}

Expand All @@ -63,7 +62,7 @@ private void Rebuild() {

//Console.Out.WriteLine("Rebuild");

lastVersion = TargetChunk!.GetVersion();
lastVersion = targetChunk!.GetVersion();
}

public void SetMesh(ChunkMesh mesh) {
Expand Down
2 changes: 1 addition & 1 deletion Common/Util/MathHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Voxel.Common.Util;
public static class MathHelper {
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static float LerpF(float from, float to, float amount)
=> from + (from - to) * amount;
=> from + (to - from) * amount;
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static double LerpD(double from, double to, double amount)
=> from + (from - to) * amount;
Expand Down

0 comments on commit ca46842

Please sign in to comment.