How to draw a single 2D pixel on the screen

This is incredible but I cat’t find a solution on how to draw on screen a single 2D pixel…

Maybe is this very complicated because Unity is a 3D engine?

Any idea?

I think you have the right idea here. Have you started learning how to write shaders? I think some knowledge in this area will lead to your answer, though I’m not totally sure.

No I haven’t. Sincerely also if Unity is a 3D engine I think it’s incredible that to write a single pixel I must learn shaders…
Why is not exposed a low level API?
Unity is a great high-level engine but if you want to do something that is not “bundled” there are some limitations
or you must do dirty tricks!!!

IMHO in Unity 2D should be “native” 2D and not a 2D “wrapped” in 3D…

If you need to manually draw individual pixels then you’re probably using the wrong engine or have the wrong approach to your problem.

1 Like

You don’t need to write your own shader to do this, but it’s certainly not straightforward. It really depends on what you’re trying to do.

  • You could create a sprite that is one pixel large (would make sense if your pixel is meant to be a “gameobject” in your world)
  • In OnPostRender, you can draw onto the current surface using low-level calls on the GL class (lines or triangles - so it’s work to get just a pixel, I guess) - but you do need to set up matrices properly.
  • Finally, you could just draw pixels to an array on the CPU, and LoadRawTextureData/Apply that data to a texture each frame, then Graphics.Blit that take, say in OnPostRender.

It really depends on why you need to draw a single pixel.

Yes.

Judging by your screen name, you come from a more literal time of computing’s past. I can relate.

3D doesn’t inherently think in terms of pixels, it’s infinitely scaleable, so everything is an abstracted geometry that’s anywhere from tinier than a 1/10000th of a pixel to millions of times bigger than a pixel.

Surfaces on these geometric shapes are a blend of algorithmic colouring and textures, which are made up of good old fashioned pixels.

Then, as someone else has said, after geometry is rendered (thanks to light hitting it relative to the camera and materials on their surfaces responding to this light), there’s ways to post process the rendered image, at which point you can think in terms of pixels, as it’s the whole screen that’s getting processed, pixel by pixel.

@LaneFox yes maybe yu’re right… I come from low-level programming where all is done pixel by pixel and I believed that Unity still allowed to do low level operations…

@icefallgames I wanted to draw single pixels because I’m creating, just for teaching purposes and to learn Unity, a clone of space invaders, and I needed a way to directly control the destruction of the pixel of the bases…

:slight_smile: yes I started programming demo and videogames in assembly and C many, many years ago on a glorious Amiga…
however I understand what you’re saying…

In the end maybe today you need to focus more on game design and let a good engine do the job at a low level… anyway I will try to do some experiments on post-rendering

1 Like

I started coding demos and primitive games in Assembler and C many, many years ago, on a glorious Atari ST :wink:

Please let me know how you go. And what you learn/find/think. I think Metal is more to our innate liking. But painfully verbose to get anything started. Nothing like the elegance and simplicity of the old days.

For a “pixel-like” experience with the bases getting destroyed by shots in Space Invaders style, look at how Box2D can be used to make lots of little objects become one object. Unity’s 2D physics engine, in a 3D space, is one of its highlights.

A Box2D Rigidbody2D as a base, made up of many colliders as to your “pixel” liking, will create the effect you want. You can remove colliders from the RigidBody2D as they’re hit by the bullets, with relative ease, due to the contacts with the specific collider of a group being reported.

1 Like

Sorry, one more thing: Have a look at this asset, and its code and how it works: SpriteLights | VFX Shaders | Unity Asset Store

It’s a really interesting insight into what’s possible in a 3D space with virtual materials posing as pixels and lights. One of the most insightful readings I’ve had, so far, in my journey into learning how Unity works and what can be done with it.

:slight_smile: Yes also the Atari ST was a glorious computer (68000 docet!!!)

In the old days we were forced to learn at a low level the operation of a cpu, this cost time but you were able to do really anything. Today, for us who come from old school is different, the graphic engines hide the complexity but if you want to do special things it is really difficult to do them…

This is a good idea; I could put Box Collider 2D components around the pixels to be destroyed and after deleting the pixels destroy the corresponding collider as well.
The only doubt is how much it costs in terms of performance to have all those colliders?
Could it be that using Edge Collider 2D component would be more efficient?

I don’t think the performance will be a problem. Even on an old iPhone you should be fine. Box2D is pretty efficient and the guy that works on it at Unity is good.

Alternatively, there’s an addon that does almost exactly what you want: Destructible 2D ☄️ Dynamic Sprite Destruction page-11#post-3473686

As soon as possible I’ll try you idea and post here the code.

For the addon I’d like first to try the code by myself…

Thank you very much for your post and tips :wink:

Sorry to point you to another Asset Store thingy… but I stumbled on something cool:

https://itunes.apple.com/us/app/rocket-plume/id1146955067?mt=8

The above is made with this:

Which is available for $14 USD: PixelSurface | Particles/Effects | Unity Asset Store

But what’s even more interesting (and potentially cool), this guy made a scripting language on top of Unity:

1 Like

I was just going to suggest PixelSurface… but I see @Deeeds beat me to it. :slight_smile: If you want to manipulate individual pixels in Unity, that’s the sort of thing PixelSurface was designed for.

Hey @JoeStrout you did a great job! Your project also include C# source code and this is an amazing thing!
If I can I’ll try it.

1 Like