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
0
Question by Tharzzat · May 19, 2020 at 07:12 PM · layersgeometrystencil

Impossible non euclidean geometry help

I've found a way to make non euclidean geometry in Unity using stencil buffer portals.
The portals are not made with multiple cameras and there is no teleporting.
The portals only hide the overlapping geometry by separating the two using stencil buffer portals and layers.
I'm importing maps from an old game named Marathon.
Marathon maps need portals to function properly.
The Marathon map editor Weland can export maps as .obj model files, then normals and textures are added with blender.
All normals point inward and the map is separated into sectors.
The sectors and portals are separate game objects.
I found a way to use stencil buffer portals without having to edit or move sectors in the maps.
The game objects that occupy the same space are separated into two layers.
Layer 1 and layer 2 cannot collide with each other or interact.

Unity explains how to make layers.
https://docs.unity3d.com/Manual/Layers.html
https://docs.unity3d.com/Manual/LayerBasedCollision.html

The default layer connects and collides with both layer 1 and 2.
When the game object, player camera or enemy enters a portal, the portal checks if they cross the portal plane.
The portal changes the layer of the game object that crosses the portal plane to that layer the sector is.
Portal layer 1 changes player to layer 1.
Exiting the sector portal changes the game object player layer to default.

Unity explains how to change layers with script.
https://docs.unity3d.com/ScriptReference/GameObject-layer.html

There are four stencil buffer shaders, a read and write for layer 1 and a read and write for layer 2.
The read shader goes on the game object sector and the write shader goes on the portal game object.

Ronja explains how the stencil buffer works.
https://www.ronja-tutorials.com/2018/08/18/stencil-buffers.html

One read and write shader is set to ref 1 and the other read and write shader is ref 2.
Write shader ref 1 only renders read shader ref 1 from behind the portal.

This Youtube video explains how stencil buffer portals work.
https://www.youtube.com/watch?v=OBb4iUiXaRA

When the player camera crosses the portal plane and enters the sector, the read shader comparison is changed from equal to always.
When the player exits the sector portal the read shader on the sector is changed back to equal.

Unity explains the stencil buffer.
https://docs.unity3d.com/Manual/SL-Stencil.html

The portals have box colliders.
Ontriggerstay with crossing the portal does two things for the player, it changes the player game object layer and it changes the sectors read shader comp to always or equal.
To hide the enemy or player, when entering the portal they also have a read shader attached.
Anything that enters a portal is changed to that sectors layer and stencil reference value changed to that portals value.

The overlapping space stays separate and only what enters or exits the portals is changed.

Is there a better way to do 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

0 Replies

· Add your reply
  • Sort: 

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

127 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 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 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 avatar image

Related Questions

creating holes in a ship 0 Answers

Unity 5 Deferred Stencil Buffer Usage 1 Answer

What is sortingLayerID used for? 2 Answers

Change the layer of trees on terrain? 0 Answers

Reversing the sorting layer on a camera 0 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