Job Open: Blitz3D/C++ DLL RPLidar Programming. View Job Posting
(Posted 1 year ago) RonTek

Simple RenderPass (Camera PostFX) for OpenB3D

Just to keep things clean and manageable on the main source when working on postfx shaders. This currently supports only 1 camera texture/sprite, but can be easily extended to handle camera attributes and some sort of stacking system and it seems 2 - 3 levels/texture buffers will be enough on most cases.

Type TRenderPass
    Field Active:Byte = False
    Field Camera:TCamera = CreateCamera()   'camera
    Field cameratex:TTexture
    Field sprite:TSprite = CreateSprite()

    Field postFxCam:TCamera = CreateCamera()
    Field postFxTex:TTexture
    Field postFxSpr:TSprite

    Function Create:TRenderPass()
        Return New TRenderPass
    End Function

    Method Init:TRenderPass()       
        CameraRange Self.Camera,0.5,1000.0 ' near must be closer than screen sprite to prevent clipping
        CameraClsColor Self.Camera,0,0,0

        CameraRange Self.postFxCam,0.5,1000.0
        CameraClsColor Self.postFxCam,0,0,0
        HideEntity Self.postFxCam

        Self.cameratex :TTexture=CreateTexture(GraphicsWidth(),GraphicsHeight(),1+256)
        ScaleTexture Self.cameratex ,1.0,-1.0
        CameraToTex Self.cameratex ,Self.Camera
        'Setup other textures here..
        TGlobal.CheckFramebufferStatus(GL_FRAMEBUFFER_EXT) ' check for framebuffer errors

        EntityOrder Self.sprite,-1
        ScaleSprite Self.sprite,1.0,Float( GraphicsHeight() ) / GraphicsWidth() ' 0.75
        MoveEntity Self.sprite,0,0,1.0 
        EntityParent Self.sprite,Self.Camera
        PositionEntity Self.Camera,0,7,0 ' move camera now sprite is parented to it
        MoveEntity Self.Camera,0,0,-25      

    End Method

    Method Update:TRenderPass()

        PositionEntity Self.postFxCam,EntityX(Self.Camera),EntityY(Self.Camera),EntityZ(Self.Camera)
        RotateEntity Self.postFxCam,EntityPitch(Self.Camera),EntityYaw(Self.Camera),EntityRoll(Self.Camera)

        If Self.Active = False Then
            HideEntity Self.postFxCam
            ShowEntity Self.Camera
            HideEntity Self.sprite      
            ShowEntity Self.postFxCam
            HideEntity Self.Camera
            HideEntity Self.sprite

            CameraToTex Self.cameratex,Self.postFxCam

            HideEntity Self.postFxCam
            ShowEntity Self.Camera
            ShowEntity Self.sprite      


    End Method

    Method Activate()
        Self.Active = True
    End Method

    Method DeActivate()
        Self.Active = False
    End Method

End Type

Example in just 5 Steps

PostFX is just a variable name and will just be used as an instance here, call it whatever you like..

  1. Init OpenB3D and create your instance, this will create main and postfx camera (Lines 4-5 below)...
Graphics3D width,height,depth,mode
SeedRnd MilliSecs()
ClearTextureFilters ' remove mipmap flag for postfx texture
Local PostFX:TRenderPass = TRenderPass.Create() 'Creates a Game and PostFX Camera
PostFX.Init() 'Creates PostFX Render Textures and Sprites for Shaders
PositionEntity,0,0,-5 'Re-align to original position from example
  1. Apply PostFX.cameratex field as ColorBuffer or Scene texture
ShaderTexture(shader1,PostFX.cameratex,"sceneTex",0) ' Our render texture
  1. Load the PostFX.sprite field to your shader
ShadeEntity(PostFX.sprite, shader)
  1. Field will now act as the main camera, update move rotate as standard camera.
  1. Update through PostFX.Update before Renderworld

Call PostFX.Activate and PostFX.Deactivate to toggle and PostFX.Active to check for state


Antialias example with a few changes using TRenderPass to add FXAA

(Posted 1 year ago)

Hi Ron,

this looks very nice, thanks!

I don't think I can add this to the core though as it needs customized, I'll add it to some of the shader examples.

(Posted 1 year ago)

I agree Mark. Yes, this is still a major work in progress and falls under preference or extension. Ah ok great, working it through the examples would be fine as well. thanks and cheers!

Reply To Topic

Please log in to reply