I am currently working on a particle system in which each particle is a point. I am using shaders to color the particles. I would like the particle to change colors based on its position. However, when I try to include an extra vector variable in my fragment and vertex shaders, my shaders do not compile.
Fragment shader:
varying vec3 normal;
varying vec3 vertex_to_light_vector;
varying vec3 vertex_to_eye_vector;
//out vec3 color;
//varying float red;
//varying float green;
//varying float blue;
//black body radiation color map
void main ()
{
const vec4 AmbientColor = vec4(0.2, 0.2, 0.2, 0.2);
const vec4 DiffuseColor = vec4(0.0, 0.1,0.3, 0.1);
const vec4 SpecularColor = vec4(1.0, 1.0, 1.0, 0.1);
vec3 normalized_normal = normalize(normal);
vec3 normalized_vertex_to_light_vector = normalize(vertex_to_light_vector);
vec3 normalized_vertex_to_eye_vector = normalize(vertex_to_eye_vector);
vec3 bisector = normalize(vertex_to_light_vector + vertex_to_eye_vector);
float DiffuseTerm = clamp(max(0.0, dot(normalized_normal, normalized_vertex_to_light_vector)), 0.0, 1.0);
float SpecularTerm = clamp(max(0.0, dot(normalized_normal, bisector)), 0.0, 1.0);
gl_FragColor = DiffuseColor * DiffuseTerm;
//+ SpecularColor * pow(SpecularTerm, 80.0);
}
Vertex shader:
varying vec3 normal;
varying vec3 vertex_to_light_vector;
varying vec3 vertex_to_eye_vector;
//out vec3 color;
//varying float red;
//varying float green;
//varying float blue;
//varying vec2 texture_coordinate;
//uniform sample2D my_color_texture;
void main ()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; //gettingfinal position in projection space
if (gl_Position[0] > 0.5){
// color = vec3(1.0, 0.0, 0.0);
// red =1.0;
// green = 0.0;
// blue = 0.0;
}
else {
// color = vec3(0.0, 0.0, 1.0);
// color[0] = 0.0;
// color[1] = 0.0;
// color[2] = 1.0;
// red = 0.0;
// green = 0.0;
// blue = 1.0;
}
normal = gl_NormalMatrix * gl_Normal;
vec4 vertex_in_modelView_space = gl_ModelViewMatrix * gl_Vertex;
vertex_to_light_vector = vec3(gl_LightSource[0].position - vertex_in_modelView_space);
vertex_to_eye_vector = vec3(-vertex_in_modelView_space);
//texture_coordinate = vec2(gl_MultiTexCoord0);
}