我目前正在研究一个粒子系统,其中每个粒子都是一个点。我正在使用着色器为粒子着色。我希望粒子根据其位置改变颜色。但是,当我尝试在片段和顶点着色器中包含一个额外的向量变量时,我的着色器无法编译。
片段着色器:
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);
}
顶点着色器:
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);
}