mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 20:21:26 +00:00
Move static layout code back to wadsrc
This commit is contained in:
parent
15ff88d7a4
commit
8682361194
2 changed files with 190 additions and 189 deletions
|
@ -32,8 +32,8 @@
|
|||
|
||||
bool VkShaderManager::CompileNextShader()
|
||||
{
|
||||
const char *mainvp = "shaders/glsl/main.vp";
|
||||
const char *mainfp = "shaders/glsl/main.fp";
|
||||
const char *mainvp = "shaders/glsl/vert_scene.vp";
|
||||
const char *mainfp = "shaders/glsl/frag_surface.fp";
|
||||
int i = compileIndex;
|
||||
|
||||
if (compileState == 0)
|
||||
|
@ -153,191 +153,6 @@ VkShaderProgram *VkShaderManager::Get(unsigned int eff, bool alphateston, EPassT
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
static const char *shaderBindings = R"(
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D ShadowMap;
|
||||
layout(set = 0, binding = 1) uniform sampler2DArray LightMap;
|
||||
#ifdef SUPPORTS_RAYTRACING
|
||||
layout(set = 0, binding = 2) uniform accelerationStructureEXT TopLevelAS;
|
||||
#endif
|
||||
|
||||
// This must match the HWViewpointUniforms struct
|
||||
layout(set = 1, binding = 0, std140) uniform ViewpointUBO {
|
||||
mat4 ProjectionMatrix;
|
||||
mat4 ViewMatrix;
|
||||
mat4 NormalViewMatrix;
|
||||
|
||||
vec4 uCameraPos;
|
||||
vec4 uClipLine;
|
||||
|
||||
float uGlobVis; // uGlobVis = R_GetGlobVis(r_visibility) / 32.0
|
||||
int uPalLightLevels;
|
||||
int uViewHeight; // Software fuzz scaling
|
||||
float uClipHeight;
|
||||
float uClipHeightDirection;
|
||||
int uShadowmapFilter;
|
||||
|
||||
int uLightBlendMode;
|
||||
};
|
||||
|
||||
layout(set = 1, binding = 1, std140) uniform MatricesUBO {
|
||||
mat4 ModelMatrix;
|
||||
mat4 NormalModelMatrix;
|
||||
mat4 TextureMatrix;
|
||||
};
|
||||
|
||||
struct StreamData
|
||||
{
|
||||
vec4 uObjectColor;
|
||||
vec4 uObjectColor2;
|
||||
vec4 uDynLightColor;
|
||||
vec4 uAddColor;
|
||||
vec4 uTextureAddColor;
|
||||
vec4 uTextureModulateColor;
|
||||
vec4 uTextureBlendColor;
|
||||
vec4 uFogColor;
|
||||
float uDesaturationFactor;
|
||||
float uInterpolationFactor;
|
||||
float timer; // timer data for material shaders
|
||||
int useVertexData;
|
||||
vec4 uVertexColor;
|
||||
vec4 uVertexNormal;
|
||||
|
||||
vec4 uGlowTopPlane;
|
||||
vec4 uGlowTopColor;
|
||||
vec4 uGlowBottomPlane;
|
||||
vec4 uGlowBottomColor;
|
||||
|
||||
vec4 uGradientTopPlane;
|
||||
vec4 uGradientBottomPlane;
|
||||
|
||||
vec4 uSplitTopPlane;
|
||||
vec4 uSplitBottomPlane;
|
||||
|
||||
vec4 uDetailParms;
|
||||
vec4 uNpotEmulation;
|
||||
vec4 padding1, padding2, padding3;
|
||||
};
|
||||
|
||||
layout(set = 1, binding = 2, std140) uniform StreamUBO {
|
||||
StreamData data[MAX_STREAM_DATA];
|
||||
};
|
||||
|
||||
// light buffers
|
||||
layout(set = 1, binding = 3, std430) buffer LightBufferSSO
|
||||
{
|
||||
vec4 lights[];
|
||||
};
|
||||
|
||||
// bone matrix buffers
|
||||
layout(set = 1, binding = 4, std430) buffer BoneBufferSSO
|
||||
{
|
||||
mat4 bones[];
|
||||
};
|
||||
|
||||
// textures
|
||||
layout(set = 2, binding = 0) uniform sampler2D tex;
|
||||
layout(set = 2, binding = 1) uniform sampler2D texture2;
|
||||
layout(set = 2, binding = 2) uniform sampler2D texture3;
|
||||
layout(set = 2, binding = 3) uniform sampler2D texture4;
|
||||
layout(set = 2, binding = 4) uniform sampler2D texture5;
|
||||
layout(set = 2, binding = 5) uniform sampler2D texture6;
|
||||
layout(set = 2, binding = 6) uniform sampler2D texture7;
|
||||
layout(set = 2, binding = 7) uniform sampler2D texture8;
|
||||
layout(set = 2, binding = 8) uniform sampler2D texture9;
|
||||
layout(set = 2, binding = 9) uniform sampler2D texture10;
|
||||
layout(set = 2, binding = 10) uniform sampler2D texture11;
|
||||
layout(set = 2, binding = 11) uniform sampler2D texture12;
|
||||
|
||||
// This must match the PushConstants struct
|
||||
layout(push_constant) uniform PushConstants
|
||||
{
|
||||
int uTextureMode;
|
||||
float uAlphaThreshold;
|
||||
vec2 uClipSplit;
|
||||
|
||||
// Lighting + Fog
|
||||
float uLightLevel;
|
||||
float uFogDensity;
|
||||
float uLightFactor;
|
||||
float uLightDist;
|
||||
int uFogEnabled;
|
||||
|
||||
// dynamic lights
|
||||
int uLightIndex;
|
||||
|
||||
// Blinn glossiness and specular level
|
||||
vec2 uSpecularMaterial;
|
||||
|
||||
// bone animation
|
||||
int uBoneIndexBase;
|
||||
|
||||
int uDataIndex;
|
||||
int padding2, padding3;
|
||||
};
|
||||
|
||||
// material types
|
||||
#if defined(SPECULAR)
|
||||
#define normaltexture texture2
|
||||
#define speculartexture texture3
|
||||
#define brighttexture texture4
|
||||
#define detailtexture texture5
|
||||
#define glowtexture texture6
|
||||
#elif defined(PBR)
|
||||
#define normaltexture texture2
|
||||
#define metallictexture texture3
|
||||
#define roughnesstexture texture4
|
||||
#define aotexture texture5
|
||||
#define brighttexture texture6
|
||||
#define detailtexture texture7
|
||||
#define glowtexture texture8
|
||||
#else
|
||||
#define brighttexture texture2
|
||||
#define detailtexture texture3
|
||||
#define glowtexture texture4
|
||||
#endif
|
||||
|
||||
#define uObjectColor data[uDataIndex].uObjectColor
|
||||
#define uObjectColor2 data[uDataIndex].uObjectColor2
|
||||
#define uDynLightColor data[uDataIndex].uDynLightColor
|
||||
#define uAddColor data[uDataIndex].uAddColor
|
||||
#define uTextureBlendColor data[uDataIndex].uTextureBlendColor
|
||||
#define uTextureModulateColor data[uDataIndex].uTextureModulateColor
|
||||
#define uTextureAddColor data[uDataIndex].uTextureAddColor
|
||||
#define uFogColor data[uDataIndex].uFogColor
|
||||
#define uDesaturationFactor data[uDataIndex].uDesaturationFactor
|
||||
#define uInterpolationFactor data[uDataIndex].uInterpolationFactor
|
||||
#define timer data[uDataIndex].timer
|
||||
#define useVertexData data[uDataIndex].useVertexData
|
||||
#define uVertexColor data[uDataIndex].uVertexColor
|
||||
#define uVertexNormal data[uDataIndex].uVertexNormal
|
||||
#define uGlowTopPlane data[uDataIndex].uGlowTopPlane
|
||||
#define uGlowTopColor data[uDataIndex].uGlowTopColor
|
||||
#define uGlowBottomPlane data[uDataIndex].uGlowBottomPlane
|
||||
#define uGlowBottomColor data[uDataIndex].uGlowBottomColor
|
||||
#define uGradientTopPlane data[uDataIndex].uGradientTopPlane
|
||||
#define uGradientBottomPlane data[uDataIndex].uGradientBottomPlane
|
||||
#define uSplitTopPlane data[uDataIndex].uSplitTopPlane
|
||||
#define uSplitBottomPlane data[uDataIndex].uSplitBottomPlane
|
||||
#define uDetailParms data[uDataIndex].uDetailParms
|
||||
#define uNpotEmulation data[uDataIndex].uNpotEmulation
|
||||
|
||||
#define SUPPORTS_SHADOWMAPS
|
||||
#define VULKAN_COORDINATE_SYSTEM
|
||||
#define HAS_UNIFORM_VERTEX_DATA
|
||||
|
||||
// GLSL spec 4.60, 8.15. Noise Functions
|
||||
// https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.pdf
|
||||
// "The noise functions noise1, noise2, noise3, and noise4 have been deprecated starting with version 4.4 of GLSL.
|
||||
// When not generating SPIR-V they are defined to return the value 0.0 or a vector whose components are all 0.0.
|
||||
// When generating SPIR-V the noise functions are not declared and may not be used."
|
||||
// However, we need to support mods with custom shaders created for OpenGL renderer
|
||||
float noise1(float) { return 0; }
|
||||
vec2 noise2(vec2) { return vec2(0); }
|
||||
vec3 noise3(vec3) { return vec3(0); }
|
||||
vec4 noise4(vec4) { return vec4(0); }
|
||||
)";
|
||||
|
||||
std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername, const char *vert_lump, const char *defines)
|
||||
{
|
||||
FString code = GetTargetGlslVersion();
|
||||
|
@ -346,7 +161,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadVertShader(FString shadername
|
|||
#ifdef NPOT_EMULATION
|
||||
code << "#define NPOT_EMULATION\n";
|
||||
#endif
|
||||
code << shaderBindings;
|
||||
code << LoadPrivateShaderLump("shaders/scene/layout_shared.glsl");
|
||||
if (!fb->device->EnabledFeatures.Features.shaderClipDistance) code << "#define NO_CLIPDISTANCE_SUPPORT\n";
|
||||
code << "#line 1\n";
|
||||
code << LoadPrivateShaderLump(vert_lump).GetChars() << "\n";
|
||||
|
@ -369,7 +184,7 @@ std::unique_ptr<VulkanShader> VkShaderManager::LoadFragShader(FString shadername
|
|||
#ifdef NPOT_EMULATION
|
||||
code << "#define NPOT_EMULATION\n";
|
||||
#endif
|
||||
code << shaderBindings;
|
||||
code << LoadPrivateShaderLump("shaders/scene/layout_shared.glsl");
|
||||
FString placeholder = "\n";
|
||||
|
||||
if (!fb->device->EnabledFeatures.Features.shaderClipDistance) code << "#define NO_CLIPDISTANCE_SUPPORT\n";
|
||||
|
|
186
wadsrc/static/shaders/scene/layout_shared.glsl
Normal file
186
wadsrc/static/shaders/scene/layout_shared.glsl
Normal file
|
@ -0,0 +1,186 @@
|
|||
|
||||
layout(set = 0, binding = 0) uniform sampler2D ShadowMap;
|
||||
layout(set = 0, binding = 1) uniform sampler2DArray LightMap;
|
||||
#ifdef SUPPORTS_RAYTRACING
|
||||
layout(set = 0, binding = 2) uniform accelerationStructureEXT TopLevelAS;
|
||||
#endif
|
||||
|
||||
// This must match the HWViewpointUniforms struct
|
||||
layout(set = 1, binding = 0, std140) uniform ViewpointUBO
|
||||
{
|
||||
mat4 ProjectionMatrix;
|
||||
mat4 ViewMatrix;
|
||||
mat4 NormalViewMatrix;
|
||||
|
||||
vec4 uCameraPos;
|
||||
vec4 uClipLine;
|
||||
|
||||
float uGlobVis; // uGlobVis = R_GetGlobVis(r_visibility) / 32.0
|
||||
int uPalLightLevels;
|
||||
int uViewHeight; // Software fuzz scaling
|
||||
float uClipHeight;
|
||||
float uClipHeightDirection;
|
||||
int uShadowmapFilter;
|
||||
|
||||
int uLightBlendMode;
|
||||
};
|
||||
|
||||
layout(set = 1, binding = 1, std140) uniform MatricesUBO
|
||||
{
|
||||
mat4 ModelMatrix;
|
||||
mat4 NormalModelMatrix;
|
||||
mat4 TextureMatrix;
|
||||
};
|
||||
|
||||
// This must match the StreamData struct
|
||||
struct StreamData
|
||||
{
|
||||
vec4 uObjectColor;
|
||||
vec4 uObjectColor2;
|
||||
vec4 uDynLightColor;
|
||||
vec4 uAddColor;
|
||||
vec4 uTextureAddColor;
|
||||
vec4 uTextureModulateColor;
|
||||
vec4 uTextureBlendColor;
|
||||
vec4 uFogColor;
|
||||
float uDesaturationFactor;
|
||||
float uInterpolationFactor;
|
||||
float timer; // timer data for material shaders
|
||||
int useVertexData;
|
||||
vec4 uVertexColor;
|
||||
vec4 uVertexNormal;
|
||||
|
||||
vec4 uGlowTopPlane;
|
||||
vec4 uGlowTopColor;
|
||||
vec4 uGlowBottomPlane;
|
||||
vec4 uGlowBottomColor;
|
||||
|
||||
vec4 uGradientTopPlane;
|
||||
vec4 uGradientBottomPlane;
|
||||
|
||||
vec4 uSplitTopPlane;
|
||||
vec4 uSplitBottomPlane;
|
||||
|
||||
vec4 uDetailParms;
|
||||
vec4 uNpotEmulation;
|
||||
vec4 padding1, padding2, padding3;
|
||||
};
|
||||
|
||||
layout(set = 1, binding = 2, std140) uniform StreamUBO
|
||||
{
|
||||
StreamData data[MAX_STREAM_DATA];
|
||||
};
|
||||
|
||||
// light buffers
|
||||
layout(set = 1, binding = 3, std430) buffer LightBufferSSO
|
||||
{
|
||||
vec4 lights[];
|
||||
};
|
||||
|
||||
// bone matrix buffers
|
||||
layout(set = 1, binding = 4, std430) buffer BoneBufferSSO
|
||||
{
|
||||
mat4 bones[];
|
||||
};
|
||||
|
||||
// textures
|
||||
layout(set = 2, binding = 0) uniform sampler2D tex;
|
||||
layout(set = 2, binding = 1) uniform sampler2D texture2;
|
||||
layout(set = 2, binding = 2) uniform sampler2D texture3;
|
||||
layout(set = 2, binding = 3) uniform sampler2D texture4;
|
||||
layout(set = 2, binding = 4) uniform sampler2D texture5;
|
||||
layout(set = 2, binding = 5) uniform sampler2D texture6;
|
||||
layout(set = 2, binding = 6) uniform sampler2D texture7;
|
||||
layout(set = 2, binding = 7) uniform sampler2D texture8;
|
||||
layout(set = 2, binding = 8) uniform sampler2D texture9;
|
||||
layout(set = 2, binding = 9) uniform sampler2D texture10;
|
||||
layout(set = 2, binding = 10) uniform sampler2D texture11;
|
||||
layout(set = 2, binding = 11) uniform sampler2D texture12;
|
||||
|
||||
// This must match the PushConstants struct
|
||||
layout(push_constant) uniform PushConstants
|
||||
{
|
||||
int uTextureMode;
|
||||
float uAlphaThreshold;
|
||||
vec2 uClipSplit;
|
||||
|
||||
// Lighting + Fog
|
||||
float uLightLevel;
|
||||
float uFogDensity;
|
||||
float uLightFactor;
|
||||
float uLightDist;
|
||||
int uFogEnabled;
|
||||
|
||||
// dynamic lights
|
||||
int uLightIndex;
|
||||
|
||||
// Blinn glossiness and specular level
|
||||
vec2 uSpecularMaterial;
|
||||
|
||||
// bone animation
|
||||
int uBoneIndexBase;
|
||||
|
||||
int uDataIndex;
|
||||
int padding2, padding3;
|
||||
};
|
||||
|
||||
// material types
|
||||
#if defined(SPECULAR)
|
||||
#define normaltexture texture2
|
||||
#define speculartexture texture3
|
||||
#define brighttexture texture4
|
||||
#define detailtexture texture5
|
||||
#define glowtexture texture6
|
||||
#elif defined(PBR)
|
||||
#define normaltexture texture2
|
||||
#define metallictexture texture3
|
||||
#define roughnesstexture texture4
|
||||
#define aotexture texture5
|
||||
#define brighttexture texture6
|
||||
#define detailtexture texture7
|
||||
#define glowtexture texture8
|
||||
#else
|
||||
#define brighttexture texture2
|
||||
#define detailtexture texture3
|
||||
#define glowtexture texture4
|
||||
#endif
|
||||
|
||||
#define uObjectColor data[uDataIndex].uObjectColor
|
||||
#define uObjectColor2 data[uDataIndex].uObjectColor2
|
||||
#define uDynLightColor data[uDataIndex].uDynLightColor
|
||||
#define uAddColor data[uDataIndex].uAddColor
|
||||
#define uTextureBlendColor data[uDataIndex].uTextureBlendColor
|
||||
#define uTextureModulateColor data[uDataIndex].uTextureModulateColor
|
||||
#define uTextureAddColor data[uDataIndex].uTextureAddColor
|
||||
#define uFogColor data[uDataIndex].uFogColor
|
||||
#define uDesaturationFactor data[uDataIndex].uDesaturationFactor
|
||||
#define uInterpolationFactor data[uDataIndex].uInterpolationFactor
|
||||
#define timer data[uDataIndex].timer
|
||||
#define useVertexData data[uDataIndex].useVertexData
|
||||
#define uVertexColor data[uDataIndex].uVertexColor
|
||||
#define uVertexNormal data[uDataIndex].uVertexNormal
|
||||
#define uGlowTopPlane data[uDataIndex].uGlowTopPlane
|
||||
#define uGlowTopColor data[uDataIndex].uGlowTopColor
|
||||
#define uGlowBottomPlane data[uDataIndex].uGlowBottomPlane
|
||||
#define uGlowBottomColor data[uDataIndex].uGlowBottomColor
|
||||
#define uGradientTopPlane data[uDataIndex].uGradientTopPlane
|
||||
#define uGradientBottomPlane data[uDataIndex].uGradientBottomPlane
|
||||
#define uSplitTopPlane data[uDataIndex].uSplitTopPlane
|
||||
#define uSplitBottomPlane data[uDataIndex].uSplitBottomPlane
|
||||
#define uDetailParms data[uDataIndex].uDetailParms
|
||||
#define uNpotEmulation data[uDataIndex].uNpotEmulation
|
||||
|
||||
#define SUPPORTS_SHADOWMAPS
|
||||
#define VULKAN_COORDINATE_SYSTEM
|
||||
#define HAS_UNIFORM_VERTEX_DATA
|
||||
|
||||
// GLSL spec 4.60, 8.15. Noise Functions
|
||||
// https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.pdf
|
||||
// "The noise functions noise1, noise2, noise3, and noise4 have been deprecated starting with version 4.4 of GLSL.
|
||||
// When not generating SPIR-V they are defined to return the value 0.0 or a vector whose components are all 0.0.
|
||||
// When generating SPIR-V the noise functions are not declared and may not be used."
|
||||
// However, we need to support mods with custom shaders created for OpenGL renderer
|
||||
float noise1(float) { return 0; }
|
||||
vec2 noise2(vec2) { return vec2(0); }
|
||||
vec3 noise3(vec3) { return vec3(0); }
|
||||
vec4 noise4(vec4) { return vec4(0); }
|
Loading…
Reference in a new issue