PDA

View Full Version : Fragment Shader Gradient?



Mr_Approved
01-16-2012, 01:47 PM
Hey guys i have a fragment shader and vertex shader and so far i can get a nice looking background image, but i cant get 2 colours to fade in to each other, the problem im having is that the Y position is 1.0 and then at the bottom -1.0, now i can just work out the different and take it away, because if i did then once it hit the middle of the screen it will be the second colour, does anyone know a algorithm to work it out?

this is my fragment shader code


#version 120

varying vec3 pos_fragment;
uniform vec3 color1;
uniform vec3 color2;
vec3 actuallyColor;
vec3 difference;

void main()
{
//col = (pos.y * col1.y/col2.y);
gl_FragColor = vec4((color1.rgb) * (pos_fragment.y * pos_fragment.y), 1.0); // white
}

and here is my vertex shader


#version 120

attribute vec3 position;
varying vec3 pos_fragment;

void main()
{
gl_Position = vec4(position.xyz,1);
pos_fragment = vec3(position.xyz);
}


cheers

The Little Body
01-16-2012, 05:23 PM
What do you want exactely, color1 at y=-1 and color2 at y=1 ?