2016-07-06 20 views
-1

次のフラグメントシェーダで何が問題になっていますか? GLSL 4.0ではOKをコンパイルしますが、GLSL 1.30では失敗します。GLSL 1.30でフラグメントシェーダをコンパイルする際にエラーが発生しました

これはコードです:

// Fragment Shader 
"uniform sampler2D texture;\n" 
"uniform sampler1D cmap;\n" 
"uniform float minZ;\n" 
"uniform float maxZ;\n" 
"\n" 
"void main() {\n" 
" float height = texture2D(texture,gl_TexCoord[0].st);\n" 
" float lum = (height-minZ)/(maxZ-minZ);\n" 
" if (lum > 1.0) lum = 1.0;\n" 
" else if (lum < 0.0) lum = 0.0;\n" 
" gl_FragColor = texture1D(cmap, lum);\n" 
"}" 

これらのエラーです:

FRAGMENT glCompileShader "" FAILED 
FRAGMENT Shader "" infolog: 
0:7(2): error: initializer of type vec4 cannot be assigned to variable of type float 
0:8(2): error: initializer of type vec4 cannot be assigned to variable of type float 
0:9(6): error: operands to relational operators must be scalar and numeric 
0:9(6): error: if-statement condition must be scalar boolean 
0:9(17): error: value of type float cannot be assigned to variable of type vec4 
0:10(11): error: operands to relational operators must be scalar and numeric 
+1

"* GLSL 4.0では正常にコンパイルできますが、GLSL 3.0では失敗します。*" GLSL 3.0はありません。 GLSL *** ES *** 3.00がありますが、それは異なっています。 –

+1

GLSL 3.5 *どこでも*ありません。 –

答えて

4

まあ、エラーメッセージが間違っているかについて非常に明確である:

0:7(2): error: initializer of type vec4 cannot be assigned to variable of type float 
---- 
float height = texture2D(texture,gl_TexCoord[0].st); 

ひとつはできませんvec4をフロートに割り当てます。 texture2Dはvec4を返します。したがって、floatの高さに割り当てることはできません。 ソリューション:texture2Dtexture1Dためgl_TexCoordが同じ150で削除されましたので、この他に

float height = texture2D(texture,gl_TexCoord[0].st).r; 

は、シェーダは、任意のGLSLバージョン> 140でコンパイルしてはならない行く:あなたは一つのチャンネルのみを必要なときにスウィズル演算子を追加します。メソッドは150でtexture関数に置き換えられました。実際に#version 400でglslバージョンを指定していますか?

3

コンパイルするバージョンを宣言する必要があります。 Core Language GLSL @ opengl.orgで説明されているように:

#versionディレクティブは、シェーダ内の他のものよりも前に現れ、空白とコメントを保存する必要があります。 #versionディレクティブが先頭に表示されない場合、それは1.10とみなされます。これはほとんどあなたが望むものではありません。

関連する問題