diff --git a/CMake/Templates/resources2.cfg.in b/CMake/Templates/resources2.cfg.in index 4a6305ce090..3d7c952defb 100644 --- a/CMake/Templates/resources2.cfg.in +++ b/CMake/Templates/resources2.cfg.in @@ -17,7 +17,6 @@ FileSystem=@OGRE_MEDIA_TEXTURES_DIR@/textures/Cubemaps FileSystem=@OGRE_MEDIA_DIR_REL@/2.0/scripts/materials/Common FileSystem=@OGRE_MEDIA_DIR_REL@/2.0/scripts/materials/Common/Any FileSystem=@OGRE_MEDIA_DIR_REL@/2.0/scripts/materials/Common/GLSL -FileSystem=@OGRE_MEDIA_DIR_REL@/2.0/scripts/materials/Common/GLSLES FileSystem=@OGRE_MEDIA_DIR_REL@/2.0/scripts/materials/Common/HLSL FileSystem=@OGRE_MEDIA_DIR_REL@/2.0/scripts/materials/Common/Metal FileSystem=@OGRE_MEDIA_DIR_REL@/Hlms/Common/Any diff --git a/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp b/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp index c8f7a8a54c1..8c846f00560 100644 --- a/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp +++ b/Components/Hlms/Pbs/src/OgreHlmsPbs.cpp @@ -3863,9 +3863,7 @@ namespace Ogre // name of the compatible shading language is part of the path Ogre::RenderSystem *renderSystem = Ogre::Root::getSingleton().getRenderSystem(); Ogre::String shaderSyntax = "GLSL"; - if( renderSystem->getName() == "OpenGL ES 2.x Rendering Subsystem" ) - shaderSyntax = "GLSLES"; - else if( renderSystem->getName() == "Direct3D11 Rendering Subsystem" ) + if( renderSystem->getName() == "Direct3D11 Rendering Subsystem" ) shaderSyntax = "HLSL"; else if( renderSystem->getName() == "Metal Rendering Subsystem" ) shaderSyntax = "Metal"; diff --git a/Components/Hlms/Unlit/src/OgreHlmsUnlit.cpp b/Components/Hlms/Unlit/src/OgreHlmsUnlit.cpp index 0a903a32a0d..b59d950eda2 100644 --- a/Components/Hlms/Unlit/src/OgreHlmsUnlit.cpp +++ b/Components/Hlms/Unlit/src/OgreHlmsUnlit.cpp @@ -1205,9 +1205,7 @@ namespace Ogre // name of the compatible shading language is part of the path RenderSystem *renderSystem = Root::getSingleton().getRenderSystem(); String shaderSyntax = "GLSL"; - if( renderSystem->getName() == "OpenGL ES 2.x Rendering Subsystem" ) - shaderSyntax = "GLSLES"; - else if( renderSystem->getName() == "Direct3D11 Rendering Subsystem" ) + if( renderSystem->getName() == "Direct3D11 Rendering Subsystem" ) shaderSyntax = "HLSL"; else if( renderSystem->getName() == "Metal Rendering Subsystem" ) shaderSyntax = "Metal"; diff --git a/OgreMain/include/OgreHlms.h b/OgreMain/include/OgreHlms.h index 5e8b8b6bf0b..0dfc5dd4a57 100644 --- a/OgreMain/include/OgreHlms.h +++ b/OgreMain/include/OgreHlms.h @@ -292,16 +292,29 @@ namespace Ogre HlmsDatablockMap mDatablocks; - String mShaderProfile; ///< "glsl", "glsles", "hlsl" + /// This is what we tell the RenderSystem to compile as. + /// + /// For example if we set at the same time: + /// - mShaderProfile = "metal" + /// - mShaderSyntax = "hlsl" + /// - mShaderFileExt = ".glsl" + /// + /// Then we will: + /// - Look for *.hlsl files. + /// - Tell the Hlms parser that it is glsl, i.e. `@property( syntax == glsl )`. + /// - Tell the RenderSystem to compile it as Metal. + String mShaderProfile; //< "glsl", "glslvk", "hlsl", "metal" + /// This is what we tell the Hlms parser what the syntax is. IdString mShaderSyntax; IdStringVec mRsSpecificExtensions; String const *mShaderTargets[NumShaderTypes]; ///[0] = "vs_4_0", etc. Only used by D3D - String mShaderFileExt; ///< Either glsl or hlsl - String mOutputPath; - bool mDebugOutput; - bool mDebugOutputProperties; - uint8 mPrecisionMode; ///< See PrecisionMode - bool mFastShaderBuildHack; + /// This is the extension we look for. e.g. .glsl, .hlsl, etc. + String mShaderFileExt; + String mOutputPath; + bool mDebugOutput; + bool mDebugOutputProperties; + uint8 mPrecisionMode; ///< See PrecisionMode + bool mFastShaderBuildHack; public: struct DatablockCustomPieceFile @@ -1240,12 +1253,10 @@ namespace Ogre static const IdString Syntax; static const IdString Hlsl; static const IdString Glsl; - static const IdString Glsles; static const IdString Glslvk; static const IdString Hlslvk; static const IdString Metal; static const IdString GL3Plus; - static const IdString GLES; static const IdString iOS; static const IdString macOS; static const IdString GLVersion; diff --git a/OgreMain/src/OgreHlms.cpp b/OgreMain/src/OgreHlms.cpp index 3376dee8078..8cb374759b0 100644 --- a/OgreMain/src/OgreHlms.cpp +++ b/OgreMain/src/OgreHlms.cpp @@ -220,12 +220,10 @@ namespace Ogre const IdString HlmsBaseProp::Syntax = IdString( "syntax" ); const IdString HlmsBaseProp::Hlsl = IdString( "hlsl" ); const IdString HlmsBaseProp::Glsl = IdString( "glsl" ); - const IdString HlmsBaseProp::Glsles = IdString( "glsles" ); const IdString HlmsBaseProp::Glslvk = IdString( "glslvk" ); const IdString HlmsBaseProp::Hlslvk = IdString( "hlslvk" ); const IdString HlmsBaseProp::Metal = IdString( "metal" ); const IdString HlmsBaseProp::GL3Plus = IdString( "GL3+" ); - const IdString HlmsBaseProp::GLES = IdString( "GLES" ); const IdString HlmsBaseProp::iOS = IdString( "iOS" ); const IdString HlmsBaseProp::macOS = IdString( "macOS" ); const IdString HlmsBaseProp::PrecisionMode = IdString( "precision_mode" ); @@ -1661,16 +1659,10 @@ namespace Ogre { setProperty( tid, HlmsBaseProp::GL3Plus, mRenderSystem->getNativeShadingLanguageVersion() ); } - else if( mShaderProfile == "glsles" ) // TODO: String comparision - { - setProperty( tid, HlmsBaseProp::GLES, mRenderSystem->getNativeShadingLanguageVersion() ); - } setProperty( tid, HlmsBaseProp::Syntax, static_cast( mShaderSyntax.getU32Value() ) ); setProperty( tid, HlmsBaseProp::Hlsl, static_cast( HlmsBaseProp::Hlsl.getU32Value() ) ); setProperty( tid, HlmsBaseProp::Glsl, static_cast( HlmsBaseProp::Glsl.getU32Value() ) ); - setProperty( tid, HlmsBaseProp::Glsles, - static_cast( HlmsBaseProp::Glsles.getU32Value() ) ); setProperty( tid, HlmsBaseProp::Glslvk, static_cast( HlmsBaseProp::Glslvk.getU32Value() ) ); setProperty( tid, HlmsBaseProp::Hlslvk, @@ -2354,11 +2346,6 @@ namespace Ogre setProperty( tid, HlmsBaseProp::GL3Plus, mRenderSystem->getNativeShadingLanguageVersion() ); } - else if( mShaderProfile == "glsles" ) // TODO: String comparision - { - setProperty( tid, HlmsBaseProp::GLES, - mRenderSystem->getNativeShadingLanguageVersion() ); - } setProperty( tid, HlmsBaseProp::Syntax, static_cast( mShaderSyntax.getU32Value() ) ); @@ -2366,8 +2353,6 @@ namespace Ogre static_cast( HlmsBaseProp::Hlsl.getU32Value() ) ); setProperty( tid, HlmsBaseProp::Glsl, static_cast( HlmsBaseProp::Glsl.getU32Value() ) ); - setProperty( tid, HlmsBaseProp::Glsles, - static_cast( HlmsBaseProp::Glsles.getU32Value() ) ); setProperty( tid, HlmsBaseProp::Glslvk, static_cast( HlmsBaseProp::Glslvk.getU32Value() ) ); setProperty( tid, HlmsBaseProp::Hlslvk, @@ -3897,8 +3882,8 @@ namespace Ogre mFastShaderBuildHack = StringConverter::parseBool( itor->second.currentValue ); } - // Prefer glslvk over hlslvk over glsl, and glsl over glsles - const String shaderProfiles[6] = { "hlsl", "glsles", "glsl", "hlslvk", "glslvk", "metal" }; + // Prefer glslvk over hlslvk over glsl + const String shaderProfiles[6] = { "hlsl", "glsl", "hlslvk", "glslvk", "metal" }; const RenderSystemCapabilities *capabilities = mRenderSystem->getCapabilities(); for( size_t i = 0; i < 6; ++i ) diff --git a/OgreMain/src/OgreHlmsCompute.cpp b/OgreMain/src/OgreHlmsCompute.cpp index f4a54a71e34..0e9476f02c9 100644 --- a/OgreMain/src/OgreHlmsCompute.cpp +++ b/OgreMain/src/OgreHlmsCompute.cpp @@ -130,7 +130,6 @@ namespace Ogre filename.compare( pos + 1, String::npos, "any" ) != 0 && filename.compare( pos + 1, String::npos, "metal" ) != 0 && filename.compare( pos + 1, String::npos, "glsl" ) != 0 && - filename.compare( pos + 1, String::npos, "glsles" ) != 0 && filename.compare( pos + 1, String::npos, "hlsl" ) != 0 ) ) { filename += mShaderFileExt; @@ -191,8 +190,6 @@ namespace Ogre setProperty( kNoTid, HlmsBaseProp::GL3Plus, mRenderSystem->getNativeShadingLanguageVersion() ); } - if( mShaderProfile == "glsles" ) // TODO: String comparision - setProperty( kNoTid, HlmsBaseProp::GLES, 300 ); setProperty( kNoTid, HlmsBaseProp::Syntax, static_cast( mShaderSyntax.getU32Value() ) ); setProperty( kNoTid, HlmsBaseProp::Hlsl, @@ -203,8 +200,6 @@ namespace Ogre static_cast( HlmsBaseProp::Glslvk.getU32Value() ) ); setProperty( kNoTid, HlmsBaseProp::Hlslvk, static_cast( HlmsBaseProp::Hlslvk.getU32Value() ) ); - setProperty( kNoTid, HlmsBaseProp::Glsles, - static_cast( HlmsBaseProp::Glsles.getU32Value() ) ); setProperty( kNoTid, HlmsBaseProp::Metal, static_cast( HlmsBaseProp::Metal.getU32Value() ) ); diff --git a/Samples/2.0/Tutorials/Tutorial_Terrain/src/Tutorial_Terrain.cpp b/Samples/2.0/Tutorials/Tutorial_Terrain/src/Tutorial_Terrain.cpp index 8954485d677..3d8e821a38e 100644 --- a/Samples/2.0/Tutorials/Tutorial_Terrain/src/Tutorial_Terrain.cpp +++ b/Samples/2.0/Tutorials/Tutorial_Terrain/src/Tutorial_Terrain.cpp @@ -137,8 +137,6 @@ namespace Demo Ogre::RenderSystem *renderSystem = mRoot->getRenderSystem(); Ogre::String shaderSyntax = "GLSL"; - if( renderSystem->getName() == "OpenGL ES 2.x Rendering Subsystem" ) - shaderSyntax = "GLSLES"; if( renderSystem->getName() == "Direct3D11 Rendering Subsystem" ) shaderSyntax = "HLSL"; else if( renderSystem->getName() == "Metal Rendering Subsystem" ) diff --git a/Samples/Media/2.0/scripts/materials/Common/GLSLES/CubeToDpsm_ps.glsles b/Samples/Media/2.0/scripts/materials/Common/GLSLES/CubeToDpsm_ps.glsles deleted file mode 100644 index 0349069656c..00000000000 --- a/Samples/Media/2.0/scripts/materials/Common/GLSLES/CubeToDpsm_ps.glsles +++ /dev/null @@ -1,35 +0,0 @@ -#version 300 es -precision highp float; - -uniform samplerCube depthTexture; - -in block -{ - vec2 uv0; -} inPs; - -in vec4 gl_FragCoord; -//out float gl_FragDepth; - -#if OUTPUT_TO_COLOUR - out float fragColour; -#endif - -void main() -{ - vec3 cubeDir; - - cubeDir.x = mod( inPs.uv0.x, 0.5 ) * 4.0 - 1.0; - cubeDir.y = inPs.uv0.y * 2.0 - 1.0; - cubeDir.z = 0.5 - 0.5 * (cubeDir.x * cubeDir.x + cubeDir.y * cubeDir.y); - - cubeDir.z = inPs.uv0.x < 0.5 ? cubeDir.z : -cubeDir.z; - - float depthValue = textureLod( depthTexture, cubeDir.xyz, 0 ).x; - -#if OUTPUT_TO_COLOUR - fragColour = depthValue; -#else - gl_FragDepth = depthValue; -#endif -} diff --git a/Samples/Media/2.0/scripts/materials/Common/GLSLES/QuadCameraDir_vs.glsles b/Samples/Media/2.0/scripts/materials/Common/GLSLES/QuadCameraDir_vs.glsles deleted file mode 100644 index c24467e566f..00000000000 --- a/Samples/Media/2.0/scripts/materials/Common/GLSLES/QuadCameraDir_vs.glsles +++ /dev/null @@ -1,25 +0,0 @@ -#version 300 es -precision highp float; - -in vec4 vertex; -in vec3 normal; -in vec2 uv0; -uniform mat4 worldViewProj; - -out gl_PerVertex -{ - vec4 gl_Position; -}; - -out block -{ - vec2 uv0; - vec3 cameraDir; -} outVs; - -void main() -{ - gl_Position = (worldViewProj * vertex).xyzw; - outVs.uv0.xy = uv0.xy; - outVs.cameraDir.xyz = normal.xyz; -} diff --git a/Samples/Media/2.0/scripts/materials/Common/GLSLES/Quad_vs.glsles b/Samples/Media/2.0/scripts/materials/Common/GLSLES/Quad_vs.glsles deleted file mode 100644 index 3a4479fddf5..00000000000 --- a/Samples/Media/2.0/scripts/materials/Common/GLSLES/Quad_vs.glsles +++ /dev/null @@ -1,22 +0,0 @@ -#version 300 es -precision highp float; - -in vec4 vertex; -in vec2 uv0; -uniform mat4 worldViewProj; - -out gl_PerVertex -{ - vec4 gl_Position; -}; - -out block -{ - vec2 uv0; -} outVs; - -void main() -{ - gl_Position = worldViewProj * vertex; - outVs.uv0.xy = uv0.xy; -} diff --git a/Samples/Media/Hlms/Common/GLSLES/CrossPlatformSettings_piece_all.glsl b/Samples/Media/Hlms/Common/GLSLES/CrossPlatformSettings_piece_all.glsl deleted file mode 100644 index 01f75c3b5ad..00000000000 --- a/Samples/Media/Hlms/Common/GLSLES/CrossPlatformSettings_piece_all.glsl +++ /dev/null @@ -1,90 +0,0 @@ -@piece( SetCrossPlatformSettings ) -@property( 300 <= GLES )#version 300 es -precision highp float; -precision highp isampler2D; -precision highp usampler2D; -precision highp sampler2DShadow; -precision highp sampler2DArray; -@end - -@property( GL_ARB_shading_language_420pack ) - #extension GL_ARB_shading_language_420pack: require - #define layout_constbuffer(x) layout( std140, x ) -@end -@property( GL_ARB_texture_buffer_range ) - #define bufferFetch texelFetch -@end - -#define float2 vec2 -#define float3 vec3 -#define float4 vec4 - -#define int2 ivec2 -#define int3 ivec3 -#define int4 ivec4 - -#define uint2 uvec2 -#define uint3 uvec3 -#define uint4 uvec4 - -#define float2x2 mat2 -#define float3x3 mat3 -#define float4x4 mat4 - -#define ushort uint - -#define toFloat3x3( x ) mat3( x ) -#define buildFloat3x3( row0, row1, row2 ) mat3( row0, row1, row2 ) - -#define buildFloat4x4( row0, row1, row2, row3 ) mat4( row0, row1, row2, row3 ) - -#define mul( x, y ) ((x) * (y)) -#define saturate(x) clamp( (x), 0.0, 1.0 ) -#define lerp mix -#define rsqrt inversesqrt -#define INLINE - -#define finalDrawId drawId -#define PARAMS_ARG_DECL -#define PARAMS_ARG - -#define outVs_Position gl_Position -#define OGRE_Sample( tex, sampler, uv ) texture( tex, uv ) -#define OGRE_SampleLevel( tex, sampler, uv, lod ) textureLod( tex, uv.xy, lod ) -#define OGRE_SampleArray2D( tex, sampler, uv, arrayIdx ) texture( tex, vec3( uv, arrayIdx ) ) -#define OGRE_SampleArray2DLevel( tex, sampler, uv, arrayIdx, lod ) textureLod( tex, vec3( uv, arrayIdx ), lod ) -#define OGRE_SampleGrad( tex, sampler, uv, ddx, ddy ) textureGrad( tex, uv, ddx, ddy ) -#define OGRE_SampleArray2DGrad( tex, sampler, uv, arrayIdx, ddx, ddy ) textureGrad( tex, vec3( uv, arrayIdx ), ddx, ddy ) -#define OGRE_ddx( val ) dFdx( val ) -#define OGRE_ddy( val ) dFdy( val ) - -#define bufferFetch1( buffer, idx ) texelFetch( buffer, idx ).x -@end - -@property( GLES < 320) -@piece( SetCompatibilityLayer ) - @property( !GL_ARB_texture_buffer_range ) - #define samplerBuffer sampler2D - #define isamplerBuffer isampler2D - #define usamplerBuffer usampler2D - vec4 bufferFetch( in sampler2D sampl, in int pixelIdx ) - { - ivec2 pos = ivec2( mod( float(pixelIdx), 2048. ), int( uint(pixelIdx) >> 11u ) ); - return texelFetch( sampl, pos, 0 ); - } - ivec4 bufferFetch(in isampler2D sampl, in int pixelIdx) - { - ivec2 pos = ivec2( mod( float(pixelIdx), 2048. ), int( uint(pixelIdx) >> 11u ) ); - return texelFetch( sampl, pos, 0 ); - } - uvec4 bufferFetch( in usampler2D sampl, in int pixelIdx ) - { - ivec2 pos = ivec2( mod( float(pixelIdx), 2048. ), int( uint(pixelIdx) >> 11u ) ); - return texelFetch( sampl, pos, 0 ); - } - @end - @property( !GL_ARB_shading_language_420pack ) - #define layout_constbuffer(x) layout( std140 ) - @end -@end -@end diff --git a/Samples/Media/Hlms/Common/GLSLES/Matrix_piece_all.glsl b/Samples/Media/Hlms/Common/GLSLES/Matrix_piece_all.glsl deleted file mode 100644 index 9eda568abc9..00000000000 --- a/Samples/Media/Hlms/Common/GLSLES/Matrix_piece_all.glsl +++ /dev/null @@ -1,53 +0,0 @@ -@property( GL_ARB_texture_buffer_range ) -@piece( Common_Matrix_DeclUnpackMatrix4x4 ) -mat4 UNPACK_MAT4( samplerBuffer matrixBuf, uint pixelIdx ) -{ - vec4 row0 = texelFetch( matrixBuf, int((pixelIdx) << 2u) ); - vec4 row1 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 1u) ); - vec4 row2 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 2u) ); - vec4 row3 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 3u) ); - return mat4( row0, row1, row2, row3 ); -} -@end - -@piece( Common_Matrix_DeclUnpackMatrix3x4 ) -mat3x4 UNPACK_MAT3x4( samplerBuffer matrixBuf, uint pixelIdx ) -{ - vec4 row0 = texelFetch( matrixBuf, int((pixelIdx) << 2u) ); - vec4 row1 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 1u) ); - vec4 row2 = texelFetch( matrixBuf, int(((pixelIdx) << 2u) + 2u) ); - return mat3x4( row0, row1, row2 ); -} -@end -@end - -@property( !GL_ARB_texture_buffer_range ) -@piece( Common_Matrix_DeclUnpackMatrix4x4 ) -mat4 UNPACK_MAT4( in sampler2D matrixBuf, in uint pixelIdx ) -{ - ivec2 pos0 = ivec2(int(((pixelIdx) << 2u) & 2047u), int(((pixelIdx) << 2u) >> 11u)); - ivec2 pos1 = ivec2(int((((pixelIdx) << 2u) + 1u) & 2047u), int((((pixelIdx) << 2u) + 1u) >> 11u)); - ivec2 pos2 = ivec2(int((((pixelIdx) << 2u) + 2u) & 2047u), int((((pixelIdx) << 2u) + 2u) >> 11u)); - ivec2 pos3 = ivec2(int((((pixelIdx) << 2u) + 3u) & 2047u), int((((pixelIdx) << 2u) + 3u) >> 11u)); - vec4 row0 = texelFetch( matrixBuf, pos0, 0 ); - vec4 row1 = texelFetch( matrixBuf, pos1, 0 ); - vec4 row2 = texelFetch( matrixBuf, pos2, 0 ); - vec4 row3 = texelFetch( matrixBuf, pos3, 0 ); - return mat4( row0, row1, row2, row3 ); -} -@end - -@piece( Common_Matrix_DeclUnpackMatrix3x4 ) -mat3x4 UNPACK_MAT3x4( in sampler2D matrixBuf, in uint pixelIdx ) -{ - ivec2 pos0 = ivec2(int(((pixelIdx) << 2u) & 2047u), int(((pixelIdx) << 2u) >> 11u)); - ivec2 pos1 = ivec2(int((((pixelIdx) << 2u) + 1u) & 2047u), int((((pixelIdx) << 2u) + 1u) >> 11u)); - ivec2 pos2 = ivec2(int((((pixelIdx) << 2u) + 2u) & 2047u), int((((pixelIdx) << 2u) + 2u) >> 11u)); - vec4 row0 = texelFetch( matrixBuf, pos0, 0 ); - vec4 row1 = texelFetch( matrixBuf, pos1, 0 ); - vec4 row2 = texelFetch( matrixBuf, pos2, 0 ); - return mat3x4( row0, row1, row2 ); -} -@end -@end - diff --git a/Samples/Media/Hlms/Common/GLSLES/QuaternionCode_piece_all.glsl b/Samples/Media/Hlms/Common/GLSLES/QuaternionCode_piece_all.glsl deleted file mode 100644 index b72defabff7..00000000000 --- a/Samples/Media/Hlms/Common/GLSLES/QuaternionCode_piece_all.glsl +++ /dev/null @@ -1,55 +0,0 @@ -@piece( DeclQuat_xAxis ) -vec3 xAxis( vec4 qQuat ) -{ - float fTy = 2.0 * qQuat.y; - float fTz = 2.0 * qQuat.z; - float fTwy = fTy * qQuat.w; - float fTwz = fTz * qQuat.w; - float fTxy = fTy * qQuat.x; - float fTxz = fTz * qQuat.x; - float fTyy = fTy * qQuat.y; - float fTzz = fTz * qQuat.z; - - return vec3( 1.0-(fTyy+fTzz), fTxy+fTwz, fTxz-fTwy ); -} -@end - -@piece( DeclQuat_yAxis ) -vec3 yAxis( vec4 qQuat ) -{ - float fTx = 2.0 * qQuat.x; - float fTy = 2.0 * qQuat.y; - float fTz = 2.0 * qQuat.z; - float fTwx = fTx * qQuat.w; - float fTwz = fTz * qQuat.w; - float fTxx = fTx * qQuat.x; - float fTxy = fTy * qQuat.x; - float fTyz = fTz * qQuat.y; - float fTzz = fTz * qQuat.z; - - return vec3( fTxy-fTwz, 1.0-(fTxx+fTzz), fTyz+fTwx ); -} -@end - -@piece( DeclQuat_zAxis ) -vec3 zAxis( vec4 qQuat ) -{ - float fTx = 2.0 * qQuat.x; - float fTy = 2.0 * qQuat.y; - float fTz = 2.0 * qQuat.z; - float fTwx = fTx * qQuat.w; - float fTwy = fTy * qQuat.w; - float fTxx = fTx * qQuat.x; - float fTxz = fTz * qQuat.x; - float fTyy = fTy * qQuat.y; - float fTyz = fTz * qQuat.y; - - return vec3( fTxz+fTwy, fTyz-fTwx, 1.0-(fTxx+fTyy) ); -} -@end - -@piece( DeclQuat_AllAxis ) -@insertpiece( DeclQuat_xAxis ) -@insertpiece( DeclQuat_yAxis ) -@insertpiece( DeclQuat_zAxis ) -@end diff --git a/Samples/Media/Hlms/Common/GLSLES/RenderDepthOnly_piece_ps.glsl b/Samples/Media/Hlms/Common/GLSLES/RenderDepthOnly_piece_ps.glsl deleted file mode 100644 index 7ba220fcd34..00000000000 --- a/Samples/Media/Hlms/Common/GLSLES/RenderDepthOnly_piece_ps.glsl +++ /dev/null @@ -1,3 +0,0 @@ -@property( 0 && hlms_render_depth_only && !alpha_test && !hlms_shadows_esm && !macOS) - @set( hlms_disable_stage, 1 ) -@end diff --git a/Samples/Media/Hlms/Pbs/GLSLES/BRDFs_piece_ps.glsl b/Samples/Media/Hlms/Pbs/GLSLES/BRDFs_piece_ps.glsl deleted file mode 100644 index c86fbbd73dc..00000000000 --- a/Samples/Media/Hlms/Pbs/GLSLES/BRDFs_piece_ps.glsl +++ /dev/null @@ -1,240 +0,0 @@ -@property( !metallic_workflow && (!specular_map || !fresnel_workflow) && !hlms_decals_diffuse ) - @property( !transparent_mode ) - @piece( F0 )material.F0@end - @end @property( transparent_mode ) - //Premultiply F0.xyz with the alpha from the texture, but only in transparent mode. - @piece( F0 )(material.F0.@insertpiece( FresnelSwizzle ) * diffuseCol.w)@end - @end -@end @property( metallic_workflow || (specular_map && fresnel_workflow) || hlms_decals_diffuse ) - @piece( F0 )F0@end -@end - -@property( !fresnel_scalar ) - @piece( maxR1F0 )max( 1.0 - ROUGHNESS, @insertpiece( F0 ).x )@end -@end @property( fresnel_scalar ) - @piece( maxR1F0 )max( (1.0 - ROUGHNESS).xxx, @insertpiece( F0 ).xyz )@end -@end - -//For mortals: -// getSpecularFresnel = F0 + pow( 1.0 - VdotH, 5.0 ) * (1.0 - F0) -// getDiffuseFresnel = 1.0 - F0 + pow( 1.0 - NdotL, 5.0 ) * F0 -// getSpecularFresnelWithRoughness = F0 + pow( 1.0 - VdotH, 5.0 ) * (max(ROUGHNESS, (1.0 - F0)) - F0) -// getDiffuseFresnelWithRoughness = max(ROUGHNESS, (1.0 - F0) - F0 + pow( 1.0 - NdotL, 5.0 ) * F0 -@piece( getSpecularFresnel )@insertpiece( F0 ).@insertpiece( FresnelSwizzle ) + pow( 1.0 - VdotH, 5.0 ) * (1.0 - @insertpiece( F0 ).@insertpiece( FresnelSwizzle ))@end -@piece( getDiffuseFresnel )1.0 - @insertpiece( F0 ).@insertpiece( FresnelSwizzle ) + pow( 1.0 - NdotL, 5.0 ) * @insertpiece( F0 ).@insertpiece( FresnelSwizzle )@end - -@piece( getSpecularFresnelWithRoughness )@insertpiece( F0 ).@insertpiece( FresnelSwizzle ) + pow( 1.0 - VdotH, 5.0 ) * (@insertpiece( maxR1F0 ) - @insertpiece( F0 ).@insertpiece( FresnelSwizzle ))@end -@piece( getDiffuseFresnelWithRoughness )@insertpiece( maxR1F0 ) - @insertpiece( F0 ).@insertpiece( FresnelSwizzle ) + pow( 1.0 - NdotL, 5.0 ) * @insertpiece( F0 ).@insertpiece( FresnelSwizzle )@end - -@property( !fresnel_scalar ) - @piece( getMaxFresnelS )fresnelS@end -@end @property( fresnel_scalar ) - @property( hlms_amd_trinary_minmax )@piece( getMaxFresnelS )max3( fresnelS.x, fresnelS.y, fresnelS.z )@end @end - @property( !hlms_amd_trinary_minmax )@piece( getMaxFresnelS )max( fresnelS.x, max( fresnelS.y, fresnelS.z ) )@end @end -@end - -@property( BRDF_BlinnPhong ) -@piece( DeclareBRDF ) -//Blinn-Phong -vec3 BRDF( vec3 lightDir, vec3 viewDir, float NdotV, vec3 lightDiffuse, vec3 lightSpecular ) -{ - vec3 halfWay= normalize( lightDir + viewDir ); - float NdotL = clamp( dot( nNormal, lightDir ), 0.0, 1.0 ); //Diffuse (Lambert) - float NdotH = clamp( dot( nNormal, halfWay ), 0.001, 1.0 ); //Specular - @property( !legacy_math_brdf ) - float VdotH = clamp( dot( viewDir, halfWay ), 0.001, 1.0 ); //Fresnel - - //Fresnel term (Schlick's approximation) - @insertpiece( FresnelType ) fresnelS = @insertpiece( getSpecularFresnel ); - @property( fresnel_separate_diffuse ) - @insertpiece( FresnelType ) fresnelD = @insertpiece( getDiffuseFresnel ); - @end @property( !fresnel_separate_diffuse ) - float fresnelD = 1.0f - @insertpiece( getMaxFresnelS ); - @end - @end - - @property( !roughness_is_shininess ) - float shininess = exp2( 10.0 * (1.0 - ROUGHNESS) + 1.0 ) * 0.25; - @end @property( roughness_is_shininess ) - float shininess = ROUGHNESS; - @end - float blinnPhong = pow( NdotH, shininess ); - - @property( !legacy_math_brdf ) - //Normalize Blinn-Phong using (n + 8) / (8 * pi) - //Note this factor is an approximation. The real normalization is - //*much* more expensive. See: - //http://www.rorydriscoll.com/2009/01/25/energy-conservation-in-games/ - blinnPhong *= (shininess + 8.0) / (8.0 * 3.141592654); - - //Avoid very small denominators, they go to NaN or cause aliasing artifacts - //Note: For blinn-phong we use larger denominators otherwise specular blows out of proportion - @insertpiece( FresnelType ) Rs = ( fresnelS * blinnPhong ) / max( 4.0 * NdotV * NdotL, 0.75 ); - //Make diffuse look closer to Default. - fresnelD *= mix( 1.0, 1.0 / 1.51, ROUGHNESS ); - @end @property( legacy_math_brdf ) - float Rs = blinnPhong; - float fresnelD = 1.0; - @end - - return NdotL * (@insertpiece( kS ).xyz * lightSpecular * Rs + - @insertpiece( kD ).xyz * lightDiffuse * fresnelD); -} -@end -@end - -@property( BRDF_CookTorrance ) -@piece( DeclareBRDF ) -//Cook-Torrance -vec3 BRDF( vec3 lightDir, vec3 viewDir, float NdotV, vec3 lightDiffuse, vec3 lightSpecular ) -{ - vec3 halfWay= normalize( lightDir + viewDir ); - float NdotL = clamp( dot( nNormal, lightDir ), 0.0, 1.0 ); - float NdotH = clamp( dot( nNormal, halfWay ), 0.001, 1.0 ); - float VdotH = clamp( dot( viewDir, halfWay ), 0.001, 1.0 ); - - float sqR = ROUGHNESS * ROUGHNESS; - - //Roughness/Distribution/NDF term (Beckmann distribution) - //Formula: - // Where alpha = NdotH and m = roughness - // R = [ 1 / (m^2 x cos(alpha)^4 ] x [ e^( -tan(alpha)^2 / m^2 ) ] - // R = [ 1 / (m^2 x cos(alpha)^4 ] x [ e^( ( cos(alpha)^2 - 1 ) / (m^2 cos(alpha)^2 ) ] - float NdotH_sq = NdotH * NdotH; - float roughness_a = 1.0 / ( 3.141592654 * sqR * NdotH_sq * NdotH_sq );//( 1 / (m^2 x cos(alpha)^4 ) - float roughness_b = NdotH_sq - 1.0; //( cos(alpha)^2 - 1 ) - float roughness_c = sqR * NdotH_sq; //( m^2 cos(alpha)^2 ) - - //Avoid Inf * 0 = NaN; we need Inf * 0 = 0 - float R = min( roughness_a, 65504.0 ) * exp( roughness_b / roughness_c ); - - //Geometric/Visibility term (Cook Torrance) - float shared_geo = 2.0 * NdotH / VdotH; - float geo_b = shared_geo * NdotV; - float geo_c = shared_geo * NdotL; - @property( !hlms_amd_trinary_minmax )float G = min( 1.0, min( geo_b, geo_c ) );@end - @property( hlms_amd_trinary_minmax )float G = min3( 1.0, geo_b, geo_c );@end - - //Fresnel term (Schlick's approximation) - //Formula: - // fresnelS = lerp( (1 - V*H)^5, 1, F0 ) - // fresnelD = lerp( (1 - N*L)^5, 1, 1 - F0 ) [See s2010_course_note_practical_implementation_at_triace.pdf] - @insertpiece( FresnelType ) fresnelS = @insertpiece( getSpecularFresnel ); -@property( fresnel_separate_diffuse ) - @insertpiece( FresnelType ) fresnelD = @insertpiece( getDiffuseFresnel ); -@end @property( !fresnel_separate_diffuse ) - float fresnelD = 1.0f - @insertpiece( getMaxFresnelS );@end - - //Avoid very small denominators, they go to NaN or cause aliasing artifacts - @insertpiece( FresnelType ) Rs = ( fresnelS * (R * G) ) / max( 4.0 * NdotV * NdotL, 0.01 ); - - return NdotL * (@insertpiece( kS ).xyz * lightSpecular * Rs + - @insertpiece( kD ).xyz * lightDiffuse * fresnelD); -} -@end -@end - -@property( BRDF_Default ) -@piece( DeclareBRDF ) -//Default BRDF -vec3 BRDF( vec3 lightDir, vec3 viewDir, float NdotV, vec3 lightDiffuse, vec3 lightSpecular ) -{ - vec3 halfWay= normalize( lightDir + viewDir ); - float NdotL = clamp( dot( nNormal, lightDir ), 0.0, 1.0 ); - float NdotH = clamp( dot( nNormal, halfWay ), 0.0, 1.0 ); - float VdotH = clamp( dot( viewDir, halfWay ), 0.0, 1.0 ); - - float sqR = ROUGHNESS * ROUGHNESS; - - //Roughness/Distribution/NDF term (GGX) - //Formula: - // Where alpha = roughness - // R = alpha^2 / [ PI * [ ( NdotH^2 * (alpha^2 - 1) ) + 1 ]^2 ] - float f = ( NdotH * sqR - NdotH ) * NdotH + 1.0; - float R = sqR / (f * f + 1e-6f); - - //Geometric/Visibility term (Smith GGX Height-Correlated) -@property( GGX_height_correlated ) - float Lambda_GGXV = NdotL * sqrt( (-NdotV * sqR + NdotV) * NdotV + sqR ); - float Lambda_GGXL = NdotV * sqrt( (-NdotL * sqR + NdotL) * NdotL + sqR ); - - float G = 0.5 / (( Lambda_GGXV + Lambda_GGXL + 1e-6f ) * 3.141592654); -@end @property( !GGX_height_correlated ) - float gL = NdotL * (1-sqR) + sqR; - float gV = NdotV * (1-sqR) + sqR; - float G = 1.0 / (( gL * gV + 1e-4f ) * 4 * 3.141592654); -@end - - //Formula: - // fresnelS = lerp( (1 - V*H)^5, 1, F0 ) - @insertpiece( FresnelType ) fresnelS = @insertpiece( getSpecularFresnel ); - - //We should divide Rs by PI, but it was done inside G for performance - vec3 Rs = ( fresnelS * (R * G) ) * @insertpiece( kS ).xyz * lightSpecular; - - //Diffuse BRDF (*Normalized* Disney, see course_notes_moving_frostbite_to_pbr.pdf - //"Moving Frostbite to Physically Based Rendering" Sebastien Lagarde & Charles de Rousiers) - float energyBias = ROUGHNESS * 0.5; - float energyFactor = mix( 1.0, 1.0 / 1.51, ROUGHNESS ); - float fd90 = energyBias + 2.0 * VdotH * VdotH * ROUGHNESS; - float lightScatter = 1.0 + (fd90 - 1.0) * pow( 1.0 - NdotL, 5.0 ); - float viewScatter = 1.0 + (fd90 - 1.0) * pow( 1.0 - NdotV, 5.0 ); - -@property( fresnel_separate_diffuse ) - @insertpiece( FresnelType ) fresnelD = @insertpiece( getDiffuseFresnel ); -@end @property( !fresnel_separate_diffuse ) - float fresnelD = 1.0f - @insertpiece( getMaxFresnelS );@end - - //We should divide Rd by PI, but it is already included in kD - vec3 Rd = (lightScatter * viewScatter * energyFactor * fresnelD) * @insertpiece( kD ).xyz * lightDiffuse; - - return NdotL * (Rs + Rd); -} -@end -@end - -@property( hlms_enable_vpls ) -@piece( DeclareBRDF_InstantRadiosity ) -//Simplified cheap BRDF for Instant Radiosity. -vec3 BRDF_IR( vec3 lightDir, vec3 lightDiffuse ) -{ - float NdotL = clamp( dot( nNormal, lightDir ), 0.0, 1.0 ); - @insertpiece( FresnelType ) fresnelD = @insertpiece( getDiffuseFresnel ); - - //We should divide Rd by PI, but it is already included in kD - return NdotL * fresnelD * @insertpiece( kD ).xyz * lightDiffuse; -} -@end -@end - -/// Applying Fresnel term to prefiltered cubemap has a bad effect of always showing high specular -/// color at edge, even for rough surface. See https://seblagarde.wordpress.com/2011/08/17/hello-world/ -/// and see http://www.ogre3d.org/forums/viewtopic.php?f=25&p=523550#p523544 -/// "The same Fresnel term which is appropriate for unfiltered environment maps (i.e. perfectly smooth -/// mirror surfaces) is not appropriate for filtered environment maps since there you are averaging -/// incoming light colors from many directions, but using a single Fresnel value computed for the -/// reflection direction. The correct function has similar values as the regular Fresnel expression -/// at v=n, but at glancing angle it behaves differently. In particular, the lerp(from base specular -/// to white) does not go all the way to white at glancing angles in the case of rough surfaces." -/// So we use getSpecularFresnelWithRoughness instead. -@piece( BRDF_EnvMap ) - float NdotL = clamp( dot( nNormal, reflDir ), 0.0, 1.0 ); - float VdotH = clamp( dot( viewDir, normalize( reflDir + viewDir ) ), 0.0, 1.0 ); - @insertpiece( FresnelType ) fresnelS = @insertpiece( getSpecularFresnelWithRoughness ); - - @property( fresnel_separate_diffuse ) - @insertpiece( FresnelType ) fresnelD = @insertpiece( getDiffuseFresnelWithRoughness ); - @end @property( !fresnel_separate_diffuse ) - float fresnelD = 1.0f - @insertpiece( getMaxFresnelS );@end - - finalColour += envColourD * @insertpiece( kD ).xyz * fresnelD + - envColourS * @insertpiece( kS ).xyz * fresnelS; -@end - -@property( hlms_fine_light_mask ) - @piece( DeclareObjLightMask )uint objLightMask = instance.worldMaterialIdx[inPs.drawId].z;@end - @piece( ObjLightMaskCmp )if( (objLightMask & floatBitsToUint( passBuf.lights[@counter(fineMaskLightIdx)].position.w )) != 0u )@end - @piece( andObjLightMaskCmp )&& ((objLightMask & floatBitsToUint( passBuf.lights[@counter(fineMaskLightIdx)].position.w )) != 0u)@end - @piece( andObjAreaApproxLightMaskCmp )&& ((objLightMask & floatBitsToUint( passBuf.areaApproxLights[@counter(fineMaskAreaApproxLightIdx)].position.w )) != 0u)@end - @piece( andObjAreaLtcLightMaskCmp )&& ((objLightMask & floatBitsToUint( passBuf.areaLtcLights[@counter(fineMaskAreaLtcLightIdx)].position.w )) != 0u)@end -@end diff --git a/Samples/Media/Hlms/Pbs/GLSLES/BlendModes_piece_ps.glsl b/Samples/Media/Hlms/Pbs/GLSLES/BlendModes_piece_ps.glsl deleted file mode 100644 index f77d203852a..00000000000 --- a/Samples/Media/Hlms/Pbs/GLSLES/BlendModes_piece_ps.glsl +++ /dev/null @@ -1,105 +0,0 @@ -//Reset t to 0 just in case (values are preserved from previous stages) -@pset( t, 0 ) - -@property( !hlms_shadowcaster ) -@piece( NormalNonPremul ) - //Normal Non Premultiplied @value(t) - diffuseCol.xyz = mix( diffuseCol.xyz, detailCol@value(t).xyz, detailCol@value(t).a ); - diffuseCol.w = mix( diffuseCol.w, 1.0, detailCol@value(t).w ); -@end - -@piece( NormalPremul ) - //Normal Premultiplied @value(t) - diffuseCol.xyz = (1.0 - detailCol@value(t).a) * diffuseCol.xyz + detailCol@value(t).xyz; - diffuseCol.w = mix( diffuseCol.w, 1.0, detailCol@value(t).w ); -@end - -@piece( Add ) - //Add @value(t) - diffuseCol.xyz = mix( diffuseCol.xyz, - min( diffuseCol.xyz + detailCol@value(t).xyz, vec3(1.0, 1.0, 1.0) ), - detailCol@value(t).a ); -@end - -@piece( Subtract ) - //Subtract @value(t) - diffuseCol.xyz = mix( diffuseCol.xyz, - max( diffuseCol.xyz - detailCol@value(t).xyz, vec3(0.0, 0.0, 0.0) ), - detailCol@value(t).a ); -@end - -@piece( Multiply ) - //Multiply @value(t) - diffuseCol.xyz = mix( diffuseCol.xyz, - diffuseCol.xyz * detailCol@value(t).xyz, - detailCol@value(t).a ); -@end - -@piece( Multiply2x ) - //Multiply2x @value(t) - diffuseCol.xyz = mix( diffuseCol.xyz, - min( diffuseCol.xyz * detailCol@value(t).xyz * 2.0, vec3(1.0, 1.0, 1.0) ), - detailCol@value(t).a ); -@end - -@piece( Screen ) - //Screen @value(t) - diffuseCol.xyz = mix( diffuseCol.xyz, - 1.0 - (1.0 - diffuseCol.xyz) * (1.0 - detailCol@value(t).xyz), - detailCol@value(t).a ); -@end - -@piece( Overlay ) - //Overlay @value(t) - diffuseCol.xyz = mix( diffuseCol.xyz, - diffuseCol.xyz * ( diffuseCol.xyz + 2.0 * detailCol@value(t).xyz * (1.0 - diffuseCol.xyz) ), - detailCol@value(t).a ); -@end - -@piece( Lighten ) - //Lighten @value(t) - diffuseCol.xyz = mix( diffuseCol.xyz, - max( diffuseCol.xyz, detailCol@value(t).xyz ), - detailCol@value(t).a ); -@end - -@piece( Darken ) - //Darken @value(t) - diffuseCol.xyz = mix( diffuseCol.xyz, - min( diffuseCol.xyz, detailCol@value(t).xyz ), - detailCol@value(t).a ); -@end - -@piece( GrainExtract ) - //GrainExtract @value(t) - diffuseCol.xyz = mix( diffuseCol.xyz, - (diffuseCol.xyz - detailCol@value(t).xyz) + 0.5f, - detailCol@value(t).a ); -@end - -@piece( GrainMerge ) - //GrainMerge @value(t) - diffuseCol.xyz = mix( diffuseCol.xyz, - (diffuseCol.xyz + detailCol@value(t).xyz) - 0.5f, - detailCol@value(t).a ); -@end - -@piece( Difference ) - //Difference @value(t) - diffuseCol.xyz = mix( diffuseCol.xyz, - abs(diffuseCol.xyz - detailCol@value(t).xyz), - detailCol@value(t).a ); -@end -@end @property( hlms_shadowcaster ) - -@piece( NormalNonPremul ) - //Normal Non Premultiplied @value(t) - diffuseCol = mix( diffuseCol, 1.0, detailCol@value(t) ); -@end - -@piece( NormalPremul ) - //Normal Premultiplied @value(t) - diffuseCol = mix( diffuseCol, 1.0, detailCol@value(t) ); -@end - -@end diff --git a/Samples/Media/Hlms/Pbs/GLSLES/DetailMaps_piece_ps.glsl b/Samples/Media/Hlms/Pbs/GLSLES/DetailMaps_piece_ps.glsl deleted file mode 100644 index 4f6a1ab30fe..00000000000 --- a/Samples/Media/Hlms/Pbs/GLSLES/DetailMaps_piece_ps.glsl +++ /dev/null @@ -1,26 +0,0 @@ -// detail_maps_diffuse & detail_maps_normal are either 0 or 4 - -@pmax( NumDetailMaps, detail_maps_diffuse, detail_maps_normal ) -@foreach( NumDetailMaps, n ) - @property( detail_offsets@n ) - @piece( offsetDetail@n ) * material.detailOffsetScale[@n].zw + material.detailOffsetScale[@n].xy@end - @end -@end - -@piece( detail_swizzle0 )x@end; -@piece( detail_swizzle1 )y@end; -@piece( detail_swizzle2 )z@end; -@piece( detail_swizzle3 )w@end; - -/* -Down below we perform: - if( detail_maps_normal ) - second_valid_detail_map_nm = first_valid_detail_map_nm + 1; - else - second_valid_detail_map_nm = 0; -*/ -@property( detail_maps_normal ) - @add( second_valid_detail_map_nm, first_valid_detail_map_nm, 1 ) -@end @property( !detail_maps_normal ) - @set( second_valid_detail_map_nm, 0 ) -@end diff --git a/Samples/Media/Hlms/Pbs/GLSLES/Forward3D_piece_ps.glsl b/Samples/Media/Hlms/Pbs/GLSLES/Forward3D_piece_ps.glsl deleted file mode 100644 index b7edd58ad50..00000000000 --- a/Samples/Media/Hlms/Pbs/GLSLES/Forward3D_piece_ps.glsl +++ /dev/null @@ -1,261 +0,0 @@ -@property( hlms_forwardplus ) - -@property( hlms_forwardplus_fine_light_mask ) - @piece( andObjLightMaskFwdPlusCmp )&& ((objLightMask & floatBitsToUint( lightDiffuse.w )) != 0u)@end -@end - -@property( hlms_enable_decals ) -@piece( DeclDecalsSamplers ) - @property( hlms_decals_diffuse )uniform sampler2DArray decalsDiffuseTex;@end - @property( hlms_decals_normals )uniform sampler2DArray decalsNormalsTex;@end - @property( hlms_decals_diffuse == hlms_decals_emissive ) - #define decalsEmissiveTex decalsDiffuseTex - @end - @property( hlms_decals_emissive && hlms_decals_diffuse != hlms_decals_emissive ) - uniform sampler2DArray decalsEmissiveTex; - @end -@end -@end - -/// The header is automatically inserted. Whichever subsystem needs it first, will call it -@piece( forward3dHeader ) - @property( hlms_forwardplus_covers_entire_target ) - #define FWDPLUS_APPLY_OFFSET_Y(v) (v) - #define FWDPLUS_APPLY_OFFSET_X(v) (v) - @end - - @property( hlms_forwardplus_fine_light_mask && !hlms_fine_light_mask ) - uint objLightMask = instance.worldMaterialIdx[inPs.drawId].z; - @end - @property( hlms_forwardplus == forward3d ) - float f3dMinDistance = passBuf.f3dData.x; - float f3dInvMaxDistance = passBuf.f3dData.y; - float f3dNumSlicesSub1 = passBuf.f3dData.z; - uint cellsPerTableOnGrid0= floatBitsToUint( passBuf.f3dData.w ); - - // See C++'s Forward3D::getSliceAtDepth - /*float fSlice = 1.0 - clamp( (-inPs.pos.z + f3dMinDistance) * f3dInvMaxDistance, 0.0, 1.0 ); - fSlice = (fSlice * fSlice) * (fSlice * fSlice); - fSlice = (fSlice * fSlice); - fSlice = floor( (1.0 - fSlice) * f3dNumSlicesSub1 );*/ - float fSlice = clamp( (-inPs.pos.z + f3dMinDistance) * f3dInvMaxDistance, 0.0, 1.0 ); - fSlice = floor( fSlice * f3dNumSlicesSub1 ); - uint slice = uint( fSlice ); - - //TODO: Profile performance: derive this mathematically or use a lookup table? - uint offset = cellsPerTableOnGrid0 * (((1u << (slice << 1u)) - 1u) / 3u); - - float lightsPerCell = passBuf.f3dGridHWW[0].w; - - @property( !hlms_forwardplus_covers_entire_target ) - #define FWDPLUS_APPLY_OFFSET_Y(v) (v - passBuf.f3dViewportOffset.y) - #define FWDPLUS_APPLY_OFFSET_X(v) (v - passBuf.f3dViewportOffset.x) - @end - - //passBuf.f3dGridHWW[slice].x = grid_width / renderTarget->width; - //passBuf.f3dGridHWW[slice].y = grid_height / renderTarget->height; - //passBuf.f3dGridHWW[slice].z = grid_width * lightsPerCell; - //uint sampleOffset = 0; - @property( hlms_forwardplus_flipY ) - float windowHeight = passBuf.f3dGridHWW[1].w; //renderTarget->height - uint sampleOffset = offset + - uint(floor( (windowHeight - FWDPLUS_APPLY_OFFSET_Y(gl_FragCoord.y) ) * - passBuf.f3dGridHWW[slice].y ) * passBuf.f3dGridHWW[slice].z) + - uint(floor( FWDPLUS_APPLY_OFFSET_X(gl_FragCoord.x) * - passBuf.f3dGridHWW[slice].x ) * lightsPerCell); - @end @property( !hlms_forwardplus_flipY ) - uint sampleOffset = offset + - uint(floor( FWDPLUS_APPLY_OFFSET_Y(gl_FragCoord.y) * - passBuf.f3dGridHWW[slice].y ) * passBuf.f3dGridHWW[slice].z) + - uint(floor( FWDPLUS_APPLY_OFFSET_X(gl_FragCoord.x) * - passBuf.f3dGridHWW[slice].x ) * lightsPerCell); - @end - @end @property( hlms_forwardplus != forward3d ) - float f3dMinDistance = passBuf.f3dData.x; - float f3dInvExponentK = passBuf.f3dData.y; - float f3dNumSlicesSub1 = passBuf.f3dData.z; - - // See C++'s ForwardClustered::getSliceAtDepth - float fSlice = log2( max( -inPs.pos.z - f3dMinDistance, 1 ) ) * f3dInvExponentK; - fSlice = floor( min( fSlice, f3dNumSlicesSub1 ) ); - uint sliceSkip = uint( fSlice * @value( fwd_clustered_width_x_height ) ); - - @property( !hlms_forwardplus_covers_entire_target ) - #define FWDPLUS_APPLY_OFFSET_Y(v) (v - passBuf.fwdScreenToGrid.w) - #define FWDPLUS_APPLY_OFFSET_X(v) (v - passBuf.fwdScreenToGrid.z) - @end - - uint sampleOffset = sliceSkip + - uint(floor( FWDPLUS_APPLY_OFFSET_X(gl_FragCoord.x) * passBuf.fwdScreenToGrid.x )); - @property( hlms_forwardplus_flipY ) - float windowHeight = passBuf.f3dData.w; //renderTarget->height - sampleOffset += uint(floor( (windowHeight - FWDPLUS_APPLY_OFFSET_Y(gl_FragCoord.y) ) * - passBuf.fwdScreenToGrid.y ) * - @value( fwd_clustered_width )); - @end @property( !hlms_forwardplus_flipY ) - sampleOffset += uint(floor( FWDPLUS_APPLY_OFFSET_Y(gl_FragCoord.y) * - passBuf.fwdScreenToGrid.y ) * - @value( fwd_clustered_width )); - @end - - sampleOffset *= @value( fwd_clustered_lights_per_cell )u; - @end - - @property( hlms_forwardplus_debug )uint totalNumLightsInGrid = 0u;@end -@end - -@piece( forward3dLighting ) - @property( !hlms_enable_decals ) - @insertpiece( forward3dHeader ) - uint numLightsInGrid; - @end - - @property( hlms_decals_emissive ) - finalColour += finalDecalEmissive; - @end - - numLightsInGrid = bufferFetch( f3dGrid, int(sampleOffset) ).x; - - @property( hlms_forwardplus_debug )totalNumLightsInGrid += numLightsInGrid;@end - - for( uint i=0u; i= spotParams.y ) - { - vec3 tmpColour = BRDF( lightDir, viewDir, NdotV, lightDiffuse.xyz, lightSpecular ); - finalColour += tmpColour * atten; - } - } - } - -@property( hlms_enable_vpls ) - prevLightCount = numLightsInGrid; - numLightsInGrid = bufferFetch( f3dGrid, int(sampleOffset + 2u) ).x; - - @property( hlms_forwardplus_debug )totalNumLightsInGrid += numLightsInGrid;@end - - for( uint i=prevLightCount; i> 16u;@end -@property( specular_map ) specularIdx = material.indices0_3.y & 0x0000FFFFu;@end -@property( roughness_map ) roughnessIdx = material.indices0_3.y >> 16u;@end -@property( detail_weight_map ) weightMapIdx = material.indices0_3.z & 0x0000FFFFu;@end -@property( detail_map0 ) detailMapIdx0 = material.indices0_3.z >> 16u;@end -@property( detail_map1 ) detailMapIdx1 = material.indices0_3.w & 0x0000FFFFu;@end -@property( detail_map2 ) detailMapIdx2 = material.indices0_3.w >> 16u;@end -@property( detail_map3 ) detailMapIdx3 = material.indices4_7.x & 0x0000FFFFu;@end -@property( detail_map_nm0 ) detailNormMapIdx0 = material.indices4_7.x >> 16u;@end -@property( detail_map_nm1 ) detailNormMapIdx1 = material.indices4_7.y & 0x0000FFFFu;@end -@property( detail_map_nm2 ) detailNormMapIdx2 = material.indices4_7.y >> 16u;@end -@property( detail_map_nm3 ) detailNormMapIdx3 = material.indices4_7.z & 0x0000FFFFu;@end -@property( emissive_map ) emissiveMapIdx = material.indices4_7.z >> 16u;@end -@property( use_envprobe_map ) envMapIdx = material.indices4_7.w & 0x0000FFFFu;@end - - @insertpiece( DeclareObjLightMask ) - - @insertpiece( custom_ps_posMaterialLoad ) - -@property( detail_maps_diffuse || detail_maps_normal ) - //Prepare weight map for the detail maps. - @property( detail_weight_map ) - vec4 detailWeights = @insertpiece( SamplerDetailWeightMap ); - @property( detail_weights )detailWeights *= material.cDetailWeights;@end - @end @property( !detail_weight_map ) - @property( detail_weights )vec4 detailWeights = material.cDetailWeights;@end - @property( !detail_weights )vec4 detailWeights = vec4( 1.0, 1.0, 1.0, 1.0 );@end - @end -@end - - /// Sample detail maps and weight them against the weight map in the next foreach loop. -@foreach( detail_maps_diffuse, n )@property( detail_map@n ) - vec4 detailCol@n = texture( textureMaps[@value(detail_map@n_idx)], - vec3( UV_DETAIL@n( inPs.uv@value(uv_detail@n).xy@insertpiece( offsetDetail@n ) ), - detailMapIdx@n ) ); - @property( !hw_gamma_read )//Gamma to linear space - detailCol@n.xyz = detailCol@n.xyz * detailCol@n.xyz;@end - detailWeights.@insertpiece(detail_swizzle@n) *= detailCol@n.w; - detailCol@n.w = detailWeights.@insertpiece(detail_swizzle@n);@end -@end - -@property( !hlms_prepass || alpha_test ) - @insertpiece( SampleDiffuseMap ) - - /// 'insertpiece( SampleDiffuseMap )' must've written to diffuseCol. However if there are no - /// diffuse maps, we must initialize it to some value. If there are no diffuse or detail maps, - /// we must not access diffuseCol at all, but rather use material.kD directly (see piece( kD ) ). - @property( !diffuse_map )diffuseCol = material.bgDiffuse;@end - - /// Blend the detail diffuse maps with the main diffuse. - @foreach( detail_maps_diffuse, n ) - @insertpiece( blend_mode_idx@n ) @add( t, 1 ) @end - - /// Apply the material's diffuse over the textures - @property( !transparent_mode ) - diffuseCol.xyz *= material.kD.xyz; - @end @property( transparent_mode ) - diffuseCol.xyz *= material.kD.xyz * diffuseCol.w * diffuseCol.w; - @end - - @property( alpha_test && !alpha_test_shadow_caster_only ) - if( material.kD.w @insertpiece( alpha_test_cmp_func ) diffuseCol.a ) - discard; - @end -@end - - @insertpiece( SampleSpecularMap ) - @insertpiece( SampleRoughnessMap ) - - @insertpiece( forwardPlusDoDecals ) - -@property( !hlms_use_prepass ) - @property( !normal_map ) - // Geometric normal - nNormal = normalize( inPs.normal ) @insertpiece( two_sided_flip_normal ); - @end @property( normal_map ) - //Normal mapping. - vec3 geomNormal = normalize( inPs.normal ) @insertpiece( two_sided_flip_normal ); - vec3 vTangent = normalize( inPs.tangent ); - - //Get the TBN matrix - vec3 vBinormal = normalize( cross( geomNormal, vTangent )@insertpiece( tbnApplyReflection ) ); - mat3 TBN = mat3( vTangent, vBinormal, geomNormal ); - - @property( normal_map_tex )nNormal = getTSNormal( vec3( UV_NORMAL( inPs.uv@value(uv_normal).xy ), - normalIdx ) );@end - @property( normal_weight_tex ) - // Apply the weight to the main normal map - nNormal = mix( vec3( 0.0, 0.0, 1.0 ), nNormal, normalMapWeight ); - @end - @end - - /// If there is no normal map, the first iteration must - /// initialize nNormal instead of try to merge with it. - @property( normal_map_tex ) - @piece( detail_nm_op_sum )+=@end - @piece( detail_nm_op_mul )*=@end - @end @property( !normal_map_tex ) - @piece( detail_nm_op_sum )=@end - @piece( detail_nm_op_mul )=@end - @end - - /// Blend the detail normal maps with the main normal. - @foreach( second_valid_detail_map_nm, n, first_valid_detail_map_nm ) - vec3 vDetail = @insertpiece( SampleDetailMapNm@n ); - nNormal.xy @insertpiece( detail_nm_op_sum ) vDetail.xy; - nNormal.z @insertpiece( detail_nm_op_mul ) vDetail.z + 1.0 - detailWeights.@insertpiece(detail_swizzle@n) @insertpiece( detail@n_nm_weight_mul );@end - @foreach( detail_maps_normal, n, second_valid_detail_map_nm )@property( detail_map_nm@n ) - vDetail = @insertpiece( SampleDetailMapNm@n ); - nNormal.xy += vDetail.xy; - nNormal.z *= vDetail.z + 1.0 - detailWeights.@insertpiece(detail_swizzle@n) @insertpiece( detail@n_nm_weight_mul );@end @end - - @insertpiece( custom_ps_posSampleNormal ) - - @insertpiece( forwardPlusApplyDecalsNormal ) - - @property( normal_map ) - nNormal = normalize( TBN * nNormal ); - @end - - @insertpiece( DoDirectionalShadowMaps ) - -@end @property( hlms_use_prepass ) - ivec2 iFragCoord = ivec2( gl_FragCoord.x, - @property( !hlms_forwardplus_flipY )passBuf.windowHeight.x - @end - gl_FragCoord.y ); - - @property( hlms_use_prepass_msaa ) - //SV_Coverage/gl_SampleMaskIn is always before depth & stencil tests, - //so we need to perform the test ourselves - //See http://www.yosoygames.com.ar/wp/2017/02/beware-of-sv_coverage/ - float msaaDepth; - int subsampleDepthMask; - float pixelDepthZ; - float pixelDepthW; - float pixelDepth; - int intPixelDepth; - int intMsaaDepth; - //Unfortunately there are precision errors, so we allow some ulp errors. - //200 & 5 are arbitrary, but were empirically found to be very good values. - int ulpError = int( lerp( 200.0, 5.0, gl_FragCoord.z ) ); - @foreach( hlms_use_prepass_msaa, n ) - pixelDepthZ = interpolateAtSample( inPs.zwDepth.x, @n ); - pixelDepthW = interpolateAtSample( inPs.zwDepth.y, @n ); - pixelDepth = pixelDepthZ / pixelDepthW; - msaaDepth = texelFetch( gBuf_depthTexture, iFragCoord.xy, @n ); - intPixelDepth = floatBitsToInt( pixelDepth ); - intMsaaDepth = floatBitsToInt( msaaDepth ); - subsampleDepthMask = int( (abs( intPixelDepth - intMsaaDepth ) <= ulpError) ? 0xffffffffu : ~(1u << @nu) ); - //subsampleDepthMask = int( (pixelDepth <= msaaDepth) ? 0xffffffffu : ~(1u << @nu) ); - gl_SampleMaskIn &= subsampleDepthMask; - @end - - gl_SampleMaskIn[0] = gl_SampleMaskIn[0] == 0u ? 1u : gl_SampleMaskIn[0]; - - int gBufSubsample = findLSB( gl_SampleMaskIn[0] ); - @end @property( !hlms_use_prepass_msaa ) - //On non-msaa RTTs gBufSubsample is the LOD level. - int gBufSubsample = 0; - @end - - nNormal = normalize( texelFetch( gBuf_normals, iFragCoord, gBufSubsample ).xyz * 2.0 - 1.0 ); - vec2 shadowRoughness = texelFetch( gBuf_shadowRoughness, iFragCoord, gBufSubsample ).xy; - - float fShadow = shadowRoughness.x; - - @property( roughness_map ) - ROUGHNESS = shadowRoughness.y * 0.98 + 0.02; /// ROUGHNESS is a constant otherwise - @end -@end - -@property( !hlms_prepass ) - //Everything's in Camera space -@property( hlms_lights_spot || use_envprobe_map || hlms_use_ssr || use_planar_reflections || ambient_hemisphere || hlms_forwardplus ) - vec3 viewDir = normalize( -inPs.pos ); - float NdotV = clamp( dot( nNormal, viewDir ), 0.0, 1.0 ); -@end - -@property( !ambient_fixed ) - vec3 finalColour = vec3(0); -@end @property( ambient_fixed ) - vec3 finalColour = passBuf.ambientUpperHemi.xyz * @insertpiece( kD ).xyz; -@end - - @insertpiece( custom_ps_preLights ) - -@property( !custom_disable_directional_lights ) -@property( hlms_lights_directional ) - @insertpiece( ObjLightMaskCmp ) - finalColour += BRDF( passBuf.lights[0].position.xyz, viewDir, NdotV, passBuf.lights[0].diffuse, passBuf.lights[0].specular ) @insertpiece(DarkenWithShadowFirstLight); -@end -@foreach( hlms_lights_directional, n, 1 ) - @insertpiece( ObjLightMaskCmp ) - finalColour += BRDF( passBuf.lights[@n].position.xyz, viewDir, NdotV, passBuf.lights[@n].diffuse, passBuf.lights[@n].specular )@insertpiece( DarkenWithShadow );@end -@foreach( hlms_lights_directional_non_caster, n, hlms_lights_directional ) - @insertpiece( ObjLightMaskCmp ) - finalColour += BRDF( passBuf.lights[@n].position.xyz, viewDir, NdotV, passBuf.lights[@n].diffuse, passBuf.lights[@n].specular );@end -@end - -@property( hlms_lights_point || hlms_lights_spot || hlms_lights_area_approx || hlms_lights_area_ltc ) vec3 lightDir; - float fDistance; - vec3 tmpColour; - float spotCosAngle;@end - - //Point lights -@foreach( hlms_lights_point, n, hlms_lights_directional_non_caster ) - lightDir = passBuf.lights[@n].position.xyz - inPs.pos; - fDistance= length( lightDir ); - if( fDistance <= passBuf.lights[@n].attenuation.x @insertpiece( andObjLightMaskCmp ) ) - { - lightDir *= 1.0 / fDistance; - tmpColour = BRDF( lightDir, viewDir, NdotV, passBuf.lights[@n].diffuse, passBuf.lights[@n].specular )@insertpiece( DarkenWithShadowPoint ); - float atten = 1.0 / (0.5 + (passBuf.lights[@n].attenuation.y + passBuf.lights[@n].attenuation.z * fDistance) * fDistance ); - finalColour += tmpColour * atten; - }@end - - //Spot lights - //spotParams[@value(spot_params)].x = 1.0 / cos( InnerAngle ) - cos( OuterAngle ) - //spotParams[@value(spot_params)].y = cos( OuterAngle / 2 ) - //spotParams[@value(spot_params)].z = falloff -@foreach( hlms_lights_spot, n, hlms_lights_point ) - lightDir = passBuf.lights[@n].position.xyz - inPs.pos; - fDistance= length( lightDir ); -@property( !hlms_lights_spot_textured ) spotCosAngle = dot( normalize( inPs.pos - passBuf.lights[@n].position.xyz ), passBuf.lights[@n].spotDirection.xyz );@end -@property( hlms_lights_spot_textured ) spotCosAngle = dot( normalize( inPs.pos - passBuf.lights[@n].position.xyz ), zAxis( passBuf.lights[@n].spotQuaternion ) );@end - if( fDistance <= passBuf.lights[@n].attenuation.x && spotCosAngle >= passBuf.lights[@n].spotParams.y @insertpiece( andObjLightMaskCmp ) ) - { - lightDir *= 1.0 / fDistance; - @property( hlms_lights_spot_textured ) - vec3 posInLightSpace = qmul( spotQuaternion[@value(spot_params)], inPs.pos ); - float spotAtten = texture( texSpotLight, normalize( posInLightSpace ).xy ).x; - @end - @property( !hlms_lights_spot_textured ) - float spotAtten = clamp( (spotCosAngle - passBuf.lights[@n].spotParams.y) * passBuf.lights[@n].spotParams.x, 0.0, 1.0 ); - spotAtten = pow( spotAtten, passBuf.lights[@n].spotParams.z ); - @end - tmpColour = BRDF( lightDir, viewDir, NdotV, passBuf.lights[@n].diffuse, passBuf.lights[@n].specular )@insertpiece( DarkenWithShadow ); - float atten = 1.0 / (0.5 + (passBuf.lights[@n].attenuation.y + passBuf.lights[@n].attenuation.z * fDistance) * fDistance ); - finalColour += tmpColour * (atten * spotAtten); - }@end - - //Custom 2D shape lights - @insertpiece( DoAreaApproxLights ) - @insertpiece( DoAreaLtcLights ) - -@insertpiece( forward3dLighting ) -@insertpiece( applyIrradianceVolumes ) - -@property( emissive_map || emissive_constant ) - @insertpiece( SampleEmissiveMap ) - finalColour += emissiveCol.xyz; -@end - -@property( use_envprobe_map || hlms_use_ssr || use_planar_reflections || ambient_hemisphere ) - vec3 reflDir = 2.0 * dot( viewDir, nNormal ) * nNormal - viewDir; - - @property( use_envprobe_map ) - @property( use_parallax_correct_cubemaps ) - vec3 envColourS; - vec3 envColourD; - vec3 posInProbSpace = toProbeLocalSpace( inPs.pos, @insertpiece( pccProbeSource ) ); - float probeFade = getProbeFade( posInProbSpace, @insertpiece( pccProbeSource ) ); - if( probeFade > 0 ) - { - vec3 reflDirLS = localCorrect( reflDir, posInProbSpace, @insertpiece( pccProbeSource ) ); - vec3 nNormalLS = localCorrect( nNormal, posInProbSpace, @insertpiece( pccProbeSource ) ); - envColourS = textureLod( texEnvProbeMap, - reflDirLS, ROUGHNESS * 12.0 ).xyz @insertpiece( ApplyEnvMapScale );// * 0.0152587890625; - envColourD = textureLod( texEnvProbeMap, - nNormalLS, 11.0 ).xyz @insertpiece( ApplyEnvMapScale );// * 0.0152587890625; - - envColourS = envColourS * clamp( probeFade * 200.0, 0.0, 1.0 ); - envColourD = envColourD * clamp( probeFade * 200.0, 0.0, 1.0 ); - } - else - { - //TODO: Fallback to a global cubemap. - envColourS = vec3( 0, 0, 0 ); - envColourD = vec3( 0, 0, 0 ); - } - @end @property( !use_parallax_correct_cubemaps ) - vec3 envColourS = textureLod( texEnvProbeMap, reflDir * passBuf.invViewMatCubemap, ROUGHNESS * 12.0 ).xyz @insertpiece( ApplyEnvMapScale );// * 0.0152587890625; - vec3 envColourD = textureLod( texEnvProbeMap, nNormal * passBuf.invViewMatCubemap, 11.0 ).xyz @insertpiece( ApplyEnvMapScale );// * 0.0152587890625; - @end - @property( !hw_gamma_read ) //Gamma to linear space - envColourS = envColourS * envColourS; - envColourD = envColourD * envColourD; - @end - @end - - @property( hlms_use_ssr ) - //TODO: SSR pass should be able to combine global & local cubemap. - vec4 ssrReflection = texelFetch( ssrTexture, iFragCoord, 0 ).xyzw; - @property( use_envprobe_map ) - envColourS = mix( envColourS.xyz, ssrReflection.xyz, ssrReflection.w ); - @end @property( !use_envprobe_map ) - vec3 envColourS = ssrReflection.xyz * ssrReflection.w; - vec3 envColourD = vec3( 0, 0, 0 ); - @end - @end - - @insertpiece( DoPlanarReflectionsPS ) - - @property( ambient_hemisphere ) - float ambientWD = dot( passBuf.ambientHemisphereDir.xyz, nNormal ) * 0.5 + 0.5; - float ambientWS = dot( passBuf.ambientHemisphereDir.xyz, reflDir ) * 0.5 + 0.5; - - @property( use_envprobe_map || hlms_use_ssr || use_planar_reflections ) - envColourS += mix( passBuf.ambientLowerHemi.xyz, passBuf.ambientUpperHemi.xyz, ambientWD ); - envColourD += mix( passBuf.ambientLowerHemi.xyz, passBuf.ambientUpperHemi.xyz, ambientWS ); - @end @property( !use_envprobe_map && !hlms_use_ssr && !use_planar_reflections ) - vec3 envColourS = mix( passBuf.ambientLowerHemi.xyz, passBuf.ambientUpperHemi.xyz, ambientWD ); - vec3 envColourD = mix( passBuf.ambientLowerHemi.xyz, passBuf.ambientUpperHemi.xyz, ambientWS ); - @end - @end - - @insertpiece( BRDF_EnvMap ) -@end -@end ///!hlms_prepass - -@property( !hlms_render_depth_only ) - @property( !hlms_prepass ) - @property( !hw_gamma_write ) - //Linear to Gamma space - outColour.xyz = sqrt( finalColour ); - @end @property( hw_gamma_write ) - outColour.xyz = finalColour; - @end - - @property( hlms_alphablend ) - @property( use_texture_alpha ) - outColour.w = material.F0.w * diffuseCol.w; - @end @property( !use_texture_alpha ) - outColour.w = material.F0.w; - @end - @end @property( !hlms_alphablend ) - outColour.w = 1.0;@end - - @end @property( !hlms_normal && !hlms_qtangent ) - outColour = vec4( 1.0, 1.0, 1.0, 1.0 ); - @end - - @property( debug_pssm_splits ) - outColour.xyz = mix( outColour.xyz, debugPssmSplit.xyz, 0.2f ); - @end - @end @property( hlms_prepass ) - outNormals = vec4( nNormal * 0.5 + 0.5, 1.0 ); - @property( hlms_pssm_splits ) - outShadowRoughness = vec2( fShadow, (ROUGHNESS - 0.02) * 1.02040816 ); - @end @property( !hlms_pssm_splits ) - outShadowRoughness = vec2( 1.0, (ROUGHNESS - 0.02) * 1.02040816 ); - @end - @end -@end - - @insertpiece( custom_ps_posExecution ) -} -@end -@property( hlms_shadowcaster ) - -@insertpiece( DeclShadowCasterMacros ) - -@property( alpha_test ) - Material material; - float diffuseCol; - @property( num_textures )uniform sampler2DArray textureMaps[@value( num_textures )];@end - @property( diffuse_map )uint diffuseIdx;@end - @property( detail_weight_map )uint weightMapIdx;@end - @foreach( 4, n ) - @property( detail_map@n )uint detailMapIdx@n;@end @end -@end - -@property( hlms_shadowcaster_point || exponential_shadow_maps ) - @insertpiece( PassDecl ) -@end - -void main() -{ - @insertpiece( custom_ps_preExecution ) - -@property( alpha_test ) - @property( !lower_gpu_overhead ) - uint materialId = instance.worldMaterialIdx[inPs.drawId].x & 0x1FFu; - material = materialArray.m[materialId]; - @end @property( lower_gpu_overhead ) - material = materialArray.m[0]; - @end -@property( diffuse_map ) diffuseIdx = material.indices0_3.x & 0x0000FFFFu;@end -@property( detail_weight_map ) weightMapIdx = material.indices0_3.z & 0x0000FFFFu;@end -@property( detail_map0 ) detailMapIdx0 = material.indices0_3.z >> 16u;@end -@property( detail_map1 ) detailMapIdx1 = material.indices0_3.w & 0x0000FFFFu;@end -@property( detail_map2 ) detailMapIdx2 = material.indices0_3.w >> 16u;@end -@property( detail_map3 ) detailMapIdx3 = material.indices4_7.x & 0x0000FFFFu;@end - -@property( detail_maps_diffuse || detail_maps_normal ) - //Prepare weight map for the detail maps. - @property( detail_weight_map ) - vec4 detailWeights = @insertpiece( SamplerDetailWeightMap ); - @property( detail_weights )detailWeights *= material.cDetailWeights;@end - @end @property( !detail_weight_map ) - @property( detail_weights )vec4 detailWeights = material.cDetailWeights;@end - @property( !detail_weights )vec4 detailWeights = vec4( 1.0, 1.0, 1.0, 1.0 );@end - @end -@end - - /// Sample detail maps and weight them against the weight map in the next foreach loop. -@foreach( detail_maps_diffuse, n )@property( detail_map@n ) - float detailCol@n = texture( textureMaps[@value(detail_map@n_idx)], - vec3( UV_DETAIL@n( inPs.uv@value(uv_detail@n).xy@insertpiece( offsetDetail@n ) ), - detailMapIdx@n ) ).w; - detailCol@n = detailWeights.@insertpiece(detail_swizzle@n) * detailCol@n;@end -@end - -@insertpiece( SampleDiffuseMap ) - - /// 'insertpiece( SampleDiffuseMap )' must've written to diffuseCol. However if there are no - /// diffuse maps, we must initialize it to some value. If there are no diffuse or detail maps, - /// we must not access diffuseCol at all, but rather use material.kD directly (see piece( kD ) ). - @property( !diffuse_map )diffuseCol = material.bgDiffuse.w;@end - - /// Blend the detail diffuse maps with the main diffuse. -@foreach( detail_maps_diffuse, n ) - @insertpiece( blend_mode_idx@n ) @add( t, 1 ) @end - - /// Apply the material's alpha over the textures -@property( TODO_REFACTOR_ACCOUNT_MATERIAL_ALPHA ) diffuseCol.xyz *= material.kD.xyz;@end - - if( material.kD.w @insertpiece( alpha_test_cmp_func ) diffuseCol ) - discard; -@end /// !alpha_test - - @insertpiece( DoShadowCastPS ) - - @insertpiece( custom_ps_posExecution ) -} -@end diff --git a/Samples/Media/Hlms/Pbs/GLSLES/Structs_piece_vs_piece_ps.glsl b/Samples/Media/Hlms/Pbs/GLSLES/Structs_piece_vs_piece_ps.glsl deleted file mode 100644 index b6b5dfc43ea..00000000000 --- a/Samples/Media/Hlms/Pbs/GLSLES/Structs_piece_vs_piece_ps.glsl +++ /dev/null @@ -1,253 +0,0 @@ -@piece( PassDecl ) -struct ShadowReceiverData -{ - mat4 texViewProj; -@property( exponential_shadow_maps ) - vec4 texViewZRow; -@end - vec2 shadowDepthRange; - vec4 invShadowMapSize; -}; - -struct Light -{ - vec4 position; //.w contains the objLightMask - vec3 diffuse; - vec3 specular; -@property( hlms_num_shadow_map_lights ) - vec3 attenuation; - //Spotlights: - // spotDirection.xyz is direction - // spotParams.xyz contains falloff params - //Custom 2D Shape: - // spotDirection.xyz direction - // spotDirection.w customShapeHalfRectSize.x - // spotParams.xyz tangent - // spotParams.w customShapeHalfRectSize.y - vec4 spotDirection; - vec4 spotParams; -@end -}; - -#define areaLightDiffuseMipmapStart areaApproxLights[0].diffuse.w -#define areaLightNumMipmapsSpecFactor areaApproxLights[0].specular.w - -struct AreaLight -{ - vec4 position; //.w contains the objLightMask - vec4 diffuse; //[0].w contains diffuse mipmap start - vec4 specular; //[0].w contains mipmap scale - vec4 attenuation; //.w contains texture array idx - //Custom 2D Shape: - // direction.xyz direction - // direction.w invHalfRectSize.x - // tangent.xyz tangent - // tangent.w invHalfRectSize.y - vec4 direction; - vec4 tangent; - vec4 doubleSided; -}; - -struct AreaLtcLight -{ - vec4 position; //.w contains the objLightMask - vec4 diffuse; //.w contains attenuation range - vec4 specular; //.w contains doubleSided - vec3 points[4]; -}; - -@insertpiece( DeclCubemapProbeStruct ) - -//Uniforms that change per pass -layout_constbuffer(binding = 0) uniform PassBuffer -{ - //Vertex shader (common to both receiver and casters) - mat4 viewProj; - -@property( hlms_global_clip_planes ) - vec4 clipPlane0; -@end - -@property( hlms_shadowcaster_point ) - vec4 cameraPosWS; //Camera position in world space -@end - -@property( !hlms_shadowcaster ) - //Vertex shader - mat4 view; - @property( hlms_num_shadow_map_lights )ShadowReceiverData shadowRcv[@value(hlms_num_shadow_map_lights)];@end - - //------------------------------------------------------------------------- - - //Pixel shader - mat3 invViewMatCubemap; - - -@property( hlms_use_prepass ) - vec4 windowHeight; -@end - -@property( ambient_hemisphere || ambient_fixed || envmap_scale ) - vec4 ambientUpperHemi; -@end -@property( ambient_hemisphere ) - vec4 ambientLowerHemi; - vec4 ambientHemisphereDir; -@end - -@property( irradiance_volumes ) - vec4 irradianceOrigin; //.w = maxPower - vec4 irradianceSize; //.w = 1.0f / irradianceTexture->getHeight() - mat4 invView; -@end - -@property( hlms_pssm_splits )@psub( hlms_pssm_splits_minus_one, hlms_pssm_splits, 1 )@foreach( hlms_pssm_splits, n ) - float pssmSplitPoints@n;@end @end -@property( hlms_pssm_blend )@foreach( hlms_pssm_splits_minus_one, n ) - float pssmBlendPoints@n;@end @end -@property( hlms_pssm_fade ) - float pssmFadePoint;@end - @property( hlms_lights_spot )Light lights[@value(hlms_lights_spot)];@end - @property( hlms_lights_area_approx )AreaLight areaApproxLights[@value(hlms_lights_area_approx)];@end - @property( hlms_lights_area_ltc )AreaLtcLight areaLtcLights[@value(hlms_lights_area_ltc)];@end -@end @property( hlms_shadowcaster ) - //Vertex shader - @property( exponential_shadow_maps )vec4 viewZRow;@end - vec2 depthRange; -@end - -@property( hlms_forwardplus ) - //Forward3D - //f3dData.x = minDistance; - //f3dData.y = invMaxDistance; - //f3dData.z = f3dNumSlicesSub1; - //f3dData.w = uint cellsPerTableOnGrid0 (floatBitsToUint); - - //Clustered Forward: - //f3dData.x = minDistance; - //f3dData.y = invExponentK; - //f3dData.z = f3dNumSlicesSub1; - //f3dData.w = renderWindow->getHeight(); - vec4 f3dData; - @property( hlms_forwardplus == forward3d ) - vec4 f3dGridHWW[@value( forward3d_num_slices )]; - vec4 f3dViewportOffset; - @end - @property( hlms_forwardplus != forward3d ) - vec4 fwdScreenToGrid; - @end -@end - - @insertpiece( DeclPlanarReflUniforms ) - -@property( parallax_correct_cubemaps ) - CubemapProbe autoProbe; -@end - - @insertpiece( custom_passBuffer ) -} passBuf; -@end - -@property( fresnel_scalar )@piece( FresnelType )vec3@end @piece( FresnelSwizzle )xyz@end @end -@property( !fresnel_scalar )@piece( FresnelType )float@end @piece( FresnelSwizzle )x@end @end - -@piece( MaterialDecl ) -//Uniforms that change per Item/Entity, but change very infrequently -struct Material -{ - /* kD is already divided by PI to make it energy conserving. - (formula is finalDiffuse = NdotL * surfaceDiffuse / PI) - */ - vec4 bgDiffuse; - vec4 kD; //kD.w is alpha_test_threshold - vec4 kS; //kS.w is roughness - //Fresnel coefficient, may be per colour component (vec3) or scalar (float) - //F0.w is transparency - vec4 F0; - vec4 normalWeights; - vec4 cDetailWeights; - vec4 detailOffsetScale[4]; - vec4 emissive; //emissive.w contains mNormalMapWeight. - vec4 userValue[3]; - - uvec4 indices0_3; - uvec4 indices4_7; - - @insertpiece( custom_materialBuffer ) -}; - -layout_constbuffer(binding = 1) uniform MaterialBuf -{ - Material m[@value( materials_per_buffer )]; -} materialArray; -@end - -@piece( InstanceDecl ) -//Uniforms that change per Item/Entity -layout_constbuffer(binding = 2) uniform InstanceBuffer -{ - //.x = - //The lower 9 bits contain the material's start index. - //The higher 23 bits contain the world matrix start index. - // - //.y = - //shadowConstantBias. Send the bias directly to avoid an - //unnecessary indirection during the shadow mapping pass. - //Must be loaded with uintBitsToFloat - // - //.z = - //lightMask. Ogre must have been compiled with OGRE_NO_FINE_LIGHT_MASK_GRANULARITY - uvec4 worldMaterialIdx[1024]; -} instance; -@end - -@property( envprobe_map && envprobe_map != target_envprobe_map && use_parallax_correct_cubemaps ) -@piece( PccManualProbeDecl ) -layout_constbuffer(binding = 3) uniform ManualProbe -{ - CubemapProbe probe; -} manualProbe; -@end -@end - -@piece( VStoPS_block ) - @property( !hlms_shadowcaster ) - @property( !lower_gpu_overhead ) - flat uint drawId; - @end - @property( hlms_normal || hlms_qtangent ) - vec3 pos; - vec3 normal; - @property( normal_map )vec3 tangent; - @property( hlms_qtangent )flat float biNormalReflection;@end - @end - @end - @foreach( hlms_uv_count, n ) - vec@value( hlms_uv_count@n ) uv@n;@end - - @foreach( hlms_num_shadow_map_lights, n ) - @property( !hlms_shadowmap@n_is_point_light ) - vec4 posL@n;@end @end - @property( hlms_pssm_splits )float depth;@end - @property( hlms_use_prepass_msaa > 1 ) - float2 zwDepth; - @end - @end - @property( hlms_shadowcaster ) - @property( alpha_test ) - flat uint drawId; - @foreach( hlms_uv_count, n ) - vec@value( hlms_uv_count@n ) uv@n;@end - @end - @property( (!hlms_shadow_uses_depth_texture || exponential_shadow_maps) && !hlms_shadowcaster_point ) - float depth; - @end - @property( hlms_shadowcaster_point ) - vec3 toCameraWS; - @property( !exponential_shadow_maps ) - flat float constBias; - @end - @end - @end - @insertpiece( custom_VStoPS ) -@end diff --git a/Samples/Media/Hlms/Pbs/GLSLES/Textures_piece_ps.glsl b/Samples/Media/Hlms/Pbs/GLSLES/Textures_piece_ps.glsl deleted file mode 100644 index 32f7281b3b3..00000000000 --- a/Samples/Media/Hlms/Pbs/GLSLES/Textures_piece_ps.glsl +++ /dev/null @@ -1,140 +0,0 @@ -@property( diffuse_map ) - @property( !hlms_shadowcaster ) - @piece( SampleDiffuseMap ) diffuseCol = texture( textureMaps[@value( diffuse_map_idx )], - vec3( UV_DIFFUSE( inPs.uv@value(uv_diffuse).xy ), - diffuseIdx ) ); - @property( !hw_gamma_read ) diffuseCol = diffuseCol * diffuseCol;@end - @end - @end @property( hlms_shadowcaster ) - @piece( SampleDiffuseMap ) diffuseCol = texture( textureMaps[@value( diffuse_map_idx )], - vec3( UV_DIFFUSE( inPs.uv@value(uv_diffuse).xy ), - diffuseIdx ) ).w;@end - @end -@end - -//diffuseCol always has some colour and is multiplied against material.kD in PixelShader_ps. -@piece( kD )diffuseCol@end - -@property( !hlms_prepass ) -@property( !metallic_workflow ) - @property( specular_map && !fresnel_workflow ) - @piece( SampleSpecularMap ) - specularCol = texture( textureMaps[@value( specular_map_idx )], - vec3( UV_SPECULAR( inPs.uv@value(uv_specular).xy ), - specularIdx) ).xyz * material.kS.xyz; - @property( hlms_decals_diffuse ) - F0 = material.F0.@insertpiece( FresnelSwizzle ); - @end - @end - @piece( kS )specularCol@end - @end - @property( specular_map && fresnel_workflow ) - @piece( SampleSpecularMap ) - F0 = texture( textureMaps[@value( specular_map_idx )], - vec3( UV_SPECULAR( inPs.uv@value(uv_specular).xy ), - specularIdx) ).@insertpiece( FresnelSwizzle ) * material.F0.@insertpiece( FresnelSwizzle ); - @property( hlms_decals_diffuse ) - specularCol.xyz = material.kS.xyz; - @end - @end - @end - @property( !specular_map || fresnel_workflow ) - @property( !hlms_decals_diffuse ) - @piece( kS )material.kS@end - @end - @property( hlms_decals_diffuse ) - @property( !specular_map ) - //We'll need write access to F0 & specularCol - @piece( SampleSpecularMap ) - F0 = material.F0.@insertpiece( FresnelSwizzle ); - specularCol.xyz = material.kS.xyz; - @end - @end - @piece( kS )specularCol@end - @end - @end -@end -@property( metallic_workflow ) - @piece( SampleSpecularMap ) - @property( specular_map ) - float metalness = texture( textureMaps[@value( specular_map_idx )], - vec3( UV_SPECULAR( inPs.uv@value(uv_specular).xy ), - specularIdx) ).x * material.F0.x; - F0 = mix( vec3( 0.03f ), @insertpiece( kD ).xyz * 3.14159f, metalness ); - @insertpiece( kD ).xyz = @insertpiece( kD ).xyz - @insertpiece( kD ).xyz * metalness; - @end @property( !specular_map ) - F0 = mix( vec3( 0.03f ), @insertpiece( kD ).xyz * 3.14159f, material.F0.x ); - @insertpiece( kD ).xyz = @insertpiece( kD ).xyz - @insertpiece( kD ).xyz * material.F0.x; - @end - @property( hlms_alphablend )F0 *= material.F0.w;@end - @property( transparent_mode )F0 *= diffuseCol.w;@end - @property( hlms_decals_diffuse )specularCol.xyz = material.kS.xyz;@end - @end /// SampleSpecularMap - - @property( !hlms_decals_diffuse ) - @piece( kS )material.kS.xyz@end - @end - @property( hlms_decals_diffuse ) - @piece( kS )specularCol@end - @end -@end -@end - -@property( roughness_map ) - @piece( SampleRoughnessMap ) - ROUGHNESS = material.kS.w * texture( textureMaps[@value( roughness_map_idx )], - vec3( UV_ROUGHNESS( inPs.uv@value(uv_roughness).xy ), - roughnessIdx) ).x; - ROUGHNESS = max( ROUGHNESS, 0.001f ); - @end -@end -@property( !roughness_map && hlms_decals_diffuse ) - //We'll need write access to ROUGHNESS - @piece( SampleRoughnessMap )ROUGHNESS = material.kS.w;@end -@end - -@foreach( detail_maps_normal, n ) - @piece( SampleDetailMapNm@n )getTSDetailNormal( textureMaps[@value(detail_map_nm@n_idx)], - vec3( UV_DETAIL_NM@n( inPs.uv@value(uv_detail_nm@n).xy@insertpiece( offsetDetail@n ) ), - detailNormMapIdx@n ) ) * detailWeights.@insertpiece(detail_swizzle@n) - @insertpiece( detail@n_nm_weight_mul )@end -@end - -@property( detail_weight_map ) - @piece( SamplerDetailWeightMap )texture( textureMaps[@value(detail_weight_map_idx)], - vec3( UV_DETAIL_WEIGHT( inPs.uv@value(uv_detail_weight).xy ), weightMapIdx) )@end -@end - -@property( envmap_scale ) - @piece( ApplyEnvMapScale )* passBuf.ambientUpperHemi.w@end -@end - -@property( (envprobe_map && envprobe_map != target_envprobe_map) || parallax_correct_cubemaps ) - @set( use_envprobe_map, 1 ) - - @property( !envprobe_map || envprobe_map == target_envprobe_map ) - /// "No cubemap"? Then we're in auto mode or... - /// We're rendering to the cubemap probe we're using as manual. Use the auto mode as fallback. - @piece( pccProbeSource )passBuf.autoProbe@end - @set( use_parallax_correct_cubemaps, 1 ) - @end - @property( envprobe_map && envprobe_map != target_envprobe_map && use_parallax_correct_cubemaps ) - @piece( pccProbeSource )manualProbe.probe@end - @end -@end - -@property( emissive_map ) - @piece( SampleEmissiveMap ) - vec3 emissiveCol = texture( textureMaps[@value( emissive_map_idx )], - vec3( UV_EMISSIVE( inPs.uv@value(uv_emissive).xy ), - emissiveMapIdx ) ).xyz; - @property( emissive_constant ) - emissiveCol *= material.emissive.xyz; - @end - @end -@end -@property( !emissive_map && emissive_constant ) - @piece( SampleEmissiveMap ) - vec3 emissiveCol = material.emissive.xyz; - @end -@end diff --git a/Samples/Media/Hlms/Pbs/GLSLES/VertexShader_vs.glsl b/Samples/Media/Hlms/Pbs/GLSLES/VertexShader_vs.glsl deleted file mode 100644 index 38b8b022e30..00000000000 --- a/Samples/Media/Hlms/Pbs/GLSLES/VertexShader_vs.glsl +++ /dev/null @@ -1,294 +0,0 @@ -@insertpiece( SetCrossPlatformSettings ) -@insertpiece( SetCompatibilityLayer ) - -@property( GL3+ ) -out gl_PerVertex -{ - vec4 gl_Position; -@property( hlms_global_clip_planes ) - float gl_ClipDistance[@value(hlms_global_clip_planes)]; -@end -}; -@end - -layout(std140) uniform; - -@insertpiece( Common_Matrix_DeclUnpackMatrix4x4 ) -@insertpiece( Common_Matrix_DeclUnpackMatrix3x4 ) - -in vec4 vertex; - -@property( hlms_normal )in vec3 normal;@end -@property( hlms_qtangent )in vec4 qtangent;@end - -@property( normal_map && !hlms_qtangent ) -in vec3 tangent; -@property( hlms_binormal )in vec3 binormal;@end -@end - -@property( hlms_skeleton ) -in uvec4 blendIndices; -in vec4 blendWeights;@end - -@foreach( hlms_uv_count, n ) -in vec@value( hlms_uv_count@n ) uv@n;@end - -@property( GL_ARB_base_instance ) - in uint drawId; -@end - -@insertpiece( custom_vs_attributes ) - -@property( !hlms_shadowcaster || !hlms_shadow_uses_depth_texture || alpha_test || exponential_shadow_maps ) -out block -{ -@insertpiece( VStoPS_block ) -} outVs; -@end - -// START UNIFORM DECLARATION -@insertpiece( PassDecl ) -@property( hlms_skeleton || hlms_shadowcaster || hlms_pose )@insertpiece( InstanceDecl )@end -/*layout(binding = 0) */uniform samplerBuffer worldMatBuf; -@insertpiece( custom_vs_uniformDeclaration ) -@property( !GL_ARB_base_instance )uniform uint baseInstance;@end -@property( hlms_pose ) - uniform samplerBuffer poseBuf; -@end -// END UNIFORM DECLARATION - -@property( hlms_qtangent ) -@insertpiece( DeclQuat_xAxis ) -@property( normal_map ) -@insertpiece( DeclQuat_yAxis ) -@end @end - -@property( !hlms_pose ) -@piece( input_vertex )vertex@end -@end -@property( hlms_pose ) -@piece( input_vertex )inputPos@end -@end - -@property( !hlms_pose_normals ) -@piece( input_normal )normal@end -@end -@property( hlms_pose_normals ) -@piece( input_normal )inputNormal@end -@end - -@property( !hlms_skeleton ) -@piece( local_vertex )@insertpiece( input_vertex )@end -@piece( local_normal )@insertpiece( input_normal )@end -@piece( local_tangent )tangent@end -@end -@property( hlms_skeleton ) -@piece( local_vertex )worldPos@end -@piece( local_normal )worldNorm@end -@piece( local_tangent )worldTang@end -@end - -@property( hlms_skeleton )@piece( SkeletonTransform ) - uint _idx = (blendIndices[0] << 1u) + blendIndices[0]; //blendIndices[0] * 3u; a 32-bit int multiply is 4 cycles on GCN! (and mul24 is not exposed to GLSL...) - uint matStart = instance.worldMaterialIdx[drawId].x >> 9u; - vec4 worldMat[3]; - worldMat[0] = bufferFetch( worldMatBuf, int(matStart + _idx + 0u) ); - worldMat[1] = bufferFetch( worldMatBuf, int(matStart + _idx + 1u) ); - worldMat[2] = bufferFetch( worldMatBuf, int(matStart + _idx + 2u) ); - vec4 worldPos; - worldPos.x = dot( worldMat[0], @insertpiece( input_vertex ) ); - worldPos.y = dot( worldMat[1], @insertpiece( input_vertex ) ); - worldPos.z = dot( worldMat[2], @insertpiece( input_vertex ) ); - worldPos.xyz *= blendWeights[0]; - @property( hlms_normal || hlms_qtangent )vec3 worldNorm; - worldNorm.x = dot( worldMat[0].xyz, @insertpiece( input_normal ) ); - worldNorm.y = dot( worldMat[1].xyz, @insertpiece( input_normal ) ); - worldNorm.z = dot( worldMat[2].xyz, @insertpiece( input_normal ) ); - worldNorm *= blendWeights[0];@end - @property( normal_map )vec3 worldTang; - worldTang.x = dot( worldMat[0].xyz, tangent ); - worldTang.y = dot( worldMat[1].xyz, tangent ); - worldTang.z = dot( worldMat[2].xyz, tangent ); - worldTang *= blendWeights[0];@end - - @psub( NeedsMoreThan1BonePerVertex, hlms_bones_per_vertex, 1 ) - @property( NeedsMoreThan1BonePerVertex )vec4 tmp; - tmp.w = 1.0;@end //!NeedsMoreThan1BonePerVertex - @foreach( hlms_bones_per_vertex, n, 1 ) - _idx = (blendIndices[@n] << 1u) + blendIndices[@n]; //blendIndices[@n] * 3; a 32-bit int multiply is 4 cycles on GCN! (and mul24 is not exposed to GLSL...) - worldMat[0] = bufferFetch( worldMatBuf, int(matStart + _idx + 0u) ); - worldMat[1] = bufferFetch( worldMatBuf, int(matStart + _idx + 1u) ); - worldMat[2] = bufferFetch( worldMatBuf, int(matStart + _idx + 2u) ); - tmp.x = dot( worldMat[0], @insertpiece( input_vertex ) ); - tmp.y = dot( worldMat[1], @insertpiece( input_vertex ) ); - tmp.z = dot( worldMat[2], @insertpiece( input_vertex ) ); - worldPos.xyz += (tmp * blendWeights[@n]).xyz; - @property( hlms_normal || hlms_qtangent ) - tmp.x = dot( worldMat[0].xyz, @insertpiece( input_normal ) ); - tmp.y = dot( worldMat[1].xyz, @insertpiece( input_normal ) ); - tmp.z = dot( worldMat[2].xyz, @insertpiece( input_normal ) ); - worldNorm += tmp.xyz * blendWeights[@n];@end - @property( normal_map ) - tmp.x = dot( worldMat[0].xyz, tangent ); - tmp.y = dot( worldMat[1].xyz, tangent ); - tmp.z = dot( worldMat[2].xyz, tangent ); - worldTang += tmp.xyz * blendWeights[@n];@end - @end - - worldPos.w = 1.0; -@end @end //SkeletonTransform // !hlms_skeleton - -@property( hlms_pose )@piece( PoseTransform ) - // Pose data starts after all 3x4 bone matrices - int poseDataStart = int(instance.worldMaterialIdx[drawId].x >> 9u) @property( hlms_skeleton ) + @value(hlms_bones_per_vertex) * 3@end ; - vec4 inputPos = vertex; - @property( hlms_pose_normals && (hlms_normal || hlms_qtangent) )vec3 inputNormal = normal;@end - - vec4 poseData = bufferFetch( worldMatBuf, poseDataStart ); - int baseVertexID = int(floatBitsToUint( poseData.x )); - int vertexID = gl_VertexID - baseVertexID; - - @psub( MoreThanOnePose, hlms_pose, 1 ) - @property( !MoreThanOnePose ) - vec4 poseWeights = bufferFetch( worldMatBuf, poseDataStart + 1 ); - vec4 posePos = bufferFetch( poseBuf, vertexID @property( hlms_pose_normals )<< 1@end ); - inputPos += posePos * poseWeights.x; - @property( hlms_pose_normals && (hlms_normal || hlms_qtangent) ) - vec4 poseNormal = bufferFetch( poseBuf, (vertexID << 1) + 1 ); - inputNormal += poseNormal.xyz * poseWeights.x; - @end - @pset( NumPoseWeightVectors, 1 ) - @end @property( MoreThanOnePose ) - // NumPoseWeightVectors = (hlms_pose / 4) + min(hlms_pose % 4, 1) - @pdiv( NumPoseWeightVectorsA, hlms_pose, 4 ) - @pmod( NumPoseWeightVectorsB, hlms_pose, 4 ) - @pmin( NumPoseWeightVectorsC, NumPoseWeightVectorsB, 1 ) - @padd( NumPoseWeightVectors, NumPoseWeightVectorsA, NumPoseWeightVectorsC) - int numVertices = int(floatBitsToUint( poseData.y )); - - @psub( MoreThanOnePoseWeightVector, NumPoseWeightVectors, 1) - @property( !MoreThanOnePoseWeightVector ) - vec4 poseWeights = bufferFetch( worldMatBuf, poseDataStart + 1 ); - @foreach( hlms_pose, n ) - inputPos += bufferFetch( poseBuf, (vertexID + numVertices * @n) @property( hlms_pose_normals )<< 1@end ) * poseWeights[@n]; - @property( hlms_pose_normals && (hlms_normal || hlms_qtangent) ) - inputNormal += bufferFetch( poseBuf, ((vertexID + numVertices * @n) << 1) + 1 ).xyz * poseWeights[@n]; - @end - @end - @end @property( MoreThanOnePoseWeightVector ) - float poseWeights[@value(NumPoseWeightVectors) * 4]; - @foreach( NumPoseWeightVectors, n) - vec4 weights@n = bufferFetch( worldMatBuf, poseDataStart + 1 + @n ); - poseWeights[@n * 4 + 0] = weights@n[0]; - poseWeights[@n * 4 + 1] = weights@n[1]; - poseWeights[@n * 4 + 2] = weights@n[2]; - poseWeights[@n * 4 + 3] = weights@n[3]; - @end - @foreach( hlms_pose, n ) - inputPos += bufferFetch( poseBuf, (vertexID + numVertices * @n) @property( hlms_pose_normals )<< 1@end ) * poseWeights[@n]; - @property( hlms_pose_normals && (hlms_normal || hlms_qtangent) ) - inputNormal += bufferFetch( poseBuf, ((vertexID + numVertices * @n) << 1) + 1 ).xyz * poseWeights[@n]; - @end - @end - @end - @end - - // If hlms_skeleton is defined the transforms will be provided by bones. - // If hlms_pose is not combined with hlms_skeleton the object's worldMat and worldView have to be set. - @property( !hlms_skeleton ) - vec4 worldMat[3]; - worldMat[0] = bufferFetch( worldMatBuf, poseDataStart + @value(NumPoseWeightVectors) + 1 ); - worldMat[1] = bufferFetch( worldMatBuf, poseDataStart + @value(NumPoseWeightVectors) + 2 ); - worldMat[2] = bufferFetch( worldMatBuf, poseDataStart + @value(NumPoseWeightVectors) + 3 ); - vec4 worldPos; - worldPos.x = dot( worldMat[0], inputPos ); - worldPos.y = dot( worldMat[1], inputPos ); - worldPos.z = dot( worldMat[2], inputPos ); - worldPos.w = 1.0; - - @property( hlms_normal || hlms_qtangent ) - @foreach( 4, n ) - vec4 row@n = bufferFetch( worldMatBuf, poseDataStart + @value(NumPoseWeightVectors) + 4 + @n ); @end - mat4 worldView = mat4( row0, row1, row2, row3 ); - @end - @end -@end @end // PoseTransform - -@property( hlms_skeleton ) - @piece( worldViewMat )passBuf.view@end -@end @property( !hlms_skeleton ) - @piece( worldViewMat )worldView@end -@end - -@piece( CalculatePsPos )(@insertpiece(local_vertex) * @insertpiece( worldViewMat )).xyz@end - -@piece( VertexTransform ) -@insertpiece( custom_vs_preTransform ) - //Lighting is in view space - @property( hlms_normal || hlms_qtangent )outVs.pos = @insertpiece( CalculatePsPos );@end - @property( hlms_normal || hlms_qtangent )outVs.normal = @insertpiece(local_normal) * mat3(@insertpiece( worldViewMat ));@end - @property( normal_map )outVs.tangent = @insertpiece(local_tangent) * mat3(@insertpiece( worldViewMat ));@end -@property( !hlms_dual_paraboloid_mapping ) - gl_Position = worldPos * passBuf.viewProj;@end -@property( hlms_dual_paraboloid_mapping ) - //Dual Paraboloid Mapping - gl_Position.w = 1.0f; - @property( hlms_normal || hlms_qtangent )gl_Position.xyz = outVs.pos;@end - @property( !hlms_normal && !hlms_qtangent )gl_Position.xyz = @insertpiece( CalculatePsPos );@end - float L = length( gl_Position.xyz ); - gl_Position.z += 1.0f; - gl_Position.xy /= gl_Position.z; - gl_Position.z = (L - NearPlane) / (FarPlane - NearPlane);@end -@end - -void main() -{ -@property( !GL_ARB_base_instance ) - uint drawId = baseInstance + uint( gl_InstanceID ); -@end - - @insertpiece( custom_vs_preExecution ) - -@property( !hlms_skeleton && !hlms_pose ) - - mat3x4 worldMat = UNPACK_MAT3x4( worldMatBuf, drawId @property( !hlms_shadowcaster )<< 1u@end ); - @property( hlms_normal || hlms_qtangent ) - mat4 worldView = UNPACK_MAT4( worldMatBuf, (drawId << 1u) + 1u ); - @end - - vec4 worldPos = vec4( (vertex * worldMat).xyz, 1.0f ); -@end - -@property( hlms_qtangent ) - //Decode qTangent to TBN with reflection - vec3 normal = xAxis( normalize( qtangent ) ); - @property( normal_map ) - vec3 tangent = yAxis( qtangent ); - outVs.biNormalReflection = sign( qtangent.w ); //We ensure in C++ qtangent.w is never 0 - @end -@end - - @insertpiece( PoseTransform ) - @insertpiece( SkeletonTransform ) - @insertpiece( VertexTransform ) - - @insertpiece( DoShadowReceiveVS ) - @insertpiece( DoShadowCasterVS ) - - /// hlms_uv_count will be 0 on shadow caster passes w/out alpha test -@foreach( hlms_uv_count, n ) - outVs.uv@n = uv@n;@end - -@property( (!hlms_shadowcaster || alpha_test) && !lower_gpu_overhead ) - outVs.drawId = drawId;@end - - @property( hlms_use_prepass_msaa > 1 ) - outVs.zwDepth.xy = outVs.gl_Position.zw; - @end - -@property( hlms_global_clip_planes ) - gl_ClipDistance[0] = dot( float4( worldPos.xyz, 1.0 ), passBuf.clipPlane0.xyzw ); -@end - - @insertpiece( custom_vs_posExecution ) -} diff --git a/Samples/Media/Hlms/Terra/GLSLES/PbsTerraShadows/PbsTerraShadows_piece_vs_piece_ps.glsl b/Samples/Media/Hlms/Terra/GLSLES/PbsTerraShadows/PbsTerraShadows_piece_vs_piece_ps.glsl deleted file mode 100644 index 0a13d01d647..00000000000 --- a/Samples/Media/Hlms/Terra/GLSLES/PbsTerraShadows/PbsTerraShadows_piece_vs_piece_ps.glsl +++ /dev/null @@ -1,38 +0,0 @@ -@property( !hlms_shadowcaster && terra_enabled ) - -@piece( custom_VStoPS ) - float terrainShadow; -@end - -/// Extra per-pass global data we need for applying our -/// shadows to regular objects, passed to all PBS shaders. -@piece( custom_passBuffer ) - vec4 terraOrigin; //Normalized. i.e. -terrainOrigin / terrainDimensions - //.xz = terrain 1.0 / XZ dimensions. - //.y = 1.0 / terrainHeight; - vec4 invTerraBounds; -@end - -/// Add the shadows' texture to the vertex shader -@piece( custom_vs_uniformDeclaration ) - uniform sampler2D terrainShadows; -@end - -/// Evaluate the shadow based on world XZ position & height in the vertex shader. -/// Doing it at the pixel shader level would be more accurate, but the difference -/// is barely noticeable, and slower -@piece( custom_vs_posExecution ) - vec3 terraShadowData = textureLod( terrainShadows, worldPos.xz * passBuf.invTerraBounds.xz + passBuf.terraOrigin.xz, 0 ).xyz; - float terraHeightWeight = worldPos.y * passBuf.invTerraBounds.y + passBuf.terraOrigin.y; - terraHeightWeight = (terraHeightWeight - terraShadowData.y) * terraShadowData.z * 1023.0; - outVs.terrainShadow = mix( terraShadowData.x, 1.0, clamp( terraHeightWeight, 0.0, 1.0 ) ); -@end - -@property( hlms_lights_directional ) - @piece( custom_ps_preLights )fShadow *= inPs.terrainShadow;@end -@end @property( !hlms_num_shadow_map_lights ) - @piece( custom_ps_preLights )float fShadow = inPs.terrainShadow;@end - @piece( DarkenWithShadowFirstLight )* fShadow@end -@end - -@end diff --git a/Samples/Media/Hlms/Terra/GLSLES/PixelShader_ps.glsl b/Samples/Media/Hlms/Terra/GLSLES/PixelShader_ps.glsl deleted file mode 100644 index a3068015869..00000000000 --- a/Samples/Media/Hlms/Terra/GLSLES/PixelShader_ps.glsl +++ /dev/null @@ -1,334 +0,0 @@ -@property( false ) -@insertpiece( SetCrossPlatformSettings ) -@insertpiece( SetCompatibilityLayer ) - -layout(std140) uniform; -#define FRAG_COLOR 0 -layout(location = FRAG_COLOR) out vec4 outColour; - -uniform sampler2D terrainNormals; - -in block -{ -@insertpiece( Terra_VStoPS_block ) -} inPs; - -void main() -{ - outColour = vec4( inPs.uv0.xy, 0.0, 1.0 ); -} - -@end -@property( !false ) -@insertpiece( SetCrossPlatformSettings ) -@property( GL3+ < 430 ) - @property( hlms_tex_gather )#extension GL_ARB_texture_gather: require@end -@end - -@property( hlms_amd_trinary_minmax )#extension GL_AMD_shader_trinary_minmax: require@end -@insertpiece( SetCompatibilityLayer ) - -layout(std140) uniform; -#define FRAG_COLOR 0 -layout(location = FRAG_COLOR) out vec4 outColour; - -@property( hlms_vpos ) -in vec4 gl_FragCoord; -@end - -// START UNIFORM DECLARATION -@insertpiece( PassDecl ) -@insertpiece( TerraMaterialDecl ) -@insertpiece( TerraInstanceDecl ) -@insertpiece( custom_ps_uniformDeclaration ) -// END UNIFORM DECLARATION -in block -{ -@insertpiece( Terra_VStoPS_block ) -} inPs; - -uniform sampler2D terrainNormals; -uniform sampler2D terrainShadows; - -@property( hlms_forwardplus ) -/*layout(binding = 1) */uniform usamplerBuffer f3dGrid; -/*layout(binding = 2) */uniform samplerBuffer f3dLightList; -@end -@property( num_textures )uniform sampler2DArray textureMaps[@value( num_textures )];@end -@property( envprobe_map )uniform samplerCube texEnvProbeMap;@end - -vec4 diffuseCol; -@insertpiece( FresnelType ) F0; -float ROUGHNESS; - -vec3 nNormal; - -@property( hlms_lights_spot_textured )@insertpiece( DeclQuat_zAxis ) -vec3 qmul( vec4 q, vec3 v ) -{ - return v + 2.0 * cross( cross( v, q.xyz ) + q.w * v, q.xyz ); -} -@end - -@property( detail_maps_normal )vec3 getTSDetailNormal( sampler2DArray normalMap, vec3 uv ) -{ - vec3 tsNormal; -@property( signed_int_textures ) - //Normal texture must be in U8V8 or BC5 format! - tsNormal.xy = texture( normalMap, uv ).xy; -@end @property( !signed_int_textures ) - //Normal texture must be in LA format! - tsNormal.xy = texture( normalMap, uv ).xw * 2.0 - 1.0; -@end - tsNormal.z = sqrt( max( 0.0, 1.0 - tsNormal.x * tsNormal.x - tsNormal.y * tsNormal.y ) ); - - return tsNormal; -} - @foreach( 4, n ) - @property( normal_weight_detail@n ) - @piece( detail@n_nm_weight_mul ) * material.normalWeights.@insertpiece( detail_swizzle@n )@end - @end - @end -@end - -@insertpiece( DeclareBRDF ) - -@insertpiece( DeclShadowMapMacros ) -@insertpiece( DeclShadowSamplers ) -@insertpiece( DeclShadowSamplingFuncs ) - -void main() -{ - @insertpiece( custom_ps_preExecution ) - - @insertpiece( custom_ps_posMaterialLoad ) - -//Prepare weight map for the detail maps. -@property( detail_weight_map ) - vec4 detailWeights = texture( textureMaps[@value( detail_weight_map_idx )], - vec3( inPs.uv0.xy, @value(detail_weight_map_idx_slice) ) ); -@end @property( !detail_weight_map ) - vec4 detailWeights = vec4( 1.0, 1.0, 1.0, 1.0 ); -@end - -@property( diffuse_map ) - diffuseCol = texture( textureMaps[@value( diffuse_map_idx )], vec3( inPs.uv0.xy, @value(diffuse_map_idx_slice) ) ); -@end - - /// Sample detail maps -@foreach( 4, n ) - @property( detail_map@n ) - vec3 detailCol@n = texture( textureMaps[@value(detail_map@n_idx)], - vec3( inPs.uv0.xy * material.detailOffsetScale[@value(currOffsetDetail)].zw + - material.detailOffsetScale[@value(currOffsetDetail)].xy, - @value(detail_map@n_idx_slice) ) ).xyz; - @end @property( !detail_map@n ) - vec3 detailCol@n = vec3( 0, 0, 0 ); - @end - - @property( metalness_map@n ) - float metalness@n = texture( textureMaps[@value( metalness_map@n_idx )], - vec3( inPs.uv0.xy * material.detailOffsetScale[@value(currOffsetDetail)].zw + - material.detailOffsetScale[@value(currOffsetDetail)].xy, - @value( metalness_map@n_idx_slice ) ) ).x; - @end @property( !metalness_map@n ) - float metalness@n = 0; - @end - - @property( roughness_map@n ) - float roughness@n = texture( textureMaps[@value( roughness_map@n_idx )], - vec3( inPs.uv0.xy * material.detailOffsetScale[@value(currOffsetDetail)].zw + - material.detailOffsetScale[@value(currOffsetDetail)].xy, - @value( roughness_map@n_idx_slice ) ) ).x; - @end @property( !roughness_map@n ) - float roughness@n = 0; - @end - - @add( currOffsetDetail, 1 ) -@end - - float metalness = (metalness0 * detailWeights.x * material.metalness.x + - metalness1 * detailWeights.y * material.metalness.y) + - (metalness2 * detailWeights.z * material.metalness.z + - metalness3 * detailWeights.w * material.metalness.w); - - ROUGHNESS = (roughness0 * detailWeights.x * material.roughness.x + - roughness1 * detailWeights.y * material.roughness.y) + - (roughness2 * detailWeights.z * material.roughness.z + - roughness3 * detailWeights.w * material.roughness.w); - ROUGHNESS = max( ROUGHNESS, 0.02 ); - -@property( diffuse_map ) - diffuseCol.xyz *= (detailCol0 * detailWeights.x + detailCol1 * detailWeights.y) + - (detailCol2 * detailWeights.z + detailCol3 * detailWeights.w); -@end @property( !diffuse_map ) - @property( detail_maps_diffuse ) - diffuseCol.xyz = (detailCol0 * detailWeights.x + detailCol1 * detailWeights.y) + - (detailCol2 * detailWeights.z + detailCol3 * detailWeights.w); - @end @property( !detail_maps_diffuse ) - diffuseCol.xyzw = vec4( 1, 1, 1, 1 ); - @end -@end - - /// Apply the material's diffuse over the textures - diffuseCol.xyz *= material.kD.xyz; - - //Calculate F0 from metalness, and dim kD as metalness gets bigger. - F0 = mix( vec3( 0.03f ), @insertpiece( kD ).xyz * 3.14159f, metalness ); - @insertpiece( kD ).xyz = @insertpiece( kD ).xyz - @insertpiece( kD ).xyz * metalness; - -@property( !detail_maps_normal ) - // Geometric normal - nNormal = texture( terrainNormals, inPs.uv0.xy ).xyz * 2.0 - 1.0; - //nNormal.xz = texture( terrainNormals, inPs.uv0.xy ).xy; - //nNormal.y = sqrt( max( 1.0 - nNormal.x * nNormal.x - nNormal.z * nNormal.z, 0.0 ) ); - nNormal = nNormal * mat3(passBuf.view); -@end @property( detail_maps_normal ) - vec3 geomNormal = texture( terrainNormals, inPs.uv0.xy ).xyz * 2.0 - 1.0; - geomNormal = geomNormal * mat3(passBuf.view); - - //Get the TBN matrix - vec3 viewSpaceUnitX = vec3( passBuf.view[0].x, passBuf.view[1].x, passBuf.view[2].x ); - vec3 vTangent = normalize( cross( geomNormal, viewSpaceUnitX ) ); - vec3 vBinormal = cross( vTangent, geomNormal ); - mat3 TBN = mat3( vBinormal, vTangent, geomNormal ); -@end - - float fTerrainShadow = texture( terrainShadows, inPs.uv0.xy ).x; - @property( !(hlms_pssm_splits || (!hlms_pssm_splits && hlms_num_shadow_map_lights && hlms_lights_directional)) ) - float fShadow = 1.0f; - @end - @insertpiece( DoDirectionalShadowMaps ) - fShadow *= fTerrainShadow; - - /// The first iteration must initialize nNormal instead of try to merge with it. - /// Blend the detail normal maps with the main normal. -@foreach( second_valid_detail_map_nm, n, first_valid_detail_map_nm ) - vec3 vDetail = @insertpiece( SampleDetailMapNm@n ) * detailWeights.@insertpiece(detail_swizzle@n); - nNormal.xy = vDetail.xy; - nNormal.z = vDetail.z + 1.0 - detailWeights.@insertpiece(detail_swizzle@n);@end -@foreach( detail_maps_normal, n, second_valid_detail_map_nm )@property( detail_map_nm@n ) - vDetail = @insertpiece( SampleDetailMapNm@n ) * detailWeights.@insertpiece(detail_swizzle@n); - nNormal.xy += vDetail.xy; - nNormal.z *= vDetail.z + 1.0 - detailWeights.@insertpiece(detail_swizzle@n);@end @end - -@property( detail_maps_normal ) - nNormal = normalize( TBN * nNormal ); -@end - - //Everything's in Camera space -@property( hlms_lights_spot || ambient_hemisphere || envprobe_map || hlms_forwardplus ) - vec3 viewDir = normalize( -inPs.pos ); - float NdotV = clamp( dot( nNormal, viewDir ), 0.0, 1.0 );@end - -@property( !ambient_fixed ) - vec3 finalColour = vec3(0); -@end @property( ambient_fixed ) - vec3 finalColour = passBuf.ambientUpperHemi.xyz * @insertpiece( kD ).xyz; -@end - - @insertpiece( custom_ps_preLights ) - -@property( !custom_disable_directional_lights ) -@property( hlms_lights_directional ) - finalColour += BRDF( passBuf.lights[0].position.xyz, viewDir, NdotV, passBuf.lights[0].diffuse, passBuf.lights[0].specular ) @insertpiece(DarkenWithShadowFirstLight); -@end -@foreach( hlms_lights_directional, n, 1 ) - finalColour += BRDF( passBuf.lights[@n].position.xyz, viewDir, NdotV, passBuf.lights[@n].diffuse, passBuf.lights[@n].specular )@insertpiece( DarkenWithShadow );@end -@foreach( hlms_lights_directional_non_caster, n, hlms_lights_directional ) - finalColour += BRDF( passBuf.lights[@n].position.xyz, viewDir, NdotV, passBuf.lights[@n].diffuse, passBuf.lights[@n].specular );@end -@end - -@property( hlms_lights_point || hlms_lights_spot ) vec3 lightDir; - float fDistance; - vec3 tmpColour; - float spotCosAngle;@end - - //Point lights -@foreach( hlms_lights_point, n, hlms_lights_directional_non_caster ) - lightDir = passBuf.lights[@n].position.xyz - inPs.pos; - fDistance= length( lightDir ); - if( fDistance <= passBuf.lights[@n].attenuation.x ) - { - lightDir *= 1.0 / fDistance; - tmpColour = BRDF( lightDir, viewDir, NdotV, passBuf.lights[@n].diffuse, passBuf.lights[@n].specular )@insertpiece( DarkenWithShadowPoint ); - float atten = 1.0 / (0.5 + (passBuf.lights[@n].attenuation.y + passBuf.lights[@n].attenuation.z * fDistance) * fDistance ); - finalColour += tmpColour * atten; - }@end - - //Spot lights - //spotParams[@value(spot_params)].x = 1.0 / cos( InnerAngle ) - cos( OuterAngle ) - //spotParams[@value(spot_params)].y = cos( OuterAngle / 2 ) - //spotParams[@value(spot_params)].z = falloff -@foreach( hlms_lights_spot, n, hlms_lights_point ) - lightDir = passBuf.lights[@n].position.xyz - inPs.pos; - fDistance= length( lightDir ); -@property( !hlms_lights_spot_textured ) spotCosAngle = dot( normalize( inPs.pos - passBuf.lights[@n].position.xyz ), passBuf.lights[@n].spotDirection );@end -@property( hlms_lights_spot_textured ) spotCosAngle = dot( normalize( inPs.pos - passBuf.lights[@n].position.xyz ), zAxis( passBuf.lights[@n].spotQuaternion ) );@end - if( fDistance <= passBuf.lights[@n].attenuation.x && spotCosAngle >= passBuf.lights[@n].spotParams.y ) - { - lightDir *= 1.0 / fDistance; - @property( hlms_lights_spot_textured ) - vec3 posInLightSpace = qmul( spotQuaternion[@value(spot_params)], inPs.pos ); - float spotAtten = texture( texSpotLight, normalize( posInLightSpace ).xy ).x; - @end - @property( !hlms_lights_spot_textured ) - float spotAtten = clamp( (spotCosAngle - passBuf.lights[@n].spotParams.y) * passBuf.lights[@n].spotParams.x, 0.0, 1.0 ); - spotAtten = pow( spotAtten, passBuf.lights[@n].spotParams.z ); - @end - tmpColour = BRDF( lightDir, viewDir, NdotV, passBuf.lights[@n].diffuse, passBuf.lights[@n].specular )@insertpiece( DarkenWithShadow ); - float atten = 1.0 / (0.5 + (passBuf.lights[@n].attenuation.y + passBuf.lights[@n].attenuation.z * fDistance) * fDistance ); - finalColour += tmpColour * (atten * spotAtten); - }@end - -@insertpiece( forward3dLighting ) - -@property( envprobe_map || ambient_hemisphere ) - vec3 reflDir = 2.0 * dot( viewDir, nNormal ) * nNormal - viewDir; - - @property( envprobe_map ) - vec3 envColourS = textureLod( texEnvProbeMap, reflDir * passBuf.invViewMatCubemap, ROUGHNESS * 12.0 ).xyz @insertpiece( ApplyEnvMapScale );// * 0.0152587890625; - vec3 envColourD = textureLod( texEnvProbeMap, nNormal * passBuf.invViewMatCubemap, 11.0 ).xyz @insertpiece( ApplyEnvMapScale );// * 0.0152587890625; - @property( !hw_gamma_read ) //Gamma to linear space - envColourS = envColourS * envColourS; - envColourD = envColourD * envColourD; - @end - @end - @property( ambient_hemisphere ) - float ambientWD = dot( passBuf.ambientHemisphereDir.xyz, nNormal ) * 0.5 + 0.5; - float ambientWS = dot( passBuf.ambientHemisphereDir.xyz, reflDir ) * 0.5 + 0.5; - - @property( envprobe_map ) - envColourS += mix( passBuf.ambientLowerHemi.xyz, passBuf.ambientUpperHemi.xyz, ambientWD ); - envColourD += mix( passBuf.ambientLowerHemi.xyz, passBuf.ambientUpperHemi.xyz, ambientWS ); - @end @property( !envprobe_map ) - vec3 envColourS = mix( passBuf.ambientLowerHemi.xyz, passBuf.ambientUpperHemi.xyz, ambientWD ); - vec3 envColourD = mix( passBuf.ambientLowerHemi.xyz, passBuf.ambientUpperHemi.xyz, ambientWS ); - @end - @end - - @insertpiece( BRDF_EnvMap ) -@end -@property( !hw_gamma_write ) - //Linear to Gamma space - outColour.xyz = sqrt( finalColour ); -@end @property( hw_gamma_write ) - outColour.xyz = finalColour; -@end - -@property( hlms_alphablend ) - @property( use_texture_alpha ) - outColour.w = material.F0.w * diffuseCol.w; - @end @property( !use_texture_alpha ) - outColour.w = material.F0.w; - @end -@end @property( !hlms_alphablend ) - outColour.w = 1.0;@end - - @property( debug_pssm_splits ) - outColour.xyz = mix( outColour.xyz, debugPssmSplit.xyz, 0.2f ); - @end - - @insertpiece( custom_ps_posExecution ) -} -@end diff --git a/Samples/Media/Hlms/Terra/GLSLES/Structs_piece_vs_piece_ps.glsl b/Samples/Media/Hlms/Terra/GLSLES/Structs_piece_vs_piece_ps.glsl deleted file mode 100644 index 21f7c4feac6..00000000000 --- a/Samples/Media/Hlms/Terra/GLSLES/Structs_piece_vs_piece_ps.glsl +++ /dev/null @@ -1,46 +0,0 @@ - -@piece( TerraMaterialDecl ) -layout_constbuffer(binding = 1) uniform MaterialBuf -{ - /* kD is already divided by PI to make it energy conserving. - (formula is finalDiffuse = NdotL * surfaceDiffuse / PI) - */ - vec4 kD; //kD.w is padding - vec4 roughness; - vec4 metalness; - vec4 detailOffsetScale[4]; - - @insertpiece( custom_materialBuffer ) -} material; -@end - -@piece( TerraInstanceDecl ) -struct CellData -{ - //.x = numVertsPerLine - //.y = lodLevel - //.z = vao->getPrimitiveCount() / m_verticesPerLine - 2u - //.w = skirtY (float) - uvec4 numVertsPerLine; - ivec4 xzTexPosBounds; //XZXZ - vec4 pos; //.w contains 1.0 / xzTexPosBounds.z - vec4 scale; //.w contains 1.0 / xzTexPosBounds.w -}; - -layout_constbuffer(binding = 2) uniform InstanceBuffer -{ - CellData cellData[256]; -} instance; -@end - -@piece( Terra_VStoPS_block ) - //flat uint drawId; - vec3 pos; - vec2 uv0; - - @foreach( hlms_num_shadow_map_lights, n ) - @property( !hlms_shadowmap@n_is_point_light ) - vec4 posL@n;@end @end - @property( hlms_pssm_splits )float depth;@end - @insertpiece( custom_VStoPS ) -@end diff --git a/Samples/Media/Hlms/Terra/GLSLES/Textures_piece_ps.glsl b/Samples/Media/Hlms/Terra/GLSLES/Textures_piece_ps.glsl deleted file mode 100644 index 5ae13440dfb..00000000000 --- a/Samples/Media/Hlms/Terra/GLSLES/Textures_piece_ps.glsl +++ /dev/null @@ -1,12 +0,0 @@ - -@undefpiece( kD ) -@piece( kD )diffuseCol@end - -@undefpiece( kS ) -@piece( kS )vec3( 1, 1, 1 )@end - -@foreach( detail_maps_normal, n ) - @undefpiece( SampleDetailMapNm@n ) - @piece( SampleDetailMapNm@n )getTSDetailNormal( textureMaps[@value(detail_map_nm@n_idx)], vec3( inPs.uv0.xy * material.detailOffsetScale[@n].zw + - material.detailOffsetScale[@n].xy , @value(detail_map_nm@n_idx_slice) ) )@end -@end diff --git a/Samples/Media/Hlms/Terra/GLSLES/VertexShader_vs.glsl b/Samples/Media/Hlms/Terra/GLSLES/VertexShader_vs.glsl deleted file mode 100644 index 2377a38b5e0..00000000000 --- a/Samples/Media/Hlms/Terra/GLSLES/VertexShader_vs.glsl +++ /dev/null @@ -1,126 +0,0 @@ -@insertpiece( SetCrossPlatformSettings ) -@insertpiece( SetCompatibilityLayer ) - -@property( GL3+ ) -out gl_PerVertex -{ - vec4 gl_Position; -}; -@end - -layout(std140) uniform; - -//To render a 2x2 (quads) terrain: -//You'll normally need 6 vertices per line + 2 for degenerates. -//You'll need 8 vertices per line. -//So you'll need a total of 16 vertices. - -//To render a 4x2 (quads) terrain: -//You'll need 10 vertices per line. -//If we include degenerate vertices, you'll need 12 per line -//So you'll need a total of 24 vertices. -//in int gl_VertexID; - -@property( GL_ARB_base_instance ) - in uint drawId; -@end - -@insertpiece( custom_vs_attributes ) - -out block -{ -@insertpiece( Terra_VStoPS_block ) -} outVs; - -// START UNIFORM DECLARATION -@insertpiece( PassDecl ) -@insertpiece( TerraInstanceDecl ) -uniform sampler2D heightMap; -@insertpiece( custom_vs_uniformDeclaration ) -@property( !GL_ARB_base_instance )uniform uint baseInstance;@end -// END UNIFORM DECLARATION - -@piece( VertexTransform ) - //Lighting is in view space - outVs.pos = ( vec4(worldPos.xyz, 1.0f) * passBuf.view ).xyz; -@property( !hlms_dual_paraboloid_mapping ) - gl_Position = vec4(worldPos.xyz, 1.0f) * passBuf.viewProj;@end -@property( hlms_dual_paraboloid_mapping ) - //Dual Paraboloid Mapping - gl_Position.w = 1.0f; - gl_Position.xyz = outVs.pos; - float L = length( gl_Position.xyz ); - gl_Position.z += 1.0f; - gl_Position.xy /= gl_Position.z; - gl_Position.z = (L - NearPlane) / (FarPlane - NearPlane);@end -@end - -void main() -{ -@property( !GL_ARB_base_instance ) - uint drawId = baseInstance + uint( gl_InstanceID ); -@end - - @insertpiece( custom_vs_preExecution ) - - CellData cellData = instance.cellData[drawId]; - - //Map pointInLine from range [0; 12) to range [0; 9] so that it reads: - // 0 0 1 2 3 4 5 6 7 8 9 9 - uint pointInLine = uint(gl_VertexID) % (cellData.numVertsPerLine.x); //cellData.numVertsPerLine.x = 12 - pointInLine = uint(clamp( int(pointInLine) - 1, 0, int(cellData.numVertsPerLine.x - 3u) )); - - uvec2 uVertexPos; - - uVertexPos.x = pointInLine >> 1u; - //Even numbers are the next line, odd numbers are current line. - uVertexPos.y = (pointInLine & 0x01u) == 0u ? 1u : 0u; - uVertexPos.y += uint(gl_VertexID) / cellData.numVertsPerLine.x; - //uVertexPos.y += floor( (float)gl_VertexID / (float)cellData.numVertsPerLine ); Could be faster on GCN. - -@property( use_skirts ) - //Apply skirt. - bool isSkirt =( pointInLine.x <= 1u || - pointInLine.x >= (cellData.numVertsPerLine.x - 4u) || - uVertexPos.y == 0u || - uVertexPos.y == (cellData.numVertsPerLine.z + 2u) ); - - //Now shift X position for the left & right skirts - uVertexPos.x = uint( max( int(uVertexPos.x) - 1, 0 ) ); - uVertexPos.x = min( uVertexPos.x, ((cellData.numVertsPerLine.x - 7u) >> 1u) ); - // uVertexPos.x becomes: - // 0 0 0 1 1 2 2 3 3 4 4 4 - // 0 0 0 0 0 1 1 2 2 3 3 3 - // 0 0 0 0 0 1 1 2 2 2 2 2 - - //Now shift Y position for the front & back skirts - uVertexPos.y = uint( max( int(uVertexPos.y) - 1, 0 ) ); - uVertexPos.y = min( uVertexPos.y, cellData.numVertsPerLine.z ); -@end - - uint lodLevel = cellData.numVertsPerLine.y; - uVertexPos = uVertexPos << lodLevel; - - uVertexPos.xy = uvec2( clamp( ivec2(uVertexPos.xy) + cellData.xzTexPosBounds.xy, - ivec2( 0, 0 ), cellData.xzTexPosBounds.zw ) ); - - vec3 worldPos; - worldPos.y = texelFetch( heightMap, ivec2( uVertexPos.xy ), 0 ).x; -@property( use_skirts ) - worldPos.y = isSkirt ? uintBitsToFloat(cellData.numVertsPerLine.w) : worldPos.y; -@end - worldPos.xz = uVertexPos.xy; - worldPos.xyz = worldPos.xyz * cellData.scale.xyz + cellData.pos.xyz; - - @insertpiece( VertexTransform ) - - outVs.uv0.xy = vec2( uVertexPos.xy ) * vec2( cellData.pos.w, cellData.scale.w ); - - @insertpiece( DoShadowReceiveVS ) - -@property( hlms_pssm_splits ) outVs.depth = gl_Position.z;@end - - //outVs.drawId = drawId; - - @insertpiece( custom_vs_posExecution ) -} diff --git a/Samples/Media/Hlms/Unlit/GLSLES/BlendModes_piece_ps.glsl b/Samples/Media/Hlms/Unlit/GLSLES/BlendModes_piece_ps.glsl deleted file mode 100644 index f70f16bf778..00000000000 --- a/Samples/Media/Hlms/Unlit/GLSLES/BlendModes_piece_ps.glsl +++ /dev/null @@ -1,137 +0,0 @@ -//Reset t to 0 just in case (values are preserved from previous stages) -@pset( t, 0 ) - -@piece( NormalNonPremul ) - //Normal Non Premultiplied @counter(t) - outColour.xyz = mix( outColour.xyz, topImage@value(t).xyz, topImage@value(t).a ); - outColour.w = mix( outColour.w, 1.0, topImage@value(t).w ); -@end - -@piece( NormalPremul ) - //Normal Premultiplied @counter(t) - outColour.xyz = (1.0 - topImage@value(t).a) * outColour.xyz + topImage@value(t).xyz; - outColour.w = mix( outColour.w, 1.0, topImage@value(t).w ); -@end - -@piece( Add ) - //Add @counter(t) - outColour.xyz = mix( outColour.xyz, - min( outColour.xyz + topImage@value(t).xyz, vec3(1.0) ), - topImage@value(t).a ); -@end - -@piece( Subtract ) - //Subtract @counter(t) - outColour.xyz = mix( outColour.xyz, - max( outColour.xyz - topImage@value(t).xyz, vec3(0.0) ), - topImage@value(t).a ); -@end - -@piece( Multiply ) - //Multiply @counter(t) - outColour.xyz = mix( outColour.xyz, - outColour.xyz * topImage@value(t).xyz, - topImage@value(t).a ); -@end - -@piece( Multiply2x ) - //Multiply2x @counter(t) - outColour.xyz = mix( outColour.xyz, - min( outColour.xyz * topImage@value(t).xyz * 2.0, vec3(1.0) ), - topImage@value(t).a ); -@end - -@piece( Screen ) - //Screen @counter(t) - outColour.xyz = mix( outColour.xyz, - 1.0 - (1.0 - outColour.xyz) * (1.0 - topImage@value(t).xyz), - topImage@value(t).a ); -@end - -@piece( Overlay ) - //Overlay @counter(t) - outColour.xyz = mix( outColour.xyz, - outColour.xyz * ( outColour.xyz + 2.0 * topImage@value(t).xyz * (1.0 - outColour.xyz) ), - topImage@value(t).a ); -@end - -@piece( Lighten ) - //Lighten @counter(t) - outColour.xyz = mix( outColour.xyz, - max( outColour.xyz, topImage@value(t).xyz ), - topImage@value(t).a ); -@end - -@piece( Darken ) - //Darken @counter(t) - outColour.xyz = mix( outColour.xyz, - min( outColour.xyz, topImage@value(t).xyz ), - topImage@value(t).a ); -@end - -@piece( GrainExtract ) - //GrainExtract @counter(t) - outColour.xyz = mix( outColour.xyz, - (outColour.xyz - topImage@value(t).xyz) + 0.5f, - topImage@value(t).a ); -@end - -@piece( GrainMerge ) - //GrainMerge @counter(t) - outColour.xyz = mix( outColour.xyz, - (outColour.xyz + topImage@value(t).xyz) - 0.5f, - topImage@value(t).a ); -@end - -@piece( Difference ) - //Difference @counter(t) - outColour.xyz = mix( outColour.xyz, - abs(outColour.xyz - topImage@value(t).xyz), - topImage@value(t).a ); -@end - -@foreach( 16, n ) -@property( uv_atlas@n ) @piece( atlasOffset@n )* atlasOffsets[@n].z + atlasOffsets[@n].xy @end @end @end - -// Get the indexes to the textureMaps[] array using template code. We had to add 1 -// to the actual value otherwise property( diffuse_map ) fails when the index is 0 -@foreach( diffuse_map, n ) - @sub( diffuse_map@n_idx, diffuse_map@n, 1 ) @end - -@piece( diffuseIdx0 )material.indices0_3.x & 0x0000FFFFu@end -@piece( diffuseIdx1 )material.indices0_3.x >> 16u@end -@piece( diffuseIdx2 )material.indices0_3.y & 0x0000FFFFu@end -@piece( diffuseIdx3 )material.indices0_3.y >> 16u@end -@piece( diffuseIdx4 )material.indices0_3.z & 0x0000FFFFu@end -@piece( diffuseIdx5 )material.indices0_3.z >> 16u@end -@piece( diffuseIdx6 )material.indices0_3.w & 0x0000FFFFu@end -@piece( diffuseIdx7 )material.indices0_3.w >> 16u@end - -@foreach( diffuse_map, n ) - @property( diffuse_map@n_array ) - @piece( SamplerOrigin@n )textureMapsArray[@value(diffuse_map@n_idx)]@end - @end @property( !diffuse_map@n_array ) - @piece( SamplerOrigin@n )textureMaps[@value(diffuse_map@n_idx)]@end - @end - @property( !diffuse_map@n_reflection ) - @property( diffuse_map@n_array ) - @piece( SamplerUV@n )vec3( inPs.uv@value( uv_diffuse@n ).@insertpiece( uv_diffuse_swizzle@n ), @insertpiece( diffuseIdx@n ) )@end - @end @property( !diffuse_map@n_array ) - @piece( SamplerUV@n )inPs.uv@value( uv_diffuse@n ).@insertpiece( uv_diffuse_swizzle@n )@end - @end - @end @property( diffuse_map@n_reflection ) - @property( !hlms_forwardplus_flipY ) - @property( diffuse_map@n_array ) - @piece( SamplerUV@n )vec3( gl_FragCoord.x * passBuf.invWindowSize.x, 1.0 - gl_FragCoord.y * passBuf.invWindowSize.y, @insertpiece( diffuseIdx@n ) )@end - @end @property( !diffuse_map@n_array ) - @piece( SamplerUV@n )vec2( gl_FragCoord.x * passBuf.invWindowSize.x, 1.0 - gl_FragCoord.y * passBuf.invWindowSize.y )@end - @end - @end @property( hlms_forwardplus_flipY ) - @property( diffuse_map@n_array ) - @piece( SamplerUV@n )vec3( gl_FragCoord.xy * passBuf.invWindowSize.xy, @insertpiece( diffuseIdx@n ) )@end - @end @property( !diffuse_map@n_array ) - @piece( SamplerUV@n )vec2( gl_FragCoord.xy * passBuf.invWindowSize.xy )@end - @end - @end - @end -@end diff --git a/Samples/Media/Hlms/Unlit/GLSLES/PixelShader_ps.glsl b/Samples/Media/Hlms/Unlit/GLSLES/PixelShader_ps.glsl deleted file mode 100644 index 92ac0b698a2..00000000000 --- a/Samples/Media/Hlms/Unlit/GLSLES/PixelShader_ps.glsl +++ /dev/null @@ -1,97 +0,0 @@ -@insertpiece( SetCrossPlatformSettings ) -@insertpiece( SetCompatibilityLayer ) - -layout(std140) uniform; -#define FRAG_COLOR 0 - -@property( hlms_vpos ) -in vec4 gl_FragCoord; -@end - -@property( !hlms_shadowcaster ) -layout(location = FRAG_COLOR) out vec4 outColour; -@end @property( hlms_shadowcaster ) -layout(location = FRAG_COLOR) out float outColour; -@end - -// START UNIFORM DECLARATION -@property( has_planar_reflections ) - @insertpiece( PassDecl ) -@end -@property( !hlms_shadowcaster && (diffuse_map || alpha_test || hlms_alpha_hash || diffuse) ) -@insertpiece( MaterialDecl ) -@insertpiece( InstanceDecl ) -@end -@insertpiece( custom_ps_uniformDeclaration ) -// END UNIFORM DECLARATION -@property( !hlms_shadowcaster || !hlms_shadow_uses_depth_texture || exponential_shadow_maps ) -in block -{ -@insertpiece( VStoPS_block ) -} inPs; -@end - -@property( !hlms_shadowcaster ) -@property( num_array_textures )uniform sampler2DArray textureMapsArray[@value( num_array_textures )];@end -@property( num_textures )uniform sampler2D textureMaps[@value( num_textures )];@end - -@property( diffuse )@piece( MultiplyDiffuseConst )* material.diffuse@end @end - -@property( diffuse_map || alpha_test || hlms_alpha_hash || diffuse )Material material;@end - -void main() -{ - @insertpiece( custom_ps_preExecution ) -@property( diffuse_map || alpha_test || hlms_alpha_hash || diffuse ) - uint materialId = instance.worldMaterialIdx[inPs.drawId].x; - material = materialArray.m[materialId]; -@end - @insertpiece( custom_ps_posMaterialLoad ) - -@property( !diffuse_map && !diffuse_map0 ) -@property( hlms_colour && !diffuse_map ) outColour = inPs.colour @insertpiece( MultiplyDiffuseConst );@end -@property( !hlms_colour && !diffuse ) outColour = vec4(1, 1, 1, 1);@end -@property( !hlms_colour && diffuse ) outColour = material.diffuse;@end -@end - -@property( diffuse_map )@property( diffuse_map0 ) - //Load base image - outColour = texture( @insertpiece( SamplerOrigin0 ), @insertpiece( SamplerUV0 ) ).@insertpiece(diffuse_map0_tex_swizzle);@end - -@foreach( diffuse_map, n, 1 )@property( diffuse_map@n ) - vec4 topImage@n = texture( @insertpiece( SamplerOrigin@n ), @insertpiece( SamplerUV@n ) ).@insertpiece(diffuse_map@n_tex_swizzle);@end @end - -@foreach( diffuse_map, n, 1 )@property( diffuse_map@n ) - @insertpiece( blend_mode_idx@n )@end @end - - @property( hlms_colour )outColour *= inPs.colour @insertpiece( MultiplyDiffuseConst );@end - @property( !hlms_colour && diffuse )outColour *= material.diffuse;@end -@end - - @insertpiece( custom_ps_preLights ) - -@property( alpha_test && !alpha_test_shadow_caster_only ) - if( material.alpha_test_threshold.x @insertpiece( alpha_test_cmp_func ) outColour.a ) - discard;@end - - @insertpiece( custom_ps_posExecution ) -} - -@end @property( hlms_shadowcaster ) - @property( 0 && hlms_render_depth_only && !macOS) - @set( hlms_disable_stage, 1 ) - @end - -@insertpiece( DeclShadowCasterMacros ) - -@property( hlms_shadowcaster_point ) - @insertpiece( PassDecl ) -@end - -void main() -{ - @insertpiece( custom_ps_preExecution ) - @insertpiece( DoShadowCastPS ) - @insertpiece( custom_ps_posExecution ) -} -@end diff --git a/Samples/Media/Hlms/Unlit/GLSLES/Structs_piece_vs_piece_ps.glsl b/Samples/Media/Hlms/Unlit/GLSLES/Structs_piece_vs_piece_ps.glsl deleted file mode 100644 index 5e73a167f52..00000000000 --- a/Samples/Media/Hlms/Unlit/GLSLES/Structs_piece_vs_piece_ps.glsl +++ /dev/null @@ -1,66 +0,0 @@ -@piece( PassDecl ) -//Uniforms that change per pass -layout_constbuffer(binding = 0) uniform PassBuffer -{ - @insertpiece( PassInternalDecl ) -} passBuf; -@end - -@piece( MaterialDecl ) -struct Material -{ - vec4 alpha_test_threshold; - vec4 diffuse; - - uvec4 indices0_3; - uvec4 indices4_7; - - @insertpiece( custom_materialBuffer ) -}; - -layout_constbuffer(binding = 1) uniform MaterialBuf -{ - Material m[@value( materials_per_buffer )]; -} materialArray; -@end - - -@piece( InstanceDecl ) -//Uniforms that change per Item/Entity -layout_constbuffer(binding = 2) uniform InstanceBuffer -{ - //.x = - //Contains the material's start index. - // - //.y = - //shadowConstantBias. Send the bias directly to avoid an - //unnecessary indirection during the shadow mapping pass. - //Must be loaded with uintBitsToFloat - // - //.z = - //Contains 0 or 1 to index into passBuf.viewProj[]. Only used - //if hlms_identity_viewproj_dynamic is set. - uvec4 worldMaterialIdx[1024]; -} instance; -@end - -@piece( VStoPS_block ) - @property( !hlms_shadowcaster ) - flat uint drawId; - @property( hlms_colour )vec4 colour;@end - @foreach( out_uv_half_count, n ) - vec@value( out_uv_half_count@n ) uv@n;@end - @end - @property( hlms_shadowcaster ) - @property( (!hlms_shadow_uses_depth_texture || exponential_shadow_maps) && !hlms_shadowcaster_point ) - float depth; - @end - @property( hlms_shadowcaster_point ) - vec3 toCameraWS; - @property( !exponential_shadow_maps ) - flat float constBias; - @end - @end - @end - @insertpiece( custom_VStoPS ) -@end diff --git a/Samples/Media/Hlms/Unlit/GLSLES/VertexShader_vs.glsl b/Samples/Media/Hlms/Unlit/GLSLES/VertexShader_vs.glsl deleted file mode 100644 index 8d2ff5b8a5f..00000000000 --- a/Samples/Media/Hlms/Unlit/GLSLES/VertexShader_vs.glsl +++ /dev/null @@ -1,113 +0,0 @@ -@insertpiece( SetCrossPlatformSettings ) -@insertpiece( SetCompatibilityLayer ) - -@property( GL3+ ) -out gl_PerVertex -{ - vec4 gl_Position; -@property( hlms_pso_clip_distances ) - float gl_ClipDistance[@value(hlms_pso_clip_distances)]; -@end -}; -@end - -layout(std140) uniform; - -@insertpiece( Common_Matrix_DeclUnpackMatrix4x4 ) - -in vec4 vertex; -@property( hlms_colour )in vec4 colour;@end - -@foreach( hlms_uv_count, n ) -in vec@value( hlms_uv_count@n ) uv@n;@end - -@property( GL_ARB_base_instance ) - in uint drawId; -@end - -@insertpiece( custom_vs_attributes ) - -@property( !hlms_shadowcaster || !hlms_shadow_uses_depth_texture || exponential_shadow_maps ) -out block -{ -@insertpiece( VStoPS_block ) -} outVs; -@end - -// START UNIFORM DECLARATION -@insertpiece( PassDecl ) -@property( hlms_identity_world && hlms_identity_viewproj_dynamic )@set(VsUseInstanceDecl,1)@end -@foreach( out_uv_count, n )@property( out_uv@n_texture_matrix )@set(VsUseInstanceDecl,1)@end@end -#if @value(VsUseInstanceDecl) // iOS GLSL ES compiler optimizes unused uniform blocks up to the breaking VS/PS layout compatibility -@insertpiece( InstanceDecl ) -#endif -/*layout(binding = 0) */uniform samplerBuffer worldMatBuf; -@property( texture_matrix )/*layout(binding = 1) */uniform samplerBuffer animationMatrixBuf;@end -@insertpiece( custom_vs_uniformDeclaration ) -@property( !GL_ARB_base_instance )uniform uint baseInstance;@end -// END UNIFORM DECLARATION - -@property( !hlms_identity_world ) - @piece( worldViewProj )worldViewProj@end -@end @property( hlms_identity_world ) - @property( !hlms_identity_viewproj_dynamic ) - @piece( worldViewProj )passBuf.viewProj[@value(hlms_identity_viewproj)]@end - @end @property( hlms_identity_viewproj_dynamic ) - @piece( worldViewProj )passBuf.viewProj[instance.worldMaterialIdx[finalDrawId].z]@end - @end -@end - -void main() -{ -@property( !GL_ARB_base_instance ) - uint drawId = baseInstance + uint( gl_InstanceID ); -@end - - @insertpiece( custom_vs_preExecution ) - @property( !hlms_identity_world ) - mat4 worldViewProj; - worldViewProj = UNPACK_MAT4( worldMatBuf, finalDrawId ); - @end - -@property( !hlms_dual_paraboloid_mapping ) - gl_Position = vertex * @insertpiece( worldViewProj ); -@end - -@property( hlms_dual_paraboloid_mapping ) - //Dual Paraboloid Mapping - gl_Position.w = 1.0f; - gl_Position.xyz = (vertex * @insertpiece( worldViewProj )).xyz; - float L = length( gl_Position.xyz ); - gl_Position.z += 1.0f; - gl_Position.xy /= gl_Position.z; - gl_Position.z = (L - NearPlane) / (FarPlane - NearPlane); -@end - -@property( !hlms_shadowcaster ) -@property( hlms_colour ) outVs.colour = colour;@end - -@property( texture_matrix ) mat4 textureMatrix;@end - -@foreach( out_uv_count, n ) - @property( out_uv@n_texture_matrix ) - textureMatrix = UNPACK_MAT4( animationMatrixBuf, (instance.worldMaterialIdx[finalDrawId].x << 4u) + @value( out_uv@n_tex_unit )u ); - outVs.uv@value( out_uv@n_out_uv ).@insertpiece( out_uv@n_swizzle ) = (vec4( uv@value( out_uv@n_source_uv ).xy, 0, 1 ) * textureMatrix).xy; - @end @property( !out_uv@n_texture_matrix ) - outVs.uv@value( out_uv@n_out_uv ).@insertpiece( out_uv@n_swizzle ) = uv@value( out_uv@n_source_uv ).xy; - @end @end - - outVs.drawId = finalDrawId; - -@end - - @property( hlms_global_clip_planes || (hlms_shadowcaster && (exponential_shadow_maps || hlms_shadowcaster_point)) ) - float3 worldPos = (gl_Position * passBuf.invViewProj).xyz; - @end - @insertpiece( DoShadowCasterVS ) - -@property( hlms_global_clip_planes ) - gl_ClipDistance[0] = dot( float4( worldPos.xyz, 1.0 ), passBuf.clipPlane0.xyzw ); -@end - - @insertpiece( custom_vs_posExecution ) -}