core/fullscreenpass
풀스크린 패스. (화면 전체를 덮는 삼각형 1개 + 프래그먼트 셰이더)
- 원본 core/fullscreenpass.js 를 옮긴 것이다. 배경 / 후처리 같은 화면 단위 효과의 기본 단위. (ScreenEffect 가 쓴다)
- 버텍스 버퍼 없이 gl_VertexID 로 삼각형을 만든다. 빈 버텍스 어레이를 묶어 그린다. (GL 3.3 코어도 WebGL2 도 버텍스 어레이만 묶여 있으면 된다)
- 셰이더는 원본과 같은 GLSL ES 3.00 이다. 데스크탑은 ShaderProgram 이 머리만 #version 330 core 로 바꿔 컴파일한다.
- 원본과 다른 점: GL 컨텍스트를 들지 않고 함수마다 받는다. 만들기 실패는 예외 대신 Err 로 돌려준다. GL 자원은 destroy 로 지운다.
Fullscreen pass. (one triangle covering the whole screen + a fragment shader)
- A port of the original core/fullscreenpass.js. The basic unit of screen-wide effects such as backgrounds / post-processing. (used by ScreenEffect)
- Builds the triangle from gl_VertexID without a vertex buffer. Draws with an empty vertex array bound. (both GL 3.3 core and WebGL2 only need a vertex array bound)
- The shader is GLSL ES 3.00 like the original. On desktop, ShaderProgram replaces only the header with #version 330 core before compiling.
- Differences from the original: it does not hold the GL context but takes it in each function. Creation failure returns Err instead of an exception. GL resources are deleted with destroy.
FullscreenPassstruct
풀스크린 패스. (화면 전체를 덮는 삼각형 하나를 프래그먼트 셰이더로 칠한다)
- 프래그먼트 셰이더는 fragmentCoordinate(클립 좌표, -1 ~ 1)와 fragmentTextureCoordinate(텍스처 좌표, 0 ~ 1)를 in 으로 받을 수 있다.
- 쓰는 차례: use_program, 유니폼 올리기, draw. 다 쓰면 destroy 로 GL 자원을 지운다.
Fullscreen pass. (paints a single triangle that covers the whole screen with a fragment shader)
- The fragment shader can receive fragmentCoordinate (clip coordinates, -1 to 1) and fragmentTextureCoordinate (texture coordinates, 0 to 1) as in.
- Order of use: use_program, upload uniforms, draw. When finished, destroy deletes the GL resources.
use vanilla::{FullscreenPass, Graphic};
const VIGNETTE_FRAGMENTSHADER_SOURCE: &str = "#version 300 es
precision highp float;
in vec2 fragmentTextureCoordinate;
uniform float strength;
out vec4 outputColor;
void main() {
float centerDistance = length(fragmentTextureCoordinate - 0.5);
outputColor = vec4(0.0, 0.0, 0.0, clamp(centerDistance * strength, 0.0, 1.0));
}
";
fn create_vignette(graphic: &Graphic) -> Result<FullscreenPass, String> {
FullscreenPass::new(graphic.get_gl(), VIGNETTE_FRAGMENTSHADER_SOURCE)
}
fn draw_vignette(graphic: &mut Graphic, fullscreen_pass: &FullscreenPass) {
graphic.run_external_pass(false, |gl| {
fullscreen_pass.use_program(gl);
unsafe {
gl.uniform_1_f32(fullscreen_pass.get_uniform_location(gl, "strength").as_ref(), 1.2);
}
fullscreen_pass.draw(gl);
});
}
fn destroy_vignette(graphic: &Graphic, fullscreen_pass: FullscreenPass) {
fullscreen_pass.destroy(graphic.get_gl());
}pub fn new(gl: &GlContext, fragment_shader_source: &str) -> Result<FullscreenPass, String>#생성. (프래그먼트 셰이더 컴파일 / 링크 실패면 로그를 담은 오류)
Constructor. (an error holding the log if the fragment shader compile / link fails)
- gl&GlContext
- GL 컨텍스트. (Graphic 의 get_gl)GL context. (get_gl of Graphic)
- fragment_shader_source&str
- 프래그먼트 셰이더 소스. (GLSL ES 3.00, 앞뒤 빈칸은 뗀다)Fragment shader source. (GLSL ES 3.00, leading and trailing whitespace is trimmed)
반환ReturnsResult<FullscreenPass, String> 만든 패스. 셰이더 컴파일이나 링크, 버텍스 어레이 만들기에 실패하면 그 오류 글을 담은 Err.The created pass. Err holding the error text if shader compile or link, or vertex array creation fails.
짝Counterpart: vanilla.js FullscreenPass.constructor
패스 사용 시작. (프로그램 + 빈 버텍스 어레이 바인드, 원본 useProgram)
Starts using the pass. (binds the program and an empty vertex array; the original useProgram)
- gl&GlContext
- 패스를 만든 GL 컨텍스트.GL context that created the pass.
짝Counterpart: vanilla.js FullscreenPass.useProgram
출력. (use_program 과 유니폼 설정 이후 호출)
Output. (called after use_program and setting uniforms)
- gl&GlContext
- 패스를 만든 GL 컨텍스트. (정점 3 개로 삼각형 하나를 그린다)GL context that created the pass. (draws one triangle with 3 vertices)
짝Counterpart: vanilla.js FullscreenPass.draw
pub fn get_uniform_location(&self, gl: &GlContext, uniform_name: &str) -> Option<GlUniformLocation>#유니폼 위치 반환. (캐시)
Returns the uniform location. (cached)
- gl&GlContext
- 패스를 만든 GL 컨텍스트.GL context that created the pass.
- uniform_name&str
- 유니폼 이름. (셰이더 소스의 이름 그대로)Uniform name. (exactly as named in the shader source)
반환ReturnsOption<GlUniformLocation> 유니폼 위치. 그 이름의 활성 유니폼이 없으면 None.Uniform location. None if there is no active uniform with that name.
짝Counterpart: vanilla.js FullscreenPass.getUniformLocation
셰이더 프로그램 반환.
Returns the shader program.
반환Returns&ShaderProgram 패스의 셰이더 프로그램.Shader program of the pass.
짝Counterpart: vanilla.js FullscreenPass.getShaderProgram
버텍스 어레이 반환.
Returns the vertex array.
반환ReturnsGlVertexArray 그릴 때 묶는 빈 버텍스 어레이.Empty vertex array bound when drawing.
짝Counterpart: vanilla.js FullscreenPass.getVertexArray
파괴. (GL 프로그램과 버텍스 어레이를 지운다)
Destroy. (deletes the GL program and vertex array)
- gl&GlContext
- 패스를 만든 GL 컨텍스트.GL context that created the pass.
짝Counterpart: vanilla.js FullscreenPass.destroy