Skip to content

Instantly share code, notes, and snippets.

@quizcanners
Last active February 28, 2024 14:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quizcanners/6bc0b06172977c1a324e81e626079fb2 to your computer and use it in GitHub Desktop.
Save quizcanners/6bc0b06172977c1a324e81e626079fb2 to your computer and use it in GitHub Desktop.
// All functions: http://developer.download.nvidia.com/CgTutorial/cg_tutorial_appendix_e.html
// Performance
// Accessing with "_Name" is slower
Shader.SetGlobalFloat("_Name", value); // =>
int id = Shader.PropertyToID("_Name"); // Once at Start/ OnEnable
Shader.SetGlobalFloat(id, value);
// Trouble-shooting:
// Black Pixels on some devices = Division by zero
// Pixelation after running for while = using _Time to modify sampling uv (loss of percision), consider _SinTime, _CosTime
// Unity crashing and stuff ... also division by zero. A very common scenario: before you initialized values they are zero,
// so if script sets any value intended to be divided by, on the first render frame it may be 0.
// Dictionary:
y=cos(x) // Returns in range [-1, 1] f(0) = 1
y=sin(x) // Returns in range [-1, 1] f(0) = 0
lerp(a,b,t) // (b*t + a*(1-t))
fmod( x , y ) = x % y
frac( x ) = x % 1
_SinTime, _CosTime
_SinTime.x == Sin(t/8)
_SinTime.y == Sin(t/4)
_SinTime.z == Sin(t/2)
_SinTime.w == Sin(t)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment