Ray Marching (Full C# & GDI+)
Vložit
- čas přidán 6. 09. 2024
- I've finally implemented Ray Marching in my engine, aiming to create interesting structures to navigate in three-dimensional space.
Unfortunately, even these basic shapes with flat colors are causing the performance to drop to 5 or 6 frames per second.
I'll continue my efforts to optimize it, but I'm starting to doubt if it really has a place in my engine...
For reference, this are two videos that helped me understand the concept.
• How to Make 3D Fractals
• I made this 3D game wi...
Quite impressive Adrian!
Not necessarily related to raymarching, but I've always wondered, is that background a skybox? 😅
Thanks, man! And yeah, it is a polygonal cubesphere.
However, adding spherical texture mapping for backgrounds is on my to-do list. Maybe I'll tackle that next.
Ooo this is an unexpected addition! Very cool. It's definitely hard to get great performance without parallel processing. How did you make the lattice shapes by the way??
Thanks, man!! I feel like parallel processing would bring a new set of problems, so I've been avoiding it.
Regarding the lattice shapes: they complement the others. The last one in the video is the complement of the space with the 'infinite spheres,' and the same applies to the cubic one.
For example, this is my code for the 'infinite spheres':
protected override float Scene(Vector3F vertex) {
vertex = vertex.Mod(256, 256, 256).Abs();
return vertex.Minus(128, 128, 128).GetNorm() - 64 /*radius of the sphere*/;
}
- "Scene" is the method that returns the next distance to advance to the next step.
- "vertex" is the current position of the algorithm.
- "Mod" applies modulo to every coordinate, creating an infinite repetition.
For the 'infinite holes,' it is the same, but subtracted from a constant (let's say 100):
100f - (vertex.Minus(128, 128, 128).GetNorm() - 64);
Then:
164f - vertex.Minus(128, 128, 128).GetNorm();
Finally:
protected override float Scene(Vector3F vertex) {
vertex = vertex.Mod(256, 256, 256).Abs();
return 164f - vertex.Minus(128, 128, 128).GetNorm();
}
Qué locura, se ve excelente. Es una locura que hayas hecho todo usando solamente GDI. Se pueden hacer efectos muy bonitos con esto que implementaste, no abusaría de ellos, pero los tendría en el código para usarlos cuando sea necesario. Muy bueno!
Gracias, loco! Hacía rato conocía el concepto de Ray Marching, pero no lo había implementado porque realmente no lo entendía. Vi varios videos, pero en ninguno explicaba lo suficientemente claro el concepto. Y de repente un día cayó la ficha y lo entendí. Eso no significa que sea capaz de renderizar cualquier escenario a gusto, como fractales complejas, pero al menos tengo claro cómo funciona.
Looks very cool. Raymarching makes it easier to render smooth shaded shapes, but not sure if the performance cost is worth it.
Yeah. If you check the videos I added as context in the description, using the GPU doesn't significantly impact performance. However, for software rendering, it's not looking promising.
I still have faith that I'll find a way to optimize my code enough for it to be useful.
Adrian let me see if i understood correctly, you mean the level is generated entirely by code? ooo another impressive project!
Thanks, man! And yeah, the environments are being render by the ray marching algorithm.
It's like, imagine you've a ray casting engine, but your map is just 2x2 cells, and only one is occupied. Like this:
1 0
0 0
Then, you cast the rays, as usual, but you apply modulo to every coordinate by the size of the 2x2 map (let's say, every cell is 128x128 pixels, so you take the modulus by 256). The rays will only check for walls in that small area, finding the same walls over and over again. Then, the map will repeat infinitely.
1 0 1 0 1 0 1 0 1 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 0 1 0 1 0 1 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0
That's basically it.
@@adrikriptok7225 it was a really easy to follow explanation, thank you! so that's why fractal :)
@@LeoOno You're welcome. I'm actually trying to create a scene like this with ray casting in 3D hoping that if the scene is very simple and enclosed enough, it can run at an acceptable speed. No luck yet.