Last active
March 3, 2024 10:45
-
-
Save m-hayabusa/334b5402706802de29cf55dcf1779747 to your computer and use it in GitHub Desktop.
VRChatのアバターで文字列表示するやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Client } from 'node-osc'; | |
const client = new Client('127.0.0.1', 9000); | |
async function send(path, data) { | |
console.log(path, data); | |
return new Promise(resolve => { | |
client.send(path, data, () => { | |
resolve(); | |
}); | |
}); | |
} | |
(async () => { | |
let row = 0; | |
let col = 0; | |
const str = process.argv[2]; | |
send('/avatar/parameters/nsStrChar', 0 + 0.000000000000001); | |
send("/avatar/parameters/nsStrClearTrigger", 1); | |
await new Promise(r => setTimeout(r, 200)); | |
send('/avatar/parameters/nsStrClearTrigger', 0); | |
// await new Promise(r => setTimeout(r, 100)); | |
for (let i = 0; i < str.length; i++) { | |
if (str[i] == '\n' || col >= 16){ | |
row++; | |
col = 0; | |
} | |
if (str[i] != '\n') | |
{ | |
console.log(str.codePointAt(i)); | |
send('/avatar/parameters/nsStrChar', 0 + 0.000000000000001); //なんかfloatに0入れるとコケる? あとで確認 | |
send('/avatar/parameters/nsStrPosX', (col * 1.0 / 16)+ 0.000000000000001); | |
send('/avatar/parameters/nsStrPosY', (row * 1.0 / 4)+ 0.000000000000001); | |
send('/avatar/parameters/nsStrChar', (str.codePointAt(i) * 1.0 / 255 / 255)+ 0.000000000000001); | |
await new Promise(r => setTimeout(r, 100)); //フレームレートを気にする必要がある | |
col++; | |
} | |
} | |
client.close(); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "nS/StrShader" | |
{ | |
Properties | |
{ | |
_MainTex ("(ダミー)", 2D) = "white" {} | |
_BgColor ("背景色", Color) = (1,1,1,1) | |
_Color ("文字色", Color) = (0,0,0,0) | |
_UnifontTex ("フォント", 2D) = "white" {} | |
_DataTex ("記憶用", 2D) = "white" {} | |
_WidRow ("横幅", Vector) = (16,4,0,0) | |
_CodePoint ("文字", Float) = 0 | |
_Pos_Char ("場所 x,y", Vector) = (0,0,0,0) | |
} | |
SubShader | |
{ | |
Tags { "RenderType"="Fade" "Queue"="Transparent"} | |
Blend SrcAlpha OneMinusSrcAlpha | |
LOD 100 | |
Cull off | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
// make fog work | |
// #pragma multi_compile_fog | |
#include "UnityCG.cginc" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
UNITY_FOG_COORDS(1) | |
float4 vertex : SV_POSITION; | |
}; | |
sampler2D _UnifontTex; | |
sampler2D _DataTex; | |
float4 _Color; | |
float4 _BgColor; | |
float4 _UnifontTex_ST; | |
float4 _WidRow; | |
float _RefreshTrigger; | |
float4 _Pos_Char; | |
float _CodePoint; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = UnityObjectToClipPos(v.vertex); | |
o.uv = TRANSFORM_TEX(v.uv, _UnifontTex); | |
UNITY_TRANSFER_FOG(o,o.vertex); | |
return o; | |
} | |
fixed4 frag (v2f i, fixed facing : VFACE) : SV_Target | |
{ | |
float2 uv_main; | |
uv_main = i.uv.xy * _WidRow.xy; | |
_Pos_Char.xy = floor(_Pos_Char.xy); | |
_Pos_Char.y = _WidRow.y - _Pos_Char.y; | |
_CodePoint = floor(_CodePoint + 0.5) / 256; //四捨五入 | |
float2 charcter = ( | |
_CodePoint != 0 | |
) && ( | |
_Pos_Char.x <= uv_main.x && uv_main.x <= _Pos_Char.x + 1 | |
) && ( | |
_Pos_Char.y - 1 <= uv_main.y && uv_main.y <= _Pos_Char.y | |
) ? float2(frac(_CodePoint) , floor(_CodePoint) / 256) | |
: | |
float2(tex2D(_DataTex, i.uv).r, tex2D(_DataTex, i.uv).g); | |
if(!any(charcter.xy)) { //Nullなら何もせず | |
return (facing > 0) ? _BgColor : tex2D(_DataTex, i.uv); // ←これ何かfixed4(0,0,0,0)でも動くっぽいんだけど何で??? | |
} | |
float color = tex2D(_UnifontTex, float2( | |
fmod( uv_main.x, 1) / 256 + charcter.x, | |
1 - (fmod(-uv_main.y, 1) / 256) - 1.0f/256 - charcter.y | |
)).a; | |
return (facing > 0) ? ( | |
lerp (_BgColor, _Color, color) | |
) : ( | |
fixed4(charcter.x , charcter.y , 0, 1) | |
); | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment