Bloxel Development Journal – July 28, 2013

The Bloxel C++ library is nearing completion, and I’ve started to work on the C library that will allow language support for:

  • .NET (through P/Invoke)
    • As P/Invoke is used, Mono.NET will be supported too!
  • Java
  • C/C++
  • Any language that allows C++ interfacing or dynamic library loading

Once I’ve finished the C API wrapper, I’ll probably work on the .NET wrapper, and after that, I’ll start adding level of detail support to the engine and texture mapping.   Then, it’s just test, test, test, War of the Voxels integration, and then release!

Release and Debug builds…

Today, I spent the day scratching my head as to why the debug-compiled C++ port of Bloxel was 10-20x slower than the debug-compiled C# version of Bloxel, while the release build of the C++port was faster than the C# version.

After looking in the code for a whole day, I finally decided to google the issue, at which point I learned that STL containers are horrifically slow when compiling on debug builds…

Oh well, at least I optimized (to some extent) the code and I now know that STL-debug-build quirk.

Moral of the story: always use Google first.

The Bloxel Chronicles – Polygonizing Voxels

For the past couple of weeks, I’ve been rewriting the voxel engine that powers War of the Voxels — Bloxel — to be more flexible.  The ultimate goal of this flexibility will be the ability to switch out different voxel extractors, to allow easy library functionality pluggability, and to allow access to the library from a host of different languages.  Something some of you may find interesting is that Bloxel will support dual contouring (I’ll explain more about it really soon).  Here in this series of posts you’ll find technical explanations/rants/gotchas that I’ve encountered whilst trying (that’s a keyword there) to write the code.

Here’s a rough estimate of the posts that will be in this series (may or may not be in order):

  • Polygonizing Voxels (that’s this article)
  • Managing the dynamic world
  • Dynamic lighting
  • Programming Language Accessibility
  • Level of detail
  • Multithreading

Polygonizing Voxels

Of course, you don’t necessarily have to go with the polygonization route.  One alternative approach is volumetric rendering with raycasting, which produces some very nice results, but that isn’t very feasible when you’re trying to develop a user-facing real-time rendering engine (by user-facing I mean one that can run on most ordinary computers) because of performance constraints.  Briefly, how volume ray casting works is that you send out a ray and trace it through the volumetric world.  Do that for each pixel, setting its color based on what the ray hits, and you have yourself a nice rendered image.  As you may imagine though, it isn’t exactly fast enough for real-time rendering.

Enter polygonization.

Continue reading

BloxWar Development Log – July 7th, 2012

Just thought I’d start a development log.

So, in the past few weeks, here’s what’s been added:

  • Player rendering system
  • Fixed some networking problems (and added better network prediction)
  • Added a weapons system!
  • Added various animations to make the game more fluid (switching weapons, reloading, etc.)
  • A primitive HUD
  • Melee attacks
  • Two weapons! (The default pistol you see in most of the screenshots and a knife)

So what’s up next?

  • “Better designed” HUD
  • More weapons
  • Sound!
  • Textured blocks
  • Performance customization (enable bloom, render distance, etc.)
  • MORE DESTRUCTION! (I have something big prepared for this… :))
  • Larger maps so that the world doesn’t look so small.
  • Lighting revamp

Hoping to get a public alpha release out by the beginning of August, and a beta release by winter break. 🙂

Still need to adjust some proportions and add textures...


The new knife! I might use another model...

PHP Session Security

One big problem in session-tracking for websites (such as storing login details as cookies, remembering what was in someone’s shopping cart, etc.) is that the cookies can easily be stolen and used to imitate someon

Before we continue, let’s define some terms:

Cookie – A small text file stored on a computer that contains site data.  A cookie has an expiration date and can easily be opened.
 –  Something that allows a server and a unique client to transfer information; i.e. a log-in session or a shopping session on an online store.
XSS Injection – Cross Site Scripting, or injecting unwanted scripts on a page.  For example, adding some javascript that redirects the user when an image is clicked.

For example, if I were to login in to a site and use their “remember me” function, the site would probably store a cookie on my computer with some sort of authentication key to link my computer with a session.  Now, what happens if someone takes the content of that cookie, places it on their machine, and goes to the website?  The website will receive the cookie, authenticate it, and the person now has your account.

Now you may be asking, “how will he get the cookies?”

Continue reading

LinkedIn Password Checker (PHP)

Wondering if your password was one of the 6.5 million that were leaked?

You’ll need a webserver that runs PHP to be able to use this script.

Download the leaked password list here: (plain, uncompressed 259MB TXT) (compressed 118 MB ZIP)

Download my script

Copy & Paste:


Download the code:

Place the PHP code in the same directory as the combo_not.txt, then run the script!

Good luck!

How to install “unsupported” drivers (or programs) on a Windows Server Installation

When I first installed Windows Server 2008 R2 on my desktop, everything went well…until I checked device manager and realized that a lot of my drivers were generic, and my system could be running faster.

Unfortunately, I had to go through several hours (ok, more like minutes, but that’s not the point) of trying to figure out how to bypass the annoying installers which would spew out “Your system does not meet the minimum requirements” because I was running a server installation, and not a desktop installation.

I would like to stress that this guide does not only apply to drivers, but to any program with an installer that checks for compatibility

Let’s get started!

1. First, you need to actually run the installer.  If it doesn’t check (or is ok with a server installation), everything’s all good!  You don’t have to read the rest of this guide. 🙂

Otherwise, you’ll need to do a bit of trickery in installing the driver.

If your driver software is in the form of an exe, read the following step.  Otherwise, skip the next step (go to step 3).

2. First, you’ll need some archive extraction software, capable of opening CAB files.  My favorite is WinRAR, but you can use something else, like 7zip.  Basically, you just want to extract the actual EXE installer, as most are just self extracting archives, to a folder.  If you are unable to extract the driver software from the installer, you’ll need to do some manual work and look for where the EXE extracts its driver files to (or you can cheat and use a hard drive file monitoring program 🙂 ).  After doing that, proceed to the next step…

2.5 At this point, if you are trying to install a program and not a driver, simply go to the folder and look for the installer file.  If the file also tells you that the program isn’t compatible, try looking for an MSI file.  (if this works, then you’re done, and you shouldn’t read the rest of the guide, which is for drivers only)

3. Now, go to device manager, and find the device that you want to install the driver for.  Right click the device, and then click “Properties”, then click the “Driver” tab, and then click “Update Driver”.  When it asks if you want to search automatically for driver software (which never works…) or browse for driver software, click the “browse for driver software” option, and select the folder where you extracted the driver software to.  Make sure “Include subfolders” is checked.  Finally, press the “Next” button, and Windows will start installing the driver.

4. After that, your driver software should be installed!

More Fun with Shaders (and how to write your own bloom shader!)


Try not to get dizzy…

I exaggerated the bloom power a bit so that you could see it; I think I just might turn it down a bit in the future 🙂

I think I’ll work on the particle system now (aka rip it from my previous project 😛 )

Bloom code:

So there are three parts in a bloom shader, but I only really have two stages.

1. Threshold out bright pixels
2. Apply Gaussian Blur Horizontally (of the thresholded image)
3. Apply Gaussian Blur Vertically (of the thresholded/blurred image)
4. (I guess this is technically a step?) Add the two pixel colors (blurred and original)

My bloom set-up is a two-pass shader, or, it creates the bloom with two passes (who would’ve guessed?).

My first shader, “ThresholdPostProcess.fx”, contains the following:

sampler TextureSampler : register(s0);

float ColorThreshold = 0.25f;

struct VertexShaderOutput
  float2 uv : TEXCOORD0;

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
  float4 pixColor = tex2D(TextureSampler, input.uv);

  // clamp to [0, 1] and scale based on 1 - threshold
    return saturate((pixColor - ColorThreshold) / (1.0f - ColorThreshold));

technique Technique1
    pass Pass1
        PixelShader = compile ps_2_0 PixelShaderFunction();

This is pretty simple stuff; you take the color of the current pixel, and you use saturate (which clamps values to the interval of [0, 1] on color – threshold (a value less than the threshold will be thrown out because it will yield a negative number, clamping it to 0) divided by 1.0f – threshold.  This allows us to scale the extracted color.

In my second pass, I blur the thresholded image and combine the newly blurred image and raw frame.

sampler BloomSampler : register(s0);
sampler TextureSampler : register(s1);

float BlurPower;

float BaseIntensity, BaseSaturation;
float BloomIntensity, BloomSaturation;

const float2 SAMPLE_OFFSETS[12] = { 
 -0.326212, -0.405805, 
 -0.840144, -0.073580, 
 -0.695914,   0.457137, 
 -0.203345,   0.620716, 
  0.962340, -0.194983, 
  0.473434, -0.480026, 
  0.519456,   0.767022, 
  0.185461, -0.893124, 
  0.507431,   0.064425, 
  0.896420,   0.412458, 
 -0.321940, -0.932615, 
 -0.791559, -0.597705, 

struct VertexShaderOutput
    float2 uv : TEXCOORD0;

float4 AdjustSaturation(float4 color, float saturation)
  float gray = dot(color, float3(0.3, 0.59, 0.11));

  return lerp(gray, color, saturation);

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
  float4 pixColor = tex2D(TextureSampler, input.uv);
  // gaussian blur
  float4 g_sum = tex2D(BloomSampler, input.uv);

  for(int i = 0; i < 12; i++)
    g_sum += tex2D(BloomSampler, input.uv + (BlurPower * SAMPLE_OFFSETS[i]));

  // average
  g_sum = g_sum / 13;

  pixColor = AdjustSaturation(pixColor, BaseSaturation) * BaseIntensity;
  g_sum = AdjustSaturation(g_sum, BloomSaturation) * BloomIntensity;

  pixColor *= (1 - saturate(g_sum));

  return pixColor + g_sum;

technique Technique1
    pass Pass1
        PixelShader = compile ps_2_0 PixelShaderFunction();


This is also pretty self-explanatory; we simply take the average of the 13 pixels (one which is the actual pixel, and 12 pixels that are around it), we adjust the saturation, and then we damp the original color a bit to avoid really really bright  pixels.  After that, we just add the original color and the averaged color together, and voila!  You have bloom.

Using this is quite easy; you just render the scene you want bloom in to a render target, apply the threshold to the first rendertarget and save it to a second rendertarget, and then you take the second rendertarget, feed it into the last shader (remember to set GraphicsDevice.Textures[1] to your actual scene rendertarget), and out comes the bloom!

Pseudo code:

rendertarget rawframe = new rendertarget();
rendertarget threshold = new rendertarget();


sb.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, ThresholdEffect);
sb.Draw(rawFrame, Vector2.Zero, Color.White);

GraphicsDevice.SetRenderTarget(null); // reset to our back buffer
sb.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, BloomEffect);
GraphicsDevice.Textures[1] = rawframe;
sb.Draw(threshold, Vector2.Zero, Color.White);

// done!