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/05/27 12:31] – [Iterations] admin | renderpass [2020/01/09 14:09] – [Start / End] 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. | ||
+ | |||
+ | ===== Render-Pass Material ===== | ||
+ | |||
+ | To create an individual material shader for your render-pass you need to extend **TGorillaRenderPassMaterialSource** and **TGorillaRenderPassMaterial**. | ||
+ | |||
+ | <file pascal> | ||
+ | uses | ||
+ | FMX.Types3D, | ||
+ | FMX.Materials, | ||
+ | FMX.MaterialSources, | ||
+ | Gorilla.Controller; | ||
+ | | ||
+ | TMyRenderPassMaterial = class(TGorillaRenderPassMaterial) | ||
+ | protected | ||
+ | procedure DoApply(const Context: TContext3D); | ||
+ | procedure DoInitialize(); | ||
+ | public | ||
+ | end; | ||
+ | |||
+ | TMyRenderPassMaterialSource = class(TGorillaRenderPassMaterialSource) | ||
+ | protected | ||
+ | function CreateMaterial() : TMaterial; override; | ||
+ | public | ||
+ | end; | ||
+ | </ | ||
+ | |||
+ | Here you can have a look at this example of a render-pass material implementation. | ||
+ | |||
+ | Notice: No multiple targets used here. We just write to default output buffer by gl_FragColor. | ||
+ | |||
+ | <file pascal> | ||
+ | uses | ||
+ | Gorilla.Context.GLES; | ||
+ | | ||
+ | ResourceString SOURCE_VS = | ||
+ | ' | ||
+ | '' | ||
+ | ' | ||
+ | '' | ||
+ | ' | ||
+ | '' | ||
+ | 'void main( void ){' + | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | ResourceString SOURCE_FS = | ||
+ | ' | ||
+ | '' | ||
+ | 'void main( void ){' + | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | procedure TMyRenderPassMaterial.DoInitialize(); | ||
+ | var LOGLBytes : TArray< | ||
+ | begin | ||
+ | LOGLBytes := TEncoding.ASCII.GetBytes(SOURCE_VS); | ||
+ | FVertexShader := TShaderManager.RegisterShaderFromData(' | ||
+ | TContextShaderSource.Create(TContextShaderArch.GLSL, | ||
+ | LOGLBytes, | ||
+ | [ | ||
+ | TContextShaderVariable.Create(' | ||
+ | ] | ||
+ | ) | ||
+ | ]); | ||
+ | |||
+ | LOGLBytes := TEncoding.ASCII.GetBytes(SOURCE_FS); | ||
+ | FPixelShader := TShaderManager.RegisterShaderFromData(' | ||
+ | TContextShaderSource.Create(TContextShaderArch.GLSL, | ||
+ | LOGLBytes, | ||
+ | [] | ||
+ | ) | ||
+ | ]); | ||
+ | end; | ||
+ | |||
+ | { TMyRenderPassMaterial } | ||
+ | |||
+ | procedure TMyRenderPassMaterial.DoApply(const Context: TContext3D); | ||
+ | begin | ||
+ | // activate shaders | ||
+ | Context.SetShaders(FVertexShader, | ||
+ | // set model view projection matrix | ||
+ | TCustomContextOpenGL(Context).SetShaderVariable(' | ||
+ | end; | ||
+ | |||
+ | { TMyRenderPassMaterialSource } | ||
+ | |||
+ | function TMyRenderPassMaterialSource.CreateMaterial() : TMaterial; | ||
+ | begin | ||
+ | Result := TMyRenderPassMaterial.Create(Self); | ||
+ | end; | ||
+ | </ | ||
+ | |||
+ | You than have to overwrite the CreateMaterialSource() method and create your material source. | ||
+ | In case you'd like to use the element specific material shaders, return nil in the CreateMaterialSource() method. | ||
+ | |||
+ | <file pascal> | ||
+ | function TMyRenderPass.CreateMaterialSource() : TGorillaRenderPassMaterialSource; | ||
+ | begin | ||
+ | result := TMyRenderPassMaterialSource.Create(Self); | ||
+ | end; | ||
+ | </ | ||
===== Start / End ===== | ===== Start / End ===== | ||
Line 58: | Line 170: | ||
[TRenderTarget.Color_0, | [TRenderTarget.Color_0, | ||
TAlphaColorF.Create(0, | TAlphaColorF.Create(0, | ||
- | FFBO.Bind(); | + | |
+ | // prepare framebufferobject for multiple render targets | ||
FFBO.Prepare([TRenderTarget.Color_0, | FFBO.Prepare([TRenderTarget.Color_0, | ||
end; | end; | ||
Line 64: | Line 177: | ||
OnPassEnd: | OnPassEnd: | ||
begin | begin | ||
- | AContext.SetCameraMatrix(FPrevCamView); | + | AContext.SetCameraMatrix(FPrevCamView); |
- | + | ||
- | FFBO.Unbind(); | + | |
end; | end; | ||
end; | end; | ||
Line 275: | Line 386: | ||
* function GetProjectionMatrix(const AContext : TContext3D) : TMatrix3D; | * function GetProjectionMatrix(const AContext : TContext3D) : TMatrix3D; | ||
- | ===== Render-Pass Material ===== | ||
- | |||
- | To create an individual material shader for your render-pass you need to extend **TGorillaRenderPassMaterialSource** and **TGorillaRenderPassMaterial**. | ||
- | |||
- | <file pascal> | ||
- | uses | ||
- | FMX.Types3D, | ||
- | FMX.Materials, | ||
- | FMX.MaterialSources, | ||
- | Gorilla.Controller; | ||
- | | ||
- | TMyRenderPassMaterial = class(TGorillaRenderPassMaterial) | ||
- | protected | ||
- | procedure DoApply(const Context: TContext3D); | ||
- | procedure DoInitialize(); | ||
- | public | ||
- | end; | ||
- | |||
- | TMyRenderPassMaterialSource = class(TGorillaRenderPassMaterialSource) | ||
- | protected | ||
- | function CreateMaterial() : TMaterial; override; | ||
- | public | ||
- | end; | ||
- | </ | ||
- | |||
- | Here you can have a look at this example of a render-pass material implementation. | ||
- | |||
- | Notice: No multiple targets used here. We just write to default output buffer by gl_FragColor. | ||
- | |||
- | <file pascal> | ||
- | uses | ||
- | Gorilla.Context.GLES; | ||
- | | ||
- | ResourceString SOURCE_VS = | ||
- | ' | ||
- | '' | ||
- | ' | ||
- | '' | ||
- | ' | ||
- | '' | ||
- | 'void main( void ){' + | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | |||
- | ResourceString SOURCE_FS = | ||
- | ' | ||
- | '' | ||
- | 'void main( void ){' + | ||
- | ' | ||
- | ' | ||
- | |||
- | procedure TMyRenderPassMaterial.DoInitialize(); | ||
- | var LOGLBytes : TArray< | ||
- | begin | ||
- | LOGLBytes := TEncoding.ASCII.GetBytes(SOURCE_VS); | ||
- | FVertexShader := TShaderManager.RegisterShaderFromData(' | ||
- | TContextShaderSource.Create(TContextShaderArch.GLSL, | ||
- | LOGLBytes, | ||
- | [ | ||
- | TContextShaderVariable.Create(' | ||
- | ] | ||
- | ) | ||
- | ]); | ||
- | |||
- | LOGLBytes := TEncoding.ASCII.GetBytes(SOURCE_FS); | ||
- | FPixelShader := TShaderManager.RegisterShaderFromData(' | ||
- | TContextShaderSource.Create(TContextShaderArch.GLSL, | ||
- | LOGLBytes, | ||
- | [] | ||
- | ) | ||
- | ]); | ||
- | end; | ||
- | |||
- | { TMyRenderPassMaterial } | ||
- | |||
- | procedure TMyRenderPassMaterial.DoApply(const Context: TContext3D); | ||
- | begin | ||
- | // activate shaders | ||
- | Context.SetShaders(FVertexShader, | ||
- | // set model view projection matrix | ||
- | TCustomContextOpenGL(Context).SetShaderVariable(' | ||
- | end; | ||
- | |||
- | { TMyRenderPassMaterialSource } | ||
- | |||
- | function TMyRenderPassMaterialSource.CreateMaterial() : TMaterial; | ||
- | begin | ||
- | Result := TMyRenderPassMaterial.Create(Self); | ||
- | end; | ||
- | </ | ||
- | |||
- | You than have to overwrite the CreateMaterialSource() method and create your material source. | ||
- | In case you'd like to use the element specific material shaders, return nil in the CreateMaterialSource() method. | ||
- | |||
- | <file pascal> | ||
- | function TMyRenderPass.CreateMaterialSource() : TGorillaRenderPassMaterialSource; | ||
- | begin | ||
- | result := TMyRenderPassMaterialSource.Create(Self); | ||
- | end; | ||
- | </ | ||
===== How to use ===== | ===== How to use ===== |