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 [2020/01/09 13:36] – [Rendering Method] admin | renderpass [2020/01/09 14:07] – [Rendering Method] admin | ||
---|---|---|---|
Line 19: | Line 19: | ||
* FrameBufferObject (FBO) | * FrameBufferObject (FBO) | ||
- | While the Context | + | While the context |
- | The FrameBufferObject (FBO) can be used to temporarily store your rendering result and push it to another | + | The FrameBufferObject (FBO) can be used to temporarily store your rendering result and push it to another |
For further information read down below. | For further information read down below. | ||
^ Type ^ Description ^ | ^ Type ^ Description ^ | ||
- | | TRenderPassMethod.RenderListToContext | Will render all 3D objects in rendering list to the default FrameBufferObject (so called FBO / context | + | | TRenderPassMethod.RenderListToContext | Will render all 3D objects in rendering list to context. If a render pass material exists it will be applied, otherwise it will use the 3D object |
- | | TRenderPassMethod.RenderListToFBO | Will render all 3D objects in rendering list to the render pass specific FrameBufferObject (FBO) and attached textures. | | + | | TRenderPassMethod.RenderListToFBO | Will render all 3D objects in rendering list to render pass specific FrameBufferObject (FBO) and its attached textures. | |
- | | TRenderPassMethod.RectToContext | Will render a rectangle to default FrameBufferObject (FBO). The render pass need to have an individual material applied, otherwise an error occurs. Use this method for rendering post effects. The shader program will render to default FBO / context | + | | TRenderPassMethod.RectToContext | Will render a rectangle to context. The render pass need to have an individual material applied, otherwise an error occurs. Use this method for rendering |
- | | TRenderPassMethod.RectToFBO | Will render a rectangle to the render pass specific FrameBufferObject (FBO). | + | | TRenderPassMethod.RectToFBO | Will render a rectangle to the render pass specific FrameBufferObject (FBO). |
- | 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 284: | Line 387: | ||
* 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 ===== |