2

Im making simple fps game using raycasting, because I thought its very fast and light method. My Raycasting function saves data in to a vertex array, which is then rendered by OpenGl. But because this array contains vertex for every pixel on the screen, it means that every frame Im rendering 2073600 verticies (1920x1080), which in my opinion isnt exactly great. So at this point I think that it would be better idea to ditch the whole raycasting thing and just make it just seem like raycaster but with real 3d, which would mean rendering only something about 20 verticies per frame.

So, what should I do? Should I use raycasting just with differrent rendering method? Should I use a real 3d? Or is 2073600 verticies per frame just fine?

Dave F.
  • 145
  • 6

1 Answers1

4

Fastest would be to ray cast directly on GPU you can use compute shaders for this (I do not have any experience with those) however Its possible to do this also on standard shader rendering pipeline see my GLSL version:

of coarse you need to add BVH or Octree to have reasonable speeds for complex scenes...

If you insist on ray casting on CPU side then it would be much better to store your output into 2 textures one holding depth and the other RGB color. If you have access to 4 component textures with enough precision you can use RGBD format and single texture. Then to render you just render single QUAD and fragment shader do the rest ...

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Oh, when I said raycasting I actually meant something like wolfenstein3d map renderer. So no 3d stuff involved. I just have a 2d array of numbers which represents a topdown map. And the I cast a ray for every column on the screen - width of 1920 means 1920 casted rays. And then I save the results to a vertex array. So your suggestion is to save them to a texture, ok Ill try that – Dave F. Jan 23 '21 at 14:37
  • @DaveF. the voxel grid ray trace is the same as wolfenstein just ported to 3D ... for 2.5D like [this](https://stackoverflow.com/a/47251071/2521214) you still can do it fully on GPU ... map is a single 2D texture and walls are texture atlas ...no need for BVH nor OCTREE. If you insist on VBO then comprise your VBO as set of vertical lines instead of pixels ... – Spektre Jan 23 '21 at 16:06
  • @DaveF. Your current VBO size might be a problem ... You know the gfx card could most likely render it fine but you need to realize you have to copy the VBO data to gfx each frame (as its not static) and that can be considerably slower than you think... In case of doing this directly in shaders you just pass 2 textures once (not per frame)... On per frame basis you need to pass just few uniforms with camera position and orientation so 4 floats which can packed to single `vec4` vector ... – Spektre Jan 23 '21 at 16:15
  • Yeah I thought of compressing it to just vertical lines, but that would mean that every column would have the same color. Ive also seen someone doing this via legacy opengl, is it good idea? – Dave F. Jan 23 '21 at 16:40
  • @DaveF. no it does not mean just single color as you can texture the lines the horizontal position of the line gives you one texture coordinate and the other (vertical) is fixed to min and max for the endpoint of line... (unless you got different height walls)... so 1. render floor and sky 2. ray cast and pass x-resolution vertical lines with texture coordiantes ... – Spektre Jan 23 '21 at 21:02