0
\$\begingroup\$

Hello everyone I am working with unity3d and I am faced with a task. I have a list of 3D points and I want to draw a pixel for every point on the list that exists after my cameras frustums far-plane. After I draw each of the pixels I would like to add a few simple effects to them. Sorry for the terminology I am new to unity! Any help is much appreciated.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ I've only used unity for a very small number of apps when I was in University, but why not just pick a 3D shape (cube/sphere/etc) and draw it really small? \$\endgroup\$
    – JSideris
    Feb 29, 2016 at 19:35
  • \$\begingroup\$ Why do you want to draw the points in 3D if you want them equally big(1px)? If they are the same size, you cant tell which ones are further and which are closer, which kills the reason for 3D for me. \$\endgroup\$
    – wondra
    Feb 29, 2016 at 19:39
  • \$\begingroup\$ @wondra You are right. Unless the OP is actually talking about 3D points just to mention they refer to 3D coordinates, i.e. talking about the screen 2D projection of 3D coordinates. \$\endgroup\$
    – MAnd
    Feb 29, 2016 at 21:17

2 Answers 2

2
\$\begingroup\$

You can do this by constructing a custom Mesh and using the Points topology. This tells Unity to render every indexed vertex of the mesh as a single pixel.

Mesh CreatePointMesh(Vector3[] points)
{
    Mesh mesh = new Mesh();
    mesh.vertices = points;
    // You can also apply UVs or vertex colours here.

    int[] indices = new int[points.Length];
    for(int i = 0; i < points.Length; i++)
       indices[i] = i;

    mesh.SetIndices(indices, MeshTopology.Points, 0);

    return mesh;
}

I'm not sure I fully understand what you're asking with regard to being "after" the camera far plane, so here are two interpretations:

  • Draw individual pixels for each point nearer than the far plane: you're done - the above technique does this out of the box. :)

  • Draw individual pixels only for content farther than the far plane: (maybe you're drawing something else nearer, like fully-shaded polygons) To do this, you'll want two cameras: one with your normal near & far planes which renders your near content, and a second whose near plane starts at the other camera's far plane, and whose far plane is very much further out. This second camera should be set to see the layer containing your point mesh created above, while the first camera sees only layers containing the near content. The second/far camera should render before the first/near one, which should clear depth values in order to ensure your content layers correctly. This will result in some overdraw, but since the points mesh is only drawing pixels at a time it probably won't be excessive.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I think he's doing a starfield skybox. Everything beyond "local space" is "pixels". \$\endgroup\$
    – Jon
    Mar 1, 2016 at 0:35
  • \$\begingroup\$ If so, just clamp scene-depth during transformation. \$\endgroup\$
    – Jon
    Mar 1, 2016 at 0:45
-1
\$\begingroup\$

"How do I draw individual pixels in the distance?"

Short answer:

You can't. Pixels aren't 3D and 3D space is not defined by pixels.

Workaround:

Pixels don't define the 3D space of your game world, but they do define the 2D space of your screen. While it is impossible by definition to draw a pixel in 3D space, it is possible to map a 3D object onto the camera and draw a pixel on the screen representing the result of that transformation. You'd then be circumventing the 3D rendering system in order to draw directly to the screen. Here is something to get you started. Also, you might also need to use a bit of math to know where to draw the points.

Alternatively, and definitely something I'd recommend, is don't draw pixels - draw spheres. Just scale a sphere down super small until it ends up filling about 1 pixel. You can even scale the sphere based on distance from the camera to make sure it stays about the same size regardless of how near or far the camera is from it.

Disclaimer:

I'm not an expert in Unity, and there may very well be an easy technique to accomplish the first workaround automatically.

\$\endgroup\$
5
  • \$\begingroup\$ I think, rather than how to project 3D to 2D, he was asking how to tell Unity to draw them as a POINTLIST rather than the more common (and probably default) TRIANGLESTRIP. \$\endgroup\$
    – Jon
    Mar 1, 2016 at 0:42
  • \$\begingroup\$ @Jon yea I figured he may have intended to ask about a specific Unity feature, but one literal response doesn't hurt. Wording matters. \$\endgroup\$
    – JSideris
    Mar 1, 2016 at 2:13
  • 1
    \$\begingroup\$ Rendering a collection of 3D points as individual pixels at their projected positions on a screen is not a Unity-specific feature. Point primitives and point cloud rendering go back to very early days of computer graphics, and are supported natively in DirectX, OpenGL, Vulkan, etc. I thought it was fairly clear from context that the author wanted to project 3D points onto a screen in order to mark their projected positions with pixels - the same as we do when rendering really any 3D content as a 2D raster. \$\endgroup\$
    – DMGregory
    Mar 1, 2016 at 13:11
  • \$\begingroup\$ @DMGregory Right, my first work around is to do a projection (whether or not unity or other frameworks can do this for you). But computing a 3D projection to a pixel is a different thing from drawing a pixel (setting a pixel's RGB value), which is done in screen space, not in a 3D scene. I can update my answer to clarify that the projection does not have to manually be computed. \$\endgroup\$
    – JSideris
    Mar 2, 2016 at 0:02
  • 1
    \$\begingroup\$ What I mean is answering "how can I draw a pixel at a 3D point" with "you can't" is similar to answering "how can I draw a triangle in 3D space?" with "you can't. You're drawing on a 2D raster screen of square pixels, so all you can do is approximate a projection of a triangle using a pixels within a staircase-edged region" — yes, that's the default assumption when we talk about drawing anything "in 3D" when we're working with raster monitors in games. I don't think the asker had any illusions that 3D space is composed of pixels, they just took a 2D screen representation of 3D as a given. \$\endgroup\$
    – DMGregory
    Mar 2, 2016 at 0:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .