Tuesday, August 16, 2011

Nice repository commits visualization tool - http://code.google.com/p/gource/

Wednesday, July 13, 2011

Cannons and the Swarm

An attempt to create fast algorithm for swarm movement in dynamic terrain, I've adapted the A* to work on a grid, that guides the agents. The grid cells contain danger level and flow direction. The "danger" is increased when a projectile hits the swarm agent. Once in a while, I run A* on the resulting grid, pathing from agent spawn points to the center. Flow directions are then aligned along the resulting path. Agents are using the flow vectors as movement direction (+ some primitive danger avoidance behavior).

The cannons use backpropagation neural network with 8 inputs, 12 tanh hidden nodes and 2 outputs. Inputs are projectile velocity vector, cannon location, target location and target velocity. I record projectile location when it passes closest to the target, and use the offset from the real target location as error for network learning. It gets better over time :)

Thursday, June 2, 2011

Tuesday, April 12, 2011

Quadraturin test - 2D shadows



For each light source, I use the engine's spatial indexer to determine shadow casters in range (depends on light intensity). The idea is to use a single texture to cover just the light extent of the source, making it usable to render multiple small lights. In this implementation larger lights suffer from both increased number of shadow casters and large texture sizes. It takes 3 quads per shadow caster to define shadow geometry: one for full shadow and two for penumbrae. I use red color component to represent shadow depth. Penumbrae quads is defined to have (0,0) at the caster's edges. A shader is used to approximate penumbra gradient:

uniform sampler2D sceneTex; // 0

void main()
{
    vec4 coord = gl_TexCoord[0];
    float sum = atan((coord.y)/(coord.x));

    // pixel angle ranges from 0 to pi/2
    gl_FragColor = vec4(3.14159/2-2*sum,0,0,0);
}

Shadows are blended by:
gl.glBlendEquation( GL.GL_MAX );
gl.glBlendFunc(GL.GL_SRC_COLOR, GL.GL_DST_COLOR);

Shadow quads are rendered on frame buffer, whose texture is processed by additional shader to add light:
uniform sampler2D sceneTex; // 0
uniform vec4 color;
uniform float cutoff;
void main()
{
    vec4 coord = gl_TexCoord[0];
    vec4 tc = texture2D(sceneTex, gl_TexCoord[0].xy).rgba;
   
    float distance = 2 * sqrt(pow(0.5-coord.x, 2) + pow(0.5-coord.y, 2));
    float param = (1-tc.r) * (1 / (distance*cutoff) - 1/cutoff);
      
    gl_FragColor = vec4(color.r * param, color.g * param, color.b * param, 0);
}
The "distance" value varies from 0 to 1. The "cutoff" parameter then specifies which real distance is considered zero.

Another option is to use:
float coef = cutoff/height;
float a = 3.1415/2 * atan(distance*coef) / atan(coef);
float param = (1-tc.r) * cos(a);

This imitates a light source that is located at specified height above surface.

TODO:
* Shadow geometry is incorrect for small objects and big light sources. Also, the shadow quad's far edge is visible when caster is very close to a light.
* The entire shadow distribution can be improved by supplying the gradient shader distance and size of the light source. Shadow then can be rendered by a single quad.
* Shadow/light textures are blended using (GL_ONE, GL_ONE), which causes color over-saturation. This also causes lights to cast unrealistic shadows of each other.
* Caster geometry is ignored. Might be interesting to implement proper casting for non-convex bezier curves :)

Sunday, March 27, 2011

Monday, March 21, 2011

Quadraturin engine demo

Shader fade/blur effect and bezier curves test

Monday, November 15, 2010

Monday, August 2, 2010

Colloid begins

The game idea is a blue bubble that falls on planet and starts to spread. The locals are trying to burn out the goo, so you control the flow direction, accumulation, temperature and other goo's properties to overwhelm the defenses. Some articles for goo simulation:

Good overview:
http://software.intel.com/en-us/articles/fluid-simulation-for-video-games-part-1/

Some algorithmics:
http://www.colinbraley.com/Pubs/FluidSimColinBraley.pdf

Saturday, March 20, 2010

Obstacle in range

Used http://stackoverflow.com/questions/1073336/circle-line-collision-detection article as reference for line-circle intersection.

Following code extracts the part of line that is inside a circle:

Fast closest object search

First notable implementation fragment for game/intelligent agent engine I'd like to show. It is a part of ant hive simulation. It's goal is to serve a playground for some swarm intelligence algorithms. Anyway, I'll need a good performance on large number of interacting agents.


ObjectLocator's purpose is to locate physical objects closest to specified one. It uses a tile array over the two-dimensional "world". The search is done over closest tiles in spiral manner.
Invoked to detect which agents should interact each with other, it notably reduces the closest/fittest agents search time (compared to one-to-one search). This implementation gives real-time performance for over 10000 uniformly spread interacting units (for 200x200 tiles). I may append performance charts later.

Hello, Collective!

This blog was created to share/track some ideas/implementations from my programming hobby. Other stuff that conquers my attention will also come here. I'll try to keep it updated at least once in a week, to keep track on progress. Any source code published here can be used as freely as you like (doomsday machines excluded).
And yep, I am a MBTI fan, ENTP in nature :)

P.S: Would appreciate a hint to how and where can I host some applets.