def MainLoop ():
# for each object
for obj in ShaderObjects:
mesh_index = 0
mesh = obj.getMesh(mesh_index)
while mesh != None:
for mat in mesh.materials:
# regular TexFace materials do NOT have this function
if not hasattr(mat, "getMaterialIndex"):
return
mat_index = mat.getMaterialIndex()
# find an index
found = 0
for i in range(len(MaterialIndexList)):
if mat_index == MaterialIndexList[i]:
found=1
break
if not found: continue
shader = mat.getShader()
if not shader.isValid():
shader.setSource(VertexShader, FragmentShader,1)
shader.setNumberOfPasses(1)
shader.setUniform4f('vWidths', obj.Cel1, obj.Cel2, obj.Cel3, obj.LineWidth)
mesh_index += 1
mesh = obj.getMesh(mesh_index)
I would check out your source for that script. To me, it looks like some of it was written in C/C++ and some was written in python. I didn’t think you could run C/C++ scripts in the BGE. Not only that, there are two “functions” labeled “main()”, instead of just one (in C/C++). My first, and mostly uneducated guess is that it won’t work.
To try it and see what happens, create an object (suzy) and name it “Suzanne”. Load the script into a text window and call it “celshader.py” (or whatever you want). Go into logic (f4) and set them up as so:
ALWAYS — Python: celshader.py
I’d make sure to have a console/terminal open so you can look for errors.
in the apricot builds you can use the cell shading in the material buttons, they work in the game engine, no script/code required but there is a working cell shader, try searching the forums
Well as I wrote it I guess I should jump in here…
That was the old way of using GLSL, basically you define the vertex and fragment shaders as strings (note the GLSL code above is encased in triple quotes: “”"), then call the python functions to bind those shaders to the objects material. Which is why it’s a mix of Python and GLSL.
I don’t know if it’ll work in newer builds, but you should just be able to do what J09 states, hook up an always sensor->python controller and you’re good to go.
And yes, it does work, although maybe not in newer builds and as RagingChaos points out, it’s pretty much redundant now anyway.
Which one doesn’t work? The script or the shadows?
The script needs to be formatted, like all the tabs and spaces at the start of the lines need to be in place for python to make sense of it. Can you link the tutorial where you got the script from?
To get the realtime shadows you need to turn on Blender GLSL Materials in the Game menu in the main window and use a spot light to cast the shadows.
You need a SVN build of the Apricot branch to use the realtime GLSL materials and realtime shadows, but the script should work in Blender 2.46 when you run the game.
Edit: For future reference, the formatting of code is kept if you put it between code brackets by selecting the code and pressing the # key at the top of the window to post your comments:
So code appears like this
and you can start typing away from the start of the line
Edit 2: Below is a link to a thread that has some really great examples of scripts like the one you posted in action. Check out the scripts in the text editor (you only need Blender 2.46 for this, not one of the Apricot builds): http://blenderartists.org/forum/showthread.php?t=127869
google GLSL… basically if your card doesn’t support GLSL then it can’t do all the fancy cartoon shaders other special effects… most recent cards have been supporting it for at least 3 years by now…
I know Mico27 has a really nice toon shader script. It works very well, and it is easy to tweak to your needs. If you search the forums for toon shading, which is another name for cell shading, you should find a thread with Mico27’s script.