씬에서 스카이박스를 반사 소스로 사용하는 경우(조명 창 참조), 스카이박스 데이터를 포함하는 ‘기본’ 반사 프로브가 생성됩니다. 반사 프로브는 내부적으로는 큐브맵 텍스처입니다. 이를 살펴보기 위해 위의 월드-공간 노멀 셰이더를 확장해 보겠습니다.
이제는 코드가 좀 더 복잡해지기 시작했습니다. 물론 광원, 그림자, 반사, 그리고 조명 시스템의 나머지 요소와 함께 자동으로 동작하는 셰이더를 원한다면 표면 셰이더를 사용하는 편이 훨씬 쉽습니다. 이 예시는 조명 시스템의 일부를 ‘수동’ 방식으로 사용하는 방법을 보여주기 위한 것입니다.
Shader "Unlit/SkyReflection"
{
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
half3 worldRefl : TEXCOORD0;
float4 pos : SV_POSITION;
};
v2f vert (float4 vertex : POSITION, float3 normal : NORMAL)
{
v2f o;
o.pos = UnityObjectToClipPos(vertex);
// compute world space position of the vertex
float3 worldPos = mul(_Object2World, vertex).xyz;
// compute world space view direction
float3 worldViewDir = normalize(UnityWorldSpaceViewDir(worldPos));
// world space normal
float3 worldNormal = UnityObjectToWorldNormal(normal);
// world space reflection vector
o.worldRefl = reflect(-worldViewDir, worldNormal);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the default reflection cubemap, using the reflection vector
half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.worldRefl);
// decode cubemap data into actual color
half3 skyColor = DecodeHDR (skyData, unity_SpecCube0_HDR);
// output it!
fixed4 c = 0;
c.rgb = skyColor;
return c;
}
ENDCG
}
}
}
위 예제는 빌트인 셰이더 첨부 파일의 여러 가지를 요소를 사용합니다.