Show / Hide Table of Contents

    Interface IShader

    Represents a shader which is a user defined program that can be written to directly affect what's rendered on the screen. See here: https://www.opengl.org/wiki/Shader We're currently supporting vertex & fragment shaders.

    Namespace: AGS.API
    Assembly: AGS.API.dll
    Syntax
    public interface IShader

    Properties

    | Improve this Doc View Source

    ProgramId

    Gets the program identifier for the shader (used by GLSL).

    Declaration
    int ProgramId { get; }
    Property Value
    Type Description
    System.Int32

    The program identifier.

    Methods

    | Improve this Doc View Source

    Bind()

    Binds the shader. This must be performed from the rendering thread. Once the shader is bound, all rendering activities will run through the shader until it is unbound (or when another shader is bound). Setting variables for the shader must also be performed when the shader is bound.

    Declaration
    void Bind()
    Examples
    //assuming shader was already successfully compiled...
    shader.Bind(); //shader is now in control!        
    | Improve this Doc View Source

    Compile()

    Compiles this shader.

    Declaration
    IShader Compile()
    Returns
    Type Description
    IShader

    Will return itself if compiled successfully or null if there are compilation errors (those will be logged to the screen).

    Examples

    A common pattern will look like this:

    const string VERTEX_SHADER = "GLSL vertex shader code goes here";
    const string FRAGMENT_SHADER = "GLSL fragment shader code goes here";
    IShader shader = GLShader.FromText(VERTEX_SHADER, FRAGMENT_SHADER).Compile();
    if (shader == null)
    {
      //oh oh, it did not compile!
    }

    There's also a possibility of loading the shader from a resource/file:

    IShader shader = await GLShader.FromResource("vertexShader.glsl", "fragmentShader.glsl");
    | Improve this Doc View Source

    SetTextureVariable(String, Int32)

    Sets a texture variable in the shader program.

    Declaration
    bool SetTextureVariable(string name, int texture)
    Parameters
    Type Name Description
    System.String name

    The name.

    System.Int32 texture

    The texture.

    Returns
    Type Description
    System.Boolean

    True if the variable was found and set

    | Improve this Doc View Source

    SetVariable(String, Color)

    Sets a color variable in the shader program (GLSL sees it as a 4d vector). This is just a convenience method that can be used instead of the 4d version for colors.

    Declaration
    bool SetVariable(string name, Color c)
    Parameters
    Type Name Description
    System.String name

    The name of the variable.

    Color c

    The color.

    Returns
    Type Description
    System.Boolean

    True if the variable was found and set

    Examples
    //In GLSL shader:
    uniform vec4 myColor;
    //Do stuff with myColor...
    ...
    ...
    //In AGS code:
    shader.Bind();
    shader.SetVariable("myColor", Colors.White);
    | Improve this Doc View Source

    SetVariable(String, Single)

    Sets a float variable in the shader program.

    Declaration
    bool SetVariable(string name, float x)
    Parameters
    Type Name Description
    System.String name

    The name of the variable.

    System.Single x

    The value.

    Returns
    Type Description
    System.Boolean

    True if the variable was found and set

    Examples
    //In GLSL shader:
    uniform float myVariable;
    //Do stuff with myVariable...
    ...
    ...
    //In AGS code:
    shader.Bind();
    shader.SetVariable("myVariable", 5.5f);
    | Improve this Doc View Source

    SetVariable(String, Single, Single)

    Sets a 2d vector variable in the shader program.

    Declaration
    bool SetVariable(string name, float x, float y)
    Parameters
    Type Name Description
    System.String name

    The name of the variable.

    System.Single x

    The x value.

    System.Single y

    The y value.

    Returns
    Type Description
    System.Boolean

    True if the variable was found and set

    Examples
    //In GLSL shader:
    uniform vec2 myVariable;
    //Do stuff with myVariable...
    ...
    ...
    //In AGS code:
    shader.Bind();
    shader.SetVariable("myVariable", 5.5f, 3f);
    | Improve this Doc View Source

    SetVariable(String, Single, Single, Single)

    Sets a 3d vector variable in the shader program.

    Declaration
    bool SetVariable(string name, float x, float y, float z)
    Parameters
    Type Name Description
    System.String name

    The name of the variable.

    System.Single x

    The x value.

    System.Single y

    The y value.

    System.Single z

    The z value.

    Returns
    Type Description
    System.Boolean

    True if the variable was found and set

    Examples
    //In GLSL shader:
    uniform vec3 myVariable;
    //Do stuff with myVariable...
    ...
    ...
    //In AGS code:
    shader.Bind();
    shader.SetVariable("myVariable", 5.5f, 3f, 0.1f);
    | Improve this Doc View Source

    SetVariable(String, Single, Single, Single, Single)

    Sets a 4d vector variable in the shader program.

    Declaration
    bool SetVariable(string name, float x, float y, float z, float w)
    Parameters
    Type Name Description
    System.String name

    The name of the variable.

    System.Single x

    The x value.

    System.Single y

    The y value.

    System.Single z

    The z value.

    System.Single w

    The w value.

    Returns
    Type Description
    System.Boolean

    True if the variable was found and set

    Examples
    //In GLSL shader:
    uniform vec4 myVariable;
    //Do stuff with myVariable...
    ...
    ...
    //In AGS code:
    shader.Bind();
    shader.SetVariable("myVariable", 5.5f, 3f, 0.1f, 2.5f);
    | Improve this Doc View Source

    Unbind()

    Unbinds this shader, leaving control to the normal renderer. This must be performed from the rendering thread.

    Declaration
    void Unbind()
    Examples
    shader.Bind(); //shader is now in control!
    await Task.Delay(2000);
    shader.Unbind(); //shader is done, back to normal rendering.
    • Improve this Doc
    • View Source
    Back to top Generated by DocFX