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 Eye_of_Triad · Sep 17, 2017 at 03:25 PM · camera2dshadershader programming

2d Shader: How to show camera view on a sprite?

I want to write a shader that shows the camera view from the same perspective & ratio (not fit to the shape of the object).

I want to achieve the grander aim of starting with a background (e.g. bricks) and have a shape “punch a see-through hole” that I can move around and place where I want.

Background (Repeated): (series of bricks- I can only upload 2 images so just imagine it!)

Foreground Object: window

Hole shape: window hole

I want to write a shader for this hole shape, so that it shows the exact view of a camera parented to the main camera that is set up to see only background layers.

The part I am missing is the actual shader. I have almost no shader experience but am willing to learn. Point me in the right direction?

sm-foreground.png (12.5 kB)
sm-window-hole.png (10.3 kB)
Comment
Add comment · Show 6
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 Cherno · Sep 17, 2017 at 05:27 PM 0
Share

Well, I was in the same spot you are in now some time ago. I was scared of shader code but I absolutely needed a custom shader which wasn't available so I just dug in and now I can write shaders. It's not as hard as you might think. The Unity website has great tutorials on writing basic and advanced fragment and vertex shaders, so why not start there and try to understand how a shder is built and what each part does. It's actually really simple and it will open all kind of possibilities for your future projects.

avatar image Glurth Cherno · Sep 17, 2017 at 05:36 PM 0
Share

I'm not clear what the camera should be showing "around" the holes. If you just want a solid color or static image around the holes, no need for a shader: you can simply child a sprite object to the camera, where the hole is transparent (color.a=0.0 is completely transparent), and the rest is your solid color/static image (color.a=1.0 is opaque). Just make sure it's offset to slightly in front of the camera (probably the same amount as the camera's near plane.)

oops: didn't mean to make this comment a reply.. whatever.

avatar image Eye_of_Triad Glurth · Sep 19, 2017 at 11:58 AM 0
Share

The transparent hole will still show the brick layer behind it. I need to see "through" the brick wall and into the background.

I've looked into masking options for sprites in Unity, but it seems the way to do this is through shaders.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by JonPQ · Sep 20, 2017 at 04:55 PM

make a texture that is of type render texture. create a camera assign it to render to that render texture. make a material.. use the render texture as the material. Now you can put that material on an object or a sprite material.... that gets you half way there. Next on the material, you'll want a shader that can provide a second texture as a mask / alpha to cutout the first one... You can probably find that on Unity Shader wiki website at a guess ;)

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

192 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 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

Get the screen coordinates of an object altered by Fisheye 0 Answers

How to get the value of a pixel of a noise node if it's greater than some threshold? 0 Answers

Rewrite shader so that the Sprite-Diffuse shader doesn't take incidence angle into consideration when applying lighting? 1 Answer

How to make Standard Shader _Color property be Per Instance Data? 0 Answers

Shader graph node that return the value of the input node if it's greater than some value? 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