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 Renardjojo · Sep 12, 2021 at 04:53 PM · shaderrenderingrendertexture

Interger return value in shader with R8 R16 RenderTexture

I am trying to construct a render texture with format R8 our R16 that is integer format. I only need 1 channel for my texture. My shader is very simple :

  Properties
  {
      _ID ("ID", Int) = 1
  } 
  int frag () : SV_Target
  {
      return _ID;
  }

This code doesn't work and it seems that only float works for the return statement of the fragment shader. How can I use format R8 or R16 ? How can I convert my int to float and them float to int if it's impossible to store int ?

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 Renardjojo · Sep 19, 2021 at 05:39 PM

After some test in rederDock, shader is correctly create but I use custom render pass with my camera and VBO seams to be disable for undifned reason.

Here the corerct fragment shader used :

 #version 450
 #extension GL_ARB_explicit_attrib_location : require
 #ifdef GL_ARB_shader_bit_encoding
 #extension GL_ARB_shader_bit_encoding : enable
 #endif
 
 #define HLSLCC_ENABLE_UNIFORM_BUFFERS 1
 #if HLSLCC_ENABLE_UNIFORM_BUFFERS
 #define UNITY_UNIFORM
 #else
 #define UNITY_UNIFORM uniform
 #endif
 #define UNITY_SUPPORTS_UNIFORM_LOCATION 1
 #if UNITY_SUPPORTS_UNIFORM_LOCATION
 #define UNITY_LOCATION(x) layout(location = x)
 #define UNITY_BINDING(x) layout(binding = x, std140)
 #else
 #define UNITY_LOCATION(x)
 #define UNITY_BINDING(x) layout(std140)
 #endif
 uniform     int _ID;
 layout(location = 0) out int SV_Target0;
 void main()
 {
     SV_Target0 = _ID;
     return;
 }

Here the disabled VBO : alt text

So, I will try to create my own render pipeline to avoid this problem (And also because I need to create them for my feature). However, I'm not sure why it works with float because my VBO is also disabled ... maybe undefined behaviour is happening and luckily works with the float instruction ... I don't know


RESOLVE: If you use camera.Render, you need to wait the end of frame. To do this, you can use coroutine like :

     IEnumerator Start()
     {       
         while (true)
         {
             // Wait until all rendering + UI is done.
             yield return new WaitForEndOfFrame();
            YOUR_RENDER_FUNCTION();
         }
     }

capture-decran-2021-09-19-193846.png (188.0 kB)
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

201 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

How to Sample colors from a quad to a RenderTexture? 1 Answer

RenderTexture to Shader everyframe 0 Answers

Pixelart camera shader 2 Answers

[Unity SRP] How do I clear 3d RW RenderTexture? 1 Answer

CustomRenderTexture not working 5 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