I have a shader written in GLSL, I would like to import into Blender. I have already gathered, that I have to import it into BGE. Is it also possible for Cycles or BI (preferred)? In any case, how do I import a GLSL Shader?
1 Answer
Blender doesn't have way to directly interpret GLSL shaders. You can, however, use a BGE python script that tells blender to use a particular shader during a game's runtime.
To do this you will need two things: your GLSL shader formatted in the following way (inside of a text datablock)...
import bge
cont = bge.logic.getCurrentController()
VertexShader = """
void main(){
//your vertex shader here
}
"""
FragmentShader = """
void main(){
//your fragment shader here
}
"""
mesh = cont.owner.meshes[0]
for mat in mesh.materials:
shader = mat.getShader()
if shader != None:
if not shader.isValid():
shader.setSource(VertexShader, FragmentShader, 1)
and a bit of a logic brick setup: