1/* 2 * Copyright 2020-2022 Matias N. Goldberg 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 * DEALINGS IN THE SOFTWARE. 21 */ 22 23 24#define min3( a, b, c ) min( a, min( b, c ) ) 25#define max3( a, b, c ) max( a, max( b, c ) ) 26 27#define float2 vec2 28#define float3 vec3 29#define float4 vec4 30 31#define int2 ivec2 32#define int3 ivec3 33#define int4 ivec4 34 35#define uint2 uvec2 36#define uint3 uvec3 37#define uint4 uvec4 38 39#define float2x2 mat2 40#define float3x3 mat3 41#define float4x4 mat4 42#define ogre_float4x3 mat3x4 43 44#define ushort uint 45#define ushort3 uint3 46#define ushort4 uint4 47 48//Short used for read operations. It's an int in GLSL & HLSL. An ushort in Metal 49#define rshort int 50#define rshort2 int2 51#define rint int 52//Short used for write operations. It's an int in GLSL. An ushort in HLSL & Metal 53#define wshort2 int2 54#define wshort3 int3 55 56#define toFloat3x3( x ) mat3( x ) 57#define buildFloat3x3( row0, row1, row2 ) mat3( row0, row1, row2 ) 58 59#define mul( x, y ) ((x) * (y)) 60#define saturate(x) clamp( (x), 0.0, 1.0 ) 61#define lerp mix 62#define rsqrt inversesqrt 63#define INLINE 64#define NO_INTERPOLATION_PREFIX flat 65#define NO_INTERPOLATION_SUFFIX 66 67#define PARAMS_ARG_DECL 68#define PARAMS_ARG 69 70#define reversebits bitfieldReverse 71 72#define OGRE_Sample( tex, sampler, uv ) texture( tex, uv ) 73#define OGRE_SampleLevel( tex, sampler, uv, lod ) textureLod( tex, uv, lod ) 74#define OGRE_SampleArray2D( tex, sampler, uv, arrayIdx ) texture( tex, vec3( uv, arrayIdx ) ) 75#define OGRE_SampleArray2DLevel( tex, sampler, uv, arrayIdx, lod ) textureLod( tex, vec3( uv, arrayIdx ), lod ) 76#define OGRE_SampleArrayCubeLevel( tex, sampler, uv, arrayIdx, lod ) textureLod( tex, vec4( uv, arrayIdx ), lod ) 77#define OGRE_SampleGrad( tex, sampler, uv, ddx, ddy ) textureGrad( tex, uv, ddx, ddy ) 78#define OGRE_SampleArray2DGrad( tex, sampler, uv, arrayIdx, ddx, ddy ) textureGrad( tex, vec3( uv, arrayIdx ), ddx, ddy ) 79#define OGRE_ddx( val ) dFdx( val ) 80#define OGRE_ddy( val ) dFdy( val ) 81#define OGRE_Load2D( tex, iuv, lod ) texelFetch( tex, iuv, lod ) 82#define OGRE_LoadArray2D( tex, iuv, arrayIdx, lod ) texelFetch( tex, ivec3( iuv, arrayIdx ), lod ) 83#define OGRE_Load2DMS( tex, iuv, subsample ) texelFetch( tex, iuv, subsample ) 84 85#define OGRE_Load3D( tex, iuv, lod ) texelFetch( tex, ivec3( iuv ), lod ) 86 87#define OGRE_GatherRed( tex, sampler, uv ) textureGather( tex, uv, 0 ) 88#define OGRE_GatherGreen( tex, sampler, uv ) textureGather( tex, uv, 1 ) 89#define OGRE_GatherBlue( tex, sampler, uv ) textureGather( tex, uv, 2 ) 90 91#define bufferFetch1( buffer, idx ) texelFetch( buffer, idx ).x 92 93#define OGRE_SAMPLER_ARG_DECL( samplerName ) 94#define OGRE_SAMPLER_ARG( samplerName ) 95 96#define OGRE_Texture3D_float4 sampler3D 97#define OGRE_OUT_REF( declType, variableName ) out declType variableName 98#define OGRE_INOUT_REF( declType, variableName ) inout declType variableName 99