Skip to content

Instantly share code, notes, and snippets.

@hiroakioishi
hiroakioishi / eulerAnglesToRotationMatrix.hlsl
Created June 15, 2020 13:51
オイラー角(ラジアン)を回転行列に変換
// オイラー角(ラジアン)を回転行列に変換
float4x4 eulerAnglesToRotationMatrix(float3 angles)
{
float ch = cos(angles.y); float sh = sin(angles.y); // heading
float ca = cos(angles.z); float sa = sin(angles.z); // attitude
float cb = cos(angles.x); float sb = sin(angles.x); // bank
// Ry-Rx-Rz (Yaw Pitch Roll)
return float4x4(
ch * ca + sh * sb * sa, -ch * sa + sh * sb * ca, sh * cb, 0,
@hiroakioishi
hiroakioishi / quaternionSlerp.hlsl
Last active June 14, 2020 20:30
Quaternionの球面線形補間(HLSL)
// Quaternion slerp
// https://en.wikipedia.org/wiki/Slerp
float4 slerp(float4 q0, float4 q1, float t)
{
q0 = normalize(q0);
q1 = normalize(q1);
float dot_q0q1 = dot(q0, q1);
bool dotIsNegative = dot_q0q1 < 0.0;
@hiroakioishi
hiroakioishi / randomInsideUnitSphere.hlsl
Created June 2, 2020 05:29
球体内部のランダムな点
// Generate random number
float rand(float2 co)
{
return frac(sin(dot(co.xy, float2(12.9898, 78.233))) * 43758.5453);
}
// 半径1の球体の内部のランダムな点
float3 randomInsideUnitSphere(float co)
{
@hiroakioishi
hiroakioishi / wang_hasl.hlsl
Created June 2, 2020 05:28
wang_hash ランダム
// Wang Hash Random
#define WANG_HASH_SEED_MAX 4294967295
#define INV_WANG_HASH_DIV 2.3283064e-10
float wang_hash(uint seed)
{
seed = (seed ^ 61) ^ (seed >> 16);
seed *= 9;
seed = seed ^ (seed >> 4);
seed *= 0x27d4eb2d;
seed = seed ^ (seed >> 15);
@hiroakioishi
hiroakioishi / quaternion_to_rotation_matrix.hlsl
Last active May 12, 2020 23:49
Quaternionを4x4回転マトリックスに変換
// Quaterion to Rotation Matrix4x4
float4x4 quaternion_to_rotation_matrix(float4 q)
{
float n = 1.0 / sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
q.x *= n;
q.y *= n;
q.z *= n;
q.w *= n;
return float4x4(
// Quaterion to Rotation Matrix4x4
float4x4 quaternion_to_rotation_matrix(float4 q)
{
float n = 1.0 / sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
q.x *= n;
q.y *= n;
q.z *= n;
q.w *= n;
return float4x4(
@hiroakioishi
hiroakioishi / AvoidDoubleLaunch.cs
Last active February 5, 2024 05:04
Unity: アプリケーションの二重起動防止
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 二重起動を防止する
/// </summary>
public class AvoidDoubleLaunch : MonoBehaviour
{
void Start()
@hiroakioishi
hiroakioishi / AsyncMailSender.cs
Created December 19, 2017 02:50
非同期でUnityからメール(GMail)を送信する. 場合によってはGMailのセキュリティ設定で、 安全性の低いアプリのアクセスを オン にしなければならない. https://www.google.com/settings/security/lesssecureapps
using UnityEngine;
using System.Collections;
public class AsyncMailSender : MonoBehaviour {
public string MailFromAddress = "from@gmail.com";
public string MailHost = "smtp.gmail.com";
public int MailPort = 587;
public string MailPassword = "frompassword";
public string MailToAddress = "to@gmail.com";
@hiroakioishi
hiroakioishi / AsyncMailSender.cs
Created December 19, 2017 02:50
非同期でUnityからメール(GMail)を送信する. 場合によってはGMailのセキュリティ設定で、 安全性の低いアプリのアクセスを オン にしなければならない. https://www.google.com/settings/security/lesssecureapps
using UnityEngine;
using System.Collections;
public class AsyncMailSender : MonoBehaviour {
public string MailFromAddress = "from@gmail.com";
public string MailHost = "smtp.gmail.com";
public int MailPort = 587;
public string MailPassword = "frompassword";
public string MailToAddress = "to@gmail.com";
@hiroakioishi
hiroakioishi / VectorFieldFlow.shader
Last active March 1, 2018 08:08
[Unity]デバッグ用に法線方向に矢印を描画するShader
/*
* 2D Vector Field Flow Debug Arrow Render
*
* This code is a porting of
* https://www.shadertoy.com/view/4s23DG
*/
Shader "Debug/VectorFieldFlowArrowRender"
{
Properties