Skip to content

Instantly share code, notes, and snippets.

View sugi-cho's full-sized avatar
😪
zzz

Hironori Sugino sugi-cho

😪
zzz
View GitHub Profile
@sugi-cho
sugi-cho / getAngle.shader
Last active December 20, 2015 15:19
http://sugi.cc/post/57405474012/get-angle-in-shader UnityのShaderで、角度を求める(0~1)
float PI = 3.14159265359;
float x = (atan2(v.vertex.z,v.vertex.x) - PI/2.0);
float y = 2.0*PI;
float angle = (x - y * floor(x/y))/(2.0*PI);
//いちばん、Unityで、ただしそうな、かきかた
float2 p = IN.uv - float2(0.5,0.5);
angle = fmod(atan2(p.y,p.x)-PI/2+2*PI, 2*PI)/(2*PI);
#ifndef COONSCURVE_INCLUDED
#define COONSCURVE_INCLUDED
float3 coons(float t, float3 p0, float3 p1, float3 v0, float3 v1)
{
float3 a = 2*p0 - 2*p1 + v0 + v1;
float3 b = -3*p0 + 3*p1 - 2*v0 - v1;
float t2 = t*t;
float t3 = t2*t;
@sugi-cho
sugi-cho / ImageEffectBase.shader
Last active December 12, 2017 08:47
use vertex shader in surface shader
Shader "Custom/ImageEffectBase" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
CGINCLUDE
#include "UnityCG.cginc"
sampler2D _MainTex;
half4 _MainTex_TexelSize;
Shader "ImageEffect/Base" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
pass{
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
ColorMask RGB
CGPROGRAM
Shader "Custom/surfaceBillbord" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert
@sugi-cho
sugi-cho / ShowMaterialEditor.cs
Last active July 16, 2021 18:59
show material's property in inspector in Unity use this function in Custom Editor Class.
void ShowMaterialEditor(Material[] ms){
for(int i = 0; i < ms.Length; i++){
Material m = ms[i];
if(m == null)
return;
Shader s = m.shader;
EditorGUILayout.LabelField(m.name);
EditorGUI.indentLevel++;
for(int j = 0; j < ShaderUtil.GetPropertyCount(s); j++){
velocity = Vector3.ClampMagnitude(velocity, speedScale * controller.globalSpeed);
Quaternion rotation = Quaternion.FromToRotation(transform.forward, velocity);
transform.rotation = Quaternion.RotateTowards(Quaternion.identity, rotation, controller.globalYawSpeed * yawScale * Time.deltaTime) * transform.rotation;
transform.position += transform.forward * velocity.magnitude * Time.deltaTime;