GLSL fragment shader gets vertex position
<script id="shader-triangle-fs" type="x-shader/x-fragment">
precision mediump float;
uniform vec4 colorVec;
uniform sampler2D uSampler;
varying highp vec2 vTextureCoord;
varying vec3 vVertexPosition;
void main(void) {
float dist = length(vVertexPosition.xy - gl_FragCoord.xy);
float att = 100.0/dist;
vec4 color = vec4(att,att,att, 1);
vec4 texture = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));
gl_FragColor = color;
}
</script>
<script id="shader-triangle-vs" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec2 aTextureCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
varying highp vec2 vTextureCoord;
varying vec3 vVertexPosition;
void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
vTextureCoord = aTextureCoord;
vVertexPosition = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>
In float dist = length(vVertexPosition.xy - gl_FragCoord.xy);, what I want to get is the distance from the current vertex coordinate to the fragment coordinate.
But always I get it.
http://puu.sh/6rbva.jpg
http://puu.sh/6rbzM.jpg
(I used triangleStrip.)
These images show vVertexPosition.xy - gl_FragCoord.xy = 0so vVertexPosition.xy == gl_FragCoord.xy.
Why is this happening?
And how to get the distance from the current vertex position to the current FragCoord?