New DoF with DSLR model [WIP] need help

share shaders here
  • Author
  • Message
Offline
*blah-blah-blah maniac*
Posts: 565
Joined: 05 Apr 2014, 10:29
Location: Taiwan

Re: New DoF with DSLR model [WIP] need help

Black area are where the blur diameter is < 1 pixel( set temp to 0 to disable it), I forgot to reset default value.
_________________
Intel Xeon L5639 6C12T @3.96GHz | Gigabyte ga-x58a-ud3r | MSI GTX680 4G | 48G RAM | Intel 760p Nvme w clover bootloader
Flickr
YouTube

Offline
User avatar
*blah-blah-blah maniac*
Posts: 530
Joined: 30 Jan 2012, 13:18

Re: New DoF with DSLR model [WIP] need help

Can I use your focussing in my own DOF shader? Would be great, my own one is crappy and I don't like the ones from other DOF shaders...

Offline
*blah-blah-blah maniac*
Posts: 565
Joined: 05 Apr 2014, 10:29
Location: Taiwan

Re: New DoF with DSLR model [WIP] need help

Sure. here is the clean version.

Code: Select all


bool MF_MODE <	string UIName="MF mode";> = {false};

float FocalPlaneDepth <
	string UIName="MF Focal Plane (m)";
	string UIWidget="Slider";
	float UIMin=0.00;
	float UIMax=1000.00;
> = {0.00};

float FocalLength <
	string UIName="Focal Length (mm)";
	string UIWidget="Slider";
	float UIMin=0.00;
	float UIMax=1000.00;
> = {35};

float F_Number <
	string UIName="F_Number";
	string UIWidget="Slider";
	float UIMin=0.00;
	float UIMax=1000.00;
> = {5.6};

float TS_Axis <
	string UIName="TS_rotation";
	string UIWidget="Slider";
	float UIMin=0.00;
	float UIMax=180;
	float UIStep=1;
> = {0};

float TS_Angle <
	string UIName="TS_angle";
	string UIWidget="Slider";
	float UIMin= -10;
	float UIMax= 10;
> = {0};


float zF = 3000;
float zN = 0.15;

float linearizeDepth(float zB)
{
	return zF * zN / (zF + zB * ( zN - zF));
}

float4 PS_CoCtoAlpha(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{
	float2 coord = IN.txcoord;		
	float4 res = tex2D(SamplerColor, coord);
	float depth = linearizeDepth(tex2D(SamplerDepth, coord).x);	
	
	float FilmWide = 0.0359;//D3X, 35mm film
	float TS_Dist = ((coord.x - 0.5) * tan(TS_Axis * 0.0174533) - ScreenSize.z * ( coord.y - 0.5)) / length(float2( tan(TS_Axis * 0.0174533), ScreenSize.z)) * FilmWide;		
	
	float CenterFocusDepth = ( MF_MODE == true)? FocalPlaneDepth : tex2D(SamplerFocus, 0.5).x;
	float focallength = FocalLength / 1000;
	float PrincipalDist = CenterFocusDepth * focallength / (CenterFocusDepth - focallength);
	PrincipalDist += tan( TS_Angle * 0.0174533) * TS_Dist;

	float FocusDepth = PrincipalDist * focallength / (PrincipalDist - focallength);
	res.w = (focallength / F_Number ) * (abs(depth - FocusDepth) / depth) * (PrincipalDist / FocusDepth); 


	res.w /= FilmWide;// in % to x	[0, 1]
	return res;
}

_________________
Intel Xeon L5639 6C12T @3.96GHz | Gigabyte ga-x58a-ud3r | MSI GTX680 4G | 48G RAM | Intel 760p Nvme w clover bootloader
Flickr
YouTube
Post Reply