VOGONS

Common searches


First post, by Azarien

User metadata
Rank Oldbie
Rank
Oldbie

I've reimplemented Unreal's software renderer texture dithering in Q2.
What do you think?

image.png

image.png

image.png

It's a bit buggy now because even the hud is dithered, and I think Unreal didn't do that effect for the models.

If anyone is interested in the code, this is Unreal's texture filtering effect as an OpenGL 2.1 fragment shader:

uniform sampler2D uTexture;
uniform vec2 uTexelSize;
uniform vec2 uUnrealCoords[4];

void main()
{
vec2 m = mod(gl_FragCoord.xy - 0.5, 2.0);
int idx = int(m.x + 2.0 * m.y);
gl_FragColor = texture2D(uTexture, gl_TexCoord[0].xy + uUnrealCoords[idx] * uTexelSize);
}

where uTexelSize is set to inverse of texture size (1/width, 1/height) and uUnrealCoords is
{{0.25f, 0.00f}, {0.50f, 0.75f}, {0.75f, 0.50f}, {0.00f, 0.25f}}

The texture itself uses nearest-neighbour filtering (gl_texturemode GL_NEAREST in Q2).

Reply 2 of 6, by leileilol

User metadata
Rank l33t++
Rank
l33t++

Shouldn't eat much as it's a fragment shader that tells it to pick different texels. The bad part of quick texturing filter shaders is that mipmaps have to be sacrificed (otherwise mipmaps will also be filtered incorrectly)

(though, software kernel filtering can also be done in software and has been done before. Fabien Sanglard adapted an old flipcode kernel filter routine )

apsosig.png
long live PCem

Reply 3 of 6, by Azarien

User metadata
Rank Oldbie
Rank
Oldbie
mrau wrote:

how much fps does that thing eat?

570 fps for GL_LINEAR_MIPMAP_LINEAR vs 560 fps for GL_NEAREST with the shader on Q6600, HD5770, 1280x960.

The bad part of quick texturing filter shaders is that mipmaps have to be sacrificed (otherwise mipmaps will also be filtered incorrectly)

I also sacrificed multitexturing, and some other effects like translucent breakable glass at the beginning of Unit 1.1.
Reimplementing them in the shader would be much more work, though I think someone has probably done that already.

Reply 4 of 6, by DracoNihil

User metadata
Rank Oldbie
Rank
Oldbie

Wait why would you get more framerate in Trilinear vs Nearest Neighbour?

“I am the dragon without a name…”
― Κυνικός Δράκων

Reply 6 of 6, by DracoNihil

User metadata
Rank Oldbie
Rank
Oldbie

Oh... Sorry the way that was written confused me alot.

You did a good job with the shader by the way, it looks pretty legit to my eyes. Too bad I hate the effect haha... I always turned that thing off in Unreal's software renderer.

“I am the dragon without a name…”
― Κυνικός Δράκων