Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 zjtzyrc · Apr 03, 2017 at 06:49 AM · shadergraphics

Problems about rendertarget

Simple version:
I have a group of procedural meshes, I need to draw each of them first to screen(call it main draw), then to another buffer(RenderTexture maybe). the order can't be rearranged, since every main draw needs info that the last mesh drawed in the second buffer. How to write code?

here's a full description.

I'm implementing Volume Rendering in Unity these days (using guide at http://http.developer.nvidia.com/GPUGems/gpugems_ch39.html). And I've come with some problems when I try to implement the lighting effects(I'll quickly describe it below, no need to check the page). So for now, I have a script does the rendering( it's a Monobehaviour, I attatched it to a gameobject that represents volume.

     void Update(){
         // some calculation
         ...

         for ( float slicePlane = 0 ; slicePlane < destination; slicePlane += sliceDistance){
             Mesh mesh = new Mesh();
             //calculate the slice mesh.
             ...
 
             //draw the slice mesh.
             Graphics.DrawMesh(mesh, Matrix4x4.TRS(transform.position, transform.rotation, transform.localScale),volumeMaterial,gameObject.layer);
             }
     }

As you can see, it does the rendering by slice the volume many times then draw the mesh. And the result is composed by alpha blending. This works perfectly for now.
So in order to implement the lighting effect, I have to draw the slice mesh to another texture(called light buffer) after the main draw of a slice is over(the next slice drawing requires info from the light buffer, so the correspoinding light buffer draw must be done after each slice is drawn). So I changed my code like this.

     void Update(){
         // some calculation
         ...

         for ( float slicePlane = 0 ; slicePlane < destination; slicePlane += sliceDistance){
             Mesh mesh = new Mesh();
             //calculate the slice mesh.
              ...
     
              //draw the slice mesh.
              Graphics.DrawMesh(mesh, Matrix4x4.TRS(transform.position, transform.rotation, transform.localScale),volumeMaterial,gameObject.layer);

              //calculate and set some shader properties
              ...
              //draw the slice mesh in light buffer.
              Graphics.SetRenderTarget(lightBuffer);
              Graphics.DrawMesh(mesh, Matrix4x4.TRS(transform.position, transform.rotation, transform.localScale),lightBufferMaterial, gameObject.layer);
              }
     }

then it failes, It seems it's due to while DrawMesh submit the draw request to pipeline, SetRenderTarget does its job where it is.
Also, I tried to use a second camera to do the light buffer rendering, by change the parameter in DrawMesh to only draw in the second camera. But when I open the Frame Debugger, I fount that draw calls are grouped together by camera, so the light buffer rendering begins after all the slices are rendered in the main camera( I didn't really examine this, but I assume the draw call order is the same as shown in the hierachry of frame debugger.). But as I mentioned, the light buffer should be drawed to instantly after each slice is drawn in the main camera.
I'm quite confused now. plz help.

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 zjtzyrc · Apr 04, 2017 at 07:16 AM 0
Share

so I've found a workaround for my project. Ins$$anonymous$$d of using Draw$$anonymous$$esh, I use Draw$$anonymous$$eshNow in OnRenderObject. And Draw$$anonymous$$eshNow works well with SetRenderTarget as expected. But Draw$$anonymous$$eshNow doesn't interact with lighting or reflection, which is a disadvantage. I wonder if there's a better solution?

0 Replies

· Add your reply
  • Sort: 

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

Culling part of a sprite in Sprite Manager 2 1 Answer

How to remove URP from the project 0 Answers

The Best Way To Make Stylised Grass in Unity? 0 Answers

Rewrite shader so that the Sprite-Diffuse shader doesn't take incidence angle into consideration when applying lighting? 1 Answer

How to add interactivity (move/raycast objects) to a mostly GPU-based particle system 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