yum-mirror/glslang
git clone https://git.yummers.dev/yum-mirror/glslang
5398d55e
main
1#version 460 2uniform sampler2D sTDNoiseMap ; 3uniform sampler1D sTDSineLookup ; 4uniform sampler2D sTDWhite2D ; 5uniform sampler3D sTDWhite3D ; 6uniform sampler2DArray sTDWhite2DArray ; 7uniform samplerCube sTDWhiteCube ; 8uniform int uTDInstanceIDOffset ; 9uniform int uTDNumInstances ; 10uniform float uTDAlphaTestVal ; 11#define TD_NUM_COLOR_BUFFERS 1 12#define TD_NUM_LIGHTS 0 13#define TD_NUM_SHADOWED_LIGHTS 0 14#define TD_NUM_ENV_LIGHTS 0 15#define TD_LIGHTS_ARRAY_SIZE 1 16#define TD_ENV_LIGHTS_ARRAY_SIZE 1 17#define TD_NUM_CAMERAS 1 18struct TDLight 19{ 20vec4 position ; 21vec3 direction ; 22vec3 diffuse ; 23vec4 nearFar ; 24vec4 lightSize ; 25vec4 misc ; 26vec4 coneLookupScaleBias ; 27vec4 attenScaleBiasRoll ; 28mat4 shadowMapMatrix ; 29mat4 shadowMapCamMatrix ; 30vec4 shadowMapRes ; 31mat4 projMapMatrix ; 32}; 33struct TDEnvLight 34{ 35vec3 color ; 36mat3 rotate ; 37}; 38layout (std140 )uniform TDLightBlock 39{ 40TDLight uTDLights [TD_LIGHTS_ARRAY_SIZE ]; 41}; 42layout (std140 )uniform TDEnvLightBlock 43{ 44TDEnvLight uTDEnvLights [TD_ENV_LIGHTS_ARRAY_SIZE ]; 45}; 46layout (std430 )readonly restrictbuffer TDEnvLightBuffer 47{ 48vec3 shCoeffs [9 ]; 49}uTDEnvLightBuffers [TD_ENV_LIGHTS_ARRAY_SIZE ]; 50struct TDPhongResult 51{ 52vec3 diffuse ; 53vec3 specular ; 54vec3 specular2 ; 55float shadowStrength ; 56}; 57struct TDPBRResult 58{ 59vec3 diffuse ; 60vec3 specular ; 61float shadowStrength ; 62}; 63struct TDMatrix 64{ 65mat4 world ; 66mat4 worldInverse ; 67mat4 worldCam ; 68mat4 worldCamInverse ; 69mat4 cam ; 70mat4 camInverse ; 71mat4 camProj ; 72mat4 camProjInverse ; 73mat4 proj ; 74mat4 projInverse ; 75mat4 worldCamProj ; 76mat4 worldCamProjInverse ; 77mat4 quadReproject ; 78mat3 worldForNormals ; 79mat3 camForNormals ; 80mat3 worldCamForNormals ; 81}; 82layout (std140 )uniform TDMatricesBlock { 83TDMatrix uTDMats [TD_NUM_CAMERAS ]; 84}; 85struct TDCameraInfo 86{ 87vec4 nearFar ; 88vec4 fog ; 89vec4 fogColor ; 90int renderTOPCameraIndex ; 91}; 92layout (std140 )uniform TDCameraInfoBlock { 93TDCameraInfo uTDCamInfos [TD_NUM_CAMERAS ]; 94}; 95struct TDGeneral 96{ 97vec4 ambientColor ; 98vec4 nearFar ; 99vec4 viewport ; 100vec4 viewportRes ; 101vec4 fog ; 102vec4 fogColor ; 103}; 104layout (std140 )uniform TDGeneralBlock { 105TDGeneral uTDGeneral ; 106}; 107 108layout (binding = 15 )uniform samplerBuffer sTDInstanceT ; 109layout (binding = 16 )uniform samplerBuffer sTDInstanceTexCoord ; 110layout (binding = 17 )uniform samplerBuffer sTDInstanceColor ; 111vec4 TDDither (vec4 color ); 112vec3 TDHSVToRGB (vec3 c ); 113vec3 TDRGBToHSV (vec3 c ); 114#define PI 3.14159265 115 116vec4 TDColor (vec4 color ) {return color ; } 117void TDCheckOrderIndTrans () { 118} 119void TDCheckDiscard () { 120TDCheckOrderIndTrans (); 121} 122vec4 TDDither (vec4 color ) 123{ 124float d = texture (sTDNoiseMap , 125gl_FragCoord .xy /256.0 ).r ; 126d -= 0.5 ; 127d /=256.0 ; 128return vec4 (color .rgb + d ,color .a ); 129} 130bool TDFrontFacing (vec3 pos ,vec3 normal ) 131{ 132return gl_FrontFacing ; 133} 134float TDAttenuateLight (int index ,float lightDist ) 135{ 136return 1.0 ; 137} 138void TDAlphaTest (float alpha ) { 139} 140float TDHardShadow (int lightIndex ,vec3 worldSpacePos ) 141{return 0.0 ; } 142float TDSoftShadow (int lightIndex ,vec3 worldSpacePos ,int samples ,int steps ) 143{return 0.0 ; } 144float TDSoftShadow (int lightIndex ,vec3 worldSpacePos ) 145{return 0.0 ; } 146float TDShadow (int lightIndex ,vec3 worldSpacePos ) 147{return 0.0 ; } 148vec3 TDEquirectangularToCubeMap (vec2 mapCoord ); 149vec2 TDCubeMapToEquirectangular (vec3 envMapCoord ); 150vec2 TDCubeMapToEquirectangular (vec3 envMapCoord ,out float mipMapBias ); 151vec2 TDTexGenSphere (vec3 envMapCoord ); 152float iTDRadicalInverse_VdC (uint bits ) 153{ 154bits = (bits <<16u ) | (bits >>16u ); 155bits = ((bits & 0x55555555u ) <<1u ) | ((bits & 0xAAAAAAAAu ) >>1u ); 156bits = ((bits & 0x33333333u ) <<2u ) | ((bits & 0xCCCCCCCCu ) >>2u ); 157bits = ((bits & 0x0F0F0F0Fu ) <<4u ) | ((bits & 0xF0F0F0F0u ) >>4u ); 158bits = ((bits & 0x00FF00FFu ) <<8u ) | ((bits & 0xFF00FF00u ) >>8u ); 159return float (bits )* 2.3283064365386963e-10 ;// / 0x100000000 160} 161vec2 iTDHammersley (uint i ,uint N ) 162{ 163return vec2 (float (i ) /float (N ),iTDRadicalInverse_VdC (i )); 164} 165vec3 iTDImportanceSampleGGX (vec2 Xi ,float roughness2 ,vec3 N ) 166{ 167float a = roughness2 ; 168float phi = 2 * 3.14159265 * Xi .x ; 169float cosTheta = sqrt ( (1 - Xi .y ) / (1 + (a * a - 1 )* Xi .y ) ); 170float sinTheta = sqrt (1 - cosTheta * cosTheta ); 171 172vec3 H ; 173H .x = sinTheta * cos (phi ); 174H .y = sinTheta * sin (phi ); 175H .z = cosTheta ; 176 177vec3 upVector = abs (N .z )< 0.999 ?vec3 (0 ,0 ,1 ) :vec3 (1 ,0 ,0 ); 178vec3 tangentX = normalize (cross (upVector ,N )); 179vec3 tangentY = cross (N ,tangentX ); 180 181// Tangent to world space 182vec3 worldResult = tangentX * H .x + tangentY * H .y + N * H .z ; 183return worldResult ; 184} 185float iTDDistributionGGX (vec3 normal ,vec3 half_vector ,float roughness2 ) 186{ 187const float Epsilon = 0.000001 ; 188 189float NdotH = clamp (dot (normal ,half_vector ),Epsilon ,1.0 ); 190 191float alpha2 = roughness2 * roughness2 ; 192 193float denom = NdotH * NdotH * (alpha2 - 1.0 )+ 1.0 ; 194denom = max (1e-8 ,denom ); 195return alpha2 / (PI * denom * denom ); 196} 197vec3 iTDCalcF (vec3 F0 ,float VdotH ) { 198return F0 + (vec3 (1.0 )- F0 )* pow (2.0 , (-5.55473 * VdotH - 6.98316 )* VdotH ); 199} 200 201float iTDCalcG (float NdotL ,float NdotV ,float k ) { 202float Gl = 1.0 / (NdotL * (1.0 - k )+ k ); 203float Gv = 1.0 / (NdotV * (1.0 - k )+ k ); 204return Gl * Gv ; 205} 206// 0 - All options 207TDPBRResult TDLightingPBR (int index ,vec3 diffuseColor ,vec3 specularColor ,vec3 worldSpacePos ,vec3 normal ,float shadowStrength ,vec3 shadowColor ,vec3 camVector ,float roughness ) 208{ 209TDPBRResult res ; 210return res ; 211} 212// 0 - All options 213void TDLightingPBR (inout vec3 diffuseContrib ,inout vec3 specularContrib ,inout float shadowStrengthOut ,int index ,vec3 diffuseColor ,vec3 specularColor ,vec3 worldSpacePos ,vec3 normal ,float shadowStrength ,vec3 shadowColor ,vec3 camVector ,float roughness ) 214{ 215TDPBRResult res = TDLightingPBR (index ,diffuseColor ,specularColor ,worldSpacePos ,normal ,shadowStrength ,shadowColor ,camVector ,roughness );diffuseContrib = res .diffuse ; 216specularContrib = res .specular ; 217shadowStrengthOut = res .shadowStrength ; 218} 219// 0 - All options 220void TDLightingPBR (inout vec3 diffuseContrib ,inout vec3 specularContrib ,int index ,vec3 diffuseColor ,vec3 specularColor ,vec3 worldSpacePos ,vec3 normal ,float shadowStrength ,vec3 shadowColor ,vec3 camVector ,float roughness ) 221{ 222TDPBRResult res = TDLightingPBR (index ,diffuseColor ,specularColor ,worldSpacePos ,normal ,shadowStrength ,shadowColor ,camVector ,roughness );diffuseContrib = res .diffuse ; 223specularContrib = res .specular ; 224} 225// 0 - All options 226TDPBRResult TDEnvLightingPBR (int index ,vec3 diffuseColor ,vec3 specularColor ,vec3 normal ,vec3 camVector ,float roughness ,float ambientOcclusion ) 227{ 228TDPBRResult res ; 229return res ; 230} 231// 0 - All options 232void TDEnvLightingPBR (inout vec3 diffuseContrib ,inout vec3 specularContrib ,int index ,vec3 diffuseColor ,vec3 specularColor ,vec3 normal ,vec3 camVector ,float roughness ,float ambientOcclusion ) 233{ 234TDPBRResult res = TDEnvLightingPBR (index ,diffuseColor ,specularColor ,normal ,camVector ,roughness ,ambientOcclusion ); 235diffuseContrib = res .diffuse ; 236specularContrib = res .specular ; 237} 238// 0 - All options 239TDPhongResult TDLighting (int index ,vec3 worldSpacePos ,vec3 normal ,float shadowStrength ,vec3 shadowColor ,vec3 camVector ,float shininess ,float shininess2 ) 240{ 241TDPhongResult res ; 242switch (index ) 243 { 244default : 245res .diffuse = vec3 (0.0 ); 246res .specular = vec3 (0.0 ); 247res .specular2 = vec3 (0.0 ); 248res .shadowStrength = 0.0 ; 249break ; 250 } 251return res ; 252} 253// 0 - Legacy 254void TDLighting (inout vec3 diffuseContrib ,inout vec3 specularContrib ,inout vec3 specularContrib2 ,inout float shadowStrengthOut ,int index ,vec3 worldSpacePos ,vec3 normal ,float shadowStrength ,vec3 shadowColor ,vec3 camVector ,float shininess ,float shininess2 ) 255{ 256TDPhongResult res ; 257switch (index ) 258 { 259default : 260res .diffuse = vec3 (0.0 ); 261res .specular = vec3 (0.0 ); 262res .specular2 = vec3 (0.0 ); 263res .shadowStrength = 0.0 ; 264break ; 265 } 266diffuseContrib = res .diffuse ; 267specularContrib = res .specular ; 268specularContrib2 = res .specular2 ; 269shadowStrengthOut = res .shadowStrength ; 270} 271// 0 - Legacy 272void TDLighting (inout vec3 diffuseContrib ,inout vec3 specularContrib ,inout vec3 specularContrib2 ,int index ,vec3 worldSpacePos ,vec3 normal ,float shadowStrength ,vec3 shadowColor ,vec3 camVector ,float shininess ,float shininess2 ) 273{ 274TDPhongResult res ; 275switch (index ) 276 { 277default : 278res .diffuse = vec3 (0.0 ); 279res .specular = vec3 (0.0 ); 280res .specular2 = vec3 (0.0 ); 281res .shadowStrength = 0.0 ; 282break ; 283 } 284diffuseContrib = res .diffuse ; 285specularContrib = res .specular ; 286specularContrib2 = res .specular2 ; 287} 288// 1 - Without specular2 289void TDLighting (inout vec3 diffuseContrib ,inout vec3 specularContrib ,int index ,vec3 worldSpacePos ,vec3 normal ,float shadowStrength ,vec3 shadowColor ,vec3 camVector ,float shininess ) 290{ 291TDPhongResult res ; 292switch (index ) 293 { 294default : 295res .diffuse = vec3 (0.0 ); 296res .specular = vec3 (0.0 ); 297res .specular2 = vec3 (0.0 ); 298res .shadowStrength = 0.0 ; 299break ; 300 } 301diffuseContrib = res .diffuse ; 302specularContrib = res .specular ; 303} 304// 2 - Without shadows 305void TDLighting (inout vec3 diffuseContrib ,inout vec3 specularContrib ,inout vec3 specularContrib2 ,int index ,vec3 worldSpacePos ,vec3 normal ,vec3 camVector ,float shininess ,float shininess2 ) 306{ 307TDPhongResult res ; 308switch (index ) 309 { 310default : 311res .diffuse = vec3 (0.0 ); 312res .specular = vec3 (0.0 ); 313res .specular2 = vec3 (0.0 ); 314res .shadowStrength = 0.0 ; 315break ; 316 } 317diffuseContrib = res .diffuse ; 318specularContrib = res .specular ; 319specularContrib2 = res .specular2 ; 320} 321// 3 - diffuse and specular only 322void TDLighting (inout vec3 diffuseContrib ,inout vec3 specularContrib ,int index ,vec3 worldSpacePos ,vec3 normal ,vec3 camVector ,float shininess ) 323{ 324TDPhongResult res ; 325switch (index ) 326 { 327default : 328res .diffuse = vec3 (0.0 ); 329res .specular = vec3 (0.0 ); 330res .specular2 = vec3 (0.0 ); 331res .shadowStrength = 0.0 ; 332break ; 333 } 334diffuseContrib = res .diffuse ; 335specularContrib = res .specular ; 336} 337// 4 - Diffuse only 338void TDLighting (inout vec3 diffuseContrib ,int index ,vec3 worldSpacePos ,vec3 normal ) 339{ 340TDPhongResult res ; 341switch (index ) 342 { 343default : 344res .diffuse = vec3 (0.0 ); 345res .specular = vec3 (0.0 ); 346res .specular2 = vec3 (0.0 ); 347res .shadowStrength = 0.0 ; 348break ; 349 } 350diffuseContrib = res .diffuse ; 351} 352// 5 - diffuse only with shadows 353void TDLighting (inout vec3 diffuseContrib ,int index ,vec3 worldSpacePos ,vec3 normal ,float shadowStrength ,vec3 shadowColor ) 354{ 355TDPhongResult res ; 356switch (index ) 357 { 358default : 359res .diffuse = vec3 (0.0 ); 360res .specular = vec3 (0.0 ); 361res .specular2 = vec3 (0.0 ); 362res .shadowStrength = 0.0 ; 363break ; 364 } 365diffuseContrib = res .diffuse ; 366} 367vec4 TDProjMap (int index ,vec3 worldSpacePos ,vec4 defaultColor ) { 368switch (index ) 369 { 370default :return defaultColor ; 371 } 372} 373vec4 TDFog (vec4 color ,vec3 lightingSpacePosition ,int cameraIndex ) { 374switch (cameraIndex ) { 375default : 376case 0 : 377 { 378return color ; 379 } 380 } 381} 382vec4 TDFog (vec4 color ,vec3 lightingSpacePosition ) 383{ 384return TDFog (color ,lightingSpacePosition ,0 ); 385} 386vec3 TDInstanceTexCoord (int index ,vec3 t ) { 387vec3 v ; 388int coord = index ; 389vec4 samp = texelFetch (sTDInstanceTexCoord ,coord ); 390v [0 ]= t .s ; 391v [1 ]= t .t ; 392v [2 ]= samp [0 ]; 393t .stp = v .stp ; 394return t ; 395} 396bool TDInstanceActive (int index ) { 397index -= uTDInstanceIDOffset ; 398float v ; 399int coord = index ; 400vec4 samp = texelFetch (sTDInstanceT ,coord ); 401v = samp [0 ]; 402return v != 0.0 ; 403} 404vec3 iTDInstanceTranslate (int index ,out bool instanceActive ) { 405int origIndex = index ; 406index -= uTDInstanceIDOffset ; 407vec3 v ; 408int coord = index ; 409vec4 samp = texelFetch (sTDInstanceT ,coord ); 410v [0 ]= samp [1 ]; 411v [1 ]= samp [2 ]; 412v [2 ]= samp [3 ]; 413instanceActive = samp [0 ]!= 0.0 ; 414return v ; 415} 416vec3 TDInstanceTranslate (int index ) { 417index -= uTDInstanceIDOffset ; 418vec3 v ; 419int coord = index ; 420vec4 samp = texelFetch (sTDInstanceT ,coord ); 421v [0 ]= samp [1 ]; 422v [1 ]= samp [2 ]; 423v [2 ]= samp [3 ]; 424return v ; 425} 426mat3 TDInstanceRotateMat (int index ) { 427index -= uTDInstanceIDOffset ; 428vec3 v = vec3 (0.0 ,0.0 ,0.0 ); 429mat3 m = mat3 (1.0 ); 430{ 431mat3 r ; 432} 433return m ; 434} 435vec3 TDInstanceScale (int index ) { 436index -= uTDInstanceIDOffset ; 437vec3 v = vec3 (1.0 ,1.0 ,1.0 ); 438return v ; 439} 440vec3 TDInstancePivot (int index ) { 441index -= uTDInstanceIDOffset ; 442vec3 v = vec3 (0.0 ,0.0 ,0.0 ); 443return v ; 444} 445vec3 TDInstanceRotTo (int index ) { 446index -= uTDInstanceIDOffset ; 447vec3 v = vec3 (0.0 ,0.0 ,1.0 ); 448return v ; 449} 450vec3 TDInstanceRotUp (int index ) { 451index -= uTDInstanceIDOffset ; 452vec3 v = vec3 (0.0 ,1.0 ,0.0 ); 453return v ; 454} 455mat4 TDInstanceMat (int id ) { 456bool instanceActive = true; 457vec3 t = iTDInstanceTranslate (id ,instanceActive ); 458if (!instanceActive ) 459 { 460return mat4 (0.0 ); 461 } 462mat4 m = mat4 (1.0 ); 463 { 464vec3 tt = t ; 465m [3 ][0 ]+= m [0 ][0 ]* tt .x ; 466m [3 ][1 ]+= m [0 ][1 ]* tt .x ; 467m [3 ][2 ]+= m [0 ][2 ]* tt .x ; 468m [3 ][3 ]+= m [0 ][3 ]* tt .x ; 469m [3 ][0 ]+= m [1 ][0 ]* tt .y ; 470m [3 ][1 ]+= m [1 ][1 ]* tt .y ; 471m [3 ][2 ]+= m [1 ][2 ]* tt .y ; 472m [3 ][3 ]+= m [1 ][3 ]* tt .y ; 473m [3 ][0 ]+= m [2 ][0 ]* tt .z ; 474m [3 ][1 ]+= m [2 ][1 ]* tt .z ; 475m [3 ][2 ]+= m [2 ][2 ]* tt .z ; 476m [3 ][3 ]+= m [2 ][3 ]* tt .z ; 477 } 478return m ; 479} 480mat3 TDInstanceMat3 (int id ) { 481mat3 m = mat3 (1.0 ); 482return m ; 483} 484mat3 TDInstanceMat3ForNorm (int id ) { 485mat3 m = TDInstanceMat3 (id ); 486return m ; 487} 488vec4 TDInstanceColor (int index ,vec4 curColor ) { 489index -= uTDInstanceIDOffset ; 490vec4 v ; 491int coord = index ; 492vec4 samp = texelFetch (sTDInstanceColor ,coord ); 493v [0 ]= samp [0 ]; 494v [1 ]= samp [1 ]; 495v [2 ]= samp [2 ]; 496v [3 ]= 1.0 ; 497curColor [0 ]= v [0 ]; 498; 499curColor [1 ]= v [1 ]; 500; 501curColor [2 ]= v [2 ]; 502; 503return curColor ; 504}