API / core/colorspace
core/colorspace
색 공간. (게임마다 3D 빛 셈을 어느 공간에서 할지 고르는 칸, 유니티 Player Settings 의 Color Space 꼴, 원본 core/graphic/colorspace.js)
- Gamma(기본): 지금까지의 길이다. 색 텍스처를 RGBA 로 올리고 셰이더가 pow(색, 2.2) 근사로 선형으로 바꿔 빛을 셈하고 pow(1 / 2.2) 로 화면 색을 낸다. 바탕색, 틴트, 데칼은 감마를 건 색(sRGB) 그대로 곱하고 섞는다. 이미 나온 게임의 화면이 바뀌지 않는다.
- Linear: 3D 의 정석 길이다. 색 텍스처(바탕색, 빛남, 데칼, 매트캡, 천사 고리, 램프)를 SRGB8_ALPHA8 로 올려 GPU 가 선형으로 풀어 읽고 (거르기와 밉맵이 선형 공간) 넘기는 색(꼭짓점 색, 틴트, 빛남 색, 데칼 색, 바깥선 색)은 sRGB 표준 곡선(IEC 61966-2-1)으로 선형으로 바꿔 곱하고 섞는다. 화면에 낼 때도 같은 곡선으로 sRGB 로 바꾼다. 노멀, 마스크 같은 자료 텍스처는 선형 그대로. (ToonTextureOptions 의 is_color_data: false)
- 게임은 EngineConfiguration::color_space 로 한 번 고른다. 툰 렌더러, 후처리, 화면 바깥선, GLB 읽기는 따로 주지 않으면 엔진의 값을 따른다. (엔진을 만들지 않았으면 Gamma) 고른 값은 짓는 때 정해지고 그 뒤에 바뀌지 않는다. (프로그램과 텍스처 형식이 갈리므로)
- 2D(Graphic 의 2D 묶음, 글자, UI)는 어느 값이든 지금처럼 감마 공간(sRGB 값 그대로)에서 섞고 합성한다. 이 칸은 3D(툰) 길만 가른다.
- 셰이더: Linear 면 엔진이 짓는 3D 셰이더의 #version 다음 줄에 #define VANILLA_COLOR_SPACE_LINEAR 1 이 들어간다. 머티리얼 조각은 #ifdef VANILLA_COLOR_SPACE_LINEAR 로 가를 수 있다. (유니티 셰이더의 UNITY_COLORSPACE_GAMMA 와 같은 쓰임)
- 데스크탑 GL 은 기본 프레임버퍼에 GL_FRAMEBUFFER_SRGB 를 켜지 않는다. (셰이더가 곡선을 직접 걸므로 켜면 두 번 걸린다, 웹 캔버스와 같음)
Color space. (the setting that picks which space each game computes 3D light in, in the style of Color Space in Unity Player Settings, original core/graphic/colorspace.js)
- Gamma (default): the path so far. Color textures are uploaded as RGBA, the shader converts them to linear with the pow(color, 2.2) approximation to compute light, and pow(1 / 2.2) produces the screen color. Base color, tint and decal are multiplied and mixed as gamma-encoded colors (sRGB). The screens of games already released do not change.
- Linear: the standard 3D path. Color textures (base color, emission, decal, matcap, angel ring, ramp) are uploaded as SRGB8_ALPHA8 so the GPU decodes them to linear when reading (filtering and mipmaps in linear space), and passed colors (vertex color, tint, emissive color, decal color, outline color) are converted to linear with the standard sRGB curve (IEC 61966-2-1) before they are multiplied and mixed. The screen output uses the same curve back to sRGB. Data textures such as normals and masks stay linear. (is_color_data: false in ToonTextureOptions)
- A game picks it once with EngineConfiguration::color_space. The toon renderer, post process, screen outline and GLB readers follow the engine's value unless given one. (Gamma when no engine was created) The chosen value is fixed at creation and does not change afterwards. (programs and texture formats depend on it)
- 2D (Graphic's 2D batches, text, UI) is mixed and composited in gamma space (sRGB values as they are) either way, as before. This setting only splits the 3D (toon) path.
- Shaders: with Linear, #define VANILLA_COLOR_SPACE_LINEAR 1 is put on the line after #version of the 3D shaders the engine builds. Material chunks can branch with #ifdef VANILLA_COLOR_SPACE_LINEAR. (the same use as UNITY_COLORSPACE_GAMMA in Unity shaders)
- Desktop GL does not enable GL_FRAMEBUFFER_SRGB on the default framebuffer. (the shaders apply the curve themselves, so enabling it would apply it twice, the same as the web canvas)
예제Example선형 색 공간 게임의 엔진 설정과 그 엔진이 짓는 툰 렌더러Engine configuration of a linear color space game and a toon renderer that engine builds
use vanilla::{ColorSpace, Engine, EngineConfiguration, ToonRenderer};
let mut engine_configuration = EngineConfiguration::new();
engine_configuration.color_space = ColorSpace::Linear;
let engine = Engine::new(engine_configuration);
if let Some(graphic) = engine.get_graphic() {
let renderer = ToonRenderer::new(graphic.get_gl()).unwrap();
assert_eq!(renderer.get_color_space(), ColorSpace::Linear);
}ColorSpaceenum traits Clone, Copy, Debug, Default, PartialEq, Eq, Hash
색 공간 종류. (원본 ColorSpace)
Color space kind. (original ColorSpace)
예제Example선형 색 공간으로 엔진 설정 짓기Build an engine configuration with the linear color space
use vanilla::{ColorSpace, EngineConfiguration};
let mut engine_configuration = EngineConfiguration::new();
assert_eq!(engine_configuration.color_space, ColorSpace::Gamma);
engine_configuration.color_space = ColorSpace::Linear;
assert_eq!(engine_configuration.color_space, ColorSpace::Linear);| 이름Name | 설명Description |
|---|---|
Gamma | 감마 공간. (기본, 지금까지의 화면, pow 2.2 근사)Gamma space. (default, the screen so far, pow 2.2 approximation) |
Linear | 선형 공간. (sRGB 텍스처, sRGB 표준 곡선, 3D 의 정석)Linear space. (sRGB textures, the standard sRGB curve, the standard for 3D) |