diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 2405aff09..119444af6 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -177,6 +177,7 @@ bool FRenderState::ApplyShader() activeShader->muAlphaThreshold.Set(mAlphaThreshold); activeShader->muLightIndex.Set(mLightIndex); // will always be -1 for now activeShader->muClipSplit.Set(mClipSplit); + activeShader->muViewHeight.Set(viewheight); if (mGlowEnabled) { diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index edd0da1d9..e287c7215 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -73,7 +73,7 @@ CVAR(Bool, gl_billboard_particles, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Int, gl_enhanced_nv_stealth, 3, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CUSTOM_CVAR(Int, gl_fuzztype, 0, CVAR_ARCHIVE) { - if (self < 0 || self > 7) self = 0; + if (self < 0 || self > 8) self = 0; } EXTERN_CVAR (Float, transsouls) diff --git a/src/gl/shaders/gl_shader.cpp b/src/gl/shaders/gl_shader.cpp index d551106a4..4af1ef5a1 100644 --- a/src/gl/shaders/gl_shader.cpp +++ b/src/gl/shaders/gl_shader.cpp @@ -254,6 +254,7 @@ bool FShader::Load(const char * name, const char * vert_prog_lump, const char * muClipHeight.Init(hShader, "uClipHeight"); muClipHeightDirection.Init(hShader, "uClipHeightDirection"); muAlphaThreshold.Init(hShader, "uAlphaThreshold"); + muViewHeight.Init(hShader, "uViewHeight"); muTimer.Init(hShader, "timer"); lights_index = glGetUniformLocation(hShader, "lights"); @@ -392,6 +393,7 @@ static const FDefaultShader defaultshaders[]= {"Jagged Fuzz", "shaders/glsl/fuzz_jagged.fp"}, {"Noise Fuzz", "shaders/glsl/fuzz_noise.fp"}, {"Smooth Noise Fuzz", "shaders/glsl/fuzz_smoothnoise.fp"}, + {"Software Fuzz", "shaders/glsl/fuzz_software.fp"}, {NULL,NULL} }; diff --git a/src/gl/shaders/gl_shader.h b/src/gl/shaders/gl_shader.h index f41f7467b..6265d62a9 100644 --- a/src/gl/shaders/gl_shader.h +++ b/src/gl/shaders/gl_shader.h @@ -284,6 +284,7 @@ class FShader FBufferedUniform1f muClipHeight; FBufferedUniform1f muClipHeightDirection; FBufferedUniform1f muAlphaThreshold; + FBufferedUniform1i muViewHeight; FBufferedUniform1f muTimer; int lights_index; @@ -397,7 +398,7 @@ public: } }; -#define FIRST_USER_SHADER 12 +#define FIRST_USER_SHADER 13 enum { diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 43c86b712..c4ecd2877 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -2111,6 +2111,7 @@ OptionValue "FuzzStyle" 4, "$OPTVAL_TRANSLUCENTFUZZ" 6, "$OPTVAL_NOISE" 7, "$OPTVAL_SMOOTHNOISE" + 8, "$OPTVAL_SOFTWARE" //5, "$OPTVAL_JAGGEDFUZZ" I can't see any difference between this and 4 so it's disabled for now. } diff --git a/wadsrc/static/shaders/glsl/fuzz_software.fp b/wadsrc/static/shaders/glsl/fuzz_software.fp new file mode 100644 index 000000000..cf905bb6e --- /dev/null +++ b/wadsrc/static/shaders/glsl/fuzz_software.fp @@ -0,0 +1,52 @@ +// Fuzz effect as rendered by the software renderer +uniform float timer; + +#define FUZZTABLE 50 +#define FUZZ_RANDOM_X_SIZE 100 +#define FRACBITS 16 +#define fixed_t int + +int fuzz_random_x_offset[FUZZ_RANDOM_X_SIZE] = +{ + 75, 76, 21, 91, 56, 33, 62, 99, 61, 79, + 95, 54, 41, 18, 69, 43, 49, 59, 10, 84, + 94, 17, 57, 46, 9, 39, 55, 34,100, 81, + 73, 88, 92, 3, 63, 36, 7, 28, 13, 80, + 16, 96, 78, 29, 71, 58, 89, 24, 1, 35, + 52, 82, 4, 14, 22, 53, 38, 66, 12, 72, + 90, 44, 77, 83, 6, 27, 48, 30, 42, 32, + 65, 15, 97, 20, 67, 74, 98, 85, 60, 68, + 19, 26, 8, 87, 86, 64, 11, 37, 31, 47, + 25, 5, 50, 51, 23, 2, 93, 70, 40, 45 +}; + +int fuzzoffset[FUZZTABLE] = +{ + 6, 11, 6, 11, 6, 6, 11, 6, 6, 11, + 6, 6, 6, 11, 6, 6, 6, 11, 15, 18, + 21, 6, 11, 15, 6, 6, 6, 6, 11, 6, + 11, 6, 6, 11, 15, 6, 6, 11, 15, 18, + 21, 6, 6, 6, 6, 11, 6, 6, 11, 6 +}; + +vec4 ProcessTexel() +{ + vec2 texCoord = vTexCoord.st; + vec4 basicColor = getTexel(texCoord); + + // Ideally fuzzpos would be an uniform and differ from each sprite so that overlapping demons won't get the same shade for the same pixel + int next_random = int(abs(mod(timer * 35.0, float(FUZZ_RANDOM_X_SIZE)))); + int fuzzpos = (/*fuzzpos +*/ fuzz_random_x_offset[next_random] * FUZZTABLE / 100) % FUZZTABLE; + + int x = int(gl_FragCoord.x); + int y = int(gl_FragCoord.y); + + fixed_t fuzzscale = (200 << FRACBITS) / uViewHeight; + int scaled_x = (x * fuzzscale) >> FRACBITS; + int fuzz_x = fuzz_random_x_offset[scaled_x % FUZZ_RANDOM_X_SIZE] + fuzzpos; + fixed_t fuzzcount = FUZZTABLE << FRACBITS; + fixed_t fuzz = ((fuzz_x << FRACBITS) + y * fuzzscale) % fuzzcount; + float alpha = float(fuzzoffset[fuzz >> FRACBITS]) / 32.0; + + return vec4(0.0, 0.0, 0.0, basicColor.a * alpha); +} diff --git a/wadsrc/static/shaders/glsl/shaderdefs.i b/wadsrc/static/shaders/glsl/shaderdefs.i index c8fcf7b6b..15d68428e 100644 --- a/wadsrc/static/shaders/glsl/shaderdefs.i +++ b/wadsrc/static/shaders/glsl/shaderdefs.i @@ -48,6 +48,9 @@ uniform float uGlobVis; // uGlobVis = R_GetGlobVis(r_visibility) / 32.0 // dynamic lights uniform int uLightIndex; +// Software fuzz scaling +uniform int uViewHeight; + // quad drawer stuff #ifdef USE_QUAD_DRAWER uniform mat4 uQuadVertices;