Page 1 of 1

Lens Flare effect example

Posted: Sun Apr 13, 2014 12:38 pm
by applePi
an approximation of the lensFlare using the ribbon example as a frame
we use the function

Code: Select all

CreateLensFlareEffect(#Effect, CameraID, NodeID, BurstSize, HaloSize, HaloMaterialID, CircleMaterialID, BurstMaterialID)
i think we should look with an angle relative to the sun/light to see the effect such as

Code: Select all

CameraLookAt(0, 1000-eyeMove, 1000, 500)
just a primary example since there are about 3 types of lens flare
use Left/ right keys to change the lens flare effect by changing the CameraLookAt x direction, just for fun we change the flare color to orange or green when we look left or right
Image

Code: Select all

IncludeFile "Screen3DRequester.pb"

Define yaw.f, X.f, Y.f, Z.f, FOV.f, Timer.i, eyeMove.f
#LensFlare = 27
#flareMat = 30

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/OPE/material_scripts", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Packs/desert.zip", #PB_3DArchive_Zip)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  If Screen3DRequester()
    
    ; Ground
    ;
    GetScriptMaterial(0, "Scene/GroundBlend")
    GetScriptMaterial(#flareMat, "PE/lensflare")
        
    CreatePlane(0, 10000, 10000, 100, 100, 50, 50)
    CreateEntity(0, MeshID(0), MaterialID(0))
    
    ; Camera
    ;
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 2000, 100, 2000, #PB_Absolute)
    CameraLookAt(0, 0, 1500, 0)
    CameraFOV(0, 60)
    
    ; Node for lensflare
    ;
    CreateNode(0, 0, 500, 0)
    
       
    CreateLensFlareEffect(#Lensflare, CameraID(0), NodeID(0), 10, 100, MaterialID(#flareMat), MaterialID(#flareMat), MaterialID(#flareMat))
   
     
    
    ; Skybox
    ;
    SkyBox("desert07.jpg")
        
    Repeat
      Screen3DEvents()
                     
            
      If KeyboardPushed(#PB_Key_Left)
        eyeMove+5
        If eyeMove > 30
          LensFlareEffectColor(#LensFlare, #PB_LensFlare_HaloColor , RGB(254,232,180))
        EndIf
      ElseIf KeyboardPushed(#PB_Key_Right)
        eyeMove-5
        If eyeMove < 30
          LensFlareEffectColor(#LensFlare, #PB_LensFlare_HaloColor , RGB(100,232,180))
        EndIf
      EndIf
      
      MoveNode(0, 0, 1000, 0, #PB_Absolute)
      
      ;Camera
      FOV = 60 - 30 * Cos(ElapsedMilliseconds() / 2500)
      ;RotateCamera(0, 1000, 0, 0)
      CameraFOV(0, FOV)
      CameraLookAt(0, 1000-eyeMove, 1000, 500)
         
      
      RenderWorld()
      Screen3DStats()
      FlipBuffers()
      
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

Re: Lens Flare effect example

Posted: Thu Apr 17, 2014 4:28 pm
by heartbone
Although my Windows XP installation is using a low end Intel 8294G Express on motherboard graphics chipset,
it can run most 3D programs.
However when attempting to run your example through my 5.21 LTS compiler applePi,
I receive an error "Line: 26 - The specified #Material is not initialised."

Code: Select all

26    CreateEntity(0, MeshID(0), MaterialID(0))
Can you tell what might be wrong?
Thanks.

Re: Lens Flare effect example

Posted: Thu Apr 17, 2014 7:54 pm
by DK_PETER
@Heartbone

Your paths are probably wrong:

Change the following lines to:

Code: Select all

IncludeFile #PB_Compiler_Home + "Examples/3D/Screen3DRequester.pb"
And....

Code: Select all

If InitEngine3D()
 
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/OPE/material_scripts", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)

Re: Lens Flare effect example

Posted: Thu Apr 17, 2014 8:23 pm
by applePi
@heartbone , with the DK_PETER correction the example will run from any folder such as if we save it to the desktop. but with my first post the example will run only if saved to the PureBasic\Examples\3D folder like the original "Ribbon.PB" example which i used it as a base. i will use DK_PETER way from now on.
regarding the lens flare, i am trying to remember where i saw it before, is it in real life or in a movie, usually we will consider it harmful for the eye . it will be great and funny if most people saw the lens flare from a movie only since the director camera may reflect the light like that especially in a documentary videos.

Re: Lens Flare effect example

Posted: Thu Apr 17, 2014 8:48 pm
by heartbone
@ DK_PETER and applePi, I understand the problem and solution.
Thank you for the answer.

Nice demo. 8)