https://github.com/Cyanilux/BakeShader
Unity editor tool for baking shaders to textures. Texture2D, Texture3D, Flipbook, or MeshRenderer (uses model UV)
https://github.com/Cyanilux/BakeShader
baking blit shaders texture-baking unity uv
Last synced: 8 months ago
JSON representation
Unity editor tool for baking shaders to textures. Texture2D, Texture3D, Flipbook, or MeshRenderer (uses model UV)
- Host: GitHub
- URL: https://github.com/Cyanilux/BakeShader
- Owner: Cyanilux
- License: mit
- Created: 2022-08-31T13:11:05.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-03-04T22:36:50.000Z (over 2 years ago)
- Last Synced: 2024-06-06T09:34:43.911Z (about 2 years ago)
- Topics: baking, blit, shaders, texture-baking, unity, uv
- Language: C#
- Homepage:
- Size: 29.3 KB
- Stars: 158
- Watchers: 6
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- anything_about_game - BakeShader
README
## BakeShader

- Adds "Bake Shader" window (under Window/Cyanilux/BakeShader)
- Includes modes : Texture2D (png), Texture3D asset, Flipbook, MeshRenderer
- Also adds "Bake" options to the "..." context menus on Material asset and MeshRenderer component
- (If BakeShader window is open, this will use resolution & path settings set there, otherwise uses defaults mentioned below)
- Should work in any render pipeline!
- By default, results are saved under Assets/BakedTextures
### Setup:
- Install via Package Manager → Add package via git URL :
- `https://github.com/Cyanilux/BakeShader.git`
- Alternatively, download and put the folder in your Assets
### Bake Modes :
- **Texture2D (png)**
- Shader is blit (basically draws a quad)
- Result saved as .png
- Defaults to 2048x2048 size
- **Texture3D**
- Shader is blit in slices. Use `_Slice` Float property in shader calculations. This ranges from 0 to 1 through the depth of the Texture3D
- Result saved as Texture3D asset
- Defaults to 128x128x128 size
- **Flipbook**
- Same as Texture3D, but slices are combined vertically into a long Texture2D
- Result saved as .png, this could then be imported as a regular texture (for usage with Flipbook node later) or as a 2D Array, or 3D Texture.
- Defaults to 256x256 size (per slice), 32 slices, (so final image size of 256x8192)
- **MeshRenderer : Renderer is drawn to Texture2D**
- Will bake using first Material only. Scene View must be open for Renderer baking to occur
- Defaults to 2048x2048 size
- For the intended result, shader should be **unlit** and **output using UV coordinates instead of vertices** :
- For Shader Graphs, use the provided `Bake Shader Vertex Pos` subgraph in the **Position** port on the **Vertex** stack. Also use `Render Face : Both` in graph settings.
- Note that using the `Position` node in **Fragment** stage will now produce different results, as this changes the vertex positions. In v12+ we can avoid this by using a **Custom Interpolator** to pass the unmodified vertex pos through, if required. See : https://www.cyanilux.com/tutorials/intro-to-shader-graph/#custom-interpolators
- For Shader Code (CG/HLSL), the following should work (though some variables may need renaming). The pass should also specify `Cull Off`
```
#pragma multi_compile _ _BAKESHADER
// in vertex function :
#ifdef _BAKESHADER
float2 remappedUV = IN.uv.xy * 2 - 1;
float4 outputPos = float4(remappedUV.x, remappedUV.y, 0, 1);
OUT.vertex = outputPos; // Built-in RP
OUT.positionCS = outputPos; // URP
#else
OUT.vertex = UnityObjectToClipPos(IN.vertex); // Built-in RP
OUT.positionCS = TransformObjectToHClip(IN.vertex); // URP
#endif
// (where "vertex" / "positionCS" is the common naming convention for the parameter using SV_POSITION semantic)
```