Regex Helpers - Snippets

Working on a parser the other day, I decided to use the new <regex> library in C++ 11. It's awesome, once you get to know the regex sintax. To make development faster, I coded a couple functions. They are nothing fancy,

Continue Reading...

PhysX Particles Simulation - Take Two

Well, after a lot of fighting, I managed to get the volumetric render working. I'm using a 128*128*128 3D texture, and then I raymarch it in a compute shader. The results are quite good actually. I'm getting around 140 - 170

Continue Reading...

PhysX Particles Simulation - First Take

So, the other day I decided I wanted to try to add particles to my engine. I already have PhysX ( 3.3 beta ) working, so I grabbed the documentation and started from there. The documentation includes a guide that it's

Continue Reading...

Simple random numbers using std::random

Another of the great things added in C++11 was the random library. It provides a bunch of facilities to create random numbers, way better than the C rand(). As it happens a lot of time, its use is cumbersome, compared to

Continue Reading...

Here I present what I like to call a "Dynamic Struct".
The idea is to have a struct that you can define at run-time, and get the elements by a string.
What's the use, you might ask? Well, my reason to do this is to have a way to define a constant buffer in a text file, load and update it in the C++ side, and pass it to the GPU.
So, with that in mind, here's a partial implementation( partial in that it has just a couple types, but it's easy to extend ), and how to use it.

Code:


And to use it:


Or:


It should be noted that I'm using this in production code, with just a few changes, like clean-ups, proper ctors, etc.
Speed-wise, it shouldn't be that bad. I use a std::map instead of a std::hash_map, as constant buffer and structures in general tend to have few items, and a hash map suffers in that conditions. Also is O(1) in the creation of each element, so you can add all the elements TYPES you want( C++ 11 and lambda functions make it possible to throw the old switch() case away in a clearer and might even faster way. Functional programming to the rescue!)

PS: uint is just a typedef for unsigned int. Also XMFLOAT4X4 and XMFLOAT3 are from the DirectX Math Library ( DirectX 11).

Branchless Ternary Operator

Branches, while faster every day, can be slow in some systems, especially in GPUs. By slow I mean slower than some arithmetic operations. If the branch is operating with numeric values, and assuming that boolean operations are convertible to 0 and

Continue Reading...

Pages

Powered by Blogger.