Spellcaster Studios

Make it happen…

Argh, more precision bugs!

The days started great… Added the “grass” shader to OpenGL, and added the option to hide the UI (great for screenshots), and was adding something pretty cool: water splashes when the player jumps or falls into water.


In the process, I found another silly precision bug (that of course, manifests if I switch renderers): when the player holds the jump key while in the water, on OpenGL it behaves as expected, but on D3D it would hover above the water!

After a lot of debugging (hard to do, because it’s an interactive thing, which means that I can’t use breakpoints, and debugger doesn’t work well with rivers), I finally found out the issue: a jump can only be triggered when the following conditions are met:

  • Height above the ground is smaller than 10cm
  • Vertical speed is zero


So, when we jump, there’s a point where the vertical velocity is zero: when we’re at the apex of the jump… That meant that if there’s terrain just below 10cm, it will be ready for another jump! On OpenGL, the vertical velocity would never be zero (it would be very small before going to negative, because of gravity), but on D3D (that sets the floating point unit to work with less precision), the velocity was zero, so a new jump could be triggered if we were just above the water, which happened…

So I had to add a very ugly piece of code, which checks if the velocity is more than zero and if the gravity effect would turn it into zero, it will set it to a very small negative value, to stop it from triggering a jump…

Alternatively, I could try to change the gravity strength so that it wouldn’t happen (risky), or use doubles (would cause the floating point unit to shift between normal and double precision, which could cause a real decrease in FPS).

This way is very hacky, but it works fine…

Now listening to “Undertow” by “Tool”

Link of the Day: This script looks awful… I know the movie it will be awful… But I need to watch it:

More grass

Worked a bit more on grass today… In the process I found a silly bug with the terrain generation:


The water over there should have a barrier making a basin… The reason for this was that the terrain around it was marked as “static” (because it’s rock), but it shouldn’t in this case… The result after the fix (which took me a bit, because I can’t use debug mode with rivers, it takes too long to generate):


Much better… Smile

Then I went back to the grass, wondering if the problem was the rendering or the texture… So I went online and found a random bush image and tried it out… The results were way better than I expected:


So I need to get the artist to make me some bushes (maybe a couple of different ones)… I’ve also added some vertex animation to get them swaying (it’s subtle, but I think it adds to the scene).

So now, it’s time for bugfixing and start work on the multi-threaded area generation (this one is going to be a big one, I think, since I don’t have multithreaded primitives in this framework).

Now listening to “Storm” by “Theatre of Tragedy”


Working on grass for the alien planet… Results are absolutely terrible!

First I tried putting in grass in a triangular pattern, so you could look at it from any angle (for cutscenes, mainly)…


The first problem shows up… The normal of one or two prongs will always be extra dark, which will cause the ugliness above…

So, moving on, I tried just using a quad aligned XY plane:


Bleargh! I can even animate the vertex, that won’t make a difference, that’s absolutely terrible!

Tried playing around with the texture, results were even worse:


And to add injury to insult, there’s a small issue that I can’t track down:


If you look at the marked places, it seems to be some UV issue, or interpolation issue, but I have no idea where that comes from… It’s always in the position in the texture, but I’ve looked and looked and looked at the texture and there’s nothing there that can explain that…

So currently, the grass is a bust… The problem might be primarily with the texture, so I’m going to look into that, but maybe the type of perspective the game uses doesn’t work with grass…

Now listening to “Powerhouse” by “Mustasch”

Alien planet polish

Started the polishing of the alien planet…

This is the initial state:


Very barren, looks artificial,etc…

Started by the usual places: getting the water flow/rivers working, improving the terrain generation… My focus was really off today, so this went way slower than it should…

Then I added crystals to the landscape, which helps with the barrenness:


I’m not too sure I’m keeping the alpha-blending on them or not, and I still want to add alien grass, but it’s looking better…

Now listening to “Hellfire Club” by “Edguy”

Now playing: “Trine”… When it came out I didn’t have a computer capable of playing it decently, and I forgot about it, but the other day I saw the trailer for “Trine 3”, so I decided to pick it up and play it… It’s fun so far, although a bit “always the same”… Let’s see how it goes… Just gave up on “Thief”, which really sucked… Loved the originals, but this one had so much issues (balancing, level design, the art direction) that I couldn’t play it anymore…

No much time…

Not much time for work today (just wrote one sentence in the game!), so here’s something to keep you busy: a GIF with all the screenshots I took of the game so far! Smile

Now listening to “The Varangian Way” by “Turisas”

More bugs down!

Today was mostly a bug-hunting day, but I had time to do other stuff… First things first, I removed one of the big bugs in the game: a raycast issue that would sometimes cause the game to freeze… This was very hard to detect, but after I found a way to replicate it consistently, it was fairly easy to fix!

Fixed also some bugs with the AI (the enemies were trying to get too close), atmospheric effects (ashes, rain) no longer show up while inside facilities, fixed some stuff with aiming (was very subtle but sometimes it would cause really hard target situations)…

Also worked on some optimization of the decal system, and managed to get some polish in…

Now when the player shoots water or lava, it won’t leave a scorch mark, but do a splash instead!



It looks pretty cool, to be honest… It’s one of those very small details that liven up a scene… Smile

While waiting on compilations, also worked on trying to get the Spellcaster Studios logo music into 8-bits… The idea was to start the music as usual and crossfade to an 8-bit version…

The results are interesting enough that I want to pursue it, but it currently sounds terrible:

For reference, the original logo music:

Need to see if I can either get the original MIDI files made by the excellent João Camacho, or find someone that can hear the music and do a MIDI version of it…

Now listening to “Carved In Stone” by “Rage”

That was quick…

Finished the polish of the swamp level… Quite impressive, to be honest, since I was expecting it to take more or less the same time as the previous ones…

Added a rain effect, which worked great!


And then, for good measure, added some droplets in the water, to simulate the splash, using some decals:


The effect is subtle, but in movement you can definitely see it… This one is a bit too performance intensive, going to see if I can optimize it by playing around with the scene graph…

So, optimization and debug task next… Let me see the list… Oh, stupid raycast bug and the scene graph… *rolls sleeves*

Now listening to “Lust Stained Despair” by “Poisonblack”

Polishing the swamp…

Today I started polishing the swamp… First, I added the water with the flow… This was way more work than it should, but since I don’t have rivers, I don’t have a notion of flow, so I had to invent one…

Basically, what happens here is that the water will try to move in one direction (very slowly), while keeping away from the shoreline:


It looks good in motion! Smile

Then I decided to change the algorithm to generate the swamp terrain…

The previous algorithm was using the same basis as the rest of the terrain types, but taking the average height and making everything below that water. This worked more or less fine, but it tended to create terrains that would be all “ground” on an end of the map, and all “water” on the other end…

I decided to adapt the cavern algorithm to generate more clustered terrain, using a cellular automata. The results were much better!


This is a terrain with about 55% water, I can control that to make it less watery… Smile

Next step, to add visual effects to the swamp to increase the interest of the area in general…

Now listening to “The Wall” by “Pink Floyd”

I hate precision issues…

So, better camp sites (more seamless with the surroundings):


And then I decided to tackle a bug that was plaguing me for some time: the world generation on Direct3D and OpenGL were yielding different results:


OpenGL on the left, D3D9 on the right… Way different…

After a load of time and logging, I finally found the problem… Apparently, one of them (not sure which one, to be honest), changes something on the precision of the floating point unit, which meant that on one case a particular calculation (number of terrain splits) was yielding 25.9999999 (so, since I was truncating, it was 25 splits) and the other was yielding 26.000000 (so 26 splits)…

The offending piece of code was:

unsigned long splits=(unsigned long)((1.0f-roughness)*80.0f+10.0f);

I replaced this with:

#define RoundUL(X) ((unsigned long)(floorf((float)X+0.5f)))

unsigned long    splits=RoundUL((1.0f-roughness)*80.0f+10.0f);

And the results are the same on both renderers!

This took me way longer than it should considering the end result, but it’s good to have coherent results on both systems!

Now listening to “Rosenrot” by “Rammstein”

Link of the Day: Found some interesting thoughts on multithreaded gameplay code (which is HARD)… I’m not sure if gameplay should be multithreaded (think maybe the multithreaded part might be better exploited and better controlled by putting the rendering/physics/path-finding in it, instead of gameplay), but it’s an interesting read nevertheless: http://bitsquid.blogspot.pt/2015/03/multithreaded-gameplay.html

More bug fixing

Not much time to work on the game today, so I mostly took care of some outstanding bugs related to the placement of enemies.

This sort of case would happen pretty often:


Note that spawner would overlap the lava… The issue was that when considering places to position enemies, I’d only search for a single voxel, and not account for the vicinity.

After a bit of a struggle (because I was screwing up two lines of code), I managed to improve the placement… The above spawner would now be positioned here:


Much better! Smile

I’ve detected another bug, but I can’t replicate it, which makes it very hard for me to fix it… Sometimes the raycasting system will enter an endless loop, but I have no idea what exactly provokes that situation, so I need to try to figure a way to make it more consistent….

Anyway, tomorrow I’ll probably finish the polish of the lava world and move towards some more bug fixing and optimization!

Now listening to “Plagues of Babylon” by “Iced Earth”

Link of the Day: I never payed much attention to Trine, except for the fact that it was an absolutely beautiful platformer, but the trailer of the third one got me in the mood to fetch the other 2 (and I got them at a low, low price on Steam, so that’s win!):