버텍스컬러 출력하기

{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}


}

 

SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200

CGPROGRAM

#pragma surface surf Standard noambient


sampler2D _MainTex;

struct Input
{
float2 uv_MainTex;
float4 color:COLOR; //
컬러를 추가하였음.
};

 

void surf (Input IN, inout SurfaceOutputStandard o)
{

fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
//o.Albedo = c.rgb;
//o.Albedo = IN.color.rgb; //
이렇게 해도됨. 다만 그림자가 진다.
//o.Albedo = c.rgb+IN.color.rgb; //
이러면 버텍스 컬러와 이미지가 같이 나오겠지.
//o.Albedo = c.rgb*IN.color.rgb; //
이러면 버텍스 컬러와 이미지가 곱해지니깐 검은곳은 어둡게(검은곳은 0이니깐).
이렇게하면 텍스쳐 없는 오클루젼을 만들수 있다.(라이트맵처럼)
o.Emission = IN.color.rgb; // Emission
으로 출력
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}

   

여러장 버텍스 텍스쳐사용

{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_MainTex2 ("Albedo (RGB)", 2D) = "white" {}
_MainTex3 ("Albedo (RGB)", 2D) = "white" {}
_MainTex4 ("Albedo (RGB)", 2D) = "white" {}


}

 

SubShader
{
Tags { "RenderType"="Opaque" }


CGPROGRAM

#pragma surface surf Standard noambient


sampler2D _MainTex;
sampler2D _MainTex2;
sampler2D _MainTex3;
sampler2D _MainTex4;

 

struct Input
{
float2 uv_MainTex;
float2 uv_MainTex2;
float2 uv_MainTex3;
float2 uv_MainTex4;
float4 color:COLOR;



};
<![if !supportLineBreakNewLine]>
<![endif]>

 

void surf (Input IN, inout SurfaceOutputStandard o)
{

fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
fixed4 d = tex2D (_MainTex2, IN.uv_MainTex2);
fixed4 e = tex2D (_MainTex3, IN.uv_MainTex3);
fixed4 f = tex2D (_MainTex4, IN.uv_MainTex4);

o.Albedo = lerp(c.rgb, d.rgb, IN.color.r);
o.Albedo = lerp(o.Albedo, e.rgb, IN.color.g);
o.Albedo = lerp(o.Albedo, f.rgb, IN.color.b);

o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}

 

유니티 쉐이더 스타트업 자료(정종필저)

'Unity > Surface Shader' 카테고리의 다른 글

Lambert 공식  (0) 2020.05.17
라이팅구조  (0) 2020.05.17
texture  (0) 2020.05.16
CGPROGRAM03  (0) 2020.05.16
CGPROGRAM02  (0) 2020.05.16

흑백이미지

void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo =(c.r+c.g+c.g)/3;
o.Alpha = c.a;
}

   
       

UV 밀기

void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex+0.5);
o.Albedo = c.rgb;
o.Alpha = c.a;
}

   
       

lerp함수

_MainTex ("텍스쳐1", 2D) = "white { }
_MainTex2 ("
텍스쳐2", 2D) = "white { }

Properties

lerp(X,Y,s)
X,Y
반드시 float, float1,float2,float3,float4형태
s
float 한자리수로 0~1이다.

 

sampler2D _MainTex;
sampler2D _MainTex2;

   
 

void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
fixed4 d = tex2D (_MainTex, IN.uv_MainTex2);

o.Albedo =lerp(c.rgb, d.rgb, 0.5);
o.Alpha = c.a;
}

2개의 텍스쳐를 혼합
선형 보간(그라데이션)

lerp(X, Y, s) s
float(숫자)이어야 합니다.

0.5
인하여 이미지가 반반씩 섞이게 됩니다.

 
 

void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
fixed4 d = tex2D (_MainTex, IN.uv_MainTex2);

o.Albedo =lerp(c.rgb, d.rgb, c.a);
o.Alpha = c.a;
}

알패 채널을 이용하여 두가지의 텍스쳐를 나오게 하는 방법.

o.Albedo =lerp(c.rgb, d.rgb, 1-c.a)
하면 반대로 뒤집힌다.
위엣것이랑 같은게 된다.o.Albedo =lerp(d.rgb, c.rgb, c.a)

 
       

lerp함수 비슷한거

void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
fixed4 d = tex2D (_MainTex, IN.uv_MainTex2);

o.Albedo = c.rgb * d.rgb;
o.Alpha = c.a;
}

*으로 곱해줌.

o.Albedo = c.rgb * (d.rgb+_lerptest);
위에 프로버티를 그대로 적용하면 컬러가 섞인다.

 

 

유니티 쉐이더 스타트업 자료(정종필저)

'Unity > Surface Shader' 카테고리의 다른 글

라이팅구조  (0) 2020.05.17
Vertex color  (0) 2020.05.17
CGPROGRAM03  (0) 2020.05.16
CGPROGRAM02  (0) 2020.05.16
CGPROGRAM01  (0) 2020.05.16

변수

void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color

float4 test = float4(1,0,0,1)

fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = test;

o.Alpha = c.a;
}

빨란색이 출력

o.Albedo = test.rgb;
라고 써야 맞다. 이유는 rgb 사용하기 때문이다.

rgb
앞에 마침표는 내부에 들어갈 값이다.

.rgb
라고 쓰면 float3으로 변경되는것이다.

float4 test = float4(1,0,0,1)
위치가 위어야 정상으로 출력이된다.

void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color

float K = 1;
float G = float2(0.5,0);
float BB = float3(1,0,1);

fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = float3(K,G,BB)

o.Alpha = c.a;
}

핑크 컬러 출력

o.Albedo = float3(0.2,G,1)
이런식으로 숫자를 넣어도 된다.

 

'Unity > Surface Shader' 카테고리의 다른 글

Vertex color  (0) 2020.05.17
texture  (0) 2020.05.16
CGPROGRAM02  (0) 2020.05.16
CGPROGRAM01  (0) 2020.05.16
Propeties  (0) 2020.05.16

색상출력

void surf (Input IN, inout SurfaceOutputStandard o){ }

SurfaceOutputStandard 라는 구조체를 o.이라고 부르겠다.
마침표는 ' 안에 있는' 같은 의미

input구조체를 IN이란 이름으로 함수 안에 받아들이고,
SurfaceOutputStandard
라는 구조체를 o라는 이름으로
함수안에 받기도 집어 넣기도 하겠다.

void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo =float3 (1,0,0)
o.Alpha = c.a;
}

빨간색을 출력

o.Albedo = 'o'
안에 Albedo 변수라는 의미

// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows noambient

// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0

ambient 컬러가 꺼진다.

target 3.0
쉐이더 모델3.0이상에서만 돌아가게 하는 코드
불필요하면 지워도 된다.

void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo =float3 (1,0,0)+float3 (0,1,0)
o.Alpha = c.a;
}

노란색으로 출력

+
add 포토샵의 Liner Dodge 같다.
*
Multipy 이다.

 

'Unity > Surface Shader' 카테고리의 다른 글

texture  (0) 2020.05.16
CGPROGRAM03  (0) 2020.05.16
CGPROGRAM01  (0) 2020.05.16
Propeties  (0) 2020.05.16
기초  (0) 2020.05.16

SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200

기본

CGPROGRAM

중요하지만 이름이 없음.

// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows

// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0

설정부분 스니핏(snippet)
쉐이더의 조명계산 설정이나, 세부적인 분기를 정해주는 부분

sampler2D _MainTex;

중요하지만 이름이 없음.
대소문자를 중요하게 생각하세요.

struct Input
{
float2 uv_MainTex;
};

Input이라는 구조체(structure)입니다.
엔진으로 부터 받아와야할 데이터가 들어갑니다.

{ }
안에 들어 있으며, ; 끝에 있다.

uv uv 2개의 숫자로 float2이며, MainTax uv라는 뜻으로
uv_MainTex
처럼 텍스쳐 샘플러 이름 앞에 uv라는 글자를 붙입니다.

half _Glossiness;
half _Metallic;
fixed4 _Color;

중요하지만 이름이 없음.

void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}

surf라는 이름의 함수 영역.
색상이나 이미지가 출력되는 부분을 만들수 있다.
;
없다.

fixed4 c라는 변수를 선언하였습니다.
float
보다 1/2 half(16비트), fixed(11비트) 필요에 따라 사용됩니다.
대부분 텍스쳐컬러는 8비트 이하이므로 fixed 충분하기 때문에 사용.
float
사용해도 무방합니다.
float4
결과 = text2D(샘플러, UV)

ENDCG

중요하지만 이름이 없음.

 

'Unity > Surface Shader' 카테고리의 다른 글

texture  (0) 2020.05.16
CGPROGRAM03  (0) 2020.05.16
CGPROGRAM02  (0) 2020.05.16
Propeties  (0) 2020.05.16
기초  (0) 2020.05.16

Range

_Name (“display name”, Range(min,max)) = number

 

_Brightness(“밝기”, Range(0,1)) = 0.5

   
 

_Name

 

변수명입니다.

 

한글 안되고, 띄워쓰기 안되고, 숫자로 시작 안되고, 특수문자 안되고,

 

내부 언어를 써도 안된다.

   
 

display name

 

엔진에서 순수한 글씨로 인식한다.

   
 

Range(min,max)

 

슬라이더 바를 만들겠다.

   
 

number

 

초기값을 넣는 부분

   

Float

_Name (“display name”,Float) = number

 

_test(“test”,Float) = 0.5

   
 

float 자라의 소수점을 입력받는 인터페이스를 만들어준다.

   
   

Color

_Name ("display name", Color ) = (number, number, number, number)

 

_Testcolor("컬러",Color) = (1,1,1,1)

   
 

컬러 인터페이스를 만들어준다.

 

RGBA float4 받는다. 컬러 픽커를 만든다.

   

Vector

_Name ("display name", Vector ) = (number, number, number, number)

 

_TestVecr("숫자방식을 입력",Vector) = (1,1,1,1)

   
 

float4 직접 받는 인터페이슬 만들수 있다.(정해진것이 아닌 내가 숫자를 넣어 값을 만드는것)

   

tex2D

_Name ("display name", 2D ) = "name"{options}

 

_Test2D("UV텍스쳐",2D) = "white" { }

   
 

float 계열로 분류되지 않는 sampler

 

텍스쳐는 UV 좌표와 함께 계산되어야 float4 출력될수 있기 때문에, 아직 UV 계산되지 않은 텍스쳐는 색상(float4)

 

나타낼수 없습니다. 그래서 이때까지는 sampler라고 부릅니다.

   
 

white black이나 gray 써도 된다.

 

유니티 쉐이더 스타트업 자료(정종필저)

'Unity > Surface Shader' 카테고리의 다른 글

texture  (0) 2020.05.16
CGPROGRAM03  (0) 2020.05.16
CGPROGRAM02  (0) 2020.05.16
CGPROGRAM01  (0) 2020.05.16
기초  (0) 2020.05.16

빨,녹,파(RGB)

Float3(1.0,1.0,1.0) - 힌색  /  Float3(0.5,0.5,0.5) - 회색  /  Float3(0.0,0.0,0.0) - 검정색

Float3(1.0,0.0,0.0) - 빨간색 / Float3(1.0,1.0,0.0) - 노란색 

 

영어 /소문자

 
   

괄호는 반드시 닫는다.

 
   

띄어쓰기와 엔터는 의미가 없다.

 
   

세미콜론은 엔터의 의미.

 
   

A = B

같다는 의미가 아니라 B A안에 담긴다는 뜻이다.

   

변수

변하는 (데이터를 담아놓는 상자)

 

B 변수이다.

   
   

Surface shader 작성한다.

vertex & Fragment shader 코딩을 배워서 해야한다.

서피스 쉐이더

cg 쉐이더 코드를 이용한다.

   
   
   

Unlit

라이팅연산이 없는 쉐이더

   
   

lerp함수

o.Albedo =lerp(c.rgb, d.rgb, 0.5);

   

"노란색으로 출력

+
add 포토샵의 Liner Dodge 같다.
*
Multipy 이다."

   

float ndotl = saturate(dot(s.Normal, lightDir))

saturate 함수는 0보다 낮은 값은 0으로 1보다 높은 값은 1

   

//float ndotl = max(0.2,dot(s.Normal, lightDir));

//max 한쪽의 값을 0.2으로 하면, 0.2보다 작은 다른쪽 값을 무조건 0으로 출력

   

//float ndotl = dot(s.Normal, lightDir)*0.5+0.5;

// halp Lambert 연산 만들기

   

o.Emission = pow(1- rim, 3);
spec = pow(spec,_SpecPow);

그래서 pow(exponet, 지수) 써서 그래프가 산모양으로 되게 만들어서
굵기를 얇게 하는것이다.

pow
연산은 비교적 무겁다.

   

viewDir

// 버텍스가 카메라 방향을 보는 방향

   

PR

photo realistic

NPR

Non photo realistic

   

cull front

앞을 날림

cull back

뒤를 날림

cull off

2 side

2pass

오브젝트를 두번그리는것

   

vertex shader

버텍스를 변환 제어 쉐이더

pixel shader

화면 출력될 픽셀의 컬러를 결정하는 쉐이더

   

ceil

올림으로 소수점이 있는 숫자를 정수로 만들어준다.

 

'Unity > Surface Shader' 카테고리의 다른 글

texture  (0) 2020.05.16
CGPROGRAM03  (0) 2020.05.16
CGPROGRAM02  (0) 2020.05.16
CGPROGRAM01  (0) 2020.05.16
Propeties  (0) 2020.05.16