- 2022.03.28 Monday
- スポンサーサイト
-
一定期間更新がないため広告を表示しています
- | スポンサードリンク | - | | - | - | pookmark |
- 2016.05.31 Tuesday
- 全部のjointの移動、回転、スケール キーのベイク mel
-
全部の移動、回転、スケール キーのベイク
このまえにジョイント選択たり
全部のキーの最後とったりしなきゃだけど。
bakeResults -simulation true -t "0:100" -attribute "tx" -attribute "ty" -attribute "tz" -attribute "rx" -attribute "ry" -attribute "rz" -attribute "sx" -attribute "sy" -attribute "sz" -sampleBy 1;
  - | whaison | MEL(Maya Embedded Language) | 13:52 | comments(0) | - | pookmark |
- 2016.05.29 Sunday
- GLSL でなんかshaderが書けるゴリゴリのios7アプリ Gryphos GmbH「Shaderific - OpenGL ES shader development with GLSL」 https://appsto.re/jp/JyVBE.i
-
GLSL でなんかshaderが書けるゴリゴリのios7アプリ Gryphos GmbH「Shaderific - OpenGL ES shader development with GLSL」 https://appsto.re/jp/JyVBE.i
きいろ
シェーダ名変えてDone saveで右上で再生
できた - | whaison | OpenGL,OpenGLES,glsl,DirectX,hlsl,webGL,metal,vulkan | 14:36 | comments(0) | - | pookmark |
- 2016.05.29 Sunday
- オクルージョンカリング
- | whaison | - | 10:56 | comments(0) | - | pookmark |
- 2016.05.29 Sunday
- ポストエフェクト側でカメラに映ってる頂点をとりたかったけど、RenderTextureの頂点の四角しか取れないなあ
-
ポストエフェクト側でカメラに映ってる頂点をとりたかったけど、RenderTextureの頂点の四角しか取れないなあ
-----
-----
------
------
Shader "Motion/MotionVertex"
{
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert vertex:vert
struct Input {
float4 color : COLOR;
};
void vert (inout appdata_full v) {
int count=_Time.x*10;
float nowTime = _Time.y;
//float radian = radius(count % 360);//gl3.TRI.rad[count % 360];
// 平行移動(translate)-------------------------------------------
//float sinf = _SinTime.z ;//sin(radian);//時間のサイン関数: (t/8、t/4、t/2、t)
//float cosf = _CosTime.z;//cos(radian);//時間のコサイン関数: (t/8、t/4、t/2、t)float sinf = sin(_Time.y);//時間のサイン関数: (t/8、t/4、t/2、t)
//float cosf = cos(radian);//時間のコサイン関数: (t/8、t/4、t/2、t)float3 offset = (sinf, sinf, 0.0);
//v.vertex.x=v.vertex.x+offset.x*100;//v.vertex.x=sin(_Time.y*30);OK
//v.vertex.y=v.vertex.y+offset.y;
//v.vertex.z=v.vertex.z+offset.z;
v.vertex.x += 0.2 * v.normal.x * sin(v.vertex.y * 3.14 * 16)*(sin(_Time.y*5));//時間 (t/20、t、t×2、t×3)
}
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = half3(0.0, 0.0, sin(_Time.y*30));
}
ENDCG
}
Fallback "Diffuse"
}
//------------------------------
Shader "Hidden/GraphicsBlitPostEffect"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest AlwaysPass
{
CGPROGRAM
#pragma vertex vert//頂点プログラムへ頂点データの流し込み
#pragma fragment frag//内蔵のシェーダー include ファイル
//Unity は自身の 頂点シェーダーと Fragment シェーダーのプログラミング で、
//定義済み変数やヘルパー関数を利用できる、いくつかのファイルを持たせることができます。
//これは標準的な #include ディレクティブで実現できます、例えば、
#include "UnityCG.cginc"//頂点プログラムへ頂点データの流し込み
//UnityCG.cginc のデータ構造
//struct appdata_base: 位置、法線、テクスチャ座標の、頂点シェーダー入力。uniform float _FLOAT=0.5;
uniform float3 _FLOAT3=float3(0.1,1.0,0.1);/*
struct appdata_base {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
};
//struct appdata_tan: 位置、法線、接線、ひとつのテクスチャ座標の、頂点シェーダー入力。
struct appdata_tan {
float4 vertex : POSITION;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
};
//struct appdata_full: 位置、法線、接線、頂点カラー、ふたつのテクスチャ座標の、頂点シェーダー入力。
struct appdata_full {
float4 vertex : POSITION;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
fixed4 color : COLOR;
};
//struct appdata_img: 位置、ひとつのテクスチャ座標の、頂点シェーダー入力。
struct appdata_img {
float4 vertex : POSITION;
half2 texcoord : TEXCOORD0;
};
*/
//http://docs.unity3d.com/ja/current/Manual/SL-BuiltinIncludes.html//これはidentityだとだいたい「単位行列」呼ばれる。値を1にする行列の基礎となる行列
float4x4 identity(float4x4 dest){
//Matrix4x4.identityだとこう
//1 0 0 0
//0 1 0 0
//0 0 1 0
//0 0 0 1
//なんか変だな まあなんでもいいから1にしたいののよね きっと。
dest[0,0] = 0;
dest[1,0] = 0;
dest[2,0] = 0;
dest[3,0] = 1;
return dest;
}//shaderLab内でビューカメラ行列を生成。
float4x4 lookAt(float3 eye, float3 center,float3 up){//ビュー行列変換、目の位置、中視点、カメラUP
float4x4 dest;
float eyeX = eye.x, eyeY = eye.y, eyeZ = eye.z,
upX = up.x, upY = up.y, upZ = up.z,
centerX = center.x, centerY = center.y, centerZ = center.z;
if(eyeX == centerX && eyeY == centerY && eyeZ == centerZ){
//上に定義した関数。
return identity(dest);
}
float x0, x1, x2, y0, y1, y2, z0, z1, z2, l;
z0 = eyeX - center.x; z1 = eyeY - center.y; z2 = eyeZ - center.z;
l = 1 / sqrt(z0 * z0 + z1 * z1 + z2 * z2);
z0 *= l; z1 *= l; z2 *= l;
x0 = upY * z2 - upZ * z1;
x1 = upZ * z0 - upX * z2;
x2 = upX * z1 - upY * z0;
l = sqrt(x0 * x0 + x1 * x1 + x2 * x2);
if(!l){
x0 = 0; x1 = 0; x2 = 0;
} else {
l = 1 / l;
x0 *= l; x1 *= l; x2 *= l;
}
y0 = z1 * x2 - z2 * x1; y1 = z2 * x0 - z0 * x2; y2 = z0 * x1 - z1 * x0;
l = sqrt(y0 * y0 + y1 * y1 + y2 * y2);
if(!l){
y0 = 0; y1 = 0; y2 = 0;
} else {
l = 1 / l;
y0 *= l; y1 *= l; y2 *= l;
}
dest[0,1] = x0; dest[0,1] = y0; dest[0,2] = z0; dest[0,3] = 0;
dest[1,0] = x1; dest[1,1] = y1; dest[1,2] = z1; dest[1,3] = 0;
dest[2,0] = x2; dest[2,1] = y2; dest[2,2] = z2; dest[2,3] = 0;
dest[3,0] = -(x0 * eyeX + x1 * eyeY + x2 * eyeZ);
dest[3,1] = -(y0 * eyeX + y1 * eyeY + y2 * eyeZ);
dest[3,2] = -(z0 * eyeX + z1 * eyeY + z2 * eyeZ);
dest[3,3] = 1;
return dest;
}
/*
struct appdata
{//頂点シェーダの受け取る型
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
*/
struct appdata_whaison
{//頂点シェーダの型
float4 vertex : POSITION;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
float2 uv : TEXCOORD2;
fixed4 color : COLOR;//Vertex Color
//float4 color : COLOR;
};
struct v2f
{//ピクセルシェーダの受け取る型
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
fixed4 color : COLOR;//Vertex Color
};
//Unity.cgincのappdata_baseを使う
//v2f vert (appdata v)
//v2f vert (appdata_base v)
//v2f vert (appdata_full v) appdata_whaison
v2f vert (appdata_whaison v)
{
v2f o;// 各行列を掛け合わせる順序を示す一例
//[Unity] シェーダで使える定義済値
//http://qiita.com/edo_m18/items/591925d7fc960d843afa//一旦モデルは後で
//現在のビュー行列。 //カメラのパラメーターをシェーダ内部でパラメータ設定
float3 eye =float3(0.0, 0.0, 100.0); // カメラの位置 eye
//[定義済み]_WorldSpaceCameraPos float3 カメラのワールド空間位置 eye
float3 center = float3(0.0, 0.0, 0.0); // カメラの注視点 center
float3 up = float3(0.0, 1.0, 0.0); // カメラの上方向 up
//-----------------------------------------------
float4x4 vMatrixFunc =lookAt( eye, center, up);//shaderLab内でビューカメラ行列を生成。
//---------------------------------------------------//float4x4 vMatrix= UNITY_MATRIX_V;// View
//現在の投影行列
float4x4 pMatrix= UNITY_MATRIX_P;// Projection(投影方法)//この列オーダーなので 逆順番にするのが重要 Projection(投影方法)*viewPort(カメラ)*Model(頂点)
// p*v*m
float4x4 vpMatrixFunc=mul(pMatrix, vMatrixFunc); // Projection に viewPort(カメラ) を掛ける//////////////////////////現在のモデルマトリックス //もともとの頂点の位置を三次元空間のどこに頂点を置くのか を決める作業
float4x4 mMatrix= _Object2World;// Modelfloat3 position1 = float3(-0.5, 0.5, 0.0);
float3 position2 = float3(0.5, 0.5, 0.0);
float3 position3 = float3(-0.5, -0.5, 0.0);
float3 position4 = float3(0.5, -0.5, 0.0);//float4 vertexPosition=float4(-0.5, 0.5, 0.0);
//http://docs.unity3d.com/ja/current/Manual/SL-VertexProgramInputs.html
//頂点プログラムへ頂点データの流し込み
// Cg/HLSL 頂点プログラム のために、メッシュ 頂点データは頂点シェーダー関数に入力データとして渡されます。各入力には、それを指定するセマンティクス が必要です。例えば、入力データ POSITION は頂点位置、NORMAL は頂点法線ベクトル、など。
//頂点データの流し込みは、1つずつデータを渡す代わりに、しばしば 1つの構造体として宣言されます。
//一般的に使用される頂点構造体は、UnityCG.cginc の include ファイル で定義され、たいていそれだけで十分です。
//構造体には以下のものがあります。
//UNITY_MATRIX_MVP=現在のモデルビュー行列×射影行列 (model*view*projection)//o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
// o.pos = mul (vpMatrix, v.vertex);
// o.color.xyz = v.normal * 0.5 + 0.5;
// o.color.w = 1.0;//appdata_base: 位置、法線および 1 つのテクスチャ座標で構成されます。
//appdata_tan: 位置、接線、法線および 1 つのテクスチャ座標で構成されます。
//appdata_full: 位置、接線、法線、4 つのテクスチャ座標および色で構成されています。
//例えば、このシェーダーは、その法線に基づいて、メッシュに色を付け、頂点プログラム入力として、appdata_base を使用します。//Unity でVBO (Vertex Buffer Object)は
//https://docs.unity3d.com/ScriptReference/Mesh-vertices.html
//csでMesh mesh = GetComponent<MeshFilter>().mesh;
//Vector3[] vertices = mesh.vertices;
/*
mMatrix[0,1] = 0.5; mMatrix[0,1] = 0.5; mMatrix[0,2] = 0.5; mMatrix[0,3] = 0.5;
mMatrix[1,0] = 0.5; mMatrix[1,1] = 0.5; mMatrix[1,2] = 0.5; mMatrix[1,3] = 0.5;
mMatrix[2,0] = 0.5; mMatrix[2,1] = 0.5; mMatrix[2,2] = 0.5; mMatrix[2,3] = 0.5;
mMatrix[3,0] = 0.5; mMatrix[3,1] = 0.5; mMatrix[3,2] = 0.5; mMatrix[3,3] = 0.5;
*/
//float4x4
//vMatrix= UNITY_MATRIX_V;// View 使わない。//現在の投影行列
//float4x4
//pMatrix= UNITY_MATRIX_P;// Projection(投影方法)//この列オーダーなので 逆順番にするのが重要 Projection(投影方法)*viewPort(カメラ)*Model(頂点)
// p*v*m
float4x4 vpMatrix=mul(pMatrix, vMatrixFunc); // Projection に viewPort(カメラ) を掛けるmMatrix= _Object2World;// Model
//float4x4
//mvpMatrix=mul(vpMatrixFunc, v.vertex)); // さらに model(頂点) を掛ける//////////////////////////////////////o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);//UNITY_MATRIX_MVP///使わない//////////
float4x4 UNITYvpMatrix=mul(UNITY_MATRIX_P, UNITY_MATRIX_V); // Projection に viewPort(カメラ) を掛ける
float4x4 vFuncUNITYpMatrix=mul(UNITY_MATRIX_P, vMatrixFunc); // Projection に viewPort(カメラ) を掛ける
float4 myvertex=float4(0.5,1.0,0.1,1.0);//モデルを動かし変えてみよう!
/*
int count=_Time.x*10;
float nowTime = _Time;
float radian = radius(count % 360);//gl3.TRI.rad[count % 360];
// 平行移動(translate)-------------------------------------------
float sin = sin(radian);
float cos = cos(radian);
float3 offset = (cos, sin, 0.0);
//gl3.mat4.translate(mMatrix, offset, mMatrix);
// var offset = [1.0, 0.0, 0.0];
// gl3.mat4.translate(mMatrix, offset, mMatrix);// 回転(rotate)--------------------------------------------------
float3 axis = float3(0.0, 1.0, 0.0);
gl3.mat4.rotate(mMatrix, radian*10, axis, mMatrix);
//gl3.mat4.rotate(mMatrix, uSin, axis, mMatrix);
//var offset = [1.0, 0.0, 0.0];
//gl3.mat4.translate(mMatrix, offset, mMatrix);
*/// 拡大縮小(scale)-----------------------------------------------
// var uSin = Math.abs(Math.sin(radian));
// var scale = [uSin, uSin, 1.0];
// gl3.mat4.scale(mMatrix, scale, mMatrix);// o.vertex = mul(UNITYvpMatrix, (v.vertex*0.1)+myvertex*_Time.x);//UNITY_MATRIX_MVP///使わない//////////
o.vertex = mul(UNITYvpMatrix, v.vertex);//o.vertex.x += 0.2 * v.normal.x * sin(o.vertex.y * 3.14 * 16);
//o.vertex.z += 0.2 * v.normal.z * sin(o.vertex.y * 3.14 * 16);//float4x4 mvpMatrix=mul(vpMatrix, mMatrix); // さらに m を掛ける
//o.vertex = mul(mvpMatrix, v.vertex);float4x4 mvpMatrixFunc=mul(vpMatrixFunc, mMatrix);
//o.vertex = mul(mvpMatrixFunc, v.vertex);//float4 vertex : POSITION;
//float4 _Time
//o.vertex = mul(mvpMatrix,float4(0.1,1.0,0.1,1.0));
//o.vertex = mul(mvpMatrix,float4(_Time.x,_Time.y,_Time.z,1.0));
//o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
float4 vertexPosition=float4(-0.5, 0.5, 0.0,1.0);
//o.vertex = mul (mvpMatrix, vertexPosition);
//o.uv = v.uv;
//return o;
//unity.cging appdata_bace float3 normal
//unity.cging appdata_bace float4 texcoord
o.uv = float2(v.texcoord.x,v.texcoord.y);
//fixed4 color : COLOR;
//o.color.xyz = v.normal * 0.5 + 0.5;
fixed v_color_xyz = v.normal * 0.5 + 0.5;
//o.color.w = 1.0;
//o.color=fixed4(v_color_xyz,v_color_xyz,v_color_xyz,1.0);
o.color=fixed4(1.0,1.0,1.0,1.0);
//o.color=v.color;
//o.color=float4(o.color.x,o.color.y,o.color.z,1.0);
return o;
}sampler2D _MainTex;
fixed4 frag (v2f i) : SV_Target
{
fixed4 maintex = tex2D(_MainTex, i.uv);
fixed4 col = fixed4(0.0,0.0,0.0,0.0);
col = maintex;
// 座標を正規化する//////////////////////////////////////sample_05.frag
fixed2 p = i.uv;
//col=fixed4(p.x,p.y,1.0+i.color.r,1.0);
col=fixed4(p.x,p.y,1.0,1.0);// 座標を正規化し原点を中心に置く////////////////////////////sample_06.frag
p = (p * 2.0 - 1.0);
/// gl_FragColor = vec4(p, 0.0, 1.0);
col = fixed4(p.x,p.y, 0.0, 1.0);
///各ピクセルの原点からの距離を計測し色として出力する/////////////////////sample_07.frag
fixed leng=length(p);
col = fixed4(leng,leng,leng, 1.0);
// 強い光のような表現を行う一例//////////////////////////////sample_08.frag
fixed light = (leng*0.20);col = fixed4(light,light,light, 1.0);
//マイナス減算する
col=fixed4(maintex.r-light,maintex.g-light,maintex.b-light,1.0);
//col.color = i.color;
col=fixed4(col.x*i.color.x,col.y*i.color.y,col.z*i.color.z,col.w);//vertex color
col=fixed4(col.x+i.vertex.x,col.y+i.vertex.y,col.z+i.vertex.z,col.w);//vertex position
//col.color =fixed4(0.1,1.0,0.5,1.0);
return col;
}
ENDCG
}
}
}
//----------------------------------------- - 続きを読む >>
- | whaison | Unity3d | 02:07 | comments(0) | - | pookmark |
- 2016.05.29 Sunday
- ん?ビルトインのシェーダー変数 増えた? _ZBufferParams float4 Z バッファ値を線形化するために使用します。 x は (1-far/near)、 y は (far/near)、 zは (x/far)、 w は (y/far) です。
-
http://docs.unity3d.com/ja/current/Manual/SL-UnityShaderVariables.html
なんか増えてる 気がする
ビルトインのシェーダー変数
Unity は、シェーダー用のビルトイン・グローバル変数をいくつか提供しています。例えば、現在のオブジェクトの変形マトリックス、ライトパラメーター、現在のタイムなどです。これらは他の変数と同様、 シェーダープログラム で使用します。ただ一つの違いは、宣言する必要がないことです。これらの変数はすべて、自動的に含められるインクルードファイル
UnityShaderVariables.cginc
の中で宣言されています。変形
これらすべてのマトリックスは
float4x4
タイプです。Name Value UNITY_MATRIX_MVP 現在のモデル*ビュー*射影行列(model*view*projection) UNITY_MATRIX_MV 現在のモデル * ビュー行列。 UNITY_MATRIX_V 現在のビュー行列。 UNITY_MATRIX_P 現在の投影行列 UNITY_MATRIX_VP 現在のビュー行列*射影行列 UNITY_MATRIX_T_MV モデル * ビュー行列の転置行列 UNITY_MATRIX_IT_MV モデル * ビュー行列の逆行列の転置行列 _Object2World 現在のモデルマトリックス _World2Object 現在のワールド行列の逆 カメラと画面
これらの変数は、レンダリング中の カメラ に対応します。例えば、シャドウマップのレンダリング中であれば、 シャドウマップの投影に使用されている「仮想カメラ」ではなく、カメラコンポーネントの値を参照します。
Name Type Value _WorldSpaceCameraPos float3 カメラのワールド空間位置 _ProjectionParams float4 x
は 1.0 または –1.0、反転した射影行列で現在レンダリングしている場合は負の値。y
はカメラに近い平面、z
はカメラの遠い平面、w
は 1/FarPlane です。_ScreenParams float4 “x” はカメラのレンダーターゲットの幅(単位:ピクセル)、 “y” はカメラのレンダーターゲットの高さ(単位:ピクセル)、 “z” は 1.0 + 1.0/幅、 “w” は 1.0 + 1.0/高さです。 _ZBufferParams float4 Z バッファ値を線形化するために使用します。 x
は (1-far/near)、y
は (far/near)、z
は (x/far)、w
は (y/far) です。unity_OrthoParams float4 x
平行投影カメラの幅、y
は平行投影カメラの高さ、z
は未使用、w
はカメラが平行投影の場合 1.0 で透視投影の場合 0.0 です。unity_CameraProjection float4x4 カメラの投影マトリックスです。 unity_CameraInvProjection float4x4 カメラの投影マトリックスのリバースです。 unity_CameraWorldClipPlanes[6] float4 カメラ錘台面のワールド空間上の方程式です。左、右、下、near、far の順番です。 Time
Name Type Value _Time float4 ステージの読み込みからのタイム (t/20、 t、 t*2、 t*3)。シェーダー内でアニメーション化を行うために使用します。 _SinTime float4 時間の正弦: (t/8, t/4, t/2, t). _CosTime float4 時間の余弦: (t/8, t/4, t/2, t). unity_DeltaTime float4 デルタ時間: (dt、1/dt、smoothDt、1/smoothDt) ライティング
ライトパラメーターは、どのレンダリング パス が使用されているか、 またどの LightModePass タグ がシェーダー内で使用されているかによって、異なる方法でシェーダーにパスされます。
Forward Rendering (パスタイプ
ForwardBase
とForwardAdd
)Name Type Value _LightColor0 (declared in Lighting.cginc) fixed4 ライトの色 _WorldSpaceLightPos0 float4 ディレクショナルライト: (ワールド空間方向, 0)、他のライト: (ワールド空間位置, 1) _LightMatrix0 (declared in AutoLight.cginc) float4x4 ワールドとライトのマトリクス。クッキーと Attenuation テクスチャをサンプリングするのに使用されます。 unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0 float4 (ForwardBase パスのみ) 重要でない最初の 4つのポイントライトのワールド空間位置。 unity_4LightAtten0 float4 (ForwardBase パスのみ) 重要でない最初の 4つのポイントライトの Attenuation ファクター。 unity_LightColor half4[4] (ForwardBase パスのみ) 重要でない最初の 4つのポイントライトの色 ライティングパス シェーダー内で使用される、 Deferred シェーディングと Deferred ライティング(すべて UnityDeferredLibrary.cginc) 内で宣言される)
Name Type Value _LightColor float4 ライトの色 _LightMatrix0 float4x4 ワールドとライトのマトリクス。クッキーと Attenuation テクスチャをサンプリングするのに使用されます。 球面調和関数の相互作用 (Ambient とライトプローブにより使用される) は、
ForwardBase
、PrePassFinal
、Deferred
いずれかの型のパス向けに設定されます。 それらは3番目の球面調和関数を含み、ワールド空間の法線ベクトルによって評価されます (UnityCG.cgincのShadeSH9
を参照)。 変数はすべて、half4 型で、unity_SHAr
や似た名前を持っています。Vertex Lit レンダリングパス詳細 (
Vertex
パスタイプ)1つの
Vertex
パスタイプに、8 ライトまで設定できます。常に、最も明るいものから順番になっています。 2つのライトから同時に影響を受けるオブジェクトをレンダリングする場合、配列の最初の 2エントリーを取得するだけで行えます。 オブジェクトに影響するライトが 8つより少ない場合は、残りのライトの色を黒に設定します。Name Type Value unity_LightColor half4[8] ライトの色 unity_LightPosition float4[8] ビュー空間ライト位置。ディレクショナルライト (-direction,0)、ポイント/スポットライト (position,1) unity_LightAtten half4[8] ライト Attenuation ファクター。スポットライト以外のx は cos(spotAngle/2) か –1、スポットライト以外の yは 1/cos(spotAngle/4) か 1、スポットライト以外の z は 2次 Attenuation、スポットライト以外の w は 平方のライト範囲。 unity_SpotDirection float4[8] ビュー空間スポットライト位置。スポットライト以外は、(0,0,1,0) フォグとアンビエント
Name Type Value UNITY_LIGHTMODEL_AMBIENT fixed4 アンビエントライティングカラー (3色ライティングの場合の Equator ambient) unity_AmbientSky fixed4 3色ライティングの場合の Sky ambient ライティングカラー unity_AmbientGround fixed4 3色ライティングの場合の Ground Ambient ライティングカラー unity_FogColor fixed4 フォグカラー unity_FogParams float4 フォグ計算のためのパラメーター: (density / sqrt(ln(2))、density / ln(2)、–1/(end-start)、end/(end-start))。x は Exp2 fog モード用、yは Exp モード用、z と w は Linear モード用。 その他、さまざま
Name Type Value unity_LODFade float4 LOD グループを使用する際の細分化したレベルの fade。x は fade (0..1)、y は16 レベルに量子化された fade、z と w は不使用。
- | whaison | Unity3d | 01:36 | comments(0) | - | pookmark |
- 2016.05.29 Sunday
- ん?ビルトインのシェーダー変数 増えた? _ZBufferParams float4 Z バッファ値を線形化するために使用します。 x は (1-far/near)、 y は (far/near)、 zは (x/far)、 w は (y/far) です。
-
http://docs.unity3d.com/ja/current/Manual/SL-UnityShaderVariables.html
なんか増えてる 気がする
ビルトインのシェーダー変数
Unity は、シェーダー用のビルトイン・グローバル変数をいくつか提供しています。例えば、現在のオブジェクトの変形マトリックス、ライトパラメーター、現在のタイムなどです。これらは他の変数と同様、 シェーダープログラム で使用します。ただ一つの違いは、宣言する必要がないことです。これらの変数はすべて、自動的に含められるインクルードファイル
UnityShaderVariables.cginc
の中で宣言されています。変形
これらすべてのマトリックスは
float4x4
タイプです。Name Value UNITY_MATRIX_MVP 現在のモデル*ビュー*射影行列(model*view*projection) UNITY_MATRIX_MV 現在のモデル * ビュー行列。 UNITY_MATRIX_V 現在のビュー行列。 UNITY_MATRIX_P 現在の投影行列 UNITY_MATRIX_VP 現在のビュー行列*射影行列 UNITY_MATRIX_T_MV モデル * ビュー行列の転置行列 UNITY_MATRIX_IT_MV モデル * ビュー行列の逆行列の転置行列 _Object2World 現在のモデルマトリックス _World2Object 現在のワールド行列の逆 カメラと画面
これらの変数は、レンダリング中の カメラ に対応します。例えば、シャドウマップのレンダリング中であれば、 シャドウマップの投影に使用されている「仮想カメラ」ではなく、カメラコンポーネントの値を参照します。
Name Type Value _WorldSpaceCameraPos float3 カメラのワールド空間位置 _ProjectionParams float4 x
は 1.0 または –1.0、反転した射影行列で現在レンダリングしている場合は負の値。y
はカメラに近い平面、z
はカメラの遠い平面、w
は 1/FarPlane です。_ScreenParams float4 “x” はカメラのレンダーターゲットの幅(単位:ピクセル)、 “y” はカメラのレンダーターゲットの高さ(単位:ピクセル)、 “z” は 1.0 + 1.0/幅、 “w” は 1.0 + 1.0/高さです。 _ZBufferParams float4 Z バッファ値を線形化するために使用します。 x
は (1-far/near)、y
は (far/near)、z
は (x/far)、w
は (y/far) です。unity_OrthoParams float4 x
平行投影カメラの幅、y
は平行投影カメラの高さ、z
は未使用、w
はカメラが平行投影の場合 1.0 で透視投影の場合 0.0 です。unity_CameraProjection float4x4 カメラの投影マトリックスです。 unity_CameraInvProjection float4x4 カメラの投影マトリックスのリバースです。 unity_CameraWorldClipPlanes[6] float4 カメラ錘台面のワールド空間上の方程式です。左、右、下、near、far の順番です。 Time
Name Type Value _Time float4 ステージの読み込みからのタイム (t/20、 t、 t*2、 t*3)。シェーダー内でアニメーション化を行うために使用します。 _SinTime float4 時間の正弦: (t/8, t/4, t/2, t). _CosTime float4 時間の余弦: (t/8, t/4, t/2, t). unity_DeltaTime float4 デルタ時間: (dt、1/dt、smoothDt、1/smoothDt) ライティング
ライトパラメーターは、どのレンダリング パス が使用されているか、 またどの LightModePass タグ がシェーダー内で使用されているかによって、異なる方法でシェーダーにパスされます。
Forward Rendering (パスタイプ
ForwardBase
とForwardAdd
)Name Type Value _LightColor0 (declared in Lighting.cginc) fixed4 ライトの色 _WorldSpaceLightPos0 float4 ディレクショナルライト: (ワールド空間方向, 0)、他のライト: (ワールド空間位置, 1) _LightMatrix0 (declared in AutoLight.cginc) float4x4 ワールドとライトのマトリクス。クッキーと Attenuation テクスチャをサンプリングするのに使用されます。 unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0 float4 (ForwardBase パスのみ) 重要でない最初の 4つのポイントライトのワールド空間位置。 unity_4LightAtten0 float4 (ForwardBase パスのみ) 重要でない最初の 4つのポイントライトの Attenuation ファクター。 unity_LightColor half4[4] (ForwardBase パスのみ) 重要でない最初の 4つのポイントライトの色 ライティングパス シェーダー内で使用される、 Deferred シェーディングと Deferred ライティング(すべて UnityDeferredLibrary.cginc) 内で宣言される)
Name Type Value _LightColor float4 ライトの色 _LightMatrix0 float4x4 ワールドとライトのマトリクス。クッキーと Attenuation テクスチャをサンプリングするのに使用されます。 球面調和関数の相互作用 (Ambient とライトプローブにより使用される) は、
ForwardBase
、PrePassFinal
、Deferred
いずれかの型のパス向けに設定されます。 それらは3番目の球面調和関数を含み、ワールド空間の法線ベクトルによって評価されます (UnityCG.cgincのShadeSH9
を参照)。 変数はすべて、half4 型で、unity_SHAr
や似た名前を持っています。Vertex Lit レンダリングパス詳細 (
Vertex
パスタイプ)1つの
Vertex
パスタイプに、8 ライトまで設定できます。常に、最も明るいものから順番になっています。 2つのライトから同時に影響を受けるオブジェクトをレンダリングする場合、配列の最初の 2エントリーを取得するだけで行えます。 オブジェクトに影響するライトが 8つより少ない場合は、残りのライトの色を黒に設定します。Name Type Value unity_LightColor half4[8] ライトの色 unity_LightPosition float4[8] ビュー空間ライト位置。ディレクショナルライト (-direction,0)、ポイント/スポットライト (position,1) unity_LightAtten half4[8] ライト Attenuation ファクター。スポットライト以外のx は cos(spotAngle/2) か –1、スポットライト以外の yは 1/cos(spotAngle/4) か 1、スポットライト以外の z は 2次 Attenuation、スポットライト以外の w は 平方のライト範囲。 unity_SpotDirection float4[8] ビュー空間スポットライト位置。スポットライト以外は、(0,0,1,0) フォグとアンビエント
Name Type Value UNITY_LIGHTMODEL_AMBIENT fixed4 アンビエントライティングカラー (3色ライティングの場合の Equator ambient) unity_AmbientSky fixed4 3色ライティングの場合の Sky ambient ライティングカラー unity_AmbientGround fixed4 3色ライティングの場合の Ground Ambient ライティングカラー unity_FogColor fixed4 フォグカラー unity_FogParams float4 フォグ計算のためのパラメーター: (density / sqrt(ln(2))、density / ln(2)、–1/(end-start)、end/(end-start))。x は Exp2 fog モード用、yは Exp モード用、z と w は Linear モード用。 その他、さまざま
Name Type Value unity_LODFade float4 LOD グループを使用する際の細分化したレベルの fade。x は fade (0..1)、y は16 レベルに量子化された fade、z と w は不使用。
- | whaison | Unity3d | 01:36 | comments(0) | - | pookmark |
- 2016.05.28 Saturday
- Unity(Unity3D) > 内蔵シェーダのソースコード > UnityCG.cginc
-
Unity(Unity3D) > 内蔵シェーダのソースコード > UnityCG.cginc
http://www32.atwiki.jp/nakamura001/pages/275.html
#ifndef UNITY_CG_INCLUDED #define UNITY_CG_INCLUDED #include "UnityShaderVariables.cginc" #if SHADER_API_FLASH uniform float4 unity_NPOTScale; #endif #if defined(SHADER_API_PS3) # define UNITY_SAMPLE_DEPTH(value) (dot((value).wxy, float3(0.996093809371817670572857294849, 0.0038909914428586627756752238080039, 1.5199185323666651467481343000015e-5))) #elif defined(SHADER_API_FLASH) # define UNITY_SAMPLE_DEPTH(value) (DecodeFloatRGBA(value)) #else # define UNITY_SAMPLE_DEPTH(value) (value).r #endif uniform fixed4 unity_ColorSpaceGrey; // ------------------------------------------------------------------- // helper functions and macros used in many standard shaders #if defined (DIRECTIONAL) || defined (DIRECTIONAL_COOKIE) || defined (POINT) || defined (SPOT) || defined (POINT_NOATT) || defined (POINT_COOKIE) #define USING_LIGHT_MULTI_COMPILE #endif #define SCALED_NORMAL (v.normal * unity_Scale.w) struct appdata_base { float4 vertex : POSITION; float3 normal : NORMAL; float4 texcoord : TEXCOORD0; }; struct appdata_tan { float4 vertex : POSITION; float4 tangent : TANGENT; float3 normal : NORMAL; float4 texcoord : TEXCOORD0; }; struct appdata_full { float4 vertex : POSITION; float4 tangent : TANGENT; float3 normal : NORMAL; float4 texcoord : TEXCOORD0; float4 texcoord1 : TEXCOORD1; fixed4 color : COLOR; #if defined(SHADER_API_XBOX360) half4 texcoord2 : TEXCOORD2; half4 texcoord3 : TEXCOORD3; half4 texcoord4 : TEXCOORD4; half4 texcoord5 : TEXCOORD5; #endif }; // Computes world space light direction inline float3 WorldSpaceLightDir( in float4 v ) { float3 worldPos = mul(_Object2World, v).xyz; #ifndef USING_LIGHT_MULTI_COMPILE return _WorldSpaceLightPos0.xyz - worldPos * _WorldSpaceLightPos0.w; #else #ifndef USING_DIRECTIONAL_LIGHT return _WorldSpaceLightPos0.xyz - worldPos; #else return _WorldSpaceLightPos0.xyz; #endif #endif } // Computes object space light direction inline float3 ObjSpaceLightDir( in float4 v ) { float3 objSpaceLightPos = mul(_World2Object, _WorldSpaceLightPos0).xyz; #ifndef USING_LIGHT_MULTI_COMPILE return objSpaceLightPos.xyz - v.xyz * _WorldSpaceLightPos0.w; #else #ifndef USING_DIRECTIONAL_LIGHT return objSpaceLightPos.xyz * unity_Scale.w - v.xyz; #else return objSpaceLightPos.xyz; #endif #endif } // Computes world space view direction inline float3 WorldSpaceViewDir( in float4 v ) { return _WorldSpaceCameraPos.xyz - mul(_Object2World, v).xyz; } // Computes object space view direction inline float3 ObjSpaceViewDir( in float4 v ) { float3 objSpaceCameraPos = mul(_World2Object, float4(_WorldSpaceCameraPos.xyz, 1)).xyz * unity_Scale.w; return objSpaceCameraPos - v.xyz; } // Declares 3x3 matrix 'rotation', filled with tangent space basis #define TANGENT_SPACE_ROTATION ¥ float3 binormal = cross( v.normal, v.tangent.xyz ) * v.tangent.w; ¥ float3x3 rotation = float3x3( v.tangent.xyz, binormal, v.normal ) float3 Shade4PointLights ( float4 lightPosX, float4 lightPosY, float4 lightPosZ, float3 lightColor0, float3 lightColor1, float3 lightColor2, float3 lightColor3, float4 lightAttenSq, float3 pos, float3 normal) { // to light vectors float4 toLightX = lightPosX - pos.x; float4 toLightY = lightPosY - pos.y; float4 toLightZ = lightPosZ - pos.z; // squared lengths float4 lengthSq = 0; lengthSq += toLightX * toLightX; lengthSq += toLightY * toLightY; lengthSq += toLightZ * toLightZ; // NdotL float4 ndotl = 0; ndotl += toLightX * normal.x; ndotl += toLightY * normal.y; ndotl += toLightZ * normal.z; // correct NdotL float4 corr = rsqrt(lengthSq); ndotl = max (float4(0,0,0,0), ndotl * corr); // attenuation float4 atten = 1.0 / (1.0 + lengthSq * lightAttenSq); float4 diff = ndotl * atten; // final color float3 col = 0; col += lightColor0 * diff.x; col += lightColor1 * diff.y; col += lightColor2 * diff.z; col += lightColor3 * diff.w; return col; } float3 ShadeVertexLights (float4 vertex, float3 normal) { float3 viewpos = mul (UNITY_MATRIX_MV, vertex).xyz; float3 viewN = mul ((float3x3)UNITY_MATRIX_IT_MV, normal); float3 lightColor = UNITY_LIGHTMODEL_AMBIENT.xyz; for (int i = 0; i < 4; i++) { float3 toLight = unity_LightPosition[i].xyz - viewpos.xyz * unity_LightPosition[i].w; float lengthSq = dot(toLight, toLight); float atten = 1.0 / (1.0 + lengthSq * unity_LightAtten[i].z); float diff = max (0, dot (viewN, normalize(toLight))); lightColor += unity_LightColor[i].rgb * (diff * atten); } return lightColor; } // normal should be normalized, w=1.0 half3 ShadeSH9 (half4 normal) { half3 x1, x2, x3; // Linear + constant polynomial terms x1.r = dot(unity_SHAr,normal); x1.g = dot(unity_SHAg,normal); x1.b = dot(unity_SHAb,normal); // 4 of the quadratic polynomials half4 vB = normal.xyzz * normal.yzzx; x2.r = dot(unity_SHBr,vB); x2.g = dot(unity_SHBg,vB); x2.b = dot(unity_SHBb,vB); // Final quadratic polynomial float vC = normal.x*normal.x - normal.y*normal.y; x3 = unity_SHC.rgb * vC; return x1 + x2 + x3; } // Transforms 2D UV by scale/bias property #define TRANSFORM_TEX(tex,name) (tex.xy * name##_ST.xy + name##_ST.zw) // Transforms 4D UV by a texture matrix (use only if you know exactly which matrix you need) #define TRANSFORM_UV(idx) mul (UNITY_MATRIX_TEXTURE##idx, v.texcoord).xy struct v2f_vertex_lit { float2 uv : TEXCOORD0; fixed4 diff : COLOR0; fixed4 spec : COLOR1; }; inline fixed4 VertexLight( v2f_vertex_lit i, sampler2D mainTex ) { fixed4 texcol = tex2D( mainTex, i.uv ); fixed4 c; c.xyz = ( texcol.xyz * i.diff.xyz + i.spec.xyz * texcol.a ) * 2; c.w = texcol.w * i.diff.w; return c; } // Calculates UV offset for parallax bump mapping inline float2 ParallaxOffset( half h, half height, half3 viewDir ) { h = h * height - height/2.0; float3 v = normalize(viewDir); v.z += 0.42; return h * (v.xy / v.z); } // Converts color to luminance (grayscale) inline fixed Luminance( fixed3 c ) { return dot( c, fixed3(0.22, 0.707, 0.071) ); } // Decodes lightmaps: // - doubleLDR encoded on GLES // - RGBM encoded with range [0;8] on other platforms using surface shaders inline fixed3 DecodeLightmap( fixed4 color ) { #if defined(SHADER_API_GLES) && defined(SHADER_API_MOBILE) return 2.0 * color.rgb; #else // potentially faster to do the scalar multiplication // in parenthesis for scalar GPUs return (8.0 * color.a) * color.rgb; #endif } // Helpers used in image effects. Most image effects use the same // minimal vertex shader (vert_img). struct appdata_img { float4 vertex : POSITION; half2 texcoord : TEXCOORD0; }; struct v2f_img { float4 pos : SV_POSITION; half2 uv : TEXCOORD0; }; float2 MultiplyUV (float4x4 mat, float2 inUV) { float4 temp = float4 (inUV.x, inUV.y, 0, 0); temp = mul (mat, temp); return temp.xy; } v2f_img vert_img( appdata_img v ) { v2f_img o; o.pos = mul (UNITY_MATRIX_MVP, v.vertex); o.uv = MultiplyUV( UNITY_MATRIX_TEXTURE0, v.texcoord ); return o; } // Encoding/decoding [0..1) floats into 8 bit/channel RGBA. Note that 1.0 will not be encoded properly. inline float4 EncodeFloatRGBA( float v ) { float4 kEncodeMul = float4(1.0, 255.0, 65025.0, 160581375.0); float kEncodeBit = 1.0/255.0; float4 enc = kEncodeMul * v; enc = frac (enc); enc -= enc.yzww * kEncodeBit; return enc; } inline float DecodeFloatRGBA( float4 enc ) { float4 kDecodeDot = float4(1.0, 1/255.0, 1/65025.0, 1/160581375.0); return dot( enc, kDecodeDot ); } // Encoding/decoding [0..1) floats into 8 bit/channel RG. Note that 1.0 will not be encoded properly. inline float2 EncodeFloatRG( float v ) { float2 kEncodeMul = float2(1.0, 255.0); float kEncodeBit = 1.0/255.0; float2 enc = kEncodeMul * v; enc = frac (enc); enc.x -= enc.y * kEncodeBit; return enc; } inline float DecodeFloatRG( float2 enc ) { float2 kDecodeDot = float2(1.0, 1/255.0); return dot( enc, kDecodeDot ); } // Encoding/decoding view space normals into 2D 0..1 vector inline float2 EncodeViewNormalStereo( float3 n ) { float kScale = 1.7777; float2 enc; enc = n.xy / (n.z+1); enc /= kScale; enc = enc*0.5+0.5; return enc; } inline float3 DecodeViewNormalStereo( float4 enc4 ) { float kScale = 1.7777; float3 nn = enc4.xyz*float3(2*kScale,2*kScale,0) + float3(-kScale,-kScale,1); float g = 2.0 / dot(nn.xyz,nn.xyz); float3 n; n.xy = g*nn.xy; n.z = g-1; return n; } inline float4 EncodeDepthNormal( float depth, float3 normal ) { float4 enc; enc.xy = EncodeViewNormalStereo (normal); enc.zw = EncodeFloatRG (depth); return enc; } inline void DecodeDepthNormal( float4 enc, out float depth, out float3 normal ) { depth = DecodeFloatRG (enc.zw); normal = DecodeViewNormalStereo (enc); } inline fixed3 UnpackNormalDXT5nm (fixed4 packednormal) { fixed3 normal; normal.xy = packednormal.wy * 2 - 1; normal.z = sqrt(1 - normal.x*normal.x - normal.y * normal.y); return normal; } inline fixed3 UnpackNormal(fixed4 packednormal) { #if defined(SHADER_API_GLES) && defined(SHADER_API_MOBILE) return packednormal.xyz * 2 - 1; #else fixed3 normal; normal.xy = packednormal.wy * 2 - 1; normal.z = sqrt(1 - normal.x*normal.x - normal.y * normal.y); return normal; #endif } // Z buffer to linear 0..1 depth (0 at eye, 1 at far plane) inline float Linear01Depth( float z ) { return 1.0 / (_ZBufferParams.x * z + _ZBufferParams.y); } // Z buffer to linear depth inline float LinearEyeDepth( float z ) { return 1.0 / (_ZBufferParams.z * z + _ZBufferParams.w); } // Depth render texture helpers #if defined(UNITY_MIGHT_NOT_HAVE_DEPTH_TEXTURE) #define UNITY_TRANSFER_DEPTH(oo) oo = o.pos.zw #if SHADER_API_FLASH #define UNITY_OUTPUT_DEPTH(i) return EncodeFloatRGBA(i.x/i.y) #else #define UNITY_OUTPUT_DEPTH(i) return i.x/i.y #endif #else #define UNITY_TRANSFER_DEPTH(oo) #define UNITY_OUTPUT_DEPTH(i) return 0 #endif #define DECODE_EYEDEPTH(i) LinearEyeDepth(i) #define COMPUTE_EYEDEPTH(o) o = -mul( UNITY_MATRIX_MV, v.vertex ).z #define COMPUTE_DEPTH_01 -(mul( UNITY_MATRIX_MV, v.vertex ).z * _ProjectionParams.w) #define COMPUTE_VIEW_NORMAL mul((float3x3)UNITY_MATRIX_IT_MV, v.normal) // Projected screen position helpers #define V2F_SCREEN_TYPE float4 inline float4 ComputeScreenPos (float4 pos) { float4 o = pos * 0.5f; #if defined(UNITY_HALF_TEXEL_OFFSET) o.xy = float2(o.x, o.y*_ProjectionParams.x) + o.w * _ScreenParams.zw; #else o.xy = float2(o.x, o.y*_ProjectionParams.x) + o.w; #endif #if defined(SHADER_API_FLASH) o.xy *= unity_NPOTScale.xy; #endif o.zw = pos.zw; return o; } inline float4 ComputeGrabScreenPos (float4 pos) { #if UNITY_UV_STARTS_AT_TOP float scale = -1.0; #else float scale = 1.0; #endif float4 o = pos * 0.5f; o.xy = float2(o.x, o.y*scale) + o.w; o.zw = pos.zw; return o; } inline float2 TransformViewToProjection (float2 v) { return float2(v.x*UNITY_MATRIX_P[0][0], v.y*UNITY_MATRIX_P[1][1]); } inline float3 TransformViewToProjection (float3 v) { return float3(v.x*UNITY_MATRIX_P[0][0], v.y*UNITY_MATRIX_P[1][1], v.z*UNITY_MATRIX_P[2][2]); } // Shadow caster pass helpers #ifdef SHADOWS_CUBE #define V2F_SHADOW_CASTER float4 pos : SV_POSITION; float3 vec : TEXCOORD0 #define TRANSFER_SHADOW_CASTER(o) o.vec = mul( _Object2World, v.vertex ).xyz - _LightPositionRange.xyz; o.pos = mul(UNITY_MATRIX_MVP, v.vertex); #define SHADOW_CASTER_FRAGMENT(i) return EncodeFloatRGBA( length(i.vec) * _LightPositionRange.w ); #else #if defined(UNITY_MIGHT_NOT_HAVE_DEPTH_TEXTURE) #define V2F_SHADOW_CASTER float4 pos : SV_POSITION; float4 hpos : TEXCOORD0 #define TRANSFER_SHADOW_CASTER(o) o.pos = mul(UNITY_MATRIX_MVP, v.vertex); o.pos.z += unity_LightShadowBias.x; ¥ float clamped = max(o.pos.z, o.pos.w*UNITY_NEAR_CLIP_VALUE); o.pos.z = lerp(o.pos.z, clamped, unity_LightShadowBias.y); o.hpos = o.pos; #else #define V2F_SHADOW_CASTER float4 pos : SV_POSITION #define TRANSFER_SHADOW_CASTER(o) o.pos = mul(UNITY_MATRIX_MVP, v.vertex); o.pos.z += unity_LightShadowBias.x; ¥ float clamped = max(o.pos.z, o.pos.w*UNITY_NEAR_CLIP_VALUE); o.pos.z = lerp(o.pos.z, clamped, unity_LightShadowBias.y); #endif #define SHADOW_CASTER_FRAGMENT(i) UNITY_OUTPUT_DEPTH(i.hpos.zw); #endif // Shadow collector pass helpers #ifdef SHADOW_COLLECTOR_PASS #if !defined(SHADOWMAPSAMPLER_DEFINED) UNITY_DECLARE_SHADOWMAP(_ShadowMapTexture); #endif #define V2F_SHADOW_COLLECTOR float4 pos : SV_POSITION; float3 _ShadowCoord0 : TEXCOORD0; float3 _ShadowCoord1 : TEXCOORD1; float3 _ShadowCoord2 : TEXCOORD2; float3 _ShadowCoord3 : TEXCOORD3; float4 _WorldPosViewZ : TEXCOORD4 #define TRANSFER_SHADOW_COLLECTOR(o) ¥ o.pos = mul(UNITY_MATRIX_MVP, v.vertex); ¥ float4 wpos = mul(_Object2World, v.vertex); ¥ o._WorldPosViewZ.xyz = wpos; ¥ o._WorldPosViewZ.w = -mul( UNITY_MATRIX_MV, v.vertex ).z; ¥ o._ShadowCoord0 = mul(unity_World2Shadow[0], wpos).xyz; ¥ o._ShadowCoord1 = mul(unity_World2Shadow[1], wpos).xyz; ¥ o._ShadowCoord2 = mul(unity_World2Shadow[2], wpos).xyz; ¥ o._ShadowCoord3 = mul(unity_World2Shadow[3], wpos).xyz; #if defined (SHADOWS_NATIVE) #define SAMPLE_SHADOW_COLLECTOR_SHADOW(coord) ¥ half shadow = UNITY_SAMPLE_SHADOW(_ShadowMapTexture,coord); ¥ shadow = _LightShadowData.r + shadow * (1-_LightShadowData.r); #else #define SAMPLE_SHADOW_COLLECTOR_SHADOW(coord) ¥ float shadow = UNITY_SAMPLE_DEPTH(tex2D( _ShadowMapTexture, coord.xy )) < coord.z ? _LightShadowData.r : 1.0; #endif #define COMPUTE_SHADOW_COLLECTOR_SHADOW(i, weights, shadowFade) ¥ float4 coord = float4(i._ShadowCoord0 * weights[0] + i._ShadowCoord1 * weights[1] + i._ShadowCoord2 * weights[2] + i._ShadowCoord3 * weights[3], 1); ¥ SAMPLE_SHADOW_COLLECTOR_SHADOW(coord) ¥ float4 res; ¥ res.x = saturate(shadow + shadowFade); ¥ res.y = 1.0; ¥ res.zw = EncodeFloatRG (1 - i._WorldPosViewZ.w * _ProjectionParams.w); ¥ return res; #if defined (SHADOWS_SPLIT_SPHERES) #define SHADOW_COLLECTOR_FRAGMENT(i) ¥ float3 fromCenter0 = i._WorldPosViewZ.xyz - unity_ShadowSplitSpheres[0].xyz; ¥ float3 fromCenter1 = i._WorldPosViewZ.xyz - unity_ShadowSplitSpheres[1].xyz; ¥ float3 fromCenter2 = i._WorldPosViewZ.xyz - unity_ShadowSplitSpheres[2].xyz; ¥ float3 fromCenter3 = i._WorldPosViewZ.xyz - unity_ShadowSplitSpheres[3].xyz; ¥ float4 distances2 = float4(dot(fromCenter0,fromCenter0), dot(fromCenter1,fromCenter1), dot(fromCenter2,fromCenter2), dot(fromCenter3,fromCenter3)); ¥ float4 cascadeWeights = float4(distances2 < unity_ShadowSplitSqRadii); ¥ cascadeWeights.yzw = saturate(cascadeWeights.yzw - cascadeWeights.xyz); ¥ float sphereDist = distance(i._WorldPosViewZ.xyz, unity_ShadowFadeCenterAndType.xyz); ¥ float shadowFade = saturate(sphereDist * _LightShadowData.z + _LightShadowData.w); ¥ COMPUTE_SHADOW_COLLECTOR_SHADOW(i, cascadeWeights, shadowFade) #else #define SHADOW_COLLECTOR_FRAGMENT(i) ¥ float4 viewZ = i._WorldPosViewZ.w; ¥ float4 zNear = float4( viewZ >= _LightSplitsNear ); ¥ float4 zFar = float4( viewZ < _LightSplitsFar ); ¥ float4 cascadeWeights = zNear * zFar; ¥ float shadowFade = saturate(i._WorldPosViewZ.w * _LightShadowData.z + _LightShadowData.w); ¥ COMPUTE_SHADOW_COLLECTOR_SHADOW(i, cascadeWeights, shadowFade) #endif #endif #endif
- | whaison | Unity3d | 22:30 | comments(0) | - | pookmark |
- 2016.05.28 Saturday
- GrabPass 使い方 描画されている画面のコンテンツを、テクスチャ内に掴みとる。このテクスチャは後続プロセスで高度な画像ベースのエフェクトに使用できる。
-
http://unity-game.blogspot.jp/2014/06/shader.html
描画されている画面のコンテンツを、テクスチャ内に掴みとる。このテクスチャは後続プロセスで高度な画像ベースのエフェクトに使用できる。 使い方は二つあり、以下であるGrabPass { }
と指定し、単に現在の画面コンテンツをテクスチャ内に掴みとります。このテクスチャは後続のパスで_GrabTexture
でアクセスすることができる。この形式のGrap Passは画面の掴みとり処理を使用する各オブジェクトごとに行う。GrabPass { "TextureName" }
により画面コンテンツをテクスチャ内に掴みとるが、フレームごとに1回のみ、指定のテクスチャ名を使用する最初のオブジェクト分のみ、実施する。テクスチャは後続のパスで指定のテクスチャ名でアクセスすることが出来きる。シーンでGrab Passを使用するオブジェクトが複数ある場合に効率的な方法です。
?1
2
3
4
5
6
7
8
9
10
11
12
13
14Shader
"GrabPassInvert"
{
SubShader {
// 全ての不透明な形状の後に、自身を描画します
Tags {
"Queue"
=
"Transparent"
}
// オブジェクトより後ろのシーンを_GrabTextureに掴み取ります
GrabPass { }
// 上で生成したテクスチャでオブジェクトをレンダリングし、カラーを反転します。
Pass {
SetTexture [_GrabTexture] { combine one-texture }
}
}
}
このシェーダには二つのパスがあり、最初のパスはレンダリングのときにオブジェクトにある全てを掴みとり、次にをそれを二つめのパスで適用します。同じエフェクトはより安価にinvertblend mode を使用して得ることも出来きる。 - | whaison | Unity3d | 21:27 | comments(0) | - | pookmark |
- 2016.05.26 Thursday
- Maya 致命的なエラーでクラッシュする`file -q -reference -shortName`ファイル名と`file -q -reference`のフルパス
-
さらにやるならファイルあるか確認しないとだめね。
- string $reference[] = `file -q -reference -shortName`;
+ //string $reference[] = `file -q -reference`;
これで落ちてた
print("//file -importReference はじめるよ¥n");
//string $reference[] = `file -q -reference`;
string $reference[] = `file -q -reference`;
print("-----$reference[]---------"+"¥n");
print($reference);
print("¥n");
print("-----$reference[]---------"+"¥n");
int $countRef = 0;
int $refMax =size($reference);
for ( $countRef = $refMax-1; $countRef >= 0; $countRef-- )
{
print("$reference["+$countRef+"]= "+$reference[$countRef]+"¥n");
// file -open $reference[$count5];
if(`file -q -writable`=="1"){
if($countRef<0){
print("ないよーマイナス1だよ¥n");
}else{
file -importReference $reference[$countRef];
}//if($countRef<0){
}// if(`file -q -writable`=="1"){
//$count5--;
};//for ( $countRef = $refMax-1; $countRef >= 0; $countRef-- )
print("//file -importReference おわったよ¥n"); - | whaison | C# | 19:51 | comments(0) | - | pookmark |
- 2016.05.26 Thursday
- C#でOpenXMLを使ったExcelの読み込み エクセル Unity
-
テラシュールさん Excelでデータを管理してUnity iOS/Androidで使うワークフローをもう少し詳しく(修正版)http://tsubakit1.hateblo.jp/entry/20130702/1372771366
OpenXMLはmsi のWindowsインストーラしかないよ。
Unity3D用のC# ライブラリーと.NET Frameworkのバージョン。設定は3.5ですよ、3.5!
C#でOpenXMLを使ったExcelの読み込み
結局こっちのサイトがいいかも?。
http://symfoware.blog68.fc2.com/blog-entry-1137.html
Open XML SDK 2.0 for Microsoft Officeのインストール
こちらから、ライブラリのインストーラーを取得し、インストールを行います。
http://www.microsoft.com/ja-jp/download/details.aspx?id=5124
OpenXMLSDKシステム要件は次のとおりです。Microsoft Office Excel® 2010- .NET Framework 3.5 SP1 ギリダメだった
Open XML 形式 SDK 1.0のインストール
https://www.microsoft.com/ja-jp/download/details.aspx?id=12546
SDK のシステム要件は以下のとおりです。Microsoft Office Excel® 2007- .NET Framework 3.0 あいけるかも。ソースが紹介いない。。。。古いから古いエクセルしか読めないとかありそう。
あー
死んだ、、、、OpenXMLなんて使えない失速
またあした
Unity は.net2.0を魔改造していて.NET 3.5系まで使用出来るので、この手のライブラリも使用出来る。
http://tsubakit1.hateblo.jp/entry/20130702/1372771366NPOI 2.0
http://npoi.codeplex.com/releases/view/112932
ということで次回
http://whaison.jugem.jp/?eid=850
- | whaison | C# | 12:38 | comments(0) | - | pookmark |