유니티 기반의 라이트맵 모바일 셰이더분석?
유니티라이트맵 기번 모바일 셰이더는 유니티에서 만들어 주는 라이트 맵 시스템을 따른다.
그래서 인지 솅;더에 라이트 맵을 따로 넣은 프로퍼티가 없다.
대신 셰이더 코드에서 texcoord를 추가하고 매트릭스를 유니티 라이트 맵으로 지정해준다.
패스는 총 3번을 그려서 적용한다.
// Unlit shader. Simplest possible textured shader.
// - SUPPORTS lightmap
// - no lighting
// - no per-material color
Shader "Mobile/Unlit (Supports Lightmap)" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 100
// Non-lightmapped 첫번째 패스는 라이트를 받지않은 기본 텍스쳐만 그리는 패스.
Pass {
Tags { "LightMode" = "Vertex" }
Lighting Off
SetTexture [_MainTex] { combine texture }
}
//pass
// Lightmapped, encoded as dLDR 두번째 패스 라이트맵이 들어 갈수 있는 texcoord를 추가하고 유니티 라이트맵 매트릭스를 적용한다.
//VertexLM: 물체가 조명에 매핑되지 않을 때 Vertex Lit rendering 에서 사용됩니다; lightmap이double-LDR으로 인코딩되는
//플랫폼 (일반적으로 모바일 플랫폼 & 오래된 데스크탑 GPUs).
Pass {
Tags { "LightMode" = "VertexLM" }
Lighting Off
BindChannels {
Bind "Vertex", vertex
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
Bind "texcoord", texcoord1 // main uses 1st uv
}
SetTexture [unity_Lightmap] {
matrix [unity_LightmapMatrix]
combine texture
}
SetTexture [_MainTex] {
combine texture * previous DOUBLE, texture * primary
}
}
//pass
// Lightmapped, encoded as RGBM 세번째 패스는 테그에 VertexLMRGBM를 적용하고
//유니티 라이트 맵에 알파를 적용하고, 최종 결과물에 Quad로 어두어진 맵을 밝게 해준다?(테스트를 안해봐서 ㅎㅎ)
Pass {
Tags { "LightMode" = "VertexLMRGBM" }
Lighting Off
BindChannels {
Bind "Vertex", vertex
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
Bind "texcoord", texcoord1 // main uses 1st uv
}
SetTexture [unity_Lightmap] {
matrix [unity_LightmapMatrix]
combine texture * texture alpha DOUBLE
}
SetTexture [_MainTex] {
combine texture * previous QUAD, texture * primary
}
}
//pass
}
//subshader
}
//shader
'Unity공부 > Unity Fixed Shader 공부' 카테고리의 다른 글
unity fixed shader 로 짜는 shader 공부 6- 염색셰이더 (1) | 2012.07.23 |
---|---|
unity fixed shader 로 짜는 shader 공부 4 - Blend Test (1) | 2012.07.19 |
unity fixed shader 로 짜는 shader 공부 3 - SetTexture Test (0) | 2012.07.18 |
unity fixed shader 로 짜는 shader 공부 2 (0) | 2012.07.17 |
unity fixed shader 로 짜는 shader 공부 1 (0) | 2012.07.16 |