我正在使用这个着色器,结果如下:
<script id="per-fragment-lighting-vs2" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec2 aTextureCoord;
uniform mat4 uMVMatrix;
uniform mat4 uMV2Matrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;
varying vec2 vTextureCoord;
varying vec3 vTransformedNormal;
varying vec4 vPosition;
void main(void) {
gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0);
vTextureCoord = aTextureCoord;
vTransformedNormal = uNMatrix * aVertexNormal;
}
</script>
<script id="per-fragment-lighting-fs2" type="x-shader/x-fragment">
precision mediump float;
varying vec2 vTextureCoord;
varying vec3 vTransformedNormal;
varying vec4 vPosition;
uniform float uMaterialShininess;
uniform vec3 uAmbientColor;
uniform vec3 uPointLightingLocation;
uniform vec3 uPointLightingSpecularColor;
uniform vec3 uPointLightingDiffuseColor;
uniform sampler2D uSampler;
void main(void) {
vec4 fragmentColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
gl_FragColor = fragmentColor;
}
</script>
但是如果我在着色器上添加一个变量,它会完全改变结果,尽管它没有在片段着色器上使用:
<script id="per-fragment-lighting-vs2" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec2 aTextureCoord;
uniform mat4 uMVMatrix;
uniform mat4 uMV2Matrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;
varying vec2 vTextureCoord;
varying vec3 vTransformedNormal;
varying vec4 vPosition;
void main(void) {
gl_Position = uMVMatrix * vec4(aVertexPosition, 1.0);
vTextureCoord = aTextureCoord;
vTransformedNormal = uNMatrix * aVertexNormal;
**vPosition = vec4(1,1,1,1);**
}
</script>
你能帮我解释一下这里发生了什么吗?
谢谢!!