woensdag 17 april 2013

Distorting pixels

Hello everyone!

Today I want to talk about refraction, what it is and how you can use it to enhance special effects in your games. 

In the image above, you can clearly see that the pixels are distorted, they are not rendered at the place you'd expect them to be. The light seems to bend around something in the 3D world. This is what we call a refraction effect, gamewise. In the real world refraction works a bit more complicated than just pixels being distorted on the screen, but that doesn't matter for now. I think you can clearly see the point of what I'm trying to explain from the image.

There is a shader involved which renders this effect using simple geometry ( billboarding plane). The shader renders the object as of its 100% transparent. It also renders the object after the first 'transparent object render pass', this is important. In Unity you use the tag ' Tags { "Queue"="Transparent+1"} ' to achieve this in the shader. 
However, it also transforms the already rendered pixels behind this piece of geometry according to a normalmap. This all sounds quite complicated just from plain text, maybe some pictures can make it a bit more clear.

The above image shows you schemetically what normally happens during rendering without any refraction effect applied. As you can see every geometry is being rendered using its material onto the screen, nothing fancy. 

The second image shows you what the refraction shader is doing to the already rendered pixels using the simple billboarding plane geometry and it's normalmap texture.

This render techinique can be used to enhance your special effects. For example to visualize a shockwave moving through the world coming from a big explosion. Or a heat effect, wich makes the light 'ripple' in front of the viewer's eyes.

One big issue with this technique is that you can't fade the refraction effect by default. In the non-refracted shockwave particles I created, I made the particles fade out by altering their alpha values. However this doesn't doesn't affect the normal distortion off course. I fixed this problem by taking the vertex alpha's into the normals calculation of the effect. 

During the lifetime of a shockwave particle, it's alpha decreases from 1.0 to 0.0. I multiply this value by the normals I get from the refraciton normalmap. Less alpha means less distortion, which makes the effect able to fade in/out.

When taking this technique several steps further you could combine it with reflection to create realistic looking water reflections and distortions.. the possibilities are endless :) !


donderdag 11 april 2013

Recycle for a better game environment!

Today some news about a new game! Just like Eugene im working on a new project as well!
And I am going to tell you a technique to reduce the memory usage by recycling objects.

In this game we are re-using a lot of objects during the game. Like in every other game but this time we are re-using it at the time we are not using it any more. So when we are following a path, we pass numerous objects. Once we pass them we will recycle it and not destroying it. We set it to the next possible spot. This way we won't need to delete it and create it again.
Just a quick reset of its variables and visuals and then set it again for another use! A very nice way of recycling!
Level unmodified

Well this sounds very promising but we need to cooperate with the artist for this. Normally u want to place all these objects in Max and export it the normal way. But since we are recycling all of those objects we don't want a normal export. The export we want, to save some memory and size, has to be modified.

Their are some things we need to know of that model, name, position, scale and rotation. So its name and transform. This can be done in several ways without actually exporting the models. Write all of its data to a text file or replace the model with a dummy and give it the same properties. There are several other ways but we are going to use the dummies. To do this we are using a max script that will search through the scene and replace all the models with dummies.
Models replaced by dummies

We can then search for the specific dummies and add their transform to a array.
So let's say we want to create different sets of objects we now know the type, position, rotation and scale of that specific object. The next part to make it all work, we need a pool of those object types. For each object type we need an original model so we can clone that and put it in a object pool.
So when we need to create a set of objects we can get it from the pool, get its transform we listed before.

This can sound a bit weird but it's very useful.
This can actually increase your game's performance if you use the same objects over and over again. Instead of destroying them on the end and allocating new ones later we are now recycling them. So stop wasting the garbage collector with the same stuff over and over again!

In game


donderdag 4 april 2013

The Art of Looping

The Art of looping
Hi everybody!

Melvin here, senior audio designer and animator at Xform for just about two months now and this my first Xform blog ever.

Well kids, today I'm going to tell you a story about a thing called "looping". The reason why I'm going to discuss this is that I want to show you the relation between sound and movement. And also because this is something you have to deal with, whether as an audio designer or an animator.  In music and sound we use the word loop where in animation we often use the term cycle.

They key thought when creating a seamless loop in audio and animation is that the loop should roughly be like a sine in a graphical approach. I mentioned roughly because it's not necessary to be as curvy as a sine. You could see a sine as a drawn circle, cycle or better yet, a loop in a certain time. We could say we have come full circle!

A sine starts at y=0 and ends at y=0, the origin. The audio example below consists of two sinuses, thus two loops or cycles.The red markers indicate where the loop starts and ends.

Avoiding this story to sound as your monday morning mathclass, I'll just say the more your visual representation of your audio file or animation resembles a sine, the better your loop will be. Thus, if you want a flawless loop, your start and end should have the same y-coordinates and the same angle. The y-coordinate doesn't necessarily need to be 0.  If you do not do this, your animation loop will stutter and in case of your audio loop, it will pop and click.

There are some exceptions in animation where you actually want mirrored angles. A bouncing ball is an example of that.
Here is an examples of bad a loop. (the loop is indicated in blue)

Although the loop start and ends at the same y-value, the loop will pop because the angles are mirrored.
3ds Max users know that if you open the Track View - Curve Editor you will see the graphic representation of your animation.

Here is an example of the movement of a biped pelvis in the animation above. Notice the similarities between this graph and that of the sine audio example.

Of course in real life sound isn’t just one sine and neither do all of we have the same walk cycle. Otherwise everything would be monotonous and boring.  If we look at a more complex audio loop such as this lava audio loop, we can see all of different sorts of sinuses. This gives the sound authenticity.

Importing files

I always save my sounds as wav files, and consider them as my master source files, which I can encode to other formats such as ogg, wma or mp3. I try to avoid saving to mp3 because of the problem, that mp3 encoding places several frames of silence at the start and end of the waveform, which makes looping impossible. The way Unity3d handles audio files is actually quite nice. You can import wav files and choose in Unity3d how it handles its audio files. It also ogg-vorbis compression to keep your final file small.

So this is a small portion of what I do at Xform, I hope haven't dozed you off  to sleep and you can use this in your own work.  
Lets's say goodbye with a seamless loopable track from the forthcoming smash hit
Burnin' Rubber 5.