Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Hoeloe · Oct 02, 2013 at 02:44 PM · shaderpassz-depth

Shader - Don't render parts at certain distance

Hey all! I've written a shader, which uses quite a few passes to achieve the right effect. Obviously, this is very expensive, and the issue is that some of these passes are only really necessary close up. So I'm wondering whether it's possible to skip the rendering of certain pixels if they are too far away from the camera, or to skip out entire passes depending on the distance from the camera. I could even make do with a custom fallback, meaning it uses a different shader at a certain distance. Is there any way I can achieve this? I won't say I'm an expert at CG or ShaderLab, but I do understand the basic concept of how shaders work, and it seems like one or all of the above should be possible...

Comment
Add comment · Show 5
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 srancsik · Oct 02, 2013 at 03:37 PM -1
Share

I have an idea: Click on your camera in the hierarchy. In the Inspector panel find Camera > Clipping Planes > Far and reduce it.

avatar image Hoeloe srancsik · Oct 02, 2013 at 03:41 PM 0
Share

Yeah, no. That will stop rendering ANYTHING. That's not what I'm asking for, did you even read my question? I want to stop rendering PARTS of a SINGLE SHADER at certain distances, essentially reducing the detail in the shader, not to remove it entirely.

avatar image srancsik · Oct 02, 2013 at 04:43 PM 0
Share

Sorry for the misunderstanding. Calm down I wanted to help you out $$anonymous$$an.

avatar image Hoeloe · Oct 02, 2013 at 04:46 PM 0
Share

Sorry, your post came across as a little condescending, and it somewhat annoyed me.

avatar image srancsik · Oct 02, 2013 at 08:28 PM 1
Share

Never $$anonymous$$d, no problem. :) I hope you will have the proper answer for your question soon.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DarkPixel · Oct 03, 2013 at 12:21 AM

That's a really good question. I think the only way to do that is to render the mesh 2 times. Condition in shader should be avoided. But I'm not 100% sure it's the best way, maybe benchmark multiple solution will be a good idea.

I would make a low quality shader to render only after a certain distance from the camera with a fade value. So pixel too near the camera will be ignore with an alpha of 0. After I render the same mesh with the high quality shader only before the start fading distance of the low quality shader. It would create a nice blend with the low quality/high quality transition.

alt text


twopassshader.jpg (44.1 kB)
Comment
Add comment · Show 2 · 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 adaburns · Oct 03, 2013 at 02:23 AM 0
Share

Combining this answer (or something like it) with shortened clip-planes and different cameras for the high- and low-quality passes could indeed improve performance in some cases. The camera/render setup would be a little bit of a pain--I'd only go that far if you're actually seeing a lot of time being spent rendering with this shader.

avatar image Hoeloe · Oct 03, 2013 at 07:51 AM 0
Share

Okay. I had thought about this sort of method, but I wondered if there was another way. It seems this is the best way to do it, though. $$anonymous$$y shaders are pretty expensive (they can have up to 40 passes in them), but by missing out some of the passes, they become almost indistinguishable from the higher-quality ones at a distance. Because of this, I shouldn't actually need the fading (I may still, but there's a good chance I won't). I may be able to just alter the shader in the material, rather than drawing two at once (which could push the passes up from 40 to 60), though I'm not sure what the performance overhead of switching the shader in a material (and not shared$$anonymous$$aterial) is.

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

18 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

Related Questions

Is it possible to get back data for a specific vertex from a shader ? 0 Answers

Disabling a Pass or Subshader Programmatically 0 Answers

Unity 5 Standard Shader Transparent render order issues 1 Answer

Shaders: Using Property for Offset 3 Answers

Surface Shader, run vertex multiple times 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