OpenGL ES: mixing perspective and orthographic projections - matrix

I have a scene rendered using a perspective projection. I'm attempting to render an additional piece of geometry (a polyline) into the scene using an orthographic projection.
This is working fine, but the geometry rendered using the orthographic projection is always rendered above everything else in the scene. Ideally, I would like the polyline geometry to correctly maintain it's depth in terms of the depth buffer (with objects at a closer Z to the camera drawn over the top of it).
Is this possible, or would I be better off using a perspective projection for the polyline and negating things like perspective divide in the vertex shader?

Related

Three.js plane inherit topography from set of meshes

What's working:
I have a solution for loading in topography using terrain tiles. Each tile occupies a plane as mesh. The image on the plane can then be any map tile source. Each plane mesh is a child of an object3d and offset accordingly to create the overall terrain.
The Question:
I am not sure the best way to go about having an irregular shape inherit 3d surfaces. This shape could be drawn or imported as KML. Is there a way to use a vertex shader to inherit the topography? I would like the topography as a mesh so that I can interrogate the topography of the shape. In this way it is different from using a shader to paint the surface as a mesh result is needed.
I do not yet have code for this to share as I do not know where to start. Vertex shader? Constructive solid Geometry?

how do I get a projection matrix I can use for a pointlight shadow map?

I'm currently working on a project that uses shadowtextures to render shadows.
It was pretty easy for spotlights, since only 1 texture in the direction of the spotlight is needed, but its a little more difficult since it needs either 6 textures in all directions or 1 texture that somehow renders all the obects around the pointlight.
And thats where my problem is. How can I generate a Projection matrix that somehow renders all the object in a 360 angle around the pointlight?
Basicly how do create a fisheye (or any other 360 degree camera) vertex shader?
How can I generate a Projection matrix that somehow renders all the object in a 360 angle around the pointlight?
You can't. A 4x4 projection matrix in homogenous space cannot represent any operation which would result in bending the edges of polygons. A straight line stays a straight line.
Basicly how do create a fisheye (or any other 360 degree camera) vertex shader?
You can't do that either, at least not in the general case. And this is not a limit of the projection matrix in use, but a general limit of the rasterizer. You could of course put the formula for fisheye distortion into the vertex shader. But the rasterizer will still rasterize each triangle with straight edges, you just distort the position of the corner points of each triangle. This means that it will only be correct for tiny triangles covering a single pixel. For larger triangles, you completely screw up the image. If you have stuff like T-joints, this even results in holes or overlaps in objects which actually should be perfectly closed.
It was pretty easy for spotlights, since only 1 texture in the direction of the spotlight is needed, but its a little more difficult since it needs either 6 textures in all directions or 1 texture that somehow renders all the obects around the pointlight.
The correct solution for this would be using a single cube map texture, with provides 6 faces. In a perfect cube, each face can then be rendered by a standard symmetric perspective projection with a field of view of 90 degrees both horizontally and vertically.
In modern OpenGL, you can use layered rendering. In that case, you attach each of the 6 faces of the cube map as a single layer to an FBO, and you can use the geometry shader to amplify your geomerty 6 times, and transform it according to the 6 different projection matrices, so that you still only need one render pass for the complete shadow map.
There are some other vendor-specific extensions which might be used to further optimize the cube map rendering, like Nvidia's NV_viewport_swizzle (available on Maxwell and newer GPUs), but I only mention this for completness.

PlaneBufferGeometry isn't displayed with orthographic camera

I have a PlaneBufferGeometry that isn't displayed when I switch from a PerspectiveCamera to a OrthographicCamera. Other objects like Box2D work fine with both cameras.
Is ortographic camera not able to render planes?
Orthographic cameras can render planes, but since planes have no thickness, they will generally be "invisible" if the plane points up or down, for example, if it represents a floor. This is the nature of the orthographic camera: its field of view doesn't differ with depth, and it doesn't offer perspective.

Three.js force the shadow of a rotating 2D plane to always face the light source

I have a 2D plane with a tree texture that always faces the general direction of the camera by rotating only on its Y axis. It works great and the shadows are cast perfectly, but I don't want the shadow of the 2D plane to rotate with it.
I'd like the shadow to appear so that the 2D object is always facing directly at a light source even when its not. I've tried messing with shaders without any luck. Should I be investigating shader tricks with this, or is there already something available from within Three.js that can do this already?
I was thinking it's that or come up with an invisible plane at the same position of the other 2D plane, and force it to face the light source and cast shadows, but that would cause other complications.
The reason for needing this is to keep thick, bushy shadows for 2D trees in a scene.

Raycasting through a custom camera projection matrix

After modifying my main camera's projection matrix, the ScreenPointToRay method that use ray casting begin to fail, so the method which detect touched object use raycast fail too. Is there any way to use ScreenPointToRay method with a custom camera projection matrix?
If you made a custom camera projection matrix, then you probably know where is the user pointing to, how about casting a ray yourself and not using the helper?
If you have a problem with translation of the cursor to world position, there is a good approximation - take four angles on approxiamtely the edges of your camera's viewpoint (top of the viewport horizontal center, left of the viewport vertical center etc.) and interpolate between them.

Resources