Create a ticket

Q100410: How to make a raw texture-lookup call in custom GLSL by passing in a texture


When writing up a Custom Shader, Layer or Node XML for Mari, it is sometimes more convenient to keep custom GLSL functions contained in a separate file. If you choose to keep these functions in a separate file, you will need to use the cubemap texture-lookup which allows the function to run its own special processing.

This article explains how to make a raw texture-lookup call in Mari, so that the same call will work consistently across different shader modes and between future releases of Mari.


Although this is not considered an official feature of Mari, when developing a Custom Shader, it was previously possible to obtain a samplerCube from the imagecube attribute of a custom node. From this, in past Mari versions, users were able to create a raw texture-lookup that utilises the GLSL's texture() function.

In Mari 3.4v1 and 4.1v1, internal improvements to Mari's Shader system now mean that Mari uses an indirection variable for texture-lookup, instead.


In order to work around these changes and create a raw texture-lookup, you will need to:

  1. Include Texture.glslh in your XML
  2. Declare your texture sampler as cubemapToken
  3. Make use of mriTexture() or mriTextureLod() in order to do a texture look up in the same way that texture() and textureLod() are used in GLSL



On the caller side in a node XML file, a call to custom GLSL function can be made like below:

<Attribute Name="Cubamap" PrettyName="Image" Type="imagecube"></Attribute>
textureSampleColor = customCubemapLookup( $Cubemap, coords, lod ); 

Then in the GLSL header file, the custom function that takes in cubemapToken argument can be declared like:
//! include | Texture.glslh
vec4 customCubemapLookup(cubemapToken cubemapTexture, vec3 dir, float lod);

Beyond this, within the GLSL source code file, the custom function that takes in cubemapToken argument can be defined. The mriTexture() and mriTextureLod() functions can be used to look-up the actual texture values, like:
#version 150
//! include | Texture.glslh
vec4 customCubemapLookup(cubemapToken token, vec3 coords, float lod)
    return mriTextureLod(token, coords, lod);
Was this article helpful?

We're sorry to hear that!

Please tell us why.
0 out of 0 found this helpful