Game Development Community

Depth of Field not working

by Haru Ruben · in Torque 3D Professional · 08/10/2009 (10:59 pm) · 25 replies

even when i echo "DOFPostEffect.isEnabled();"
it accepts it and nothing happens, no effect

al the other FX i tested worked as expected
Page «Previous 1 2
#2
08/11/2009 (1:59 am)
Try it by looking through the rifle scope (alt-fire) in the FPS Genre Kit. It's more subtle and not as "overblown" as the previous effect.
#3
08/11/2009 (2:09 pm)
The problem is that its so subtle that its nearly invisible.

I've talked with James and we're turing the effect back up... it may be a bit exaggerated... but we won't get people saying its not working.

Also the API was confusing... we're cleaning that up.

Sorry that its taken this long to get this right.
#4
08/12/2009 (10:57 am)
If you look at DOF in any games that use it, it's always a bit exaggerated, and if you think of it as the DOF effect that happens with your peripheral vision being combined with your center vision, the blurring effect should be very exaggerated, except that a monitor doesn't really represent an eye all that well.

I personally didn't think the DOF in Beta 4 was that far off the mark, it just needed to be more accurate about what layers it blurred (which has already been taken care of in Beta 5 according to the changelog).
#5
08/12/2009 (12:47 pm)
Preparing my "WOAH... DOF is way too exaggerated" post.
#6
08/12/2009 (2:07 pm)
Ok did some work on DOF last night and I will post how to integrate those changes here. That way it will hopefully get some testing and gather any important feedback before the next release and have DOF in a final state for it.

Changes are fairly spread out between multiple files unfortunately...


-------------------------------------------------------------
Change #1 - engine/source/math/mConsoleFunctions.cpp

Added these new ConsoleFunctions:
ConsoleFunction( mSaturate, F32, 2, 2, "(float number) Clamp between 0 and 1" )
{
   F32 val = dAtof( argv[1] );
   return mClampF( val, 0.0f, 1.0f );
}

ConsoleFunction( getMax, F32, 3, 3, "(float number, float number) Return the greater number." )
{
   F32 v0 = dAtof( argv[1] );
   F32 v1 = dAtof( argv[2] );
   return getMax( v0, v1 );
}

ConsoleFunction( getMin, F32, 3, 3, "(float number, float number) Return the lesser number." )
{
   F32 v0 = dAtof( argv[1] );
   F32 v1 = dAtof( argv[2] );
   return getMin( v0, v1 );
}

ConsoleFunction( mLerp, F32, 4, 4, "(float f0, float f1, float t) Linearly interpolate between f0 and f1 given time t.")
{
   F32 f0 = dAtof( argv[1] );
   F32 f1 = dAtof( argv[2] );
   F32 t = dAtof( argv[3] );
   return mLerp( f0, f1, t );
}


-------------------------------------------------------------
Change #2 - engine/source/postFx/postEffect.cpp

Added this line 289 (in PostEffect::onAdd):
// Call onAdd in script
   Con::executef(this, "onAdd", Con::getIntArg(getId()));


-------------------------------------------------------------
Change #3 - Genre Kits/FPS Genre Kit/game/scripts/client/client.cs

Replace these two functions starting line 107:
function clientCmdsetZoom(%reticle)
{
   $ZoomOn = true;
   setFov($Pref::Player::CurrentFOV);
   zoomReticle.setBitmap("art/gui/weaponHud/"@ detag(%reticle));
   Reticle.setVisible(false);
   zoomReticle.setVisible(true);  
   
   DOFPostEffect.setAutoFocus( true );
   DOFPostEffect.setFocusParams( 0.5, 0.5, 50, 500, -5, 5 );
   DOFPostEffect.enable();    
}

function clientCmdUnSetZoom(%reticle)
{
   $ZoomOn = false;
   setFov($Pref::Player::defaultFOV);
   Reticle.setVisible(true);
   zoomReticle.setVisible(false);   
   
   DOFPostEffect.disable();
}


-------------------------------------------------------------
Change #4 - (your project)/game/core/scripts/client/postFx.cs

Remove these two lines at the end of the file:
if($pref::PostEffect::DOF)
      DOFPostEffect.enable();


-------------------------------------------------------------
Change #5 - (your project)/game/shaders/common/postFx/dof/DOF_DownSample_P.hlsl

Replace line 9 with this:
uniform float maxWorldCoC;

Replace line 66 with this:
coc[i] = clamp( dofEqWorld.x * depth + dofEqWorld.y, 0.0, maxWorldCoC );


-------------------------------------------------------------
Change #6 - (your project)/game/shaders/common/postFx/dof/DOF_Final_P.hlsl

Replace line 13 with this:
uniform float maxFarCoC;

Replace line 110 with this:
farCoc = clamp( dofEqFar.x * depth + dofEqFar.y, 0.0, maxFarCoC );


-------------------------------------------------------------
Change #7 - (your project)/game/core/scripts/client/postFx/dof.cs

And finally... totally replace with this file. Password is Torque3DBeta.

#7
08/12/2009 (2:14 pm)
Notes:

The API for controling DOF has been improved greatly (imo) and large amounts of documentation added to dof.cs - take a read. This is the primary change I hope to get feedback on.

Other Notes:

Expected behavior in the FPS Genre Kit should be: normally no visible DOF effect except when zoomed in with the sniper.

DOF should not be turned on/off from the game options checkbox ( in the trunk this checkbox has already been removed) because DOF requires to be initialized with valid parameters that control the DOF quality - you cannot merely turn it on or off without doing that first.

The smoothing of near/far eq or focal dist over time has been removed as it was never really working well. Auto-focus is instantaneous and adding a "smoothed" effect on top of this is left to the user (sorry).
#8
08/12/2009 (7:27 pm)
James, You mentioned in change #5: to Replace line 66 of DOF_DownSample_P.hlsl with this:
coc[i] = saturate( dofEqWorld.x * saturate( depth + depthOffset ) + dofEqWorld.y );
..I think you meant to say this:
coc[i] = saturate( dofEqWorld.x * saturate( depth + maxWorldCoC ) + dofEqWorld.y );

plz advise.

//edit
if that is true, then here is a console error: DOF_DownSample_P.hlsl(66,13): warning X3550: array reference cannot be used as an l-value; not natively addressable, forcing loop to unroll
#9
08/12/2009 (7:47 pm)
That's a warning, not an error, and it's okay.
#10
08/13/2009 (12:40 am)
..at least I can spell "error" from the letters given in that "warning". :P [/meant to be funny]
#11
08/14/2009 (9:19 pm)
hmmmm...I've just gotten around to implementing this change, and I still see no difference. I spent ages moving the scope around to various distances trying to see if I can notice any chance in focus on nearby areas, but there is no noticable change. I have noticed a shader error that I didn't notice before however:
Mapping string: MissionStartPhase2Ack to index: 1
GFXD3D9Shader::_compileShader - Error compiling shader: E_FAIL: An undetermined error occurred (80004005)
   C:/Torque/Torque 3D 2009 Beta 5/Genre Kits/FPS Genre Kit/game/shaders/common/water/waterP.hlsl(137,23): error X3004: undeclared identifier 'prepassUncondition'
GFXD3D9Shader::_compileShader - Error compiling shader: E_FAIL: An undetermined error occurred (80004005)
   C:/Torque/Torque 3D 2009 Beta 5/Genre Kits/FPS Genre Kit/game/shaders/common/water/waterP.hlsl(137,23): error X3004: undeclared identifier 'prepassUncondition'

Would this shader failing to compile perhaps stop further shaders from compiling?

EDIT: Just loaded up a template project after having implemented this and DOF definitely works there as it was apparently enabled in the prefs which meant when the missions started up the entire map beyond 20 ft or so was blurred out. I did find that the DOF doesn't work on transparent objects when in front of the scattersky though (ie. trees sticking up over the horizon weren't blurred at all while the parts under the horizon were)
#12
08/14/2009 (10:24 pm)
@Bryan
Thanks for taking the time, I know its a lot of changes...


That shader error has been pretty long-lived and it shouldn't have any effect on DOF.

Keep in mind that DOF will only work with AL, BL does not have prepass-depth which it requires.

I would recommend for testing purposes to only apply these changes to the FPS Genre Kit project. I really shouldn't have implied it would work elsewhere by putting the (your project) in the change paths.

Concerning the trees sticking up over the horizon... hopefully you weren't seeing that on the trees in warriorcamp. They should be set to use alphatest - which does write depth so DOF can work. However... for alphaBlend materials they cannot write depth so when DOF is processed it will only see the depth behind it.

If you want to have DOF occur before all transparent objects are rendered ( which would fix that but also might look a bit weird ) you can make this change

core/scripts/client/postFx/dof.cs

replace line 374 and 375 with:

renderTime = "PFXBeforeBin";
renderBin = "ObjTranslucentBin";
#13
08/15/2009 (5:41 am)
Bryan, did you alter anything besides what James mentioned ?
I can't see a single difference..nothing is DOF, it is still just distance blur.
#14
08/15/2009 (9:33 am)
The problem is that there was no difference at all when applying those changes to the FPS kit, however when applied to the template project I could get a very noticable DOF by toggling it in options, but then it's uncontrollable so you wouldn't want it on all the time without the additional infrastructure. I was using AL in both the FPS kit and the template project. When zooming in and out on the FPS kit with the sniper rifle there was no noticable difference no matter where on the level I was or how far away the reticle was looking. As for the DOF not affecting trees in warrior camp, that's not a problem as it's not affecting anything at all :D

Here's some pictures to show what I'm getting:

DOF disabled in template project: Here

DOF enabled in template project: Here

DOF should be enabled in FPS kit during scope but no noticable blur in any range: Here

I apologize for any trouble this may be causing as I know that shader effects are the most frustrating to debug.

Also if the DOF is supposed to be something similar to what I'm seeing in the template with it enabled, then it is definitely very exaggerated.
#15
08/15/2009 (2:50 pm)
I'll try installing Beta5 "retail" and applying my own changes. Maybe I'll spot something I missed.
#16
08/15/2009 (3:30 pm)
Ok first problem, which eb spotted.

change #5: to Replace line 66 of DOF_DownSample_P.hlsl with this:
coc[i] = clamp( dofEqWorld.x * depth + dofEqWorld.y, 0.0, maxWorldCoC );
That is the CORRECT line. Also fixed this in my original post.

With this correction, DOF is working for me, having applied my own changes to the Beta5 retail.
#17
08/15/2009 (7:41 pm)
Ok, I changed the shader and it possibly looks better in the template project, but it still won't work in the FPS kit. Could you perhaps give a screenshot of what we're supposed to be seeing?

Either way, I figure Beta 6 will have it fixed or changed, and it's quite possible I just missed something.
#18
08/15/2009 (8:11 pm)
In focus:
i167.photobucket.com/albums/u143/heretek/torque/BURG_inFocus-1.png

Out of focus:
i167.photobucket.com/albums/u143/heretek/torque/BURG_outFocus-1.png

Warrior Camp, extreme range (out of focus, everything is blurred)
i167.photobucket.com/albums/u143/heretek/torque/WC_noFocus-1.png

Warrior Camp, far range (notice that near and medium range are blurred)
i167.photobucket.com/albums/u143/heretek/torque/WC_far-1.png

Warrior Camp, medium range (notice that far and near range are blurred)
i167.photobucket.com/albums/u143/heretek/torque/WC_med-1.png
#19
08/16/2009 (12:31 am)
Thx for the screens Michael! ;)

I see what Bryan meant by trans and the sky. yikes-ish!
#20
08/16/2009 (4:04 pm)
Okay, thanks for the screenshots. I'm definitely not getting anything after those changes. I'll have to redo it all to see if I missed anything, otherwise just wait for Beta 6 since I don't need it anyways.
Page «Previous 1 2