How to change Focal point Position?

fixing bugs
Post Reply
  • Author
  • Message
Offline
Posts: 2
Joined: 08 Sep 2023, 09:59

How to change Focal point Position?

Hi, i am having some problems with the focal point position in Fallout 4 v0.489, when aiming any weapon, the DOF blur all my vision because of the weapon, how do i change the Focal point position? here is the code and the image:

https://terabox.com/s/14afZE0ECIyrz866uYLRdlg

/////////////////////////////////////////////////////////
// DEPTH OF FIELD //
/////////////////////////////////////////////////////////

void VS_DOF(in float3 inpos : POSITION, inout float2 txcoord0 : TEXCOORD0, out float4 outpos : SV_POSITION)
{
outpos = float4(inpos.xyz,1.0);
}

float GetLinearDepth(float2 coords)
{
float depth = TextureDepth.SampleLevel(Sampler1, coords.xy,0).x;
depth *= rcp(DepthParameters.y + depth * DepthParameters.z);
return depth;
}

float3 GetPosition(float2 coords)
{
return float3(coords.xy*2.0-1.0,1.0)*GetLinearDepth(coords.xy)*DepthParameters.y;
}

float GetBayerFromCoordLevel(float2 pixelpos, int maxLevel)
{
float finalBayer = 0.0;

for(float i = 1-maxLevel; i<= 0; i++)
{
float bayerSize = exp2(i);
float2 bayerCoord = floor(pixelpos * bayerSize) % 2.0;
float bayer = 2.0 * bayerCoord.x - 4.0 * bayerCoord.x * bayerCoord.y + 3.0 * bayerCoord.y;
finalBayer += exp2(2.0*(i+maxLevel))* bayer;
}

float finalDivisor = 4.0 * exp2(2.0 * maxLevel)- 4.0;
return finalBayer/ finalDivisor + 1.0/exp2(2.0 * maxLevel);
}

float GetCoC(float2 texcoord)
{
float scenedepth = GetLinearDepth(texcoord.xy);
float scenefocus = TextureFocus.Sample(Sampler0, texcoord.xy ).x;
float scenecoc = 0.0;

scenefocus = smoothstep(0.0,fADOF_InfiniteFocus,scenefocus);
scenedepth = smoothstep(0.0,fADOF_InfiniteFocus,scenedepth);

float farBlurDepth = scenefocus*pow(4.0,fADOF_FarBlurCurve);

if(scenedepth < scenefocus)
{
scenecoc = (scenedepth - scenefocus) / scenefocus;
scenecoc *= fADOF_NearBlurMult;
}
else
{
scenecoc=(scenedepth - scenefocus)/(farBlurDepth - scenefocus);
scenecoc *= fADOF_FarBlurMult;
scenecoc=saturate(scenecoc);
}

scenecoc = (scenedepth < 0.00000001) ? 0.0 : scenecoc; //first person models, that epsilon is handpicked, do not change
scenecoc = saturate(scenecoc * 0.5 + 0.5);
return scenecoc;
}


float3 BokehBlur(Texture2D colortex,
float2 coords,
float discRadius,
float centerDepth,
int nQuality,
int nVertices,
float BokehCurve)
{
float4 res = float4(pow(colortex.Sample(Sampler1, coords.xy).xyz,BokehCurve),1.0);
float ringIncrement = rcp(nQuality);


float2 discRadiusScaled = discRadius*float2(fADOF_ShapeAnamorphRatio,ScreenSize.z)*0.0006*ringIncrement;


float2 currentVertex,nextVertex,matrixVector;
sincos(radians(fADOF_ShapeRotation),currentVertex.y,currentVertex.x);
sincos(6.2831853 / nVertices,matrixVector.x,matrixVector.y);

float2x2 rotMatrix = float2x2(matrixVector.y,-matrixVector.x,matrixVector.x,matrixVector.y);

#if(bADOF_ShapeWeightEnable != 0)
res.w *= saturate(1.0f-fADOF_ShapeWeightAmount*nQuality);
res.xyz *= res.w;
#endif



[fastopt]
for(float iRings = 1; iRings <= nQuality && iRings <= 25; iRings++)
{
[fastopt]
for (int iVertices = 1; iVertices <= nVertices && iVertices <= 9; iVertices++)
{
nextVertex = mul(currentVertex.xy, rotMatrix);

[fastopt]
for (float iSamplesPerRing = 0; iSamplesPerRing < iRings && iSamplesPerRing < 25; iSamplesPerRing++)
{
float2 sampleOffset = lerp(currentVertex,nextVertex,iSamplesPerRing/iRings);
sampleOffset *= lerp(1.0,rsqrt(dot(sampleOffset,sampleOffset)),fADOF_ShapeCurvatureAmount);


float4 tap = colortex.SampleLevel(Sampler1, coords.xy + (sampleOffset.xy * discRadiusScaled) * iRings,0);

tap.w = (centerDepth > 0.5) ? saturate(abs(tap.w*2.0-1.0)-iRings*ringIncrement*abs(centerDepth*2.0-1.0)) : 1.0; //I believe this is almost perfect.




#if(bADOF_ShapeWeightEnable != 0)
tap.w *= lerp(1.0,pow(iRings*ringIncrement,fADOF_ShapeWeightCurve),fADOF_ShapeWeightAmount);
#endif

res.xyz += pow(tap.xyz,BokehCurve)*tap.w;
res.w += tap.w;
}

currentVertex = nextVertex;
}
}
res.xyz = pow(max(0.0,res.xyz/res.w),rcp(BokehCurve));
return res.xyz;
}

float4 ChromaticAberration(float2 tex)
{
float d = distance(tex, float2(0.5, 0.5));
float f = smoothstep(fBaseRadius, fFalloffRadius, d);
float3 chroma = pow(f + fvChroma, fChromaPower);

float2 tr = ((2.0 * tex - 1.0) * chroma.r) * 0.5 + 0.5;
float2 tg = ((2.0 * tex - 1.0) * chroma.g) * 0.5 + 0.5;
float2 tb = ((2.0 * tex - 1.0) * chroma.b) * 0.5 + 0.5;

float3 color = float3(TextureColor.Sample(Sampler0, tr).r, TextureColor.Sample(Sampler0, tg).g, TextureColor.Sample(Sampler0, tb).b) * (1.0 - f);

return float4(color, 1.0);
}


float4 ChromaticAberration(float2 tex, float outOfFocus)
{
float d = distance(tex, float2(0.5, 0.5));
float f = smoothstep(fBaseRadius, fFalloffRadius, d);
float3 chroma = pow(f + fvChroma, CHROMA_POW * outOfFocus * fChromaPower);

float2 tr = ((2.0 * tex - 1.0) * chroma.r) * 0.5 + 0.5;
float2 tg = ((2.0 * tex - 1.0) * chroma.g) * 0.5 + 0.5;
float2 tb = ((2.0 * tex - 1.0) * chroma.b) * 0.5 + 0.5;

float3 color = float3(TextureColor.Sample(Sampler0, tr).r, TextureColor.Sample(Sampler0, tg).g, TextureColor.Sample(Sampler0, tb).b) * (1.0 - outOfFocus);

return float4(color, 1.0);
}

Offline
Posts: 2
Joined: 08 Sep 2023, 09:59

Re: How to change Focal point Position?

I just found a solution, for anyone looking for a similar problem, this was the fix

//SHARPENING
#define show_sharpen 0
#define sharp_clamp 0.01
#define offset_bias lerp(1.0,0.85,sharp_strength*0.1)
#define CoefLuma float3(0.2125, 0.7154, 0.0721)

//LENS DISTORTION
#define fFisheyeZoom 0.53-(LCAStrength*0.1)
#define fFisheyeDistortion 0.02
#define fFisheyeDistortionCubic LCAStrength
#define fFisheyeColorshift 0.0000


//DOF
#define bADOF_AutofocusEnable 1
#define fADOF_AutofocusCenter float2(0.5,0.42) <------ I changed this from 0.5,0.5 to 0.5,0.42 :D /////////////////////// HERE ////////////////////////////
#define iADOF_AutofocusSamples 5
#define fADOF_AutofocusRadius 0.02
#define fADOF_ManualfocusDepth 0.05
#define bADOF_ShapeWeightEnable 1
Post Reply