MartinusMagneson's picture

Magneson (@MartinusMagneson)

Groups

    MartinusMagneson's picture
    Magneson commented on George_Toledo's Discussion, “mouse click bool/int/float

    You can use the "Receive Mouse Buttons" along with a "Select Latest (2)" to get a simple 0/1 return value (or any two different return values).

    MartinusMagneson's picture
    Magneson commented on George_Toledo's Discussion, “GLSL Image Generator

    If “TIME” is capitalized and it is working, it is not the same “time” variable that corresponds with the protocol input port for time, it appears to be a value that the shader can receive via standard uniforms, without receiving any data via ports.

    What I am trying to understand is, when a shader is created this way, there are these time, width and height ports existing as part of the protocol. How do I get these exact port values into the shader to work with?

    The time port, the TIME variable along with width and height are in a way just arbitrary input ports. If you save your shader to the library, they will work as regular input ports for their type, and they won't act on anything unless they get some sort of data/event. However, when you edit/run the shader in the shader editor, these values will be provided to you through those ports. If you run the code I first posted, and change the width/height of the rendering window the green amount will be decided by that relationship. In short, I think they are pre-defined uniforms that are reserved for the editor so that it can take over those for easier programming :)

    MartinusMagneson's picture
    Magneson commented on George_Toledo's Discussion, “GLSL Image Generator

    jersmi you can't start a variable name with a number. If you use #define twoPI 6.2831... it should work.

    I'm not sure if the implementation of inputs are totally there yet. It seems you can't add variables before declaring them in code either (they disappear for me at least).

    MartinusMagneson's picture
    Magneson commented on George_Toledo's Discussion, “GLSL Image Generator

    Yes - to both the questions I think actually. If I have understood it correctly, a fragment shader always needs a vertex shader to display anything (at least in Vuo). My guess is that the vertex shader is just a very basic quad and some default uniforms that sets up a framework for less boilerplate coding.

    At the risk of confusing you further, if you look at the code for a custom GLSL image filter node in the Vuo source (that is the C source, has nothing to do with the shader editor), you can find the following line setting up the shader:

    VuoShader_addSource(instance->shader, VuoMesh_IndividualTriangles, NULL, NULL, fragmentShaderSource);

    Looking at VuoShader_addSource in the API, it lists the inputs to the function as follows:

    void VuoShader_addSource (  VuoShader   shader,
        const VuoMesh_ElementAssemblyMethod    inputPrimitiveMode,
        const char *     vertexShaderSource,
        const char *     geometryShaderSource,
        const char *     fragmentShaderSource 
        )

    With this in mind, it can seem like there are no vertex shader for the fragment shader that does the filters, but in the notes of the function we can also read:

    GLSL vertex shader source code. If NULL, a default vertex shader is used (it passes texture coordinates through, and projects the vertex).

    Vuo Shader example: https://github.com/vuo/vuo/blob/main/example/node/imageFilterGLSL/exampl...

    VuoShader_addSource in the API: https://api.vuo.org/2.3.2/group___vuo_shader.html#gac8d913c0f6523783ba6b...

    MartinusMagneson's picture
    Magneson commented on George_Toledo's Discussion, “GLSL Image Generator

    Oh, I see it working by running it in the shader editor (like a composition). Time and resolution are supported without declaring any uniforms. If you use the Image filter protocol/editor there is also provided an image of a bird when you run it standalone.

    The code above is the only thing you need to input for a simple shader utilizing time, resolution and inputs. It will modulate the red channel by time, the green channel by the rendered window size, and the blue channel by a published port/slider.

    Pages