SlideShare a Scribd company logo
1 of 23
Download to read offline
03. Lighting과 Shader Compiler
이상윤 http://illu.tistory.com
2주차 과제 확인
Shader "Study/Terrain4BlendVertexColor" {
Properties {
_MainTex1(“Base 텍스쳐”, 2D) = “white” {}
_MainTex2(“R 텍스쳐”, 2D) = “white” {}
_MainTex3(“G 텍스쳐”, 2D) = “white” {}
_MainTex4(“B 텍스쳐”, 2D) = “white” {}
}
SubShader {
Tags { "RenderType"="Opaque" }
GPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex1;
sampler2D _MainTex2;
sampler2D _MainTex3;
sampler2D _MainTex4;
struct Input {
float4 color:COLOR;
float2 uv_MainTex1;
float2 uv_MainTex2;
float2 uv_MainTex3;
float2 uv_MainTex4;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed3 t1 = tex2D(_MainTex1, IN.uv_MainTex1).rgb;
fixed3 t2 = tex2D(_MainTex1, IN.uv_MainTex1).rgb;
fixed3 t3 = tex2D(_MainTex1, IN.uv_MainTex1).rgb;
fixed3 t4 = tex2D(_MainTex1, IN.uv_MainTex1).rgb;
fixed3 c1 = lerp( t1, t2, IN.color.r);
fixed3 c2 = lerp( c1, t3, IN.color.g);
fixed3 c3 = lerp( c2, t4, IN.co.or.b);
o.Albedo = c3.rgb;
}
ENDCG
}
}
Shader "Study/Terrain4BlendMasking" {
Properties {
_MainTex1(“Base 텍스쳐”, 2D) = “white” {}
_MainTex2(“R 텍스쳐”, 2D) = “white” {}
_MainTex3(“G 텍스쳐”, 2D) = “white” {}
_MainTex4(“B 텍스쳐”, 2D) = “white” {}
_BlendTex(“마스킹 텍스쳐”, 2D) = “white” {}
}
SubShader {
Tags { "RenderType"="Opaque" }
GPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex1;
sampler2D _MainTex2;
sampler2D _MainTex3;
sampler2D _MainTex4;
sampler2D _BlendTex;
struct Input {
float2 uv_MainTex1;
float2 uv_MainTex2;
float2 uv_MainTex3;
float2 uv_MainTex4;
float2 uv2_BlendTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed3 bl = tex2D(_BlendTex, IN.uv2_BlendTex).rgb;
fixed3 t1 = tex2D(_MainTex1, IN.uv_MainTex1).rgb;
fixed3 t2 = tex2D(_MainTex1, IN.uv_MainTex1).rgb;
fixed3 t3 = tex2D(_MainTex1, IN.uv_MainTex1).rgb;
fixed3 t4 = tex2D(_MainTex1, IN.uv_MainTex1).rgb;
fixed3 c1 = lerp( t1, t2, bl..r);
fixed3 c2 = lerp( c1, t3, bl.g);
fixed3 c3 = lerp( c2, t4, bI.b);
o.Albedo = c3.rgb;
}
ENDCG
}
}
Uv scroll
tex2D(_MainTex, IN.uv_MainTex);
tex2D(_MainTex, float2(IN.uv_MainTex.x + _Time.x, IN.uv_MainTex.y));
http://docs.unity3d.com/462/Documentation/Manual/SL-BuiltinValues.html
흐름의 세기를 조절할수 있는 Shader를 만들어 봅시다.
힌트 : IN.uv_MainTex.x + _Time ????
Custom Lighting
CGPROGRAM
#pragma surface surf Lambert
Lambert와 BlinnPhong은 Lighing.cginc 파일에 내장되어 있어 선언만 해주면 되지만 직접 만들경우(Custom
Lighting) 에는 조명 설계를 해주어야 합니다.
half4 Lighting<Name> (SurfaceOutput s, half3 lightDir, half atten)
라이트 모델의 포워드 렌더링 패스에서 사용됩니다
half4 Lighting<Name> (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
뷰 방향에 의존하고 있는 라이팅 모델의 포워드 렌더링 패스에서 사용됩니다
자세한 내용은 : http://docs.unity3d.com/kr/current/Manual/SL-SurfaceShaderLighting.html
fixed4 LightingUnityLambert (SurfaceOutput s, half3 lightDir, half atten)
{
fixed diff = max (0, dot (s.Normal, light.dir));
fixed4 c;
c.rgb = s.Albedo * light.color * diff;
c.a = s.Alpha;
return c;
}
Lambert Lighting 공식
dot ( a, b ) : a와 b의 내적
max( a, b ) : a와 b의 최대값
요한 하인리히 람베르트(Johann Heinrich Lambert) : 스위스의 수학자, 물리학자, 천문학자, 철학자
램버시안 반사율 : 관찰자가 바라보는 각도와 관계없이 같은 겉보기 밝기를 갖는다. 이를 난반사가 이루어지는 표면을 묘사하기 위해
램버시안 모델을 사용하게 되는데 이는 표면의 특징을 잘 모를때 램버시안 반사는 적당한 근사치가 될 수 있기 때문이다.
half NdotL = dot (s.Normal, lightDir);
half diff = NdotL * 0.5 + 0.5;
half4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten);
c.a = s.Alpha;
Unlit Lighting 공식
fixed4 LightingUnlit (SurfaceOutput s, half3 lightDir, half atten)
{
return fixed4(s.Albedo, 1);
}
Unlit : Unlighting을 준말으로 빛을 계산하지 않는 상태로 많이 표기 된다.}
UE4 Nod Unlit 설정. Shading Model에서 Unlit를 설정
Shading Model에서 Unlit로 설정하면
Base color 항목이 비활성되며 Emissive
color 항목만이 활성화 된다.(ambient
source의 영향은 받는 상태)
Unlit Diffuse Shader를 작성해 봅니다.
noambient option에 따른 밝기 변화 비교
Unlit 경우처럼 빛을 계산하지 않는 상태에
서도 ambient color에 영향을 받는다.
Light probe를 사용할 경우 이 옵션을 꺼버
리면 아예 빛계산을 못하고 까맣게 나온다.
Compiler code
alpha : 알파 블랜딩 타입, 반투명한 셰이더에 사용.
alphatest:VariableName : 알파 테스팅 모드, transparent-cutout 셰이더에 사용. Cutoff 값은 변수 이름에 따름
addshadow : 그림자 생성과 수집 패스를 추가. 절차적인 버텍스 애니메이션이 그림자에 영향을 미치도록 커스텀 버텍스
수정 함수와 함께 사용.
Surface는 Shader는 전처리된 코드를 적절히 잘 사용할 수 있는 반면 많은 경우의 수에 대하여 Shader가 컴파일 되므로
Compiler 구문에서 막아서 선언해줘야 한다. 반대로 fragment 구조에서는 필요한 경우에 대해서 Shader에서 계산을 해
줘야 한다.
Compiler code
noambient : 앰비언트 라이팅이나 SH라이트가 적용되지 않게 함
novertexlights : 포워드 렌더링에서 SH나 vertex light가 가동되지 않게 함
nolightmap : 셰이더가 라이트맵을 지원하지 않게 만든다
nodirlightmap : directional lightmap을 지원하지 않게 한다
noforwardadd : 포워드 렌더링 가산 패스를 비활성화한다. 그 결과 셰이더는 하나의 디렉셔널 라이트를
완전히 지원하고, 나머지 라이트는 버텍스 단위 또는 SH 방식으로 처리된다. 셰이더를 가볍게 만든다.
approxview : 픽셀이 아니라 버텍스 단위로 단위화된 시선 방향 벡터를 계산한다. 처리가 빨라지지만 카
메라가 오브젝에 근접할 경우 시선방향의 계산이 부정확할 수 있다.
>> Unity 5에서 interpolateview로 변경
halfasview : 시선 방향 대신 하프 디렉션 벡터를 라이팅 함수에 전달한다. 하프 디렉션은 벡터는 버텍스
단위로 연산되고 단위화 된다. 빠르지만 정확도가 떨어진다.
Unlit alphatest Shader를 만들어 봅시다.
Alphatest
0, 1 alpha만 존재.
Alphablend
반투명
fixed4 LightingUnlit (SurfaceOutput s, half3 lightDir, half atten)
{
return fixed4(s.Albedo, s.Alpha);
}
Properties {
_AlphaCut (“AlphaCut”, Range(0,1)) = 0.5
}
SubShader {
Tags {“Queue"=“Transparent” "RenderType"=“Transparent”}
CGPROGRAM
#pragma surface surf Unlit alphatest:_AlphaCut
512x256 4x1 texture를 animation scroll로 이펙트를 표현해 봅니다.
Gif 파일로 애니메이션되는 이미지를 올려주시기 바랍니다.
수고하셨습니다.

More Related Content

What's hot

Startup JavaScript 3 - 조건문, 반복문, 예외처리
Startup JavaScript 3 - 조건문, 반복문, 예외처리Startup JavaScript 3 - 조건문, 반복문, 예외처리
Startup JavaScript 3 - 조건문, 반복문, 예외처리Circulus
 
Startup JavaScript 4 - 객체
Startup JavaScript 4 - 객체Startup JavaScript 4 - 객체
Startup JavaScript 4 - 객체Circulus
 
TestBCD2018-2(answer)
TestBCD2018-2(answer)TestBCD2018-2(answer)
TestBCD2018-2(answer)Yong Heui Cho
 
Startup JavaScript 6 - 함수, 스코프, 클로저
Startup JavaScript 6 - 함수, 스코프, 클로저Startup JavaScript 6 - 함수, 스코프, 클로저
Startup JavaScript 6 - 함수, 스코프, 클로저Circulus
 
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field종빈 오
 
2.Startup JavaScript - 연산자
2.Startup JavaScript - 연산자2.Startup JavaScript - 연산자
2.Startup JavaScript - 연산자Circulus
 
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기Chris Ohk
 
D2 Depth of field
D2 Depth of fieldD2 Depth of field
D2 Depth of fieldYoupyo Choi
 
Rendering realistic Ice objects
Rendering realistic Ice objectsRendering realistic Ice objects
Rendering realistic Ice objectsyong gyun im
 
Cpp 0x kimRyungee
Cpp 0x kimRyungeeCpp 0x kimRyungee
Cpp 0x kimRyungeescor7910
 
자료구조 그래프 보고서
자료구조 그래프 보고서자료구조 그래프 보고서
자료구조 그래프 보고서mil23
 
자료구조 05 최종 보고서
자료구조 05 최종 보고서자료구조 05 최종 보고서
자료구조 05 최종 보고서pkok15
 
포인터와 배열
포인터와 배열포인터와 배열
포인터와 배열Kim YoSep
 
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...Seok-joon Yun
 

What's hot (20)

Startup JavaScript 3 - 조건문, 반복문, 예외처리
Startup JavaScript 3 - 조건문, 반복문, 예외처리Startup JavaScript 3 - 조건문, 반복문, 예외처리
Startup JavaScript 3 - 조건문, 반복문, 예외처리
 
Startup JavaScript 4 - 객체
Startup JavaScript 4 - 객체Startup JavaScript 4 - 객체
Startup JavaScript 4 - 객체
 
TestBCD2018-2(answer)
TestBCD2018-2(answer)TestBCD2018-2(answer)
TestBCD2018-2(answer)
 
Startup JavaScript 6 - 함수, 스코프, 클로저
Startup JavaScript 6 - 함수, 스코프, 클로저Startup JavaScript 6 - 함수, 스코프, 클로저
Startup JavaScript 6 - 함수, 스코프, 클로저
 
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
 
2.Startup JavaScript - 연산자
2.Startup JavaScript - 연산자2.Startup JavaScript - 연산자
2.Startup JavaScript - 연산자
 
3D Graphics 101
3D Graphics 1013D Graphics 101
3D Graphics 101
 
Ch10
Ch10Ch10
Ch10
 
Ch11
Ch11Ch11
Ch11
 
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
 
D2 Depth of field
D2 Depth of fieldD2 Depth of field
D2 Depth of field
 
Rendering realistic Ice objects
Rendering realistic Ice objectsRendering realistic Ice objects
Rendering realistic Ice objects
 
D2 Rain (2/2)
D2 Rain (2/2)D2 Rain (2/2)
D2 Rain (2/2)
 
D2 Rain (1/2)
D2 Rain (1/2)D2 Rain (1/2)
D2 Rain (1/2)
 
Cpp 0x kimRyungee
Cpp 0x kimRyungeeCpp 0x kimRyungee
Cpp 0x kimRyungee
 
자료구조 그래프 보고서
자료구조 그래프 보고서자료구조 그래프 보고서
자료구조 그래프 보고서
 
자료구조 05 최종 보고서
자료구조 05 최종 보고서자료구조 05 최종 보고서
자료구조 05 최종 보고서
 
포인터와 배열
포인터와 배열포인터와 배열
포인터와 배열
 
픽킹
픽킹픽킹
픽킹
 
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
Effective Modern C++ MVA item 18 Use std::unique_ptr for exclusive-ownership ...
 

Viewers also liked

레퍼런스만 알면 언리얼 엔진이 제대로 보인다
레퍼런스만 알면 언리얼 엔진이 제대로 보인다레퍼런스만 알면 언리얼 엔진이 제대로 보인다
레퍼런스만 알면 언리얼 엔진이 제대로 보인다Lee Dustin
 
GameMath-Chapter 08 고급렌더링
GameMath-Chapter 08 고급렌더링GameMath-Chapter 08 고급렌더링
GameMath-Chapter 08 고급렌더링Mark Choi
 
Game Visual Art Technologies
Game Visual Art TechnologiesGame Visual Art Technologies
Game Visual Art TechnologiesSangYun Yi
 
유니티 게임 그래픽스 아트 개발 사례 분석
유니티 게임 그래픽스 아트 개발 사례 분석유니티 게임 그래픽스 아트 개발 사례 분석
유니티 게임 그래픽스 아트 개발 사례 분석SangYun Yi
 
전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012
전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012
전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012devCAT Studio, NEXON
 
LCD Monitor 선택 가이드와 Gamma의 이해
LCD Monitor 선택 가이드와 Gamma의 이해LCD Monitor 선택 가이드와 Gamma의 이해
LCD Monitor 선택 가이드와 Gamma의 이해SangYun Yi
 
【Unite 2017 Tokyo】Unityライティング最新情報
【Unite 2017 Tokyo】Unityライティング最新情報【Unite 2017 Tokyo】Unityライティング最新情報
【Unite 2017 Tokyo】Unityライティング最新情報Unite2017Tokyo
 
Rooms2 vr ArtWorks
Rooms2 vr ArtWorksRooms2 vr ArtWorks
Rooms2 vr ArtWorksSangYun Yi
 
Unite seoul 2016 Rooms2 mobile to VR
Unite seoul 2016 Rooms2 mobile to VRUnite seoul 2016 Rooms2 mobile to VR
Unite seoul 2016 Rooms2 mobile to VRSangYun Yi
 
Unite Seoul 2017 Yi SangYun
Unite Seoul 2017 Yi SangYunUnite Seoul 2017 Yi SangYun
Unite Seoul 2017 Yi SangYunSangYun Yi
 
Display color와 Digital texture format의 이해
Display color와 Digital texture format의 이해Display color와 Digital texture format의 이해
Display color와 Digital texture format의 이해SangYun Yi
 
Igc2016 Technical Artist가 뭐하는 사람이에요?
Igc2016 Technical Artist가 뭐하는 사람이에요?Igc2016 Technical Artist가 뭐하는 사람이에요?
Igc2016 Technical Artist가 뭐하는 사람이에요?SangYun Yi
 

Viewers also liked (12)

레퍼런스만 알면 언리얼 엔진이 제대로 보인다
레퍼런스만 알면 언리얼 엔진이 제대로 보인다레퍼런스만 알면 언리얼 엔진이 제대로 보인다
레퍼런스만 알면 언리얼 엔진이 제대로 보인다
 
GameMath-Chapter 08 고급렌더링
GameMath-Chapter 08 고급렌더링GameMath-Chapter 08 고급렌더링
GameMath-Chapter 08 고급렌더링
 
Game Visual Art Technologies
Game Visual Art TechnologiesGame Visual Art Technologies
Game Visual Art Technologies
 
유니티 게임 그래픽스 아트 개발 사례 분석
유니티 게임 그래픽스 아트 개발 사례 분석유니티 게임 그래픽스 아트 개발 사례 분석
유니티 게임 그래픽스 아트 개발 사례 분석
 
전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012
전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012
전형규, 가성비 좋은 렌더링 테크닉 10선, NDC2012
 
LCD Monitor 선택 가이드와 Gamma의 이해
LCD Monitor 선택 가이드와 Gamma의 이해LCD Monitor 선택 가이드와 Gamma의 이해
LCD Monitor 선택 가이드와 Gamma의 이해
 
【Unite 2017 Tokyo】Unityライティング最新情報
【Unite 2017 Tokyo】Unityライティング最新情報【Unite 2017 Tokyo】Unityライティング最新情報
【Unite 2017 Tokyo】Unityライティング最新情報
 
Rooms2 vr ArtWorks
Rooms2 vr ArtWorksRooms2 vr ArtWorks
Rooms2 vr ArtWorks
 
Unite seoul 2016 Rooms2 mobile to VR
Unite seoul 2016 Rooms2 mobile to VRUnite seoul 2016 Rooms2 mobile to VR
Unite seoul 2016 Rooms2 mobile to VR
 
Unite Seoul 2017 Yi SangYun
Unite Seoul 2017 Yi SangYunUnite Seoul 2017 Yi SangYun
Unite Seoul 2017 Yi SangYun
 
Display color와 Digital texture format의 이해
Display color와 Digital texture format의 이해Display color와 Digital texture format의 이해
Display color와 Digital texture format의 이해
 
Igc2016 Technical Artist가 뭐하는 사람이에요?
Igc2016 Technical Artist가 뭐하는 사람이에요?Igc2016 Technical Artist가 뭐하는 사람이에요?
Igc2016 Technical Artist가 뭐하는 사람이에요?
 

Similar to Unity Surface Shader for Artist 03

[0326 박민근] deferred shading
[0326 박민근] deferred shading[0326 박민근] deferred shading
[0326 박민근] deferred shadingMinGeun Park
 
[Ndc11 박민근] deferred shading
[Ndc11 박민근] deferred shading[Ndc11 박민근] deferred shading
[Ndc11 박민근] deferred shadingMinGeun Park
 
Modern gpu optimize blog
Modern gpu optimize blogModern gpu optimize blog
Modern gpu optimize blogozlael ozlael
 
NDC11_김성익_슈퍼클래스
NDC11_김성익_슈퍼클래스NDC11_김성익_슈퍼클래스
NDC11_김성익_슈퍼클래스Sungik Kim
 
Deview 2019 눈발자국
Deview 2019 눈발자국Deview 2019 눈발자국
Deview 2019 눈발자국hanbeom Park
 
C Language I
C Language IC Language I
C Language ISuho Kwon
 
이펙트 쉐이더 1강 - Shader 기초 개념
이펙트 쉐이더 1강 - Shader 기초 개념이펙트 쉐이더 1강 - Shader 기초 개념
이펙트 쉐이더 1강 - Shader 기초 개념Jihoo Oh
 
Deferred Shading
Deferred ShadingDeferred Shading
Deferred Shading종빈 오
 
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)Sang Don Kim
 
효과적인 임베디드 디버깅 환경구축
효과적인 임베디드 디버깅 환경구축효과적인 임베디드 디버깅 환경구축
효과적인 임베디드 디버깅 환경구축guest0ad316e
 
Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심흥배 최
 
Tips and experience of DX12 Engine development .
Tips and experience of DX12 Engine development .Tips and experience of DX12 Engine development .
Tips and experience of DX12 Engine development .YEONG-CHEON YOU
 
[0312 조진현] good bye dx9
[0312 조진현] good bye dx9[0312 조진현] good bye dx9
[0312 조진현] good bye dx9진현 조
 
Implements Cascaded Shadow Maps with using Texture Array
Implements Cascaded Shadow Maps with using Texture ArrayImplements Cascaded Shadow Maps with using Texture Array
Implements Cascaded Shadow Maps with using Texture ArrayYEONG-CHEON YOU
 
Reproducible research(2)
Reproducible research(2)Reproducible research(2)
Reproducible research(2)건웅 문
 
Programming skills 1부
Programming skills 1부Programming skills 1부
Programming skills 1부JiHyung Lee
 
gametech 2012 Gladius project
gametech 2012 Gladius projectgametech 2012 Gladius project
gametech 2012 Gladius projectWuwon Yu
 

Similar to Unity Surface Shader for Artist 03 (20)

[0326 박민근] deferred shading
[0326 박민근] deferred shading[0326 박민근] deferred shading
[0326 박민근] deferred shading
 
[Ndc11 박민근] deferred shading
[Ndc11 박민근] deferred shading[Ndc11 박민근] deferred shading
[Ndc11 박민근] deferred shading
 
Modern gpu optimize blog
Modern gpu optimize blogModern gpu optimize blog
Modern gpu optimize blog
 
Modern gpu optimize
Modern gpu optimizeModern gpu optimize
Modern gpu optimize
 
NDC11_김성익_슈퍼클래스
NDC11_김성익_슈퍼클래스NDC11_김성익_슈퍼클래스
NDC11_김성익_슈퍼클래스
 
Deview 2019 눈발자국
Deview 2019 눈발자국Deview 2019 눈발자국
Deview 2019 눈발자국
 
C Language I
C Language IC Language I
C Language I
 
이펙트 쉐이더 1강 - Shader 기초 개념
이펙트 쉐이더 1강 - Shader 기초 개념이펙트 쉐이더 1강 - Shader 기초 개념
이펙트 쉐이더 1강 - Shader 기초 개념
 
Deferred Shading
Deferred ShadingDeferred Shading
Deferred Shading
 
Color Control
Color ControlColor Control
Color Control
 
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
 
효과적인 임베디드 디버깅 환경구축
효과적인 임베디드 디버깅 환경구축효과적인 임베디드 디버깅 환경구축
효과적인 임베디드 디버깅 환경구축
 
Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심Modern C++ 프로그래머를 위한 CPP11/14 핵심
Modern C++ 프로그래머를 위한 CPP11/14 핵심
 
Tips and experience of DX12 Engine development .
Tips and experience of DX12 Engine development .Tips and experience of DX12 Engine development .
Tips and experience of DX12 Engine development .
 
[0312 조진현] good bye dx9
[0312 조진현] good bye dx9[0312 조진현] good bye dx9
[0312 조진현] good bye dx9
 
Shader Driven
Shader DrivenShader Driven
Shader Driven
 
Implements Cascaded Shadow Maps with using Texture Array
Implements Cascaded Shadow Maps with using Texture ArrayImplements Cascaded Shadow Maps with using Texture Array
Implements Cascaded Shadow Maps with using Texture Array
 
Reproducible research(2)
Reproducible research(2)Reproducible research(2)
Reproducible research(2)
 
Programming skills 1부
Programming skills 1부Programming skills 1부
Programming skills 1부
 
gametech 2012 Gladius project
gametech 2012 Gladius projectgametech 2012 Gladius project
gametech 2012 Gladius project
 

More from SangYun Yi

Devtree lightmapping unity5_2_1stday
Devtree lightmapping unity5_2_1stdayDevtree lightmapping unity5_2_1stday
Devtree lightmapping unity5_2_1stdaySangYun Yi
 
Unity3D 엔진을 활용한 게임환경 분석 및 3D 그래픽스 기술 /제작 사례
Unity3D 엔진을 활용한 게임환경 분석 및 3D 그래픽스 기술 /제작 사례Unity3D 엔진을 활용한 게임환경 분석 및 3D 그래픽스 기술 /제작 사례
Unity3D 엔진을 활용한 게임환경 분석 및 3D 그래픽스 기술 /제작 사례SangYun Yi
 
Unite2015 probelight English version
Unite2015 probelight English versionUnite2015 probelight English version
Unite2015 probelight English versionSangYun Yi
 
Unite2015 probelight(150417)
Unite2015 probelight(150417)Unite2015 probelight(150417)
Unite2015 probelight(150417)SangYun Yi
 
Kgc2013 defense technica_converting_이상윤
Kgc2013 defense technica_converting_이상윤Kgc2013 defense technica_converting_이상윤
Kgc2013 defense technica_converting_이상윤SangYun Yi
 

More from SangYun Yi (7)

Devtree lightmapping unity5_2_1stday
Devtree lightmapping unity5_2_1stdayDevtree lightmapping unity5_2_1stday
Devtree lightmapping unity5_2_1stday
 
Unity3D 엔진을 활용한 게임환경 분석 및 3D 그래픽스 기술 /제작 사례
Unity3D 엔진을 활용한 게임환경 분석 및 3D 그래픽스 기술 /제작 사례Unity3D 엔진을 활용한 게임환경 분석 및 3D 그래픽스 기술 /제작 사례
Unity3D 엔진을 활용한 게임환경 분석 및 3D 그래픽스 기술 /제작 사례
 
Unite2015 probelight English version
Unite2015 probelight English versionUnite2015 probelight English version
Unite2015 probelight English version
 
Unite2015 probelight(150417)
Unite2015 probelight(150417)Unite2015 probelight(150417)
Unite2015 probelight(150417)
 
Gametech2015
Gametech2015Gametech2015
Gametech2015
 
Devtree illu
Devtree illuDevtree illu
Devtree illu
 
Kgc2013 defense technica_converting_이상윤
Kgc2013 defense technica_converting_이상윤Kgc2013 defense technica_converting_이상윤
Kgc2013 defense technica_converting_이상윤
 

Unity Surface Shader for Artist 03

  • 1. 03. Lighting과 Shader Compiler 이상윤 http://illu.tistory.com
  • 3. Shader "Study/Terrain4BlendVertexColor" { Properties { _MainTex1(“Base 텍스쳐”, 2D) = “white” {} _MainTex2(“R 텍스쳐”, 2D) = “white” {} _MainTex3(“G 텍스쳐”, 2D) = “white” {} _MainTex4(“B 텍스쳐”, 2D) = “white” {} } SubShader { Tags { "RenderType"="Opaque" } GPROGRAM #pragma surface surf Lambert sampler2D _MainTex1; sampler2D _MainTex2; sampler2D _MainTex3; sampler2D _MainTex4; struct Input { float4 color:COLOR; float2 uv_MainTex1; float2 uv_MainTex2; float2 uv_MainTex3; float2 uv_MainTex4; }; void surf (Input IN, inout SurfaceOutput o) { fixed3 t1 = tex2D(_MainTex1, IN.uv_MainTex1).rgb; fixed3 t2 = tex2D(_MainTex1, IN.uv_MainTex1).rgb; fixed3 t3 = tex2D(_MainTex1, IN.uv_MainTex1).rgb; fixed3 t4 = tex2D(_MainTex1, IN.uv_MainTex1).rgb; fixed3 c1 = lerp( t1, t2, IN.color.r); fixed3 c2 = lerp( c1, t3, IN.color.g); fixed3 c3 = lerp( c2, t4, IN.co.or.b); o.Albedo = c3.rgb; } ENDCG } }
  • 4. Shader "Study/Terrain4BlendMasking" { Properties { _MainTex1(“Base 텍스쳐”, 2D) = “white” {} _MainTex2(“R 텍스쳐”, 2D) = “white” {} _MainTex3(“G 텍스쳐”, 2D) = “white” {} _MainTex4(“B 텍스쳐”, 2D) = “white” {} _BlendTex(“마스킹 텍스쳐”, 2D) = “white” {} } SubShader { Tags { "RenderType"="Opaque" } GPROGRAM #pragma surface surf Lambert sampler2D _MainTex1; sampler2D _MainTex2; sampler2D _MainTex3; sampler2D _MainTex4; sampler2D _BlendTex; struct Input { float2 uv_MainTex1; float2 uv_MainTex2; float2 uv_MainTex3; float2 uv_MainTex4; float2 uv2_BlendTex; }; void surf (Input IN, inout SurfaceOutput o) { fixed3 bl = tex2D(_BlendTex, IN.uv2_BlendTex).rgb; fixed3 t1 = tex2D(_MainTex1, IN.uv_MainTex1).rgb; fixed3 t2 = tex2D(_MainTex1, IN.uv_MainTex1).rgb; fixed3 t3 = tex2D(_MainTex1, IN.uv_MainTex1).rgb; fixed3 t4 = tex2D(_MainTex1, IN.uv_MainTex1).rgb; fixed3 c1 = lerp( t1, t2, bl..r); fixed3 c2 = lerp( c1, t3, bl.g); fixed3 c3 = lerp( c2, t4, bI.b); o.Albedo = c3.rgb; } ENDCG } }
  • 5. Uv scroll tex2D(_MainTex, IN.uv_MainTex); tex2D(_MainTex, float2(IN.uv_MainTex.x + _Time.x, IN.uv_MainTex.y)); http://docs.unity3d.com/462/Documentation/Manual/SL-BuiltinValues.html
  • 6. 흐름의 세기를 조절할수 있는 Shader를 만들어 봅시다. 힌트 : IN.uv_MainTex.x + _Time ????
  • 8. CGPROGRAM #pragma surface surf Lambert Lambert와 BlinnPhong은 Lighing.cginc 파일에 내장되어 있어 선언만 해주면 되지만 직접 만들경우(Custom Lighting) 에는 조명 설계를 해주어야 합니다. half4 Lighting<Name> (SurfaceOutput s, half3 lightDir, half atten) 라이트 모델의 포워드 렌더링 패스에서 사용됩니다 half4 Lighting<Name> (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) 뷰 방향에 의존하고 있는 라이팅 모델의 포워드 렌더링 패스에서 사용됩니다 자세한 내용은 : http://docs.unity3d.com/kr/current/Manual/SL-SurfaceShaderLighting.html
  • 9. fixed4 LightingUnityLambert (SurfaceOutput s, half3 lightDir, half atten) { fixed diff = max (0, dot (s.Normal, light.dir)); fixed4 c; c.rgb = s.Albedo * light.color * diff; c.a = s.Alpha; return c; } Lambert Lighting 공식 dot ( a, b ) : a와 b의 내적 max( a, b ) : a와 b의 최대값
  • 10. 요한 하인리히 람베르트(Johann Heinrich Lambert) : 스위스의 수학자, 물리학자, 천문학자, 철학자 램버시안 반사율 : 관찰자가 바라보는 각도와 관계없이 같은 겉보기 밝기를 갖는다. 이를 난반사가 이루어지는 표면을 묘사하기 위해 램버시안 모델을 사용하게 되는데 이는 표면의 특징을 잘 모를때 램버시안 반사는 적당한 근사치가 될 수 있기 때문이다.
  • 11. half NdotL = dot (s.Normal, lightDir); half diff = NdotL * 0.5 + 0.5; half4 c; c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten); c.a = s.Alpha;
  • 12. Unlit Lighting 공식 fixed4 LightingUnlit (SurfaceOutput s, half3 lightDir, half atten) { return fixed4(s.Albedo, 1); } Unlit : Unlighting을 준말으로 빛을 계산하지 않는 상태로 많이 표기 된다.}
  • 13.
  • 14. UE4 Nod Unlit 설정. Shading Model에서 Unlit를 설정 Shading Model에서 Unlit로 설정하면 Base color 항목이 비활성되며 Emissive color 항목만이 활성화 된다.(ambient source의 영향은 받는 상태)
  • 15. Unlit Diffuse Shader를 작성해 봅니다.
  • 16. noambient option에 따른 밝기 변화 비교 Unlit 경우처럼 빛을 계산하지 않는 상태에 서도 ambient color에 영향을 받는다. Light probe를 사용할 경우 이 옵션을 꺼버 리면 아예 빛계산을 못하고 까맣게 나온다.
  • 17. Compiler code alpha : 알파 블랜딩 타입, 반투명한 셰이더에 사용. alphatest:VariableName : 알파 테스팅 모드, transparent-cutout 셰이더에 사용. Cutoff 값은 변수 이름에 따름 addshadow : 그림자 생성과 수집 패스를 추가. 절차적인 버텍스 애니메이션이 그림자에 영향을 미치도록 커스텀 버텍스 수정 함수와 함께 사용.
  • 18. Surface는 Shader는 전처리된 코드를 적절히 잘 사용할 수 있는 반면 많은 경우의 수에 대하여 Shader가 컴파일 되므로 Compiler 구문에서 막아서 선언해줘야 한다. 반대로 fragment 구조에서는 필요한 경우에 대해서 Shader에서 계산을 해 줘야 한다.
  • 19. Compiler code noambient : 앰비언트 라이팅이나 SH라이트가 적용되지 않게 함 novertexlights : 포워드 렌더링에서 SH나 vertex light가 가동되지 않게 함 nolightmap : 셰이더가 라이트맵을 지원하지 않게 만든다 nodirlightmap : directional lightmap을 지원하지 않게 한다 noforwardadd : 포워드 렌더링 가산 패스를 비활성화한다. 그 결과 셰이더는 하나의 디렉셔널 라이트를 완전히 지원하고, 나머지 라이트는 버텍스 단위 또는 SH 방식으로 처리된다. 셰이더를 가볍게 만든다. approxview : 픽셀이 아니라 버텍스 단위로 단위화된 시선 방향 벡터를 계산한다. 처리가 빨라지지만 카 메라가 오브젝에 근접할 경우 시선방향의 계산이 부정확할 수 있다. >> Unity 5에서 interpolateview로 변경 halfasview : 시선 방향 대신 하프 디렉션 벡터를 라이팅 함수에 전달한다. 하프 디렉션은 벡터는 버텍스 단위로 연산되고 단위화 된다. 빠르지만 정확도가 떨어진다.
  • 20. Unlit alphatest Shader를 만들어 봅시다. Alphatest 0, 1 alpha만 존재. Alphablend 반투명
  • 21. fixed4 LightingUnlit (SurfaceOutput s, half3 lightDir, half atten) { return fixed4(s.Albedo, s.Alpha); } Properties { _AlphaCut (“AlphaCut”, Range(0,1)) = 0.5 } SubShader { Tags {“Queue"=“Transparent” "RenderType"=“Transparent”} CGPROGRAM #pragma surface surf Unlit alphatest:_AlphaCut
  • 22. 512x256 4x1 texture를 animation scroll로 이펙트를 표현해 봅니다. Gif 파일로 애니메이션되는 이미지를 올려주시기 바랍니다.