Skip to content

Latest commit

 

History

History
125 lines (78 loc) · 6.12 KB

README.md

File metadata and controls

125 lines (78 loc) · 6.12 KB

Shaders And CG Notes On Unity

Experiments and notes based on different sources. This page shows the effects and key points of shaders created. Also for each experiment, there is a link to see full codes. Shaders are created in cg for now.

Sources

Assets

Many thanks to the creators of these valuable sources.

Experiments

Experiment_002 Stencil Shader

Hole Mechanic From Donut County

StencilMask Shader

StencilBlocked Shader

See Full Stencil Shader Codes

Experiment_003 Kaleidoscope Effect

Kaleidoscope Effect

Kaleidoscope Shader

See Full Kaleidoscope Effect Shader Codes

Note: Unity_Rotate_Degrees_float is a function written by Unity included in Shader Graph. The function rotates the value of input UV around a reference point defined by the input Center by the amount of input rotation. See in Shader Graph Manual

Experiment_004 Zoom Effect

Zoom Effect Kaleidoscope Shader
See Full Zoom Effect Shader Codes

Experiment_005 Health Bar

Experiment_005.1 Simple Health Bar

Simple Health Bar Simple Health Bar Shader

Experiment_005.2 Fancy Health Bar

Fancy Health Bar Fancy Health Bar Shader

See Full Healthbar Shader Codes

Note: My implementation for roundness and border is overcomplex. It can be easily made with SDF. Please watch this part from Freya Holmér's Shader Video if you'd like to see a clean implementation.

Experiment_006 Sprite Outline Effect

Sprite Outline Sprite Outline Shader
See Full Sprite Outline Shader Codes

Experiment_007 Lighting

Lambertian Phong Lambertian Phong Shader
See Full Lighting codes

Note 1: _LightColor0, _WorldSpaceLightPos0 and _WorldSpaceCameraPos are built-in shader variables in Unity. See document here.
Note 2: reflect is a cg function that returns the reflection vector given an incidence vector i and a normal vector n. See document here.
Note 3: We used Tags{"LightMode" = "ForwardBase"} in code because we want to use Forward rendering. This rendering target is the default in Unity. See document here.

Experiment_008 Fresnel Effect

Fresnel Effect

Fresnel Shader

See Full Fresnel Effect Shader Codes


Note: This effect only works properly on rounded objects due to its nature. It is a popular technique used in many games.

Experiment_009 Gradient Effect

Gradient Effect

Gradient Shader

See Full Gradient Effect Shader Codes

Experiment_010 UV Distortion Effect

UV Distortion Effect

UV Distortion Shader

See Full UV Distortion Effect Shader Codes

Experiment_011 Raymarching

Raymarching Gradient Spheres

Raymarching Lava Lamp

Here is good resources that I used to learn this technique:

Note: Since shaders are a bit larger than other examples I didn't add them here. Please take a look at them link down below.

See Raymarching Codes