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
1
Question by ronike · Nov 09, 2016 at 08:31 AM · camerarenderingshadersvolumevisible

Rendering an Object only inside of a certain area

I'm working on a VR game where you are looking down on at a level with your units (think RTS view in VR basically), and I'm trying to get it so that only objects in a given area are rendered, and objects on the edge are partially rendered, very similar to what you see in this video of Airmech Command.

However, despite my best efforts I've yet to find a great way to do this. I've tried stencils, but have only managed to create something like a window, where things to the left or right of the area aren't shown at all, but even if an object is in front or behind the area they are still rendered. I've tried depthmasking, but had similar problems. The best I've managed is a setup where I use a depth mask to remove an area from being rendered at all on one camera, and filled the area with the rendering of another camera, but this resulted in just a flat image basically, so if you had objects with height, they would be cut off at a certain height.

Basically, everything I've found seems to just cull pixels on a 2d level, just based on screen position, as opposed to world space, and I need something that stops rendering based on 3D space. Any help given would be greatly appreciated

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 BenHolz · Nov 09, 2016 at 01:13 PM

you definetly need a stencil buffer. One object is the mask it has the shape of everything you want to cut and is placed directly in front of the camera. The rest of the objects are normal where the schould be.

the mask object need a shader, put this in the subshader part of the shader you create (assets->create->shader->Standard Surface Shader):

     Tags { "RenderType"="Opaque" "Queue"="Geometry-1" }
     ColorMask 0
     ZWrite off

     Stencil{
         Ref 1
         Comp always
         Pass replace
     }

and this in the shader that will be put on every object that should be hidden:

     Tags{ "RenderType" = "Opaque" "Queue" = "Geometry" }
          LOD 200
     Stencil{
         Ref 1
         Comp notequal
         Pass keep
     }

I hope this helps

Comment
Add comment · Show 1 · 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 ronike · Nov 09, 2016 at 01:50 PM 1
Share

The problem with the stencil buffer, at least as I implemented it which looks very similar to the way you are suggesting, is it acts like a window. Anything behind the area is rendered, so you can neither stop an object from being rendered if it is behind the volume you want renderered (too far), or if it is in front of said volume (too close). I really need a solution that works in 3D space I think, the stencil stuff just checks if a pixel falls within or without the masking area on the screen

avatar image
0

Answer by kavanavak · May 21, 2019 at 08:00 PM

Where you able to find a solution? @ronike

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

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

8 People are following this question.

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

Related Questions

Does the projection matrix calculation affect the shader? 1 Answer

RTX Recursive Rendering HDRP Issue 0 Answers

How to render a Layer without the Volume Mask 0 Answers

Applying full screen image effects to UI only 2 Answers

(HELP) Volume Ray Marching rendered always on top of the other objects 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