2

我在使用 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'

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

4

1 回答 1

4

我试着编译你的代码。由于您使用了浮点数、1f、2f、3f 等,问题似乎即将到来

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

于 2012-09-16T05:43:04.233 回答