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.