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 Jazzer008 · Oct 08, 2013 at 10:15 PM · rendertextureproceduralskyboxdrawcallssingle

Single computing/rendering for complex Skybox shader.

I have a fairly complex procedural space skybox shader. It uses multiple passes with perlin noise algorithms to generate nebula. On lower end machines it's quite taxing on the frame rate because of the amount of calculations.

Is there a way to run a shader once and then never again? The skybox doesn't need to be dynamic, it needs to be computed once and then never again. Is this possible?

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

Answer by aldonaletto · Oct 09, 2013 at 12:59 AM

The skybox must be rendered every frame - it usually clears the screen before the new frame is rendered. What you could do is to start with your complex skybox shader, render its faces on RenderTextures only once (requires Pro), then assign them to the faces of a regular skybox material and assign it to RenderSettings.skybox - after that your skybox will be rendered at lower cost.

The code could be something like this, attached to an empty game object:

 private var cam: Camera;
 private var skyMat: Material;
 
 function Start(){
   // create a regular skybox material:
   skyMat = new Material(Shader.Find("RenderFX/Skybox"));
   // create a temporary camera:
   cam = gameObject.AddComponent(Camera);
   cam.clearFlags = CameraClearFlags.Skybox; // clear with current skybox
   cam.cullingMask = 0; // draw nothing but the current skybox
   cam.fieldOfView = 90; // adjust view to exactly one face
   cam.aspect = 1;
   // render the faces and assign them to the new skybox material:
   RenderFace("_FrontTex", 0, 0);
   RenderFace("_BackTex", 0, 180);
   RenderFace("_LeftTex", 0, 90);
   RenderFace("_RightTex", 0, -90);
   RenderFace("_UpTex", -90, 0);
   RenderFace("_DownTex", 90, 0);
   // assign the new skybox material to RenderSettings.skybox:
   RenderSettings.skybox = skyMat;
   DestroyImmediate(cam); // camera not needed anymore
 }

 // rotate the camera according to angX, angY and render a face,
 // then assign it to the texName texture in skyMat

 function RenderFace(texName: String, angX, angY){
   cam.transform.eulerAngles = Vector3(angX, angY, 0); // look at the desired face
   var face: Texture2D = new Texture2D(512, 512); // create the face texture
   cam.targetTexture = face;
   cam.Render(); // take a snapshot of the face
   skyMat.SetTexture(texName, face); // assign it to the correct face in the shader
 }

NOTE: The purpose of this code is just to show you the path. It wasn't tested, and may fail miserably - but the basic idea will probably work with a few adjustments.

Comment
Add comment · Show 3 · 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 Jazzer008 · Oct 09, 2013 at 02:52 AM 0
Share

Render to texture would be the only feasable way?

avatar image aldonaletto · Oct 09, 2013 at 01:14 PM 0
Share

There's also RenderToCubemap, but it also requires Pro - the advantage is that you can render a cubemap skybox in a single drawcall, while the conventional skybox takes six (I created a cubemap skybox shader and rendering script - let me know if you decide for this approach).

If you don't have Pro and the skybox is always the same, you may do the job by hand: adjust the main camera like above, run and take a snapshot of the screen; repeat this procedure for each face, then edit the images and assign them to a new skybox material.

avatar image Jazzer008 · Oct 09, 2013 at 04:37 PM 0
Share

Alright, thanks for the help! I'll be fine with creating the scripts myself if I ever get my hands on pro, I can't really take screenshots as it defeats the purpose of a procedural system. :P

It's only taxing on older graphics cards so unless I get pro I'll just have to reduce it's complexity for these lower end cards.

Thanks again!

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

16 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

Related Questions

Using Render Textures To Create a Cubemap 0 Answers

Procedural Skyboxes Based on Scene Data 1 Answer

Unity 5 (beta 13) procedural skybox, no colour properties? 1 Answer

Batch drawcalls of GameObjects with a script attached? 1 Answer

Runtime cubemap generation from 1x256 gradient image? 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