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
1
Question by Geoffrey91 · Jul 22, 2016 at 07:38 PM · shadersgraphicsrendertexturedeferred rendering

Modify Gbuffer Layout / Add RenderTarget

I've posted this on the forum already (http://forum.unity3d.com/threads/add-new-rendertarget-to-gbuffer.417650/), but I know realize that this might be a better place for this question.

Premise:

As specified in the API documentation the current default GBuffer layout in Unity is:

  • RT0, ARGB32 format: Diffuse color (RGB), occlusion (A).

  • RT1, ARGB32 format: Specular color (RGB), roughness (A).

  • RT2, ARGB2101010 format: World space normal (RGB), unused (A).

  • RT3, ARGB2101010 (non-HDR) or ARGBHalf (HDR) format: Emission + lighting + lightmaps + reflection probes buffer.

  • Depth+Stencil buffer.

If I'm correct, the engine renders to this textures using the Standard shader, which (in a deferred rendering setup) invokes the vertDeferred and fragDeferred functions defined inside UnityStandardCore.cginc .

In particular fragDeferred has the following signature:

 void fragDeferred (
     VertexOutputDeferred i,
     out half4 outDiffuse : SV_Target0, //RT0: diffuse color (rgb), occlusion (a)
     out half4 outSpecSmoothness : SV_Target1, //RT1: spec color (rgb), smoothness (a)
     out half4 outNormal : SV_Target2, //RT2: normal (rgb), unused, very low precision (a)
     out half4 outEmission : SV_Target3 //RT3: emission (rgb), --unused-- (a)
 );

My Current Progress:

From my new StandardCustom.shader, (mostly similar to Unity's Standard.shader) I'm now including my own version of UnityStandardCore.cginc, called UnityStandardCustomCore.cginc.

UnityStandardCustomCore.cginc adds a new RenderTarget to fragDeferred, changing its signature has follows:

 void fragDeferred (
     VertexOutputDeferred i,
     out half4 outDiffuse : SV_Target0, //RT0: diffuse color (rgb), occlusion (a)
     out half4 outSpecSmoothness : SV_Target1, //RT1: spec color (rgb), smoothness (a)
     out half4 outNormal : SV_Target2, //RT2: normal (rgb), unused, very low precision (a)
     out half4 outEmission : SV_Target3 //RT3: emission (rgb), --unused-- (a)
     out half4 customRT: SV_Target4 //RT4: my custom RT
 );

Question:

Although the shaders are now ready to handle an additional RenderTarget, I'm not sure how to "feed" them one. Does anyone know how to achieve this?

Summary:

  1. I want to add an additional RenderTarget to the GBuffer

  2. I've rewritten Unity's shaders to handle an additional RT

  3. I don't know how modify Unity's Gbuffer setup so that I can provide to the shaders an additional RenderTexture

Anyway knows how to help me? 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by PortalMk2 · Jul 29, 2016 at 06:02 PM

MRT only supports 4 render targets. It's a hardware limit....

DX11 RWTexture2D<> or RWStructuredBuffer<> may be used as additional render targets, but the performance can be a problem. In fact, more render targets might not be practical.

Maybe you can try change the gbuffer layout, compress some components? Say, use baseColor+metallic+roughness. This will save two channels....or use interlacing trick on baseColor(diffuseColor) to save one more channel?

Comment
Add comment · Show 1 · 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 Zarenityx · Dec 06, 2017 at 02:13 AM 0
Share

This is not, or at least no longer, the case. Look at SystemInfo.supportedRenderTargetCount. A lot of modern hardware out supports 8 $$anonymous$$RTs ($$anonymous$$e included), and actually SV_Target4 is used by Unity for shadowmasks. I ran across this thread looking to read from SV_Target5, which I can successfully write to but so far cannot sample in an image effect. (_CameraGBufferTexture only seems to work for 0-3 still).

Changing the gbuffer layout is and option, but one that requires a little more fiddling and (at least in my experiences) doesn't always play nice with the rest of unity's shaders.

avatar image
0

Answer by mimimiprod · Sep 16, 2019 at 11:25 AM

Hi @Zarenityx ,

did you manage to read from your additional render target? I want to try the same thing but will just start working on it. Or did you end up with another approach? Thanks

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

All pixels drawn on my RenderTexture with a Sprite Diffuse material are shown as black instead of the intended texture colour 1 Answer

Shader.SetGlobalTexture not working on Windows 0 Answers

Is it possible to avoid writing to certain g-buffers? 1 Answer

Creating a Masking Object with Variable Pass Through 0 Answers

dynamic hole in layer / texture / camera 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