Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
renderpass [2020/01/09 14:06] – [Rendering Method] admin | renderpass [2020/01/09 14:07] – [Render-Pass Material] admin | ||
---|---|---|---|
Line 284: | Line 284: | ||
* 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 ===== |