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

Tuesday, January 25, 2011