unity surface shader for artist 04

15
04. Custom effect 이상윤 http://illu.tistory.com

Upload: sangyun-yi

Post on 15-Apr-2017

149 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Unity Surface Shader for Artist 04

04. Custom effect

이상윤 http://illu.tistory.com

Page 2: Unity Surface Shader for Artist 04

3주차 과제 확인

Page 3: Unity Surface Shader for Artist 04

Shader "Study/Fire" {

Properties {

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

}

SubShader {

Tags {"Queue" = "Transparent" "RenderType"="Transparent" }

LOD 200Blend One One

CGPROGRAM

#pragma surface surf Unlit alpha

fixed4 LightingUnlit (SurfaceOutput s, half3 lightDir, half atten){

return fixed4(s.Albedo, s.Alpha);

}

sampler2D _MainTex;

struct Input {

float2 uv_MainTex;

};

void surf (Input IN, inout SurfaceOutput o) {

fixed4 c = tex2D(_MainTex, float2(IN.uv_MainTex.x * 0.25 + (0.25 * ceil(_Time.z * 2)) , IN.uv_MainTex.y));

//ceil(x) : x이상의 최소 정수

o.Albedo = c.rgb;

o.Alpha = c.r;

}ENDCG

}

}

Page 4: Unity Surface Shader for Artist 04

Rim Light

Page 5: Unity Surface Shader for Artist 04

Fresnel Effect

우리가 물체가 인식하는 현상은 빛이 매질에 반사되어 시신경에 맺히는 과정을 거쳐 인식하게 됩니다.

이를 물체의 표면에 빛이 반사하는 모델을 BRDF(Bidirectional

reflectance distribution function) 양방향 반사 분포 함수라고

합니다.

물체와 면이 수직으로 이룰때는 면의 내부가 잘 들여다보이지만 면의 내부와 이루는 각이 커질수록 내부가 보이는

것이 아닌 입사각의 빛의 많이 반사하게 된다.

Page 6: Unity Surface Shader for Artist 04

모든 물체는 프레넬을 가진다.

NDC2013 김동석 – UDK3로 물리기반 셰이더 구현하기

Page 7: Unity Surface Shader for Artist 04

Rim light

실제 프레넬 계산을 좀 더 가볍게 구현한

것이 Rim light 방식입니다.

Rim light의 효용.

객체와 배경을 분리시켜준다.

분위기를 더하는 효과

광원의 연출을 빛이 없이 가능

Page 8: Unity Surface Shader for Artist 04
Page 9: Unity Surface Shader for Artist 04

Fresnel effect

struct Input {

float2 uv_MainTex;

float3 viewDir;float3 worldNormal;

};

void surf (Input IN, inout SurfaceOutput o) {

float rim = dot(normalize(IN.viewDir), normalize(IN.worldNormal));

fixed3 c = tex2D(_MainTex, IN.uv_MainTex);

o.Albedo = c * _Color;

o.Emission = rim;

}ENDCG}

}

Page 10: Unity Surface Shader for Artist 04

struct Input {

float2 uv_MainTex;

float3 viewDir;float3 worldNormal;

};

void surf (Input IN, inout SurfaceOutput o) {

float rim = dot(normalize(IN.viewDir), normalize(IN.worldNormal));

fixed3 c = tex2D(_MainTex, IN.uv_MainTex);

o.Albedo = c * _Color;

o.Emission = 1 - rim;

}ENDCG}

}

Page 11: Unity Surface Shader for Artist 04

Half rim = 1.0 – saturate(dot(normalize(IN.viewDir), o.Normal);pow = pow(rim, a)

normalize : 벡터의 크기를 1로 만든다. 정규화라고도

하며 벡터의 방향은 그대로 유지한채 크기만 0~1 사

이로 변경하는 것.

Saturate(x) : x를 0, 1 범위로 절삭한다.(0보다 적으면

0으로 1보다 크면 1로 반환한다)

pow (a, b) : a^b. a의 b 제곱.

Page 12: Unity Surface Shader for Artist 04

기왕에 만든거 color와 세기도 조절해 봅시다.

Rim Intensity

Rim Color

Page 13: Unity Surface Shader for Artist 04

Compiler code의 halfasview의 기능에 대해서도 확인해봅시다

Page 14: Unity Surface Shader for Artist 04

하는김에 반투명도 그려봅시다.

Cull option 도 제어해봅니다.

Cull off : 앞뒷면을 다 그림

Cull front : 앞면 안그림

Cull back : 뒷면 안그림

2 side라고 이야기하는 면을 앞뒤로 그리는 명령입니다.

당연히 폴리곤도 X2 배~!!

Page 15: Unity Surface Shader for Artist 04

수고하셨습니다.