havok2 Posted May 3, 2020 Posted May 3, 2020 (edited) Update 24.05.2020: New Download Links in this Post Update 05.05.2020: Download Depth Of Field 2.0 OvGME Ready - Thanks Morpheus. Update 05.08.2020: Download Heatair V2.0 OvGME Ready Update 05.11.2020: Download MotionBlur V2.0 OvGME Ready Scientific article about Boke from Zeiss [GER] Hello pilots and modders, as an owner of a film company, a problem jumped right into my eye at DCS. For some reason (the reason is: ED uses Focal Length as well as Focal Distance and Distance for calculation. That is correct. But in DCS the zoom is not controlled by the focal length, but by the zoom - equivalent to a digital zoom. But this is not considered in the formula. Would be correct in reality, but nobody zooms this far lossless digitally and let's be honest - it doesn't look cool! And they missed the distance from the Camera to the Object to be noticed) the depth of field is not really calculated correctly. As you can see in the following picture, the background gets blurred the more you increase the focal length or simply zoom in. This is true for the same aperture, of course. But currently it looks like this in DCS. (v2.5.5) Wide Normal Tele Furthermore, the further you are away from the object, the less blurred the background becomes. At this point I am really a filmmaker and not a mathematician or full-time programmer. However, with my rudimentary knowledge and a lot of time of reverse code reading I have been working on the DOF.fx. You can find it here: *DCS Installation Path*\Bazar\shaders\PostEffects\DOF.fx The formula used here is obviously correct focalWidth * abs(focalDistance-dist)/dist but various parameters seem to be identical all the time especially the focalDistance and focalWidth where the latter should be called focalLength. Therefore the maximum blur does not change when zooming, nor when changing the distance to the object. Even worse. It has the effect that the image becomes sharper when zooming in. Simply because you have more image and details at the same bokeh. First of all I tried to transfer the real values from the camera into the formula. For this purpose I read out the zoom, the target point of the camera as well as the camera position, because these values seem to remain always the same in the current DOF.fx of DCS. Strangely enough I had to leave the value focalDistance in the formula anyway. So my calculation is still far away from perfection. Unfortunately, without debugging I don't know what values and value ranges DCS spits out here. So I had to test a lot with try and error. I have edited the following lines and tried to correct the incorrect calculation. At the beginning #include "../common/samplers11.hlsl" #include "../common/states11.hlsl" #include "common/context.hlsl" //added to get access to some camera values out of the game then the function of getBlurFactor float getBlurFactor(float dist) { //get game camera values float near = gNearFarFovZoom.x; //get nearest point rendered float far = gNearFarFovZoom.y; //get farest point rendered float zoom = gNearFarFovZoom.w; //get fov value of the camera float3 camOrigin = gOrigin; //get camera origin float3 camPosition = gCameraPos; //get camera pos //calculations float focalLength = 1/zoom; //it looks like the zoom is defined from 0.0 - 1.0 where 0 is the largest zoom - with more zoom you get more bokeh - simply inverted that thing and called it like what it is in our context float clipminmax = far-near; //calc the distance between clipping - that is normaly the range where the depth map is calculated and I think the dist value is something between 0.0-1.0 float3 d = camOrigin-camPosition; //calc absolut values of x,y,z - distance float cameraDistance = sqrt((d.x * d.x)+(d.y * d.y)+(d.z * d.z)); //calc absolut direct distance aka focalDistance (Pythagorean theorem) cameraDistance = 1/clipminmax*cameraDistance; //remap the distance to something like 0.0-1.0 float aperture = 2.8;//the standard blur looks like aperture 1 - this multiplier reduces the heavy blur (https://en.wikipedia.org/wiki/Aperture) aperture = aperture*aperture; //calc the size of the bokeh with this aperture. The aperture² gives you the ammount of reducing light. Also its the ammount the bokeh decreases. For example 1 = 1. Maximum Bokeh. At Aperture 1.4 you have the half ammount of light and the half size of bokeh. //output return focalLength * abs(cameraDistance + focalDistance - dist)/dist/aperture; //default -> focalWidth * abs(focalDistance-dist)/dist; | I cannot delete focalDistance, then you see extreme blur. In theory that means that my calculation of cameraDistance is wrong. I'm pretty sure it is, but hey at this moment it works. } float getRadius(float2 uv) { #ifdef MSAA float depth = DepthMap.Load(uint2(uv*dims), 0).r; #else float depth = DepthMap.Load(uint3(uv*dims, 0)).r; #endif float4 p = mul(float4(uv*2-1, depth, 1), invProj); float f = getBlurFactor(p.z/p.w); return pow(f, 1.5); //does the boke effect really grow exponentially with distance? - but this does enlarge the area where it is sharp. Default 1.5. } and then something for the performance here #define GOLDEN_ANGLE 2.39996323 #define NUMBER 150.0 #define ITERATIONS_STEP 8 //increasing this value means more fps because of less calculations. But also the look is different. Less iterations creates smaller bokeh. There is something in the loop down. Maybe in it could prevent. #define ITERATIONS (GOLDEN_ANGLE * NUMBER) // This creates the 2D offset for the next point. // (r-1.0) is the equivalent to sqrt(0, 1, 2, 3...) float2 Sample(in float theta, inout float r) { r += 1.0 / r; return (r-1.0) * float2(cos(theta), sin(theta)) * .06; } float3 Bokeh(Texture2D tex, float2 uv, float radius, float amount) { float3 acc = float3(0,0,0); float3 div = float3(0,0,0); float2 pixel = float2(aspect, 1.0) * radius * .025; float r = 1.0; for (float j = 0.0; j < ITERATIONS; j += ITERATIONS_STEP) { //using here ITERATIONS_STEP instead of GOLDEN_ANGLE float2 s = Sample(j, r); float2 tuv = uv + pixel * s; // rebuild tuv float nr = min(getRadius(tuv), radius); tuv = uv + pixel * s * (nr/radius); float3 col = tex.Sample(ClampLinearSampler, tuv).rgb; float3 bokeh = float3(5.0, 5.0, 5.0) + pow(col, 9.0) * amount; acc += col * bokeh; div += bokeh; } return acc / div; } The code can be optimized for all cases, but is easier to understand at this stage! This is how it looks like after my tuning. Wide Normal Tele and... Wide Normal Tele I would be glad about feedback and further developments to make DCS even more beautiful. Best greetings from Germany! Edited May 24, 2021 by havok2 added Post Icon, changed code snipped, added DL Link 3 2
diogofalcao Posted May 3, 2020 Posted May 3, 2020 Congrats for the amazing job! Pictures looks great. A-10C / AJS-37 / AV-8B / BF-109 / KA-50 / F-14 / F-16C / F-5E / F/A-18C / FC3 / JF-17 / F-86 / M-2000C / MiG-21bis / P-51D / Spitfire LF Mk. IX / UH-1H Huey
havok2 Posted May 3, 2020 Author Posted May 3, 2020 Thanks diogofalcao, the engine can produce really nice effects, but unfortunately there are very few possibilities especially for replays. For example, there is no way to set the aperture, which is the main control for the depth of field. This is more or less hard coded and can be edited in the DOF.fx. Also concerning motionblur, there are no possibilities to vary it. Of course the focus is more on flying, but the basic camera functions should at least be implemented (correctly) =)
FoxDelta Posted May 4, 2020 Posted May 4, 2020 very nice effect, well done my projects: https://www.sim-addons.com/ https://www.shapeways.com/shops/sim-addons-1 AV8B nozzle lever https://forums.eagle.ru/showthread.php?t=233670 F18C fingerlifts https://forums.eagle.ru/showthread.php?t=234747 F18C radar elevation https://forums.eagle.ru/showthread.php?t=248080
==Wiggy== Posted May 4, 2020 Posted May 4, 2020 Incredible! THANK YOU! Cheers, Rick CSEL\CMEL\IFR Certified Airplane Nut
Mustang Posted May 4, 2020 Posted May 4, 2020 (edited) This looks very nice, well done! BTW are you using Bokeh or Simple for your DOF? Also, is it at all possible to make this work from within the cockpit view? P.S just tested your values and they do look amazing with very liitle impact on performance. Edited May 4, 2020 by Mustang 2
havok2 Posted May 4, 2020 Author Posted May 4, 2020 Hello, Mustang, very nice screenshots. I use Bokeh myself, because it comes closest to a real photo/video recording. But I think you could play around with the intensity a bit. Of course it is always an individual feeling, what looks nice and what doesn't. Therefore I always try to include the possibility to adjust the intensity myself. Depth of Field in the cockpit would be nice! Of course only very discreetly on the horizon. Soon I will slim down the code first and then I can have a look around in the files to see if I find something about it. Since many things are not documented and partly in Russian, I don't want to give false hopes at this point. Greetings.
Fri13 Posted May 4, 2020 Posted May 4, 2020 (edited) DOF is a magnification related. More you magnify the subject by either moving camera closer to subject or using longer focal length, then shallower the DOF is. But if you keep subject magnification same (same size in the FOV) then DOF is same when F-stop value is same (like f/5.6) and format is same (sensor / film size), meaning your focal length or distance to subject is irrelevant. And as longer focal length narrow the field of view, the background gets cropped more behind the subject and so on gets blurrier even if DOF is identical with same magnification when using shorter focal length (wider field of view), but background becomes then more clear as it is smaller. Need to try this modification as the blur effect is so bad in DCS and this seems to fix it. Next, waiting ED to add environmental elements to targeting systems and overall vision so that targeting pods resolution becomes realistically low 640*480 and it gets blurry, and even more blurrier at distance as haze affect it, and then have a FLIR that is blurry and gets just blurrier when using zoom at distance and especially digital zoom. Edited May 4, 2020 by Fri13 i7-8700k, 32GB 2666Mhz DDR4, 2x 2080S SLI 8GB, Oculus Rift S. i7-8700k, 16GB 2666Mhz DDR4, 1080Ti 11GB, 27" 4K, 65" HDR 4K.
havok2 Posted May 4, 2020 Author Posted May 4, 2020 Hey Fri13, thanks for your input. Are you sure there's no effect from the distance? I briefly unpacked my Canon 77D and took photos with 25mm, 50mm, 100mm and 200mm at aperture 2.8. Here is the series of pictures with the same distance. 25mm 50mm 100mm 200mm Here is the row of pictures with different distances to compare the Bokeh Close Mid Far The greater the distance, the greater the sharpness range. This of course also reduces the bokeh in the background. For example, when I take a landscape photo with my 11mm lens everything is in focus. But if I take a close up photo of a flower, this landscape will appear completely out of focus at the same focal length and aperture. But how exactly now the mathematical connections are... I would have to read a lot or do a small test series at home and measure everything correctly.
Strut Posted May 4, 2020 Posted May 4, 2020 This is a great fix , thanks Havok, great work mate !! Regards DL available skins here: https://www.digitalcombatsimulator.com/en/files/?CREATED_BY=Strut Pictures of my Skins here: https://imgur.com/a/bOQyQqW [sIGPIC][/sIGPIC] Win10 64bit, Intel® Core i7-5820K CPU OC @ 4.50GHz x6, X99A GAMING PRO CARBON, MSI RTX 2080 TI GAMING X TRIO 11Gb, 32GB DDR4 RAM, SSD 960 EVO250GB, SSD 850 EVO 500GB, JetSeat, MFG Crosswind Pedals, VPC Mongoose T-50, TMWH, DSD ButtonBox, Pimax 5k XR/BE
JumboJBT Posted May 5, 2020 Posted May 5, 2020 Hello I'm very interested about this topic. As a beginner could you tell me which program I need to use for editing DOF.FX Sorry about my question Patrice
Morpheus Posted May 5, 2020 Posted May 5, 2020 Hello I'm very interested about this topic. As a beginner could you tell me which program I need to use for editing DOF.FX Sorry about my question Patrice Notepad++ fait très bien l'affaire (gratuit) Notepad++ (free) will do it
havok2 Posted May 5, 2020 Author Posted May 5, 2020 New Version Hey pilots, I have done a lot of testing and try and error. Now it is little bit more correct in some points and the code is cleaner. Try yourself - just copy & paste: You can edit line: 48 for your own DOF strength and line: 71 to increase or decrease visual quality and performance impact. Don't forget to make a backup file :thumbup: #include "../common/samplers11.hlsl" #include "../common/states11.hlsl" #include "common/context.hlsl" //added to get access to some camera values out of the game Texture2D Source; #ifdef MSAA Texture2DMS<float, MSAA> DepthMap; #else Texture2D<float> DepthMap; #endif uint2 dims; float4 viewport; float4x4 invProj; float focalDistance, focalWidth; float aspect, bokehAmount; struct VS_OUTPUT { noperspective float4 pos: SV_POSITION0; noperspective float2 texCoords: TEXCOORD0; }; static const float2 quad[4] = { float2(-1, -1), float2(1, -1), float2(-1, 1), float2(1, 1), }; VS_OUTPUT VS(uint vid: SV_VertexID) { VS_OUTPUT o; o.pos = float4(quad[vid], 0, 1); o.texCoords = float2(o.pos.x*0.5+0.5, -o.pos.y*0.5+0.5)*viewport.zw + viewport.xy; return o; } float getBlurFactor(float dist) { //get game camera values float zoom = gNearFarFovZoom.w; //get fov value of the camera float3 camOrigin = gOrigin; //get camera origin float3 camPosition = gCameraPos; //get camera pos //calculations float focalLength = (1/zoom)-0.41667305; //I added this, so the distance will be a multiplier of the blur strengh. The smallest value that zoom can have is the golden angle defined in line 67. This is 180° FOV and then the DOF is Zero. float3 d = camOrigin-camPosition; //calc absolut values of x,y,z - distance float cameraDistance = sqrt((d.x * d.x)+(d.y * d.y)+(d.z * d.z)); //calc absolut direct distance aka focalDistance (Pythagorean theorem) cameraDistance = cameraDistance/100000; //I divded the camera distance with 100000 (cm? so its 1km?) so at minimal zoom we get nearly the lowest DOF - this is not physical based, but approximately good enough - have tried and error this value. //USER CAN EDIT THIS VALUE BELOW. USE lower Values for more DOF and higher values for less. 1, 1.4, 2.0, 3.5, 4, 5.6, 8 - of course you can use every number you want when you like pi for example float aperture = 4.0;//the standard blur looks like aperture 1 - this multiplier reduces the heavy blur (https://en.wikipedia.org/wiki/Aperture) aperture = aperture*aperture; //calc the size of the bokeh with this aperture. The aperture² gives you the ammount of reducing light. Also its the ammount the bokeh decreases. For example 1 = 1. Maximum Bokeh. At Aperture 1.4 you have the half ammount of light and the half size of bokeh. //output return focalLength * cameraDistance * abs(focalDistance - dist) / dist / aperture; //default -> focalWidth * abs(focalDistance-dist)/dist; | I cannot delete focalDistance, then you see extreme blur. In theory that means that my calculation of cameraDistance is wrong. I'm pretty sure it is, but hey at this moment it works. } float getRadius(float2 uv) { #ifdef MSAA float depth = DepthMap.Load(uint2(uv*dims), 0).r; #else float depth = DepthMap.Load(uint3(uv*dims, 0)).r; #endif float4 p = mul(float4(uv*2-1, depth, 1), invProj); float f = getBlurFactor(p.z/p.w); return pow(f, 2.0); //does the boke effect really grow exponentially with distance? - but this does enlarge the area where it is sharp. Default 1.5. } #define ONEOVER_ITR 1.0 / ITERATIONS #define PI 3.141596 // This is (3.-sqrt(5.0))*PI radians, which doesn't precompiled for some reason. #define GOLDEN_ANGLE 2.39996323 #define NUMBER 150.0 #define ITERATIONS_STEP 8//increasing this value means more fps because of less calculations. But also the look is different. Less iterations creates smaller and "worser" bokeh and sometimes dotted star looking bokeh. There is something in the loop down. Some values are a sweet spot. #define ITERATIONS (GOLDEN_ANGLE * NUMBER) // This creates the 2D offset for the next point. // (r-1.0) is the equivalent to sqrt(0, 1, 2, 3...) float2 Sample(in float theta, inout float r) { r += 1.0 / r; return (r-1.0) * float2(cos(theta), sin(theta)) * .06; } float3 Bokeh(Texture2D tex, float2 uv, float radius, float amount) { float3 acc = float3(0,0,0); float3 div = float3(0,0,0); float2 pixel = float2(aspect, 1.0) * radius * .025; float r = 2.5; //default = 1.0 - this is smootging the bokeh what is neccessary because of less samples for (float j = 0.0; j < ITERATIONS; j += ITERATIONS_STEP) { //using here ITERATIONS_STEP instead of GOLDEN_ANGLE float2 s = Sample(j, r); float2 tuv = uv + pixel * s; // rebuild tuv float nr = min(getRadius(tuv), radius); tuv = uv + pixel * s * (nr/radius); float3 col = tex.Sample(ClampLinearSampler, tuv).rgb; float3 bokeh = float3(5.0, 5.0, 5.0) + pow(col, 9.0) * amount; acc += col * bokeh; div += bokeh; } return acc / div; } float4 PS(const VS_OUTPUT i): SV_TARGET0 { return float4(Bokeh(Source, i.texCoords.xy, 0.5, bokehAmount), 1.0); } technique10 LinearDistance { pass P0 { SetVertexShader(CompileShader(vs_4_0, VS())); SetGeometryShader(NULL); SetPixelShader(CompileShader(ps_4_0, PS())); SetDepthStencilState(disableDepthBuffer, 0); SetBlendState(disableAlphaBlend, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF); SetRasterizerState(cullNone); } } Some Screenshots, because DCS is so beautyful:
JumboJBT Posted May 5, 2020 Posted May 5, 2020 Yeah !!!!! Pictures are amazing. Thanks for that. Cheers.
havok2 Posted May 5, 2020 Author Posted May 5, 2020 Thanks Morpheus, I didn't know the tool before, but I'm still quite new in the DCS universe.
JumboJBT Posted May 6, 2020 Posted May 6, 2020 Hi Havok2, You are able to do such useful mod in DCS as a newbee. Definitively can not wait your future project. Cheers.
Morpheus Posted May 6, 2020 Posted May 6, 2020 Thanks Morpheus, I didn't know the tool before, but I'm still quite new in the DCS universe. Just help :smilewink:
dali Posted May 6, 2020 Posted May 6, 2020 havok2, thank your for this, ED should include it into DCS. As DCS "zoom lenses" insofar were producing incorrect result, I never used it. But now, you have opened possibilty for realistic virtual "photo-shoots" :)
davidp57 Posted May 6, 2020 Posted May 6, 2020 havok2, thanks, this looks wonderful ! Zip - VEAF :pilotfly: If you want to learn, talk and fly with french-speaking friends, the Virtual European Air Force is here for you ! Meet us on our Discord and our forum If you're a mission creator, you may want to check the VEAF Mission Creation Tools (and its GitHub repository) a set of open-source scripts and tools that make creating a dynamic mission a breeze !
havok2 Posted May 7, 2020 Author Posted May 7, 2020 Hi Havok2, You are able to do such useful mod in DCS as a newbee. Definitively can not wait your future project. Cheers. Hey JumboJBT, thank you! Programming and modding are not completely foreign to me. I first built a mod for myself in the game Morrowind 2002. At Oblivion, the German translation was really bad at that time and my German mod was on many magazine CDs and was loaded several hundred thousand times. Unfortunately, real life grabbed me when my youth was over, but thanks to the crisis I have some time again. By necessity. My daily work also revolves around After Effects and 3D rendering. So it should be useful. I've even adjusted the heat effect and the motion blur a little bit, if you're interested in watching it, I can post the files as well. Currently, however, after 50 flying hours with takeoff and landing training on land and on the aircraft carrier, I concentrate on learning the weapon systems of the F-18. However, the adaptation of the DOF.fx was a need for me =D
JumboJBT Posted May 7, 2020 Posted May 7, 2020 Hi Havok2, Interested with your work on heat effect and motion blur so far. Because of this crisis, I'm Learning more on M2000 and F16. As an Airline pilot, I'm stuck at home for an extra couple of months. Your work is excellent. Congrats.
Eight Ball Posted May 7, 2020 Posted May 7, 2020 :surprise: I have no words. More realistic, makes the game look better and in my case it's actually more FPS friendly than the default DOF. Thank you so much for this!!! :clap: 1 Find The Links To All My Mods And Liveries Here (in the gallery)
JumboJBT Posted May 8, 2020 Posted May 8, 2020 Eight Ball, And make your F-16 or F-18 pictures amazing. Cheers
Recommended Posts