Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Circle rasterization?

Discussion in 'Scripting' started by thevvulf, Dec 5, 2021.

  1. thevvulf

    thevvulf

    Joined:
    Oct 31, 2020
    Posts:
    36
    I'm bored and figured rasterization would be a cool project since I find it pretty interesting. I figured I'd do a circle first since its literally the easiest shape possible. To do this I figured I could get the current pixel on the screen and if the distance between it and the center pixel of the circle is less than the radius of the circle, set its color the the circles color, and if not, set it to a transparent color. I got a mockup of it working with a tex2d, so now I'm moving onto the full version. The problem with my plan is that for the entire version, I need a way to get the pixel on the literal screen and not just the tex2d. Basically, if I'm zoomed in in say the scene view window, I'm going to be seeing pixels that are smaller than the ones on the tex2d, if that makes sense. I need to be able to get those specific pixels, not just the ones on the tex2d that dont scale with how zoomed in I am and how much detail I need. I hope that makes sense. I know theres the vector graphics package but I want to make my own since it seems like a fun project and its something I've never done before.
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    A render texture for the camera will give you the "actual pixels" of the camera you're talking about. I'm sure there's some roundabout way to hijack the scene camera in the editor to target a specific render target, but it might be some work.

    https://docs.unity3d.com/Manual/class-RenderTexture.html
     
  3. thevvulf

    thevvulf

    Joined:
    Oct 31, 2020
    Posts:
    36
    I completely forgot about render textures, thats perfect.