PANEL = {}
local BlurSize = 0.5
local pnlWindow = nil
local Window = nil
local Status = "Preview"
local sldDistance = nil
local lblDistance = nil
local lblSize = nil
local FocusGrabber = false
local ScreenshotTimer = 0
local strTitle
= Localize( "SuperDOF_WindowTitle",
"Super DOF" )
local strBlurSize
= Localize( "SuperDOF_BlurSize",
"Blur Size:" )
local strDistance
= Localize( "SuperDOF_Distance",
"Focus Distance:" )
local strRender
= Localize( "SuperDOF_Render",
"Render" )
local strScreenshot
= Localize( "SuperDOF_Screenshot",
"Save Screenshot" )
local strOpenWindow
= Localize( "SuperDoF_Open",
"Open Window" )
local strInformation
= Localize( "SuperDoF_Warning",
"Warning: This is VERY experimental so it might not totally work on your graphics card. \n\nThis effect is not realtime. You render it and then save a screenshot of your render. Also, you will have low fps when previewing - that's normal.")
function PANEL:Init()
self:SetTitle( strTitle )
self.BlurSize:SetMin( 0 )
self.BlurSize:SetMax( 10 )
self.BlurSize:SetDecimals( 3 )
self.BlurSize:
SetText( strBlurSize
)
self.BlurSize:SetValue( BlurSize )
function self.BlurSize:OnValueChanged( val ) BlurSize = val end
function self.Render:DoClick() Status = "Render" end
self.Screenshot:
SetText( strScreenshot
)
end
function PANEL:ChangeDistanceTo( dist )
end
function PANEL:PerformLayout()
end
local matFSB
= Material( "pp/motionblur" )
local function RenderDoF( vOrigin, vAngle, vFocus, fAngleSize, radial_steps, passes, drawhud )
local view
= { x
= 0, y
= 0, w
= ScrW(), h
= ScrH(), drawhud
= drawhud
}
local fDistance
= vOrigin:
Distance( vFocus
)
fAngleSize
= fAngleSize
* math.Clamp( 256/fDistance,
0.1,
1 ) * 0.5
view.origin = vOrigin
view.angles = vAngle
// Straight render (to act as a canvas)
local Radials
= (math.pi*2) / radial_steps
for mul=(1 / passes), 1, (1 / passes) do
local VA = vAngle * 1 // hack - this makes it copy the angles instead of the reference
// Rotate around the focus point
ViewOrigin
= vFocus - VA:
Forward() * fDistance
view.origin = ViewOrigin
view.angles = VA
// Render to the front buffer
// Copy it to our floating point buffer at a reduced alpha
local alpha
= (Radials
/(math.pi*2)) // Divide alpha by number of radials
alpha = alpha * (1-mul) // Reduce alpha the further away from center we are
end
end
// Restore RT
// Render our result buffer to the screen
end
if ( FocusGrabber ) then
Status = "Preview"
end
if ( Status == "Preview" ) then
// A low quality, pretty quickly drawn rough outline
RenderDoF( ViewOrigin, ViewAngles, FocusPoint, BlurSize, 2, 2, 1 )
elseif ( Status == "Render" ) then
// A great quality render..
RenderDoF( ViewOrigin, ViewAngles, FocusPoint, BlurSize, 16, 8, 1 )
Status = "ViewShot"
elseif ( Status == "ViewShot" ) then
end
end
local function RenderSceneHook( ViewOrigin, ViewAngles )
// Don't render it when the console is up
return true;
end
hook.Add( "RenderScene",
"RenderSuperDoF", RenderSceneHook
)
local function OpenWindow()
Status = "Preview"
return end
end
/*---------------------------------------------------------
Mouse button down
---------------------------------------------------------*/
local function MouseDown( mouse )
FocusGrabber = true
end
/*---------------------------------------------------------
Mouse button released
---------------------------------------------------------*/
local function MouseUp( mouse )
FocusGrabber = false
end
hook.Add( "GUIMousePressed",
"SuperDOFMouseDown", MouseDown
)
hook.Add( "GUIMouseReleased",
"SuperDOFMouseUp", MouseUp
)
/*
// Control Panel
*/
local function BuildControlPanel( CPanel )
CPanel:Help( strInformation )
CPanel:Button( strOpenWindow, "pp_superdof" )
end
/*
// Tool Menu
*/
local function AddPostProcessMenu()
end
hook.Add( "PopulateToolMenu",
"AddPostProcessMenu_SuperDoF", AddPostProcessMenu
)