Skip to content

Instantly share code, notes, and snippets.

@mewlist
Created July 12, 2017 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mewlist/d08e70585c685abc346a6d12c598ce0c to your computer and use it in GitHub Desktop.
Save mewlist/d08e70585c685abc346a6d12c598ce0c to your computer and use it in GitHub Desktop.
Shader "Custom/UVScroll" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Velocity ("Velocity", Range(0, 100)) = 0
_Rotation ("Rotation", Range(0, 360)) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Standard vertex:vert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
fixed4 _Color;
float _Rotation;
float _Velocity;
void vert(inout appdata_full v)
{
const float PI = 3.141592;
// 回転行列を作る
float c = cos(PI * _Rotation / 180);
float s = sin(PI * _Rotation / 180);
float2x2 rotationMatrix = float2x2( c, -s, s, c);
// 移動方向を求める
float2 dir = mul(rotationMatrix, float2(1, 0));
// ずらす
v.texcoord.x = v.texcoord.x + _Time.x * dir.x * _Velocity;
v.texcoord.y = v.texcoord.y + _Time.x * dir.y * _Velocity;
}
void surf (Input IN, inout SurfaceOutputStandard o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
}
@mewlist
Copy link
Author

mewlist commented Jul 12, 2017

処理の効率面でこんなツッコミをもらいました

PI / 180 を予め求めておいたほうが効率良い
なぜsurface shaderを使ってしまったのか
ずらす のところを 1行で書けるはず
vector 演算が減らせる 掛け算の中でスカラー演算を最初におく

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment