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
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;
@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++){
Shader "Custom/surfaceBillbord" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert
Shader "ImageEffect/Base" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
pass{
ZTest Always Cull Off ZWrite Off
Fog { Mode off }
ColorMask RGB
CGPROGRAM
@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;
#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 / 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);
@sugi-cho
sugi-cho / alphablend.shader
Created September 9, 2013 10:19
v2f、shader、参考にする書き方
Shader "AngryBots/Particle/AlphaBlend" {
Properties {
_MainTex ("Base", 2D) = "white" {}
_TintColor ("TintColor", Color) = (1.0, 1.0, 1.0, 1.0)
}
CGINCLUDE
#include "UnityCG.cginc"
@sugi-cho
sugi-cho / suikomi.cs
Created September 13, 2013 05:43
てきとう。エラー出るはず!
Mesh mesh = GetComponent<MeshFilter>().mesh;
Vector3 targetPoint;
Vector3[] vertices = mesh.vertices;
float power; //吸い込まれ力
for(int i = 0; i < vertices.Length; i++){
//ここら変の計算を変えて、吸い込まれ方を調整
float d = (vertices[i] - targetPoint).sqrMagnitude;
vertices[i] += (vertices[i] - targetPoint)*Time.deltaTime*d*power;
}
using UnityEngine;
using UnityEditor;
using System.Collections;
public class CreateMesh {
//16250枚Quadが入ったMeshを作る。
[MenuItem("Custom/Create/16250meshes")]
public static void CreateParticleMesh(){
Mesh mesh = new Mesh();
int vertexCount = 65000;