Unity Render Pipeline

RP is a series of operations that take the contents of a Scene and displays them on a screen. At a high level, these operations are Culling, Rendering, and Post-Processing. It’s difficult to switch from one to another RP because the shader outputs varies and might not have the same feature. We can custom shaders in different piplelines, but the ultimate effect may be different. Unity has Built-In, Universal, and High Definition and Scriptable RP....

May 30, 2020 · Kyle Fang

Guide Mask Shader

Shader "UI/GuideMask" { Properties { [PreRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} _Color ("tint", Color) = (1,1,1,1) _StencilComp ("Stencil Comparison", Float) = 8 _Stencil ("Stencil ID", Float) = 0 _StencilOp ("Stencil Operation", Float) = 0 _StencilWritemask("Stencil Write Mask", Float ) = 255 _StencilReadMask("Stencil Read Mask", Float) = 255 _ColorMask("Color Mask", Float) = 15 [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0 _Center("Center", vector) = (0, 0, 0, 0) _Slider("Slider", Range(0, 1500)) = 1500 } SubShader { Tags { "RenderType"="Opaque" "IgnoreProjector" = "True" "RenderType" = "Transparent" "PreviewType" = "Plane" "CanUseSpriteAtlas" = "True" } Stencil { Ref [_Stencil] Comp [_StencilComp] Pass [_StencilOp] ReadMask [_StencilReadmask] Writemask [_StencilWriteMask] } Cull Off Lighting Off ZWrite Off ZTest [unit_GUIZTestMode] Blend SrcAlpha OneMinusSrcAlpha ColorMask [_ColorMask] Pass { Name "Default" CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma target 2....

May 7, 2020 · Kyle Fang

Unity Vertex And Fragment Shader

Rendering is done in 2 steps. First, geometry is passed to the vertex function which can alter the position and data of each vertex. Then, the result goes through a fragment function which outputs the color. There’s no albedo, gloss and specular properties in here, so Vertex and fragment shader is often used in non-realistic material, 2D graphics, and post-processing effects. *Surface shader is actually compiled to vert/frag shader. Shader "Unlit/SolidColor" { SubShader { Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag struct vertInput { float4 pos : POSITION; }; struct vertOuput { float4 pos : SV_POSITION; }; vertOuput vert(vertInput input) { vertOuput o; o....

November 30, 2019 · Kyle Fang

Unity Shader Overview

Thanks to these posts and blogs: Michael Sanders Catike Coding Alan Zucconi Unity has 3 types of shader: surface shader, fragment and vertex shader, and the obsolete fixed function shader. They all have the same anatomy. Catlike Coding Shader "MyShader" { Properties { // The properties of your shaders // - textures // - colours // - parameters // ... _MyTexture ("My texture", 2D) = "white" {} _MyNormalMap ("My normal map", 2D) = "bump" {} // Grey _MyInt ("My integer", Int) = 2 _MyFloat ("My float", Float) = 1....

November 30, 2019 · Kyle Fang

Shader Basic

Basics shader language has a single main that returns color at the end final pixel color is assigned to gl_FragColor C-flavored language has built in variable, function, type preprocessor macros (pre-compiled) #define global variable #ifdef and #endif lower precision → faster rendering, less quality precision medium float precision lowp float precision highp float GLSL specs doesn’t guarantee auto-cast vec4(1, 0, 0, 1) will raise error, because it’s not float multiple ways of constructing vec4 vec4 color = vec4(vec3(1....

September 23, 2019 · Kyle Fang