The purpose of this post is documenting how to write GLSL code in Blender. I’m using Blender 2.77a windows 64 for this instruction.

The first step of setting up custom GLSL in Blender is choosing Blender Game. Because custom GLSL shader is only supported by Blender Game. How to select Blender Game as the engine?

  • Select Blender Game in the info header:
BlenderInfoHeader

If you are not sure where is the info header or you can’t find it.. please refer to this short answer to find the info header:

http://blender.stackexchange.com/questions/8384/how-can-i-reset-my-menus

Then, attach a sensor and a controller to a SELECTED object. Note that you have to select the object so Blender knows which object the sensor and the controller belong to! The following steps are for newbies:

  • Select an object: right-click an object. The object’s bounds should be highlighted by orange when it’s selected:
BlenderSelectedObject
  • Show the Logic Editor where we can set up the sensor and controller. Logic Editor can be found like this:
BlenderFindLogicEditor

Your fresh Logic Editor should be like:

BlenderLogicEditor
  • Attach a sensor for the selected object. Select “Add Sensor” -> “Always”
  • Attach a controller for the selected object. Select “Add Controller” -> “Python”. Set the file name in the Text Editor to the controller’s python name
  • Connect the sensor to the controller. Drag from the disk of the right side of the sensor to the disk of the left side of the controller. Now your Logic Editor should be like this:
BlenderLogicEditorSensorController

After attaching the sensor and controller to an object, set up the GLSL code in the python script. Try the python example in this wiki page first:

https://en.wikibooks.org/wiki/GLSL_Programming/Blender/Minimal_Shader

Render the scene! In the 3D view, hit ‘p’. The scene should be totally red. I changed the color to blue as the red scene is so scaring.. Hit ‘ESC’ to exit the rendering loop.

BlenderFirstScene
Advertisements