diff --git a/src/hardware/hw_glob.h b/src/hardware/hw_glob.h index 8eea81149..2c89fa933 100644 --- a/src/hardware/hw_glob.h +++ b/src/hardware/hw_glob.h @@ -236,8 +236,8 @@ void HWR_CompileShaders(void); int HWR_GetShaderFromTarget(int shader_target); -void HWR_LoadAllCustomShaders(void); -void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3); +void HWR_LoadAllBaseShaders(void); +void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3, boolean startup); const char *HWR_GetShaderName(INT32 shader); extern customshaderxlat_t shaderxlat[]; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index f6daa8da6..e0e018391 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -1067,9 +1067,9 @@ void HWR_Startup(void) HWR_InitMapTextures(); HWR_InitModels(); + HWR_LoadAllBaseShaders(); gl_shadersavailable = HWR_InitShaders(); HWR_SetShaderState(); - HWR_LoadAllCustomShaders(); HWR_TogglePaletteRendering(); } diff --git a/src/hardware/hw_shaders.c b/src/hardware/hw_shaders.c index 1763761b9..9e8bb7e92 100644 --- a/src/hardware/hw_shaders.c +++ b/src/hardware/hw_shaders.c @@ -21,41 +21,9 @@ // ================ static struct { - const char *vertex; - const char *fragment; -} const gl_shadersources[] = { - // Floor shader - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_FLOOR_FRAGMENT_SHADER}, - - // Wall shader - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, - - // Sprite shader - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, - - // Model shader - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WALL_FRAGMENT_SHADER}, - - // Model shader + diffuse lighting from above - {GLSL_MODEL_LIGHTING_VERTEX_SHADER, GLSL_SOFTWARE_MODEL_LIGHTING_FRAGMENT_SHADER}, - - // Water shader - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_WATER_FRAGMENT_SHADER}, - - // Fog shader - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_FOG_FRAGMENT_SHADER}, - - // Sky shader - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_SKY_FRAGMENT_SHADER}, - - // Palette postprocess shader - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_PALETTE_POSTPROCESS_FRAGMENT_SHADER}, - - // UI colormap fade shader - {GLSL_DEFAULT_VERTEX_SHADER, GLSL_UI_COLORMAP_FADE_FRAGMENT_SHADER}, - - {NULL, NULL}, -}; + char *vertex; + char *fragment; +} gl_baseshaders[NUMSHADERTARGETS]; typedef struct { @@ -95,8 +63,28 @@ boolean HWR_InitShaders(void) for (i = 0; i < NUMSHADERTARGETS; i++) { // set up string pointers for base shaders - gl_shaders[i].vertex = Z_StrDup(gl_shadersources[i].vertex); - gl_shaders[i].fragment = Z_StrDup(gl_shadersources[i].fragment); + if (gl_baseshaders[i].vertex) + { + gl_shaders[i].vertex = Z_StrDup(gl_baseshaders[i].vertex); + } + else + { + CONS_Alert(CONS_ERROR, "HWR_InitShaders: Could not load base vertex shader for%s\n", shaderxlat[i].type); + gl_shaders[i].vertex = Z_StrDup(GLSL_FALLBACK_VERTEX_SHADER); + } + + + if (gl_baseshaders[i].fragment) + { + gl_shaders[i].fragment = Z_StrDup(gl_baseshaders[i].fragment); + } + else + { + CONS_Alert(CONS_ERROR, "HWR_InitShaders: Could not load base fragment shader for%s\n", shaderxlat[i].type); + gl_shaders[i].fragment = Z_StrDup(GLSL_FALLBACK_FRAGMENT_SHADER); + } + + // set shader target indices to correct values gl_shadertargets[i].base_shader = i; gl_shadertargets[i].custom_shader = -1; @@ -450,18 +438,18 @@ customshaderxlat_t shaderxlat[] = {NULL, 0}, }; -void HWR_LoadAllCustomShaders(void) +void HWR_LoadAllBaseShaders(void) { - /* INT32 i; - // read every custom shader + // read every base shader added by iwads. for (i = 0; i < numwadfiles; i++) - HWR_LoadCustomShadersFromFile(i, (type == RET_PK3))); - */ + { + HWR_LoadCustomShadersFromFile(i, (wadfiles[i]->type == RET_PK3), true); + } } -void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3) +void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3, boolean startup) { UINT16 lump; char *shaderdef, *line; @@ -473,7 +461,7 @@ void HWR_LoadCustomShadersFromFile(UINT16 wadnum, boolean PK3) int i; boolean modified_shaders[NUMSHADERTARGETS] = {0}; - if (!gl_shadersavailable) + if (!startup && !gl_shadersavailable) return; lump = HWR_FindShaderDefs(wadnum); @@ -570,7 +558,11 @@ skip_lump: W_ReadLumpPwad(wadnum, shader_lumpnum, shader_source); shader_source[shader_string_length-1] = '\0'; - shader_index = shaderxlat[i].id + NUMSHADERTARGETS; + if (startup) + shader_index = shaderxlat[i].id; + else + shader_index = shaderxlat[i].id + NUMSHADERTARGETS; + if (!modified_shaders[shaderxlat[i].id]) { // this will clear any old custom shaders from previously loaded files @@ -579,26 +571,59 @@ skip_lump: gl_shaders[shader_index].vertex = NULL; Z_Free(gl_shaders[shader_index].fragment); gl_shaders[shader_index].fragment = NULL; + + if (startup) + { + Z_Free(gl_baseshaders[shader_index].vertex); + gl_baseshaders[shader_index].vertex = NULL; + Z_Free(gl_baseshaders[shader_index].fragment); + gl_baseshaders[shader_index].fragment = NULL; + } } + modified_shaders[shaderxlat[i].id] = true; if (shadertype == 1) { - if (gl_shaders[shader_index].vertex) + if (startup) { - CONS_Alert(CONS_WARNING, "HWR_LoadCustomShadersFromFile: %s is overwriting another %s vertex shader from the same addon! (file %s, line %d)\n", shader_lumpname, shaderxlat[i].type, wadfiles[wadnum]->filename, linenum); - Z_Free(gl_shaders[shader_index].vertex); + if (gl_baseshaders[shader_index].vertex) + { + CONS_Alert(CONS_WARNING, "HWR_LoadCustomShadersFromFile: %s is overwriting another %s vertex shader from the same addon! (file %s, line %d)\n", shader_lumpname, shaderxlat[i].type, wadfiles[wadnum]->filename, linenum); + Z_Free(gl_baseshaders[shader_index].vertex); + } + gl_baseshaders[shader_index].vertex = Z_StrDup(shader_source); + } + else + { + if (gl_shaders[shader_index].vertex) + { + CONS_Alert(CONS_WARNING, "HWR_LoadCustomShadersFromFile: %s is overwriting another %s vertex shader from the same addon! (file %s, line %d)\n", shader_lumpname, shaderxlat[i].type, wadfiles[wadnum]->filename, linenum); + Z_Free(gl_shaders[shader_index].vertex); + } + gl_shaders[shader_index].vertex = shader_source; } - gl_shaders[shader_index].vertex = shader_source; } else { - if (gl_shaders[shader_index].fragment) + if (startup) { - CONS_Alert(CONS_WARNING, "HWR_LoadCustomShadersFromFile: %s is overwriting another %s fragment shader from the same addon! (file %s, line %d)\n", shader_lumpname, shaderxlat[i].type, wadfiles[wadnum]->filename, linenum); - Z_Free(gl_shaders[shader_index].fragment); + if (gl_baseshaders[shader_index].fragment) + { + CONS_Alert(CONS_WARNING, "HWR_LoadCustomShadersFromFile: %s is overwriting another %s fragment shader from the same addon! (file %s, line %d)\n", shader_lumpname, shaderxlat[i].type, wadfiles[wadnum]->filename, linenum); + Z_Free(gl_baseshaders[shader_index].fragment); + } + gl_baseshaders[shader_index].fragment = Z_StrDup(shader_source); + } + else + { + if (gl_shaders[shader_index].fragment) + { + CONS_Alert(CONS_WARNING, "HWR_LoadCustomShadersFromFile: %s is overwriting another %s fragment shader from the same addon! (file %s, line %d)\n", shader_lumpname, shaderxlat[i].type, wadfiles[wadnum]->filename, linenum); + Z_Free(gl_shaders[shader_index].fragment); + } + gl_shaders[shader_index].fragment = shader_source; } - gl_shaders[shader_index].fragment = shader_source; } Z_Free(shader_lumpname); @@ -611,21 +636,24 @@ skip_field: } } - for (i = 0; i < NUMSHADERTARGETS; i++) + if (!startup) { - if (modified_shaders[i]) + for (i = 0; i < NUMSHADERTARGETS; i++) { - int shader_index = i + NUMSHADERTARGETS; // index to gl_shaders - gl_shadertargets[i].custom_shader = shader_index; - // if only one stage (vertex/fragment) is defined, the other one - // is copied from the base shaders. - if (!gl_shaders[shader_index].fragment) - gl_shaders[shader_index].fragment = Z_StrDup(gl_shadersources[i].fragment); - if (!gl_shaders[shader_index].vertex) - gl_shaders[shader_index].vertex = Z_StrDup(gl_shadersources[i].vertex); - HWR_CompileShader(shader_index); - if (!gl_shaders[shader_index].compiled) - CONS_Alert(CONS_ERROR, "HWR_LoadCustomShadersFromFile: A compilation error occured for the %s shader in file %s. See the console messages above for more information.\n", shaderxlat[i].type, wadfiles[wadnum]->filename); + if (modified_shaders[i]) + { + int shader_index = i + NUMSHADERTARGETS; // index to gl_shaders + gl_shadertargets[i].custom_shader = shader_index; + // if only one stage (vertex/fragment) is defined, the other one + // is copied from the base shaders. + if (!gl_shaders[shader_index].fragment) + gl_shaders[shader_index].fragment = Z_StrDup(gl_baseshaders[i].fragment); + if (!gl_shaders[shader_index].vertex) + gl_shaders[shader_index].vertex = Z_StrDup(gl_baseshaders[i].vertex); + HWR_CompileShader(shader_index); + if (!gl_shaders[shader_index].compiled) + CONS_Alert(CONS_ERROR, "HWR_LoadCustomShadersFromFile: A compilation error occured for the %s shader in file %s. See the console messages above for more information.\n", shaderxlat[i].type, wadfiles[wadnum]->filename); + } } } diff --git a/src/hardware/hw_shaders.h b/src/hardware/hw_shaders.h index cadd9944c..950d016c5 100644 --- a/src/hardware/hw_shaders.h +++ b/src/hardware/hw_shaders.h @@ -22,430 +22,6 @@ // Generic vertex shader // -#define GLSL_DEFAULT_VERTEX_SHADER \ - "void main()\n" \ - "{\n" \ - "gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;\n" \ - "gl_FrontColor = gl_Color;\n" \ - "gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;\n" \ - "gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;\n" \ - "}\0" - -// reinterpretation of sprite lighting for models -// it's a combination of how it works for normal sprites & papersprites -#define GLSL_MODEL_LIGHTING_VERTEX_SHADER \ - "uniform float lighting;\n" \ - "uniform vec3 light_dir;\n" \ - "uniform float light_contrast;\n" \ - "uniform float light_backlight;\n" \ - "void main()\n" \ - "{\n" \ - "gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;\n" \ - "float light = lighting;\n" \ - "if (length(light_dir) > 0.000001) {\n" \ - "mat4 m4 = gl_ProjectionMatrix * gl_ModelViewMatrix;\n" \ - "mat3 m3 = mat3( m4[0].xyz, m4[1].xyz, m4[2].xyz );\n" \ - "float extralight = -dot(normalize(gl_Normal * m3), normalize(light_dir));\n" \ - "extralight *= light_contrast - light_backlight;\n" \ - "extralight *= lighting / 255.0;\n" \ - "light += extralight * 2.5;\n" \ - "}\n" \ - "light = clamp(light / 255.0, 0.0, 1.0);\n" \ - "gl_FrontColor = vec4(light, light, light, 1.0);\n" \ - "gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;\n" \ - "gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;\n" \ - "}\0" - -// ================== -// Fragment shaders -// ================== - -// -// Generic fragment shader -// - -#define GLSL_DEFAULT_FRAGMENT_SHADER \ - "uniform sampler2D tex;\n" \ - "uniform vec4 poly_color;\n" \ - "void main(void) {\n" \ - "gl_FragColor = texture2D(tex, gl_TexCoord[0].st) * poly_color;\n" \ - "}\0" - -// -// Software fragment shader -// - -// Include GLSL_FLOOR_FUDGES or GLSL_WALL_FUDGES or define the fudges in shaders that use this macro. -#define GLSL_DOOM_COLORMAP_DITHER \ - "float baseValue = max(startmap * STARTMAP_FUDGE - scale * 0.5 * SCALE_FUDGE, cap);\n" \ - "float endResolutionx = scr_resolution.x;\n" \ - "float endResolutiony = scr_resolution.y;\n" \ - "if (scr_resolution.x > 1280.0) {\n" \ - "endResolutionx = scr_resolution.x * 0.5;\n" \ - "}\n" \ - "if (scr_resolution.y > 720.0) {\n" \ - "endResolutiony = scr_resolution.y * 0.5;\n" \ - "}\n" \ - "float zFactor = clamp((z - 192.0) / (6144.0 - 192.0), 0.0, 1.0);\n" \ - "int scaleFactor = int(mix(1.0, 8.0, zFactor));\n" \ - "endResolutionx = endResolutionx * scaleFactor;\n" \ - "endResolutiony = endResolutiony * scaleFactor;\n" \ - "vec2 normalizedPosition = position * vec2(endResolutionx / scr_resolution.x, endResolutiony / scr_resolution.y);\n" \ - "int x = int(mod(normalizedPosition.x, 4.0));\n" \ - "int y = int(mod(normalizedPosition.y, 4.0));\n" \ - "float bayerMatrix[4*4] = float[4*4](\n" \ - "0.0, 8.0, 2.0, 10.0,\n" \ - "12.0, 4.0, 14.0, 6.0,\n" \ - "3.0, 11.0, 1.0, 9.0,\n" \ - "15.0, 7.0, 13.0, 5.0\n" \ - ");\n" \ - "#ifdef SRB2_PALETTE_RENDERING\n" \ - "float threshold = (1.0 - pow(zFactor, 2.0)) * (bayerMatrix[y*4 + x] / 11.0);\n" \ - "#else\n" \ - "float threshold = (1.0 - pow(zFactor, 2.0)) * (bayerMatrix[y*4 + x] / 16.0);\n" \ - "#endif\n" \ - "return mix(baseValue + threshold - 0.5 / 16.0, baseValue, zFactor);\n" - -#define GLSL_DOOM_COLORMAP_NODITHER \ - "return max(startmap * STARTMAP_FUDGE - scale * 0.5 * SCALE_FUDGE, cap);\n" \ - -#define GLSL_DOOM_COLORMAP \ - "uniform vec2 scr_resolution;\n" \ - "float R_DoomColormap(float light, float z, vec2 position)\n" \ - "{\n" \ - "float lightnum = clamp(light / 17.0, 0.0, 15.0);\n" \ - "float lightz = clamp(z / 16.0, 0.0, 127.0);\n" \ - "float startmap = (15.0 - lightnum) * 4.0;\n" \ - "float scale = 160.0 / (lightz + 1.0);\n" \ - "float cap = (155.0 - light) * 0.26;\n" \ - "#ifdef SRB2_LIGHT_DITHER\n" \ - GLSL_DOOM_COLORMAP_DITHER \ - "#else\n" \ - GLSL_DOOM_COLORMAP_NODITHER \ - "#endif\n" \ - "}\n" -// lighting cap adjustment: -// first num (155.0), increase to make it start to go dark sooner -// second num (0.26), increase to make it go dark faster - -#define GLSL_DOOM_LIGHT_EQUATION \ - "float R_DoomLightingEquation(float light)\n" \ - "{\n" \ - "float z = gl_FragCoord.z / gl_FragCoord.w;\n" \ - "float colormap = floor(R_DoomColormap(light, z, gl_FragCoord.xy)) + 0.5;\n" \ - "return clamp(colormap, 0.0, 31.0) / 32.0;\n" \ - "}\n" - -#define GLSL_SOFTWARE_TINT_EQUATION \ - "if (mix(tint_color.a, 0.0, brightmap_mix) > 0.0) {\n" \ - "float color_bright = sqrt((base_color.r * base_color.r) + (base_color.g * base_color.g) + (base_color.b * base_color.b));\n" \ - "float strength = sqrt(mix(9.0 * tint_color.a, 0.0, brightmap_mix));\n" \ - "final_color.r = clamp((color_bright * (tint_color.r * strength)) + (base_color.r * (1.0 - strength)), 0.0, 1.0);\n" \ - "final_color.g = clamp((color_bright * (tint_color.g * strength)) + (base_color.g * (1.0 - strength)), 0.0, 1.0);\n" \ - "final_color.b = clamp((color_bright * (tint_color.b * strength)) + (base_color.b * (1.0 - strength)), 0.0, 1.0);\n" \ - "}\n" - -#define GLSL_SOFTWARE_FADE_EQUATION \ - "float darkness = R_DoomLightingEquation(final_lighting);\n" \ - "if (fade_start > 0.0 || fade_end < 31.0) {\n" \ - "float fs = fade_start / 31.0;\n" \ - "float fe = fade_end / 31.0;\n" \ - "float fd = fe - fs;\n" \ - "darkness = clamp((darkness - fs) * (1.0 / fd), 0.0, 1.0);\n" \ - "}\n" \ - "if (newfade)\n" \ - "{\n" \ - "float colorBrightness = sqrt((final_color.r * final_color.r) + (final_color.g * final_color.g) + (final_color.b * final_color.b));\n" \ - "float fogBrightness = sqrt((fade_color.r * fade_color.r) + (fade_color.g * fade_color.g) + (fade_color.b * fade_color.b));\n" \ - "float colorIntensity = 0.0;\n" \ - "if (colorBrightness < fogBrightness) {\n" \ - "colorIntensity = 1.0 - min(final_color.r, min(final_color.g, final_color.b));\n" \ - "colorIntensity = abs(colorIntensity - (1.0 - max(fade_color.r, max(fade_color.g, fade_color.b))));\n" \ - "} else {\n" \ - "colorIntensity = max(final_color.r, max(final_color.g, final_color.b));\n" \ - "colorIntensity = abs(colorIntensity - min(fade_color.r, min(fade_color.g, fade_color.b)));\n" \ - "}\n" \ - "colorIntensity *= darkness;\n" \ - "colorIntensity *= fade_color.a * 10.0;\n" \ - "if (abs(final_color.r - fade_color.r) <= colorIntensity) {\n" \ - "final_color.r = fade_color.r;\n" \ - "} else if (final_color.r < fade_color.r) {\n" \ - "final_color.r += colorIntensity;\n" \ - "} else {\n" \ - "final_color.r -= colorIntensity;\n" \ - "}\n" \ - "if (abs(final_color.g - fade_color.g) <= colorIntensity) {\n" \ - "final_color.g = fade_color.g;\n" \ - "} else if (final_color.g < fade_color.g) {\n" \ - "final_color.g += colorIntensity;\n" \ - "} else {\n" \ - "final_color.g -= colorIntensity;\n" \ - "}\n" \ - "if (abs(final_color.b - fade_color.b) <= colorIntensity) {\n" \ - "final_color.b = fade_color.b;\n" \ - "} else if (final_color.b < fade_color.b) {\n" \ - "final_color.b += colorIntensity;\n" \ - "} else {\n" \ - "final_color.b -= colorIntensity;\n" \ - "}\n" \ - "} else {\n" \ - "final_color = mix(final_color, fade_color, darkness);\n" \ - "}\n" - -#define GLSL_PALETTE_RENDERING \ - "float tex_pal_idx = texture3D(palette_lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \ - "float z = gl_FragCoord.z / gl_FragCoord.w;\n" \ - "float light_y = clamp(floor(R_DoomColormap(final_lighting, z, gl_FragCoord.xy)), 0.0, 31.0);\n" \ - "vec2 lighttable_coord = vec2((tex_pal_idx + 0.5) / 256.0, (light_y + 0.5) / 32.0);\n" \ - "vec4 final_color = texture2D(lighttable_tex, lighttable_coord);\n" \ - "final_color.a = texel.a * poly_color.a;\n" \ - "gl_FragColor = final_color;\n" \ - -#define GLSL_SOFTWARE_FRAGMENT_SHADER \ - "#ifdef SRB2_PALETTE_RENDERING\n" \ - "uniform sampler2D tex;\n" \ - "uniform sampler2D brightmap;\n" \ - "uniform vec4 poly_color;\n" \ - "uniform float lighting;\n" \ - "uniform sampler3D palette_lookup_tex;\n" \ - "uniform sampler2D lighttable_tex;\n" \ - GLSL_DOOM_COLORMAP \ - "void main(void) {\n" \ - "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - "float brightmap_mix = floor(texture2D(brightmap, gl_TexCoord[0].st).r);\n" \ - "float light_gain = (255.0 - lighting) * brightmap_mix;\n" \ - "float final_lighting = lighting + light_gain;\n" \ - GLSL_PALETTE_RENDERING \ - "}\n" \ - "#else\n" \ - "uniform sampler2D tex;\n" \ - "uniform sampler2D brightmap;\n" \ - "uniform vec4 poly_color;\n" \ - "uniform vec4 tint_color;\n" \ - "uniform vec4 fade_color;\n" \ - "uniform float lighting;\n" \ - "uniform float fade_start;\n" \ - "uniform float fade_end;\n" \ - "uniform bool newfade;\n" \ - GLSL_DOOM_COLORMAP \ - GLSL_DOOM_LIGHT_EQUATION \ - "void main(void) {\n" \ - "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - "vec4 base_color = texel * poly_color;\n" \ - "vec4 final_color = base_color;\n" \ - "float brightmap_mix = floor(texture2D(brightmap, gl_TexCoord[0].st).r);\n" \ - "float light_gain = (255.0 - lighting) * brightmap_mix;\n" \ - "float final_lighting = lighting + light_gain;\n" \ - GLSL_SOFTWARE_TINT_EQUATION \ - GLSL_SOFTWARE_FADE_EQUATION \ - "final_color.a = texel.a * poly_color.a;\n" \ - "gl_FragColor = final_color;\n" \ - "}\n" \ - "#endif\0" - -// hand tuned adjustments for light level calculation -#define GLSL_FLOOR_FUDGES \ - "#define STARTMAP_FUDGE 1.06\n" \ - "#define SCALE_FUDGE 1.15\n" - -#define GLSL_WALL_FUDGES \ - "#define STARTMAP_FUDGE 1.05\n" \ - "#define SCALE_FUDGE 2.2\n" - -#define GLSL_FLOOR_FRAGMENT_SHADER \ - "#version 120\n" \ - GLSL_FLOOR_FUDGES \ - GLSL_SOFTWARE_FRAGMENT_SHADER - -#define GLSL_WALL_FRAGMENT_SHADER \ - "#version 120\n" \ - GLSL_WALL_FUDGES \ - GLSL_SOFTWARE_FRAGMENT_SHADER - -// same as above but multiplies results with the lighting value from the -// accompanying vertex shader (stored in gl_Color) -#define GLSL_SOFTWARE_MODEL_LIGHTING_FRAGMENT_SHADER \ - GLSL_WALL_FUDGES \ - "#ifdef SRB2_PALETTE_RENDERING\n" \ - "uniform sampler2D tex;\n" \ - "uniform sampler2D brightmap;\n" \ - "uniform sampler3D palette_lookup_tex;\n" \ - "uniform sampler2D lighttable_tex;\n" \ - "uniform vec4 poly_color;\n" \ - "uniform float lighting;\n" \ - GLSL_DOOM_COLORMAP \ - "void main(void) {\n" \ - " vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - "#ifdef SRB2_MODEL_LIGHTING\n" \ - "texel *= gl_Color;\n" \ - "#endif\n" \ - "float final_lighting = gl_Color.r * 255.0;\n" \ - "float brightmap_mix = floor(texture2D(brightmap, gl_TexCoord[0].st).r);\n" \ - "float light_gain = (255.0 - final_lighting) * brightmap_mix;\n" \ - "final_lighting += light_gain;\n" \ - GLSL_PALETTE_RENDERING \ - "}\n" \ - "#else\n" \ - "uniform sampler2D tex;\n" \ - "uniform sampler2D brightmap;\n" \ - "uniform vec4 poly_color;\n" \ - "uniform vec4 tint_color;\n" \ - "uniform vec4 fade_color;\n" \ - "uniform float fade_start;\n" \ - "uniform float fade_end;\n" \ - "uniform bool newfade;\n" \ - GLSL_DOOM_COLORMAP \ - GLSL_DOOM_LIGHT_EQUATION \ - "void main(void) {\n" \ - "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - "vec4 base_color = texel * poly_color;\n" \ - "vec4 final_color = base_color;\n" \ - "float final_lighting = gl_Color.r * 255.0;\n" \ - "float brightmap_mix = floor(texture2D(brightmap, gl_TexCoord[0].st).r);\n" \ - "float light_gain = (255.0 - final_lighting) * brightmap_mix;\n" \ - "final_lighting += light_gain;\n" \ - GLSL_SOFTWARE_TINT_EQUATION \ - GLSL_SOFTWARE_FADE_EQUATION \ - "final_color.a = texel.a * poly_color.a;\n" \ - "gl_FragColor = final_color;\n" \ - "}\n" \ - "#endif\0" - -// -// Water surface shader -// -// Mostly guesstimated, rather than the rest being built off Software science. -// Still needs to distort things underneath/around the water... -// - -#define GLSL_WATER_TEXEL \ - "float water_z = (gl_FragCoord.z / gl_FragCoord.w) / 2.0;\n" \ - "float a = -pi * (water_z * freq) + (leveltime * speed);\n" \ - "float sdistort = sin(a) * amp * 1.5;\n" \ - "float cdistort = cos(a) * amp * 2.2;\n" \ - "vec4 texel = texture2D(tex, vec2(gl_TexCoord[0].s - sdistort, gl_TexCoord[0].t - cdistort));\n" - -#define GLSL_WATER_FRAGMENT_SHADER \ - "#version 120\n" \ - GLSL_FLOOR_FUDGES \ - "const float freq = 0.03;\n" \ - "const float amp = 0.025;\n" \ - "const float speed = 1.6;\n" \ - "const float pi = 3.14159;\n" \ - "#ifdef SRB2_PALETTE_RENDERING\n" \ - "uniform sampler2D tex;\n" \ - "uniform sampler2D brightmap;\n" \ - "uniform sampler3D palette_lookup_tex;\n" \ - "uniform sampler2D lighttable_tex;\n" \ - "uniform vec4 poly_color;\n" \ - "uniform float lighting;\n" \ - "uniform float leveltime;\n" \ - GLSL_DOOM_COLORMAP \ - "void main(void) {\n" \ - GLSL_WATER_TEXEL \ - "float brightmap_mix = floor(texture2D(brightmap, gl_TexCoord[0].st).r);\n" \ - "float light_gain = (255.0 - lighting) * brightmap_mix;\n" \ - "float final_lighting = lighting + light_gain;\n" \ - GLSL_PALETTE_RENDERING \ - "}\n" \ - "#else\n" \ - "uniform sampler2D tex;\n" \ - "uniform sampler2D brightmap;\n" \ - "uniform vec4 poly_color;\n" \ - "uniform vec4 tint_color;\n" \ - "uniform vec4 fade_color;\n" \ - "uniform float lighting;\n" \ - "uniform float fade_start;\n" \ - "uniform float fade_end;\n" \ - "uniform bool newfade;\n" \ - "uniform float leveltime;\n" \ - GLSL_DOOM_COLORMAP \ - GLSL_DOOM_LIGHT_EQUATION \ - "void main(void) {\n" \ - GLSL_WATER_TEXEL \ - "vec4 base_color = texel * poly_color;\n" \ - "vec4 final_color = base_color;\n" \ - "float brightmap_mix = floor(texture2D(brightmap, gl_TexCoord[0].st).r);\n" \ - "float light_gain = (255.0 - lighting) * brightmap_mix;\n" \ - "float final_lighting = lighting + light_gain;\n" \ - GLSL_SOFTWARE_TINT_EQUATION \ - GLSL_SOFTWARE_FADE_EQUATION \ - "final_color.a = texel.a * poly_color.a;\n" \ - "gl_FragColor = final_color;\n" \ - "}\n" \ - "#endif\0" - -// -// Fog block shader -// -// Alpha of the planes themselves are still slightly off -- see HWR_FogBlockAlpha -// - -// The floor fudges are used, but should the wall fudges be used instead? or something inbetween? -// or separate values for floors and walls? (need to change more than this shader for that) -#define GLSL_FOG_FRAGMENT_SHADER \ - "#version 120\n" \ - GLSL_FLOOR_FUDGES \ - "uniform vec4 tint_color;\n" \ - "uniform vec4 fade_color;\n" \ - "uniform float lighting;\n" \ - "uniform float fade_start;\n" \ - "uniform float fade_end;\n" \ - "uniform bool newfade;\n" \ - GLSL_DOOM_COLORMAP \ - GLSL_DOOM_LIGHT_EQUATION \ - "void main(void) {\n" \ - "vec4 base_color = gl_Color;\n" \ - "vec4 final_color = base_color;\n" \ - "float brightmap_mix = 0.0;\n" \ - "float light_gain = 0.0;\n" \ - "float final_lighting = lighting + light_gain;\n" \ - GLSL_SOFTWARE_TINT_EQUATION \ - GLSL_SOFTWARE_FADE_EQUATION \ - "gl_FragColor = final_color;\n" \ - "}\0" - -// -// Sky fragment shader -// Modulates poly_color with gl_Color -// -#define GLSL_SKY_FRAGMENT_SHADER \ - "uniform sampler2D tex;\n" \ - "uniform vec4 poly_color;\n" \ - "void main(void) {\n" \ - "gl_FragColor = texture2D(tex, gl_TexCoord[0].st) * gl_Color * poly_color;\n" \ - "}\0" - -// Shader for the palette rendering postprocess step -#define GLSL_PALETTE_POSTPROCESS_FRAGMENT_SHADER \ - "uniform sampler2D tex;\n" \ - "uniform sampler3D palette_lookup_tex;\n" \ - "uniform sampler1D palette_tex;\n" \ - "void main(void) {\n" \ - "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - "float tex_pal_idx = texture3D(palette_lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \ - "float palette_coord = (tex_pal_idx + 0.5) / 256.0;\n" \ - "vec4 final_color = texture1D(palette_tex, palette_coord);\n" \ - "gl_FragColor = final_color;\n" \ - "}\0" - -// Applies a palettized colormap fade to tex -#define GLSL_UI_COLORMAP_FADE_FRAGMENT_SHADER \ - "uniform sampler2D tex;\n" \ - "uniform float lighting;\n" \ - "uniform sampler3D palette_lookup_tex;\n" \ - "uniform sampler2D lighttable_tex;\n" \ - "void main(void) {\n" \ - "vec4 texel = texture2D(tex, gl_TexCoord[0].st);\n" \ - "float tex_pal_idx = texture3D(palette_lookup_tex, vec3((texel * 63.0 + 0.5) / 64.0))[0] * 255.0;\n" \ - "vec2 lighttable_coord = vec2((tex_pal_idx + 0.5) / 256.0, (lighting + 0.5) / 32.0);\n" \ - "gl_FragColor = texture2D(lighttable_tex, lighttable_coord);\n" \ - "}\0" - -// -// Generic vertex shader -// - #define GLSL_FALLBACK_VERTEX_SHADER \ "void main()\n" \ "{\n" \ @@ -466,15 +42,4 @@ "gl_FragColor = texture2D(tex, gl_TexCoord[0].st) * poly_color;\n" \ "}\0" -// -// Sky fragment shader -// Modulates poly_color with gl_Color -// -#define GLSL_SKY_FRAGMENT_SHADER \ - "uniform sampler2D tex;\n" \ - "uniform vec4 poly_color;\n" \ - "void main(void) {\n" \ - "gl_FragColor = texture2D(tex, gl_TexCoord[0].st) * gl_Color * poly_color;\n" \ - "}\0" - #endif diff --git a/src/w_wad.c b/src/w_wad.c index a54212400..e9a667ffe 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1076,7 +1076,7 @@ UINT16 W_InitFile(const char *filename, boolean mainfile, boolean startup, boole #ifdef HWRENDER // Read shaders from file if (rendermode == render_opengl && (vid.glstate == VID_GL_LIBRARY_LOADED)) - HWR_LoadCustomShadersFromFile(numwadfiles - 1, (type == RET_PK3)); + HWR_LoadCustomShadersFromFile(numwadfiles - 1, (type == RET_PK3), false); #endif // HWRENDER // check if compatmode is needed