PDA

View Full Version : Why does this happen? (part of large, flat plane missing from render)



accursedCursive
12-14-2016, 05:52 PM
2304
It seems like it renders fine as long as none of the vertices are out of sight.
Also, it renders behind things it should be intersecting, though that only happens if I try to use my poorly coded perspective system rather than simple orthographic.

GClements
12-15-2016, 12:10 AM
No-one can say why it happens if you don't provide any information about what you're doing.

Post code. The code for rendering a single quad shouldn't be more than a few dozen lines.

accursedCursive
12-15-2016, 03:27 PM
Post code. The code for rendering a single quad shouldn't be more than a few dozen lines.
I can't post all of it, but I can post the tMatrix and pMatrix construction, the projection matrix, and the vertex shader.
I improved the perspective system recently, though I realised one issue I forgot to mention: that the camera appears to orbit a point one unit in front of it when it rotates.




var tMatrix = m4.scaling(object.xScale, object.yScale, object.zScale);
tMatrix = m4.xRotate(tMatrix, object.xRotation);
tMatrix = m4.yRotate(tMatrix, object.yRotation);
tMatrix = m4.zRotate(tMatrix, object.zRotation);
tMatrix = m4.translate(tMatrix, object.xPosition, object.yPosition, object.zPosition);

tMatrix = m4.translate(tMatrix, -camera.xPosition, -camera.yPosition, -camera.zPosition);
tMatrix = m4.zRotate(tMatrix, -camera.zRotation);
tMatrix = m4.xRotate(tMatrix, -camera.xRotation);
tMatrix = m4.yRotate(tMatrix, -camera.yRotation);

var pMatrix = m4.projection(gl.canvas.width, gl.canvas.height, camera.near, camera.far, camera.scale, camera.perspective);


projection: function (w, h, n, f, s, p) {
return [
s/((w+h)/h), 0, 0, 0,
0, s/((w+h)/w), 0, 0,
0, 0, 10/(f-n), p,
0, 0, (f+n)/(n-f), 1
];
},


var vertexShaderGeneric3D = `#version 300 es
precision mediump float;

in vec3 vertexPosition;
uniform mat4 tMatrix;
uniform mat4 pMatrix;
out vec3 vPosition;

void main() {
vPosition = vertexPosition;
vec4 position = tMatrix * vec4(vertexPosition, 1.0);
vec4 projectedPosition = pMatrix*position;
gl_Position = vec4(projectedPosition.xy/projectedPosition.w, projectedPosition.z, 1.0);
}
`;



Also, the quad is constructed with two clockwise triangles, rendered with gl.TRIANGLES, and the way part of it fails to render depends on the angle of approach: two corners cause the missing region to be triangular like earlier pic, two corners cause the missing region to be a slice off the bottom.

accursedCursive
12-27-2016, 04:25 PM
Bump
10char

GClements
12-28-2016, 02:27 AM
projection: function (w, h, n, f, s, p) {
return [
s/((w+h)/h), 0, 0, 0,
0, s/((w+h)/w), 0, 0,
0, 0, 10/(f-n), p,
0, 0, (f+n)/(n-f), 1
];
},


That's wrong; the last element should be zero, not one.

accursedCursive
12-28-2016, 02:34 PM
That's wrong; the last element should be zero, not one.

It makes a huge mess if it's zero, weird things happen like objects that should have passed out of sight end up moving away from the camera overhead.
I've fixed the problem of the camera looking like it's orbiting by adding a camera translation into the matrix construction, so now the only problem is particular things that render oddly.

GClements
12-28-2016, 10:40 PM
It makes a huge mess if it's zero, weird things happen like objects that should have passed out of sight end up moving away from the camera overhead.
In which case you have other problems, which may be partially hidden by the incorrect projection matrix.

accursedCursive
12-29-2016, 03:09 PM
In which case you have other problems, which may be partially hidden by the incorrect projection matrix.
mega dot nz/#!l0tmjBTB!r46uFJAhygZlhxmnen58oMw4nSvnyjAM_rwF0Id 8yvk
You can see it for yourself to get an idea of the problems.
The projection matrix is in WebGLEngine, vertex shader is in 3DDemo.
The matrix is constructed in drawScene and renderBuffer (WebGLEngine)