Skip to content

Instantly share code, notes, and snippets.

@fuqunaga
fuqunaga / simple Dijkstra
Created December 11, 2017 06:34
Route search as a Dijkstra whose cost between nodes is always 1
public struct DijkstraData
{
public float cost;
public Node parent;
}
// Route search as a Dijkstra whose cost between nodes is always 1
protected List<Node> CalcRoute(Node from, Node to)
{
List<Node> ret = null;
@fuqunaga
fuqunaga / DiviedPolygon.cs
Created February 8, 2018 10:34
DiviedPolygon
public class Triangle
{
public Vector3[] vertices { get; protected set; }
public Triangle(Vector3 vtx0, Vector3 vtx1, Vector3 vtx2)
{
vertices = new[] { vtx0, vtx1, vtx2 };
}
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
using System.Linq;
public class TwinBuild : EditorWindow
{
public const string configKey = "TwinBuildReimportAsset";
public const char configKeySeparator = ',';
@fuqunaga
fuqunaga / CalculateObliqueMatrix
Created September 4, 2018 05:22
CalculateObliqueMatrix inplement
// https://forum.unity.com/threads/oblique-near-plane-clipping.194722/
public class Clipper : MonoBehaviour
{
Matrix4x4 projection;
Camera offscreenCam;
void Start ()
{
projection = camera.projectionMatrix;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GUIOutSideDraggableSample : MonoBehaviour {
public Vector2 mousePos;
Vector2 boxSize = new Vector2(100f, 100f);
GUIStyle whiteBoxStyle;
public class BoolDataTemplateSelector : DataTemplateSelector
{
public DataTemplate TrueTemplate { get; set; }
public DataTemplate FalseTemplate { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
// Null value can be passed by IDE designer
if (item == null) return null;
@fuqunaga
fuqunaga / IEnumerableChunks
Last active December 26, 2018 09:29
IEnumerableChunks
public static class IEnumerableExtensions
{
public static IEnumerable<IEnumerable<T>> Chunks<T>(this IEnumerable<T> list, int size)
{
var buf = list;
while (buf.Any())
{
yield return buf.Take(size);
buf = buf.Skip(size);
}
@fuqunaga
fuqunaga / SimplestGSBillboard
Created January 7, 2019 10:16
Simplest Geometry Shader Billboard
Shader "Custom/SimplestGSBillboard"
{
Properties
{
_Size ("Size", Float) = 1.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
@fuqunaga
fuqunaga / DispatchThreadNum
Last active January 11, 2019 13:41
DispatchThreadNum
public static class ComputerShaderExtension
{
public static void DispatchThreadNum(this ComputeShader cs, int kernel, int threadNumX, int threadNumY, int threadNumZ)
{
uint x, y, z;
cs.GetKernelThreadGroupSizes(kernel, out x, out y, out z);
cs.Dispatch(kernel, Mathf.CeilToInt((float)threadNumX / x), Mathf.CeilToInt((float)threadNumY / y), Mathf.CeilToInt((float)threadNumZ / z));
}
}
#ifndef NOISE_INCLUDED
#define NOISE_INCLUDED
//
// Description : Array and textureless GLSL 2D simplex noise function.
// Author : Ian McEwan, Ashima Arts.
// Maintainer : ijm
// Lastmod : 20110822 (ijm)
// License : Copyright (C) 2011 Ashima Arts. All rights reserved.
// Distributed under the MIT License. See LICENSE file.
// https://github.com/ashima/webgl-noise