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.

Friday, June 19, 2009

Loopy Dependancy Issues

The Bug

Working on redundant load elimination for my dissertation, I wrote a loop:

for statement in statements:
        if someCond:
                ...
                lcl = value1
        else:
                ...
                lcl = value2
        process(lcl)

That is, that is the code I thought I wrote. As it turns out, I actually forgot the final assignment and in fact wrote the following:

for statement in statements:
        if someCond:
                ...
                lcl = value1
        else:
                ...
                # lcl not assigned to
        process(lcl)

Now this is a fairly straight forward bug to find and fix, right? As it turns out, this simple typo created a fairly subtle and hard-to-trace bug.

Loving your self.

A while ago I was giving a presentation that included a quick introduction to Python. An audience member asked a question that caught me off guard: isn't explicitly prefixing “self.” to each member access annoying? Looking back, when I started programing Python, yes it was annoying. Nowadays, however, I don't mind it at all, and in fact prefer it compared to languages with implicit member accesses. At the time I couldn't rationalize why that was, however, which indicated that I needed to give the issue further consideration. In a language designed for rapid development, why should anyone put up with typing five extra characters over and over? This question lingered in my mind for a while, but things finally clicked in place when I ran into a bug while programming Actionscript.