@@ -112,6 +112,9 @@ VkShaderProgram* VkShaderManager::Get(const VkShaderKey& key)
112
112
{ " dithertrans" , " shaders/scene/frag_main.glsl" , " shaders/scene/material_default.glsl" , " shaders/scene/mateffect_default.glsl" , " shaders/scene/lightmodel_shared.glsl" , " shaders/scene/lightmodel_normal.glsl" , " #define NO_ALPHATEST\n #define DITHERTRANS\n " },
113
113
};
114
114
115
+ VkShaderKey customKey = key;
116
+ customKey.AlphaTest = false ;
117
+
115
118
const auto & desc = effectshaders[key.SpecialEffect ];
116
119
program.vert = LoadVertShader (desc.ShaderName , mainvp, nullptr , desc.defines , key, nullptr );
117
120
if (!key.NoFragmentShader )
@@ -274,7 +277,7 @@ static void AddBuiltinFields(FString &layoutBlock, int &index, bool is_in, const
274
277
}
275
278
}
276
279
277
- void VkShaderManager::BuildLayoutBlock (FString &layoutBlock, bool isFrag, const VkShaderKey& key, const UserShaderDesc *shader)
280
+ void VkShaderManager::BuildLayoutBlock (FString &layoutBlock, bool isFrag, const VkShaderKey& key, const UserShaderDesc *shader, bool isUberShader )
278
281
{
279
282
bool hasClipDistance = fb->GetDevice ()->EnabledFeatures .Features .shaderClipDistance ;
280
283
@@ -293,6 +296,17 @@ void VkShaderManager::BuildLayoutBlock(FString &layoutBlock, bool isFrag, const
293
296
}
294
297
layoutBlock << " int uBoneIndexBase; // bone animation\n " ;
295
298
layoutBlock << " int uFogballIndex; // fog balls\n " ;
299
+
300
+ if (isUberShader)
301
+ {
302
+ layoutBlock << " int uShaderKey1;\n " ;
303
+ layoutBlock << " int uShaderKey2;\n " ;
304
+ }
305
+ else
306
+ {
307
+ layoutBlock << " int unused2;\n " ;
308
+ layoutBlock << " int unused3;\n " ;
309
+ }
296
310
297
311
if (shader && shader->Uniforms .UniformStructSize )
298
312
{
@@ -326,7 +340,7 @@ void VkShaderManager::BuildLayoutBlock(FString &layoutBlock, bool isFrag, const
326
340
}
327
341
}
328
342
329
- void VkShaderManager::BuildDefinesBlock (FString &definesBlock, const char *defines, bool isFrag, const VkShaderKey& key, const UserShaderDesc *shader)
343
+ void VkShaderManager::BuildDefinesBlock (FString &definesBlock, const char *defines, bool isFrag, const VkShaderKey& key, const UserShaderDesc *shader, bool isUberShader )
330
344
{
331
345
if (fb->IsRayQueryEnabled ())
332
346
{
@@ -352,86 +366,173 @@ void VkShaderManager::BuildDefinesBlock(FString &definesBlock, const char *defin
352
366
definesBlock << " #define NO_CLIPDISTANCE_SUPPORT\n " ;
353
367
}
354
368
355
- if (!key.AlphaTest ) definesBlock << " #define NO_ALPHATEST\n " ;
356
- if (key.GBufferPass ) definesBlock << " #define GBUFFER_PASS\n " ;
357
- if (key.AlphaTestOnly ) definesBlock << " #define ALPHATEST_ONLY\n " ;
358
- if (key.Simple ) definesBlock << " #define SIMPLE\n " ;
359
- if (key.Simple3D ) definesBlock << " #define SIMPLE3D\n " ;
360
-
361
- switch (key.LightBlendMode )
369
+ if (isUberShader)
362
370
{
363
- case 0 :
364
- definesBlock << " #define LIGHT_BLEND_CLAMPED\n " ;
365
- break ;
366
- case 1 :
367
- definesBlock << " #define LIGHT_BLEND_COLORED_CLAMP\n " ;
368
- break ;
369
- case 2 :
370
- definesBlock << " #define LIGHT_BLEND_UNCLAMPED\n " ;
371
- break ;
372
- }
371
+ // ugh EffectState also controls layout, because specular/pbr/etc defines switch texture indices around for normal/specular/etc
373
372
374
- switch (key.LightAttenuationMode )
375
- {
376
- case 0 :
377
- definesBlock << " #define LIGHT_ATTENUATION_LINEAR\n " ;
378
- break ;
379
- case 1 :
380
- definesBlock << " #define LIGHT_ATTENUATION_INVERSE_SQUARE\n " ;
381
- break ;
382
- }
373
+ definesBlock << LoadPrivateShaderLump (" shaders/shaderkey.glsl" ).GetChars () << " \n " ;
383
374
384
- if (key. DepthFadeThreshold ) definesBlock << " #define USE_DEPTHFADETHRESHOLD \n " ;
375
+ definesBlock << " #define UBERSHADERS \n " ;
385
376
386
- if (key.Simple2D ) definesBlock << " #define SIMPLE2D\n " ;
387
- if (key.ClampY ) definesBlock << " #define TEXF_ClampY\n " ;
388
- if (key.Brightmap ) definesBlock << " #define TEXF_Brightmap\n " ;
389
- if (key.Detailmap ) definesBlock << " #define TEXF_Detailmap\n " ;
390
- if (key.Glowmap ) definesBlock << " #define TEXF_Glowmap\n " ;
377
+ definesBlock << " #define DO_ALPHATEST ((uShaderKey1 & SK1_ALPHATEST) != 0)\n " ;
378
+
379
+ // definesBlock << "#define SIMPLE ((uShaderKey1 & SK1_SIMPLE) != 0)\n";
380
+ // definesBlock << "#define SIMPLE3D ((uShaderKey1 & SK1_SIMPLE3D) != 0)\n";
381
+ // controls layout
382
+ if (key.Simple ) definesBlock << " #define SIMPLE\n " ;
383
+ if (key.Simple3D ) definesBlock << " #define SIMPLE3D\n " ;
391
384
392
- if (key.UseRaytrace ) definesBlock << " #define USE_RAYTRACE\n " ;
393
- if (key.UseRaytracePrecise ) definesBlock << " #define USE_RAYTRACE_PRECISE\n " ;
394
- if (key.PreciseMidtextureTrace ) definesBlock << " #define PRECISE_MIDTEXTURES\n " ;
385
+ definesBlock << " #define SIMPLE2D ((uShaderKey1 & SK1_SIMPLE2D) != 0)\n " ;
395
386
396
- definesBlock << " #define SHADOWMAP_FILTER " ;
397
- definesBlock << std::to_string (key.ShadowmapFilter ).c_str ();
398
- definesBlock << " \n " ;
387
+ definesBlock << " #define TM_STENCIL (SK_GET_TEXTUREMODE() == SK1_TM_STENCIL)\n " ;
388
+ definesBlock << " #define TM_OPAQUE (SK_GET_TEXTUREMODE() == SK1_TM_OPAQUE)\n " ;
389
+ definesBlock << " #define TM_INVERSE (SK_GET_TEXTUREMODE() == SK1_TM_INVERSE)\n " ;
390
+ definesBlock << " #define TM_ALPHATEXTURE (SK_GET_TEXTUREMODE() == SK1_TM_ALPHATEXTURE)\n " ;
391
+ definesBlock << " #define TM_CLAMPY (SK_GET_TEXTUREMODE() == SK1_TM_CLAMPY)\n " ;
392
+ definesBlock << " #define TM_INVERTOPAQUE (SK_GET_TEXTUREMODE() == SK1_TM_INVERTOPAQUE)\n " ;
393
+ definesBlock << " #define TM_FOGLAYER (SK_GET_TEXTUREMODE() == SK1_TM_FOGLAYER)\n " ;
399
394
400
- if (key.UseShadowmap ) definesBlock << " #define USE_SHADOWMAP\n " ;
401
- if (key.UseLevelMesh ) definesBlock << " #define USE_LEVELMESH\n " ;
395
+ definesBlock << " #define TEXF_ClampY ((uShaderKey1 & SK1_TEXF_CLAMPY) != 0)\n " ;
396
+ definesBlock << " #define TEXF_Brightmap ((uShaderKey1 & SK1_TEXF_BRIGHTMAP) != 0)\n " ;
397
+ definesBlock << " #define TEXF_Detailmap ((uShaderKey1 & SK1_TEXF_DETAILMAP) != 0)\n " ;
398
+ definesBlock << " #define TEXF_Glowmap ((uShaderKey1 & SK1_TEXF_GLOWMAP) != 0)\n " ;
402
399
403
- switch (key.TextureMode )
404
- {
405
- case TM_STENCIL: definesBlock << " #define TM_STENCIL\n " ; break ;
406
- case TM_OPAQUE: definesBlock << " #define TM_OPAQUE\n " ; break ;
407
- case TM_INVERSE: definesBlock << " #define TM_INVERSE\n " ; break ;
408
- case TM_ALPHATEXTURE: definesBlock << " #define TM_ALPHATEXTURE\n " ; break ;
409
- case TM_CLAMPY: definesBlock << " #define TM_CLAMPY\n " ; break ;
410
- case TM_INVERTOPAQUE: definesBlock << " #define TM_INVERTOPAQUE\n " ; break ;
411
- case TM_FOGLAYER: definesBlock << " #define TM_FOGLAYER\n " ; break ;
412
- }
400
+ definesBlock << " #define GBUFFER_PASS ((uShaderKey1 & SK1_GBUFFER_PASS) != 0)\n " ;
413
401
414
- switch (key.LightMode )
415
- {
416
- case 0 : definesBlock << " #define LIGHTMODE_DEFAULT\n " ; break ;
417
- case 1 : definesBlock << " #define LIGHTMODE_SOFTWARE\n " ; break ;
418
- case 2 : definesBlock << " #define LIGHTMODE_VANILLA\n " ; break ;
419
- case 3 : definesBlock << " #define LIGHTMODE_BUILD\n " ; break ;
402
+ definesBlock << " #define USE_SHADOWMAP ((uShaderKey1 & SK1_USE_SHADOWMAP) != 0)\n " ;
403
+
404
+ definesBlock << " #define USE_RAYTRACE ((uShaderKey1 & SK1_USE_RAYTRACE) != 0)\n " ;
405
+ definesBlock << " #define USE_RAYTRACE_PRECISE ((uShaderKey1 & SK1_USE_RAYTRACE_PRECISE) != 0)\n " ;
406
+ definesBlock << " #define PRECISE_MIDTEXTURES ((uShaderKey1 & SK1_PRECISE_MIDTEXTURES) != 0)\n " ;
407
+
408
+ definesBlock << " #define SHADOWMAP_FILTER (SK_GET_SHADOWMAP_FILTER())\n " ;
409
+
410
+ definesBlock << " #define FOG_BEFORE_LIGHTS ((uShaderKey1 & SK1_FOG_BEFORE_LIGHTS) != 0)\n " ;
411
+ definesBlock << " #define FOG_AFTER_LIGHTS ((uShaderKey1 & SK1_FOG_AFTER_LIGHTS) != 0)\n " ;
412
+ definesBlock << " #define FOG_RADIAL ((uShaderKey1 & SK1_FOG_RADIAL) != 0)\n " ;
413
+
414
+ definesBlock << " #define SWLIGHT_RADIAL ((uShaderKey1 & SK1_SWLIGHT_RADIAL) != 0)\n " ;
415
+ definesBlock << " #define SWLIGHT_BANDED ((uShaderKey1 & SK1_SWLIGHT_BANDED) != 0)\n " ;
416
+
417
+ definesBlock << " #define LIGHTMODE_DEFAULT (SK_GET_LIGHTMODE() == SK1_LIGHTMODE_DEFAULT)\n " ;
418
+ definesBlock << " #define LIGHTMODE_SOFTWARE (SK_GET_LIGHTMODE() == SK1_LIGHTMODE_SOFTWARE)\n " ;
419
+ definesBlock << " #define LIGHTMODE_VANILLA (SK_GET_LIGHTMODE() == SK1_LIGHTMODE_VANILLA)\n " ;
420
+ definesBlock << " #define LIGHTMODE_BUILD (SK_GET_LIGHTMODE() == SK1_LIGHTMODE_BUILD)\n " ;
421
+
422
+ definesBlock << " #define LIGHT_BLEND_CLAMPED (SK_GET_LIGHTBLENDMODE() == SK1_LIGHT_BLEND_CLAMPED)\n " ;
423
+ definesBlock << " #define LIGHT_BLEND_COLORED_CLAMP (SK_GET_LIGHTBLENDMODE() == SK1_LIGHT_LIGHT_BLEND_COLORED_CLAMP)\n " ;
424
+ definesBlock << " #define LIGHT_BLEND_UNCLAMPED (SK_GET_LIGHTBLENDMODE() == SK1_LIGHT_BLEND_UNCLAMPED)\n " ;
425
+
426
+ definesBlock << " #define LIGHT_ATTENUATION_LINEAR ((uShaderKey1 & SK1_TEXTUREMODE) == 0)\n " ;
427
+ definesBlock << " #define LIGHT_ATTENUATION_INVERSE_SQUARE ((uShaderKey1 & SK1_TEXTUREMODE) != 0)\n " ;
428
+
429
+ // definesBlock << "#define USE_LEVELMESH (!!(uShaderKey1 & SK1_USE_LEVELMESH))\n";
430
+ // controls layout
431
+ if (key.UseLevelMesh ) definesBlock << " #define USE_LEVELMESH\n " ;
432
+
433
+ definesBlock << " #define FOGBALLS ((uShaderKey1 & SK1_FOGBALLS) != 0)\n " ;
434
+
435
+ // key.NoFragmentShader not used in defines
436
+
437
+ definesBlock << " #define USE_DEPTHFADETHRESHOLD ((uShaderKey2 & SK2_USE_DEPTHFADETHRESHOLD) != 0)\n " ;
438
+ definesBlock << " #define NOT_ALPHATEST_ONLY ((uShaderKey2 & SK2_ALPHATEST_ONLY) == 0)\n " ;
439
+
440
+ // definesBlock << "#define SHADE_VERTEX ((uShaderKey2 & SK2_SHADE_VERTEX) != 0)\n";
441
+ // controls layout
442
+ if (key.ShadeVertex ) definesBlock << " #define SHADE_VERTEX\n " ;
443
+
444
+ definesBlock << " #define LIGHT_NONORMALS ((uShaderKey2 & SK2_LIGHT_NONORMALS) != 0)\n " ;
445
+ definesBlock << " #define USE_SPRITE_CENTER ((uShaderKey2 & SK2_USE_SPRITECENTER) != 0)\n " ;
446
+
447
+ definesBlock << " #define uFogEnabled ((uShaderKey1 & SK1_SIMPLE2D) ? -3 : 0)\n " ;
420
448
}
449
+ else
450
+ {
451
+ if (key.AlphaTest ) definesBlock << " #define DO_ALPHATEST\n " ;
452
+ if (key.Simple ) definesBlock << " #define SIMPLE\n " ;
453
+ if (key.Simple2D ) definesBlock << " #define SIMPLE2D\n " ;
454
+ if (key.Simple3D ) definesBlock << " #define SIMPLE3D\n " ;
455
+
456
+ switch (key.TextureMode )
457
+ {
458
+ case TM_STENCIL: definesBlock << " #define TM_STENCIL\n " ; break ;
459
+ case TM_OPAQUE: definesBlock << " #define TM_OPAQUE\n " ; break ;
460
+ case TM_INVERSE: definesBlock << " #define TM_INVERSE\n " ; break ;
461
+ case TM_ALPHATEXTURE: definesBlock << " #define TM_ALPHATEXTURE\n " ; break ;
462
+ case TM_CLAMPY: definesBlock << " #define TM_CLAMPY\n " ; break ;
463
+ case TM_INVERTOPAQUE: definesBlock << " #define TM_INVERTOPAQUE\n " ; break ;
464
+ case TM_FOGLAYER: definesBlock << " #define TM_FOGLAYER\n " ; break ;
465
+ }
466
+
467
+ if (key.ClampY ) definesBlock << " #define TEXF_ClampY\n " ;
468
+ if (key.Brightmap ) definesBlock << " #define TEXF_Brightmap\n " ;
469
+ if (key.Detailmap ) definesBlock << " #define TEXF_Detailmap\n " ;
470
+ if (key.Glowmap ) definesBlock << " #define TEXF_Glowmap\n " ;
421
471
422
- if (key.FogBeforeLights ) definesBlock << " #define FOG_BEFORE_LIGHTS\n " ;
423
- if (key.FogAfterLights ) definesBlock << " #define FOG_AFTER_LIGHTS\n " ;
424
- if (key.FogRadial ) definesBlock << " #define FOG_RADIAL\n " ;
425
- if (key.SWLightRadial ) definesBlock << " #define SWLIGHT_RADIAL\n " ;
426
- if (key.SWLightBanded ) definesBlock << " #define SWLIGHT_BANDED\n " ;
427
- if (key.FogBalls ) definesBlock << " #define FOGBALLS\n " ;
472
+ if (key.GBufferPass ) definesBlock << " #define GBUFFER_PASS\n " ;
428
473
474
+ if (key.UseShadowmap ) definesBlock << " #define USE_SHADOWMAP\n " ;
429
475
430
- if (key.ShadeVertex ) definesBlock << " #define SHADE_VERTEX\n " ;
431
- if (key.LightNoNormals ) definesBlock << " #define LIGHT_NONORMALS\n " ;
432
- if (key.UseSpriteCenter ) definesBlock << " #define USE_SPRITE_CENTER\n " ;
433
476
434
- definesBlock << ((key.Simple2D ) ? " #define uFogEnabled -3\n " : " #define uFogEnabled 0\n " );
477
+ if (key.UseRaytrace ) definesBlock << " #define USE_RAYTRACE\n " ;
478
+ if (key.UseRaytracePrecise ) definesBlock << " #define USE_RAYTRACE_PRECISE\n " ;
479
+ if (key.PreciseMidtextureTrace ) definesBlock << " #define PRECISE_MIDTEXTURES\n " ;
480
+
481
+ definesBlock << " #define SHADOWMAP_FILTER " << std::to_string (key.ShadowmapFilter ).c_str () << " \n " ;
482
+
483
+ if (key.FogBeforeLights ) definesBlock << " #define FOG_BEFORE_LIGHTS\n " ;
484
+ if (key.FogAfterLights ) definesBlock << " #define FOG_AFTER_LIGHTS\n " ;
485
+ if (key.FogRadial ) definesBlock << " #define FOG_RADIAL\n " ;
486
+
487
+ if (key.SWLightRadial ) definesBlock << " #define SWLIGHT_RADIAL\n " ;
488
+ if (key.SWLightBanded ) definesBlock << " #define SWLIGHT_BANDED\n " ;
489
+
490
+ switch (key.LightMode )
491
+ {
492
+ case 0 : definesBlock << " #define LIGHTMODE_DEFAULT\n " ; break ;
493
+ case 1 : definesBlock << " #define LIGHTMODE_SOFTWARE\n " ; break ;
494
+ case 2 : definesBlock << " #define LIGHTMODE_VANILLA\n " ; break ;
495
+ case 3 : definesBlock << " #define LIGHTMODE_BUILD\n " ; break ;
496
+ }
497
+
498
+ switch (key.LightBlendMode )
499
+ {
500
+ case 0 :
501
+ definesBlock << " #define LIGHT_BLEND_CLAMPED\n " ;
502
+ break ;
503
+ case 1 :
504
+ definesBlock << " #define LIGHT_BLEND_COLORED_CLAMP\n " ;
505
+ break ;
506
+ case 2 :
507
+ definesBlock << " #define LIGHT_BLEND_UNCLAMPED\n " ;
508
+ break ;
509
+ }
510
+
511
+ switch (key.LightAttenuationMode )
512
+ {
513
+ case 0 :
514
+ definesBlock << " #define LIGHT_ATTENUATION_LINEAR\n " ;
515
+ break ;
516
+ case 1 :
517
+ definesBlock << " #define LIGHT_ATTENUATION_INVERSE_SQUARE\n " ;
518
+ break ;
519
+ }
520
+
521
+ if (key.UseLevelMesh ) definesBlock << " #define USE_LEVELMESH\n " ;
522
+ if (key.FogBalls ) definesBlock << " #define FOGBALLS\n " ;
523
+
524
+ // key.NoFragmentShader not used in defines
525
+
526
+ if (key.DepthFadeThreshold ) definesBlock << " #define USE_DEPTHFADETHRESHOLD\n " ;
527
+
528
+ if (!key.AlphaTestOnly ) definesBlock << " #define NOT_ALPHATEST_ONLY\n " ;
529
+
530
+ if (key.ShadeVertex ) definesBlock << " #define SHADE_VERTEX\n " ;
531
+ if (key.LightNoNormals ) definesBlock << " #define LIGHT_NONORMALS\n " ;
532
+ if (key.UseSpriteCenter ) definesBlock << " #define USE_SPRITE_CENTER\n " ;
533
+
534
+ definesBlock << ((key.Simple2D ) ? " #define uFogEnabled -3\n " : " #define uFogEnabled 0\n " );
535
+ }
435
536
436
537
// Setup fake variables for the 'in' attributes that aren't actually available because the garbage shader code thinks they exist
437
538
// God I hate this engine... :(
@@ -631,19 +732,47 @@ ShaderIncludeResult VkShaderManager::OnInclude(FString headerName, FString inclu
631
732
return ShaderIncludeResult (headerName.GetChars (), code.GetChars ());
632
733
}
633
734
634
- FString VkShaderManager::LoadPublicShaderLump (const char *lumpname)
735
+ FString VkShaderManager::LoadPublicShaderLump (const char *lumpname, bool isUberShader )
635
736
{
636
737
int lump = fileSystem.CheckNumForFullName (lumpname, 0 );
637
738
if (lump == -1 ) lump = fileSystem.CheckNumForFullName (lumpname);
638
739
if (lump == -1 ) I_Error (" Unable to load '%s'" , lumpname);
639
- return GetStringFromLump (lump);
740
+
741
+ return LoadShaderLump (lump, isUberShader);
640
742
}
641
743
642
- FString VkShaderManager::LoadPrivateShaderLump (const char *lumpname)
744
+ FString VkShaderManager::LoadPrivateShaderLump (const char *lumpname, bool isUberShader )
643
745
{
644
746
int lump = fileSystem.CheckNumForFullName (lumpname, 0 );
645
747
if (lump == -1 ) I_Error (" Unable to load '%s'" , lumpname);
646
- return GetStringFromLump (lump);
748
+
749
+ return LoadShaderLump (lump, isUberShader);
750
+ }
751
+
752
+ FString VkShaderManager::LoadShaderLump (int lumpnum, bool isUberShader)
753
+ {
754
+ FString str = GetStringFromLump (lumpnum);
755
+
756
+ if (isUberShader)
757
+ {
758
+ str.Substitute (" #uifdef" , " if" );
759
+ str.Substitute (" #uelifdef" , " else if" );
760
+ str.Substitute (" #uif" , " if" );
761
+ str.Substitute (" #uelif" , " else if" );
762
+ str.Substitute (" #uelse" , " else" );
763
+ str.Substitute (" #uendif" , " " );
764
+ }
765
+ else
766
+ {
767
+ str.Substitute (" #uifdef" , " #if defined" );
768
+ str.Substitute (" #uelifdef" , " #elif defined" );
769
+ str.Substitute (" #uif" , " #if" );
770
+ str.Substitute (" #uelif" , " #elif" );
771
+ str.Substitute (" #uelse" , " #else" );
772
+ str.Substitute (" #uendif" , " #endif" );
773
+ }
774
+
775
+ return str;
647
776
}
648
777
649
778
VkPPShader* VkShaderManager::GetVkShader (PPShader* shader)
0 commit comments