Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by globalenemy · Apr 16, 2016 at 11:20 AM · maskingmodelingmodular

modular structure (like planetbase) (way of approach)

Hey, I'm trying to 'sort of' clone this game called Planetbase, as a learning project, In this game you build a Colony on a foreign planet. Each building has a connection to another one, so that all theese buildings form one structure.

  • PlanetBase Website: http://planetbase.madrugaworks.com/

  • Random Gameplay Video: https://www.youtube.com/watch?v=6QfrdQI-9nI

The position of theese connections are not totally fixed. I was wondering how I would realize this myself in unity. I started off simple and created a dome, copied out a part and created a mask. This mask would just need to be moved and I could move the entrance/exit. I also created a simple archway to obstruct that I'm just cutting out a part of the dome.

http://gfycat.com/EnlightenedSmoothJabiru

The Dome is 2 Objects and also the Mask is 2 Objects, with seperate models for inside and outside. The inside of the Mask obstructs the inside of the Dome and the outside of the Mask obstructs the outside of the Dome.

Now, to me it sorta looks like I got things right and I just need to follow down this road. But doing this all with mask objects feels like an enormous fiddly task. I'm allready having trouble to keep control of the renderlayers. I can't view my Dome from every direction, if there is another one next to it, without getting display bugs.

Do any of you guys have some tips for me? How would you approach this?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Apr 17, 2016 at 01:28 AM

Using a depth mask isn't a good approach in this case. That usually works if you have one object that should be masked. For a modular system the result will be unpredictable.

I would recommend one of those approaches:

  • Actually cut out the doorway by performing some simple CSG operations on the geometry procedurally. You most likely only need a sphere as cut-geometry. Cutting / trimming a mesh isn't as difficult as it sounds, just a bit of fiddling. Also keep an eye open for ready to use solutions. This one states that runtime support for CSG is coming soon.

  • Use a shader that does the masking in one go. You could add parameters to a shader that define 2 or more spheres which are used to discard fragments based on their placement. @vexe once wrote such a shader. I would suggest a similar approach.

Keep in mind that realtime masking (the second approach) can add quite some overhead if you have a lot of such shaders at the same time. The first solution just requires some processing when the connection is placed. This has the advantage that the geometry can still be batched by the rendering system and renders in a single draw call.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by bloeys · Apr 16, 2016 at 12:11 PM

You could try modeling different types of domes, for example one with only an entrance, one with two doors, and another with three etc...

Now since they are models you won't need to fiddle with masks and such, they will just be simple models. Then when you place a dome, you can just rotate the whole thing around until the exits are where you want them to be.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image globalenemy · Apr 16, 2016 at 12:19 PM 0
Share

That would mean fixed connection positions. And that is the opposite of my goal here. You somehow just said, 'you could just give up on what you want to achieve' what? why?

avatar image bloeys globalenemy · Apr 16, 2016 at 12:29 PM 0
Share

Oh I didn't realize you wanted them to be movable, its not very clear in your question. How about manipulating the vertices? If you can know which vertices are masked, you might be able to manipulate/remove them, though that can be a bit tricky.

Your current solution seems simple enough, but your problem seems to be in the rendering part, can you explain a bit more about what you are doing and what the problem with rendering is, it will make it clearer for us to help you.

avatar image globalenemy · Apr 16, 2016 at 01:08 PM 0
Share

I'm changing the Renderlayer for the materials in a script an I use a shader to apply the mask. Both are found on the internet and not written by myself. As I'm just starting to uncover alot of theese topics. Allready learned some things about shaders tho.

  • mask inside: 3001

  • dome inside: 3002

  • mask outside: 3003

  • dome outside: 3004

Script: /* SetRenderQueue.cs

      Sets the RenderQueue of an object's materials on Awake. This will instance
      the materials, so the script won't interfere with other renderers that
      reference the same materials.
  */
  
  using System.Collections.Generic;
  using UnityEngine;
  
  [AddComponent$$anonymous$$enu("Rendering/SetRenderQueue")]
  
  public class SetRenderQueue : $$anonymous$$onoBehaviour
  {
  
     [SerializeField]
     protected int[] m_queues = new int[] { 3000 };
  
     protected void Awake() {
        Renderer[] rr = GetComponents<Renderer>();
        List<$$anonymous$$aterial> materials = new List<$$anonymous$$aterial>();
        foreach (Renderer r in rr) {
           materials.AddRange(r.materials);
        }
        Terrain t = GetComponent<Terrain>();
        if (t) materials.Add(t.materialTemplate);
        for (int i = 0; i < materials.Count && i < m_queues.Length; ++i) {
           materials[i].renderQueue = m_queues[i];
        }
        enabled = false;
     }
  }

Shader: Shader "$$anonymous$$asked/$$anonymous$$ask" {

     SubShader{
         // Render the mask after regular geometry, but before masked geometry and
         // transparent things.
 
         //Tags{ "Queue" = "Geometry+10" }
 
         // Don't draw in the RGBA channels; just the depth buffer
 
         Color$$anonymous$$ask 0
         ZWrite On
 
         // Do nothing specific in the pass:
 
         Pass{}
     }
 }
avatar image bloeys globalenemy · Apr 16, 2016 at 01:17 PM 0
Share

Hmmm... I'm not really experienced in shaders, but I can see why playing with rendering in the shader might cause issues with multiple of those, I think they might be overlapping each other or something. Note: If this is making new materials, be careful with your draw call count, because if each dome gets a different material, then each dome will use a draw call.

Aside from the rendering stuff, have you figured collisions yet? If you are only getting this affect by using shaders, this means that the physics engine still considers it to be a solid, and there is really no way around that if you only rely on shaders.

What you will probably have to do is do vertex manipulation. I haven't done much of that so I can't tell exactly, but you might need to create a new mesh with the doors as 'holes' in them, or modify the existing mesh to create new holes in it, then you can use a mesh collider to make the physics engine acknowledge the doors.

avatar image globalenemy bloeys · Apr 16, 2016 at 01:35 PM 0
Share

As far as I can tell, I won't need physics colliders for that region.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

42 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Weird seams on modular environment 1 Answer

creating planets in blender 1 Answer

What does Unity3D NOT do for you? What else do I need in the game creation process? 1 Answer

Shooting Game HELP PLEASE 0 Answers

Part of a model is visible while the rest is invisible. Glitch? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges