Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
✅
‏‏‎

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / Toolkit
Created October 9, 2020 19:37 — forked from gering/Toolkit
persitent data path handling in Unity with fallback
private static string[] _persistentDataPaths;
public static bool IsDirectoryWritable(string path) {
try {
if (!Directory.Exists(path)) return false;
string file = Path.Combine(path, Path.GetRandomFileName());
using (FileStream fs = File.Create(file, 1)) {}
File.Delete(file);
return true;
} catch {
@unitycoder
unitycoder / ColorSpaces.inc.glsl
Created October 11, 2020 16:52
Utility functions to convert between various color spaces in GLSL (RGB sRGB XYZ xyY HCV HUE HSV HSL HCY YCbCr)
// https://github.com/tobspr/GLSL-Color-Spaces/blob/master/ColorSpaces.inc.glsl
/*
GLSL Color Space Utility Functions
(c) 2015 tobspr
-------------------------------------------------------------------------------
The MIT License (MIT)
Copyright (c) 2015
@unitycoder
unitycoder / SurfaceDepthTexture.shader
Last active November 12, 2024 11:08
Shader World Position From Depth (Frag or Surf shader)
Shader "Custom/SurfaceDepthTexture" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
_InvFade ("Soft Factor", Range(0.01,3.0)) = 1.0
}
SubShader {
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
@unitycoder
unitycoder / ResizeWithAspectRatio.cs
Created October 14, 2020 08:53
Calculate resize with aspect ratio (scale)
//// get aspect ratio https://stackoverflow.com/a/32593158/5452781
int sourceWidth = 3000;
int sourceHeight = 2000;
int targetWidth = 1920;
int targetHeight = 1080;
float percent = (new List<float> { (float)targetWidth / (float)sourceWidth, (float)targetHeight / (float)sourceHeight }).Min();
Size resultSize = new Size((int)Math.Floor(sourceWidth * percent), (int)Math.Floor(sourceHeight * percent));
Console.WriteLine("size= " + sourceWidth + "x" + sourceHeight + " percent= " + percent + " result=" + (sourceWidth * percent) + "x" + (sourceHeight * percent));
@unitycoder
unitycoder / LatLong.cs
Created October 22, 2020 14:07
lat lon math (latitude longitude)
// https://forum.unity.com/threads/world-globe-with-latitude-and-longitude.992414/#post-6444961
using UnityEngine;
namespace YourNamespace {
public struct LatLong {
public const float PI = Mathf.PI;
public const float TWO_PI = 2f * PI;
public const float PI_HALF = .5f * PI;
@unitycoder
unitycoder / zigzag-encoding.README
Created October 25, 2020 16:56 — forked from mfuerstenau/zigzag-encoding.README
ZigZag encoding/decoding explained
ZigZag-Encoding
---------------
Maps negative values to positive values while going back and
forth (0 = 0, -1 = 1, 1 = 2, -2 = 3, 2 = 4, -3 = 5, 3 = 6 ...)
(i >> bitlength-1) ^ (i << 1)
with "i" being the number to be encoded, "^" being
XOR-operation and ">>" would be arithemtic shifting-operation
@unitycoder
unitycoder / SpriteWaterShape.cs
Created October 29, 2020 11:15 — forked from staggartcreations/SpriteWaterShape.cs
Sprite shape animated water volume
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;
[ExecuteInEditMode]
public class SpriteWaterShape : MonoBehaviour
{
public SpriteShapeController controller;
@unitycoder
unitycoder / negative.shader
Created November 9, 2020 07:59
negative invert shader
// https://forum.unity.com/threads/invert-colors-shader.205244/#post-3060583
Shader "Particles/Negative" {
Properties {
_TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
_MainTex ("Texture", 2D) = "white" {}
_Glow ("Intensity", Range(0,10)) = 1 //Allows color saturation in HDR rendering.
}
SubShader {
Tags { "Queue" = "Transparent" "PreviewType" = "Plane"}
LOD 100
@unitycoder
unitycoder / PhotoshopMathFP.hlsl
Created November 9, 2020 08:13
PhotoshopMath hlsl shader
// https://mouaif.wordpress.com/2009/01/05/photoshop-math-with-glsl-shaders/
/*
** Photoshop & misc math
** Blending modes, RGB/HSL/Contrast/Desaturate
**
** Romain Dura | Romz
** Blog: http://blog.mouaif.org
** Post: http://blog.mouaif.org/?p=94
*/
@unitycoder
unitycoder / nsight.txt
Last active July 7, 2022 10:01
nvidia nsight notes
### New 2022: install every tool on their default folders! (that is c: usually.. it fixes many problems)
trying to build c++ project:
*command to test with:
cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_GENERATOR_INSTANCE="C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools" -DNV_INSTALL_FOLDER=bin .. && cmake --build . --config RelWithDebInfo --target install
error when click build:
"could not find specified instance of Visual Studio: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools"