From BlenderWiki

Jump to: navigation, search
Note: This is an archived version of the Blender Developer Wiki. The current and active wiki is available on wiki.blender.org.

Name

Mitchell Stokes

Email / IRC / WWW

I can be contacted via email at mogurijin@gmail.com, and I’m also registered on blenderartists.org as Moguri. Furthermore, on freenode I frequent the #blendercoders, #gameblender, and #blender channels using the nick Moguri.

Synopsis

The ability to use GLSL shaders in the BGE has allowed people to do some great things. However, when I was trying to add geometry shader support, I found that the api the BGE was using for the GLSL shaders was not as flexible as it should be and it didn’t properly reflect how GLSL shaders were run. For example, the current implementation does not allow the user to only use a vertex shader. The user has to use both a fragment and vertex shader. GLSL allows the use of a vertex shader without a fragment shader. To this end, I plan to create a more flexible api and add geometry shader support. I also plan to allow users to attach shader scripts directly to materials through the UI for more flexibility and ease of use.

Benefits to Blender

The BGE will have support for GLSL geometry shaders, which are still fairly new (I don’t think Unity3D has support for them yet). Also, the BGE will have a bit more flexible shader api and the ability to attach GLSL shaders directly to materials for extra ease of use.

Deliverables

This project delivers four main things:
  • Improved BGE GLSL Python api
  • GLSL Geometry shader support
  • The ability to attach GLSL shaders to materials
  • The ability to adjust GLSL script uniforms through the UI

Project Details

This reworked shader system will use generic shader objects to represent the shaders (vertex, fragment and geometry), which will be attached to either the material or the game object (I haven’t decided which would be better yet). The shader objects will be exposed to Python with properties like source and methods such as setUniform(name, value) (this could possibly be a dictionary too).
As far as the UI goes, a new panel will be created for attaching shaders. This panel will be available in the material properties when the Blender Game render engine is selected. When shaders are attached, they will be parsed for uniform values which will be displayed in the UI and be adjustable. When the BGE is run, the converter will take the shader data and compile it into the appropriate shader object. I will look into displaying the shaders in the viewport as well, but I am unsure if this will be feasible.
Here is an example using GLSL vertex and fragment shaders:
Vertex:
void main()
{
	// Transforming The Vertex
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
Fragment
uniform vec4 ob_color;

void main()
{
	// Setting Each Pixel To The User-Defined Color
	gl_FragColor = ob_color);
}
The plan is if these two scripts are attached to a material, the user would then get the option to input values for ob_color. The values would probably default to (0.0, 0.0, 0.0, 0.0).

Project Schedule

I will begin work on the project as soon as possible after “official” work begins in May. As far as a time frame for the project, I am uncertain. It depends on if I hit any major (and unexpected snags) and how much of the existing code I can reuse.
A rough outline of milestones is as follows
  • Create the shader object and accompanying Python api
  • Add geometry shader support
  • Run some tests using the Python api to create and edit shader objects
  • Create the UI for attaching shader objects
  • Add code to the converter for creating shader objects from UI data
  • Implement shader script parsing for uniform values
  • If possible allow displaying the shaders in the viewport
  • Write documentation and example GLSL scripts

Bio

My name is Mitchell Stokes and I am an 18 year old Computer Science student at Eastern Washington University. My main hobby is game development, which I primarily use the Blender Game Engine for. I also enjoy contributing code to the Blender Game Engine, which I have been doing for over a year now.
I’ve contributed a few things to the Blender Game Engine including:
  • Participated in the 2.49 BGE Python API cleanup
  • Added functionality to the BGE Python API such as KX_Scene.addObject() and GameLogic.sendMessage()
  • Added the ability to run OpenGL code with Python scripts via KX_Scene callbacks
  • Fixed some lighting bugs
  • Fixed some bugs from when the BGE was ported to 2.5
As far as coding experience goes, I started coding about five years ago with XHTML, CSS and PHP. After doing various web projects for a while, I started getting interested in game development. To this end, I started learning Python to use with the Blender Game Engine, which was back in around the Spring of 2008. In the Fall of 2008 I started learning C++ to be able to contribute to the BGE. Up to this point I had mostly taught myself programming. I began a more formal learning at Eastern Washington University last Fall (2009) and I am now learning Java.