Runtime Texture Baking
For runtime texture baking, first, it is necessary to bake Shader Graph nodes into a .shader file. This is done by the Bake Shader button:

Only the nodes connected to the Shader Graph Baker are used in the generated .shader file.
After baking a .shader, it can be used in runtime scripts by creating a material using this shader. Properties of this material can be adjust in runtime using Unity methods like SetFloat, SetVector, SetColor, etc.
Run-time API for baking material into a texture can be brought into scope with this using directive:
Now Unity Material class will have new ShaderGraphBaker extension with BakeTexture2D(...) and UpdateRenderTexture(...) methods.
BakeTexture2D
Creates Texture2D object and renders material into it.
resolution - Generated texture's resolution.
hasMipmap - should the created texture contain mipmaps?
linear - if baking Normal or Raw Data texture, then this value should be true. It is false for Color Map texture.
UpdateRenderTexture
Renders material into the provided renderTexture. For rendering Normal and Raw Data texture, make sure the renderTexture is created using the linear flag.
Last updated