Skip to content

Commit

Permalink
Part 11 Smooth normals!
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelreyn committed Jun 15, 2022
1 parent e4fc6ba commit 7c3cf1a
Show file tree
Hide file tree
Showing 15 changed files with 383 additions and 380 deletions.
6 changes: 3 additions & 3 deletions Assets/VoxelProjectSeries/Scenes/World.unity
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,13 @@ MonoBehaviour:
metallic: 0.2
smoothness: 0.5
worldSettings:
chunkSize: 16
chunkSize: 32
maxHeight: 256
renderDistance: 64
renderDistance: 32
sharedVertices: 0
useTextures: 1
mainCamera: {fileID: 414495109}
maxChunksToProcessPerFrame: 6
maxChunksToProcessPerFrame: 3
--- !u!114 &1755072227
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ uint oceanHeight;
int noiseCount;
int seed;

int flattenCoord(uint3 idx)
uint flattenCoord(float3 idx)
{
return idx.x + (idx.y * (chunkSizeX + 3)) + (idx.z * (chunkSizeX + 3) * (chunkSizeY + 1));
return round(idx.x) + (round(idx.y) * (chunkSizeX + 5)) + (round(idx.z) * (chunkSizeX + 5) * (chunkSizeY + 1));
}

float evaluateNoise(float3 pos, float terrainHeight)
Expand Down Expand Up @@ -98,9 +98,11 @@ bool getDensityAtPoint(float3 pos, out int roundedHeight, out float density)


[numthreads(8, 8, 8)]
void FillArray(uint3 id : SV_DispatchThreadID)
void FillArray(uint3 i : SV_DispatchThreadID)
{
if (any(id.xz > chunkSizeX + 2))
float3 id = float3(i);

if (any(id.xz > chunkSizeX + 3))
return;

float3 pos = id + chunkPosition + seedOffset;
Expand Down Expand Up @@ -141,11 +143,11 @@ void FillArray(uint3 id : SV_DispatchThreadID)

if (id.y == (uint) roundedHeight && voxelId != 0 && id.y < 240)
{
bool placeFoliage = noise(float3(posXZ * 2, seed)) > 0.999;
bool placeFoliage = hnoise(float3(posXZ * 2, seed)) > 0.999;
//placeFoliage = false;
if (placeFoliage)
{
int typeOf = noise(float3(pos.xz * 25, seed)) * 75;
int typeOf = hnoise(float3(pos.xz * 25, seed)) * 75;
int foliageID;
if (typeOf < 30)
foliageID = 243;
Expand Down Expand Up @@ -182,8 +184,9 @@ void FillArray(uint3 id : SV_DispatchThreadID)
}

[numthreads(8, 8, 8)]
void ClearArray(uint3 id : SV_DispatchThreadID)
void ClearArray(uint3 i : SV_DispatchThreadID)
{
float3 id = float3(i);
Voxel emptyVoxel;
emptyVoxel.voxelData = 0;
emptyVoxel.densityData = 0u;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ float hash(float3 p) // replace this by something better
return frac(p.x * p.y * p.z * (p.x + p.y + p.z));
}

float noise(in float3 x)
float hnoise(in float3 x)
{
float3 i = floor(x);
float3 f = frac(x);
Expand Down
202 changes: 0 additions & 202 deletions Assets/VoxelProjectSeries/Scripts/ComputeShaders/VoxelCompute.compute

This file was deleted.

Loading

0 comments on commit 7c3cf1a

Please sign in to comment.