Mario's Weblog

Videogame Developer

sábado, 17 de octubre de 2015

1 Million Grass Leaf with Physics in Compute Shader

[Updated]


Compute Shaders

Compute Shaders are a really really cool stuff! It's meant to expand the GPU capabilities to run any kind of massively parallel computation.

My final career project, several years ago, was about CUDA. That was technology developed by nVidia to do exactly the same thing on their GPUs, but it was not compatible with ATI cards. But now Compute Shaders works on every card that supports DirectX 11 and it is very very similar to CUDA, the language is HLSL, very similar to C :)

Demo

I've made a Demo that shows how several balls can interact with a ground with 1 Million leafs running at 30 FPS in the next hardware; GPU nVidia Geforce GTX 680 and CPU Intel i7 920.
The same simulation in CPU is running around 0.1 FPS.

For every leaf I calculate two distances, the impact radius "less than 0" to flatten the leafs and the expansive wave radius "less than 2" meters to twist them simulating the impact of the wind generated by the impact of a ball with the floor.

The Compute Shader is configurated by a grid of 32x32 Threads per Thread Group and 32x32 Thread Groups.

All the Grass are painted in a single Render Call with Intancing and the primitive Point.
In geometry shader I recreate the quads per every point and read from the Compute Buffer the physics data that must be applied on every leaf

Code

https://github.com/mqmtech/ShadersDemo

domingo, 28 de septiembre de 2014

Football Prototype

Football Prototype


Hi, I've started a prototype of a football game, my goal is to make all the art as procedural as possible and also a great AI that is fun and does intelligent moves :)




All textures in this image is procedurally generated, yep, event the Real Madrid badge. I'd also like to make some fun with procedural meshes in the future.

Currently I already have pretty much finished the texture of the field and goals. The rest is still work in progress.

About the AI, I already have some basic stuff working, players can recover the ball, pass to a team mate and shot.

In this video it can be seen a little more of AI:


Soon I will be posting the updates, stay tunned!

domingo, 1 de junio de 2014

La Décima

Lately I've been playing with a web called Shadertoy.com, there you can find, edit, and create shaders to render worlds with a couple of triangles :)

What I've done lately is a shader to create procedurally The Champions League Cup and the Real Madrid badge. I'ts been great to learn about distance fields and I'm gonna keep experimenting with this.

You can see the result here:
I hope you enjoy it as much as I do doing it:

https://www.shadertoy.com/view/MdsSD4

martes, 19 de noviembre de 2013

Shijie, The Game

Shijie, The Game Released !!

Shijie, The Game is the videogame my team of the master of University Pompeu Fabra have been developing the last 10 months from scratch, the team is composed of 2 artists and 2 developers.

It is an action platformer with a beautiful and mistic atmosphere.

Download it

Trailer



Walkthrough




My main task in the game has been to implement a component-based architecture with multi-thread support, the Deferred render engine using DirectX, all the Shaders in HLSL of the game, physics, including ragdoll using the library Bullet and UI with LUA scripting for the menu.

viernes, 15 de noviembre de 2013

Particle Editor

A lot of time has passed since the last feature I implemented, a ragdoll, which I'll have to write a little more about how I restored the charactedr in ragdoll mode to be back in animation state.

I want to talk a bit about particles, which are a key feature in videogames, they are used to represent almost any effect such as simulation natural elements like watter, fire waterfalls, also to emphasize hits in fights with blood or some less gore effect like done in our videogame.

I've seen two main approaches to particle systems, the ones used to try to simulate some natural effect in a realistic way and a more cinematic/fake ones which are the most widely used as the effect is totally controlled.

In our game engine in the master's degree I've used the second approach because this way artists can use all their skills to make the effect exactly the way the want and fine-tweak it as much as they want. This way a particle is made by the combination of n particle systems that are player together, some of them can have a delay. Moreover the particle engine has the ability to detect particle colisions and react physically to it, also react to the presence of the player near to the particle to generate turbulence and also it support collision callbacks which allow spwaning new particles when a event occur, the events supported currently are collision, floor collision which check that the normal of very close to the vector [ 0, 1, 0 ] and also particle dead.

Technically particle systems can have some impact in performance in render time but also in update time as they are used to have a lot of parameters, in our cae, there're a LOT of parameters to let artists to have as fun as possible doing the most exciting effects.

The optimizations made in the engine in the update part was to run every particle system as a separate task, using the C++ library TBB Threading building blocks, tasks are scheduled in as cpu threads as we have in the computer, so this way it is guaranteed that we're taking full advantage of the last hardware we have.

In the render part I've done the next things. First is to have a main buffer to load all particles, instead of having a lot of little buffers around. Second I've added tripple buffer to avoid waitting to render while we're loading new particles to the vertex buffer of waitting to finish rendering previous particles, the third optimizations is to have a single render callback for all particles systems of the same type, so if we have 500 candles to be drawn the engine would just make a single draw call to render the part of the buffer that contains all the 500 particles which is really cool, more more step would be to have a SINGLE draw call for all particles but that would imply some restrictions such as all particles should share the same mesh and could be some problems with uv animations. The last optimization is to use instancing, a single mesh is uploaded and then in a separate stream we upload the particle render data such as world position, rotation, uv animation, color etc..

I've also implemented which I've named "render stages" like pre_dof, post_dof and gui. The pre/post dof stages were needed for particles that could be affected by dof as everything rendered before dof would be affected by this effect. The gui render stage is used to render 2D particles after all 3D has been rendered and also a orthogonal camera is used for this stage.

You can see a bit about how to use the Particle editor I made in the next video:


martes, 26 de marzo de 2013

Ragdoll implentation with Bullet

The past week I've been implementing a Ragdoll with our best friend, Bullet :)






The main steps that I've done to implement the ragdoll are these:
  1. Create the rigidbdoes (or Ragdoll bones) and its constraints 
  2. Match the Ragdoll bones to the animation ones
    1. There are two main possibilities here:
      1. Associate one Ragdoll bone to N animation bones
      2. Associate one Ragdoll bone to one Animation bone and the rest can be updated by a hierarchy. ( I used this second way )
  3. Calculate offsets between the Ragdoll and the Animation from the equivalent pose and orientation
    1. The bones from animation and its homologous could have a different starting position and orientation, this difference is what it's called offset and we need to know this to update the animation properly.
  4. Insert the Ragdoll rigidbodies ( bones ) in the physic engine with the right pose, that's to say, initially it's the rigidbodies the ones that need to be setup by the animation pose before being being activated inside the physic engine.
  5. Sync the animation bones from the Physic position and orientation of the rigidbodies.
  6. ( Optional ) I've to start working on this part, recovering animation from a ragdoll pose. I guess that this should be done by implementing a very large blending time, I must try and test it.

lunes, 12 de noviembre de 2012

Shot and Crush Spatial Crash Edition 2



Click here to play on browser (Chrome recommended)

This time you pilot a car with wings and helped with some propulsion to fly around the outer space and destroy twets in the form of asteroids :)

To play enter the name of the twets you want to see and start destroying asteroids to see the message of every tweet :)

There're two kinds of powerups:
* Super-shot pill: By pressing "Q" button you will be able to fire eight fire bullets.
* Extra time: As of the second 30 approx extra time powerups will start appearing and will let add you a few more seconds.


The difficulty is adaptative, the faster you kill asteroids the more tweets per second will be appearing and the more points you'll be able to sum up.



Note: The ranking at the end of the level is currently not working.