Skip to content

Instantly share code, notes, and snippets.

@shivaduke28
shivaduke28 / TransformEncoder.shader
Last active April 7, 2024 19:19
Unity shader encode model matrix to RGBA * 4
/*
MIT License
Copyright (c) 2024 shivaduke28
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@shivaduke28
shivaduke28 / delay_interval.js
Last active December 12, 2023 13:37
cluster item script for delay, interval, cancel.
const cid = () => Math.floor(Math.random() * 1e4);
const delay = (t, f, a) => {
let i = cid();
let l = $.state.l ?? [];
l.push([i, t, f.name, a]);
$.state.l = l;
return i;
};
@shivaduke28
shivaduke28 / SolidAngle.hlsl
Last active October 23, 2023 16:01
Solid angles of spherical triangle and square
float3 SolidAngle(float3 p0, float3 p1, float3 p2)
{
// edges
float cos01 = dot(p0, p1);
float cos12 = dot(p1, p2);
float cos20 = dot(p2, p0);
float sin01Inv = 1 / sqrt(1 - cos01 * cos01);
float sin12Inv = 1 / sqrt(1 - cos12 * cos12);
float sin20Inv = 1 / sqrt(1 - cos20 * cos20);
@shivaduke28
shivaduke28 / UnityPointLight.hlsl
Created October 21, 2023 07:55
Unity PointLight range and attenuation
#include "AutoLight.cginc"
#if defined(POINT)
// 1/range*range for Unity's PointLight
float UnityPointLightRangeInvSqr()
{
float3 unitLS = float3(unity_WorldToLight._m00, unity_WorldToLight._m01, unity_WorldToLight._m02);
return dot(unitLS, unitLS);
}
// https://forum.unity.com/threads/light-dist ance-in-shader.509306/#post-3326818
@shivaduke28
shivaduke28 / LightingDataAssetReplacer.cs
Last active May 6, 2023 06:22
A dirty code to replace LightingDataAsset field of SceneAsset directly
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
public static class LightingDataAssetReplacer
{
@shivaduke28
shivaduke28 / Snell.shader
Last active March 10, 2023 23:25
a minimum Snell's window shader
Shader "Snell"
{
Properties
{
_WaterColor ("Water Color", Color) = (0.2, 0.8, 1, 1)
_Absorption("Absorption (sigma_a)", Color) = (0.3, 0.04, 0.01)
}
SubShader
{
Tags
@shivaduke28
shivaduke28 / GlobalMaterialChanger.cs
Created September 7, 2022 17:38
インタラクトしたらマテリアル変更して同期するやつ
using System;
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
namespace TKMNY
{
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
public class GlobalMaterialChanger : UdonSharpBehaviour
@shivaduke28
shivaduke28 / gist:fcb91bda59fe6f7e739803130e79539a
Created August 22, 2022 16:17 — forked from j5ik2o/gist:2970973
ペアプロの心得

ペアプロの心得

休憩をとる

1.定期的に休憩をとっていますか? ペアプログラミングは、精神的な体力を消耗します。定期的に休憩をとってリフレッシュすることがとても大切です。

謙虚になる

2.「色々な実装方針がある」という認識がありますか?

@shivaduke28
shivaduke28 / streaming_assets.command
Created August 7, 2022 16:20
command file that opens StreamingAssets directory
#!/bin/sh
BASEDIR=$(dirname "$0")
open "$BASEDIR/ArshesClient.app/Contents/Resources/Data/StreamingAssets/"
osascript -e 'tell application "Terminal" to quit' &
exit
@shivaduke28
shivaduke28 / GamingLight.cs
Created March 24, 2022 06:59
GamingLight for Kanikama
using UdonSharp;
using UnityEngine;
public class GamingLight : UdonSharpBehaviour
{
[SerializeField] Renderer[] renderers;
[SerializeField] float intensity;
[SerializeField] float speed;