fguillen
fguillen

Reputation: 38878

Unity, how to set the shader tag "DisableBatching" = "True" in the Shader Graph?

I am creating my first shader using the the Shader Graph, and I am seeing weird behaviour with my vertex positions when I have several objects in the scene using the Shader/Material I have created.

It looks like Unity is batching the objects, not sure yet what does mean, but it looks like I have to deactivate the batching so the vertex positions on my shader remain relative to the object and not to the objects.

Some open threads without solution:

Long story short: How can I add tags, and specifically the DisableBatching tag in my shader created using Shader Graph?

Upvotes: 4

Views: 4052

Answers (2)

Basically Games
Basically Games

Reputation: 11

To add a tag not available in the Shader Graph editor, select your shader graph in the Project tab, and then click the "View Generated Shader" button in the inspector. Copy/paste the code to a new shader file, add the tags you want to the Tags section near the beginning of the shader code and then save it. Be sure to change the shader name at the beginning of the code to easily differentiate between the shader graph version and the modified version.

You'll need to repeat this every time you make changes to the shader graph, as the saved shader won't reflect changes from the graph automatically. This isn't too annoying once you get the process down, just keep this in mind so you don't get confused if you make changes to the shader graph, but don't see them reflected in the materials using the modified shader. To speed up development, I'll usually use the shader graph while actively developing shaders for faster iteration while ignoring the issues caused by the missing tags. Once I'm finished developing a shader I'll add the tags.

Upvotes: 0

John
John

Reputation: 11429

This does not answer your question, but I ended up doing what d2clon did in the forum post you posted, which is to duplicate the material at runtime through a script that you add to the object.

I'm posting this as an answer so people can try out something that worked (for me), without having to read all the threads you posted. I'm also wondering how to disable the batching flag myself, but this will suffice.

public class MaterialDuplicator : MonoBehaviour
{
  void Awake()
  {
    Renderer renderer = gameObject.GetComponent<Renderer>();
    renderer.material = new Material(renderer.material);
  }
}

Upvotes: 1

Related Questions