Skip to content

Instantly share code, notes, and snippets.

@fuqunaga
fuqunaga / Log10Slider.cs
Last active February 6, 2019 06:36
Log10Slider
float Log10Slider(float v, float min, float max, string label)
{
using (new GUILayout.HorizontalScope())
{
GUILayout.Label(label);
var log = GUILayout.HorizontalSlider(Mathf.Log10(v), Mathf.Log10(min), Mathf.Log10(max), GUILayout.MinWidth(200f));
v = Mathf.Pow(10, log);
v = GUIUtil.Field(v);
}
return v;
#ifndef TONE_INCLUDED
#define TONE_INCLUDED
half4 _Tone;
half3 CalcTone(half3 c)
{
return lerp(c, _Tone.x*pow(c, _Tone.y) + _Tone.z, _Tone.w);
}
#ifndef QUATERNION_INCLUDED
#define QUATERNION_INCLUDED
#include "./Random.cginc"
#define PI2 6.28318530718
// Quaternion multiplication.
// http://mathworld.wolfram.com/Quaternion.html
float4 qmul(float4 q1, float4 q2)
{
return float4(
#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
@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));
}
}
@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 / 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);
}
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;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GUIOutSideDraggableSample : MonoBehaviour {
public Vector2 mousePos;
Vector2 boxSize = new Vector2(100f, 100f);
GUIStyle whiteBoxStyle;
@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;
}