Depth of Field?
BlitzMax Forums/MiniB3D Module/Depth of Field?
| ||
Just getting started with minib3d and I have limited 3d coding experience so appologies if I'm newbish. Is there any way to impliment a depth of field effect in minib3d? either easily (some magical "setcameraDoF" function I'm missing) or to fudge it in a more complex fashion (some objects I could attack to the camera at various distances that would blur to varying degrees everything past them...) |
| ||
HI, Since minib3d is inspired in blitz3d, you should check out blitz3d forum for more info. If you want a fade effect you could use "EntityAutoFade" to set the alpha accoding with the distance from the camera. But If you want a blur effect, you should try a filter in front of the camera or render twice, there are some codes in the archive and in the blitz3d forum: DreamFilter Montion Blur FX Motion blur 3d blur |
| ||
very cool, I was affraid it might be a little too simple to support something like that. It looks like I can find some way to do it, or atleast fudge it, in there somewhere. |
| ||
as far as i know, depth of field effects are done (or can be done) via Shaders. a Shader is a program that runs on the video cards GPU. miniB3D does not support shaders by default but user Klepto2 has created an extended version of minib3d that supports GLSL (OpenGL Shader Language) fish around these forums and you will find some stuff. check this out http://ati.amd.com/developer/gdc/Scheuermann_DepthOfField.pdf |
| ||
Hello ima747 try this code. The original code is for blitz3d. I have modified it for minib3d '; '; Depth of Field '; '; Created by Mikkel Fredborg '; Use as you please! '; ' Modified for Blitzmax by IceVAN/Purples Studios Import sidesign.minib3d Graphics3D 800,600,32,True 'SetBuffer BackBuffer() HideMouse '; '; Create a camera... camera = CreateCamera() CameraRange camera,0.1,1000.0 CameraFogMode camera,True CameraFogRange camera,100,1000 CameraClsColor camera,220,220,220 '; '; create some cubes For i = 0 To 300 cube = CreateCube() PositionEntity cube,Rnd(-200,200),Rnd(-200,200),Rnd(-200,200) RotateEntity cube,Rnd(-180,180),Rnd(-180,180),Rnd(-180,180) ScaleEntity cube,Rnd(1,20),Rnd(1,20),Rnd(1,20) EntityColor cube,Rand(0,255),Rand(0,255),Rand(0,255) Next '; '; Light light = CreateLight() RotateEntity light,90,0,0 '; Depth of Field setup Type DepthOfField Field layers Field layer[99] Field texture:ttexture Field tsize Field tbuffer:ttexture Field near#,far# Field camera End Type dof:DepthOfField = DOF_Create(camera,10,2.0) Repeat RotateEntity camera,MouseY(),MouseX(),0 MoveEntity camera,KeyDown(KEY_RIGHT)-KeyDown(KEY_LEFT),0,KeyDown(KEY_UP)-KeyDown(KEY_DOWN) DOF_Update(dof) RenderWorld Flip False Until KeyHit(KEY_ESCAPE) End Function DOF_Update(dof:depthoffield) HideEntity dof.layer[0] CameraRange dof.camera,dof.near*.95,1000 CameraViewport dof.camera,0,0,dof.tsize,dof.tsize RenderWorld ' CopyRect 0,0,dof.tsize,dof.tsize,0,0,BackBuffer(),dof.tbuffer BackBufferToTex(dof.tbuffer) ShowEntity dof.layer[0] CameraRange dof.camera,0.1,1000 CameraViewport dof.camera,0,0,GraphicsWidth(),GraphicsHeight() End Function Function DOF_Create:DepthOfField(camera,layers,spread#=0.0) dof:depthoffield = New depthoffield dof.camera = camera dof.layers = layers dof.tsize = 512 dof.near = 100.0 dof.far = 200.0 ClearTextureFilters dof.texture = CreateTexture(dof.tsize,dof.tsize,1+256+16+32) ' dof.tbuffer = TextureBuffer(dof.texture) dof.tbuffer = dof.texture ang# = 360.0/Float(dof.layers) For i = 0 To dof.layers-1 dof.layer[i] = CreateFace(1) EntityAlpha dof.layer[i],1.0/Float(dof.layers) EntityFX dof.layer[i],1+8+16 ps# = dof.near+(i*((dof.far-dof.near)/Float(dof.layers))) px# = Sin(i*ang)*(i/Float(dof.layers))*spread py# = Cos(i*ang)*(i/Float(dof.layers))*spread PositionEntity dof.layer[i],px,py,ps ScaleEntity dof.layer[i],ps,ps,1.0 EntityTexture dof.layer[i],dof.texture If i = 0 EntityParent dof.layer[i],dof.camera,True Else EntityParent dof.layer[i],dof.layer[i-1],True End If Next Return dof End Function Function CreateFace(segs=1,parent=0) mesh=CreateMesh( parent ) surf=CreateSurface( mesh ) stx#=-1.0 sty#=stx stp#=Float(2)/Float(segs) y#=sty For a=0 To segs x#=stx v#=a/Float(segs) For b=0 To segs u#=b/Float(segs) AddVertex(surf,x,y,0,u,v) ; 'swap these For a different start orientation x=x+stp Next y=y+stp Next For a=0 To segs-1 For b=0 To segs-1 v0=a*(segs+1)+b v1=v0+1 v2=(a+1)*(segs+1)+b+1 v3=v2-1 AddTriangle( surf,v0,v2,v1 ) AddTriangle( surf,v0,v3,v2 ) Next Next FlipMesh mesh UpdateNormals mesh 'EntityFX(mesh,17) Return mesh End Function |
| ||
Just gave it a try and works great. I've gotta tear it apparet and A) figure out what you did and B) tweak it so it works just right for my needs but yea, code archives for this perhaps? |