1
我正在使用WebGL,並在我的.html文件中編寫頂點着色器,它與我的程序的.js文件一起使用。這主要涉及照明。'構造函數'有太多的參數[頂點着色器]
我收到的錯誤是:頂點着色器無法編譯。錯誤日誌是:ERROR:0:29:「構造」:參數太多 ERROR:0:32:「點」:沒有匹配的重載函數發現
29和32對應於那些在下面的代碼(見註釋)
這裏是我的頂點着色器代碼
<script id="vertex-shader" type="x-shader/x-vertex">
attribute vec4 a_Position;
attribute vec4 a_Color;
attribute vec3 a_Normal;
attribute vec2 a_Texture;
uniform mat4 u_MvpMatrix;
uniform mat3 u_NormalMatrix;
uniform vec3 uAmbientColor; // all 3 of these passed in .js
uniform vec3 uLightPosition; //
uniform vec3 uLightColor; //
varying vec4 v_Color;
varying vec2 v_Texture;
varying vec3 vLightWeighting;
void
main()
{
vec4 eyeLightPos = vec4(0.0, 200.0, 0.0, 1.0); // Line 29***
vec4 eyePosition = u_MvpMatrix * vec4(a_Position, 1.0); // vertex position in the eye space
vec3 normal = normalize(u_NormalMatrix * a_Normal);
float nDotL = max(dot(normal, eyeLightPos), 0.0); // Line 32***
v_Color = vec4(a_Color.rgb * nDotL, a_Color.a);
v_Texture = a_Texture;
////*************
vec3 eyeLightVector = normalize(eyeLightPos.xyz - eyePosition.xyz);
vec3 eyeViewVector = -normalize(eyePosition.xyz); // eye position is at (0, 0, 0) in the eye space
vec3 eyeReflectVector = -reflect(eyeLightVector, normal);
float shininess = 16.0;
float specular = pow(max(dot(eyeViewVector, eyeReflectVector),0.0), shininess);;
vLightWeighting = uAmbientColor + uLightColor * nDotL + uLightColor * specular;
}
</script>
這究竟是爲什麼?如果您希望看到其他內容,請告訴我。
'vec4 eyePosition = u_MvpMatrix * a_Position;'也可能工作。對於屬性'w',如果未提供,默認爲'1'。 – gman