본문 바로가기

그래픽스

[그래픽스] Height Map

Normal Map을 통해 빛에 따라 텍스쳐가 더 사실적으로 표현할 수 있었는데

Height Map을 이용하면 Vertex 자체에 굴곡을 넣을 수 있다.

 

        float height = g_heightTexture.SampleLevel(g_sampler, input.texcoord, 0).r;
        height = height * 2.0 - 1.0;
        pos += float4(output.normalWorld * height * heightScale, 0.0);

 

Vertex Shader에서 SampleLevel로 HeightMap의 r값을 가져오면(흑백 텍스쳐이기 때문에 rgb 어떤 값도 가능)

height를 구할 수 있다. NormalMap처럼 0~1 범위를 -1~1범위로 바꿔주고 정점의 위치를 normalWorld 방향으로

height만큼 더해주면 된다.