Exhausting list of all the built-it uniforms avaiable in Jitter shaders


    Nov 08 2020 | 11:40 am
    Hi everyone,
    once in a while, looking inside jitter shaders, I discover some new GL3 built-in uniforms never saw before. Sometimes, they provide the answer to problems I didn't know how to address before. I looked inside the jitter documetation, but I didn't find an exhausting list of all the avaiables built-in uniforms. I know many of them can be found in the GLSL documentation out there, but i'd love to have a comprehensive list of what Max and GLSL can offer to let the user build their own shaders. Here there are the uniforms i met so far and what i understood about them:
    [EDIT]
    MATRICES: type="mat4" state="MODELVIEW_PROJECTION_MATRIX" == P * V * M type="mat4" state="PREV_MODELVIEW_PROJECTION_MATRIX" == the previous frames modelview-projection matrix type="mat4" state="VIEW_PROJECTION_MATRIX == P * V type="mat4" state="MODELVIEW_MATRIX" == V * M type="mat4" state="VIEW_MATRIX" == V type="mat4" state="WORLD_MATRIX" == transforms into world coordinates type="mat4" state="PROJECTION_MATRIX" == P type="mat4" state="CAM_PROJECTION_MATRIX" == (gl3 only) Provides the current rendering cameras projection matrix; in most cases is equivalent to PROJECTION_MATRIX except in cases where a full-screen quad is rendering, e.g. in a jit.gl.slab/pix (or jit.gl.pass) type="mat3" state="NORMAL_MATRIX" == it orients the normals in eye space type="mat4" state="TEXTURE0_MATRIX" == Transforms normalized texture coordinates into rect coordinates
    CAMERA: type="float" state="FAR_CLIP" == Camera far clipping distance type="float" state="NEAR_CLIP" == Camera near clipping distance type="vec3" state="FAR_CORNER" == far corner of the view frustum type="vec3" state="CAMERA_POSITION" == camera position in world space type="vec3" state="CAMERA_DIRECTION" == camera direction in world space type="vec2" state="VIEWPORT" == the pixel size of rendering window type="vec2" state="INVERSE_VIEWPORT" == the inverse of the viewport dims
    LIGHT: type="mat4" state="LIGHT_VIEWPROJ_MATRIX0-7" == scene seen from the light position??? type="float" state="LIGHT_RANGE0-7 " == distance reached by the light type="vec3" state="LIGHT0-7_POSITION" == position on the light type="vec3" state="LIGHT0-7_DIRECTION" == direction of the light type="vec4" state="LIGHT0-7_AMBIENT" == ambient light color type="vec4" state="LIGHT0-7_DIFFUSE" == diffuse light color type="vec4" state="LIGHT0-7_SPECULAR" == specular reflection color type="float" state="LIGHT0-7_CUTOFF" == the spotlight cutoff in degrees (=spotlight angle) type="float" state="LIGHT0-7_EXPONENT" == exponent implied in the reflected light calculation
    MATERIAL: type="vec4" state="DIFFUSE" == material diffuse color type="vec4" state="AMBIENT" == material ambient color type="vec4" state="SPECULAR" == material specular color type="vec4" state="EMISSION" == mterial emission color state="FRONT_MATERIAL" == gives the values from the @mat_X attributes of the 3Dobj to which the shader is attached. VERTEX: type="vec3" state="POSITION" == XYZ Position type="vec4" state="COLOR" == RGBA Color type="vec3" state="NORMAL" == Normal vectors type="vec3" state="TANGENT" == Tangent vectors type="vec3" state="BITANGENT" == Bitangent vectors type="vec3" state="VERTEX_ATTR" == Custom vertex attribute type="vec3" state="VERTEX_ATTRn" == (where "n" is an integer number) Nth custom vertex attribute type="float" state="EDGEFLAG" == unused, ignore
    TEXTURES: type="vec2" state="TEXDIM0" == XY Dimension of texture 0 type="vec2" state="TEXCOORD" == XY texture coordinates
    These are the built-in uniforms i know. I ignore the meaning of some entries in this list and I guess I'm still missing some of them. Could you please integrate the list with the uniforms you know? I will edit this first post adding the entries you provide, so to keep everything compact. It would be very usefull if an analogue list were done with built-it variables.
    Hope this could be usefull to you as much as it is to me. Thank you very much!

    • Nov 08 2020 | 9:34 pm
      Thank you for this Matteo! You are right, the MODEL_MATRIX doesn't exist. The Model Space is just the position of the vertices as they come from inside the model, in which usually the 0,0,0 is the center of the model itself. If you need the coordinates in WORLD SPACE you can use the WORLD_MATRIX built-in. FRONT_MATERIAL will give you the values from the @mat_X attributes of the 3Dobj to which the shader is attached. layout (std140) uniform FrontMaterialParameters { MaterialParameters frontMaterial; }; Check the shader generated by the jit.gl.material object with the get_gl3_shader message to see how this works. You probably know this already but maybe can be useful for others: in the Max documentation "Appendix C: The JXS File Format" one can find all the built-in variables for the GLSL jxs shader format.
    • Nov 09 2020 | 3:49 pm
      Thank you very much Federico! I honestly missed that appendix...I added the missing entries in the original post, but some are still a bit obscure to me:
      type="mat4" state="PREV_MODELVIEW_PROJECTION_MATRIX" == ??? type="mat4" state="CAM_PROJECTION_MATRIX" == This one doesn't exist in the documentation, but i found it in mrt.ssao.render.gl3.jxs type="vec3" state="FAR_CORNER" == far corner of the view frustum??? type="vec2" state="VIEWPORT" == ??? type="vec2" state="INVERSE_VIEWPORT" == ??? type="float" state="LIGHT0-7_CUTOFF" == spot light falloff??? type="float" state="EDGEFLAG" == ???
    • Nov 11 2020 | 10:35 am
      Ok so I think I can only add my contribution with VIEWPORT, which is simply the size in pixels of the rendering window. Keep it up Matteo! GLSL needs to be demystified
    • Nov 11 2020 | 1:36 pm
      PREV_MODELVIEW_PROJECTION_MATRIX - the previous frames modelview-projection matrix, used for velocity based effects (e.g. jit.gl.pass @fxname motionblur)
      CAM_PROJECTION_MATRIX - gl3 only, provides the current rendering cameras projection matrix, which in most cases is equivalent to PROJECTION_MATRIX except in cases where a full-screen quad is rendering, e.g. in a jit.gl.slab/pix (or jit.gl.pass). used in the gl3 engines ssao effect
      FAR_CORNER == far corner of the view frustum??? - yup. used for depth rebuilding i think, can't quite remember. ssao shader maybe?
      VIEWPORT - as federico says above, the pixel size of rendering window INVERSE_VIEWPORT - just as it sounds, the inverse of the viewport dims
      LIGHT0-7_CUTOFF - the spotlight cutoff in degrees, another name for the spotlight angle
      EDGEFLAG - unused, ignore
    • Nov 11 2020 | 2:14 pm
      Thank you so much, Federico and Rob! I updated the list in the first post. I'll soon indicate for each built-it uniform a .jxs file in which it gets used, so that each variable can be seen in action in a reference patch.
      btw, I wanted a "PREV_MODELVIEW_PROJECTION_MATRIX"-like variable so bad, and it was right under my nose...
    • Nov 11 2020 | 6:36 pm
      cool, thanks much for taking the initiative here! btw the PREV_MODELVIEW_PROJECTION_MATRIX is not yet implemented in gl3, but I hope to fix that sooner than later
    • Dec 28 2020 | 2:25 pm
      Insane help here, and some example of code in action would indeed be of enormous value :o, I'm following you guys : )
    • Dec 28 2020 | 9:15 pm
      Hi Riccardo, this tutorial I made today should be a fitting example of code in action: https://youtu.be/gKIVuVCfBws
    • Dec 29 2020 | 12:10 am
      Oww, I felt like being halfway to convert it and here you come. Thanks for the enlightening coding.
    • Jan 08 2021 | 4:28 pm
      texture2D became texture... what about texture2DRect? If textureRect is the solution, this wasn't my real problem :o
    • Jan 08 2021 | 4:36 pm
      I've been feeding a shader with two textures, the first for extrusion purpose, the second is the texture to be applied over the distorted shape. If i use "outColor = color" I can see my grey shape being distorted from the first texture, but when I'm trying to use my second texture, I'm getting this...
      I'm hoping the problem lies here, if it is not, I can share the full code attached to a simple patcher as example.
      Best regards
    • Jan 08 2021 | 4:43 pm
      Hi Riccardo, I think you get this error because you are using a vec4 as a second argument to the function "texture", which takes a vec2 as a second argument. I think you mixed up multiplying the texcoord by the texture matrix, for which you need a vec4, and using the texcoord to read the texture with the "texture" function.
    • Jan 08 2021 | 5:01 pm
      It totally make sense. Still I'm playing with an invisible shape ohoh. I'll give it some more tries.
    • Apr 06 2021 | 10:39 am
      I found another one: state="BACK_MATERIAL" What is this? I guess it something related/opposite to FRONT_MATERIAL
    • Apr 06 2021 | 8:30 pm
      undocumented and unsupported at this time
    • Apr 07 2021 | 12:11 pm
      ah ok, thanks! I found this in one of the gl3 example patches