回答編集履歴

1

回答の追記

2017/09/04 01:12

投稿

Kapustin
Kapustin

スコア1186

test CHANGED
@@ -3,3 +3,151 @@
3
3
  [MasterCube](https://www.assetstore.unity3d.com/jp/#!/content/40033)
4
4
 
5
5
  [紹介サイト](http://tsubakit1.hateblo.jp/entry/2016/05/24/073000)
6
+
7
+
8
+
9
+ 追記:
10
+
11
+ シェーダで実装することも可能です。
12
+
13
+ 何となくですが、ワールド座標とテクスチャのUV座標を対応させたタイリング用シェーダを書いてみました。
14
+
15
+ 新規マテリアルを作成し、シェーダを`Custom > TileShader`に設定してください。
16
+
17
+ [TileScale]の値を変えるとタイルの大きさが変わります。
18
+
19
+
20
+
21
+ ```
22
+
23
+ Shader "Custom/TileShader" {
24
+
25
+ Properties {
26
+
27
+ _Color ("Color", Color) = (1,1,1,1)
28
+
29
+ _MainTex ("Albedo (RGB)", 2D) = "white" {}
30
+
31
+ _Glossiness ("Smoothness", Range(0,1)) = 0.5
32
+
33
+ _Metallic ("Metallic", Range(0,1)) = 0.0
34
+
35
+ _TileScale ("TileScale", Range(0.1, 10)) = 1
36
+
37
+ }
38
+
39
+ SubShader {
40
+
41
+ Tags { "RenderType"="Opaque" }
42
+
43
+ LOD 200
44
+
45
+
46
+
47
+ CGPROGRAM
48
+
49
+ // Physically based Standard lighting model, and enable shadows on all light types
50
+
51
+ #pragma surface surf Standard fullforwardshadows
52
+
53
+
54
+
55
+ // Use shader model 3.0 target, to get nicer looking lighting
56
+
57
+ #pragma target 3.0
58
+
59
+
60
+
61
+ sampler2D _MainTex;
62
+
63
+
64
+
65
+ struct Input {
66
+
67
+ float2 uv_MainTex;
68
+
69
+ float3 worldPos;
70
+
71
+ float3 worldNormal;
72
+
73
+ };
74
+
75
+
76
+
77
+ half _Glossiness;
78
+
79
+ half _Metallic;
80
+
81
+ fixed4 _Color;
82
+
83
+ half _TileScale;
84
+
85
+
86
+
87
+ // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
88
+
89
+ // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
90
+
91
+ // #pragma instancing_options assumeuniformscaling
92
+
93
+ UNITY_INSTANCING_CBUFFER_START(Props)
94
+
95
+ // put more per-instance properties here
96
+
97
+ UNITY_INSTANCING_CBUFFER_END
98
+
99
+
100
+
101
+ void surf (Input IN, inout SurfaceOutputStandard o) {
102
+
103
+
104
+
105
+ // Albedo comes from a texture tinted by color
106
+
107
+ fixed factorX = abs(dot(IN.worldNormal, float3(1,0,0)));
108
+
109
+ fixed factorY = abs(dot(IN.worldNormal, float3(0,1,0)));
110
+
111
+ fixed factorZ = abs(dot(IN.worldNormal, float3(0,0,1)));
112
+
113
+
114
+
115
+ float3 scaledWorldPos = IN.worldPos / _TileScale;
116
+
117
+
118
+
119
+ fixed4 cx = tex2D (_MainTex, float2(scaledWorldPos.z, scaledWorldPos.y)) * factorX;
120
+
121
+ fixed4 cy = tex2D (_MainTex, float2(scaledWorldPos.x, scaledWorldPos.z)) * factorY;
122
+
123
+ fixed4 cz = tex2D (_MainTex, float2(scaledWorldPos.x, scaledWorldPos.y)) * factorZ;
124
+
125
+
126
+
127
+ fixed4 c = (cx + cy + cz);
128
+
129
+
130
+
131
+ o.Albedo = c.rgb;
132
+
133
+ // Metallic and smoothness come from slider variables
134
+
135
+ o.Metallic = _Metallic;
136
+
137
+ o.Smoothness = _Glossiness;
138
+
139
+ o.Alpha = c.a;
140
+
141
+ }
142
+
143
+ ENDCG
144
+
145
+ }
146
+
147
+ FallBack "Diffuse"
148
+
149
+ }
150
+
151
+
152
+
153
+ ```