diff --git a/axes.js b/axes.js index 0258993..e33fee7 100644 --- a/axes.js +++ b/axes.js @@ -413,7 +413,7 @@ proto.draw = function(params) { var v = (i + 1 + (j^1)) % 3 if(this.zeroEnable[v]) { //Check if zero line in bounds - if(bounds[0][v] <= 0 && bounds[1][v] >= 0) { + if(Math.min(bounds[0][v], bounds[1][v]) <= 0 && Math.max(bounds[0][v], bounds[1][v]) >= 0) { this._lines.drawZero(u, v, this.bounds, x, this.zeroLineColor[v], this.zeroLineWidth[v]*this.pixelRatio) } } diff --git a/lib/shaders/backgroundFrag.glsl b/lib/shaders/backgroundFrag.glsl index 15274a7..7cf35aa 100644 --- a/lib/shaders/backgroundFrag.glsl +++ b/lib/shaders/backgroundFrag.glsl @@ -5,7 +5,7 @@ uniform vec4 colors[3]; varying vec3 colorChannel; void main() { - gl_FragColor = colorChannel.x * colors[0] + + gl_FragColor = colorChannel.x * colors[0] + colorChannel.y * colors[1] + colorChannel.z * colors[2]; } \ No newline at end of file diff --git a/lib/shaders/backgroundVert.glsl b/lib/shaders/backgroundVert.glsl index 34ecfb2..5b57229 100644 --- a/lib/shaders/backgroundVert.glsl +++ b/lib/shaders/backgroundVert.glsl @@ -8,11 +8,19 @@ uniform vec3 bounds[2]; varying vec3 colorChannel; void main() { - if(dot(normal, enable) > 0.0) { - vec3 nPosition = mix(bounds[0], bounds[1], 0.5 * (position + 1.0)); + + vec3 signAxis = sign(bounds[1] - bounds[0]); + + vec3 realNormal = signAxis * normal; + + if(dot(realNormal, enable) > 0.0) { + vec3 minRange = min(bounds[0], bounds[1]); + vec3 maxRange = max(bounds[0], bounds[1]); + vec3 nPosition = mix(minRange, maxRange, 0.5 * (position + 1.0)); gl_Position = projection * view * model * vec4(nPosition, 1.0); } else { gl_Position = vec4(0,0,0,0); } - colorChannel = abs(normal); + + colorChannel = abs(realNormal); } \ No newline at end of file