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
0
Question by tcz8 · Apr 02, 2017 at 01:01 AM · shaderspritesbatchinggpuinstancing

Why are my GPU instanced objects all black?

Long story short aka TLDR:
2D Grass shader > vertex animated > can't use batching afaik because objects loose their individual pivot > Trying gpu instancing > pivots are preserved yay! > Instance are all black boo :(

Can it be fixed? > Should I rethink the whole thing?

Long story, the details!:
I am making a shader to animate 2D grass, all features are implemented. Worked great until I implemented a render texture to make the grass fold when objects move through it.

Had to disable batching to get things to work (vertex animated using offsets afaik I need individual pivot points... is there a way around this?) ...batching completely screwed my performance so I got GPU instancing working on my sprites with the code bellow and HURRAY! It works and it doesn't mess with pivot points so my vertex animations work! BOoo! the instances are black.

What It looks like:

Honestly, I really dont care how I fix this. In the end, I need to cover my screen with vegetation. Right now I have about 3500 of those sprites covering the screen and with batching disabled a lot of preformance is lost just for grass. I hope gpu instancing can fix this but I am not even sure I am doing this whole grass thing the right way.

Features I want to keep working:
-Looks like actuall grass standing up, not tiles
-Wind simulation
-Can be displaced by objects moving through it

I need help fixing this and/or figuring if I should take another approach to create the grass.

Thank you for you assistance!

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
Best Answer

Answer by tcz8 · Apr 16, 2017 at 04:12 AM

Well I got this working. The mesh I was creating in code and feeding to Graphic.DrawMeshInstanced had issues.

Just apply the material to a Quad instead.

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

Answer by tanoshimi · Apr 03, 2017 at 06:01 AM

You need to use an Instanced shader on the material assigned to the object.

Comment
Add comment · Show 4 · 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 tcz8 · Apr 03, 2017 at 06:51 AM 0
Share

I already am and I am not setting it's parameters while creating the instance in the script but the shader has default values configured for everything.

avatar image tanoshimi tcz8 · Apr 03, 2017 at 07:13 AM 0
Share

Can you post the shader code you're using then? I don't see any problems per se with the code you've posted to create the mesh. (And does your instanced shader display other instanced objects correctly?)

avatar image tcz8 tanoshimi · Apr 04, 2017 at 05:43 PM 0
Share

The instanced shader is able to display nonrmal objects properly but any instance created with Graphics.Draw$$anonymous$$eshInstanced come out black.

I made the shader with Amplify Shader Editor which is node based.

I read about GPU instancing in Unity's manual and I still cant figure it out.

Here is the code:

 Shader "Custom/Fred/TESTinstance"
 {
     Properties
     {
         _$$anonymous$$askClipValue( "$$anonymous$$ask Clip Value", Float ) = 0.5
         [HideInInspector] __dirty( "", Int ) = 1
         _Color0("Color 0", Color) = (1,1,1,1)
         _$$anonymous$$ainTex("$$anonymous$$ainTex", 2D) = "white" {}
         [HideInInspector] _texcoord( "", 2D ) = "white" {}
     }
 
     SubShader
     {
         Tags{ "RenderType" = "Opaque"  "Queue" = "AlphaTest+0" }
         Cull Back
         CGPROGRA$$anonymous$$
         #pragma target 3.0
         #pragma multi_compile_instancing
         #pragma surface surf Standard keepalpha addshadow fullforwardshadows 
         struct Input
         {
             float2 uv_texcoord;
         };
 
         uniform sampler2D _$$anonymous$$ainTex;
         uniform float4 _$$anonymous$$ainTex_ST;
         uniform float _$$anonymous$$askClipValue = 0.5;
 
         UNITY_INSTANCING_CBUFFER_START(CustomFredTESTinstance)
             UNITY_DEFINE_INSTANCED_PROP(float4, _Color0)
         UNITY_INSTANCING_CBUFFER_END
 
         void surf( Input i , inout SurfaceOutputStandard o )
         {
             float2 uv_$$anonymous$$ainTex = i.uv_texcoord * _$$anonymous$$ainTex_ST.xy + _$$anonymous$$ainTex_ST.zw;
             float4 tex2DNode1 = tex2D( _$$anonymous$$ainTex,uv_$$anonymous$$ainTex);
             o.Albedo = ( ( UNITY_ACCESS_INSTANCED_PROP(_Color0) * UNITY_ACCESS_INSTANCED_PROP(_Color0).a ) + tex2DNode1 ).xyz;
             o.Alpha = 1;
             clip( tex2DNode1.a - _$$anonymous$$askClipValue );
         }
 
         ENDCG
     }
     Fallback "Diffuse"
 }


Show more comments

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

93 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

Related Questions

Unity 5.4 Gpu Instancing reduces amount of saved batches to zero 0 Answers

GPU Instancing (Dynamic Batching) Not Working on Oculus Quest 2 (Android). Works fine in-editor. 0 Answers

How to instance custom sprite shader? 0 Answers

When I enable 'GPU Instancing', transparent object starts flickering. 0 Answers

How can I create GPU Instanced meshes using Texture2DArrays with different texture indices in the SRP? 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