vanilladocs
vanillapunch.com
API / graphics3d/toon/toonpostprocess

graphics3d/toon/toonpostprocess

툰 HDR 마무리. (vanilla.js graphics3d/toon/toonpostprocess.js 의 ToonPostProcess)

  • 실수 렌더 타겟에 그린 선형 색을 블룸, 노출, 톤매핑, 감마로 화면에 낸다.
  • 엔진의 RenderTarget(반정밀 실수 색, 깊이), BloomEffect(또는 MultiLevelBloomEffect), FullscreenPass 를 엮는다.
  • 사용: ToonRenderer::set_hdr_output(true) 뒤 begin(gl, 바탕 선형 색) → ToonRenderer 로 그리기 → end(gl, 낼 프레임버퍼, 뷰포트) end 는 (멀티샘플이면 풀고) 블룸을 셈하고 톤매핑한 색을 낼 프레임버퍼(None 이면 화면)에 그린다. 2D 와 섞으려면 그 뒤 Graphic::restore_render_state.
  • 생성 옵션: new_with_options(gl, 너비, 높이, ToonPostProcessOptions { sample_count, use_float_color, depth_bits, use_depth_texture, color_space }) (원본 생성자의 options, new 는 기본 옵션으로 지금과 같은 RGBA16F, 깊이 16, 멀티샘플 없음) sample_count 가 2 이상이면 씬을 멀티샘플(MSAA) 렌더버퍼에 그리고 end 앞에서 텍스처로 푼다. 기기가 받는 수로 줄인다. (get_sample_count, set_sample_count) depth_bits 24 는 깊이 24 비트. (먼 면이 먼 장면) use_depth_texture 는 씬 깊이를 텍스처로 남긴다. (set_lit_area 가 쓴다)
  • 색 공간: 씬 렌더 타겟에는 선형 색을 쓴다. (ToonRenderer::set_hdr_output(true), ToonScreenOutline::set_hdr_output(true), ToonVfx 색도 선형으로 본다) 감마를 건 색 g 를 실수 판에 쓰고 합성에서 g^2.2 로 되돌리던 게임은 그 값을 미리 선형으로 바꿔 넘긴다. 색은 c^2.2, 감마 쪽에서 곱하던 밝기 배 k 는 선형 k^2.2 다. (예: 1.37 은 선형 2, 1.6 은 2.81, 2.08 은 5, 밝기 1.6 에 배 1.6 이면 (1.6 x 1.6)^2.2 = 7.9) 블룸 문턱과 무릎은 선형 밝기다. 이 예는 감마 쪽(감마를 건 색 g)에서 곱하던 배일 때만 맞다. 선형 색에 곱하던 배와 블룸 문턱, 무릎처럼 처음부터 선형인 값은 바꾸지 않고 그대로 넘긴다.
  • 실수 판을 못 쓰는 기기: use_float_color(기본 true)여도 is_float_color_supported 가 false 면 RGBA8 판으로 짓는다. (get_use_float_color 가 false) 그때와 use_float_color: false 는 LDR 길이다. 씬에는 화면 색(감마를 건 색, ToonRenderer::set_hdr_output(false))을 그리고, 합성은 톤매핑과 감마 없이 블룸을 더해 색 보정만 건다.
  • 캔버스 antialias: 이 후처리가 자기 MSAA 판(sample_count)에 그리므로 쓰는 게임은 EngineConfiguration::antialias 를 false 로 짓는다. true 면 캔버스 자체가 MSAA 라 화면에 옮기는 패스와 UI 가 표본마다 섞여 값이 더 든다. (맥미니 2560x1440 툰 후처리 장면 GPU 처리량 6.89 → 6.49 ms, 끈 판 6.81 → 5.22 ms, 원본 같은 장면에서 잰 값) 예: engine_configuration.antialias = false;
  • 블룸: 기본은 반 해상도 9 탭 가우시안(BloomEffect, 문턱 0.9 ~ 1.6, 주고받는 판 RGBA8, set_bloom_float_color 로 RGBA16F). set_bloom_levels(gl, 단 수, 문턱, 무릎) 로 단 수를 1 이상 주면 MultiLevelBloomEffect(반씩 줄였다 천막 꼴로 키우며 더함, 씬과 같은 정밀도의 판)로 바꾼다. 0 이면 기본으로 돌린다. 세기는 set_bloom 이 둘 다에 쓴다.
  • 톤매핑은 ACES 근사(Krzysztof Narkowicz 2016, 원문이 CC0 또는 MIT 로 쓰게 함)다. 노출(set_exposure)을 곱한 뒤 매핑하고 sRGB 감마를 건다.
  • 색 보정: 감마를 건 뒤 밝기(set_brightness, 밝힌 자리 set_lit_area 안은 1 쪽으로), 채도, 색조(밝기 1 로 맞춘 색을 곱함), 안개빛(어두운 곳을 그 색 쪽으로), 대비, 가장자리 어둡게 차례로 건다. (set_color_grade, set_vignette) 기본은 밝기 1, 채도 1, 대비 1, 색조 0, 안개빛 0, 가장자리 0 이라 보정이 없다.
  • 해상도 배율: set_resolution_scale(gl, 배율) 이면 씬 판을 출력 크기 x 배율로 짓고 end 의 뷰포트로 키워(선형 거르기) 낸다. (3D 만 낮춰 그리고 UI 는 기기 화소 그대로 둘 때, 기본 1)
  • 노드 사각형 안에 낼 때: resize(사각형 너비, 높이) → begin → 그리기(ToonRenderer 의 화면 사각형은 풀어 둔다) → end(None, [x, 드로잉 버퍼 높이 - y - 높이, 너비, 높이]).
  • 색 공간: 톤매핑 뒤 화면 색의 곡선은 감마 색 공간(기본)은 pow(1 / 2.2), 선형 색 공간(options.color_space 나 엔진의 ColorSpace::Linear)은 sRGB 표준 곡선(IEC 61966-2-1)이다. (ToonRenderer 의 LDR 출력과 같은 곡선)
  • 모서리 어둠(화면 공간 AO): set_ambient_occlusion(켬, 세기, 반지름, 해상도 배율, 직접 빛 몫) 로 켠다. (기본 꺼짐, 세기 0.5, 반지름 0.5 월드 길이, 반 해상도, 직접 빛 몫 0) 반 해상도 GTAO(Jimenez 2016) → 가로 흐림 → 세로 흐림과 온 해상도로 키우기, 세 패스다. 흐림은 깊이와 노멀로 가장자리를 지킨다. 노멀과 깊이는 화면 바깥선(ToonScreenOutline)의 선의 판을 다시 쓴다. 바깥선이 없는 장면은 선은 긋지 않고 선의 판만 그리는 get_ambient_occlusion_prepass() 를 쓴다. ToonDrawQueue::set_post_process(이것) 이면 줄이 선의 판 뒤, 몸 앞에 draw_ambient_occlusion 을 부르고 렌더러에 결과를 건다. 몸 셰이더는 바탕빛(하늘과 땅 빛)에 곱하고, 직접 빛 몫만큼 해, 채움빛, 점광의 확산과 반사광에도 곱한다. (칸을 고른 뒤라 칸 경계는 그대로, 몫 0 이면 바탕빛에만)
  • 원본과 다른 점: GL 객체를 다시 짓는 설정(set_sample_count, set_resolution_scale, set_bloom_levels, set_bloom_float_color)은 gl 을 받고 Result 를 돌려준다.

Toon HDR finishing. (ToonPostProcess of vanilla.js graphics3d/toon/toonpostprocess.js)

  • Outputs linear color drawn to a float render target to the screen with bloom, exposure, tone mapping and gamma.
  • Combines the engine's RenderTarget (half-float color, depth), BloomEffect (or MultiLevelBloomEffect) and FullscreenPass.
  • Usage: after ToonRenderer::set_hdr_output(true) begin(gl, background linear color) → draw with ToonRenderer → end(gl, output framebuffer, viewport) end (resolves first if multisampled) computes bloom and draws the tone-mapped color into the output framebuffer (screen if None). To mix with 2D, call Graphic::restore_render_state after it.
  • Constructor options: new_with_options(gl, width, height, ToonPostProcessOptions { sample_count, use_float_color, depth_bits, use_depth_texture }) (the options of the original constructor, new uses the default options, same as now: RGBA16F, depth 16, no multisampling) If sample_count is 2 or more, the scene is drawn to a multisampled (MSAA) renderbuffer and resolved to a texture before end. Reduced to a count the device supports. (get_sample_count, set_sample_count) depth_bits 24 means 24-bit depth. (scenes with a distant far plane) use_depth_texture keeps the scene depth as a texture. (used by set_lit_area)
  • Color space: linear color is written to the scene render target. (ToonRenderer::set_hdr_output(true), ToonScreenOutline::set_hdr_output(true), ToonVfx colors are also treated as linear) Games that wrote gamma-encoded color g to the float target and converted back with g^2.2 in compositing should convert those values to linear beforehand. Colors become c^2.2, and a brightness multiplier k applied on the gamma side becomes linear k^2.2. (e.g. 1.37 is linear 2, 1.6 is 2.81, 2.08 is 5, brightness 1.6 with multiplier 1.6 gives (1.6 x 1.6)^2.2 = 7.9) Bloom threshold and knee are linear brightness.
  • Devices that cannot use float targets: even with use_float_color (default true), if is_float_color_supported is false, RGBA8 targets are built. (get_use_float_color is false) That case and use_float_color: false take the LDR path. The scene is drawn in screen color (gamma-encoded color, ToonRenderer::set_hdr_output(false)), and compositing adds bloom without tone mapping and gamma and applies only color grading.
  • Canvas antialias: because this post process draws into its own MSAA target (sample_count), a game that uses it builds with EngineConfiguration::antialias set to false. With true, the canvas itself is MSAA, so the pass that copies to the screen and the UI blend per sample and cost more. (Mac mini, 2560x1440 toon post process scene, GPU throughput 6.89 → 6.49 ms, with it off 6.81 → 5.22 ms, measured on the same scene in the original) Example: engine_configuration.antialias = false;
  • Bloom: default is a half-resolution 9-tap Gaussian (BloomEffect, threshold 0.9 ~ 1.6, ping-pong targets RGBA8, RGBA16F with set_bloom_float_color). Giving set_bloom_levels(gl, level count, threshold, knee) a level count of 1 or more switches to MultiLevelBloomEffect (halves down then scales up with a tent filter while adding, targets at the same precision as the scene). 0 restores the default. Strength is applied to both by set_bloom.
  • Tone mapping is the ACES approximation (Narkowicz). Exposure (set_exposure) is multiplied in before mapping, then sRGB gamma is applied.
  • Color grading: after gamma, applies in order brightness (set_brightness, toward 1 inside the lit area set_lit_area), saturation, color tone (multiplies a color normalized to brightness 1), fog light (pulls dark areas toward that color), contrast, edge darkening. (set_color_grade, set_vignette) Defaults are brightness 1, saturation 1, contrast 1, color tone 0, fog light 0, edge 0, so there is no grading.
  • Resolution scale: with set_resolution_scale(gl, scale), the scene target is built at output size x scale and scaled up to end's viewport (linear filtering) for output. (to render only 3D at a lower resolution while leaving UI at device pixels, default 1)
  • Outputting inside a node rectangle: resize(rectangle width, height) → begin → draw (leave ToonRenderer's screen rectangle cleared) → end(None, [x, drawing buffer height - y - height, width, height]).
  • Differences from the original: settings that rebuild GL objects (set_sample_count, set_resolution_scale, set_bloom_levels, set_bloom_float_color) take gl and return a Result.

ToonPostProcessOptionsstruct traits Clone, Copy, Debug, PartialEq, Eq, Default

소스source

생성 옵션. (원본 생성자의 options, 기본값은 멀티샘플 없음 / 실수 판 / 깊이 16 / 깊이 텍스처 없음)

Constructor options. (the original constructor options, the defaults are no multisampling / float target / depth 16 / no depth texture)

예제Example멀티샘플 넷에 깊이 24 비트 옵션Options with 4 samples and 24-bit depth
use vanilla::ToonPostProcessOptions;

let options = ToonPostProcessOptions { sample_count: 4, depth_bits: 24, ..ToonPostProcessOptions::default() };
assert!(options.use_float_color);
assert!(!options.use_depth_texture);
필드fieldpub sample_count: i32#0.4.0 부터since 0.4.0소스source

멀티샘플 표본 수. (2 밑이면 없음)

Multisample count. (none below 2)

반환Returnsi32

필드fieldpub use_float_color: bool#0.4.0 부터since 0.4.0소스source

실수 판을 쓸지. (기기가 못 쓰면 false 로 짓는다)

Whether to use a float target. (built as false if the device cannot)

반환Returnsbool

필드fieldpub depth_bits: i32#0.4.0 부터since 0.4.0소스source

깊이 렌더버퍼 비트 수. (16 이나 24)

Depth renderbuffer bit count. (16 or 24)

반환Returnsi32

필드fieldpub use_depth_texture: bool#0.4.0 부터since 0.4.0소스source

씬 깊이를 텍스처로 남길지. (set_lit_area)

Whether to keep the scene depth as a texture. (set_lit_area)

반환Returnsbool

필드fieldpub color_space: ColorSpace#0.4.0 부터since 0.4.0소스source

색 공간. (원본 colorSpace, 기본은 엔진의 색 공간, ToonRenderer 와 같은 값)

Color space. (original colorSpace, default is the engine's color space, the same value as the ToonRenderer)

반환ReturnsColorSpace

ToonPostProcessstruct

짝Counterpart: vanilla.js ToonPostProcess소스source

툰 HDR 마무리. (머리말 참고)

Toon HDR post-processing. (see the header comment)

예제Example툰 장면을 실수 판에 그리고 블룸과 톤매핑으로 내기Draw a toon scene into a float target and output it with bloom and tone mapping
use vanilla::{create_sphere_geometry, Camera3D, Matrix4, MeshBuilder, ToonDrawOptions, ToonPartOptions, ToonPostProcess, ToonPostProcessOptions, ToonRenderer, Vector3};

fn draw_glowing_ball(gl: &vanilla::GlContext, width: i32, height: i32) -> Result<(), String> {
	let mut post_process = ToonPostProcess::new_with_options(gl, width, height, ToonPostProcessOptions { sample_count: 4, ..ToonPostProcessOptions::default() })?;
	post_process.set_exposure(1.2);
	post_process.set_bloom(true, 0.8, 0.9, 1.6);
	let mut renderer = ToonRenderer::new(gl)?;
	renderer.set_hdr_output(post_process.get_use_float_color());
	let mut builder = MeshBuilder::new();
	builder.add_part(&create_sphere_geometry(0.5, 32, 20, std::f64::consts::PI), &Matrix4::create_identity(), "#ffd080", ToonPartOptions { glow: 2.0, ..ToonPartOptions::default() });
	let mesh = renderer.create_mesh(gl, &builder.read_arrays()).ok_or("mesh failed")?;
	let mut camera = Camera3D::new();
	camera.set_perspective(0.8, 0.1, 100.0);
	camera.set_aspect_ratio(width as f64 / height as f64);
	camera.look_at(Vector3::create(0.0, 1.0, 3.0), Vector3::create(0.0, 0.0, 0.0), Vector3::create(0.0, 1.0, 0.0));
	post_process.begin(gl, [0.02, 0.02, 0.04]);
	renderer.begin_frame_with_camera(gl, &camera);
	renderer.draw_mesh(gl, &mesh, &Matrix4::create_identity(), ToonDrawOptions::default());
	renderer.end_frame(gl);
	post_process.end(gl, None, [0, 0, width, height]);
	Ok(())
}
생성자constructorpub fn new(gl: &GlContext, width: i32, height: i32) -> Result<ToonPostProcess, String>#0.4.0 부터since 0.4.0소스source

생성. (화면 픽셀 크기, 기본 옵션)

Constructor. (screen pixel size, default options)

gl&GlContext
툰 렌더러와 같은 컨텍스트.The same context as the toon renderer.
widthi32
출력 너비. (픽셀)Output width. (Pixels)
heighti32
출력 높이. (픽셀)Output height. (Pixels)

반환ReturnsResult<ToonPostProcess, String> 새 툰 HDR 마무리. 씬 렌더 타겟, 블룸, 합성 셰이더를 못 지으면 Err(오류 글).New toon HDR finishing. Err(error message) if the scene render target, bloom or composite shader cannot be built.

짝Counterpart: vanilla.js ToonPostProcess.constructor

정적staticpub fn new_with_options(gl: &GlContext, width: i32, height: i32, options: ToonPostProcessOptions) -> Result<ToonPostProcess, String>#0.4.0 부터since 0.4.0소스source

옵션을 주어 생성. (원본 new ToonPostProcess(gl, 너비, 높이, options))

Creates with options. (the original new ToonPostProcess(gl, width, height, options))

gl&GlContext
툰 렌더러와 같은 컨텍스트.The same context as the toon renderer.
widthi32
출력 너비. (픽셀)Output width. (Pixels)
heighti32
출력 높이. (픽셀)Output height. (Pixels)
optionsToonPostProcessOptions
생성 옵션. (멀티샘플 표본 수, 실수 판, 깊이 비트 16 이나 24, 깊이 텍스처, 색 공간)Creation options. (multisample count, float target, depth bits 16 or 24, depth texture, color space)

반환ReturnsResult<ToonPostProcess, String> 새 툰 HDR 마무리. 씬 렌더 타겟, 블룸, 합성 셰이더를 못 지으면 Err(오류 글).New toon HDR finishing. Err(error message) if the scene render target, bloom or composite shader cannot be built.

정적staticpub fn is_float_color_supported(gl: &GlContext) -> bool#0.4.0 부터since 0.4.0소스source

실수 컬러 판을 그릴 수 있는지. (웹은 EXT_color_buffer_float 나 EXT_color_buffer_half_float 가 있어야, 1 x 1 RGBA16F 를 붙인 프레임버퍼가 완성되는지)

Whether a float color buffer can be rendered to. (on the web EXT_color_buffer_float or EXT_color_buffer_half_float is required, and whether a framebuffer with a 1 x 1 RGBA16F attached is complete)

gl&GlContext
알아볼 컨텍스트.Context to check.

반환Returnsbool RGBA16F 판에 그릴 수 있으면 true.true if it can draw into an RGBA16F target.

짝Counterpart: vanilla.js ToonPostProcess.isFloatColorSupported

메서드methodpub fn resize(&mut self, gl: &GlContext, width: i32, height: i32) -> Result<(), String>#0.4.0 부터since 0.4.0소스source

크기 바꾸기. (출력 크기, 씬 판은 해상도 배율을 곱함, 같으면 그대로)

Resizes. (output size, the scene buffer is multiplied by the resolution scale, unchanged if the same)

gl&GlContext
GL 컨텍스트.GL context.
widthi32
출력 너비. (픽셀)Output width. (Pixels)
heighti32
출력 높이. (픽셀)Output height. (Pixels)

반환ReturnsResult<(), String> 판을 맞췄으면 Ok. 다시 짓다 GL 객체를 못 만들면 Err(GL 의 오류 글).Ok if the buffers were fitted. Err(GL error text) if GL objects cannot be made while rebuilding.

짝Counterpart: vanilla.js ToonPostProcess.resize

메서드methodpub fn set_resolution_scale(&mut self, gl: &GlContext, resolution_scale: f64) -> Result<(), String>#0.4.0 부터since 0.4.0소스source

해상도 배율 설정. (씬 판 = 출력 크기 x 배율, 0.05 ~ 4, 기본 1)

Sets the resolution scale. (scene buffer = output size x scale, 0.05 ~ 4, default 1)

gl&GlContext
GL 컨텍스트.GL context.
resolution_scalef64
씬 판의 배율. (0.05 ~ 4)Scale of the scene target. (0.05 ~ 4)

반환ReturnsResult<(), String> 판을 맞췄으면 Ok. 다시 짓다 GL 객체를 못 만들면 Err(GL 의 오류 글).Ok if the buffers were fitted. Err(GL error text) if GL objects cannot be made while rebuilding.

짝Counterpart: vanilla.js ToonPostProcess.setResolutionScale

메서드methodpub fn get_resolution_scale(&self) -> f64#0.4.0 부터since 0.4.0소스source

해상도 배율 반환.

Returns the resolution scale.

반환Returnsf64 씬 판의 배율.Scale of the scene target.

짝Counterpart: vanilla.js ToonPostProcess.getResolutionScale

메서드methodpub fn set_sample_count(&mut self, gl: &GlContext, sample_count: i32) -> Result<(), String>#0.4.0 부터since 0.4.0소스source

멀티샘플 표본 수 설정. (2 밑이면 없음, 바뀌면 씬 판을 다시 짓는다)

Sets the multisample sample count. (none if below 2, rebuilds the scene buffer when changed)

gl&GlContext
GL 컨텍스트.GL context.
sample_counti32
멀티샘플 표본 수. (2 밑이면 멀티샘플 없음)Multisample count. (no multisampling below 2)

반환ReturnsResult<(), String> 같은 수거나 씬 판을 다시 지었으면 Ok. 새 판을 못 지으면 Err(GL 의 오류 글, 앞의 판은 그대로 둔다).Ok if the count is the same or the scene target was rebuilt. Err(GL error text, the previous target is kept) if the new target cannot be built.

짝Counterpart: vanilla.js ToonPostProcess.setSampleCount

메서드methodpub fn get_sample_count(&self) -> i32#0.4.0 부터since 0.4.0소스source

실제로 쓰는 멀티샘플 표본 수 반환. (0 이면 없음)

Returns the multisample sample count actually in use. (0 means none)

반환Returnsi32 씬 판이 실제로 쓰는 표본 수. (기기가 받는 수로 줄인 것, 0 이면 없음)Sample count the scene target actually uses. (Reduced to what the device accepts, 0 means none)

짝Counterpart: vanilla.js ToonPostProcess.getSampleCount

메서드methodpub fn get_use_float_color(&self) -> bool#0.4.0 부터since 0.4.0소스source

씬 판이 실수인지 반환. (false 면 LDR 길)

Returns whether the scene buffer is float. (false means the LDR path)

반환Returnsbool 씬 판이 실수면 true. (ToonRenderer::set_hdr_output 에 그대로 넘긴다)true if the scene target is float. (passed straight to ToonRenderer::set_hdr_output)

짝Counterpart: vanilla.js ToonPostProcess.getUseFloatColor

메서드methodpub fn begin(&self, gl: &GlContext, clear_color: [f64; 3])#0.4.0 부터since 0.4.0소스source

씬 그리기 시작. (씬 렌더 타겟을 묶고 바탕 색과 깊이로 비운다, HDR 길은 선형 색, LDR 길은 화면 색)

Begins drawing the scene. (binds the scene render target and clears it with the background color and depth, linear color on the HDR path, screen color on the LDR path)

gl&GlContext
GL 컨텍스트.GL context.
clear_color[f64; 3]
[r, g, b] 바탕 색. (HDR 길은 선형 색, LDR 길은 화면 색)[r, g, b] background color. (Linear color on the HDR path, screen color on the LDR path)

짝Counterpart: vanilla.js ToonPostProcess.begin

메서드methodpub fn end(&self, gl: &GlContext, output_framebuffer: Option<GlFramebuffer>, viewport: [i32; 4])#0.4.0 부터since 0.4.0소스source

마무리. (멀티샘플이면 풂 → 블룸 → 톤매핑해 낼 프레임버퍼에, viewport 는 [x, y, 너비, 높이])

Finishes. (resolve if multisampled → bloom → tone map into the output framebuffer, viewport is [x, y, width, height])

gl&GlContext
GL 컨텍스트.GL context.
output_framebufferOption<GlFramebuffer>
낼 프레임버퍼. (None 이면 화면)Framebuffer to output to. (screen if None)
viewport[i32; 4]
[x, y, 너비, 높이] 낼 자리. (드로잉 버퍼 픽셀, 왼쪽 아래가 원점)[x, y, width, height] output area. (Drawing buffer pixels, bottom left is the origin)

짝Counterpart: vanilla.js ToonPostProcess.end

메서드methodpub fn set_exposure(&mut self, exposure: f64)#0.4.0 부터since 0.4.0소스source

노출 설정. (톤매핑 전에 곱한다, 1 이 기본)

Sets the exposure. (multiplied before tone mapping, 1 is the default)

exposuref64
노출 배. (0 이상, 1 이 기본)Exposure multiplier. (0 or more, 1 is the default)

짝Counterpart: vanilla.js ToonPostProcess.setExposure

메서드methodpub fn set_bloom(&mut self, is_bloom_enabled: bool, bloom_strength: f64, threshold_start: f64, threshold_end: f64)#0.4.0 부터since 0.4.0소스source

블룸 설정. (켜기, 세기, 밝은 곳을 뽑는 문턱의 시작과 끝, 문턱은 기본 9 탭 블룸에만 쓴다)

Sets the bloom. (enabled, intensity, start and end of the threshold that extracts bright areas, the threshold is used only by the default 9-tap bloom)

is_bloom_enabledbool
블룸을 켤지.Whether to turn on bloom.
bloom_strengthf64
블룸 세기. (씬 색에 더하는 배, 기본 0.6)Bloom strength. (Multiplier added to the scene color, default 0.6)
threshold_startf64
밝은 곳을 뽑기 시작하는 선형 밝기. (기본 0.9)Linear brightness where bright areas start to be extracted. (Default 0.9)
threshold_endf64
다 뽑는 선형 밝기. (기본 1.6)Linear brightness where they are fully extracted. (Default 1.6)

짝Counterpart: vanilla.js ToonPostProcess.setBloom

메서드methodpub fn set_bloom_levels(&mut self, gl: &GlContext, level_count: usize, threshold: f64, knee: f64) -> Result<(), String>#0.4.0 부터since 0.4.0소스source

블룸 단 수 설정. (0 이면 기본 9 탭 블룸, 1 이상이면 그 단 수의 다단 블룸, 문턱과 무릎은 다단 블룸의 선형 밝기)

  • 다단 블룸 판은 씬 판과 같은 정밀도다. (HDR 길은 RGBA16F)

Sets the number of bloom levels. (0 means the default 9-tap bloom, 1 or more means a multi-level bloom with that many levels, threshold and knee are the linear brightness of the multi-level bloom)

  • The multi-level bloom buffers have the same precision as the scene buffer. (RGBA16F on the HDR path)
gl&GlContext
GL 컨텍스트.GL context.
level_countusize
단 수. (0 이면 기본 9 탭 블룸으로 돌린다)Number of levels. (0 returns to the default 9-tap bloom)
thresholdf64
다단 블룸의 문턱. (선형 밝기)Threshold of the multi-level bloom. (Linear brightness)
kneef64
문턱 둘레를 부드럽게 넘기는 폭. (선형 밝기)Width for passing the threshold softly. (Linear brightness)

반환ReturnsResult<(), String> 바꿨으면 Ok. 다단 블룸의 셰이더나 판을 못 지으면 Err(오류 글).Ok if changed. Err(error message) if the multi-level bloom shader or targets cannot be built.

짝Counterpart: vanilla.js ToonPostProcess.setBloomLevels

메서드methodpub fn get_bloom_level_count(&self) -> usize#0.4.0 부터since 0.4.0소스source

블룸 단 수 반환. (0 이면 기본 9 탭 블룸)

Returns the number of bloom levels. (0 means the default 9-tap bloom)

반환Returnsusize 다단 블룸의 단 수. (0 이면 기본 9 탭 블룸)Number of levels of the multi-level bloom. (0 means the default 9-tap bloom)

짝Counterpart: vanilla.js ToonPostProcess.getBloomLevelCount

메서드methodpub fn set_bloom_float_color(&mut self, gl: &GlContext, is_float_color: bool) -> Result<(), String>#0.4.0 부터since 0.4.0소스source

기본 9 탭 블룸의 주고받는 판을 실수로. (true 면 RGBA16F, 기본 false 는 RGBA8, 씬 판이 실수가 아니면 무시)

Makes the ping-pong buffers of the default 9-tap bloom float. (true means RGBA16F, the default false means RGBA8, ignored if the scene buffer is not float)

gl&GlContext
GL 컨텍스트.GL context.
is_float_colorbool
true 면 RGBA16F, false 면 RGBA8.RGBA16F if true, RGBA8 if false.

반환ReturnsResult<(), String> 바꿨거나 이미 같으면 Ok. 새 판을 못 지으면 Err(GL 의 오류 글, 앞의 판은 그대로 둔다).Ok if changed or already the same. Err(GL error text, the previous buffers are kept) if new buffers cannot be built.

짝Counterpart: vanilla.js ToonPostProcess.setBloomFloatColor

메서드methodpub fn set_brightness(&mut self, brightness: f64)#0.4.0 부터since 0.4.0소스source

밝기 설정. (색 보정 맨 앞에서 곱한다, 1 이 그대로)

Sets the brightness. (multiplied at the very start of color grading, 1 leaves it unchanged)

brightnessf64
밝기 배. (0 이상, 1 이 그대로)Brightness multiplier. (0 or more, 1 leaves it as is)

짝Counterpart: vanilla.js ToonPostProcess.setBrightness

메서드methodpub fn set_lit_area(&mut self, center: [f64; 3], inner_radius: f64, outer_radius: f64, inverse_view_projection_matrix: &Matrix4)#0.4.0 부터since 0.4.0소스source

밝힌 자리 설정. (그 자리에서 수평 거리 inner_radius 안은 밝기 1, outer_radius 밖은 set_brightness 의 밝기, 사이는 부드럽게)

  • 씬 깊이 텍스처(옵션 use_depth_texture)와 그 프레임의 보기와 투영의 역행렬로 화소마다 월드 자리를 되짚는다. 깊이 텍스처가 없으면 무시한다.
  • 카메라가 움직이면 프레임마다 다시 준다. 아무것도 그리지 않은 바탕은 먼 면의 자리로 셈한다.

Sets the lit spot. (within horizontal distance inner_radius of that spot the brightness is 1, beyond outer_radius it is the set_brightness brightness, smooth in between)

  • Reconstructs the world position of each pixel from the scene depth texture (option use_depth_texture) and the inverse of that frame's view and projection matrices. Ignored if there is no depth texture.
  • Give it again every frame when the camera moves. The background where nothing was drawn is computed as a position on the far plane.
center[f64; 3]
밝힐 자리. ([x, y, z] 월드 자리, 수평 거리는 x 와 z 로 잰다)Position to light. ([x, y, z] world position, horizontal distance is measured with x and z)
inner_radiusf64
밝기 1 인 수평 반지름. (월드 길이)Horizontal radius with brightness 1. (World length)
outer_radiusf64
이 밖은 set_brightness 의 밝기인 수평 반지름. (월드 길이)Horizontal radius outside which the brightness of set_brightness applies. (world length)
inverse_view_projection_matrix&Matrix4
이번 프레임 보기와 투영의 역행렬.Inverse of this frame's view and projection.

짝Counterpart: vanilla.js ToonPostProcess.setLitArea

메서드methodpub fn clear_lit_area(&mut self)#0.4.0 부터since 0.4.0소스source

밝힌 자리 풀기.

Clears the lit spot.

짝Counterpart: vanilla.js ToonPostProcess.clearLitArea

메서드methodpub fn set_color_grade(&mut self, saturation: f64, contrast: f64, tone_color: [f64; 3], tone_amount: f64, haze_color: [f64; 3], haze_amount: f64)#0.4.0 부터since 0.4.0소스source

색 보정 설정. (채도와 대비는 1 이 그대로, 색조와 안개빛은 sRGB [r, g, b] 0 ~ 1 과 섞는 양 0 ~ 1)

  • 색조 색은 밝기(Rec. 709)를 1 로 맞춰 곱하므로 밝기는 그대로 두고 빛깔만 물든다.
  • 안개빛은 어두운 곳일수록 그 색 쪽으로 끌어올린다. (양 x (1 - 밝기))

Sets the color grading. (saturation and contrast leave it unchanged at 1, tint and fog color are sRGB [r, g, b] 0 ~ 1 with a mix amount 0 ~ 1)

  • The tint color is normalized to luminance (Rec. 709) 1 before multiplying, so brightness stays the same and only the hue is tinted.
  • The fog color lifts darker areas more toward that color. (amount x (1 - luminance))
saturationf64
채도. (1 이 그대로, 0 이면 흑백)Saturation. (1 leaves it as is, 0 is grayscale)
contrastf64
대비. (1 이 그대로)Contrast. (1 leaves it as is)
tone_color[f64; 3]
[r, g, b] 색조 색. (sRGB 0 ~ 1, 밝기를 1 로 맞춰 곱한다)[r, g, b] tint color. (sRGB 0 ~ 1, multiplied after normalizing its brightness to 1)
tone_amountf64
색조를 섞는 양. (0 ~ 1)Amount of tint to mix. (0 ~ 1)
haze_color[f64; 3]
[r, g, b] 안개빛 색. (sRGB 0 ~ 1)[r, g, b] haze color. (sRGB 0 ~ 1)
haze_amountf64
안개빛을 섞는 양. (0 ~ 1, 어두운 곳일수록 세다)Amount of haze to mix. (0 ~ 1, stronger in darker areas)

짝Counterpart: vanilla.js ToonPostProcess.setColorGrade

메서드methodpub fn set_vignette(&mut self, vignette_strength: f64)#0.4.0 부터since 0.4.0소스source

가장자리 어둡게 설정. (0 이 없음, 1 이면 구석이 까맣게)

Sets the vignette. (0 is none, 1 makes the corners black)

vignette_strengthf64
가장자리를 어둡게 하는 세기. (0 이 없음, 1 이면 구석이 까맣게)Strength of darkening the edges. (0 is none, 1 makes the corners black)

짝Counterpart: vanilla.js ToonPostProcess.setVignette

메서드methodpub fn get_scene_render_target(&self) -> &RenderTarget#0.4.0 부터since 0.4.0소스source

씬 렌더 타겟. (다른 후처리를 끼울 때)

Scene render target. (for inserting other post-processing)

반환Returns&RenderTarget 씬을 그리는 렌더 타겟. (해상도 배율이나 표본 수를 바꾸면 다시 지어질 수 있다)Render target the scene is drawn into. (May be rebuilt if the resolution scale or sample count changes)

짝Counterpart: vanilla.js ToonPostProcess.getSceneRenderTarget

메서드methodpub fn destroy(&mut self, gl: &GlContext)#0.4.0 부터since 0.4.0소스source

지우기.

Disposes.

gl&GlContext
GL 컨텍스트.GL context.

짝Counterpart: vanilla.js ToonPostProcess.destroy

메서드methodpub fn get_color_space(&self) -> ColorSpace#0.4.0 부터since 0.4.0소스source

색 공간 반환. (원본 getColorSpace, 생성 때 정한 값, 톤매핑 뒤 화면 색을 내는 곡선을 가른다)

Returns the color space. (original getColorSpace, fixed at creation, selects the curve that produces the screen color after tone mapping)

반환ReturnsColorSpace ColorSpace::Gamma 나 ColorSpace::Linear.ColorSpace::Gamma or ColorSpace::Linear.

짝Counterpart: vanilla.js ToonPostProcess.getColorSpace

메서드methodpub fn set_ambient_occlusion(&mut self, is_enabled: bool, intensity: f64, radius: f64, resolution_scale: f64, direct_lighting_strength: f64)#0.4.0 부터since 0.4.0소스source

모서리 어둠(화면 공간 AO) 설정. (원본 setAmbientOcclusion, 기본 꺼짐, 켜면 draw_ambient_occlusion 이 셈하고 몸 셰이더가 바탕빛에 곱한다)

Sets ambient occlusion (screen-space AO). (original setAmbientOcclusion, off by default; when on, draw_ambient_occlusion computes it and the body shader multiplies it into the ambient light)

is_enabledbool
켤지.Whether to turn it on.
intensityf64
세기. (0 ~ 1 로 자름, 원본 기본 0.5)Intensity. (clamped to 0 ~ 1, original default 0.5)
radiusf64
가리는 것을 찾는 반지름. (월드 길이, 0.0001 이상, 원본 기본 0.5)Radius to search for occluders. (world length, at least 0.0001, original default 0.5)
resolution_scalef64
셈하는 판의 해상도 배율. (0.25 ~ 1 로 자름, 원본 기본 0.5)Resolution scale of the computed target. (clamped to 0.25 ~ 1, original default 0.5)
direct_lighting_strengthf64
직접 빛(해, 채움빛, 점광의 확산과 반사광)에 미치는 몫. (0 ~ 1 로 자름, 원본 기본 0 이면 바탕빛에만)Share applied to direct light (diffuse and specular of the sun, fill light and point lights). (clamped to 0 ~ 1, original default 0 means ambient light only)

짝Counterpart: vanilla.js ToonPostProcess.setAmbientOcclusion

예제Example바깥선 없는 장면에 모서리 어둠을 켜고 그리기 줄에 맡기기Turn on ambient occlusion in a scene without outlines and hand it to the draw queue
use vanilla::{Matrix4, ToonDrawOptions, ToonDrawQueue, ToonMesh, ToonPostProcess, ToonRenderer};

fn draw_room(gl: &vanilla::GlContext, renderer: &mut ToonRenderer, post_process: &mut ToonPostProcess, room_mesh: &ToonMesh, view_matrix: &Matrix4, projection_matrix: &Matrix4) {
	post_process.set_ambient_occlusion(true, 0.5, 0.5, 0.5, 0.5);
	assert_eq!(post_process.get_ambient_occlusion_direct_lighting_strength(), 0.5);
	post_process.begin(gl, [0.1, 0.1, 0.12]);
	{
		let mut queue = ToonDrawQueue::new();
		queue.set_post_process(Some(&mut *post_process));
		queue.add_mesh(room_mesh, &Matrix4::create_identity(), ToonDrawOptions::default());
		queue.draw_with_matrices(gl, renderer, view_matrix, projection_matrix);
	}
	post_process.end(gl, None, [0, 0, 640, 360]);
}
메서드methodpub fn get_ambient_occlusion(&self) -> ToonAmbientOcclusion#0.4.0 부터since 0.4.0소스source

모서리 어둠 설정 반환. (원본 getAmbientOcclusion)

Returns the ambient occlusion settings. (original getAmbientOcclusion)

반환ReturnsToonAmbientOcclusion 설정. (ToonAmbientOcclusion, 베낀 것)Settings. (ToonAmbientOcclusion, a copy)

짝Counterpart: vanilla.js ToonPostProcess.getAmbientOcclusion

메서드methodpub fn get_ambient_occlusion_direct_lighting_strength(&self) -> f64#0.4.0 부터since 0.4.0소스source

모서리 어둠이 직접 빛에 미치는 몫 반환. (원본 getAmbientOcclusionDirectLightingStrength, set_ambient_occlusion 의 다섯째 인자, 그리기 줄이 렌더러에 건다)

Returns the share of ambient occlusion applied to direct light. (original getAmbientOcclusionDirectLightingStrength, the fifth argument of set_ambient_occlusion, the draw queue sets it on the renderer)

반환Returnsf64 0 ~ 1.

짝Counterpart: vanilla.js ToonPostProcess.getAmbientOcclusionDirectLightingStrength

메서드methodpub fn is_ambient_occlusion_enabled(&self) -> bool#0.4.0 부터since 0.4.0소스source

모서리 어둠을 켰는지. (원본 isAmbientOcclusionEnabled)

Whether ambient occlusion is on. (original isAmbientOcclusionEnabled)

반환Returnsbool set_ambient_occlusion 으로 켰으면 true.true if turned on with set_ambient_occlusion.

짝Counterpart: vanilla.js ToonPostProcess.isAmbientOcclusionEnabled

메서드methodpub fn get_ambient_occlusion_prepass(&mut self, gl: &GlContext) -> Result<&mut ToonScreenOutline, String>#0.4.0 부터since 0.4.0소스source

바깥선이 없는 장면의 미리 그리기 반환. (원본 getAmbientOcclusionPrepass, 선 굵기 0 의 화면 바깥선, 처음 부를 때 짓는다)

Returns the prepass for scenes without outlines. (original getAmbientOcclusionPrepass, a screen outline with line width 0, built on the first call)

gl&GlContext
툰 렌더러와 같은 컨텍스트.The same context as the toon renderer.

반환ReturnsResult<&mut ToonScreenOutline, String> 선의 판만 그리는 화면 바깥선. (begin_line_ids, draw_mesh, end_line_ids 로 그리고 get_line_target 을 draw_ambient_occlusion 에 준다) 짓지 못하면 Err(오류 글).A screen outline that draws only the line target. (draw with begin_line_ids, draw_mesh, end_line_ids and pass get_line_target to draw_ambient_occlusion) Err (error text) if it cannot be built.

짝Counterpart: vanilla.js ToonPostProcess.getAmbientOcclusionPrepass

메서드methodpub fn draw_ambient_occlusion_with_prepass(&mut self, gl: &GlContext, view_matrix: &Matrix4, projection_matrix: &Matrix4) -> Option<GlTexture>#0.4.0 부터since 0.4.0소스source

미리 그리기의 선의 판으로 모서리 어둠 셈하기. (draw_ambient_occlusion 에 get_ambient_occlusion_prepass 의 선의 판을 준 것과 같다, 미리 그리기가 없거나 꺼졌으면 None)

Computes ambient occlusion with the prepass line target. (the same as passing the line target of get_ambient_occlusion_prepass to draw_ambient_occlusion, None if there is no prepass or it is off)

gl&GlContext
GL 컨텍스트.GL context.
view_matrix&Matrix4
선의 판을 그린 보기 행렬.View matrix the line target was drawn with.
projection_matrix&Matrix4
선의 판을 그린 투영 행렬.Projection matrix the line target was drawn with.

반환ReturnsOption<GlTexture> 결과 텍스처. (draw_ambient_occlusion 과 같다)Result texture. (same as draw_ambient_occlusion)

메서드methodpub fn draw_ambient_occlusion(&mut self, gl: &GlContext, line_target: &ToonLineTarget, view_matrix: &Matrix4, projection_matrix: &Matrix4) -> Option<GlTexture>#0.4.0 부터since 0.4.0소스source

모서리 어둠 셈하기. (원본 drawAmbientOcclusion, 선의 판의 노멀과 깊이로 반 해상도 GTAO → 가로 흐림 → 세로 흐림과 키우기, 꺼졌으면 None)

  • 결과 텍스처는 선의 판 크기의 RGBA8 이다. (r 세기를 건 보임, gba 깊이 24 비트) ToonRenderer::set_ambient_occlusion_texture 에 준다.
  • 프레임버퍼, 뷰포트, 프로그램, 버텍스 어레이, 고른 텍스처 유닛, 깊이 시험, 섞기, 가위, 면 가리기를 되돌린다.

Computes ambient occlusion. (original drawAmbientOcclusion, half-resolution GTAO → horizontal blur → vertical blur with upsampling from the normals and depth of the line target, None when off)

  • The result texture is RGBA8 at the size of the line target. (r is the visibility with intensity applied, gba the 24-bit depth) Pass it to ToonRenderer::set_ambient_occlusion_texture.
  • Restores the framebuffer, viewport, program, vertex array, active texture unit, depth test, blending, scissor and face culling.
gl&GlContext
GL 컨텍스트.GL context.
line_target&ToonLineTarget
이번 프레임의 선의 판. (ToonScreenOutline::get_line_target)This frame's line target. (ToonScreenOutline::get_line_target)
view_matrix&Matrix4
선의 판을 그린 보기 행렬.View matrix the line target was drawn with.
projection_matrix&Matrix4
선의 판을 그린 투영 행렬.Projection matrix the line target was drawn with.

반환ReturnsOption<GlTexture> 결과 텍스처. 꺼졌거나 판이나 셰이더를 짓지 못하면 None.Result texture. None when off or when the targets or shaders cannot be built.

짝Counterpart: vanilla.js ToonPostProcess.drawAmbientOcclusion

메서드methodpub fn get_ambient_occlusion_texture(&self) -> Option<GlTexture>#0.4.0 부터since 0.4.0소스source

모서리 어둠 결과 텍스처 반환. (원본 getAmbientOcclusionTexture, 아직 셈하지 않았거나 꺼졌으면 None)

Returns the ambient occlusion result texture. (original getAmbientOcclusionTexture, None if not computed yet or off)

반환ReturnsOption<GlTexture> 결과 텍스처. (RGBA8, r 보임, gba 깊이)Result texture. (RGBA8, r visibility, gba depth)

짝Counterpart: vanilla.js ToonPostProcess.getAmbientOcclusionTexture

ToonAmbientOcclusionstruct traits Clone, Copy, Debug, PartialEq, Default

소스source

모서리 어둠 설정. (원본 getAmbientOcclusion 의 { isEnabled, intensity, radius, resolutionScale, directLightingStrength })

Ambient occlusion settings. (the { isEnabled, intensity, radius, resolutionScale, directLightingStrength } of the original getAmbientOcclusion)

예제Example기본값 읽기Read the defaults
use vanilla::ToonAmbientOcclusion;

let ambient_occlusion = ToonAmbientOcclusion::default();
assert!(!ambient_occlusion.is_enabled);
assert_eq!((ambient_occlusion.intensity, ambient_occlusion.radius, ambient_occlusion.resolution_scale, ambient_occlusion.direct_lighting_strength), (0.5, 0.5, 0.5, 0.0));
필드fieldpub is_enabled: bool#0.4.0 부터since 0.4.0소스source

켰는지.

Whether it is on.

반환Returnsbool

필드fieldpub intensity: f64#0.4.0 부터since 0.4.0소스source

세기. (0 ~ 1, 0 이면 어둡히지 않는다)

Intensity. (0 ~ 1, 0 does not darken)

반환Returnsf64

필드fieldpub radius: f64#0.4.0 부터since 0.4.0소스source

가리는 것을 찾는 반지름. (월드 길이)

Radius to search for occluders. (world length)

반환Returnsf64

필드fieldpub resolution_scale: f64#0.4.0 부터since 0.4.0소스source

셈하는 판의 해상도 배율. (0.25 ~ 1, 선의 판 크기에 곱한다)

Resolution scale of the computed target. (0.25 ~ 1, multiplied by the line target size)

반환Returnsf64

필드fieldpub direct_lighting_strength: f64#0.4.0 부터since 0.4.0소스source

직접 빛에 미치는 몫. (0 ~ 1, URP 의 Direct Lighting Strength)

Share applied to direct light. (0 ~ 1, Direct Lighting Strength of URP)

반환Returnsf64