Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
renderpass [2019/04/12 13:24] – [Multiple Rendering-Targets] admin | renderpass [2020/01/09 14:04] – [Rendering Method] admin | ||
---|---|---|---|
Line 15: | Line 15: | ||
You are allowed to configure a destination / method for your individual render pass. | You are allowed to configure a destination / method for your individual render pass. | ||
+ | A render destination is the place where computed image data is going to stored to. | ||
+ | * Context | ||
+ | * FrameBufferObject (FBO) | ||
+ | |||
+ | While the context (aka. main texture or Default-FBO) is the default texture used for final rendering output, the FrameBufferObject (FBO) is a buffer created for each render pass instance. | ||
+ | The FrameBufferObject (FBO) can be used to temporarily store your rendering result and push it to another render pass. | ||
+ | For further information read down below. | ||
^ Type ^ Description ^ | ^ Type ^ Description ^ | ||
- | | TRenderPassMethod.RenderList | + | | TRenderPassMethod.RenderListToContext |
- | | TRenderPassMethod.ToContext | + | | TRenderPassMethod.RenderListToFBO | Will render |
+ | | TRenderPassMethod.RectToContext | ||
+ | | TRenderPassMethod.RectToFBO | Will render a rectangle to the render pass specific FrameBufferObject (FBO). The render pass need to have an individual | ||
- | In the next step you have to decide, if the element materials (only in RenderList) or an especially | + | In the next step you have to decide, if a one-for-all material |
Because sometimes you want the full scene just to be rendered from another perspective (like reflection) or you want to store a specific value (like the depth-value in shadow mapping) in the FBO. | Because sometimes you want the full scene just to be rendered from another perspective (like reflection) or you want to store a specific value (like the depth-value in shadow mapping) in the FBO. | ||
+ | |||
+ | ===== Start / End ===== | ||
+ | |||
+ | The render-pass controller provides a callback event for the start and the end of each rendering cycle. Simply overwrite the protected DoOnRenderPass() method. | ||
+ | |||
+ | Here you can change the view, projection matrices or re-configure OpenGL context. | ||
+ | But do not forget to reset your changes on " | ||
+ | |||
+ | Here is a short example for a callback function. | ||
+ | |||
+ | <file pascal> | ||
+ | var | ||
+ | FPrevCamView : TMatrix3D; | ||
+ | | ||
+ | procedure TMyRenderPass.DoOnRenderPass(const AContext : TContext3D; | ||
+ | const ACount : Integer; const AState : TRenderPassEventState; | ||
+ | var LCtx : TCustomContextOpenGL; | ||
+ | begin | ||
+ | inherited; | ||
+ | |||
+ | LCtx := TCustomContextOpenGL(AContext); | ||
+ | case AState of | ||
+ | OnPassBegin: | ||
+ | begin | ||
+ | // deactivate ZTest in OpenGL | ||
+ | AContext.SetContextState(TContextState.csZTestOff); | ||
+ | | ||
+ | // Set view matrix and angle of view | ||
+ | FPrevCamView := AContext.CurrentCameraMatrix; | ||
+ | AContext.SetCameraMatrix(GetViewMatrix(AContext)); | ||
+ | AContext.SetCameraAngleOfView(Viewport.CurrentCamera.AngleOfView); | ||
+ | | ||
+ | // rendering method for rendering pass | ||
+ | FFBO.Clear(Point(AContext.Width, | ||
+ | [TRenderTarget.Color_0, | ||
+ | TAlphaColorF.Create(0, | ||
+ | FFBO.Bind(); | ||
+ | FFBO.Prepare([TRenderTarget.Color_0, | ||
+ | end; | ||
+ | |||
+ | OnPassEnd: | ||
+ | begin | ||
+ | AContext.SetCameraMatrix(FPrevCamView); | ||
+ | | ||
+ | FFBO.Unbind(); | ||
+ | end; | ||
+ | end; | ||
+ | end; | ||
+ | </ | ||
Line 138: | Line 196: | ||
<file pascal> | <file pascal> | ||
if Assigned(AContext) and Assigned(FFBO) then | if Assigned(AContext) and Assigned(FFBO) then | ||
- | FFBO.AttachTexture(AContext, | + | FFBO.AttachTexture(AContext, |
</ | </ | ||
Line 184: | Line 242: | ||
=== In Shader === | === In Shader === | ||
- | The usage in your material shader depends on your target setup and the activated targets: | + | The usage in your material shader depends on your target setup and the activated targets. |
- | Preparing | + | For example: |
<file pascal> | <file pascal> | ||
Line 191: | Line 249: | ||
</ | </ | ||
- | In Fragment-Shader: | + | In Fragment-Shader |
<file GLSL> | <file GLSL> | ||
layout(location = 0) out vec4 outColor_0; | layout(location = 0) out vec4 outColor_0; | ||
Line 207: | Line 266: | ||
// output three with blue color | // output three with blue color | ||
outColor_3 = vec4(0.0, 0.0, 1.0, 1.0); | outColor_3 = vec4(0.0, 0.0, 1.0, 1.0); | ||
- | </ | ||
- | ===== Start / End ===== | ||
- | |||
- | The render-pass controller provides a callback event for the start and the end of each rendering cycle. Simply overwrite the protected DoOnRenderPass() method. | ||
- | |||
- | Here you can change the view, projection matrices or re-configure OpenGL context. | ||
- | But do not forget to reset your changes on " | ||
- | |||
- | Here is a short example for a callback function. | ||
- | |||
- | <file pascal> | ||
- | procedure TMyRenderPass.DoOnRenderPass(const AContext : TContext3D; | ||
- | const ACount : Integer; const AState : TRenderPassEventState; | ||
- | var LCtx : TCustomContextOpenGL; | ||
- | begin | ||
- | inherited; | ||
- | |||
- | LCtx := TCustomContextOpenGL(AContext); | ||
- | case AState of | ||
- | OnPassBegin: | ||
- | begin | ||
- | // rendering method for rendering pass | ||
- | FFBO.Clear(Point(AContext.Width, | ||
- | [TRenderTarget.Color_0, | ||
- | TAlphaColorF.Create(0, | ||
- | FFBO.Bind(); | ||
- | FFBO.Prepare([TRenderTarget.Color_0, | ||
- | | ||
- | // deactivate ZTest in OpenGL | ||
- | AContext.SetContextState(TContextState.csZTestOff); | ||
- | | ||
- | // Set view matrix and angle of view | ||
- | AContext.SetCameraMatrix(GetViewMatrix(AContext)); | ||
- | AContext.SetCameraAngleOfView(Viewport.CurrentCamera.AngleOfView); | ||
- | end; | ||
- | |||
- | OnPassEnd: | ||
- | begin | ||
- | FFBO.Unbind(); | ||
- | end; | ||
- | end; | ||
- | end; | ||
</ | </ | ||
Line 255: | Line 272: | ||
The callback also provides an " | The callback also provides an " | ||
It is possible to set a number of iterations this pass should run. | It is possible to set a number of iterations this pass should run. | ||
- | This is very useful | + | This is very useful for ping-pong rendering techniques like blurring. |
Set the " | Set the " | ||
Line 269: | Line 286: | ||
===== Render-Pass Material ===== | ===== Render-Pass Material ===== | ||
- | To create | + | To create |
<file pascal> | <file pascal> | ||
Line 294: | Line 311: | ||
Here you can have a look at this example of a render-pass material implementation. | Here you can have a look at this example of a render-pass material implementation. | ||
- | Notice: No multiple targets used here. We simple | + | Notice: No multiple targets used here. We just write to default output buffer by gl_FragColor. |
<file pascal> | <file pascal> |