2
我對ES着色器有一些模糊的問題,現在我幾乎沒有想法。OpenGL 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 }
的錯誤我收到(只是在設備上,銀河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'
我沒有與着色器語言太多的經驗,所以我不確定從哪裏開始解決這個問題。任何幫助和指針,將不勝感激!
就是這樣!非常感謝!非常感謝將我指向Mali Shader編譯器,看起來非常有用! – Delyan
此外,我挖掘了語言規範的適當部分,1f表示法確實是非法語法[Chapter 4.1.4:Floats]: floating-constant:fractional-constant [exponent-part] |數字序列指數部分 小數常數:數字序列。數字序列|數字序列。 | 。數字序列 我懷疑Gallium驅動程序正在使用類似於C的着色器編譯器(我認爲它們基於LLVM),並且它們將它視爲有效的語法。 再次,非常感謝! – Delyan
很高興爲您服務!此外[馬裏開發工具](http://www.malideveloper.com/developer-resources/tools/index.php)非常方便。我發現在仿真器上運行並檢查我的代碼會更好,加快調試和整體開發速度 – Slartibartfast