Mein Code ist (innerhalb der void main):Wie kann man int in GLSL (WebGL) floaten?
float res;
for(int i=0; i<15; i++) {
res = float(i)/15.0;
//...
}
Leider float(i)/15.0
Wenn ich i/15.0
nur einen Syntaxfehler bei ich schreiben, dann ist der Fehler:
wrong operand types no operation '/' exists that takes a left-hand operand of type 'mediump int' and a right operand of type 'const float' (or there is no acceptable conversion)
Wenn Ich versuche einfach i/15
dann ist das Ergebnis eine ganze Zahl, aber ich möchte einen Float bekommen. Wie ist es möglich int
zu float
zu übertragen?
In Javascript wird diese Konvertierung automatisch durchgeführt - res = i/15; – jeff
Dies ist GLSL, nicht Javascript –
Ich [fügte Ihren Code oben in glslsandbox.com und es funktioniert gut] (http://glslsandbox.com/e#28445.0). Bist du sicher, dass du diesen Fehler nicht von einer anderen Zeile in deinem Shader erhalten hast? – gman