Announcement

Collapse
No announcement yet.

[SOLVED] Custom Iron Sight - Depth of Field Question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [SOLVED] Custom Iron Sight - Depth of Field Question

    Hey guys,

    Short version:

    Ive been working on depth of field for my iron sight views for a few days now and still could not come up with something that worked out. Ok here is what I want to achieve.



    A Depth of Field effect that just blurs out the weapon in iron sight and nothing else. How to do this?


    Long version:

    At first I tried to make my cam autofocus through unreal script using the default bokeh dof post process wich worked out well. The huge problem with that is that it blurs to much space on the screen. It just does not work out for a game. Its more suited for cutscence and stuff and I just couldn't achieve a good localized effect.

    The next thing I tried was a material effect wich uses scenedepth as a mask to lerp the normal scene with cheaply blurred scene(using UV Offset on the SceneTexture) but SceneDepth does not seem to work with foreground stuff like first person meshes.
    Even tho I think this is the right way to go I gave up on this one.

    Right now I use a photoshop painted mask to lerp between the untouched sceneTexture and the blured one and then enable/disable the effect via unrealscript, wich works out as intended, BUT. the mask is rigid. It does not move with the weaponbob. So every time I walk the mask is off a bit. The other problem I have is that my custom blur does not look good. Its just a simple box blur and I really would love to achieve the quality of the post process DoF and I have no clue how to do that.


    So what I really want is an hight quality DoF effect that just blurs the close parts of a weapon when in iron sight.


    please help me







    EDIT: I solved this with an Material Effect and a scene depth node and a custom blur.





    CUSTOM DOF FOR MOTHERJAVA



    Hey, I found a few mins yesterday to take screenshots, but I had no time left to post

    so here we go:



    first thing you have to do is to create PostProcessChain or use a existing one.

    [SHOT]http://i41.tinypic.com/vfwcv9.jpg[/SHOT]


    After that you have to create or edit an UberPostProcess node

    [SHOT]http://i40.tinypic.com/2m46nep.jpg[/SHOT]

    The next step:

    [SHOT]http://i40.tinypic.com/212ixq8.jpg[/SHOT]

    The most important step for the code to work is the Effect Name, also make sure to set DOF to FOCUS_Position, since this example only works with that and set MaxNear and MaxFar to something else than 0.



    Final Step in UDK:

    [SHOT]http://i43.tinypic.com/i39mxi.jpg[/SHOT]

    you have to set your PostProcessChain in the level. You have to redo this step for every new level you create.







    Now lets talk unrealscript.

    You have to find the PlayerTick function in your PlayerController Class and add these lines of code

    Code:
    function PlayerTick(float DeltaTime)
    {
    	local UberPostProcessEffect UberEffect;
    	local LocalPlayer PC;
    	
    	
    	local vector		HitLocation, HitNormal;
    	local Actor			HitActor;
    	local vector 		OutCamLoc;
    	local Rotator 		OutCamRot;
    	
    	GetPlayerViewPoint(OutCamLoc, OutCamRot);
    	
    	
    	HitActor = Trace(HitLocation, HitNormal, vector(OutCamRot) * 5000 * 20 + OutCamLoc, OutCamLoc, true);
    	
    	
    	if(HitActor == none)
    	{
    		HitLocation = vector(OutCamRot) * 5000 * 20 + OutCamLoc;
    	}
    	
    	PC = LocalPlayer(Player);
    	
    	if(PC != none && PC.PlayerPostProcess != none)
    	{
                    //this line uses the Effect Name we set in UDK to get a referenceof the UberPostProcessEffect
    		UberEffect = UberPostProcessEffect(  PC.PlayerPostProcess.FindPostProcessEffect('Uber'));
    		
    		if(UberEffect != none)
    		{
    			UberEffect.FocusPosition = HitLocation;
    		}
    	}
    	
            //this line is not need if you add this code to PlayerController.uc
    	Super.PlayerTick(DeltaTime);
    }




    Final notes:

    This effect only works with FOCUS_Position, if you want to change it to FOCUS_Distance, you have to calculate the distance between HitLocation and OutCamLocation and then you have to set UberEffect.FocusDistance = CalculatedDistance;


    Ok, there is absolutley no tweaking whatsoever. Its just quick and dirty code it threw together in 15mins of sparetime.

    Anyways. I don't think that this effect will ever work on a FPS game. In my opinion you have to write your own DOF Material Effect if you want real time DOF calculations that dont look ugly. The standard DOF effect really show a lot of artifacts and because of that it should just be used on CutScenes.

    #2
    Cant you make a pp box around the player that only got the dof set to close. and just enable the box around the player to start the dof that fits the zoom?

    Comment


      #3
      Originally posted by ZixXer View Post
      Cant you make a pp box around the player that only got the dof set to close. and just enable the box around the player to start the dof that fits the zoom?
      Is this the easiest or best way to implement auto focus dof in general? I'm at a loss as to how to achieve dynamic dof

      Comment


        #4
        hey, thanks for your help, but your approach did not work. The PPVolume does not take into account where it ends. When you step in you have pp for the whole world, even outside of the ppvolume box.

        But I solved in anyways... somehow. The solution was pretty simple. For some reason it now worked to use a PPMaterial and use the scene depth node and divided by 32.



        Last time I tried this, my weapon was not rendered. For some reason it works now.

        Comment


          #5
          woops, doublepost...


          edit: I will use this to answer this question


          Originally posted by MOTHERJAVA View Post
          Is this the easiest or best way to implement auto focus dof in general? I'm at a loss as to how to achieve dynamic dof

          there are serveral ways of doing this, but there is no way I know that works without UnrealScript.

          The best way is also pretty simple.

          Basically you just have to follow this tutorial.

          Instead of a material effect you take the UberPostProcessEffect and give it a name you can remember.

          After that you just have to acces the DOF setting via script and set the focusdistance to the distance of the actor your crosshair is hovering over(this is done by a simple distancetrace from the player camera).

          Comment


            #6
            Thanks man. I really really appreciate the help. I hadn't noticed the psst in your thread. .. are the dof settings located in the playercontroller.uc?

            Comment


              #7
              Sorry for all the questions.. Would this be correct?

              end = Location + normal(vector(Rotation))*32768; // trace to "infinity"
              traceHit = trace(loc, norm, end, Location, true,, hitInfo);

              Comment


                #8
                to answer your first question.

                the DOF settings are somewhere in the PostProcess object.

                you can acces this through the PlayerController using its function PostProcessEfect = PlayerPostProcess.FindPostProcessEffect('EffectNam e'));

                after that you can acces its properties/values and tweak DOF, Iam not sure how to acces this from the back of my head.....


                the trace is correct, just make sure to use this somewhere inside of the PlayerCamera object. BUT after that you still have to calculate the distance between the traceHit and your camera, since trace() returns an actor and not the distance or location you are looking for.

                So in the end you have to calculate the distance between traceHit.Location and the location of the cam.

                Comment


                  #9
                  Thanks again. I'm a relative newb to udk and have no experience whatsoever when it comes to unreal script , and I've been searching for a concrete way to do this for quite some time, so your advice is certainly appreciated..

                  How might I go about calculating the distance between the camera and trace.hitlocation? (sorry for asking so much about this).

                  Or even better- Is there any chance you could post a snippet of the completed code for the custom dof implementation so I can see what it is supposed to look like (and to prevent me from having to ask about every detail)? Seeing it completely would really help me understand how it works.

                  Thanks a TON! Your a godsend..

                  Comment


                    #10
                    I am in university all day, so I dont know when I will be able to do it, certainly not today.


                    Maybe tomorrow. But its not that hard. 15min of work if you know what you are doing in unrealscript. Rest of the time is tweaking the effect

                    Comment


                      #11
                      Understood ..

                      You mentioned in the other thread something about creating a material effect with a scene depth node... Is that necessary for this or would that be an alternative method? is editing the dof settings in script sufficient without this scene depth material? If not, how does this material factor in? Am I annoying you yet with this barrage of newbish inquiries?

                      Comment


                        #12
                        Hey, I found a few mins yesterday to take screenshots, but I had no time left to post

                        so here we go:



                        first thing you have to do is to create PostProcessChain or use a existing one.

                        [SHOT]http://i41.tinypic.com/vfwcv9.jpg[/SHOT]


                        After that you have to create or edit an UberPostProcess node

                        [SHOT]http://i40.tinypic.com/2m46nep.jpg[/SHOT]

                        The next step:

                        [SHOT]http://i40.tinypic.com/212ixq8.jpg[/SHOT]

                        The most important step for the code to work is the Effect Name, also make sure to set DOF to FOCUS_Position, since this example only works with that and set MaxNear and MaxFar to something else than 0.



                        Final Step in UDK:

                        [SHOT]http://i43.tinypic.com/i39mxi.jpg[/SHOT]

                        you have to set your PostProcessChain in the level. You have to redo this step for every new level you create.







                        Now lets talk unrealscript.

                        You have to find the PlayerTick function in your PlayerController Class and add these lines of code

                        Code:
                        function PlayerTick(float DeltaTime)
                        {
                        	local UberPostProcessEffect UberEffect;
                        	local LocalPlayer PC;
                        	
                        	
                        	local vector		HitLocation, HitNormal;
                        	local Actor			HitActor;
                        	local vector 		OutCamLoc;
                        	local Rotator 		OutCamRot;
                        	
                        	GetPlayerViewPoint(OutCamLoc, OutCamRot);
                        	
                        	
                        	HitActor = Trace(HitLocation, HitNormal, vector(OutCamRot) * 5000 * 20 + OutCamLoc, OutCamLoc, true);
                        	
                        	
                        	if(HitActor == none)
                        	{
                        		HitLocation = vector(OutCamRot) * 5000 * 20 + OutCamLoc;
                        	}
                        	
                        	PC = LocalPlayer(Player);
                        	
                        	if(PC != none && PC.PlayerPostProcess != none)
                        	{
                                        //this line uses the Effect Name we set in UDK to get a referenceof the UberPostProcessEffect
                        		UberEffect = UberPostProcessEffect(  PC.PlayerPostProcess.FindPostProcessEffect('Uber'));
                        		
                        		if(UberEffect != none)
                        		{
                        			UberEffect.FocusPosition = HitLocation;
                        		}
                        	}
                        	
                                //this line is not need if you add this code to PlayerController.uc
                        	Super.PlayerTick(DeltaTime);
                        }




                        Final notes:

                        This effect only works with FOCUS_Position, if you want to change it to FOCUS_Distance, you have to calculate the distance between HitLocation and OutCamLocation and then you have to set UberEffect.FocusDistance = CalculatedDistance;


                        Ok, there is absolutley no tweaking whatsoever. Its just quick and dirty code it threw together in 15mins of sparetime.

                        Anyways. I don't think that this effect will ever work on a FPS game. In my opinion you have to write your own DOF Material Effect if you want real time DOF calculations that dont look ugly. The standard DOF effect really show a lot of artifacts and because of that it should just be used on CutScenes.

                        Comment


                          #13
                          Thank you thank you thank you! Im sure your time is valuable and taking even 15 mins to just write that all down probably saved me 15 hours of frustration...lol

                          one problem, and im sure it's to do with what line im placing this code in, but unrealfrontend gives me this error " Src\Engine\Classes\PlayerController.uc(4737) : Error, 'PlayerTick' conflicts with 'Function Engine.PlayerController:PlayerTick' "

                          I tried placing it before the line that starts with : " Event PayerTick" ..... , as well as after that chunk of code, but the same error pops up in frontend.

                          Thank you kindly!!!

                          Comment


                            #14
                            In other words... does this code go anywhere in Playercontroller.uc, or is there a specific line that it should reside on...

                            and are we talking about engine.classes.playercontroller.uc, and not udkplayercontroller.c, right? or does it matter?

                            Edit: figured it out!

                            DennyRocket thanks for your patience and help.. Really appreciate it mate!


                            Any tweaks you personally recommend? Do you think using the distance would provide nicer results?

                            Comment


                              #15
                              hey, I was not online yesterday, but I am glad you figured it out.

                              There are a few things I tried to tweak. First thing was. Never set MaxNear and MaxFar BlurAmount to 1. anything lower than 1 gives nicer results.


                              The other thing is, that it just works with actors that have a collision applied to them. That means no collision, no location calculation. So you should make sure to apply simple colission to everything in your world.

                              Second thing is just the sky. Whenever you look at the sky the whole screen blurs out. In case the location is too far away you can calulate a location that is in sight but closer to the cam(but thats all vector math you have to dig into to solve this, and UnrealScript as well).

                              Next thing to tweak is the DOF interpolation. I mean whenever you switch between a near and a far DOF it just jumps instead of making a smooth transition. You could use the PlayerTickfunction in playercontroller.uc(that gets called every frame) to calulate a location that gets closer over time to the new location to smooth the focus transition out.

                              I don't think that FOCUS_Distance gives you an nicer effect in any way.

                              But again, there is still a nasty artifact in the standard DOF that shows up from time to time, at least on my machine. That is the reason I don't use it. Instead I just use a MaterialEffect to blur out certain positions on the screen.

                              Comment

                              Working...
                              X