BGEz Materials - Shader wrapper for the BGE

Hey everyone,

So last time I saw Martinsh work I was like “man this is awesome, how do I get it in my game ?”. But I was a bit unpleased by the way the shaders were applied in the BGE… So I made a submodule for my bigger framework, that can work independently: materials.

Link to the repository: https://gitlab.com/bgez/materials
Youtube video: https://www.youtube.com/watch?v=cRXFlVro75w
Screenshot:


This is some kind of wrapper/framework, it is meant to allow people to write shaders in a slightly better way, I hope.

I need your input on the utility of such a module, and maybe your own shaders if you get to make one !
I could embed them into the builtins if done right :slight_smile:

Feel free to look at the sources, especially in the materials/builtins/skybox0 to see an example of use for the module.

Extra:

Looks Great is it optimized and how is its impact on the performance of the Game, Im going to make use of this in one of my game projects :wink: but for now id just like to see how optimization can be applied especially for an open world map. The Code behind it is pretty neat i like neat work … Doesn’t really matter if it can be edited or tweaked u but nice framework so far buddy.

And keep up the Awesome Work !!!

Fred/K.S

Looking good! thanks for sharing :slight_smile:

I would love to help but shader programming for me is like reading ancient Egyptian algebra. Still, I think it is a really good idea and if implemented well would be nice to see included in UPBGE, as it sounds like it’s intention is of broader and more generalized scope.

I don’t really know GLSL either lol
But this allow for “easier” testing of shaders, as the code required to run one becomes maybe a bit simplier/clearer:


from materials import ShaderMaterial
from materials import ReadFile

class MyShader(ShaderMaterial):
    FragmentShader = ReadFile("./MyFragmentProgram.fs", __file__)
    VertexShader = ReadFile("./MyVertexProgram.vs", __file__)

    def init(self):
        # you can initialize the shader there

    def pre_draw_setup(self, shader):
        # and you can process stuff on events too

    def pre_draw(self, shader):
        # you have access to the shader and the object holding it
        print("owner:", self.owner)

    def post_draw(self, shader):
        # this is the last event you have access to
        print("shader:", shader)

With this you can really easily try to make your first shaders, and more sophisticated ones aswell as shown in the demo !

I think there may be some issues with the way it is managed right now, but I was hoping people could point a finger on the problems, so that the package could improve from there.

Its still a bit early to speak about putting this in UPBGE, we still have to really iron this out !

The main goal is to provide a strong foundation for some “alternative API”, programming is not necessarly easy, but it can be easier.

Just discovered that UPBGE implemented shader callbacks about a year ago, fair enough lol