Last active
March 30, 2019 00:55
-
-
Save tsubaki/7011f0e5a262432f07a4913716450302 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 "VertexRotation" | |
{ | |
Properties | |
{ | |
_MainTex ("Texture", 2D) = "white" {} | |
} | |
SubShader | |
{ | |
Tags { "RenderType"="Opaque" "DisableBatching" = "True"} | |
Pass | |
{ | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
// インスタンシング有効 | |
#pragma multi_compile_instancing | |
// バッファを元にオブジェクトを生成する処理 | |
// バッファはパーティクルが作ってくれる | |
#pragma instancing_options procedural:vertInstancingSetup // 追加 | |
#include "UnityCG.cginc" | |
// vertInstancingSetupが定義されてるのでインクルードする | |
// 必ずUnityCG.cgincの後に追加 | |
#include "UnityStandardParticleInstancing.cginc" // 追加 | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
float2 uv : TEXCOORD0; | |
float4 color : COLOR; | |
// InstancingのIDを定義しておく | |
UNITY_VERTEX_INPUT_INSTANCE_ID // 追加 | |
}; | |
struct v2f | |
{ | |
float2 uv : TEXCOORD0; | |
float4 color : TEXCOORD1; | |
float4 vertex : SV_POSITION; | |
}; | |
sampler2D _MainTex; | |
float4 _MainTex_ST; | |
float _CurveStrength; | |
v2f vert(appdata v ) | |
{ | |
// インスタンシングのセットアップ | |
UNITY_SETUP_INSTANCE_ID(v); // 追加 | |
v2f o; | |
float _Horizon = 100.0f; | |
float _FadeDist = 50.0f; | |
float4 rotVert = v.vertex; | |
rotVert.z = (v.vertex.z * cos(_Time.y * 3.14f) - v.vertex.x * sin(_Time.y * 3.14f)) ; | |
rotVert.x = (v.vertex.z * sin(_Time.y * 3.14f) + v.vertex.x * cos(_Time.y * 3.14f)); | |
o.vertex = UnityObjectToClipPos(rotVert ) ; | |
float dist = UNITY_Z_0_FAR_FROM_CLIPSPACE(o.vertex.z); | |
o.vertex.y -= _CurveStrength * dist * dist * _ProjectionParams.x; | |
o.uv = TRANSFORM_TEX(v.uv, _MainTex); | |
return o; | |
} | |
fixed4 frag(v2f i) : SV_Target | |
{ | |
fixed4 col = tex2D(_MainTex, i.uv); | |
return col; | |
} | |
ENDCG | |
} | |
} | |
} |
Author
tsubaki
commented
Jan 30, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment