GLSL Vertex Gradient

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
je06
Prole
Posts: 1
Joined: Sat Dec 12, 2015 10:31 pm

GLSL Vertex Gradient

Post by je06 »

I'm trying to write a GLSL fragment shader that will apply a gradient based off of three point on screen's color.

My code so far

Code: Select all

uniform vec2 p1; //Point 1 xy coordinates on screen
uniform vec2 p2; //Point 2  xy coordinates on screen
uniform vec2 p3; //Point 3  xy coordinates on screen

uniform number p12; //Distance between Point 1 and 2
uniform number p23; //Distance between Point 2 and 3
uniform number p31; //Distance between Point 3 and 1

uniform vec3 c1; //The Color of Point 1
uniform vec3 c2; //The Color of Point 2
uniform vec3 c3; //The Color of Point 3

vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
{

	number p1D = sqrt(pow(screen_coords.x-p1.x,2)+pow(screen_coords.y-p1.y,2));
	number p2D = sqrt(pow(screen_coords.x-p2.x,2)+pow(screen_coords.y-p2.y,2));
	number p3D = sqrt(pow(screen_coords.x-p3.x,2)+pow(screen_coords.y-p3.y,2));
	
	if (p1D < 0) {
		p1D = p1D * -1;
	}
	if (p2D < 0) {
		p2D = p2D * -1;
	}
	if (p3D < 0) {
		p3D = p3D * -1;
	}
	
	vec3 final_color = c1*(p1D/p12) + c2*(p2D/p23) + c3*(p3D/p31);
	
	
	return vec4(final_color,1);
}
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 5 guests