3
$\begingroup$

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?

$\endgroup$
5
+50
$\begingroup$

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:

logic

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.