Skip to content

Instantly share code, notes, and snippets.

View takumifukasawa's full-sized avatar

takumifukasawa takumifukasawa

View GitHub Profile
@takumifukasawa
takumifukasawa / ConvertLinear01DepthToRawDepth.hlsl
Created May 15, 2023 02:47
Unity: Convert Linear01Depth To Raw Depth
float ConvertLinear01DepthToRawDepth(float d)
{
// Linear01Depth
// return 1.0 / (_ZBufferParams.x * z + _ZBufferParams.y);
// d = 1.0 / (_ZBufferParams.x * z + _ZBufferParams.y);
// d * (_ZBufferParams.x * z + _ZBufferParams.y) = 1.0;
// _ZBufferParams.x * z * d + _ZBufferParams.y * d = 1.0;
// _ZBufferParams.x * z * d = 1.0 - _ZBufferParams.y * d;
// z = (1.0 - _ZBufferParams.y * d) / (_ZBufferParams.x * d);
@takumifukasawa
takumifukasawa / GameObjectPool.cs
Created January 30, 2023 04:59
unity: game object (component) pool
using System.Collections.Generic;
using UnityEngine;
namespace Utilities
{
public class GameObjectPool<T> where T : Component
{
private GameObject _rootObj;
private T _spawnObject;
private int _poolNum;
@takumifukasawa
takumifukasawa / TransformUtilities.cs
Created January 25, 2023 14:13
unity: transform utilities
using UnityEngine;
namespace Utilities
{
// ----------------------------------------------------------------------------------------
// refs:
// https://stackoverflow.com/questions/33437244/find-children-of-children-of-a-gameobject
// ----------------------------------------------------------------------------------------
public static class TransformUtilities
@takumifukasawa
takumifukasawa / ServiceLocator.cs
Created January 21, 2023 06:53
unity simple service locator with singleton component
using System;
using System.Collections.Generic;
namespace Utilities
{
// singleton: https://gist.github.com/takumifukasawa/9519ed0f64abdf68608d098a3441b0d9
public class ServiceLocator : SingletonComponent<ServiceLocator>
{
private static Dictionary<Type, object> _dictionary = new Dictionary<Type, object>();
@takumifukasawa
takumifukasawa / SingletonComponent.cs
Created January 21, 2023 06:51
unity simple singleton component
using System;
using UnityEngine;
namespace Utilities
{
public class SingletonComponent<T> : MonoBehaviour where T : MonoBehaviour
{
private static T _instance;
public static T Instance
@takumifukasawa
takumifukasawa / StateMachine.cs
Last active January 21, 2023 06:51
unity simple state machine
using System;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
namespace Utilities
{
public class StateMachine<T> where T : IConvertible
export class TimeAccumulator {
targetFPS;
#callback;
#lastTime;
maxChaseCount;
constructor(targetFPS, callback, maxChaseCount = 60) {
this.targetFPS = targetFPS;
this.#callback = callback;
export class TimeSkipper {
targetFPS;
#callback;
#lastTime;
constructor(targetFPS, callback) {
this.targetFPS = targetFPS;
this.#callback = callback;
}
@takumifukasawa
takumifukasawa / threejs-sandbox-template.html
Created October 7, 2022 14:47
threejs sandbox template in single html file.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
name="viewport">
<meta content="ie=edge" http-equiv="X-UA-Compatible">
<title>Document</title>
<style>
.wrapper {
@takumifukasawa
takumifukasawa / loadObj.js
Created December 19, 2021 11:01
load obj
// obj の情報はここに書いてある
// https://ja.wikipedia.org/wiki/Wavefront_.obj%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB
export default async function loadObj(path) {
const response = await fetch(path);
const text = await response.text();
const lines = text.split('\n');
// webgl用のデータ群
const positions = [];