RedTShirtGaming
RedTShirtGaming
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
at the minute, a single vertex in a chunk uses 32 bytes of memory but my chunks are 16x16x16 (might increase to 32x32x32) which doesn't need 3 floats for position and could definetely use 6-7 bits instead. Normals could use an integer like the video showed as well. And texture coordinates can be computed in the vertex shader using a single uint for voxel id. I'll see if I can start implementing that. I did follow a video tutorial about a year ago on how to recreate minecraft in python using pygame and they condensed the vertex data into a single number and it did really help performance
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
The main thing I've noticed from this video that will probably help a lot is memory usage. Currently, when the player moves X distance from a chunk, it gets destroyed and the reference lost. If I optimise the memory usage to a single 32-bit integer, I could keep a reference to every chunk that has been generated (maybe destroy very old chunks or something) so the chunk doesn't need to be reconstructed when it is reloaded.
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
https://www.youtube.com/watch?v=C1H4zIiCOaI&ab_channel=SebastianLague
I love this guy, I saw this video and it gave me the idea to subdivide chunks using a BVH as I had heard a bit about them from an interview with the teardown developer but I didn't really know much about it. But instead of checking a 32x32x32 chunk, it could first check 8 smaller chunks and keep narrowing it down until there are only 8 voxels to do the intersection tests on or something which will be (in theory) very fast
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
i think my only other option is to do what teardown does and ray trace all of the voxels, which I have actually been working on for a few week but its just taking a lot of time figuring out how to generate a BVH for the chunks. or i try to add greedy meshing which might end up being slower as actually drawing the triangles is pretty fast
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
if I've understood them correctly, I could use GL_TRIANGLE_STRIP and that could save a few vertices? currently each voxel gets its own set of vertices which is probably inefficient
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
i think i've seen those options come up for the index buffers, never used them though
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
unity has a function for directly drawing data from a gpu buffer so if opengl has something like that, I probably won't even need to send the data back to the cpu
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
i mean if i program it to make use of the gpu's parallel processing, i could process each voxel in parallel which would generate the chunk in a fraction of the time so it doesn't really matter if the sending and getting data from the gpu is a bit slow as the chunk building is really fast.
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
cant u compute the vertices, their normals and texture coords on the gpu side?
Through a compute shader? The texture coords probably can be done in the vertex/fragment shader though
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
Would it still work for procedurally generated chunks?
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
It's a function that takes an array of voxel data (a uint array) and creates a float array with all the vertex, uv, and normal data needed to render that chunk. Also, if the player isn't moving much, this function isn't ran as it only builds chunks that haven't yet been generated around the player. Also, the time to run it completely depends on chunk size, and how many voxels aren't air.
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
The 5 seconds is much longer than the actual function takes to run, the full function takes about 250-300ms to run but it's noticeable when the function is being called many times per frame. The 5 second delay was mostly to give me enough time to see if that function is blocking the main thread or not
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
yeah, I just need my data (which is a float[]) to be generated somewhere (main thread or background thread, background thread preferred) and then the gl calls to be ran on the main thread but in that order.
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
yeah same, only ever done stuff from the main thread.
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
I mean GL.GetError worked so I think it's fine. Thanks for your help! :D
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
Just got a basic implementation working, and Engine.IsMainThread is returning true which is exactly what I wanted, thank you! Last question, I'm calling each of the actions in the update loop, so why would opengl functions not work (not rendering, but things like GL.BindBuffer, GL.CreateBuffer, etc)?
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
So instead of just running the last bit of code that needs to be on the main thread, the function could look a bit like this? And I can't call any GL functions from those tasks that are being ran on the main thread?
internal static async Task GenerateChunkAsync(Dictionary<Vector3Int, Chunk> chunks)
{
// Any main-thread setup here

var chunkData = await Task.Run(() =>
{
// Execute code on a background thread
var data = SomeFunc(5);
return data;
});

// add a function to be called by the main thread at some point in the update loop
Engine.AddMainThreadFunction(() => {
Console.WriteLine("This should be running on the main thread");
GL.BindBuffer(...); // This won't work as opengl stuff cant be called from here
});
}
internal static async Task GenerateChunkAsync(Dictionary<Vector3Int, Chunk> chunks)
{
// Any main-thread setup here

var chunkData = await Task.Run(() =>
{
// Execute code on a background thread
var data = SomeFunc(5);
return data;
});

// add a function to be called by the main thread at some point in the update loop
Engine.AddMainThreadFunction(() => {
Console.WriteLine("This should be running on the main thread");
GL.BindBuffer(...); // This won't work as opengl stuff cant be called from here
});
}
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
oh. Are there any other ways of being able to run a function on another thread and returning control to the main thread? Like are there any libraries that can take care of that? when ive done a bit of async stuff, its always been in unity which has a synchronisation context and all of that stuff as i basically copied the above code from a unity project where it worked
60 replies
CC#
Created by RedTShirtGaming on 7/4/2024 in #help
async functions always finish on a background thread
how difficult is it (if even possible) to setup my own synchronisation context?
60 replies
VVALORANT
Created by James on 4/2/2024 in #community-help
Gun buddies need info
Np, that actually would be kind of cool tho
4 replies