Affine Effect Shader

A cheap try at reproducing the Affine Effect of older consoles for 3D games.

 

Shader code
shader_type spatial;

render_mode unshaded, cull_disabled, depth_prepass_alpha;

uniform float affineRadius = 4.0;
uniform float affineIntensity = 400;

uniform sampler2D image : source_color, repeat_enable;

uniform vec2 uv_scale = vec2(1.0,1.0);
varying float vertex_force;

void vertex() {
	vec3 vertex_world_pos = (MODEL_MATRIX*vec4(VERTEX,1.0f)).xyz;
	float true_dist = distance(CAMERA_POSITION_WORLD, vertex_world_pos);
	
	if (true_dist <= 0.001){
		vertex_force = 1.0/affineIntensity*length(UV)+1.0;
		
	}
	else {
		vertex_force = affineRadius/true_dist/affineIntensity*length(UV)+1.0;	
	}
	
}

void fragment() {
	vec2 new_uv = UV;
	if (uv_scale[0] > 0.0f || uv_scale[1] > 0.0f){
		
		new_uv[0] *= uv_scale[0];
		new_uv[1] *= uv_scale[1];
	
	}

	vec4 new_image;
	new_image = texture( image, new_uv*vertex_force);
	
	ALBEDO = new_image.rgb;
	ALPHA = new_image.a;
	
	
}

Tags
90s, affine, effect, ps1, psx, retro
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

Mech Gunfire Effect – Smoke Shader

Voronoi Guard Effect Shader

Mech Gunfire Effect – Muzzleflash Shader

Subscribe
Notify of
guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
laffcat
28 days ago

nice work, but afaik this one-liner in vertex() – taken from a PSX shader by dsoft20 – gets the job done:

POSITION /= abs(POSITION.w);  // discard depth for affine mapping

(but ive only ever used it in gd3, for the record)

laffcat
28 days ago
Reply to  PbmnLuv

weird. the shader in question also has this line, i assumed it was for the position rounding in the shader but maybe it’s needed for the affine trick too:

VERTEX = VERTEX;  // it breaks without this - not sure why
DmLPresents
9 days ago
Reply to  PbmnLuv

You need to build the vertex position first:

//build the position default matrix
POSITION = PROJECTION_MATRIX * MODELVIEW_MATRIX * vec4(VERTEX, 1.0); 
// discard the perspective corrections
POSITION /= abs(POSITION.w);