iPhone opengl es:顶点着色器中出错
我试图通过向场景添加一些照明来扩展着色器的功能。我在顶点着色器中添加了一系列新变量iPhone opengl es:顶点着色器中出错,iphone,opengl-es,glsl,Iphone,Opengl Es,Glsl,我试图通过向场景添加一些照明来扩展着色器的功能。我在顶点着色器中添加了一系列新变量 attribute vec4 Position; // 1 attribute vec4 SourceColor; // 2 attribute vec3 Normal; attribute vec4 Sample; attribute vec3 DiffuseMaterial; varying vec4 DestinationColor; // 3 uniform mat4 Projection; uni
attribute vec4 Position; // 1
attribute vec4 SourceColor; // 2
attribute vec3 Normal;
attribute vec4 Sample;
attribute vec3 DiffuseMaterial;
varying vec4 DestinationColor; // 3
uniform mat4 Projection;
uniform mat4 Modelview;
uniform mat3 NormalMatrix;
uniform vec3 LightPosition;
uniform vec3 AmbientMaterial;
uniform vec3 SpecularMaterial;
uniform float Shininess;
void main(void) { // 4
vec3 N = NormalMatrix * Normal;
vec3 L = normalize(LightPosition);
vec3 E = vec3(0, 0, 1);
vec3 H = normalize(L + E);
float df = max(0.0, dot(N, L));
float sf = max(0.0, dot(N, H));
sf = pow(sf, Shininess);
vec3 color = AmbientMaterial + df * DiffuseMaterial + sf * SpecularMaterial;
DestinationColor = vec4(color, 1);
// DestinationColor = SourceColor;
gl_Position = Projection * Modelview * Position;
}
但是当我这样做的时候
_normalSlot = glGetAttribLocation(programHandle, "Normal");
我总是得到0或-1的值。有人有什么想法吗?0是属性位置的正常值。在片段着色器中不使用DestinationColor Variable时,最有可能返回-1。如何始终获得0或-1?执行之间是否不一致,或者您是否做了一些使其为0的操作,然后更改了一些使其为-1的操作?实际上现在只是0。。。我再也看不见-1了。0值困扰我的原因是我有GlenableVertexAttributeArray(_normalSlot);后来在代码中,当_normalslot的值为0时,我的代码崩溃了。从顶点着色器代码中可以猜到,我正在尝试向场景中添加光源。任何提示/帮助/指导都将不胜感激