Forum

Page 1 of 1

Good docs on BSP rendering?

PostPosted: Sat Jun 03, 2017 3:12 pm
by JasonX
I'm working on a small map viewer to improve my modern OpenGL skills. I've been postponing the learning of shaders for too long! I've seen tons of BSP loaders out there, including the Assimp one, but i'm curious about the rendering of BSP maps in modern OpenGL. How would you guys do it? Would you even consider PVS? Or just send everything to the GPU? How would you do the lightmaps?

Re: Good docs on BSP rendering?

PostPosted: Sat Jun 03, 2017 10:01 pm
by Spike
pvs is still good for reducing overdraw and texture switches, but recalculating everything that's visible every frame is a lost cause.

http://triptohell.info/moodles/junk/onedraw.zip is my toy engine (or rather, renderer). source is included.
you can compile it to use either bindless textures or array textures to avoid texture switches.
you can use the number keys to switch between different bsp strategies. see for yourself which is best. for whichever map you're throwing at it.
I could claim massive framerate increases, but you wouldn't believe me anyway. see for yourself, just remember that it skips much of what quake engines do so its pretty much guarenteed to be faster...

it worked for me at the time, but I probably depended on nvidia's non-standard vulkan behaviour, so ignore that if its b0rked. and the bindless stuff requires nvidia to work properly, so that stuff might not fully work for you either. the other one requires gl3.3 or something.
anyway, bsp loading+rendering for bsp29+bsp2 can be found in gl_bsp29.cpp. see if you can figure the rest out.

Re: Good docs on BSP rendering?

PostPosted: Sun Jun 04, 2017 2:21 am
by JasonX
Outstanding. Thank you so much. I'll be digging in the source, specially in the vulkan part. :mrgreen:

Re: Good docs on BSP rendering?

PostPosted: Tue Jun 06, 2017 6:53 am
by toneddu2000
my gtx 970 makes vulkan exe crash. The other two exes go well. It's really a majestic project, I must say! It's a pity for the license.. I'd prefer MIT but whatever
You think that would be impossible to add csqc to it? :biggrin:

Re: Good docs on BSP rendering?

PostPosted: Tue Jun 06, 2017 3:47 pm
by Spike
personally I just get a black screen with the vulkan build, oh well. frankly there's no advantage to vulkan here - vulkan excels at high drawcall counts but this thing explicitly keeps drawcall counts low, while current drivers waste their time being poo, so expect half the framerate from vulkan at eg 1920*1080, were it to work properly (this is what I see with vulkan vs d3d9 in fte).
yes, gpl sucks. I don't personally care that much about my code, but I'm not going to claim that I wasn't at least influenced by the gpled quake source in terms of file format/protocol support.
while someone could write csqc support for it, I don't really see all that much point considering all the other things currently lacking. If you're going for high framerates then a qcvm won't help much. I added demo playback for benchmarking purposes more than anything else. Being able to join servers was then just a small extra tweak allowing slightly more direct comparisons. If you actually wanted to mod that thing, I'd suggest just learning C++ instead of QC (in addition to the C++ fixes/extras it would need for it to be usable as anything but a toy engine).

Re: Good docs on BSP rendering?

PostPosted: Tue Jun 06, 2017 5:29 pm
by toneddu2000
Spike wrote:yes, gpl sucks. I don't personally care that much about my code, but I'm not going to claim that I wasn't at least influenced by the gpled quake source in terms of file format/protocol support.
yeah, I imagined that, totally understandable
Spike wrote:If you actually wanted to mod that thing, I'd suggest just learning C++ instead of QC (in addition to the C++ fixes/extras it would need for it to be usable as anything but a toy engine).
Tried (tried C, not C++). But pointers and malloc beat me like a carpet :mrgreen: I'll try again. You know what I'd like to accomplish? Embed this. :biggrin:

Re: Good docs on BSP rendering?

PostPosted: Wed Jun 07, 2017 4:36 pm
by JasonX
Holy crap this qclib thing is amazing.

Re: Good docs on BSP rendering?

PostPosted: Wed Jun 07, 2017 6:59 pm
by frag.machine
Great job indeed. Some time ago I tried to do the same with the regular Quake VM (just for fun), but the final result resembled more something a drunken Dr. Frankenstein would create... Also, having the compiler embedded is definitely a plus.

Re: Good docs on BSP rendering?

PostPosted: Wed Jun 07, 2017 7:02 pm
by frag.machine
toneddu2000 wrote:Tried (tried C, not C++). But pointers and malloc beat me like a carpet :mrgreen: I'll try again.


If you never crash and burn when learning to code in C you are not really learning. :D

Re: Good docs on BSP rendering?

PostPosted: Thu Jun 08, 2017 6:39 am
by toneddu2000
frag.machine wrote:If you never crash and burn when learning to code in C you are not really learning. :D
wow, that's deep! :biggrin: You know what I hate the most? The fact the I understood HOW pointers work(deferencing are quite obscure to me, though), but not WHY I should use them! I understood that, when you pass a var as argument in C, if it's not passed by reference, that var will be copied so, it's not the original var but its copy. So you need to pass value by reference because it's the only way to "manipulate" original var. The problem is that I didn't find any resource that explain all the cases where you should or shouldn't use pointers.
You know what? It woud be great if you experienced programmers could add a thead in this forum where to post all the books, tips and tricks about C programming from the basics, maybe with examples related to game programming, because, at least for me, if the subject is interesting, it's more fun to learn! :biggrin:
Another thing that makes me wonder is: is it better C++ or C for newbies? I mean, for people who never learned programming, is it good to learn procedural language as 1st language or would it be better to learn OOP and UML so it's easier (when your newbie mind is not cluttered with procedural programming thinking) to start thinking with objects?

Re: Good docs on BSP rendering?

PostPosted: Thu Jun 08, 2017 11:51 am
by frag.machine
There are tons of free resources in the subject available in the web, but since most of what I learned about basic programming was before the internet age I'm afraid I can't give any tested pointers (pun intended).

That said, at least in my case the relatively deep knowledge of hardware inner working (again, back in the 8 bit era) helped me to understand most of the more abstract concepts as pointers, arrays, structures and even objects. This is quite rare nowadays, but maybe the success of the rPi project can change it.

Re: Good docs on BSP rendering?

PostPosted: Thu Jun 08, 2017 2:24 pm
by mh
toneddu2000 wrote:The problem is that I didn't find any resource that explain all the cases where you should or shouldn't use pointers

That's because there isn't such a resource.

Pointers are one of those topics where if you ask 5 different people you'll get 5 different answers. A modern C++ programmer will tell you to never use pointers and if you're not using std:: containers (and don't you dare call it STL) you're not using proper C++ (never mind that you're actually using C, you'll get blank looks from them if you mention that). A low level systems programmer will pass around pointers. Will you allocate it on the stack or on the heap? Will you declare it as an array and pass it to a function that expects a pointer? What if the function returns a pointer?

Do you see what I mean? A topic like pointers in C is something that you're not going to get your hand held with. You need to learn it the hard way.

Re: Good docs on BSP rendering?

PostPosted: Thu Jun 08, 2017 9:34 pm
by frag.machine
mh wrote:
toneddu2000 wrote:The problem is that I didn't find any resource that explain all the cases where you should or shouldn't use pointers

That's because there isn't such a resource.

Pointers are one of those topics where if you ask 5 different people you'll get 5 different answers. A modern C++ programmer will tell you to never use pointers and if you're not using std:: containers (and don't you dare call it STL) you're not using proper C++ (never mind that you're actually using C, you'll get blank looks from them if you mention that). A low level systems programmer will pass around pointers. Will you allocate it on the stack or on the heap? Will you declare it as an array and pass it to a function that expects a pointer? What if the function returns a pointer?

Do you see what I mean? A topic like pointers in C is something that you're not going to get your hand held with. You need to learn it the hard way.


@toneddu2000: Pretty much this. Good news is: once you finally reach the "got it" point, things suddenly starts to make sense. Pointers are basically an indirection: you have a variable (which is a label to refer to a physical memory address) which holds the physical memory adress of another variable, so you can "peek" inside this other variable.

Code: Select all
char* ptr=NULL;
char a[3];

a[0] = 'X';
a[1] = 'Y';
a[2] = 'Z';

ptr = (char *)&a[0]; // ptr receives the physical adress where the first element of a is stored
printf ("0=%c\n",*ptr); // prints 'X'
ptr++; // makes ptr point to the next element of a
printf ("1=%c\n",*ptr); // prints 'Y'
ptr++; // makes ptr point to the last element of a
printf ("2=%c\n",*ptr); // prints 'Z'
ptr++; // makes ptr point BEYOND the last element of a (in other words, we have an invalid pointer now!)
printf ("2=%c\n",*ptr); // prints God knows what...
*ptr = '\0'; // high chance to crash the program since
  // we are trying to write where we weren't supposed to
  // (like messing the stack where jump addresses from subroutine calls are stored)

Re: Good docs on BSP rendering?

PostPosted: Thu Jun 08, 2017 9:46 pm
by toneddu2000
I think I'm starting understand things now, thanks a lot to both of you! :biggrin: