GLSL shader: set material uniforms

About Monkey 2 Forums Monkey 2 Programming Help GLSL shader: set material uniforms

This topic contains 4 replies, has 3 voices, and was last updated by  Anatol 1 year, 4 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #11851

    Anatol
    Participant

    Hi!

    I’m still brand new at GLSL shaders and I’m trying to pass a value into a shader. So in the .glsl file I have this (simplified):

    From Monkey2 (in a class that extends Image) I’m trying to set m_TestColor via

    This causes an error: “Invalid uniform type 0 expecting 4”.

    So how can I use SetVec4f or other UniformBlock methods? I assume I need those to pass something to a shader?

    Thank you.

    #11869

    Mark Sibly
    Keymaster

    Would need to see more code, it looks like it can’t find a uniform but I can’t really see how you’re setting things up etc.

    It’s the right general idea though.

    [edit]The shader related error message REALLY need some work! I’ll see what I can do here.[/edit]

    #11874

    nerobot
    Participant

    Don’t know what you do, but maybe my example will be useful.

    I took mojo’s sprite shader, removed unused vars and added TestColor into fragment section.

    #11877

    Anatol
    Participant

    Thanks Mark and nerobot. Both answers were really helpful, plus it’s a face palm situation for me. It’s true that the shader couldn’t find the uniform. I set it in a method that was never called, so naturally the shader was expecting a Vec4f but probably had a null, or 0 vector if that even exists. I’m still confused enough by shaders that I was looking in the wrong place.

    Actually I base my shader and ImageExtend on your sprite-masked shader, nerobot. That post was incredibly helpful. I just need to add a few “features” to the shader mask and I’m getting there one step at a time. Next up is a way to move/translate and scale the shader mask. I’ll see how I go and will share it in the forum.

    #12249

    Anatol
    Participant

    Sometimes it’s literally weeks until I find some more time for this, but for completeness’ sake and as I said I’ll share the result, I can simply send an offset value to the shader, e.g.

    which the shader will pick up and apply like this (simplified):

    For a full working example see this test on Github with a mask that moves based on mouse coordinates.

    Here’s the shader code.

    It’s not perfect but it shows how it works in principle.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.