Skip to content

Instantly share code, notes, and snippets.

View mattatz's full-sized avatar
👁️‍🗨️
Yes

mattatz mattatz

👁️‍🗨️
Yes
View GitHub Profile
@mattatz
mattatz / MatrixToQuaternion.cginc
Created April 23, 2016 04:46
Conversion 4x4 matrix to quaternion cginc
#ifndef _MATRIX_TO_QUATERNION_
#define _MATRIX_TO_QUATERNION_
// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/
float4 matrix_to_quaternion(float4x4 m) {
float tr = m[0][0] + m[1][1] + m[2][2];
float4 q = float4(0, 0, 0, 0);
if (tr > 0) {
@mattatz
mattatz / WindowControl.cs
Last active December 20, 2023 01:49
Unityの画面の位置や解像度の指定、タイトルバーの消去などを行うユーティリティ
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
namespace Utils {
// ここからコードを拝借させてもらいました!
// http://answers.unity3d.com/questions/13523/is-there-a-way-to-set-the-position-of-a-standalone.html
@mattatz
mattatz / LookAtMatrix.cginc
Last active July 28, 2022 05:31
Build a 4x4 look at matrix in cginc
#ifndef _LOOK_AT_MATRIX_
#define _LOOK_AT_MATRIX_
float4x4 look_at_matrix(float3 at, float3 eye, float3 up) {
float3 zaxis = normalize(at - eye);
float3 xaxis = normalize(cross(up, zaxis));
float3 yaxis = cross(zaxis, xaxis);
return float4x4(
xaxis.x, yaxis.x, zaxis.x, 0,
xaxis.y, yaxis.y, zaxis.y, 0,
@mattatz
mattatz / FBXRotationHelper.cs
Created June 22, 2016 04:09
FBXモデルのrootにhelperオブジェクトが置いてある場合に発生する回転のバグを修正するやつ.
using UnityEngine;
using System.Collections;
namespace mattatz.Utils {
/*
* FBXモデルのrootにhelperオブジェクトが置いてある場合に発生する回転のバグを修正するやつ.
* rootオブジェクトをx軸に-90度回転させ,親オブジェクトを追加する.
* http://answers.unity3d.com/questions/13988/asset-import-from-3dsmax-rotation-issue.html
*/
@mattatz
mattatz / GradientTexGen
Created November 28, 2016 04:14
Gradient Texture2D Generator for Unity.
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System.IO;
using System.Collections;
namespace mattatz.Utils {
@mattatz
mattatz / Rand.cs
Created January 11, 2017 04:03
Random class for Unity.
using Random = System.Random;
using UnityEngine;
namespace mattatz {
public class Rand {
Random rnd;
@mattatz
mattatz / ComponentUtil.cs
Last active April 18, 2024 03:04
CopyComponent by Script for Unity
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace Utils
{
@mattatz
mattatz / mat4.h
Last active January 21, 2022 14:30
Column major 4x4 matrix struct for CUDA.
// Column major 4x4 matrix for CUDA.
// Sources:
// - https://github.com/JAGJ10/Snow/blob/master/Snow/matrix.h
// - https://github.com/mrdoob/three.js/blob/master/src/math/Matrix4.js
#pragma once
#include "cuda_runtime.h"
struct mat4 {
@mattatz
mattatz / Easing.hlsl
Created January 19, 2018 04:37
Easing functions for HLSL.
#ifndef _EASING_INCLUDED_
#define _EASING_INCLUDED_
float ease_linear(float x) {
return x;
}
float ease_in_quad(float x) {
float t = x; float b = 0; float c = 1; float d = 1;
return c*(t/=d)*t + b;
@mattatz
mattatz / Quaternion.hlsl
Last active May 14, 2024 21:22
Quaternion structure for HLSL
#ifndef __QUATERNION_INCLUDED__
#define __QUATERNION_INCLUDED__
#define QUATERNION_IDENTITY float4(0, 0, 0, 1)
#ifndef PI
#define PI 3.14159265359f
#endif
// Quaternion multiplication