opengl-es - OpenGL ES 中的标识符、初始化和局部变量

标签 opengl-es shader fragment-shader

我在使用 ES 着色器时遇到了一些莫名其妙的问题,现在我几乎没有想法了。

这是一些代码:

.. precision mediump float;
.. #define STEP (1f/6f)

53 vec4 colorBasedOnProgress(float progress){
54     float transition = (progress/STEP);   
55     transition = floor(transition);
56     float position = (progress - (transition*STEP)) * 7f;
57    
58     position = clamp(position, 0f, 1f);
59    
60     vec4 result;
61        
62     if(transition == 0f){
63         result = mix(COLOR_VIOLET, COLOR_BLUE, position);
64     } else if (transition == 1f){
65         result = mix(COLOR_BLUE, COLOR_GREEN, position);
66     } else if (transition == 2f){
67         result = mix(COLOR_GREEN, COLOR_YELLOW, position);
68     } else if (transition == 3f){
69         result = mix(COLOR_YELLOW, COLOR_ORANGE, position);
70     } else if (transition == 4f){
71         result = mix(COLOR_ORANGE, COLOR_RED, position);
72     } else if (transition == 5f){
73         result = mix(COLOR_RED, COLOR_VIOLET, position);
74     }
75     
76     return result;
77 }

我遇到的错误(仅在设备 Galaxy S2 上):

09-16 00:05:04.415: I/InitialLoadingScreen(29901): 0:54: L0001: Expected token ')', found 'identifier'
09-16 00:05:04.415: I/InitialLoadingScreen(29901): 0:55: L0002: Undeclared variable 'transition'
09-16 00:05:04.415: I/InitialLoadingScreen(29901): 0:56: L0002: Undeclared variable 'transition'
09-16 00:05:04.415: I/InitialLoadingScreen(29901): 0:58: L0002: Undeclared variable 'position'
09-16 00:05:04.415: I/InitialLoadingScreen(29901): 0:62: L0002: Undeclared variable 'transition'
09-16 00:05:04.415: I/InitialLoadingScreen(29901): 0:64: L0001: Expected literal or '(', got 'else'
09-16 00:05:04.415: I/InitialLoadingScreen(29901): 0:66: L0001: Expected literal or '(', got 'else'
09-16 00:05:04.415: I/InitialLoadingScreen(29901): 0:68: L0001: Expected literal or '(', got 'else'
09-16 00:05:04.415: I/InitialLoadingScreen(29901): 0:70: L0001: Expected literal or '(', got 'else'
09-16 00:05:04.415: I/InitialLoadingScreen(29901): 0:72: L0001: Expected literal or '(', got 'else'

我对着色器语言没有太多经验,所以我不确定从哪里开始解决这个问题。任何帮助和指示将不胜感激!

最佳答案

我尝试编译你的代码。问题似乎是由于您使用了 float 、1f、2f、3f 等

请尝试 1.,2.,3。这就是我在着色器程序中定义浮点的方式。 我用 Mali Shader 编译器成功编译了它。所以它应该可以在 S2 上运行,因为 S2 中有一个 Mali GPU。

关于opengl-es - OpenGL ES 中的标识符、初始化和局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12443177/

相关文章:

opengl - mat4x4 与 vec4 相乘的顺序有什么区别?

c++ - OpenglES 2.0 顶点着色器属性

Libgdx 自定义着色器逐顶点属性

ios - 自定义着色器 SCNProgram iOS 9 Scenekit

opengl - 我可以有两个统一的缓冲区指向 OpenGL 中的同一个 block 吗?

android - Android 中的自定义相机滤镜

ios - 如何在 IOS Swift OpenglES 1.0/1.1/2.0 上将文本和图像绘制为纹理

android - 如何抓取Android的GLSurfaceView创建的OpenGL上下文?

glsl - GLSL ES 中的统一与属性

opengl - 在具有多重采样的 GLSL 4.1 片段着色器中使用 'discard'