Search Unity

Inverted mask to help create easy room floors

Discussion in 'General Graphics' started by FuzzyNori, Sep 13, 2021.

  1. FuzzyNori

    FuzzyNori

    Joined:
    Dec 6, 2012
    Posts:
    47
    Hello

    I am creating rooms randomly in my project, and have now hit an issue and I'm running out of ideas on how to achieve my desired effect.

    I'm not so great with shaders but I feel like this is a job for a shader...

    So, my entire area will share the same floor texture using a plane that covers all the created rooms.

    I would like make the floor texture only visible within the walls of these rooms, but as you can see in the provided picture, I have managed to do the very opposite of what I intended to do!

    Within each room, I have a mesh that outlines the room's shape (highlighted in the screenshot), maybe I can use that mesh to mask or occlude the floor plane? can someone share some ideas on how to achieve that?

    Thank you!
     

    Attached Files:

  2. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    unless there is organic terrain you can simplify this for flat floors in shaders, so no need for outline +another floor
    [I assume floors are a flat]

    tiling is WorldSpace casting UV's in the world_Y direction
    All receive repeating texture based on position

    object position -> world position -> cross product [establish vector] * float2 [# of texture repeats in world]

    upload_2021-9-12_18-12-56.png floor.gif

    might be ways to do this cheaper; but this is my level of CG math
     
  3. FuzzyNori

    FuzzyNori

    Joined:
    Dec 6, 2012
    Posts:
    47
    That seems like a way simpler solution than what I had in mind.

    Now to convert the idea to a shader since I can't yet use shader graph :) thank you for the suggestion I'm gonna give it a go!
     
  4. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    296
    object transform is not needed now that I look/think again

    Position(world) -> cross product works
    upload_2021-9-13_0-0-49.png
     
  5. FuzzyNori

    FuzzyNori

    Joined:
    Dec 6, 2012
    Posts:
    47
    Thank you!