Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
4
Question by Wowmaniac · Jan 22, 2020 at 03:03 PM · shadersgraphinstances

How to get InstanceId in Shadergraph?

I want to work with instancing using Shadergraph but I can't find a simple way to get the InstanceID in the graph. I believe this would have many uses especially considering ECS uses drawmeshinstanced.

Is there a way to get the InstanceID in Shadergraph without a sloppy workaround?

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 Masterio · Feb 29, 2020 at 02:49 PM 0
Share

You can try create integer field in shader and from the unity script override it on start from c# script.

It is just some idea, maybe there is simpler way idk ;)

Found this also: https://forum.unity.com/threads/instance-id-in-shader.501821/

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by OutOfNothing · Nov 16, 2021 at 03:42 PM

A bit of a Necro, but some updates here for anyone else finding this off google:

Not sure when it was added, but at least in Unity 2021.2, InstanceID is now exposed in the shader graph as a standard node.

You can then add a custom function node which takes in InstanceID, and retrieves variables from a ComputeBuffer assigned to your MaterialPropertiesBlock.

For example, create a hlsl file with the following code, and call getMcguffin via the custom function node.

 #ifndef WHATEVER_INCLUDE_NAME_YOU_LIKE
 #define WHATEVER_INCLUDE_NAME_YOU_LIKE
 
 CBUFFER_START(UnityPerMaterial)
 StructuredBuffer<float4> _WhateverBufferName;
 CBUFFER_END
 
 void getMcguffin_float(in float InstanceID, out float4 mcguffin) {
     mcguffin = _WhateverBufferName[InstanceID];
 }
 #endif

Then pass in the InstanceID on the graph to the custom function node, and take your property out as output.

On the C# side, declaring and attaching the compute buffer to the MaterialPropertyBlock is standard fair, which you can google the syntax for relatively easily.

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 GeorgeAdamon · Dec 14, 2021 at 11:43 PM 0
Share

Thank you !!!

Why do you assign the Buffer via a MaterialPropertyBlock and not directly to the Material ?

avatar image
0

Answer by owen_proto · Feb 29, 2020 at 01:51 PM

I'm also interested in this. Is it possible with a custom node, maybe?

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 DongJooByun · Mar 20, 2020 at 06:56 PM

Any update for this?

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 DongJooByun · Mar 22, 2020 at 11:21 AM 0
Share

If unity has a plan to add this feature, I think it would be a separate node in the shadergraph, like a "instanceId" or "unity_InstanceID" node.

But, I have an opinion about the na$$anonymous$$g of this attribute because I was confused when I started using unity_InstanceID. Correct me if I'm wrong. As I know, the "instance id" is used for representing individual instance among multiple instances. The id of what instance the instances are just "id". Let's say that we have 1,000 particles or points, and we have a box, a sphere and a tetrahedron. When we make the points instance boxes, spheres and tetrahedrons randomly, the instance ids are

0 : box 1 : sphere 2 : tetrahedron

and the ids of particles are

0, 1, 2, ... , 997, 998, 999.

But, I think we've used "instanceId(unity_InstanceID)" like "id" in unity.

All in all, if I have the right understanding about ids, the new node in the shadergraph, should be named as "id". And "instanceId" should be used for instances in the multi-instancing system.

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

134 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

Related Questions

Why are the pixels in a shader only confined to the mesh? 1 Answer

shader graph: the color of the scene breaks down in cases I do not understand 1 Answer

Getting Sprite Renderer data in Shader Graph? 0 Answers

Object velocity affect vertex position in shader graph?? 0 Answers

shader graph: interaction of sky box shader and object shader 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