• Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

This is an Unity editor extension for generating shader code from template files.

uShaderTemplate

uShaderTemplate is an editor asset to create shaders from templates.

Install

  • Unity Package
  • Git URL (UPM)
    • Add https://github.com/hecomi/uShaderTemplate.git#upm to Package Manager.
  • Scoped Registry (UPM)
    • Add a scoped registry to your project.
      • URL: https://registry.npmjs.com
      • Scope: com.hecomi
    • Install uShaderTemplate in Package Manager.

Usage

  1. Prepare Shader Template file.
  2. Create Generator from Create > Shader > uShaderTemplate > Generator.
  3. Input Shader Name and select Shader Template from the inspector.
  4. Edit items in Conditions, Variables, and codes in code editors.
  5. Press Export (Ctrl+R) button to create a shader from the Generator.

Overview

Generator is an asset file that manages a generated shader, save parameters, and provide an interface to customize the shader with some rules written in shader template. The following image is an example of a Generator inspector which is automatically generated from shader template.

Inspector

The interface is generated from uShaderTemplate > Examples > Editor > Resources > ShaderTemplates > 1. VertFrag.txt. This is the content of this file:

1. VertFrag.txt

Shader "Custom/<Name>"
{

Properties
{
@block Properties
_MainTex("Texture", 2D) = "white" {}
@endblock
}

SubShader
{

Tags { "Queue"="<Queue=Geometry|Transparent>" "RenderType"="<RenderType=Opaque|Transparent>" }
LOD <LOD=100>

CGINCLUDE

#include "UnityCG.cginc"

struct v2f
{
    float2 uv : TEXCOORD0;
@if UseFog : true
    UNITY_FOG_COORDS(1)
@endif
    float4 vertex : SV_POSITION;
};

@block VertexShader
sampler2D _MainTex;
float4 _MainTex_ST;

v2f vert(appdata_full v)
{
    v2f o;
    o.vertex = UnityObjectToClipPos(v.vertex);
    o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
    UNITY_TRANSFER_FOG(o,o.vertex);
    return o;
}
@endblock

@block FragmentShader
fixed4 frag(v2f i) : SV_Target
{
    fixed4 col = tex2D(_MainTex, i.uv);
    UNITY_APPLY_FOG(i.fogCoord, col);
    return col;
}
@endblock

ENDCG

Pass
{
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
@if UseFog : true
    #pragma multi_compile_fog
@endif
    ENDCG
}

}

CustomEditor "uShaderTemplate.MaterialEditor"

}

You might have found some grammars like @if foo, <Bar>, @block baz, and these are special grammmars available in template file. Shader variant like #pragma multi_compile and #pragma shader_feature cannot customize the section outside CGPROGRAM, but with these grammar, you can customize the all parts of the shader.

If you put template files like this in Resources > ShaderTemplates, they are automatically detected and shown in the Shader Template field in Basic section.

Grammars in Shader Template

// Condition:
//   A toggle filed labeled "Hoge Hoge" will appear in Conditions section.
//   Only when checked, the content will be output.
@if HogeHoge
#define HOGEHOGE
@endif

// You can use else block and give a default condition.
@if HogeHoge2 : false
#define HOGEHOGE2
@else
#define HOGEHOGE3
@endif

// Variable:
//   The name with <> will appear in Variables section as a text field.
//   You can give a default value with =, and =| will be pull-down list.
#define Hoge <Hoge>
#define Fuga <Fuga=Hoge> //
#define Piyo <Piyo=Hoge|Fuga|Piyo>

// Block:
//    The content will be a code editor.
//    Output shader has block like // @block ~ // @endblock and
//    if you edit the content directly with your own editor like Vim,
//    the result will be applied to the code editor in inspector.
@block Moge
float Moge2() { return _Move * _Moge; }
@endblock

Buttons

Buttons

  • Export(Ctrl+R)
    • Export shader from Generator. You can use Ctrl + R as a shortcut key instead of pressing this button.
  • Create Material
    • Create material from the generated shader.
  • Reset to Default
    • Reset all parameters to the default parameters written in template.
  • Update Template
    • If you edit the template file, please press this before the export.
  • Reconvert All
    • Convert all generated shaders forcedly. This is useful when you edit template file and want to apply the change to all shaders.

Constants

Constants

Instead of inputting variables in each inspector, you can use Constants asset as a shared variables among multiple Generators.

Select Create > Shader > uShaderTemplate > Constants and add Name and Value pair to Values field of the created Constants asset. Then, drag and drop it to the Constants field of Generators which you want to apply the parameters to. Please remember that if you modify a parameter in Constants, you have to Reconvert All to apply the change to all generated shaders.

In a shader template, you can specify the default Constants using @constants line if you want it.

Shader "Custom/<Name>"
{

// you can insert this line anywhere in the template file.
@constants uShaderTemplate/Constants/Custom Constants

Properties
{
...

Callbacks

Generator and Constants have virtual functions, OnBeforeConvert() and OnAfterConvert(). You can create custom Generator and Constants inherited from these classes and override them to add callbacks just before and after convert.

More Repositories

1

uRaymarching

Raymarching Shader Generator in Unity
HLSL
1,189
star
2

UnityFurURP

Fur shader implementation for URP
HLSL
659
star
3

uLipSync

MFCC-based LipSync plug-in for Unity using Job System and Burst Compiler
C#
556
star
4

uREPL

In-game powerful REPL environment for Unity3D.
C#
533
star
5

uDesktopDuplication

Desktop Duplication API implementation for Unity (only for Windows 8/10)
C++
509
star
6

uWindowCapture

This allows you to use Windows Graphics Capture / PrintWindow / BitBlt in Windows to capture multiple windows individually and easily use them as Texture2D in Unity.
C++
469
star
7

UnityScreenSpaceBoolean

Screen Space Boolean Implementation for Unity.
ShaderLab
244
star
8

UnityWaterSurface

Water Surface Simulation using CutomRenderTexture in Unity 2017.1
ShaderLab
236
star
9

UnityVolumeRendering

A simple example of Volume Rendering for Unity.
GLSL
159
star
10

uRaymarchingExamples

Examples using uRaymarching (https://github.com/hecomi/uRaymarching)
C#
141
star
11

MMD4Mecanim-LipSync-Plugin

LipSync and TTS Plugin for MMD4Mecanim
C#
140
star
12

UnityPseudoInstancedGPUParticles

GPU Particles w/ Screen Space Collision Example.
GLSL
109
star
13

UnityECSBoidsSimulation

Simple Boids simulation example using Unity ECS.
C#
108
star
14

uWintab

Wintab API plugin for Unity
C++
99
star
15

node-mecab-async

Asynchronous japanese morphological analyser using MeCab.
JavaScript
94
star
16

uChromaKey

Chroma key shader asset for Unity
ShaderLab
91
star
17

uDllExporter

Tool to build DLLs in Unity.
C#
80
star
18

VrGrabber

VR Grabber components for Unity
C#
79
star
19

node-julius

Node.js module for voice recognition using Julius
C
72
star
20

UnityRemoteDesktopDuplication

An Unity example to send a desktop image to a remote PC using Desktop Duplication API and NVENC/NVDEC.
C#
64
star
21

uHomography

Homography Transformation Image Effect for Unity.
C#
64
star
22

HLSLToolsForVisualStudioConfigGenerator

Create shadertoolsconfig.json for Unity project
C#
60
star
23

uCurvedScreen

Curved-sreen shader aseet for Unity.
ShaderLab
57
star
24

UnityRaymarchingCollision

Raymarching x Rigidbody interaction example.
GLSL
54
star
25

NodejsUnity

Run Node.js automatically when Unity application starts, and they communicate with each other.
C#
51
star
26

UWO

Unity WebGL x WebSocket MMO demo
C#
49
star
27

node-openjtalk

Node.js TTS module using OpenJTalk
C++
49
star
28

Unity-WebGL-3D-Chat

Unity5 WebGL x Socket.IO = Online 3D Chat on the web browser!
JavaScript
44
star
29

UnityScreenSpaceReflection

Simple Screen Space Reflection Implementation.
GLSL
43
star
30

UnityDICOMVolumeRendering

This is a simple project for volume rendering of DICOM data in Unity.
C#
43
star
31

UnityRaymarchingSample

Unity3D Raymarching Simple Implementation.
GLSL
41
star
32

uNvEncoder

A simple wrapper of NVENC (NVIDIA's HW-accelerated encoder) for Unity.
C
41
star
33

uTouchInjection

Windows Multitouch Injection Plugin for Unity.
C#
38
star
34

UnityNativeTextureLoader

This is an example to load textures from StreaminAssets directory or web in a native plugin.
C++
36
star
35

tsubakumi2

Home Automation System for @hecomi room
JavaScript
36
star
36

HoloLensPlayground

My playground for HoloLens.
C#
31
star
37

uNvPipe

A simple NvPipe wrapper for Unity
C
25
star
38

UnityTimelineExample

A simple example of creating custom Track and Clip
C#
22
star
39

StereoAR-for-Unity

Oculus Rift にて 2 つの Playstation Eye を通じて現実世界を立体視し、更にそこへ AR を重畳するプロジェクトです。
C#
20
star
40

LITTAI

Interaction recognizer for LITTAI project.
C++
20
star
41

LITTAI-game

Unity project for the table-top projection game, LITTAI.
C#
20
star
42

unity-android-aruco-sample

Unity x Android x OpenCV x ArUco sample project.
C++
20
star
43

UnityCustomTextureUpdate

An example to load texture using CustomTextureUpdate().
C
19
star
44

node-wemo

Belkin 社の WeMo を操作する Node モジュールです
JavaScript
19
star
45

UnityRaymarchingForward

Example of raymarching in forward rendering for Unity
HLSL
17
star
46

UnityKinectV2DeferredRendering

Unity sample project to draw KinectV2 depth sensor values into G-Buffer directly.
C#
17
star
47

QwertyVR

An Unity sample project for my Mixed Reality-based concept, Visual IO.
C#
17
star
48

uNetVoice

Tiny voice chat implementation for Unity.
C#
16
star
49

CyalumeLive

Unity でシェーダを使って 20,000 人がサイリウムを音楽に合わせて振るデモです。
C
14
star
50

UnityWebGLAudioStream

A simple sample that uses the Web Audio API to play float[] sent from Unity in a WebGL build
C#
10
star
51

node-oll

Node.js module for oll (Online-Learning Library)
Shell
10
star
52

create-upm-branch-action

A Github Actions to create release branches for Unity Package Manager
Shell
10
star
53

UnityCustomFunctionNodeExample

Custom Function Node Example in Unity Shader Graph
HLSL
9
star
54

T265_Playground

Simple implementation of positional tracking for Oculus Go
C#
8
star
55

HmdInputModule

Unity VR cursor module
C#
7
star
56

dotfiles

...
Vim Script
7
star
57

node-iRemocon

iRemocon module for Node.js
JavaScript
7
star
58

node-execSync

node.js で shell コマンドを同期的に実行するアドオンです
C++
7
star
59

UnityCustomTextureUpdateForDXT1

CustomTextureUpdate for DXT1
C
7
star
60

Julius2iRemocon

Home electronics operation by speech recognition is enabled using Julius and iRemocon.
C++
6
star
61

MyoUnity-with-RawData

Emg raw data and RSSI are available
C#
5
star
62

uPacketDivision

A native plugin for Unity that provides simple packet division and restoration.
C++
5
star
63

qml-osc

QML custom element that can handle OSC.
C++
5
star
64

NativePluginExample

Unity Advent Calendar 2017 - 21 日目の記事のサンプルプロジェクトです
C#
4
star
65

node-kaden

node.js-based home electronics control system.
C
3
star
66

Outlinus

VR Effect Tool for Oculus Rift x Ovrvision
C++
3
star
67

node-openjtalk-waf

C
3
star
68

node-kana2voca

Katakana to Julius voca format converter
C++
3
star
69

TangoPlayground

my Google Tango application playground (Unity).
C#
3
star
70

node-tw2email

Twitter の特定のリストの TL をメールで送信してくれるヤツです
JavaScript
3
star
71

HAS-Project

Home Automation System (HAS) Project that makes our life lazier.
C++
2
star
72

Xml2dfa

[Julius] コマンドを記述した XML ファイルから dfa ファイルと dict ファイルを生成する
C++
2
star
73

node-voca

ICU を利用してカタカナをローマ字や Julius の voca 形式に変換する Node.js アドオンです。
C++
2
star
74

unite-fhc

Unite.vim source for Future Home Controller
Vim Script
1
star
75

JuliuslibTest

C
1
star
76

LegoAnalyzer

Maker Faire Tokyo に出展予定の LEGO の凹凸を検出する Qt ベースのアプリです
C++
1
star
77

Hellospc

HelloSPCafe
C
1
star
78

node-mecab

node.js から MeCab を利用したり文字列をカタカナに変換するアドオンです
C++
1
star
79

tsubakumi

音声認識家電コントロールシステム@hecomi 家
JavaScript
1
star
80

Blender

Blender 作品のアーカイブです。
1
star
81

tsubakumi-android-wear

凹家のホームオートメーションの Android Wear 連携用プロジェクト
Java
1
star
82

uMicrophoneWebGL

Enable microphone input buffer access in Unity WebGL builds
C#
1
star