Skip to content

Instantly share code, notes, and snippets.

View TheAllenChou's full-sized avatar
🐰
Bunnies.

Ming-Lun "Allen" Chou TheAllenChou

🐰
Bunnies.
View GitHub Profile
@TheAllenChou
TheAllenChou / Seek.cs
Last active August 26, 2019 10:15
Value Seeking
// example of how to move a current value towards a target value at a constant speed
// without going over the target value
// formula is the same for vectors of any dimension
Vector3 Seek(Vector3 currentValue, Vector3 targetValue, float maxSpeed, float dt)
{
// delta/difference from current value to target value
Vector3 delta = targetValue - currentValue;
// don't take the square root of magnitude yet
// so we can potentially early out on degenerate case of currenvValue ~= targetValue
Vector3 inputVec = Vector3.zero;
if (Input.GetKey(KeyCode.UpArrow))
inputVec += Vector3.up;
if (Input.GetKey(KeyCode.DownArrow))
inputVec += Vector3.down;
if (Input.GetKey(KeyCode.LeftArrow))
inputVec += Vector3.left;
@TheAllenChou
TheAllenChou / SdfQuantize.cginc
Last active July 6, 2020 14:33
Smooth Quantization of Signed Distance Field Sample Points
float3 quantize(float3 p, float cellSize, float strength)
{
float3 r = p / cellSize;
float3 f = floor(r);
float3 t = r - f;
return (f + smoothstep(0.0f, 1.0f, strength * (t - 0.5f) + 0.5f)) * cellSize;
}
string rpAsset = "";
if (GraphicsSettings.renderPipelineAsset != null)
rpAsset = GraphicsSettings.renderPipelineAsset.GetType().Name;
if (rpAsset.Equals("HDRenderPipelineAsset"))
renderPipeline = RenderPipeline.HDRP;
else if (rpAsset.Equals("UniversalRenderPipelineAsset"))
renderPipeline = RenderPipeline.URP;
else
renderPipeline = RenderPipeline.BuiltIn;
bool (*functions[])() =
{
Function0,
Function1,
Function2,
};
bool LogicalAnd()
{
for (auto f : functions)