G.DrawSunbeams

From GMod Wiki

Jump to: navigation, search
Function
Syntax DrawSunbeams( Float Darken ,Float Multiplier, Float SunSize, Float Screen X, Float Screen Y )
Where is this used?
Description:
Used by the "Sunbeams" Post-processing effect. It draws beams of light coming from the map's "sun".
Returns: nil
Part of Library: Global Functions
Realm: NewerClient.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=G.DrawSunbeams]G.DrawSunbeams [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionModified version of the Sunbeams effect used in the Sandbox Gamemode, except you can modify the sunbeams direction a bit, and process even though there is an obstruction between you and the sun, It isn't the best example.
Used onNewerClient.png
Code
if CLIENT then
	local ppex_sunbeams 			= CreateClientConVar( "ppex_sunbeams", 				"0", 		true, false )
	local ppex_sunbeams_ignore 		= CreateClientConVar( "ppex_sunbeams_ignore", 			"0", 		false, false )
	local ppex_sunbeams_darken	= CreateClientConVar( "ppex_sunbeams_darken", 		"0.95", 	false, false )
	local ppex_sunbeams_multiply  = CreateClientConVar( "ppex_sunbeams_multiply", 	"1.0", 		false, false )
	local ppex_sunbeams_sunsize	= CreateClientConVar( "ppex_sunbeams_sunsize", 		"0.075", 	false, false )
 
	local ppex_sunbeams_x_offset	= CreateClientConVar( "ppex_sunbeams_x_offset", 		"0.000", 	false, false )
	local ppex_sunbeams_y_offset	= CreateClientConVar( "ppex_sunbeams_y_offset", 		"0.000", 	false, false )
	local ppex_sunbeams_z_offset	= CreateClientConVar( "ppex_sunbeams_z_offset", 		"0.000", 	false, false )
 
	local function DrawInternal()
		local modx = ppex_sunbeams_x_offset:GetFloat()
		local mody = ppex_sunbeams_y_offset:GetFloat()
		local modz = ppex_sunbeams_z_offset:GetFloat()
 
		local sun = util.GetSunInfo()
		if (!sun) then return end
 
		if !ppex_sunbeams_ignore:GetBool() && (sun.obstruction == 0) then return end
 
		sun.direction.x = sun.direction.x + modx
		sun.direction.y = sun.direction.y + mody
		sun.direction.z = sun.direction.z + modz
 
		local sunpos = EyePos() + sun.direction * 4096
		local scrpos = sunpos:ToScreen()
 
		local dot = (sun.direction:Dot( EyeVector() ) - 0.8) * 5
		if (dot <= 0) then return end
 
		local newmul = ppex_sunbeams_multiply:GetFloat()
		if ppex_sunbeams_ignore:GetBool() then
			newmul = newmul * dot
		else
			newmul = newmul * dot * sun.obstruction
		end
 
		DrawSunbeams( ppex_sunbeams_darken:GetFloat(),
					newmul,
					ppex_sunbeams_sunsize:GetFloat(), 
					scrpos.x / ScrW(), 
					scrpos.y / ScrH()
					);
 
	end
	hook.Add( "RenderScreenspaceEffects", "CocksPostProcess", DrawInternal )
 
	/*
	// Control Panel
	*/
	local function BuildControlPanel( CPanel )
 
		CPanel:AddControl( "Header", { Text = "Sun Beams EX", Description = "Sun Beams EX" }  )
		CPanel:AddControl( "CheckBox", { Label = "#Enable", Command = "ppex_sunbeams" }  )
		CPanel:AddControl( "CheckBox", { Label = "Ignore Obstruction", Command = "ppex_sunbeams_ignore" }  )
 
		CPanel:AddControl( "Slider", { Label = "#Multiply", Command = "ppex_sunbeams_multiply", Type = "Float", Min = "0", Max = "1" }  )
		CPanel:AddControl( "Slider", { Label = "#Darken", Command = "ppex_sunbeams_darken", Type = "Float", Min = "0", Max = "1" }  )
		CPanel:AddControl( "Slider", { Label = "#Sun Size", Command = "ppex_sunbeams_sunsize", Type = "Float", Min = "0.01", Max = "0.25" }  )	
 
		CPanel:AddControl( "Slider", { Label = "Sun X Offset", Command = "ppex_sunbeams_x_offset", Type = "Float", Min = "-1.5", Max = "1.5" }  )
		CPanel:AddControl( "Slider", { Label = "Sun Y Offset", Command = "ppex_sunbeams_y_offset", Type = "Float", Min = "-1.5", Max = "1.5" }  )
		CPanel:AddControl( "Slider", { Label = "Sun Z Offset", Command = "ppex_sunbeams_z_offset", Type = "Float", Min = "-1.5", Max = "1.5" }  )
	end
 
	/*
	// Tool Menu
	*/
	local function AddPostProcessMenu()
		spawnmenu.AddToolMenuOption( "PostProcessing", "PPShader", "SunBeamsMod", "Sun Beams Mod", "", "", BuildControlPanel, { SwitchConVar = "ppex_sunbeams" } )
	end
	hook.Add( "PopulateToolMenu", "AddPostProcessMenu_SunBeamsEX", AddPostProcessMenu )
 
end
 
OutputN/A


Additional Notes

See Also


Color wheel.pngPost Processing

Hook: RenderScreenspaceEffects


Functions:
- DrawBloom -
- DrawColorModify -
- DrawMaterialOverlay -
- DrawMorph -
- DrawMotionBlur -
- DrawSharpen -
- DrawSobel -
- DrawSunBeams -
- DrawToyTown -


For usage of the Sandbox Post Processing menu, see Post Processing Menu.

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox