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 Patapom · Oct 04, 2011 at 12:32 PM · shadershaderseventnotificationcompilation

Notification of shader recompilation ?

Hi !

Is there a way to be notified a material's shader was recompiled ?

I mean, such an event would be the ideal place to setup shader constants that don't change across the entire shader and need to be uploaded only once. Instead, I have to upload these constants every frame, which kind of sucks...

That makes the user write 2 scenarios : one for debug mode where the shaders get recompiled often and another one for release mode where the shader gets compiled only once, too bad.

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
0

Answer by Owen-Reynolds · Oct 04, 2011 at 04:59 PM

You're talking about saving on things like renderer.material.SetFloat("_Shininess", shininess);?

I thought constants needed to be sent every frame no matter what. Sure, the shader code is stored in the graphics card, but it doesn't have a spot where it stores the uniform variables (specSize = 12 ... .) Those are stored in the CPU, with the material. Since the specular shader, say, is used by lots of materials, remembering the most recent GPU setting for specSize wouldn't be useful.

The only way you should be able to set a GPU constant once is if whatever register happens to never get overridden by any other shader, like when materials are batched.

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 Patapom · Oct 04, 2011 at 09:05 PM

I was talking more about texture uploads, not simple parameters that change per-instance...

Imagine the case where a material uses a texture as a precomputated table : that texture never changes for any instance of the material and needs to be uploaded only once and stay in video memory.

Any decent driver has a cache that allows to keep textures in video memory without having to upload them everytime. I don't know how Unity processes the "material.SetTexture()" cases but I seriously hope that calling "SetTexture()" every frame doesn't upload my texture again everytime, although it didn't change from the last frame (hence my request to post the "SetTexture()" only once, when the shader gets recompiled)

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 Owen-Reynolds · Oct 04, 2011 at 11:52 PM 1
Share

Behind the scenes, I believe the $$anonymous$$aterial is requesting the Texture each frame. The request goes through the GPU driver, which checks whether the texture is already in the GPU, loading if needed.

Even if you have just changed the shader, the textures might be in memory anyway. Ex: first use of Diffuse with Bark, but Specular has used and loaded Bark for you. Likewise, you may have been using a shader for a while, but that texture got swapped out when you loaded a huge texture last frame.

I assume that SetTexture merely changes the value in the CPU-stored material, and takes almost no time by itself. Actually drawing the object triggers the GPU texture manager, which may or may not take a while.

avatar image Patapom · Oct 05, 2011 at 12:06 PM 0
Share

Well, I surely hope that the Unity $$anonymous$$m knows what it's doing. ^^

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

GLSL link failed, no info log provided 0 Answers

Changing Shader Graph texture through Script 1 Answer

Having problems with unlit shaders casting shadows 0 Answers

RWTexture2D in Compute Shader on Android? 2 Answers

Single tone shadows in forward rendering 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