콩알라
코딩 조아
콩알라
전체 방문자
오늘
어제
  • 전체 (37)
    • 유니티 (20)
      • 꿀팁 (3)
      • 꿀팁ㅇㅇㅇ (16)
      • 클라우드 빌드 (0)
      • iOS (1)
    • 언리얼 (0)
    • 공부 (4)
      • 알고리즘 (1)
      • Effect (0)
      • Shader (2)
      • DirectX (1)
    • 일상 (1)
      • ? (1)
    • 주식 공부 (1)

블로그 메뉴

  • 방명록
  • ADMIN
  • WRITE

공지사항

인기 글

태그

  • 3DS MAX 폴리곤 줄이기
  • Maya 폴리곤 수 줄이기
  • 내일채움공제
  • 마야 폴리곤 수 줄이기
  • 만기금 수령
  • 맥스 폴리곤 수 줄이기
  • 모델 폴리곤 수 줄이기
  • 모델 폴리곤 줄이기
  • 실업급여
  • 유니티

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
콩알라

코딩 조아

공부/Shader

연습

2018. 5. 19. 19:16

Shader "Shader/Toon Rim Light"


Property

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

_BumpMap ("BumpMap", 2D) = "bump" {} //노멀맵 텍스쳐


Tags { "RenderType"="Opaque" }

LOD 300 //노멀맵을 적용하려면 LOD가 300


CGPROGRAM

#pragma surface surf Lambert


sampler2D _MainTex;

sampler2D _BumpMap;


struct Input {

float2 uv_MainTex;

float2 uv_BumpMap; //_BumpMap으로부터 색상 정보를 읽어오기 위함

};


void surf (Input IN, inout SurfaceOutput o) { //Input 구조체의 정보를 가져와 처리, 결과를 SurfaceOutput 구조체로 내보낸다.

half4 c = tex2D (_MainTex, IN.uv_MainTex); //샘플 스테이트와 텍스쳐 좌표로부터 정보 받아서 색상 정보 반환, 반환된 값은 알베도와 알파에 지정

o.Albedo = c.rgb; //색상 정보 저장

o.Alpha = c.a; //알파 정보 저장

o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));

//샘플 스테이트와 텍스처 좌표로부터 색상 정보를 얻어오기 위해 tex2D 함수 사용

//UnpackNormal 함수를 사용해 tex2D의 결과로부터 노멀을 읽어옴

}




//2

Property

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

_BumpMap ("BumpMap", 2D) = "bump" {} //노멀맵 텍스쳐

_AmbientColor ("Anbient Color", Color) = (0.1, 0.1, 0.1, 1.0)

_SpecularColor ("Specular Color", Color) = (0.12, 0.31, 0.47, 1.0)

_Glossiness ("Gloss", Range(1.0, 512.0)) = 80.0


SubShader {

Tags { "RenderType" = "Opaque" }

LOD 400 


CGPROGRAM


#pragma surface surf RampSpecular


sampler2D _MainTex;

sampler2D _BumpMap;


fixed4 _AmbientColor;

fixed4 _SpecularColor;

half _Glossiness;


struct Input {

float2 uv_MainTex;

float2 uv_BumpMap;

};


void Surf (Input IN, inout SurfaceOutput o) {

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

o.Albedo = c.rgb;

o.Alpha = c.a;

o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));

}


inline fixed4 LightingRampSpecular (SurfaceOutput s, fixed3 lightDir, fixed3 viewDir, fixed atten) {

fixed3 ambient = s.Albedo * _AmbientColor.rgb; //앰비언트 라이트

fixed NdotL = saturate(dot (s.Normal, lightDir); //디퓨즈

fixed3 diffuse = s.Albedo * _LightColor0.rgb * NdotL; //캐릭터 노멀을 기준으로 광원 방향 구한다

fixed3 h = normalize (lightDIr + viewDir); //라이트 노멀과 시선 방향

float nh = saturate(dot (s.Normal, h))

float specPower = pow (nh, _Glossiness);

fixed3 specular = _LightColor0.rgb * specPower * _SpecularColor.rgb;


//결과

fixed4 c;

c.rgb = (ambient + diffuse + specular) * (atten * 2);

c.a = s.Alpha + (_LightColor.a * _SpecularColor.a * specPower * atten);

return c;


}

ENDCG

}

'공부 > Shader' 카테고리의 다른 글

Study #1  (0) 2017.08.08
    '공부/Shader' 카테고리의 다른 글
    • Study #1
    콩알라
    콩알라
    게임 개발자

    티스토리툴바