Friday, November 27, 2009
Sunday, November 22, 2009
On the other hand, if the correct color processing is applied to the clear color, the result is much more satisfying:
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
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
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.
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.