Shader files variables
  • themarra
    junior Member
    Posts: 7
    Joined: Mon Sep 02, 2019 11:55 am

    Shader files variables

    by themarra » Mon Jan 27, 2020 6:01 pm

    Hi, I'm new to GLSL and have been trying to implement a shader/an FS file for transforming an equirectangular projection to cube maps, but I'm still trying to understand what are the variables that madMapper uses.

    1) How do I access the pixel coordinates of the Quad. In GLSL this would be fragCoord.xy but it seems that this doesn't work.

    2) In what variable does madMap expect us to store for outputting the current color of the pixel?

    3) Where can I see what the special functions of madMapper does? For example MM_SHADER_NORM_PIXEL() or MM_SHADER_THIS_NORM_PIXEL(). Is there a source code or complete list of the functions and what it does?
  • mad-matt
    garageCube team
    Posts: 1478
    Joined: Mon Sep 09, 2013 5:50 pm

    Re: Shader files variables

    by mad-matt » Wed Jan 29, 2020 12:23 am

    1) So you want to write an FX, not a Material ? FX Editing is not officially supported but there's a folder in User Documents/MadMapper/FX/quad where to pu .FS and .VS files. But that will be changed in a future version (when we'll add official editing / sharing of FX)

    MadMapper follows ISF specification. You can get the coordinate of your pixel inside the input media using "isf_FragNormCoord"
    In a FX the uniform "mm_SurfaceCoord" is a vec2 containing the position of the pixel inside the quad (in the output, not related to the position in the input media - but equal if you quad shows the entire media)

    This is for instance the code of the Vertex Noise vertex shader:

    Code: Select all

    in vec4 in_Vertex; in vec4 in_TexCoord0; uniform mat4 modelViewProjectionMatrix; uniform mat4 textureMatrix; out vec2 isf_FragNormCoord; out vec2 mm_SurfaceCoord; out float mm_alpha; #include "MadNoise.glsl" void main() { isf_FragNormCoord = (textureMatrix*vec4(in_TexCoord0.xy,0,1)).xy; mm_SurfaceCoord = in_TexCoord0.zw; mm_alpha = in_Vertex.w; vec2 noisePos = mm_SurfaceCoord.xy; float noisex = noise(vec3(noisePos + 0.123,fx_noise_time)); float noisey = noise(vec3(noisePos + 0.345,fx_noise_time)); gl_Position = modelViewProjectionMatrix * vec4(in_Vertex.xy + vec2(noisex,noisey)*fx_power,0,1); #ifdef IS_MATERIAL materialVsFunc(isf_FragNormCoord); #endif }
    2) In what variable does madMap expect us to store for outputting the current color of the pixel?
    The output of a fragment shader is defined by the fragment shader, then the "main" function must fill it, ie
    out vec4 out_color;
    void main()
    {
    out_color = MM_SHADER_THIS_NORM_PIXEL();
    out_color *= modulationColor;
    }
    For Materials, which can be used on a quad or any other surface, you don't directly write a "main" function, you write a function called "materialColorForPixel" that returns the color as a vec4 (rgba). The documentation of materials can be reached from MM Help Menu

    3) Ok so you confirm me you want to write an FX.
    FX have just a few specific definitions, which are different when using it
    with a texture:
    #define MM_SHADER_NORM_PIXEL(pos) IMG_NORM_PIXEL(inputImage,pos)
    #define MM_SHADER_THIS_NORM_PIXEL() MM_SHADER_NORM_PIXEL(isf_FragNormCoord)
    #define MM_SHADER_IMG_SIZE() IMG_SIZE(inputImage)
    or with a material:
    #define MM_SHADER_NORM_PIXEL(pos) clamp(materialColorForPixel(pos),0.0,1.0)
    #define MM_SHADER_THIS_NORM_PIXEL() MM_SHADER_NORM_PIXEL(isf_FragNormCoord)
    #define MM_SHADER_IMG_SIZE() vec2(1024)

    Actual FX code is not hidden, find it here:
    /Applications/MadMapper 3.7.5.app/Contents/Resources/SystemModules/Surface Shaders/shaders
    Or on Windows in MM folder/Resources/SystemModules/Surface Shaders/shaders

    Let us know if you made a great FX !

Who is online

Users browsing this forum: No registered users and 18 guests