CgFX in Python


Masters Thesis in Computer Science, 20 credit points, completed 2003-10-22
Student: Jonas Jonsson
Supervisor: Lennart Ohlsson, Department of Computer Science, Lund University

Description

A shader is a program which replaces the fixed-function hardware pipeline. A vertex shader program is excecuted for every vertex, performing tranformations and lighting calculations. A pixel shader program is excecuted for every pixel performing colouring and texture lookups.

This Master's thesis in computer graphics is about combining real-time shaders with scripting languages. This is done using Nvidia's effect format CgFX and the programming language Python. CgFX is an effect format which is a part of the Cg language. An effect contains all rendering conditions needed to render a particular appearance of an object.

CgFX are accessed through an interface provided by Nvidia called ICgFXEffect. This interface cannot be used directly from Pyhton, so a wrapper class is written in C++ to act as a layer between CgFX and Python. This wrapper class is called PyCgFXEffect and is wrapped to a Python module using SWIG.

PyCgFXEffect is used to create the Effect class. This Effect class handles all loading and rendering of effects. It is through this class an application written in Python can access CgFX effects.

Environmental Bump Mapping Anisotropic Lighting Cartoon Shading

These screenshots are examples of effects rendered with the Python Effect class.

Abstract

Real-time graphics is one of the fastest growing areas in computer graphics today, where modern graphics hardware can produce almost cinematic rendering. Shaders provide a new level of control over the rendering pipeline.

This master’s thesis is about combining real-time graphics programmability with scripting languages. This is accomplished by using Nvidia’s effect format CgFX and the programming language Python. This approach enables high level scene descriptions and geometric abstractions. CgFX is a file format encapsulating rendering conditions to achieve a certain visual appearance.

Python is an interpreted, high-level, object-oriented, open-source programming language, used for scripting and gluing existing components together. The dynamic bindings and semantics of the language significantly simplify connecting the parts of a graphics renderer.

This report describes the result; a Python effect class and the way it can be used in a Python renderer. This thesis has also involved a thorough study of programmable real-time computer graphics, therefore a considerable part of the report is a result of this study.

The Report

The report is in PDF format and can be read here.

Files

The Effect class and the wrapper class can be downloaded here.

Links

www.pyhton.org
www.swig.org
pyopengl.sourceforge.net
developer.nvidia.com
www.swig.org