Skip to content

Instantly share code, notes, and snippets.

@xoppa
Created October 12, 2015 20:42
Show Gist options
  • Star 32 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xoppa/33589b7d5805205f8f08 to your computer and use it in GitHub Desktop.
Save xoppa/33589b7d5805205f8f08 to your computer and use it in GitHub Desktop.
very basic outline shader
#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif
const float offset = 1.0 / 128.0;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
void main()
{
vec4 col = texture2D(u_texture, v_texCoords);
if (col.a > 0.5)
gl_FragColor = col;
else {
float a = texture2D(u_texture, vec2(v_texCoords.x + offset, v_texCoords.y)).a +
texture2D(u_texture, vec2(v_texCoords.x, v_texCoords.y - offset)).a +
texture2D(u_texture, vec2(v_texCoords.x - offset, v_texCoords.y)).a +
texture2D(u_texture, vec2(v_texCoords.x, v_texCoords.y + offset)).a;
if (col.a < 1.0 && a > 0.0)
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.8);
else
gl_FragColor = col;
}
}
attribute vec4 a_position;
attribute vec2 a_texCoord0;
uniform mat4 u_projTrans;
varying vec2 v_texCoords;
void main()
{
v_texCoords = a_texCoord0;
gl_Position = u_projTrans * a_position;
}
@xijniN
Copy link

xijniN commented Oct 7, 2023

I adapted it to gamemaker :D

varying vec2 v_vTexcoord;
varying vec4 v_vColour;

uniform float u_size;
uniform vec4 u_col; 

void main()
{
	vec4 col = texture2D(gm_BaseTexture, v_vTexcoord);
	if (col.a > 0.5)
	{
		gl_FragColor = col;
	}
	else 
	{
		float a = texture2D(gm_BaseTexture, vec2(v_vTexcoord.x + u_size, v_vTexcoord.y)).a +
			texture2D(gm_BaseTexture, vec2(v_vTexcoord.x, v_vTexcoord.y - u_size)).a +
			texture2D(gm_BaseTexture, vec2(v_vTexcoord.x - u_size, v_vTexcoord.y)).a +
			texture2D(gm_BaseTexture, vec2(v_vTexcoord.x, v_vTexcoord.y + u_size)).a;
		if (col.a < 1.0 && a > 0.0)
		{
			gl_FragColor = u_col;
		}
		else
		{
			gl_FragColor = col;
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment