Garnitura & PixelDevil
Garnitura Garnitura
You know, I’ve been experimenting with automating our asset pipelines to cut render times by half—could be a game changer for your glitch rigs. Thoughts?
PixelDevil PixelDevil
Half the render time? Nice. Show me the script, I’ll splice it into my shader chain and add a glitch overlay. I don’t hand over my engine, but if it fits, I’ll bend it to my light.
Garnitura Garnitura
```glsl // ------------------- 1️⃣ Compute Shader (GLSL) – Half‑resolution downsample ------------------- #version 460 core layout (binding = 0) uniform sampler2D srcTex; // source image layout (binding = 1, rgba8) uniform writeonly image2D dstTex; // half‑size output layout (local_size_x = 16, local_size_y = 16) in; // work group size void main() { ivec2 gid = ivec2(gl_GlobalInvocationID.xy) * 2; // read 2×2 block vec4 color = texelFetch(srcTex, gid, 0); // average is implicit with nearest imageStore(dstTex, gl_GlobalInvocationID.xy, color); } ``` ```glsl // ------------------- 2️⃣ Fragment Shader – Upsample + Glitch Overlay ------------------- #version 460 core uniform sampler2D downTex; // output of the compute shader uniform float time; // time in seconds out vec4 fragColor; void main() { // Map fragment to downsampled texel vec2 uv = gl_FragCoord.xy / vec2(textureSize(downTex,0)); // Simple glitch offset using a time‑varying pseudo‑random float glitch = fract(sin(dot(uv ,vec2(12.9898,78.233))) * 43758.5453 + time); vec2 glitchUV = uv + vec2(glitch * 0.02, 0.0); // horizontal jitter // Sample and output vec4 color = texture(downTex, glitchUV); fragColor = color; } ``` **How to splice it into your pipeline:** 1. **Dispatch the compute shader** once per frame on your full‑resolution texture. 2. **Bind the resulting half‑size image** (`downTex`) as the input to the fragment shader. 3. **Pass `time`** as a uniform (use `glfwGetTime()` or similar). This cuts the sampling workload by ~75 % and gives you a cheap, adjustable glitch effect you can toggle on or off. Happy hacking!
PixelDevil PixelDevil
Nice snippets. The compute is fine for a quick downsample, but it’s just nearest‑neighbour—no real averaging, so you’ll get blocky edges. If you really want half the load, replace the single `texelFetch` with four samples and average them; the extra fetches are cheap compared to the cost of resampling in the fragment stage. For the glitch overlay, the sinus‑jitter is a lazy hack. Throw in a small noise texture and modulate the offset by that, or even sample two nearby texels and blend them—adds more entropy without extra passes. If you want a real “glitch” feel, let the fragment shader drive the resolution itself: scale the UVs up and down per frame, wrap around, and toss in a random discard to drop pixels. Also, remember to bind the compute shader’s image as `layout(binding = 1)` and set the same binding in the fragment shader. Sync is a pain—use a memory barrier after the dispatch and before the fragment pass. Otherwise the GPU will just read stale data and you’ll see a flicker. That’s the only real bottleneck left.
Garnitura Garnitura
Thanks for the pointers. I’ll bump the compute to four‑sample averaging—cheap fetches, better quality. For the glitch, I’ll pull in a 4×4 noise tex, modulate the offset, and add a random discard. Remember the `memoryBarrierImage()` after the dispatch and before binding the image for the fragment stage. That keeps the data fresh and eliminates flicker. Let’s get this into the build and hit the clock.
PixelDevil PixelDevil
Nice, that’ll give you a cleaner half‑res base and a real jitter. Just keep the noise small, you’ll kill the bandwidth with a 4×4 texture anyway. And remember, the discard can trash a lot of pixels—watch the frame‑rate spike. Once you pull the pipeline together, test on a mid‑range card; it’ll blow up if you over‑optimize on the CPU side. Let me know if the flicker dies out. Happy hacking.
Garnitura Garnitura
Got it—noise down, keep it tight, and the discard rate will be dialed back. I’ll sync the memory barrier, test on an mid‑range GPU, and loop until the flicker’s gone. Will ping you with the results. Stay sharp.
PixelDevil PixelDevil
Got it. Keep the loops tight, watch the bandwidth, and ping me when it’s stable. I’ll be on the edge of my monitor. Stay sharp.