Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this also work in multiplayer? #1

Open
notcooler opened this issue Mar 31, 2024 · 6 comments
Open

Does this also work in multiplayer? #1

notcooler opened this issue Mar 31, 2024 · 6 comments
Assignees
Labels
core Core of the voxel generator (chunk management, rendering) enhancement New feature or request

Comments

@notcooler
Copy link

I dont see a reason why you have added networking to it as well?

@jedjoud10
Copy link
Owner

jedjoud10 commented Mar 31, 2024 via email

@notcooler
Copy link
Author

Btw, how does the seaming between chunks work can you show me which script handles that?

@jedjoud10
Copy link
Owner

jedjoud10 commented Apr 6, 2024

Since I use surface nets, the mesh vertices generated by the mesher might clip outside the boundary of a single chunk, so I just clip the vertices near chunk boundaries to the actual chunk boundaries. The script that handles this is the VertexJob file. I also extend the mesh downwards (towards the terrain) using skirts, so that you can't see the sky sphere or sky box within small gaps between chunks/

// Handle skirt vertex keko
if (math.any(skirts) && empty) {
if (voxels[index].density < 0.0 && voxels[index].density > minSkirtDensityThreshold) {
count = 1;
} else {
return;
}
}
// Must be offset by vec3(1, 1, 1)
int vertexIndex = counter.Increment();
indices[index] = vertexIndex;
// Output vertex in object space
float3 offset = (vertex / (float)count);
// Handle constricting the vertices in the axii
offset = math.select(offset, math.float3(0.0F), skirts);
float3 outputVertex = (offset - 1.0F) + position;
vertices[vertexIndex] = outputVertex * vertexScale * voxelScale;
// Calculate per vertex normals and apply it
normal = perVertexNormals ? -math.normalizesafe(normal, new float3(0, 1, 0)) : new float3(0, 1, 0);
normals[vertexIndex] = normal;

// Handle creating the skirt
if (skirt[i] && limiter) {
CheckEdge(position, i, true, end_[i]);
}

// Used for skirts
bool3 base_ = (position == math.uint3(1)) & skirtsBase;
bool3 end_ = (position == math.uint3(size - 2)) & skirtsEnd;
bool3 skirt = base_ | end_;

Normally for surface nets meshes you would use something like a full octree to be able to generate "seam" meshes that make the transition between chunks more smooth, but for now this method not only is very easy to implement but also doesn't introduce inter-chunk dependencies. I will improve it in the long run though because the seams are pretty noticeable in some cases.

On the topic of skirt generation, I should note that I had an idea for generating better skirts by first creating an SDF of the voxel terrain and then only generating the skirt vertices when getting a certain distance away from the isosurface. At the moment it is checking the density value instead, which fluctuates a lot and isn't really representative of the closest distance to the surface since the domain can be warped in many ways in the compute shader.

@jedjoud10 jedjoud10 added enhancement New feature or request core Core of the voxel generator (chunk management, rendering) labels Apr 7, 2024
@jedjoud10 jedjoud10 self-assigned this Apr 7, 2024
@jedjoud10
Copy link
Owner

As for multiplayer, I already have a crude implementation working (being able to load the same world and rendering props on all players) but nothing major so far. Next steps would be to send world information (seed value and parameters) to all clients and handle synchronized voxel/dynamic edits

@notcooler
Copy link
Author

So you just offset the vertices at the edge a bit further without knowing the data of the neighbour chunks right?

@jedjoud10
Copy link
Owner

Yes. It works most of the times but in some cases it creates "planar" surfaces with normals that differ too much from the actual surface, causing them to look very weird.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core of the voxel generator (chunk management, rendering) enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants