Skip to content

Commit 35e5279

Browse files
committed
enable to control shader from script
1 parent 30ca590 commit 35e5279

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

Assets/Shader_color.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using UnityEngine;
2+
using System.Collections;
3+
4+
5+
6+
public class Shader_color : MonoBehaviour {
7+
public Material mat;
8+
public Color color = new Color (1.0f,1.0f,0.0f,1.0f);
9+
// Use this for initialization
10+
void Start () {
11+
}
12+
13+
// Update is called once per frame
14+
void Update () {
15+
if (Input.GetKey(KeyCode.Space)) {
16+
// renderer.material.SetColor("_MyColor", Color (1,1,1,1));
17+
mat.SetColor("_MyColor", color);
18+
}
19+
}
20+
}

Assets/Shader_color.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/main.unity

2.33 KB
Binary file not shown.

Assets/test_material2.mat

28 Bytes
Binary file not shown.

Assets/test_shader2.shader

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
Shader "Custom/test_shader2" {
2+
Properties {
3+
_MyColor ("Color", Color) = (1.0, 0.0, 0.0, 1.0)
4+
}
25
SubShader {
36
Pass {
47
// GLSLシェーダ
@@ -7,15 +10,18 @@
710
#ifdef VERTEX
811
void main()
912
{
13+
//頂点の設定
1014
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
1115
}
1216
#endif
1317

1418
#ifdef FRAGMENT
1519
uniform vec4 _SinTime;
20+
uniform vec4 _MyColor;
1621
void main()
1722
{
18-
gl_FragColor = _SinTime;
23+
// gl_FragColor = _SinTime;
24+
gl_FragColor = _MyColor;
1925
}
2026
#endif
2127

0 commit comments

Comments
 (0)