Skip to content

Instantly share code, notes, and snippets.

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

mattatz mattatz

👁️‍🗨️
Yes
View GitHub Profile
@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)
@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 / 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 / UVTransform.shader
Created April 6, 2015 02:28
Example of uv transform shader for Unity.
Shader "Mattatz/UVTransform" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_TexScale ("Scale of Tex", Float) = 1.0
_TexRatio ("Ratio of Tex", Float) = 1.0
_Theta ("Rotation of Tex", Float) = 0.0
_PlaneScale ("Scale of Plane Mesh", Vector) = (1, 1, 0, 0)
}
@mattatz
mattatz / THREE.GradientCubeTexture.js
Last active January 26, 2021 15:43
Vertical linear gradient colored cube texture in three.js
// Vertical gradient cube texture
export default class GradientCubeTexture extends THREE.CubeTexture {
constructor(bottom = '#4488aa', top = '#aaddff', size = 32) {
super()
// px, nx, py, ny, pz, nz
this.images[0] = this.create(top, bottom, size)
this.images[1] = this.create(top, bottom, size)
@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 / Cone.cs
Last active March 15, 2022 23:53
Example of a cone mesh creator for Unity.
using UnityEngine;
using System.Collections;
[RequireComponent (typeof (MeshFilter))]
public class Corn : MonoBehaviour {
public int subdivisions = 10;
public float radius = 1f;
public float height = 2f;
@mattatz
mattatz / LIC.shader
Last active April 3, 2022 14:09
Simple Line Integral Convolution shader for Unity.
Shader "Mattaz/LIC" {
Properties {
_VectorFieldTex ("Vector Field Texture", 2D) = "white" {}
_NoiseTex ("Noise Texture", 2D) = "white" {}
_FlowLength ("Flow Length", int) = 10
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
@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 / 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) {