Fix rounding problems
Fragment shader does not know about the projection matrix, thus it has to take the pixel ratio into account.
This commit is contained in:
@@ -194,7 +194,7 @@ ol.render.webgl.Replay.prototype.replay = function(context,
|
|||||||
'indicesBuffer must not be null');
|
'indicesBuffer must not be null');
|
||||||
context.bindBuffer(goog.webgl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer_);
|
context.bindBuffer(goog.webgl.ELEMENT_ARRAY_BUFFER, this.indicesBuffer_);
|
||||||
|
|
||||||
var locations = this.setUpProgram_(gl, context, size);
|
var locations = this.setUpProgram_(gl, context, size, pixelRatio);
|
||||||
|
|
||||||
// set the "uniform" values
|
// set the "uniform" values
|
||||||
var projectionMatrix = ol.transform.reset(this.projectionMatrix_);
|
var projectionMatrix = ol.transform.reset(this.projectionMatrix_);
|
||||||
@@ -657,9 +657,10 @@ ol.render.webgl.ImageReplay.prototype.createTextures_ = function(textures, image
|
|||||||
* @param {WebGLRenderingContext} gl gl.
|
* @param {WebGLRenderingContext} gl gl.
|
||||||
* @param {ol.webgl.Context} context Context.
|
* @param {ol.webgl.Context} context Context.
|
||||||
* @param {ol.Size} size Size.
|
* @param {ol.Size} size Size.
|
||||||
|
* @param {number} pixelRatio Pixel ratio.
|
||||||
* @return {ol.render.webgl.imagereplay.shader.Default.Locations} Locations.
|
* @return {ol.render.webgl.imagereplay.shader.Default.Locations} Locations.
|
||||||
*/
|
*/
|
||||||
ol.render.webgl.ImageReplay.prototype.setUpProgram_ = function(gl, context, size) {
|
ol.render.webgl.ImageReplay.prototype.setUpProgram_ = function(gl, context, size, pixelRatio) {
|
||||||
// get the program
|
// get the program
|
||||||
var fragmentShader = ol.render.webgl.imagereplay.defaultshader.fragment;
|
var fragmentShader = ol.render.webgl.imagereplay.defaultshader.fragment;
|
||||||
var vertexShader = ol.render.webgl.imagereplay.defaultshader.vertex;
|
var vertexShader = ol.render.webgl.imagereplay.defaultshader.vertex;
|
||||||
@@ -1335,9 +1336,10 @@ ol.render.webgl.LineStringReplay.prototype.getDeleteResourcesFunction = function
|
|||||||
* @param {WebGLRenderingContext} gl gl.
|
* @param {WebGLRenderingContext} gl gl.
|
||||||
* @param {ol.webgl.Context} context Context.
|
* @param {ol.webgl.Context} context Context.
|
||||||
* @param {ol.Size} size Size.
|
* @param {ol.Size} size Size.
|
||||||
|
* @param {number} pixelRatio Pixel ratio.
|
||||||
* @return {ol.render.webgl.linestringreplay.shader.Default.Locations} Locations.
|
* @return {ol.render.webgl.linestringreplay.shader.Default.Locations} Locations.
|
||||||
*/
|
*/
|
||||||
ol.render.webgl.LineStringReplay.prototype.setUpProgram_ = function(gl, context, size) {
|
ol.render.webgl.LineStringReplay.prototype.setUpProgram_ = function(gl, context, size, pixelRatio) {
|
||||||
// get the program
|
// get the program
|
||||||
var fragmentShader, vertexShader;
|
var fragmentShader, vertexShader;
|
||||||
fragmentShader =
|
fragmentShader =
|
||||||
@@ -1384,6 +1386,7 @@ ol.render.webgl.LineStringReplay.prototype.setUpProgram_ = function(gl, context,
|
|||||||
gl.uniform1f(locations.u_miterLimit, this.state_.miterLimit);
|
gl.uniform1f(locations.u_miterLimit, this.state_.miterLimit);
|
||||||
}
|
}
|
||||||
gl.uniform2fv(locations.u_size, size);
|
gl.uniform2fv(locations.u_size, size);
|
||||||
|
gl.uniform1f(locations.u_pixelRatio, pixelRatio);
|
||||||
|
|
||||||
return locations;
|
return locations;
|
||||||
};
|
};
|
||||||
@@ -1398,7 +1401,9 @@ ol.render.webgl.LineStringReplay.prototype.setUpProgram_ = function(gl, context,
|
|||||||
*/
|
*/
|
||||||
ol.render.webgl.LineStringReplay.prototype.drawReplay_ = function(gl, context, skippedFeaturesHash, hitDetection) {
|
ol.render.webgl.LineStringReplay.prototype.drawReplay_ = function(gl, context, skippedFeaturesHash, hitDetection) {
|
||||||
//Save GL parameters.
|
//Save GL parameters.
|
||||||
|
/** @type {number} */
|
||||||
var tmpDepthFunc = gl.getParameter(gl.DEPTH_FUNC);
|
var tmpDepthFunc = gl.getParameter(gl.DEPTH_FUNC);
|
||||||
|
/** @type {boolean} */
|
||||||
var tmpDepthMask = gl.getParameter(gl.DEPTH_WRITEMASK);
|
var tmpDepthMask = gl.getParameter(gl.DEPTH_WRITEMASK);
|
||||||
|
|
||||||
gl.enable(gl.DEPTH_TEST);
|
gl.enable(gl.DEPTH_TEST);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
//! COMMON
|
//! COMMON
|
||||||
varying float v_round;
|
varying float v_round;
|
||||||
varying vec4 v_roundVertex;
|
varying vec2 v_roundVertex;
|
||||||
varying float v_halfWidth;
|
varying float v_halfWidth;
|
||||||
|
|
||||||
|
|
||||||
@@ -26,20 +26,15 @@ void main(void) {
|
|||||||
v_round = 0.0;
|
v_round = 0.0;
|
||||||
float direction = a_direction / abs(a_direction);
|
float direction = a_direction / abs(a_direction);
|
||||||
vec4 projPos = u_projectionMatrix * vec4(a_position, 0., 1.);
|
vec4 projPos = u_projectionMatrix * vec4(a_position, 0., 1.);
|
||||||
|
v_roundVertex = projPos.xy;
|
||||||
if (mod(a_direction, 3.0) == 0.0 || mod(a_direction, 17.0) == 0.0) {
|
if (mod(a_direction, 3.0) == 0.0 || mod(a_direction, 17.0) == 0.0) {
|
||||||
vec2 dirVect = a_nextPos - a_position;
|
vec2 dirVect = a_nextPos - a_position;
|
||||||
vec2 normal = normalize(vec2(-dirVect.y, dirVect.x));
|
vec2 normal = normalize(vec2(-dirVect.y, dirVect.x));
|
||||||
offset = v_halfWidth * normal * direction;
|
offset = v_halfWidth * normal * direction;
|
||||||
if (mod(a_direction, 2.0) == 0.0) {
|
|
||||||
v_roundVertex = projPos + u_offsetScaleMatrix * vec4(0., 0., 0., 0.);
|
|
||||||
}
|
|
||||||
} else if (mod(a_direction, 5.0) == 0.0 || mod(a_direction, 13.0) == 0.0) {
|
} else if (mod(a_direction, 5.0) == 0.0 || mod(a_direction, 13.0) == 0.0) {
|
||||||
vec2 dirVect = a_lastPos - a_position;
|
vec2 dirVect = a_lastPos - a_position;
|
||||||
vec2 normal = normalize(vec2(dirVect.y, -dirVect.x));
|
vec2 normal = normalize(vec2(dirVect.y, -dirVect.x));
|
||||||
offset = v_halfWidth * normal * direction;
|
offset = v_halfWidth * normal * direction;
|
||||||
if (mod(a_direction, 2.0) == 0.0) {
|
|
||||||
v_roundVertex = projPos + u_offsetScaleMatrix * vec4(0., 0., 0., 0.);
|
|
||||||
}
|
|
||||||
} else if (mod(a_direction, 19.0) == 0.0 || mod(a_direction, 23.0) == 0.0) {
|
} else if (mod(a_direction, 19.0) == 0.0 || mod(a_direction, 23.0) == 0.0) {
|
||||||
vec2 dirVect = a_nextPos - a_position;
|
vec2 dirVect = a_nextPos - a_position;
|
||||||
vec2 tmpNormal = normalize(vec2(-dirVect.y, dirVect.x));
|
vec2 tmpNormal = normalize(vec2(-dirVect.y, dirVect.x));
|
||||||
@@ -50,7 +45,6 @@ void main(void) {
|
|||||||
offset = normal * direction * miterLength;
|
offset = normal * direction * miterLength;
|
||||||
if (mod(a_direction, 2.0) == 0.0) {
|
if (mod(a_direction, 2.0) == 0.0) {
|
||||||
v_round = 1.0;
|
v_round = 1.0;
|
||||||
v_roundVertex = projPos + u_offsetScaleMatrix * vec4(0., 0., 0., 0.);
|
|
||||||
} else if (miterLength > u_miterLimit) {
|
} else if (miterLength > u_miterLimit) {
|
||||||
offset = tmpNormal * direction * v_halfWidth;
|
offset = tmpNormal * direction * v_halfWidth;
|
||||||
}
|
}
|
||||||
@@ -106,7 +100,6 @@ void main(void) {
|
|||||||
offset = normal * length;
|
offset = normal * length;
|
||||||
if (mod(a_direction, 2.0) == 0.0) {
|
if (mod(a_direction, 2.0) == 0.0) {
|
||||||
v_round = 1.0;
|
v_round = 1.0;
|
||||||
v_roundVertex = projPos + u_offsetScaleMatrix * vec4(0., 0., 0., 0.);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!degenerate) {
|
if (!degenerate) {
|
||||||
@@ -121,11 +114,13 @@ void main(void) {
|
|||||||
uniform float u_opacity;
|
uniform float u_opacity;
|
||||||
uniform vec4 u_color;
|
uniform vec4 u_color;
|
||||||
uniform vec2 u_size;
|
uniform vec2 u_size;
|
||||||
|
uniform float u_pixelRatio;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
if (v_round > 0.0) {
|
if (v_round > 0.0) {
|
||||||
vec2 windowCoords = vec2((v_roundVertex.x + 1.0) / 2.0 * u_size.x, (v_roundVertex.y + 1.0) / 2.0 * u_size.y);
|
vec2 windowCoords = vec2((v_roundVertex.x + 1.0) / 2.0 * u_size.x * u_pixelRatio,
|
||||||
if (length(windowCoords - gl_FragCoord.xy) > v_halfWidth) {
|
(v_roundVertex.y + 1.0) / 2.0 * u_size.y * u_pixelRatio);
|
||||||
|
if (length(windowCoords - gl_FragCoord.xy) > v_halfWidth * u_pixelRatio) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user