我在使用 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'
我对着色器语言没有太多经验,所以我不确定从哪里开始解决这个问题。任何帮助和指点将不胜感激!