assurance-tunnel
assurance-tunnel
assurance-tunnel
assurance-tunnel

[ANSWERED] Questions about GLSL in Isadora



  • I have been writing some shaders and have noticed some anomalies (or just been getting confused). I have a few questions so I'll ask them together. 

    Are the texture coordinates from the default vertex shader normalised?

    How can I save a shader as a glsl plugin if it has a vertex and a fragment shader?

    Is it possible to add an actor help to a glsl shader?

    What is the short name used for when making parameters?

    When I make a new glsl shader there are a few default parameters, are the ones that are created by default all that are available?

    The default shader sets the alpha as 1.0 is there a reason for this? Looking at some of the included shader files (the TT files downloadable from the troika tronix site) some do not pass the original alpha, is there a reason for this, is it linked to the first part of this question?

    Is the resolution parameter always passed to the shaders, no matter what is entered into the width and height parameters? What do the width and height actually do?

    For vertex shaders what is the matrix I should use to multiply by the position?

    That's all for now.

    Fred



  • @fred said:

    Your questions are in bold italic; my answers in plain text

    Are the texture coordinates from the default vertex shader normalised?

    I guess I'm not enough of an expert to answer this question. But I can show you the default vertex shader used by Isadora.

    If Isadora senses that the code is not ShaderToy code and the source contains the fragment "varying vec2 surfacePosition;" then the fragment shader will look like this

    attribute vec3 position;
    attribute vec2 surfacePosAttrib;
    varying vec2 surfacePosition;
    void main() {
        surfacePosition = surfacePosAttrib;
        gl_Position = vec4(position, 1.0);
    }

    Otherwise,  the default vertex shader is

    void main(void) {
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    }
    

    Does that answer your question?

    How can I save a shader as a glsl plugin if it has a vertex and a fragment shader?

    Use the extensions ".vert" and ".frag" when saving the files into the GLSL Plugins folder.

    Is it possible to add an actor help to a glsl shader?

    This is covered in the GLSL tutorial. The line you want is

    // ISADORA_PLUGIN_DESC("Description of what the plugin does here")

    What is the short name used for when making parameters?

    This is a unique identifier for the input. This means you can reorder the inputs and Isadora will maintain the correct connection. For example, if you have

    // ISADORA_FLOAT_PARAM(param_name_1, AAAA, 0, 1, 0, "Help for Paramter 1")
    // ISADORA_FLOAT_PARAM(param_name_2, BBBB, 0, 1, 0, "Help for Paramter 2")
    uniform float param_name_1;
    uniform float param_name_2;
    

    You will end up with two inputs, one called "param name 1" and the other "param name 2". Now imagine you make connections to those inputs, but you'd decide you like to reverse the order.

    // ISADORA_FLOAT_PARAM(param_name_2, BBBB, 0, 1, 0, "Help for Paramter 2")
    // ISADORA_FLOAT_PARAM(param_name_1, AAAA, 0, 1, 0, "Help for Paramter 1")
    uniform float param_name_1;
    uniform float param_name_2;
    

    Even after making this change, Isadora will maintain the correct connections to those inputs.

    When I make a new glsl shader there are a few default parameters, are the ones that are created by default all that are available?

    No. All of the uniforms expected by ShaderToy shaders are available.

    // uniform vec3         iResolution;              // xy = rendering resolution (in pixels) z component is always 1.0
    // uniform float        iGlobalTime;              // current time (in seconds)
    // uniform float        iTime;                    // current time (in seconds)
    // uniform vec4         iMouse;                   // xy contain the current pixel coords (if LMB is down). zw contain the click pixel.
    // uniform vec4         iDate;                    // (x = year, y = month, z = day, w = time in seconds)
    // uniform int          iFrame;                   // frame count
    // uniform float        iChannelTime[4];          // channel playback time (in seconds)
    // uniform vec3         iChannelResolution[4];    // xy = input channel resolution (in pixels), z is always 1.0
    // uniform sampler2D    iChannel0;                // sampler for input texture 0.
    // uniform sampler2D    iChannel1;                // sampler for input texture 1.
    // uniform sampler2D    iChannel2;                // sampler for input texture 2.
    // uniform sampler2D    iChannel3;                // sampler for input texture 3.

    As are those used with GLSL Sandbox shaders

    // uniform vec4 inputColor;
    // uniform float time; // elapsed time in seconds
    // uniform float time_delta; // time since last frame processed in seconds
    // uniform vec2 resolution; // resoution of the destination texture
    // uniform vec2 mouse;        // xy contain the current pixel coords (if LMB is down). zw contain the click pixel.

    Finally the vertex shader uniforms

    // uniform vec2 pos; // the point position for the current vertex -- from -1.0 to +1.0 in both dimensions (ShaderToy)
    // uniform vec2 position; // the point position for the current vertex -- from -1.0 to +1.0 in both dimensions(GLSLSandbox)
    // uniform vec2 inputTextureCoordinate; // the point position for the current vertex -- from 0.0 to +1.0 in both dimensions (GPUIMage)
    // attribute vec2 surfacePosAttrib; // needed by GLSL Sandbox... I'm going to have to do more research to remember what this is for!
    // varying vec2 surfacePosition; // needed by GLSL Sandbox... I'm going to have to do more research to remember what this is for!

    The default shader sets the alpha as 1.0 is there a reason for this? Looking at some of the included shader files (the TT files downloadable from the troika tronix site) some do not pass the original alpha, is there a reason for this, is it linked to the first part of this question?

    I wrote all of those or modified open source code to create them. As for the default shader, I guess I didn't really expect people to use the default shader... but honestly I didn't think that one through. It should pass the alpha.

    For the others, it probably came from the open source code I took it from (GPU Image.)

    TT Sliding Gradient.txt
    TT Sorbel Edge Detection.txt
    TT XY Luma Gradient.txt

    It's easy enough to modify these so you can pass the alpha if you wish to do so.

    Is the resolution parameter always passed to the shaders, no matter what is entered into the width and height parameters? What do the width and height actually do?

    The ''width" and "height" parameters allows you to override the default resolution assumed by the shader plugin.

    1) If either the ''width" or "height" parameters for a GLSL Shader are 0, then:
    -- If a shader accepts a video input, then the resolution of the destination texture will match the input
    -- If a shader has no video input (i.e., it generates video) then the  resoution of the destination texture will be the default resolution specified in the Isadora preferences.

    2) If the ''width" and "height" parameters for a GLSL Shader are both non-zero, then:
    -- The destination texture's resoution will be the resoution specified by those input

    Whatever that destination resolution is, it will be passed to the "resolution" and/or "iResolution" uniforms.

    For vertex shaders what is the matrix I should use to multiply by the position?

    Does the deafult code shown above answer that question?



  • @mark Thanks for the detailed response, super helpful.