# PREIMAGE ATTACK

created on
,
text published on
A noisy red and black video game cover. Fuzzy text reads PREIMAGE ATTACK
https://pulustelu.itch.io/preimage-attack

PREIMAGE ATTACK is a crunchy fast-paced rat blaster, made for NOISE JAM 2. Survive for as long as you can, build up your combo, and GET LOST IN THE NOISE

This was a great first gamejam experience ! I loved the process of learning how to use Godot, starting with a very basic barebones 3D environment and working up from there.

One of the things I’m the proudest of in the game is the use of shaders to really drown the screen in noise:

Screenshot with strange wavey patterns running across the screen
Screenshot of an explosion with odd colors running across it

And a video:

[Flashing lights warning]
Look at the crunchy shaders. How is this done?

The trick is a bit of “byte mucking” with the screen texture. Here’s the shader code in question. Note that this sample is edited; I’ve removed the part that adds a final layer of pixel noise on top of the final crunched up result.

shader_type canvas_item;

uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
uniform float fuckedup : hint_range(0.0, 1.0, 0.1);
uniform float fuckedup2 : hint_range(0.0, 1.0, 0.1);

void fragment() {
  vec4 sample = texture(screen_texture, UV);
  // (point 1)
  vec2 weird = sample.rg * fuckedup2 + sample.ba * (1.0 - fuckedup2);
  // (point 2)
  COLOR.rgb = texture(screen_texture, weird).rgb * fuckedup + sample.rgb * (1.0 - fuckedup);
}

The screen texture represents a buffer that’s already been drawn by the shader pipeline before this particular fragment shader runs. Sampling this texture will therefore yield colors that would have been drawn to the screen before this shader. It holds color data. Therefore, vec2 weird = ...; (in point 1) is doing a weird operation, flattening the 4 channels of a RGBA color to just 2. It uses fuckedup2 as the parameter to a weighted sum between the red+green channels and the blue+alpha channels.

Even more weird is that weird is then used as an index into the screen texture itself! In point 2, we compute texture(screen_texture, weird) which will, effectively, sample a color from an unpredictable point on the screen. This color then merges with the original sample using another weighted sum (this time with parameter fuckedup1). Effectively, it uses the screen texture both as a color palette and as a palette index. The result isn’t fully random, because regions of identical color in the screen texture will all map to the same output color, and very small changes of UV generally map to equally small changes in weird. (But not always.) Fucked up indeed.