OpenGL ES中的标识符,初始化和局部变量

时间:2012-09-15 23:10:49

标签: 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'

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

1 个答案:

答案 0 :(得分:4)

我尝试编译代码。问题似乎是因为你使用浮动,1f,2f,3f等

而是尝试1.,2.,3。这就是我总是在着色器程序中定义浮点的方法。 我成功地用Mali Shader编译器编译了这个。所以它应该适用于S2,因为S2中有一个Mali GPU。