【问题标题】:x-ray vertex shader opengl es 2.0X射线顶点着色器opengl es 2.0
【发布时间】:2014-08-30 03:04:22
【问题描述】:

我找到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 和适用于 Android 的 openGL ES 2.0 运行相同的模型。我的 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

【问题讨论】:

  • 您在 GL 日志中看到了什么错误?
  • 我编辑了帖子以包含 LogCat 输出;谢谢。

标签: android opengl-es


【解决方案1】:
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 页。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多