I'm pretty sure I know where the problem is, but I'm not sure how to fix the code. The game I'm trying to make has a lot of polygons so I really need to be able to hide objects when they're not in the screen.
Global BloomShaderEffectID as integer = 22
Global QuadShaderEffectID as integer = 23
Global FullScreenShaderPlane as integer = 5000
Global FullscreenShaderImage as integer = 2
Global BackdropColor as dword
BackdropColor = rgb(0,0,0) // the camera 0 backdrop is not usedm this variable is for setting the bloom camera backdrop to the same value as camera 0.
Global NrOfbjects as integer = 100
Sync On
Reload Display Pointer // Needed for fullscreen shaders to work properly
Color Backdrop BackdropColor
InitFullscreenShaders()
make object sphere 1, 20, 20, 20
hide object 1
Do
rem mouse look
yrotate camera wrapvalue( camera angle y() + mousemovex() / 4.0 )
xrotate camera wrapvalue( camera angle x() + mousemovey() / 4.0 )
position camera camera position x(), height#, camera position z()
if camera angle x() < 308 and camera angle x() > 300 then xrotate camera 308 'limit up
if camera angle x() < 70 and camera angle x() > 60 then xrotate camera 60 'limit down
UpdateFullScreenShaders()
Sync
Loop
Function InitFullscreenShaders()
Local TempVector as integer = 5000
// Make the "bloom camera" and set the backdrop color
Make Camera 1
Color Backdrop 1, BackdropColor
// load the bloom shader as a camera effect and set the "bloom camera" to draw on "FullscreenShaderImage"
Load Camera Effect "postbloom.fx",BloomShaderEffectID,0
Set Camera Effect 1,BloomShaderEffectID,FullscreenShaderImage
// FullScreenShaderPlane is the "canvas" where the camera image is drawn and later displayed.
Make Object Plain FullScreenShaderPlane,2,2,1
Set Object Radius FullScreenShaderPlane,-1
// Load and apply the quad shader to the "canvas" plane. The quad shader aligns the "canvas" plane to point at the camera and stretches it across the screen.
Load Effect "quad.fx",QuadShaderEffectID,0
Set Object Effect FullScreenShaderPlane,QuadShaderEffectID
// We need to set the "ViewSize" variable in the bloom shader so it knows how large our screen is.
null = Make Vector4(TempVector)
Set Vector4 TempVector, Screen Width(), Screen Height(),0,0
Set Camera Effect Constant Vector BloomShaderEffectID,"ViewSize",TempVector
null = Delete Vector4(TempVector)
// Texture the quad (canvas) plane with the image from the bloom camera.
Texture Object FullScreenShaderPlane,0, FullscreenShaderImage
EndFunction
Function UpdateFullScreenShaders()
// Before "sync" the bloom camera is placed at the correct position to view the scene.
position camera 1,camera position x(0),camera position y(0),camera position z(0)
rotate camera 1,camera angle x(0),camera angle y(0),camera angle z(0)
// Show all objects to the bloom camera. and hide the "canvas" plane so the bloom camera will not see it
ShowObjectsForFullscreenShader()
hide object FullScreenShaderPlane
// Sync the bloom camera and hide all objects again, performance degrades if both cameras has to draw all objects.
sync camera 1
HideObjectsForFullscreenShader()
// show the "canvas plane".
show object FullScreenShaderPlane
// Tell the "Sync" command to only sync camera 0 from here on.
sync mask %001
EndFunction
Function HideObjectsForFullscreenShader()
// All objects in the scene has to be hidden after the scene has been drawn to the bloom camera.
// Performance degrades if objects are drawn to both cameras.
For i = 1 To NrOfbjects
IF Object Exist(i)
Hide Object i
Endif
Next
endfunction
Function ShowObjectsForFullscreenShader()
// Show all objects (to the bloom camera only)
For i = 1 To NrOfbjects
If Object Exist(i)
Show Object i
Endif
Next
Endfunction
http://mattsmith.carbonmade.com/