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 /
  • Help Room /
avatar image
1
Question by heyx3 · Oct 07, 2015 at 09:54 PM · shadereditor-scriptingcompile

Is there a non-obsolete way to compile materials *in the editor* using a string of shader code?

I've searched around, but all the answers I found were either a) extremely outdated or b) trying to do it during gameplay.

I'm working on a plugin that involves generating and compiling shaders to do things like generate noise into textures using the GPU. I know that the Material constructor that takes shader code is being removed because not all platforms can use it, but is there a way to still do it in the editor, where we obviously know the platform supports it?

Additionally, I'd like to know if there's a way to invoke that material to render into a render texture (again, in the editor).

Comment
Add comment · Show 1
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 heyx3 · Oct 07, 2015 at 10:07 PM 0
Share

I appeared to have found a workaround from Here, but it's annoying to have to jump through all these hoops just to compile a shader. Plus, I'd still like to know whether it's possible to use the material in the editor to render to a render texture. So I'm not going to consider this "answered" just yet.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by heyx3 · Oct 08, 2015 at 06:42 AM

Figured it out myself! As mentioned in my comment, the way to do it is kind of hacky -- create a ".shader" file with the code, then call AssetDatabase.ImportAsset("Assets/MyShader.shader", ImportAssetOptions.ForceSynchronousImport) to make Unity immediately compile the shader, then use GL and RenderTexture classes to immediately render a quad with that shader into a texture. This all worked correctly inside the "OnGUI" method (because it happens when I press a button), so I'm pretty sure it works regardless of the current state of the editor/rendering context.

I'm pretty sure there's no better way to do it than that without using the obsolete Material constructor. Fortunately, it all happens pretty quickly anyways.

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

33 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

Related Questions

Saving changes made on a material from an editor script 1 Answer

Shader's CustomEditor Doesn't Appear 0 Answers

Is it possible to only recompile when I hit the play button? 0 Answers

How do I generate and compile a compute shader in the editor? 0 Answers

Shader vertex position 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