KITASENJU DESIGN BLOG

memo, html, javascript, unity

shader

glslでpowを使った減衰関数

float y(float x) { float offset = 0.0; float xx = x + offset; return cos(xx*10.0)*pow(2.0,-0.9*abs(xx)); }

mosaic effect

glslsandbox.com #extension GL_OES_standard_derivatives : enable precision highp float; uniform float time; uniform vec2 mouse; uniform vec2 resolution; float rand(vec2 co) { float a = fract(dot(co, vec2(2.067390879775102, 12.45116866290824…

fbm

#define OCTAVES 6 float fbm (in vec2 st) { // Initial values float value = 0.0; float amplitud = .5; float frequency = 0.; // // Loop of octaves for (int i = 0; i < OCTAVES; i++) { value += amplitud * noise(st); st *= 2.; amplitud *= .5; }…

短冊状に切るシェーダー

いろんな角度で行けるように極座標にする 回転後の座標系を使い、ランダム関数に渡して短冊状のずれを生む float gx = glitch.z;//分割数 vec2 displace = vec2(0.0,0.0); float rad = glitch.y;//; //座標を回転 float nx = newUV.x * cos(-rad) - newUV.y …

shaderでmatrixを使ってscaleやrotate

float4x4 object2world = (float4x4)0; object2world._11_22_33_44 = float4(scl.xyz, 1.0);//scale float4x4 rotMatrix = eulerAnglesToRotationMatrix(float3(rotX, rotY, rotZ)); object2world = mul(rotMatrix, object2world); rot // オイラー角(ラジ…

checker shader

clip( abs(fmod(round(uvv.x*ss)+stp1,2)-fmod(round(uvv.y*ss+_Time.x)+stp2,2))-0.5 );

はしっこをグラデにするシェーダー

Shader "Unlit/AboutBg" { Properties { _Width ("_Width", float) = 30 } SubShader { Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"} LOD 100 ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Pass { CGPROGRAM #pragma …

shaderで新しいnormalを計算する

float3 getNewVertPos(float3 pos){ float4 hoge = float4(0,0,0,0); hoge.y = _Amp+_Amp*sin( (pos.x*_Detail.x+pos.z*_Detail.z) *3.1415 + _Time.y*4 ); hoge.y *= step(0,pos.y);//マイナスyは無効化する return pos + hoge; } float3 getNewNormal(floa…

Cubemap shader for sphere

cubemap shader for sphere (without skybox) Shader "Unlit/CubeMapForSphere" { Properties { _Cube ("Cubemap", Cube) = "grey" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 100 cull front Pass { CGPROGRAM #pragma vertex vert #pragma frag…

shader dot pattern

https://glslsandbox.com/e#77263.0 #extension GL_OES_standard_derivatives : enable precision highp float; uniform float time; uniform vec2 mouse; uniform vec2 resolution; void main( void ) { vec2 position = ( gl_FragCoord.xy / resolution.xy…

ふたつのsmoothstep

//return x * x * (3.0 - 2.0 * x); return 6.0*x*x*x*x*x - 15.0*x*x*x*x + 10.0*x*x*x;

Mapping function - マッピング関数

js function map (value, fromMin, fromMax, toMin, toMax){ return (value - fromMin) / (fromMax - fromMin) * (toMax - toMin) + toMin; } glsl float map (float value, float fromMin, float fromMax, float toMin, float toMax){ if(value<fromMin)value=fromMin; if(value>fromMax)valu</frommin)value=frommin;>…

シェーダーで陰つける

陰影の、陰(shader)をつける Shader "RDSystem/Surface2" { Properties { _MainTex("RD Texture", 2D) = "white" {} [Space] _Color0("Color 0", Color) = (1,1,1,1) _Color1("Color 1", Color) = (1,1,1,1) [Space] _Smoothness0("Smoothness 0", Range(0, …

alpha test (cut off) on VFX Graph

Select "output particle quad". Check "use alpha clipping" on inspector.

zoom uv on shader

原点に移動してスケールして、また戻す float s = 1 - 0.95 * (0.5 + 0.5 * sin( _Time.y*0.5 )); float2 center = float2(0.5,0.5); i.uv = (i.uv - center) * s + center; fixed4 col = tex2D(_MainTex, i.uv );

ChromaKey PostEffect

Unity でクロマキーシェーダを作ってみた - 凹みTips をpost effectで使えるようにしてみました。 Shader "ChromaKey/ChromaKey_PostEffect" { Properties { [Header(Material)] _Color ("Color", Color) = (1, 1, 1, 1) _MainTex("Texture", 2D) = "white" …

screen pos and unlit

Shader "Unlit/ScreenPos" { Properties { _MainTex ("Texture", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag // make fog work #pragma multi_compile_fog #inclu…

smooth floor

float y(float x) { return floor(x) + smoothstep(0.4,1.0,fract(x)); }

how to access _MainTex_ST

How to get tile/offset information about texture in the surface shader? - Unity Forum Shader "Custom/ST access" { Properties { _MainTex ("Albedo (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } CGPROGRAM #pragma surfac…

gradation shader

in fragment shader fixed4 frag (v2f i) : SV_Target { fixed4 col = float4(1,0,0,1); col = lerp(col,float4(0,1,0,1),smoothstep(0,0.333,i.uv.x)); col = lerp(col,float4(0,0,1,1),smoothstep(0.333,0.666,i.uv.x)); col = lerp(col,float4(1,0,0,1),s…

カメラとの距離 シェーダー

Distance from camera float dist = length(_WorldSpaceCameraPos - i.worldPos);

Depthの位置取得

#pragma kernel MainCS //#include "UnityCG.cginc" #include "./CGINC/SimplexNoise3Db.cginc" #include "./StencilUV.hlsl"// // スレッドグループのスレッドサイズ #define ThreadBlockSize 64//256 // data struct CubeData { // 座標 float3 position; …

shader only shadow caster

影だけ出すシェーダー //screen mapping //https://light11.hatenadiary.com/entry/2018/06/13/235543 //lighting //http://alfa.hatenablog.jp/entry/2015/08/16/195933 Shader "Unlit/ScreenMappingShadowTrans" { Properties { //camer texture _MainTex …

sigmoid function in shader

シグモイド関数 float y(float x) { float contrast=16.0;//4.0,8.0,16.0 return 1.0/(1.0+exp(-contrast*(x-0.5))); //return 1.0/(1.0+exp(-(x-0.5))); } 参考 シェーダ

三角波的なfract

fract like triangle wave UVをミラー的に折り返したいとき。 GLSL Grapher で描画 float y(float x) { return abs(2.0*fract(0.5*x-0.5)-1.0); } unityのシェーダーで。 //hlsl float2 sankaku(float2 x) { return abs(2.0*frac(0.5*x-0.5)-1.0); } 参考 gl…

zwriteをシェーダーから指定

qiita.com

ARFoundationのprojectionMatrix

projectionMatrixかviewMatrixがバグってる.たぶんprojection. _projMat = _camera.projectionMatrix; _viewMat = _camera.worldToCameraMatrix; これをつかってスクリーンスペースのプロジェクションをしようとしたら、なんかおかしい。 ポストエフェクトを…

How to split mesh triangles

Split the connected triangles. ポリゴンを分解する gist.github.com

スプライトのためにgrid上に分割したときの座標

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; public class SpriteUV { public static Vector4 GetUv(int idx,int numX, int numY){ int splitX = numX; int splitY = numY; int xx = idx…

How to modify background shader on ARFoundation

There is ARKitBackground.shader in Library/PackageCache. Copy and rewrite it. I added it so that you can change the brightness. gist.github.com

"FOOTER"