Friday, November 27, 2009

Scamper Ghost Released

A friend and I have finally released our game




As they say, it's "a fast-paced avoidance retro pixel art game with ghosts, coin collecting, power-ups, and slow motion."

Sunday, November 22, 2009

Unified Codebases Rock

In a previous post, I eluded to the advantages of being able to run the same code on the CPU and the GPU. One obvious example is the interaction between color processing and frame buffer clearing. Shaders may process the color of a fragment before it is written to the frame buffer for a multitude of reasons, including color correction, exposure control, tone mapping, and gamma correction. This causes problems when the CPU needs to predict the final value for a color that will be output by a shader. For example, when fog is used to attenuate the colors of objects as they fade into the distance, it is necessary to match the clear color with the fog color. If the same color processing is not applied to both, the result is the following:



On the other hand, if the correct color processing is applied to the clear color, the result is much more satisfying:

PyStream Texture Support

PyStream now supports textures. There are a lot of simple issues like texture mapping that have been lost in the shuffle until now, and I am going back to fix.



def shadeVertex(self, context, pos, normal, texCoord):
    trans     = self.worldToCamera*self.objectToWorld
    newpos    = trans*pos
    newnormal = trans*vec4(normal, 0.0)

    context.position = self.projection*newpos

    return newpos.xyz, newnormal.xyz, texCoord

def shadeFragment(self, context, pos, normal, texCoord):
    surface = self.material.surface(pos, normal.normalize())

    # Texture
    surface.diffuseColor *= self.sampler.texture(texCoord).xyz
    
    # Accumulate lighting
    self.ambient.accumulate(surface, self.worldToCamera)
    self.light.accumulate(surface, self.worldToCamera)
                
    mainColor = surface.litColor()

    mainColor = rgb2srgb(tonemap(mainColor))
    
    mainColor = vec4(mainColor, 1.0)
    context.colors = (mainColor,)

Monday, November 16, 2009

Dissertation Status

Here's a simple example showing the current capabilities of the PyStream compiler. These shinny cows were drawn using a shader that was written in Python and then compiled into GLSL. The actual shading algorithm is pretty simple: phong shading, a point light, and gamma correction. The kicker is that Python's semantics are wildly different from GLSL's. Compiling Python code into GLSL is therefore a pretty neat trick.