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.

An advantage of writing shaders in Python is that the same functions can be called on both the CPU and the GPU. For example, in the following code the function rgb2srgb is used to gamma correct colors on the GPU. The same function is also used to gamma correct the clear color on the CPU, so it matches the colors output by the shader. In general, arbitrary color processing could be applied in the shader: tone mapping, etc. Unless the same processing is applied to the clear color (which is not processed by the shader), the rendered objects may "pop out" from the background. For example, if fog is used and the clear color is not processed the same way as pixels, distant objects will fade to a color that does not match the background.

This is the original Python code:

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

  context.position = self.projection*newpos


def shadeFragment(self, context, pos, normal):
  n = normal.normalize()
  e = -pos.normalize()

  # Light into camera space
  trans = self.worldToCamera
  lightPos = trans*self.lightPos

  lightDir   =
  lightDist2 =
  lightDist  = lightDist2**0.5
  l = lightDir/lightDist

  lightAtten = 1.0/(0.01+lightDist2*(1.0/(100.0**2)))
  transfer = self.material.transfer(n, l, e)
  modulated = transfer*lightAtten

  mainColor = self.material.color*(self.ambient+modulated)

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


  1. Hi, you have posted such precious and informative article which gave me lot of information. I hope that you will keep it up and we will have more informative and helping news from you. Thanks | Dissertation Writing Services

  2. Hi, I think u have posted the best article according to information. keep it up I will be glad to see such informative and helping article from u. very useful information.. thanks for sharing
    custom assignment writing services

  3. Take a deep breath and let the temptation pass. It is never, ever a good plan to do projects for your child. You will fail Parenting 101 with flying colors. There are some things you can do to help this last minute project be successful, like...
    paper on sale

  4. I found that site very usefull and this survey is very cirious, I ' ve never seen a blog that demand a survey for this actions, very curious... Essay Writing Help UK

  5. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well.. best executive resume service

  6. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. Best Essay Writing Service UK

  7. This is a great inspiring article.I am pretty much pleased with your work.You can really really helpful information. Keep it up. Keep blogging. Looking to your next post.
    best dissertation writing service

  8. Ducat is one of the sap training institute in noida with 100% placement support. Ducat has well defined course modules and training sessions for students. At Ducat ERP SAP training is conducted during day time classes, weekend classes, evening batch classes and fast track training classes.

    sap training in noida

  9. Your post is very great.i read this post this is a very helpful. i will definitely go ahead and take advantage of this. You absolutely have wonderful stories.Cheers for sharing with us your blog. python training in noida

  10. Objectivity is one quality that must absolutely be possessed by an editor. Hire an academic editor who is impartial and has written PhD dissertation before. Best Dissertation Writing Services UK

  11. Thank you for taking the time to publish this information very useful! essay代写

  12. I read your article a couple of times.Your views are in accordance with my own for the most part. This is great content for your readers. we are best water treatment company in Dubai UAE

  13. If you have one particular weblog I like reading every day, it’s that one particular. we are best shower filter thanks.