Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How would one remove rectangles from this texture via shader? Is it possible?

Discussion in 'Shaders' started by Renatusdev, Jan 19, 2021.

  1. Renatusdev

    Renatusdev

    Joined:
    Dec 9, 2018
    Posts:
    35
    Yes, I could manually remove them and then use that texture (for star sky shader I'm doing), but Id much rather have a parameter that simply diminishes the number of stars (rectangles).
    pattern55.png
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    The easiest approach I can think of would be to modify the texture to give each star a random brightness between something like 8 and 255. Then in Unity make sure the texture is set to use point filtering, and check in the shader if the value is greater than some slider with a step function.

    Code (csharp):
    1. fixed starTex = tex2D(_StarTex, i.uv).r;
    2. fixed starMask = step(starTex, 1.0 - _StarProportion * ((255.0 - 7.0) / 255.0));