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 roamcel · Jan 04, 2012 at 07:23 AM · shaderimagescreenshotoutputalternative

Output shader to image

Hi all,

Being ignorant on the matter of shaders, I wanted to know if it's possible to specify a texture, or any other texture-like format as the output for a shader.

I'm using this for a postcard/photo decal system, and CaptureScreenshot and GetPixels aren't enough for the job.

So I basically wanted to know if there's any way to ask a shader to output to an image rather than to whatever it usually outputs to

Thanks in advance

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

1 Reply

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

Answer by CHPedersen · Jan 04, 2012 at 07:50 AM

You can have a camera render itself to a texture instead of the screen - this is what is known as RenderTextures. Everything passes through the rendering pipeline as normal, and all shaders are executed like you're used to, the system just writes all the rendered pixels in a texture instead of displaying them on the screen. You can read about it if you follow the link I provided.

Keep in mind that this is unfortunately a Unity Pro feature.

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 roamcel · Jan 04, 2012 at 08:21 AM 0
Share

Thanks for the explanation. Didn't know that rendertextures were just camera=>texture. Do you happen to know where I can find what shaders can accept as input, and give as output? $$anonymous$$ight be able to find a workaround, since I don't have Unity Pro.

avatar image CHPedersen · Jan 04, 2012 at 09:07 AM 0
Share

Delving into what, specifically, shaders can input or output is a technical topic worthy of more studying than a comment in a forum offers. ;) Shaders are written in Cg which was made to look syntactically similar to C, in order to make it easier for new developers to get started. But because GPUs function fundamentally differently from a CPU, the programs one writes must follow some very specific rules which often present a limit to what you can do, such as reading and writing data whenever you want. If you're interested in some in-depth knowledge about it, I recommend you read a book on the topic, for example the Cg tutorial available here:

http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter01.html

Or, at the very least, study Unity3D's Shaderlab pages which start here:

http://unity3d.com/support/documentation/$$anonymous$$anual/Shaders.html

As a rule of thumb, however, and to briefly answer your question:

Vertex shaders are an intermediate stage and can output most anything you want them to, but a final position (for the vertex it processes) is mandatory output.

Pixel shaders are closer to the final steps (just before scissoring and depth testing), and therefore, their output options are a lot more limited - usually, they have to reduce all calculations to a single pixel value to be output to the framebuffer. To my knowledge, you cannot write values to a texture in its memory, that's one of the limitations; Cg has no concept of I/O. You can only output pixels, and if you want the target framebuffer, where the output ends up, to be a texture and not the screen, this must be specified at the application level (RenderTexture), before things enter the rendering pipeline.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Colors are wrong in in-game screenshot 1 Answer

Stippled Shader? 2 Answers

Overlapping Transparent Objects to Same Colour 0 Answers

Cant get the World Pos from Depth! 0 Answers

Why is my texture2D screenshot coming out as a grey box? 1 Answer


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