質問編集履歴
1
title
CHANGED
|
@@ -1,1 +1,1 @@
|
|
|
1
|
-
|
|
1
|
+
スクリプトから色を指定できるシェーダーを自作したい
|
body
CHANGED
|
@@ -1,78 +1,72 @@
|
|
|
1
|
-
### 前提・実現したいこと
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### 試したこと
|
|
77
|
-
|
|
78
|
-
MainTexの設定のほうが優先されてColorの設定が反映されていないのかと考え、_MainTexの行を消してみましたが灰色になるだけでした。
|
|
1
|
+
### 前提・実現したいこと
|
|
2
|
+
|
|
3
|
+
Unity3Dで以下の条件を持ったシェーダーを作ろうとしています
|
|
4
|
+
・影の描写をしない(unlit)
|
|
5
|
+
・表裏両方描く(Cull off)
|
|
6
|
+
・スクリプトでオブジェクトの色を取得できる
|
|
7
|
+
・スクリプトからオブジェクトの色を変更できる
|
|
8
|
+
・サブメッシュがある
|
|
9
|
+
|
|
10
|
+
似た質問を探してみましたが見当たりませんでした、知っている方よろしくお願いします。
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### 該当のソースコード
|
|
15
|
+
|
|
16
|
+
```ここに言語名を入力
|
|
17
|
+
Shader "Custom/ryoumen_sheder"
|
|
18
|
+
{
|
|
19
|
+
Properties
|
|
20
|
+
{
|
|
21
|
+
_Color ("Color", Color) = (1,1,1,1)
|
|
22
|
+
_MainTex ("Albedo (RGB)", 2D) = "red" {}
|
|
23
|
+
_Glossiness ("Smoothness", Range(0,1)) = 0.5
|
|
24
|
+
_Metallic ("Metallic", Range(0,1)) = 0.0
|
|
25
|
+
}
|
|
26
|
+
SubShader
|
|
27
|
+
{
|
|
28
|
+
Tags { "RenderType"="Opaque" }
|
|
29
|
+
LOD 200
|
|
30
|
+
Cull off
|
|
31
|
+
|
|
32
|
+
CGPROGRAM
|
|
33
|
+
// Physically based Standard lighting model, and enable shadows on all light types
|
|
34
|
+
#pragma surface surf Standard fullforwardshadows
|
|
35
|
+
|
|
36
|
+
// Use shader model 3.0 target, to get nicer looking lighting
|
|
37
|
+
#pragma target 3.0
|
|
38
|
+
|
|
39
|
+
sampler2D _MainTex;
|
|
40
|
+
|
|
41
|
+
struct Input
|
|
42
|
+
{
|
|
43
|
+
float2 uv_MainTex;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
half _Glossiness;
|
|
47
|
+
half _Metallic;
|
|
48
|
+
fixed4 _Color;
|
|
49
|
+
|
|
50
|
+
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
|
|
51
|
+
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
|
|
52
|
+
// #pragma instancing_options assumeuniformscaling
|
|
53
|
+
UNITY_INSTANCING_BUFFER_START(Props)
|
|
54
|
+
// put more per-instance properties here
|
|
55
|
+
UNITY_INSTANCING_BUFFER_END(Props)
|
|
56
|
+
|
|
57
|
+
void surf (Input IN, inout SurfaceOutputStandard o)
|
|
58
|
+
{
|
|
59
|
+
// Albedo comes from a texture tinted by color
|
|
60
|
+
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
|
|
61
|
+
o.Albedo = c.rgb;
|
|
62
|
+
// Metallic and smoothness come from slider variables
|
|
63
|
+
o.Metallic = _Metallic;
|
|
64
|
+
o.Smoothness = _Glossiness;
|
|
65
|
+
o.Alpha = c.a;
|
|
66
|
+
}
|
|
67
|
+
ENDCG
|
|
68
|
+
}
|
|
69
|
+
FallBack "Diffuse"
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
```
|