SUMMARY
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.
MORE INFORMATION
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.
WHAT YOU WILL NEED TO DO
In order to work around these changes and create a raw texture-lookup, you will need to:
- Include Texture.glslh in your XML
- Declare your texture sampler as cubemapToken
- Make use of
mriTexture()
ormriTextureLod()
in order to do a texture look up in the same way thattexture()
andtextureLod()
are used in GLSL
DEVELOPER EXAMPLE
On the caller side in a node XML file, a call to custom GLSL function can be made like below:
...
<Attribute Name="Cubemap" 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);
}
FURTHER HELP
If you are experiencing difficulties please create a support ticket and provide us with the information requested in this article:
Q100090: Information to send Support when reporting a Mari issue
For more information on how to open a Support ticket, please refer to this article:
Q100064: How to raise a support ticket
We're sorry to hear that
Please tell us why