teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

回答の追記

2017/09/04 01:12

投稿

Kapustin
Kapustin

スコア1188

answer CHANGED
@@ -1,3 +1,77 @@
1
1
  Cube限定ですが、こちらのアセットはいかがでしょうか?
2
2
  [MasterCube](https://www.assetstore.unity3d.com/jp/#!/content/40033)
3
- [紹介サイト](http://tsubakit1.hateblo.jp/entry/2016/05/24/073000)
3
+ [紹介サイト](http://tsubakit1.hateblo.jp/entry/2016/05/24/073000)
4
+
5
+ 追記:
6
+ シェーダで実装することも可能です。
7
+ 何となくですが、ワールド座標とテクスチャのUV座標を対応させたタイリング用シェーダを書いてみました。
8
+ 新規マテリアルを作成し、シェーダを`Custom > TileShader`に設定してください。
9
+ [TileScale]の値を変えるとタイルの大きさが変わります。
10
+
11
+ ```
12
+ Shader "Custom/TileShader" {
13
+ Properties {
14
+ _Color ("Color", Color) = (1,1,1,1)
15
+ _MainTex ("Albedo (RGB)", 2D) = "white" {}
16
+ _Glossiness ("Smoothness", Range(0,1)) = 0.5
17
+ _Metallic ("Metallic", Range(0,1)) = 0.0
18
+ _TileScale ("TileScale", Range(0.1, 10)) = 1
19
+ }
20
+ SubShader {
21
+ Tags { "RenderType"="Opaque" }
22
+ LOD 200
23
+
24
+ CGPROGRAM
25
+ // Physically based Standard lighting model, and enable shadows on all light types
26
+ #pragma surface surf Standard fullforwardshadows
27
+
28
+ // Use shader model 3.0 target, to get nicer looking lighting
29
+ #pragma target 3.0
30
+
31
+ sampler2D _MainTex;
32
+
33
+ struct Input {
34
+ float2 uv_MainTex;
35
+ float3 worldPos;
36
+ float3 worldNormal;
37
+ };
38
+
39
+ half _Glossiness;
40
+ half _Metallic;
41
+ fixed4 _Color;
42
+ half _TileScale;
43
+
44
+ // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
45
+ // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
46
+ // #pragma instancing_options assumeuniformscaling
47
+ UNITY_INSTANCING_CBUFFER_START(Props)
48
+ // put more per-instance properties here
49
+ UNITY_INSTANCING_CBUFFER_END
50
+
51
+ void surf (Input IN, inout SurfaceOutputStandard o) {
52
+
53
+ // Albedo comes from a texture tinted by color
54
+ fixed factorX = abs(dot(IN.worldNormal, float3(1,0,0)));
55
+ fixed factorY = abs(dot(IN.worldNormal, float3(0,1,0)));
56
+ fixed factorZ = abs(dot(IN.worldNormal, float3(0,0,1)));
57
+
58
+ float3 scaledWorldPos = IN.worldPos / _TileScale;
59
+
60
+ fixed4 cx = tex2D (_MainTex, float2(scaledWorldPos.z, scaledWorldPos.y)) * factorX;
61
+ fixed4 cy = tex2D (_MainTex, float2(scaledWorldPos.x, scaledWorldPos.z)) * factorY;
62
+ fixed4 cz = tex2D (_MainTex, float2(scaledWorldPos.x, scaledWorldPos.y)) * factorZ;
63
+
64
+ fixed4 c = (cx + cy + cz);
65
+
66
+ o.Albedo = c.rgb;
67
+ // Metallic and smoothness come from slider variables
68
+ o.Metallic = _Metallic;
69
+ o.Smoothness = _Glossiness;
70
+ o.Alpha = c.a;
71
+ }
72
+ ENDCG
73
+ }
74
+ FallBack "Diffuse"
75
+ }
76
+
77
+ ```