Skip to content

Instantly share code, notes, and snippets.

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

mattatz mattatz

👁️‍🗨️
Yes
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / RandomPointOnMesh.cs
Created December 25, 2015 08:22
Sample a point randomly on a given mesh script for Unity.
using UnityEngine;
using System.Collections;
namespace Utils {
public class RandomPointOnMesh {
public static Vector3 Sample (Mesh mesh) {
int[] triangles = mesh.triangles;
int index = Mathf.FloorToInt(Random.value * (triangles.Length / 3));
@mattatz
mattatz / TextureAnimation.shader
Last active March 28, 2024 22:37
Texture animation shader for Unity.
Shader "Mattatz/TextureAnimation"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Color ("Color", Color) = (1, 1, 1, 1)
_Cols ("Cols Count", Int) = 5
_Rows ("Rows Count", Int) = 3
_Frame ("Per Frame Length", Float) = 0.5
@mattatz
mattatz / LabColorspace.cginc
Created November 25, 2015 05:35
Conversion between RGB and LAB colorspace shader for Unity.
#ifndef __LAB_COLORSPACE__
#define __LAB_COLORSPACE__
/*
* Conversion between RGB and LAB colorspace.
* Import from flowabs glsl program : https://code.google.com/p/flowabs/source/browse/glsl/?r=f36cbdcf7790a28d90f09e2cf89ec9a64911f138
*/
float3 rgb2xyz( float3 c ) {
float3 tmp;
@mattatz
mattatz / BitwiseOperations.glsl
Created November 13, 2015 06:46
Bitwise operations without operators for glsl.
// BitwiseOperations.glsl
const int BIT_COUNT = 8;
int modi(int x, int y) {
return x - y * (x / y);
}
int or(int a, int b) {
int result = 0;
@mattatz
mattatz / Bezel.shader
Created October 9, 2015 03:00
Post effect shader for Unity : In multiple displays environment, this effect removes display's bezel area.
Shader "PostEffect/Bezel"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_HorizontalCount ("Horizontal Screen Count", Int) = 7
_VerticalCount ("Vertical Screen Count", Int) = 2
_Bezel ("Bezel Size", Vector) = (0.01, 0.01, -1, -1)