UUSL Textures
The Unified UNIGINE shader language (UUSL) unifies the way of using textures in shaders. You need to define the texture slot (unit number) in the material, initialize the texture in the shader's code and then use it.
Here is an example of using texture in the fragment shader's code:
// Include the UUSL header file
#include <core/shaders/common/fragment.h>
// Initialize textures.
// You don't need to define texture slot (unit number)
// by using define directive
INIT_TEXTURE(0,TEX_DEPTH)
INIT_TEXTURE(1,TEX_NORMAL)
INIT_TEXTURE(2,TEX_ALBEDO)
INIT_TEXTURE(3,TEX_SHADING)
/* Input and output structures */
MAIN_BEGIN(FRAGMENT_OUT,FRAGMENT_IN)
/* some code */
GBuffer gbuffer = GBufferDefault();
loadGBufferAlbedo(gbuffer, TEXTURE_OUT(TEX_ALBEDO),uv);
loadGBufferShading(gbuffer, TEXTURE_OUT(TEX_SHADING),uv);
loadGBufferNormal(gbuffer, TEXTURE_OUT(TEX_NORMAL),uv);
/* some code */
MAIN_END
Texture Initialization Functions#
The implementation of the SAMPLER(NUM) function in Direct3D is the following:
SamplerState s_sampler_ ## NAME : register(s ## NUM);
SamplerComparisonState s_sampler_compare_ ## NAME : register(s ## NUM);
INIT_TEXTURE ( value NUM, value NAME ) #
Initializes a sampler with the 2D texture.Equivalents
layout(binding=NUM) uniform sampler2D s_texture_ ## NAME;
Texture2D s_texture_ ## NAME : register(t ## NUM); SAMPLER(NUM,NAME)
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_TEXTURE_INT ( value NUM, value NAME ) #
Initializes a sampler with the 2D texture of int type.Equivalents
layout(binding=NUM) uniform usampler2D s_texture_ ## NAME;
Texture2D<int> s_texture_ ## NAME : register(t ## NUM); SAMPLER(NUM,NAME)
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_TEXTURE_UINT ( value NUM, value NAME ) #
Initializes a sampler with the 2D texture of uint type.Equivalents
layout(binding=NUM) uniform isampler2D s_texture_ ## NAME;
Texture2D<uint> s_texture_ ## NAME : register(t ## NUM); SAMPLER(NUM,NAME)
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_TEXTURE_CUBE ( value NUM, value NAME ) #
Initializes a sampler with the cubemap texture.Equivalents
layout(binding=NUM) uniform samplerCube s_texture_ ## NAME;
TextureCube s_texture_ ## NAME : register(t ## NUM); SAMPLER(NUM,NAME)
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_TEXTURE_3D ( value NUM, value NAME ) #
Initializes a sampler with the texture3D.Equivalents
layout(binding=NUM) uniform sampler3D s_texture_ ## NAME;
Texture3D s_texture_ ## NAME : register(t ## NUM); SAMPLER(NUM,NAME)
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_TEXTURE_ARRAY ( value NUM, value NAME ) #
Initializes a sampler with the array of 2D textures.Equivalents
layout(binding=NUM) uniform sampler2DArray s_texture_ ## NAME;
Texture2DArray s_texture_ ## NAME : register(t ## NUM); SAMPLER(NUM,NAME)
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_TEXTURE_ARRAY_INT2 ( value NUM, value NAME ) #
Initializes a sampler with the array of 2D textures of int2 type.Equivalents
layout(binding=NUM) uniform isampler2DArray s_texture_ ## NAME;
Texture2DArray<int2> s_texture_ ## NAME : register(t ## NUM); SAMPLER(NUM,NAME)
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_TEXTURE_ARRAY_UINT2 ( value NUM, value NAME ) #
Initializes a sampler with the array of 2D textures of uint2 type.Equivalents
layout(binding=NUM) uniform usampler2DArray s_texture_ ## NAME;
Texture2DArray<uint2> s_texture_ ## NAME : register(t ## NUM); SAMPLER(NUM,NAME)
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_TEXTURE_SHADOW ( value NUM, value NAME ) #
Initializes a sampler with the 2D shadow texture.Equivalents
layout(binding=NUM) uniform sampler2DShadow s_texture_ ## NAME;
Texture2D s_texture_ ## NAME : register(t ## NUM); SAMPLER(NUM,NAME)
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_TEXTURE_ARRAY_SHADOW ( value NUM, value NAME ) #
Initializes a sampler with the array of 2D shadow textures.Equivalents
layout(binding=NUM) uniform sampler2DArrayShadow s_texture_ ## NAME;
Texture2DArray s_texture_ ## NAME : register(t ## NUM); SAMPLER(NUM,NAME)
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_TEXTURE_CUBE_SHADOW ( value NUM, value NAME ) #
Initializes a sampler with the shadow cubemap textures.Equivalents
layout(binding=NUM) uniform samplerCubeShadow s_texture_ ## NAME;
TextureCube s_texture_ ## NAME : register(t ## NUM); SAMPLER(NUM,NAME)
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_W_TEXTURE ( value NUM, value NAME, value TYPE, value FORMAT ) #
Initializes input 2D write texture.Equivalents
layout(binding=NUM) coherent uniform layout(FORMAT) image2D s_rw_texture_ ## NAME;
RWTexture2D<FORMAT> s_rw_texture_ ## NAME : register(u ## NUM);
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
- value TYPE - A type of the texture (rgba8,rgba32f,etc.).
- value FORMAT - A format of the texture (float,float2,float3,float4,int).
INIT_RW_TEXTURE_R32U ( value NUM, value NAME ) #
Initializes a 2D input read-write texture that has R32U format type.Equivalents
layout(binding=NUM) coherent uniform layout(r32ui) image2D s_rw_texture_ ## NAME;
RWTexture2D<uint> s_rw_texture_ ## NAME : register(u ## NUM);
Arguments
- value NUM - Number of the texture slot.
- value NAME - Name of the texture slot.
INIT_RW_TEXTURE_R32F ( value NUM, value NAME ) #
Initializes a 2D input read-write texture that has R32F format type. Works only with USE_RW_TEXTURES enabled.Equivalents
layout(binding=NUM) coherent uniform layout(r32f) image2D s_rw_texture_ ## NAME;
RWTexture2D<float> s_rw_texture_ ## NAME : register(u ## NUM);
Arguments
- value NUM - Number of the texture slot.
- value NAME - Name of the texture slot.
INIT_RW_TEXTURE_RGBA8 ( value NUM, value NAME ) #
Initializes a 2D input read-write texture that has RGBA8 format type. Works only with USE_RW_TEXTURES enabled.Equivalents
layout(binding=NUM) coherent uniform layout(rgba8) image2D s_rw_texture_ ## NAME;
RWTexture2D<rgba8> s_rw_texture_ ## NAME : register(u ## NUM);
Arguments
- value NUM - Number of the texture slot.
- value NAME - Name of the texture slot.
INIT_RW_TEXTURE_R32U_3D ( value NUM, value NAME ) #
Initializes a 3D input read-write texture that has R32U format type. Works only with USE_RW_TEXTURES enabled.Equivalents
layout(binding=NUM) coherent uniform layout(r32ui) image3D s_rw_texture_ ## NAME;
RWTexture3D<uint> s_rw_texture_ ## NAME : register(u ## NUM);
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_RW_TEXTURE_R32F_3D ( value NUM, value NAME ) #
Initializes a 3D input read-write texture that has R32F format type. Works only with USE_RW_TEXTURES enabled.Equivalents
layout(binding=NUM) coherent uniform layout(r32f) image3D s_rw_texture_ ## NAME;
RWTexture3D<float> s_rw_texture_ ## NAME : register(u ## NUM);
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_RW_TEXTURE_RGBA8_3D ( value NUM, value NAME ) #
Initializes a 3D input read-write texture that has RGBA8 format type. Works only with USE_RW_TEXTURES enabled.Equivalents
layout(binding=NUM) coherent uniform layout(rgba8) image3D s_rw_texture_ ## NAME;
RWTexture3D<rgba8> s_rw_texture_ ## NAME : register(u ## NUM);
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
INIT_W_TEXTURE_3D ( value NUM, value NAME, value TYPE, value FORMAT ) #
Initializes input 3D write texture. Works only with USE_RW_TEXTURES enabled.Equivalents
layout(binding=NUM) coherent uniform layout(FORMAT) image3D s_rw_texture_ ## NAME;
RWTexture3D<FORMAT> s_rw_texture_ ## NAME : register(u ## NUM);
Arguments
- value NUM - A number of the texture slot.
- value NAME - A name of the texture slot.
- value TYPE - A type of the texture (rgba8,rgba32f,etc.).
- value FORMAT - A format of the texture (float,float2,float3,float4,int).
INIT_RW_STRUCTURED_BUFFER ( value NUM, value STRUCTURE, value NAME ) #
Initializes a read-write structured buffer. Works only with USE_STORAGE_BUFFERS enabled.Equivalents
layout(std430, binding=NUM) buffer storage_buffer_ ## NUM { STRUCTURE NAME[]; };
RWStructuredBuffer<STRUCTURE> NAME : register(u ## NUM);
Arguments
- value NUM - A number of the texture slot.
- value STRUCTURE - A structure to be stored in buffer.
- value NAME - A name of the texture slot.
INIT_STRUCTURED_BUFFER ( value NUM, value STRUCTURE, value NAME ) #
Initializes a structure buffer. Works only with USE_STORAGE_BUFFERS enabled.Equivalents
layout(std430, binding=NUM) readonly buffer storage_buffer_ ## NUM { STRUCTURE NAME[]; };
StructuredBuffer<STRUCTURE> NAME : register(t[NUM_TEXTURES+NUM]);
Arguments
- value NUM - A number of the texture slot.
- value STRUCTURE - A structure to be stored in buffer.
- value NAME - A name of the texture slot.
Texture Functions#
GET_TEXSIZE ( value NAME ) #
Returns texture slot size.Equivalents
s_material_textures[TEXTURE_ ## NAME ## _SLOT]
s_material_textures[TEXTURE_ ## NAME ## _SLOT]
Arguments
- value NAME - A name of the texture slot.
TEXTURE ( value NAME, value COORD ) #
Samples a texture.Equivalents
texture(s_texture_ ## NAME,COORD)
s_texture_ ## NAME.Sample(s_sampler_ ## NAME ,COORD)
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
TEXTURE_BIAS ( value NAME, value COORD, value BIAS ) #
Samples a texture using a mipmap-level offset (performs a texture lookup with explicit level-of-detail).Equivalents
textureLod(s_texture_ ## NAME,COORD,BIAS)
s_texture_ ## NAME.SampleLevel(s_sampler_ ## NAME,COORD,BIAS)
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value BIAS - Mipmap level.
TEXTURE_OFFSET_BIAS ( value NAME, value COORD, value OFFSET, value BIAS ) #
Samples a texture using a mipmap-level offset.Equivalents
textureOffset(s_texture_ ## NAME,COORD,OFFSET,BIAS)
s_texture_ ## NAME.SampleLevel(s_sampler_ ## NAME,COORD,BIAS,OFFSET)
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value OFFSET - Offset.
- value BIAS - Mipmap level.
TEXTURE_BIAS_ZERO ( value NAME, value COORDS ) #
Samples a texture using a mipmap-level offset on mipmap level 0 only.Equivalents
textureLod(s_texture_ ## NAME,COORDS,0.0f)
s_texture_ ## NAME.SampleLevel(s_sampler_ ## NAME,COORDS,0.0f)
Arguments
- value NAME - A name of the texture slot.
- value COORDS - UV coordinates.
TEXTURE_OFFSET ( value NAME, value COORD, value OFFSET ) #
Samples a texture using a offset on mipmap level 0 only (performs a texture lookup with offset).Equivalents
textureOffset(s_texture_ ## NAME,COORD,OFFSET,0)
s_texture_ ## NAME.SampleLevel(s_sampler_ ## NAME,COORD,0,OFFSET)
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value OFFSET - Offset.
TEXTURE_GRAD ( value NAME, value COORD, value DDX, value DDY ) #
Samples a texture using a gradient to influence the way the sample location is calculated.Equivalents
textureGrad(s_texture_ ## NAME,COORD,DDX,DDY)
s_texture_ ## NAME.SampleGrad(s_sampler_ ## NAME,COORD,DDX,DDY)
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value DDX - The rate of change of the surface geometry in the x direction.
- value DDY - The rate of change of the surface geometry in the y direction.
TEXTURE_MIP_OFFSET ( value NAME, value COORD, value OFFSET ) #
Samples a texture using a negative mipmap offset.Equivalents
texture(s_texture_ ## NAME, COORD, -OFFSET)
s_texture_ ## NAME.SampleBias(s_sampler_ ## NAME, COORD, -OFFSET)
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value OFFSET - Offset.
TEXTURE_FETCH_LOD ( value NAME, value COORD, value LOD ) #
Reads texel data without any filtering or sampling.Equivalents
texelFetch(s_texture_ ## NAME, int2(COORD), LOD)
s_texture_ ## NAME.Load(uint3(COORD, LOD))
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value LOD - Level-of-detail within the texture from which the texel will be fetched.
TEXTURE_FETCH ( value NAME, value COORD ) #
Reads texel data from the first level-of-detail without any filtering or sampling.Equivalents
texelFetch(s_texture_ ## NAME, int2(COORD), 0)
s_texture_ ## NAME.Load(uint3(COORD, 0))
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
TEXTURE_ARRAY_FETCH_LOD ( value NAME, value COORD, value INDEX, value LOD ) #
Reads texel data from a texture array without any filtering or sampling.Equivalents
texelFetch(s_texture_ ## NAME, int3(COORD, INDEX), LOD)
s_texture_ ## NAME.Load(uint4(COORD, INDEX, LOD))
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value INDEX - Texture index.
- value LOD - Level-of-detail within the texture from which the texel will be fetched.
TEXTURE_ARRAY_FETCH ( value NAME, value COORD, value INDEX ) #
Reads texel data from a texture array from the first level-of-detail without any filtering or sampling.Equivalents
texelFetch(s_texture_ ## NAME, int3(COORD, INDEX), 0)
s_texture_ ## NAME.Load(uint4(COORD, INDEX, 0))
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value INDEX - Texture index.
TEXTURE_LOAD_LOD ( value NAME, value COORD, value LOD ) #
Reads texel data without any filtering or sampling.Equivalents
texelFetch(s_texture_ ## NAME,COORD,LOD)
s_texture_ ## NAME.Load(uint3(COORD,LOD))
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value LOD - Level-of-detail within the texture from which the texel will be fetched.
TEXTURE_LOAD ( value NAME, value COORD ) #
Reads texel data without any filtering or sampling with zero offset.Equivalents
ttexelFetch(s_texture_ ## NAME,COORD,0)
s_texture_ ## NAME.Load(uint3(COORD,0))
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
TEXTURE_3D_FETCH_LOD ( value NAME, value COORD, value INDEX, value LOD ) #
Reads texel data from a texture array without any filtering or sampling.Equivalents
texelFetch(s_texture_ ## NAME, int3(COORD, INDEX), LOD)
s_texture_ ## NAME.Load(uint4(COORD, INDEX, LOD))
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value INDEX - Texture index.
- value LOD - Level-of-detail within the texture from which the texel will be fetched.
TEXTURE_3D_FETCH ( value NAME, value COORD, value INDEX ) #
Reads texel data from a texture array from the first level-of-detail without any filtering or sampling.Equivalents
texelFetch(s_texture_ ## NAME, int3(COORD, INDEX), 0)
s_texture_ ## NAME.Load(uint4(COORD, INDEX, 0))
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value INDEX - Texture index.
TEXTURE_3D_LOAD_LOD ( value NAME, value COORD, value LOD ) #
Reads texel data of a single level of detail of a 3D texture without any filtering or sampling.Equivalents
texelFetch(s_texture_ ## NAME, int3((COORD) * GET_TEXSIZE(NAME).xyz * (1.0f / pow(2, LOD))), LOD)
s_texture_ ## NAME.Load(uint4((COORD) * GET_TEXSIZE(NAME).xyz * (1.0f / pow(2, LOD)), LOD))
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value LOD - Level-of-detail within the texture from which the texel will be fetched.
TEXTURE_3D_LOAD ( value NAME, value COORD ) #
Reads texel data of a 3D texture without any filtering or sampling with zero offset.Equivalents
TEXTURE_3D_LOAD_LOD(NAME, COORD, 0)
TEXTURE_3D_LOAD_LOD(NAME, COORD, 0)
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
TEXTURE_SHADOW ( value NAME, value COORD ) #
Samples a shadow texture.Equivalents
texture(s_texture_ ## NAME,COORD)
s_texture_ ## NAME.SampleCmpLevelZero(s_sampler_compare_ ## NAME,(COORD).xy,(COORD).z)
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
TEXTURE_SHADOW_PROJ ( value NAME, value COORD ) #
Samples a shadow texture with projection.Equivalents
textureProj(s_texture_ ## NAME,COORD)
s_texture_ ## NAME.SampleCmpLevelZero(s_sampler_compare_ ## NAME,(COORD).xy,(COORD).z)
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
TEXTURE_CUBE_SHADOW ( value NAME, value DIRECTION, value DEPTH ) #
Samples a cubemap shadow texture.Equivalents
texture(s_texture_ ## NAME,float4(DIRECTION,DEPTH)))
s_texture_ ## NAME.SampleCmpLevelZero(s_sampler_compare_ ## NAME,DIRECTION,DEPTH)
Arguments
- value NAME - A name of the texture slot.
- value DIRECTION - Direction value.
- value DEPTH - Depth value.
TEXTURE_2D_CUBIC ( value TEXTURE_ID, value TEXCOORD ) #
Samples a texture with bicubic interpolation.Implementation
texture2DCubic(TEXTURE_OUT(TEXTURE_ID), TEXCOORD, GET_TEXSIZE(TEXTURE_ID))
Arguments
- value TEXTURE_ID - Id of the texture slot.
- value TEXCOORD - UV coordinates.
TEXTURE_2D_CATMULL ( value TEXTURE_ID, value TEXCOORD ) #
Samples a texture with catmull interpolation.Implementation
texture2DCatmull(TEXTURE_OUT(TEXTURE_ID), TEXCOORD, GET_TEXSIZE(TEXTURE_ID))
Arguments
- value TEXTURE_ID - Id of the texture slot.
- value TEXCOORD - UV coordinates.
TEXTURE_3D_CUBIC ( value NAME, value COORD ) #
Samples a 3D texture with bicubic interpolation.Implementation
texture3DCubic(TEXTURE_OUT(NAME), COORD)
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
TEXTURE_RW_LOAD_RGBA8 ( value NAME, value COORD ) #
Loads RW texture. Works only with USE_RW_TEXTURES enabled.Equivalents
imageLoad(s_rw_texture_ ## NAME, COORD)
unpack_uint32_to_rgba8(s_rw_texture_ ## NAME[ ## COORD ## ])
Arguments
- value NAME - Name of the texture slot.
- value COORD - UV coordinates.
TEXTURE_RW_LOAD_R32U ( value NAME, value COORD ) #
Loads RW texture. Works only with USE_RW_TEXTURES enabled.Equivalents
imageLoad(s_rw_texture_ ## NAME, COORD).x
s_rw_texture_ ## NAME[ ## COORD ## ]
Arguments
- value NAME - Name of the texture slot.
- value COORD - UV coordinates.
TEXTURE_RW_LOAD_R32F ( value NAME, value COORD ) #
Loads RW texture. Works only with USE_RW_TEXTURES enabled.Equivalents
imageLoad(s_rw_texture_ ## NAME, COORD).x
s_rw_texture_ ## NAME[ ## COORD ## ]
Arguments
- value NAME - Name of the texture slot.
- value COORD - UV coordinates.
TEXTURE_RW_STORE_RGBA8 ( value NAME, value COORD, value VALUE ) #
Stores RW texture. Works only with USE_RW_TEXTURES enabled.Equivalents
imageStore(s_rw_texture_ ## NAME, uint_to_int(COORD), to_gvec4(VALUE))
s_rw_texture_ ## NAME[COORD] = pack_rgba8_to_uint32(VALUE)
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value VALUE - A value to store.
TEXTURE_RW_STORE_R32U ( value NAME, value COORD, value VALUE ) #
Stores RW texture. Works only with USE_RW_TEXTURES enabled.Equivalents
imageStore(s_rw_texture_ ## NAME, uint_to_int(COORD), to_gvec4(VALUE))
s_rw_texture_ ## NAME[COORD] = VALUE
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value VALUE - A value to store.
TEXTURE_RW_STORE_R32F ( value NAME, value COORD, value VALUE ) #
Stores RW texture. Works only with USE_RW_TEXTURES enabled.Equivalents
imageStore(s_rw_texture_ ## NAME, uint_to_int(COORD), to_gvec4(VALUE))
s_rw_texture_ ## NAME[COORD] = VALUE
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value VALUE - A value to store.
TEXTURE_W_STORE ( value NAME, value COORD, value VALUE ) #
Stores W texture. Works only with USE_RW_TEXTURES enabled.Equivalents
imageStore(s_rw_texture_ ## NAME, uint_to_int(COORD), VALUE)
s_rw_texture_ ## NAME[uint2(COORD)] = VALUE
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value VALUE - A value to store.
TEXTURE_ARRAY ( value NAME, value COORDS, value LAYER, value LOD ) #
Samples a texture array using a mipmap-level.Equivalents
textureLod(s_texture_ ## NAME,float3(COORDS,LAYER),LOD)
s_texture_ ## NAME.SampleLevel(s_sampler_ ## NAME,float3(COORDS,LAYER),LOD)
Arguments
- value NAME - A name of the texture slot.
- value COORDS - UV coordinates.
- value LAYER - Layer value.
- value LOD - Level-of-detail within the texture from which the texel will be fetched.
TEXTURE_ARRAY_LOAD ( value NAME, value COORD, value INDEX ) #
Reads texel data without any filtering or sampling with zero offset.Equivalents
texelFetch(s_texture_ ## NAME,COORD,0)
s_texture_ ## NAME.Load(uint3(COORD,0))
Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value INDEX - Texture index.
TEXTURE_ARRAY_LOAD_LOD ( value NAME, value COORD, value INDEX, value LOD ) #
Reads texel data without any filtering or sampling.Arguments
- value NAME - A name of the texture slot.
- value COORD - UV coordinates.
- value INDEX - Texture index.
- value LOD - Level-of-detail within the texture from which the texel will be fetched.
TEXTURE_TRIPLANAR ( value TEXTURE_ID, value TEXCOORD, value WEIGHT ) #
Samples a texture for triplanar mapping.Implementation
(TEXTURE(TEXTURE_ID,TEXCOORD.zw) * WEIGHT.x +
TEXTURE(TEXTURE_ID,TEXCOORD.xw) * WEIGHT.y +
TEXTURE(TEXTURE_ID,TEXCOORD.xy) * WEIGHT.z )
Arguments
- value TEXTURE_ID - Texture ID.
- value TEXCOORD - UV coordinates.
- value WEIGHT - Texture's weight in triplanar mapping.
TEXTURE_TRIPLANAR_NORMAL ( value TEXTURE_ID, value TEXCOORD, value WEIGHT ) #
Samples a texture for triplanar mapping.Implementation
getTriplanarNormal(TEXTURE_OUT(TEXTURE_ID), TEXCOORD, WEIGHT, DATA_OBJECT_NORMAL)
Arguments
- value TEXTURE_ID - Texture ID.
- value TEXCOORD - UV coordinates.
- value WEIGHT - Texture's weight in triplanar mapping.
Passing Textures to Functions#
UUSL allows you to pass textures to functions as arguments.
Here is a usage example:
float4 func_name(float4 color,float2 uv,TEXTURE_IN_2(texture_0,texture_1)) {
return TEXTURE(texture_0,uv) * TEXTURE_BIAS(texture_1,uv,5.0f) * color;
}
float4 new_color = func_name(color,uv,TEXTURE_OUT_2(TEX_COLOR_0,TEX_COLOR_1));
TEXTURE_OUT ( value NAME ) #
Allows to pass a texture to function.Equivalents
s_texture_ ## NAME
s_texture_ ## NAME,s_sampler_ ## NAME
Arguments
- value NAME - A name of the texture slot.
TEXTURE_OUT_2 ( value NAME0, value NAME1 ) #
Allows to pass two textures to a function.Equivalents
TEXTURE_OUT(NAME0),TEXTURE_OUT(NAME1)
TEXTURE_OUT(NAME0),TEXTURE_OUT(NAME1)
Arguments
- value NAME0 - A name of the texture slot (for the first texture).
- value NAME1 - A name of the texture slot (for the second texture).
TEXTURE_OUT_3 ( value NAME0, value NAME1, value NAME2 ) #
Allows to pass three textures to a function.Equivalents
TEXTURE_OUT_2(NAME0,NAME1),TEXTURE_OUT(NAME2)
TEXTURE_OUT_2(NAME0,NAME1),TEXTURE_OUT(NAME2)
Arguments
- value NAME0 - A name of the texture slot (for the first texture).
- value NAME1 - A name of the texture slot (for the second texture).
- value NAME2 - A name of the texture slot (for the third texture).
TEXTURE_OUT_4 ( value NAME0, value NAME1, value NAME2, value NAME3 ) #
Allows to pass four textures to a function.Equivalents
TEXTURE_OUT_3(NAME0,NAME1,NAME2),TEXTURE_OUT(NAME3)
TEXTURE_OUT_3(NAME0,NAME1,NAME2),TEXTURE_OUT(NAME3)
Arguments
- value NAME0 - A name of the texture slot (for the first texture).
- value NAME1 - A name of the texture slot (for the second texture).
- value NAME2 - A name of the texture slot (for the third texture).
- value NAME3 - A name of the texture slot (for the fourth texture).
TEXTURE_IN ( value NAME ) #
Specifies the 2D texture for passing to function.Equivalents
sampler2D s_texture_ ## NAME
Texture2D s_texture_ ## NAME,SamplerState s_sampler_ ## NAME
Arguments
- value NAME - A name of the texture.
TEXTURE_IN_2 ( value NAME0, value NAME1 ) #
Specifies two 2D textures for passing to function.Equivalents
TEXTURE_IN(NAME0),TEXTURE_IN(NAME1)
TEXTURE_IN(NAME0),TEXTURE_IN(NAME1)
Arguments
- value NAME0 - A name of the first texture.
- value NAME1 - A name of the second texture.
TEXTURE_IN_3 ( value NAME0, value NAME1, value NAME2 ) #
Specifies three 2D textures for passing to function.Equivalents
TEXTURE_IN_2(NAME0,NAME1),TEXTURE_IN(NAME2)
TEXTURE_IN_2(NAME0,NAME1),TEXTURE_IN(NAME2)
Arguments
- value NAME0 - A name of the first texture.
- value NAME1 - A name of the second texture.
- value NAME2 - A name of the third texture.
TEXTURE_IN_4 ( value NAME0, value NAME1, value NAME2, value NAME3 ) #
Specifies four 2D textures for passing to function.Equivalents
TEXTURE_IN_3(NAME0,NAME1,NAME2),TEXTURE_IN(NAME3)
TEXTURE_IN_3(NAME0,NAME1,NAME2),TEXTURE_IN(NAME3)
Arguments
- value NAME0 - A name of the first texture.
- value NAME1 - A name of the second texture.
- value NAME2 - A name of the third texture.
- value NAME3 - A name of the fourth texture.
TEXTURE_IN_CUBE ( value NAME ) #
Specifies the cube texture for passing to function.Equivalents
samplerCube s_texture_ ## NAME
TextureCube s_texture_ ## NAME,SamplerState s_sampler_ ## NAME
Arguments
- value NAME - A name of the texture.
TEXTURE_IN_3D ( value NAME ) #
Specifies the 3D texture for passing to function.Equivalents
sampler3D s_texture_ ## NAME
Texture3D s_texture_ ## NAME,SamplerState s_sampler_ ## NAME
Arguments
- value NAME - A name of the texture.
TEXTURE_IN_ARRAY ( value NAME ) #
Specifies the texture array for passing to function.Equivalents
sampler2DArray s_texture_ ## NAME
Texture2DArray s_texture_ ## NAME,SamplerState s_sampler_ ## NAME
Arguments
- value NAME - A name of the texture.
TEXTURE_IN_ARRAY_INT2 ( value NAME ) #
Specifies the int2 texture array for passing to function.Equivalents
sampler2DArray s_texture_ ## NAME
Texture2DArray s_texture_ ## NAME,SamplerState s_sampler_ ## NAME
Arguments
- value NAME - A name of the texture.
TEXTURE_IN_SHADOW ( value NAME ) #
Specifies the texture shadow for passing to function.Equivalents
sampler2DShadow s_texture_ ## NAME
Texture2D s_texture_ ## NAME,SamplerState s_sampler_ ## NAME
Arguments
- value NAME - A name of the texture.
TEXTURE_IN_ARRAY_SHADOW ( value NAME ) #
Specifies the texture shadow array for passing to function.Equivalents
sampler2DArrayShadow s_texture_ ## NAME
Texture2DArray s_texture_ ## NAME,SamplerState s_sampler_ ## NAME
Arguments
- value NAME - A name of the texture.
TEXTURE_IN_CUBE_SHADOW ( value NAME ) #
Specifies the texture shadow cube for passing to function.Equivalents
samplerCubeShadow s_texture_ ## NAME
TextureCube s_texture_ ## NAME,SamplerState s_sampler_ ## NAME
Arguments
- value NAME - A name of the texture.
int textureResolution ( value TEXTURE ) #
Returns the texture resolution, a two- or three-component value depending on the texture type.Equivalents
ivec2 textureResolutionGL(sampler2D tex) { return textureSize(tex, 0); }
ivec3 textureResolutionGL(sampler2DArray tex) { return textureSize(tex, 0); }
ivec3 textureResolutionGL(sampler3D tex) { return textureSize(tex, 0); }
ivec2 textureResolutionGL(samplerCube tex) { return textureSize(tex, 0); }
ivec3 textureResolutionGL(samplerCubeArray tex) { return textureSize(tex, 0); }
int2 textureResolutionDX11(in Texture2D tex)
{
int2 ret = int2(0,0);
tex.GetDimensions(ret.x, ret.y);
return ret;
}
int3 textureResolutionDX11(Texture2DArray tex)
{
int3 ret = int3(0,0,0);
tex.GetDimensions(ret.x, ret.y, ret.z);
return ret;
}
int3 textureResolutionDX11(Texture3D tex)
{
int3 ret = int3(0,0,0);
tex.GetDimensions(ret.x, ret.y, ret.z);
return ret;
}
int2 textureResolutionDX11(TextureCube tex)
{
int2 ret = int2(0,0);
tex.GetDimensions(ret.x, ret.y);
return ret;
}
int3 textureResolutionDX11(TextureCubeArray tex)
{
int3 ret = int3(0,0,0);
tex.GetDimensions(ret.x, ret.y, ret.z);
return ret;
}
Arguments
- value TEXTURE - Texture.
Return value
Texture resolution, two- or three-component value depending on the texture type.float textureIResolution ( value TEXTURE ) #
Returns the inverted texture resolution, a two- or three-component value depending on the texture type.Equivalents
float2 textureIResolutionGL(sampler2D tex) { return float2(1.0f) / textureSize(tex, 0); }
float3 textureIResolutionGL(sampler2DArray tex) { return float3(1.0f) / textureSize(tex, 0); }
float3 textureIResolutionGL(sampler3D tex) { return float3(1.0f) / textureSize(tex, 0); }
float2 textureIResolutionGL(samplerCube tex) { return float2(1.0f) / textureSize(tex, 0); }
float3 textureIResolutionGL(samplerCubeArray tex) { return float3(1.0f) / textureSize(tex, 0); }
float2 textureIResolutionDX11(in Texture2D tex)
{
int2 ret = int2(0,0);
tex.GetDimensions(ret.x, ret.y);
return float2(1.0f, 1.0f) / ret;
}
float3 textureIResolutionDX11(Texture2DArray tex)
{
int3 ret = int3(0,0,0);
tex.GetDimensions(ret.x, ret.y, ret.z);
return float3(1.0f, 1.0f, 1.0f) / ret;
}
float3 textureIResolutionDX11(Texture3D tex)
{
int3 ret = int3(0,0,0);
tex.GetDimensions(ret.x, ret.y, ret.z);
return float3(1.0f, 1.0f, 1.0f) / ret;
}
float2 textureIResolutionDX11(TextureCube tex)
{
int2 ret = int2(0,0);
tex.GetDimensions(ret.x, ret.y);
return float2(1.0f, 1.0f) / ret;
}
float3 textureIResolutionDX11(TextureCubeArray tex)
{
int3 ret = int3(0,0,0);
tex.GetDimensions(ret.x, ret.y, ret.z);
return float3(1.0f, 1.0f, 1.0f) / ret;
}
Arguments
- value TEXTURE - Texture.