yquake2remaster/stuff/shaders/world_warp.frag
Ricardo Garcia 930872b358 Add resolution scaling to Vulkan renderer
This commit adds a new cvar called vk_pixel_size that represents how big
pixels should look in the rendered world in order to simulate lower
screen resolutions. With its default value of 1 everything looks normal,
but with bigger sizes (e.g. 4) the rendered world starts to look
"pixelated" due to pixels appearing bigger.

To implement the effect, the viewport and scissor are modified when
drawing the world so the rendering results cover a smaller area in the
top-left corner of the image.

The post-processing fragment shader is used to scale the image back to
the swapchain size before drawing UI elements on top of it.

The UI is not affected by this change, so the existing UI scaling
options continue to work as before with no changes, adding some
flexibility to the mix.

Related to feature request #588.
2020-12-24 10:14:39 +01:00

40 lines
1.1 KiB
GLSL

#version 450
#extension GL_ARB_separate_shader_objects : enable
// Underwater screen warp effect similar to what software renderer provides.
// Pixel size to simulate lower screen resolutions is used to restore world to full screen size.
layout(push_constant) uniform PushConstant
{
layout(offset = 68) float time;
layout(offset = 72) float scale;
layout(offset = 76) float scrWidth;
layout(offset = 80) float scrHeight;
layout(offset = 84) float pixelSize;
} pc;
layout(set = 0, binding = 0) uniform sampler2D sTexture;
layout(location = 0) out vec4 fragmentColor;
#define PI 3.1415
void main()
{
vec2 uv = vec2(gl_FragCoord.x / pc.scrWidth, gl_FragCoord.y / pc.scrHeight);
if (pc.time > 0)
{
float sx = pc.scale - abs(pc.scrWidth / 2.0 - gl_FragCoord.x) * 2.0 / pc.scrWidth;
float sy = pc.scale - abs(pc.scrHeight / 2.0 - gl_FragCoord.y) * 2.0 / pc.scrHeight;
float xShift = 2.0 * pc.time + uv.y * PI * 10;
float yShift = 2.0 * pc.time + uv.x * PI * 10;
vec2 distortion = vec2(sin(xShift) * sx, sin(yShift) * sy) * 0.00666;
uv += distortion;
}
uv /= pc.pixelSize;
fragmentColor = texture(sTexture, uv);
}