PBR Lighting
카테고리: Metal
Main Reference
- Metal by Tutorials - 4th edition
Binding LightBuffer
struct Light {
LightType type;
vector_float3 position;
vector_float3 color;
vector_float3 specularColor;
float radius;
vector_float3 attenuation;
float coneAngle;
vector_float3 coneDirection;
float coneAttenuation;
}
var lights: [Light] = []
renderEncoder.setFragmentBytes(
&lights,
length: MemoryLayout<Light>.stride * lights.count,
index: LightBuffer.index)
- Buffer로 넘겨주는 것도 가능하지만 대략 256개 정도는
SetFragmentBytes로 바인딩 가능 - 다만 lights.count를 따로 바인딩해야 사용할 수 있음
Phong Reflection Model
float3 diffuseColor = 0;
float3 ambientColor = 0;
float3 specularColor = 0;
for (uint i = 0; i < params.lightCount; i++) {
Light light = lights[i];
switch (light.type) {
case Directional: {
// ...
break;
}
case Point: {
// ...
break;
}
case Spot: {
// ...
break;
}
}
}
return diffuseColor + specularColor + ambientColor;
- Diffuse : 이론적으로는 surface에 정반사되어야 하는데, 실제 미세 표면들은 rough
- 모든 방향으로 반사하게되고, diffuse color를 생성
- Called Lambertian Reflectance
- Specular : 빛의 정반사 factor. 표면이 매끄러울 수록 더 반짝임(정반사>난반사).
- Ambient : 실제 세상에서 그림자 영역이 완전히 검은색인 경우는 드뭄(주변광 효과).
- 최종 color는 (Diffuse + Specular + Ambient) + Emissive
Surface Normal
float4 worldPosition = uniforms.modelMatrix * in.position;
uniforms.normalMatrix = uniforms.modelMatrix.upperLeft
.worldPosition = worldPosition.xyz / worldPosition.w
.worldNormal = uniforms.normalMatrix * in.normal
표면의 normal을 이용해 Lighting 연산을 하므로 World Space기준 Normal Vector의 정보가 필요하다. 일반적으로 vertex function에서 같이 계산하며, normal Matrix는 model Matrix의 3x3으로 충분하다. 왜냐하면 world normal만 필요하므로 projection을 계산할 필요가 없고, translation은 normal에 영향을 미치지 않기 때문이다.
Physically Based Rendering (PBR)
Bidirectional Reflectance Distribution Function (BRDF)
: defines how a surface responds to light

- f(l, v) = f(v, l) 에너지 보존 법칙 성립 (blinn phong은 만족 x)
- (l : light vector & v : view vector)
- Diffuse Term + Specular Term
- BRDF은 다양한 모델이 있으나 대부분 diffuse는 Lambertian, specular는 cook-torrance 모델 사용
- Specular
- D (Normal Distribution) : noram 방향과 일치하는 micro-facet 비율
- F (Fresnel) : normal과의 각도에 따라 바뀌는 반사율 반영
- G (Geometry) : 울퉁불퉁한 표면에 의한 self-shadowing 성질 반영
Rendering Equation

PBR Texture
| Simple Texture | PBR Texture |
|---|---|
![]() |
![]() |


Roughness: A grayscale value that indicates the shininess of a surface.- White is rough, and black is smooth.
Metallic: A surface is either a conductor of electricity.- Most metallic textures consist of 0(black) and 1(white).
- 0 for dielectirc and 1 for metal.
- 금, 은, 철과 같은 metalic 물질은 빛을 흡수하지 않고 표면에서 거의 모든 빛을 즉시 반사(diffuse x)
Ambient Occlusion(AO): A grayscale value that defines how much light reaches a surface- 3D 모델의 구석이나 틈새처럼 주변광(ambient light)이 닿기 어려운 부분에 부드러운 그림자를 추가하여 깊이감과 사실감을 더해주는 흑백 이미지 맵.
Reality Composer Pro

You can load in USD files and create a scene, and then export that scene out to a new USD file. Xcode > Open Developer Tool > Reality Composer Pro.


댓글 남기기