• Stars
    star
    163
  • Rank 230,040 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created about 2 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Unity editor tool for baking shaders to textures. Texture2D, Texture3D, Flipbook, or MeshRenderer (uses model UV)

BakeShader

Bake

  • 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;
    float3 bakeShaderPos = float3(remappedUV.x, remappedUV.y, 0);
#else
    float3 bakeShaderPos = IN.vertex;
#endif

OUT.vertex = UnityObjectToClipPos(bakeShaderPos); // Built-in RP
OUT.positionCS = TransformObjectToHClip(bakeShaderPos); // URP

More Repositories

1

URP_BlitRenderFeature

Blit Render Feature for Universal RP's Forward Renderer. Set specific source/destination via camera source, ID string or RenderTexture asset. Also options for _InverseView matrix and _CameraNormalsTexture generation.
C#
565
star
2

URP_ShaderGraphCustomLighting

Some custom lighting functions/sub-graphs for Shader Graph, Universal Render Pipeline
HLSL
524
star
3

URP_ShaderCodeTemplates

A few shader code templates/examples for Unity, Universal Render Pipeline (URP v10 / Unity 2020.3). ShaderLab & HLSL.
ShaderLab
267
star
4

ShaderGraphVariables

Adds 'Register Variable' and 'Get Variable' nodes to Shader Graph, allowing you to link sections of a graph without connection wires. <3
C#
251
star
5

URP_WatercolourShaders

A few experiments with watercolour-like shader effects made using Shader Graph. Unity 2020.1.2f1, URP 8.2.0
C#
180
star
6

URP_RetroCRTShader

A shader graph which replicates some retro tv/monitor effects. CRT (cathode-ray tube) warping, scanlines, static, distortion, etc.
C#
141
star
7

Cards

A few scripts which controls interactions for a hand of cards. Card model, shadergraph and example setup included.
C#
128
star
8

ShaderGraphToPNG

Screenshots a Shader Graph in multiple sections, stitches them together and saves the result as a PNG
C#
117
star
9

ToDo

Unity in-editor to-do list, attached as a component and uses a custom inspector based on ReorderableList. Also see branches for ScriptableObject / cross-scene reference version.
C#
81
star
10

URP_GrassGeometryShader

Example of a Grass Geometry Shader for Unity, Universal Render Pipeline. Based on https://github.com/IronWarrior/UnityGrassGeometryShader
HLSL
63
star
11

cyanilux.github.io

Tutorial/blog site, generated using Hugo
HTML
2
star