x射线顶点着色器opengl es 2.0

时间:2014-08-29 18:39:23

标签: android opengl-es

我找到this vertex shader

// Application to vertex shader
varying vec3 N;
varying vec3 I;
varying vec4 Cs;

void main()
{
    vec4 P = gl_ModelViewMatrix * gl_Vertex;
    I  = P.xyz - vec3 (0);
    N  = gl_NormalMatrix * gl_Normal;
    Cs = gl_Color;
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

此着色器适用于我在OSX上运行的3D模型。但是,我正在尝试为openFrameworks和openGL ES 2.0 for Android运行相同的模型。我的3D模型正确加载,我的片段着色器似乎正在为openGL ES 2.0正确编译。但是,我的顶点着色器将无法编译。有谁知道如何更改此代码,以便它可以在Android上运行?

这是我在LogCat中看到的:

08-29 13:47:24.499: V/ofShader(26349): checkAndCreateProgram(): creating GLSL program

08-29 13:47:24.499: E/ofShader(26349): setupShaderFromSource(): GL_VERTEX_SHADER shader failed to compile

08-29 13:47:24.499: E/(26349): ofShader: GL_VERTEX_SHADER shader reports:

08-29 13:47:24.499: E/(26349): Vertex shader compilation failed.

08-29 13:47:24.499: E/(26349): ERROR: 0:8: 'gl_ModelViewMatrix' : undeclared identifier 

08-29 13:47:24.499: E/(26349): ERROR: 0:8: 'gl_Vertex' : undeclared identifier 

08-29 13:47:24.499: E/(26349): ERROR: 0:8: '=' :  cannot convert from 'float' to '4-component vector of float'

08-29 13:47:24.499: E/(26349): ERROR: 0:10: 'gl_NormalMatrix' : undeclared identifier 

08-29 13:47:24.499: E/(26349): ERROR: 0:10: 'gl_Normal' : undeclared identifier 

08-29 13:47:24.499: E/(26349): ERROR: 0:10: 'assign' :  cannot convert from 'float' to 'varying 3-component vector of float'

08-29 13:47:24.499: E/(26349): ERROR: 0:11: 'gl_Color' : undeclared identifier 

08-29 13:47:24.499: E/(26349): ERROR: 0:11: 'assign' :  cannot convert from 'float' to 'varying 4-component vector of float'

08-29 13:47:24.499: E/(26349): ERROR: 0:12: 'gl_ModelViewProjectionMatrix' : undeclared identifier 

08-29 13:47:24.499: E/(26349): ERROR: 0:12: 'assign' :  cannot convert from 'float' to 'Position 4-component vector of float'

08-29 13:47:24.499: E/(26349): ERROR: 10 compilation errors.  No code generated.

08-29 13:47:24.499: V/ofShader(26349): setupShaderFromSource(): GL_FRAGMENT_SHADER shader compiled

08-29 13:47:24.499: V/(26349): linkProgram(): attaching GL_FRAGMENT_SHADER shader to program 22

08-29 13:47:24.499: E/ofShader(26349): checkProgramLinkStatus(): program failed to link

1 个答案:

答案 0 :(得分:2)

vec4 P = gl_ModelViewMatrix * gl_Vertex;
         ^^^^^^^^^^^^^^^^^^   ^^^^^^^^^ nope
I  = P.xyz - vec3 (0);
N  = gl_NormalMatrix * gl_Normal;
     ^^^^^^^^^^^^^^^   ^^^^^^^^^ nope
Cs = gl_Color;
     ^^^^^^^^ nope
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^   ^^^^^^^^^ nope

ES 2.0不提供这些内置插件。你必须使用通用的制服/属性来自己提供/计算它们。

ES 2.0仅在顶点着色器阶段提供两个内置变量:

highp vec4 gl_Position; // should be written to
mediump float gl_PointSize; // may be written to

请参阅GLSL ES 1.0 spec,第7.1节,第59页。