From 3207d8aef79c1730eef7e04ee586a63304221056 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 9 Feb 2018 23:29:31 +0100 Subject: [PATCH] - generate uniform declarations from c++ --- src/gl/shaders/gl_shader.cpp | 116 +++++++++++++++++- wadsrc/static/shaders/glsl/burn.fp | 3 +- wadsrc/static/shaders/glsl/func_brightmap.fp | 10 -- wadsrc/static/shaders/glsl/func_warp1.fp | 1 - wadsrc/static/shaders/glsl/func_warp2.fp | 1 - wadsrc/static/shaders/glsl/func_warp3.fp | 1 - wadsrc/static/shaders/glsl/func_wavex.fp | 1 - wadsrc/static/shaders/glsl/fuzz_jagged.fp | 1 - wadsrc/static/shaders/glsl/fuzz_noise.fp | 1 - wadsrc/static/shaders/glsl/fuzz_smooth.fp | 1 - .../static/shaders/glsl/fuzz_smoothnoise.fp | 1 - .../shaders/glsl/fuzz_smoothtranslucent.fp | 1 - wadsrc/static/shaders/glsl/fuzz_software.fp | 1 - wadsrc/static/shaders/glsl/fuzz_standard.fp | 1 - wadsrc/static/shaders/glsl/fuzz_swirly.fp | 1 - wadsrc/static/shaders/glsl/main.fp | 32 ----- wadsrc/static/shaders/glsl/shaderdefs.i | 71 ----------- 17 files changed, 113 insertions(+), 131 deletions(-) delete mode 100644 wadsrc/static/shaders/glsl/shaderdefs.i diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index bcaea9bb48..b535b606c3 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -63,9 +63,117 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * static char buffer[10000]; FString error; - int i_lump = Wads.CheckNumForFullName("shaders/glsl/shaderdefs.i", 0); - if (i_lump == -1) I_Error("Unable to load 'shaders/glsl/shaderdefs.i'"); - FMemLump i_data = Wads.ReadLump(i_lump); + FString i_data; + + // these settings are actually pointless but there seem to be some old ATI drivers that fail to compile the shader without setting the precision here. + i_data += "precision highp int;\n"; + i_data += "precision highp float;\n"; + + i_data += "uniform vec4 uCameraPos;\n"; + i_data += "uniform int uTextureMode;\n"; + i_data += "uniform float uClipHeight;\n"; + i_data += "uniform float uClipHeightDirection;\n"; + i_data += "uniform vec2 uClipSplit;\n"; + i_data += "uniform vec4 uClipLine;\n"; + i_data += "uniform float uAlphaThreshold;\n"; + + // colors + i_data += "uniform vec4 uObjectColor;\n"; + i_data += "uniform vec4 uObjectColor2;\n"; + i_data += "uniform vec4 uDynLightColor;\n"; + i_data += "uniform vec4 uFogColor;\n"; + i_data += "uniform float uDesaturationFactor;\n"; + i_data += "uniform float uInterpolationFactor;\n"; + + // Fixed colormap stuff + i_data += "uniform int uFixedColormap;\n"; // 0, when no fixed colormap, 1 for a light value, 2 for a color blend, 3 for a fog layer + i_data += "uniform vec4 uFixedColormapStart;\n"; + i_data += "uniform vec4 uFixedColormapRange;\n"; + + // Glowing walls stuff + i_data += "uniform vec4 uGlowTopPlane;\n"; + i_data += "uniform vec4 uGlowTopColor;\n"; + i_data += "uniform vec4 uGlowBottomPlane;\n"; + i_data += "uniform vec4 uGlowBottomColor;\n"; + + i_data += "uniform vec4 uSplitTopPlane;\n"; + i_data += "uniform vec4 uSplitBottomPlane;\n"; + + // Lighting + Fog + i_data += "uniform vec4 uLightAttr;\n"; + i_data += "#define uLightLevel uLightAttr.a\n"; + i_data += "#define uFogDensity uLightAttr.b\n"; + i_data += "#define uLightFactor uLightAttr.g\n"; + i_data += "#define uLightDist uLightAttr.r\n"; + i_data += "uniform int uFogEnabled;\n"; + i_data += "uniform int uPalLightLevels;\n"; + i_data += "uniform float uGlobVis;\n"; // uGlobVis = R_GetGlobVis(r_visibility) / 32.0 + + // dynamic lights + i_data += "uniform int uLightIndex;\n"; + + // Software fuzz scaling + i_data += "uniform int uViewHeight;\n"; + + // Blinn glossiness and specular level + i_data += "uniform vec2 uSpecularMaterial;\n"; + + // quad drawer stuff + i_data += "#ifdef USE_QUAD_DRAWER\n"; + i_data += "uniform mat4 uQuadVertices;\n"; + i_data += "uniform mat4 uQuadTexCoords;\n"; + i_data += "uniform int uQuadMode;\n"; + i_data += "#endif\n"; + + // matrices + i_data += "uniform mat4 ProjectionMatrix;\n"; + i_data += "uniform mat4 ViewMatrix;\n"; + i_data += "uniform mat4 ModelMatrix;\n"; + i_data += "uniform mat4 NormalViewMatrix;\n"; + i_data += "uniform mat4 NormalModelMatrix;\n"; + i_data += "uniform mat4 TextureMatrix;\n"; + + // light buffers + i_data += "#ifdef SHADER_STORAGE_LIGHTS\n"; + i_data += "layout(std430, binding = 1) buffer LightBufferSSO\n"; + i_data += "{\n"; + i_data += " vec4 lights[];\n"; + i_data += "};\n"; + i_data += "#elif defined NUM_UBO_LIGHTS\n"; + i_data += "uniform LightBufferUBO\n"; + i_data += "{\n"; + i_data += " vec4 lights[NUM_UBO_LIGHTS];\n"; + i_data += "};\n"; + i_data += "#endif\n"; + + // textures + i_data += "uniform sampler2D tex;\n"; + i_data += "uniform sampler2D ShadowMap;\n"; + i_data += "uniform sampler2D texture2;\n"; + i_data += "uniform sampler2D texture3;\n"; + i_data += "uniform sampler2D texture4;\n"; + i_data += "uniform sampler2D texture5;\n"; + i_data += "uniform sampler2D texture6;\n"; + + // timer data + i_data += "uniform float timer;\n"; // To do: we must search user shaders for this declaration and remove it + + // material types + i_data += "#if defined(SPECULAR)\n"; + i_data += "#define normaltexture texture2\n"; + i_data += "#define speculartexture texture3\n"; + i_data += "#define brighttexture texture4\n"; + i_data += "#elif defined(PBR)\n"; + i_data += "#define normaltexture texture2\n"; + i_data += "#define metallictexture texture3\n"; + i_data += "#define roughnesstexture texture4\n"; + i_data += "#define aotexture texture5\n"; + i_data += "#define brighttexture texture6\n"; + i_data += "#else\n"; + i_data += "#define brighttexture texture2\n"; + i_data += "#endif\n"; + + i_data += "#line 1\n"; int vp_lump = Wads.CheckNumForFullName(vert_prog_lump, 0); if (vp_lump == -1) I_Error("Unable to load '%s'", vert_prog_lump); @@ -120,7 +228,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * vp_comb << "#define SUPPORTS_SHADOWMAPS\n"; } - vp_comb << defines << i_data.GetString().GetChars(); + vp_comb << defines << i_data.GetChars(); FString fp_comb = vp_comb; vp_comb << vp_data.GetString().GetChars() << "\n"; diff --git a/wadsrc/static/shaders/glsl/burn.fp b/wadsrc/static/shaders/glsl/burn.fp index f928fd8db2..d3f6f20e9b 100644 --- a/wadsrc/static/shaders/glsl/burn.fp +++ b/wadsrc/static/shaders/glsl/burn.fp @@ -1,5 +1,4 @@ -uniform sampler2D tex; -uniform sampler2D texture2; + in vec4 vTexCoord; in vec4 vColor; out vec4 FragColor; diff --git a/wadsrc/static/shaders/glsl/func_brightmap.fp b/wadsrc/static/shaders/glsl/func_brightmap.fp index 00760bd628..7f92d36e5e 100644 --- a/wadsrc/static/shaders/glsl/func_brightmap.fp +++ b/wadsrc/static/shaders/glsl/func_brightmap.fp @@ -1,13 +1,3 @@ -#if defined(SPECULAR) -uniform sampler2D texture4; -#define brighttexture texture4 -#elif defined(PBR) -uniform sampler2D texture6; -#define brighttexture texture6 -#else -uniform sampler2D texture2; -#define brighttexture texture2 -#endif vec4 ProcessTexel() { diff --git a/wadsrc/static/shaders/glsl/func_warp1.fp b/wadsrc/static/shaders/glsl/func_warp1.fp index 891eaa9366..4214f771f2 100644 --- a/wadsrc/static/shaders/glsl/func_warp1.fp +++ b/wadsrc/static/shaders/glsl/func_warp1.fp @@ -1,4 +1,3 @@ -uniform float timer; vec4 ProcessTexel() { diff --git a/wadsrc/static/shaders/glsl/func_warp2.fp b/wadsrc/static/shaders/glsl/func_warp2.fp index ee712593d5..389fad9df7 100644 --- a/wadsrc/static/shaders/glsl/func_warp2.fp +++ b/wadsrc/static/shaders/glsl/func_warp2.fp @@ -1,4 +1,3 @@ -uniform float timer; vec4 ProcessTexel() { diff --git a/wadsrc/static/shaders/glsl/func_warp3.fp b/wadsrc/static/shaders/glsl/func_warp3.fp index a81969ca63..dceca24773 100644 --- a/wadsrc/static/shaders/glsl/func_warp3.fp +++ b/wadsrc/static/shaders/glsl/func_warp3.fp @@ -1,4 +1,3 @@ -uniform float timer; vec4 ProcessTexel() { diff --git a/wadsrc/static/shaders/glsl/func_wavex.fp b/wadsrc/static/shaders/glsl/func_wavex.fp index e4230ae879..05ab530284 100644 --- a/wadsrc/static/shaders/glsl/func_wavex.fp +++ b/wadsrc/static/shaders/glsl/func_wavex.fp @@ -1,4 +1,3 @@ -uniform float timer; vec4 ProcessTexel() { diff --git a/wadsrc/static/shaders/glsl/fuzz_jagged.fp b/wadsrc/static/shaders/glsl/fuzz_jagged.fp index c088c7b309..083c220689 100644 --- a/wadsrc/static/shaders/glsl/fuzz_jagged.fp +++ b/wadsrc/static/shaders/glsl/fuzz_jagged.fp @@ -1,5 +1,4 @@ //created by Evil Space Tomato -uniform float timer; vec4 ProcessTexel() { diff --git a/wadsrc/static/shaders/glsl/fuzz_noise.fp b/wadsrc/static/shaders/glsl/fuzz_noise.fp index 75afc251f5..6d1c0094cb 100644 --- a/wadsrc/static/shaders/glsl/fuzz_noise.fp +++ b/wadsrc/static/shaders/glsl/fuzz_noise.fp @@ -1,5 +1,4 @@ //created by Evil Space Tomato -uniform float timer; vec4 ProcessTexel() { diff --git a/wadsrc/static/shaders/glsl/fuzz_smooth.fp b/wadsrc/static/shaders/glsl/fuzz_smooth.fp index 4261d5415a..3c642c399a 100644 --- a/wadsrc/static/shaders/glsl/fuzz_smooth.fp +++ b/wadsrc/static/shaders/glsl/fuzz_smooth.fp @@ -1,5 +1,4 @@ //created by Evil Space Tomato -uniform float timer; vec4 ProcessTexel() { diff --git a/wadsrc/static/shaders/glsl/fuzz_smoothnoise.fp b/wadsrc/static/shaders/glsl/fuzz_smoothnoise.fp index bfe04ec16e..d446a3d0a9 100644 --- a/wadsrc/static/shaders/glsl/fuzz_smoothnoise.fp +++ b/wadsrc/static/shaders/glsl/fuzz_smoothnoise.fp @@ -1,5 +1,4 @@ //created by Evil Space Tomato -uniform float timer; vec4 ProcessTexel() { diff --git a/wadsrc/static/shaders/glsl/fuzz_smoothtranslucent.fp b/wadsrc/static/shaders/glsl/fuzz_smoothtranslucent.fp index 75bee03302..1b727a1bc6 100644 --- a/wadsrc/static/shaders/glsl/fuzz_smoothtranslucent.fp +++ b/wadsrc/static/shaders/glsl/fuzz_smoothtranslucent.fp @@ -1,5 +1,4 @@ //created by Evil Space Tomato -uniform float timer; vec4 ProcessTexel() { diff --git a/wadsrc/static/shaders/glsl/fuzz_software.fp b/wadsrc/static/shaders/glsl/fuzz_software.fp index cf905bb6ee..4fe4ab669e 100644 --- a/wadsrc/static/shaders/glsl/fuzz_software.fp +++ b/wadsrc/static/shaders/glsl/fuzz_software.fp @@ -1,5 +1,4 @@ // Fuzz effect as rendered by the software renderer -uniform float timer; #define FUZZTABLE 50 #define FUZZ_RANDOM_X_SIZE 100 diff --git a/wadsrc/static/shaders/glsl/fuzz_standard.fp b/wadsrc/static/shaders/glsl/fuzz_standard.fp index b467f64b2d..3eb3b67e6b 100644 --- a/wadsrc/static/shaders/glsl/fuzz_standard.fp +++ b/wadsrc/static/shaders/glsl/fuzz_standard.fp @@ -1,5 +1,4 @@ //created by Evil Space Tomato -uniform float timer; vec4 ProcessTexel() { diff --git a/wadsrc/static/shaders/glsl/fuzz_swirly.fp b/wadsrc/static/shaders/glsl/fuzz_swirly.fp index 86a66ac8ec..266858999e 100644 --- a/wadsrc/static/shaders/glsl/fuzz_swirly.fp +++ b/wadsrc/static/shaders/glsl/fuzz_swirly.fp @@ -1,5 +1,4 @@ //created by Evil Space Tomato -uniform float timer; vec4 ProcessTexel() { diff --git a/wadsrc/static/shaders/glsl/main.fp b/wadsrc/static/shaders/glsl/main.fp index a768d12449..b868f86c31 100644 --- a/wadsrc/static/shaders/glsl/main.fp +++ b/wadsrc/static/shaders/glsl/main.fp @@ -12,38 +12,6 @@ out vec4 FragFog; out vec4 FragNormal; #endif -#ifdef SHADER_STORAGE_LIGHTS - layout(std430, binding = 1) buffer LightBufferSSO - { - vec4 lights[]; - }; -#elif defined NUM_UBO_LIGHTS - /*layout(std140)*/ uniform LightBufferUBO - { - vec4 lights[NUM_UBO_LIGHTS]; - }; -#endif - - -uniform sampler2D tex; -uniform sampler2D ShadowMap; - -#if defined(SPECULAR) -uniform sampler2D texture2; -uniform sampler2D texture3; -#define normaltexture texture2 -#define speculartexture texture3 -#elif defined(PBR) -uniform sampler2D texture2; -uniform sampler2D texture3; -uniform sampler2D texture4; -uniform sampler2D texture5; -#define normaltexture texture2 -#define metallictexture texture3 -#define roughnesstexture texture4 -#define aotexture texture5 -#endif - vec4 Process(vec4 color); vec4 ProcessTexel(); vec4 ProcessLight(vec4 color); diff --git a/wadsrc/static/shaders/glsl/shaderdefs.i b/wadsrc/static/shaders/glsl/shaderdefs.i deleted file mode 100644 index 6836135d32..0000000000 --- a/wadsrc/static/shaders/glsl/shaderdefs.i +++ /dev/null @@ -1,71 +0,0 @@ -// This file contains common data definitions for both vertex and fragment shader - -// these settings are actually pointless but there seem to be some old ATI drivers that fail to compile the shader without setting the precision here. -precision highp int; -precision highp float; - -uniform vec4 uCameraPos; -uniform int uTextureMode; -uniform float uClipHeight, uClipHeightDirection; -uniform vec2 uClipSplit; -uniform vec4 uClipLine; - -uniform float uAlphaThreshold; - - -// colors -uniform vec4 uObjectColor; -uniform vec4 uObjectColor2; -uniform vec4 uDynLightColor; -uniform vec4 uFogColor; -uniform float uDesaturationFactor; -uniform float uInterpolationFactor; - -// Fixed colormap stuff -uniform int uFixedColormap; // 0, when no fixed colormap, 1 for a light value, 2 for a color blend, 3 for a fog layer -uniform vec4 uFixedColormapStart; -uniform vec4 uFixedColormapRange; - -// Glowing walls stuff -uniform vec4 uGlowTopPlane; -uniform vec4 uGlowTopColor; -uniform vec4 uGlowBottomPlane; -uniform vec4 uGlowBottomColor; - -uniform vec4 uSplitTopPlane; -uniform vec4 uSplitBottomPlane; - -// Lighting + Fog -uniform vec4 uLightAttr; -#define uLightLevel uLightAttr.a -#define uFogDensity uLightAttr.b -#define uLightFactor uLightAttr.g -#define uLightDist uLightAttr.r -uniform int uFogEnabled; -uniform int uPalLightLevels; -uniform float uGlobVis; // uGlobVis = R_GetGlobVis(r_visibility) / 32.0 - -// dynamic lights -uniform int uLightIndex; - -// Software fuzz scaling -uniform int uViewHeight; - -// Blinn glossiness and specular level -uniform vec2 uSpecularMaterial; - -// quad drawer stuff -#ifdef USE_QUAD_DRAWER -uniform mat4 uQuadVertices; -uniform mat4 uQuadTexCoords; -uniform int uQuadMode; -#endif - -// matrices -uniform mat4 ProjectionMatrix; -uniform mat4 ViewMatrix; -uniform mat4 ModelMatrix; -uniform mat4 NormalViewMatrix; -uniform mat4 NormalModelMatrix; -uniform mat4 TextureMatrix; -