Meterials 생성
Shaders 생성
Meterials 폴더 안에 MyMeterial 생성 -> 색상 레드
Shaders 폴더 안에 MtShader 생성
Cube 오브젝트 생성
재료로 MyMeterial을 넣어주고
MyShader를 MyMeterial에 넣어 준다
제일 간단하게 만든 코드
Shader "Custom/MyShader" // (/)경로 (반드시 같을 필요는 없다.)
{
Properties //inspector창
{
_Color ("Color", Color) = (1,1,1,1)
//_MainTex ("Albedo (RGB)", 2D) = "white" {}
//_Glossiness ("Smoothness", Range(0,1)) = 0.5 //매끈해짐
//_Metallic ("Metallic", Range(0,1)) = 0.0 //재질
}
SubShader //cg코드 시작
{
Tags { "RenderType"="Opaque" } //불투명
//LOD 200 //디테일
CGPROGRAM
#pragma surface surf Standard fullforwardshadows //#pragma -> 함수로 ~하겠다 //surface surf Standard 까지는 기본 //Standard -> 조명 연산
// Use shader model 3.0 target, to get nicer looking lighting
//#pragma target 3.0
sampler2D _MainTex;
struct Input
{
//float2 uv_MainTex; //모르면 서피스 쉐이더 인풋 구조 찾아보기 //인풋에는 무조건 하나는 들어가야함.
};
//half _Glossiness;
//half _Metallic;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutputStandard o) //surf안에 있는 것들이 색을 계산한다 //SurfaceOutputStandard -> 타입 //o -> 변수
{
// Albedo comes from a texture tinted by color
fixed4 c = _Color; //tex2D (_MainTex, IN.uv_MainTex) * _Color; //tex2D() -> cg의 메서드(어떤 값을 반환하는지 알아야함!) //float4 * float4라서 연산가능
o.Albedo = c.rgb;
//o.Metallic = _Metallic;
//o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG //cg코드 종료
}
FallBack "Diffuse"
}
windows -> Randering -> lightning
Environment에서 Custom을 눌러주면 색을 더 진하게 만든다
*다른색 코드
Shader "Custom/MyShader" // (/)경로 (반드시 같을 필요는 없다.)
{
Properties //inspector창
{
_Color ("Color", Color) = (1,1,1,1)
_Brightness ("Change Brightness!!", Range(0, 1)) = 0.5
_TestFloat ("Test Float", Float) = 0.5
_TestColor ("Test Color", Color) = (1,1,1,1)
_TestVector("Test Vector", Vector) = (1,1,1,1)
_TestTexture("Text Texture", 2D) = "White" { }
//_MainTex ("Albedo (RGB)", 2D) = "white" {}
//_Glossiness ("Smoothness", Range(0,1)) = 0.5 //매끈해짐
//_Metallic ("Metallic", Range(0,1)) = 0.0 //재질
}
SubShader //cg코드 시작
{
Tags { "RenderType"="Opaque" } //불투명
//LOD 200 //디테일
CGPROGRAM
#pragma surface surf Standard fullforwardshadows //#pragma -> 함수로 ~하겠다 //surface surf Standard 까지는 기본옵션 //Standard -> 조명 연산
// Use shader model 3.0 target, to get nicer looking lighting
//#pragma target 3.0
sampler2D _MainTex;
struct Input //Input구조체는 쉐이더에 의해 요구되는 텍스처 좌표가 있다. //uv texture 받아오기
{
//float2 uv_MainTex; //모르면 서피스 쉐이더 인풋 구조 찾아보기 //인풋에는 무조건 하나는 들어가야함.
float2 uv_TestTexture;
};
//half _Glossiness;
//half _Metallic;
fixed4 _Color;
sampler2D _TestTexture;
void surf (Input IN, inout SurfaceOutputStandard o) //surf안에 있는 것들이 색을 계산한다 //SurfaceOutputStandard -> 타입 //o -> 변수
{
fixed4 c = _Color; //tex2D (_MainTex, IN.uv_MainTex) * _Color; //tex2D() -> cg의 메서드(어떤 값을 반환하는지 알아야함!) //float4 * float4라서 연산가능
//o.Albedo = c.rgb; //(1, 0, 0) //r = 1 이니까 @빨강
//o.Albedo = c.rrr; //(1, 1, 1) //1,1,1 은 흰색 0,0,0은 검은색 이니까 @흰색
//o.Albedo = c.g; //(0, 0, 0) //가운데 rgb = (1, 0, 0) 이니까 g는 가운데 0이므로 @검정
//o.Alpha = c.a; //(r, g, b, a) 에서 a는 0이므로 @검정
//o.Albedo = c.rgr; //(1, 0, 1) //@보라
//텍스쳐의 색상 정보를 가져오고 싶다
//float4 textureColor = tex2D(_TestTexture, IN.uv_TestTexture);
//블랙: o.Albedo = 0; //레드: textureColor.rgb;
//블랙: o.Alpha = 1; //레드: textureColor.a;
//기본색으로
//float3 final = float3(1, 0, 0) + float3(0, 1, 0);
//float4 textureColor = tex2D(_TestTexture, IN.uv_TestTexture);
//o.Emission = final; //기본
//o.Emission = final + textureColor; //기본에서 더 밝아짐
//o.Emission = (_Color.rgb + textureColor) * _Brightness;
}
ENDCG //cg코드 종료
}
FallBack "Diffuse"
}
'Unity > 수업 내용' 카테고리의 다른 글
[게임 그래픽] Shader - UV(좌표계) (0) | 2021.11.18 |
---|---|
[게임 그래픽] Shader - Lerp (0) | 2021.11.18 |
[게임 그래픽] Shader (0) | 2021.11.17 |
[게임인공지능] - ML-Agents(Dino) (0) | 2021.11.17 |
[게임인공지능] - ML-Agents (해석) (0) | 2021.11.15 |