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

Binary, Decimal, Graycode

Gray code Gray code can reduce the errors of changing bits (or switches). It only needs to change 1 bit at a time to increments the decimal number. Example 1 decimal binary gray code 5 101 111 6 110 101 From 5 to 6, binary has two bits changed, while gray code only changed 1 bit. XOR is the method of converting binary to gray code....

May 26, 2019 · Kyle Fang

Rotation Matrix

$P = (x, y) = (1, 0)$ $P' = (x', y' )$ $\cos{\theta} = \frac{x'}{x}$ $\sin{\theta} = \frac{y'}{x}$ therefore: $x' = \cos{\theta} \cdot x$ $y' = \sin{\theta} \cdot x$ similarly: $Q = (x, y) = (0, 1)$ $ Q' = (x', y' )$ $\cos{\theta} = \frac{y'}{y}$ $\sin{\theta} = \frac{-x'}{y}$ therefore: $x' = -\sin{\theta} \cdot y$ $y' = \cos{\theta} \cdot y$ add them together: $\begin{bmatrix} \cos{\theta} & -\sin{\theta} \\ \sin{\theta} & \cos{\theta} \\...

May 14, 2019 · Kyle Fang

Matplotlib, Figure, Axes, Axis, And Subplot

Figure, Axes, Axis, and Subplot As we can see, the Figure is a top-level container that includes “Axes” and “Axis”.“Axes” is the area where plots appear, while “Axis” is the axis of the plots. Axes is set up by calling subplot, so “Axes” and “Subplot” are synonymous in many cases. Subplot vs. Axes Subplot can arrange grid. plt.subplot(row, col, index) return me an area where occupies part of the Figure. For example:...

January 30, 2019 · Kyle Fang