new post | browse code | authors | help | about

LuaBin 2.0

Viewing file root / lua / postprocess / sobel.lua

  1.  
  2. local SobelMaterial = Material( "pp/sobel" )
  3. SobelMaterial:SetMaterialTexture( "$fbtexture", render.GetScreenEffectTexture() );
  4.  
  5. // convars
  6. local pp_sobel_threshold = CreateClientConVar( "pp_sobel_threshold", "0.11", false, false );
  7. local pp_sobel = CreateClientConVar( "pp_sobel", "0", false, false );
  8.  
  9. /*------------------------------------
  10.         DrawSobel()
  11. ------------------------------------*/
  12. function DrawSobel( threshold )
  13.  
  14.  
  15.         // update threshold value
  16.         SobelMaterial:SetMaterialFloat( "$threshold", threshold );
  17.  
  18.         render.SetMaterial( SobelMaterial );
  19.         render.DrawScreenQuad();
  20.        
  21. end
  22.  
  23.  
  24. /*------------------------------------
  25.         DrawInternal()
  26. ------------------------------------*/
  27. local function DrawInternal()
  28.  
  29.         if ( !pp_sobel:GetBool() ) then return; end
  30.         if ( !GAMEMODE:PostProcessPermitted( "sobel" ) ) then return; end
  31.  
  32.         DrawSobel( pp_sobel_threshold:GetFloat() );
  33.  
  34. end
  35. hook.Add( "RenderScreenspaceEffects", "RenderSobel", DrawInternal );
  36.  
  37.  
  38. /*------------------------------------
  39.         BuildControlPanel()
  40. ------------------------------------*/
  41. local function BuildControlPanel( panel )
  42.  
  43.         panel:AddControl( "Header", { Text = "#Sobel", Description = "" }  )
  44.         panel:AddControl( "CheckBox", { Label = "#Enable", Command = "pp_sobel" }  )
  45.        
  46.         panel:AddControl( "Slider", {
  47.                 Label = "#Threshold",
  48.                 Command = "pp_sobel_threshold",
  49.                 Type = "Float",
  50.                 Min = "0",
  51.                 Max = "1"
  52.         } );
  53.  
  54. end
  55.  
  56. /*------------------------------------
  57.         AddPostProcessMenu()
  58. ------------------------------------*/
  59. local function AddPostProcessMenu()
  60.  
  61.         spawnmenu.AddToolMenuOption( "PostProcessing", "PPShader", "Sobel", "#Sobel", "", "", BuildControlPanel, { SwitchConVar = "pp_sobel" } );
  62.  
  63. end
  64. hook.Add( "PopulateToolMenu", "AddPostProcessMenu_Sobel", AddPostProcessMenu );
  65.