------ All content © 2008 DigiPen (USA) Corporation, all rights reserved. ------
-- Author: Matt Anderson
-- Updated: 02/17/2009

--------------------------------------------------------------------------------
-- load render passes


-- shadow casters from light perspective
Global:AddRenderPass(
	"gShadow",
	1,
	"TARGET", "Shadow",
	"WINDOWSIZE", "1024 1024",
	"CLEAR", "none",
	"CULL", "Front",
	"SHADOWTRANSFORM", "none",
    5,
    "IsCaster"
)
--[[

-- blur vsm 
Global:AddRenderPass(
	0,
	"WINDOWSIZE", "1024 1024",
	"TARGET", "ShadowAux0",
	"SOURCE", "0 0 0 Shadow",
	"MATERIAL", "pDownsample",
	"FULLSCREENQUAD", "2 2",
	"TARGET", "ShadowAux1",
	"SOURCE", "0 0 0 ShadowAux0",
	"MATERIAL", "pBlurHorz",
	"FULLSCREENQUAD", "2 2",
	"TARGET", "ShadowAux0",
	"SOURCE", "0 0 0 ShadowAux1",
	"MATERIAL", "pBlurVert",
	"FULLSCREENQUAD", "2 2",
	13,
	"BlurVSM"
)
--]]
-- light first pass
-- fills "g-buffer" with normals and position data
Global:AddRenderPass(
    "gNentity",
    "lfFlat",
    "lfVine",
    "lfMoon",
    "lfDock",
    "lfGroundGrassFirefly",
    "lfGround",
    "lfSky",
    8,
	"TARGET", "LightFirst",
	"CLEAR", "none",
	"DEPTHBIAS", "none",
	3,
	"LightFirst"
)

-- directional lights are rendered as full screen
-- quads in deferred rendering. also adding an ambient
-- term here. in the future this could be optimized
-- with the stencil buffer or z-buffer to skip shading
-- the sky
Global:AddRenderPass(
    0,
	"TARGET", "Light",
	"SOURCE", "0 0 0 LightFirst",
	"SOURCE", "1 0 0 Shadow",--Aux0",
	"MATERIAL", "LightPass", --"pAmbientOcclusion", --
	"FULLSCREENQUAD", "1 1",
	5,
	"AmbientPass"
)

-- light pass, rendering all the point lights in the 
-- scene. for both of these passes, reading in the 
-- position and normal values to calculate lighting
-- saving to light buffer
Global:AddRenderPass(
	0,
	"TARGET", "Light",
	"SOURCE", "0 0 0 LightFirst",
	"BLEND", "One One",
	"CULL", "Front",
	"DEPTH", "GreaterEqual",
	"NODEPTH", "none",
	"RENDERL", "lflPointLight",
	7,
	"LightPass"
)

-- geometry pass, here rendering all scene geometry
-- a second time, using lighting which has already been 
-- computed per pixel. because has already been rendered once
-- the depth buffer is filled and only the top most layer
-- gets rendered a second time.

-- Note: here rendering to aux2, which has depth buffer
-- attached.
Global:AddRenderPass(
    "gaFlat",
    "gaLantern",
    "gaAster",
    "gaVine",
    "gaMoon",
    "gaDock",
    "gaGroundGrass",
    "gaFirefly",
    "gaGround",
    "gaGround1",
    "gaGround2",
    "gaGround3",
    "gaGround4",
    "gaGround5",
    "gaSky",
    "gaFireflyParticle",
    "gaBlueFireflyParticle",
    "gaFireflyGetParticle",
    "gaRing",
    "gaRingInner",
    "gaTitle",
    21,  
	"TARGET", "Aux2",
	"SOURCE", "0 0 0 Light",
	"SOURCE", "1 0 1 LightFirst",
	3,
	"GeometryAfter"
)

--[[
Global:AddRenderPass(
	0,
	"TARGET", "Aux2",
	"SOURCE", "0 0 0 LightFirst",
	"BLEND", "One One",
	--"CULL", "Front",
	--"DEPTH", "GreaterEqual",
	"NODEPTH", "none",
	"RENDERL", "lRain",
	5,--7,
	"RainPass"
)
--]]
--[[
Global:AddRenderPass(
	0,
	"TARGET", "Light",
	"SOURCE", "0 0 0 LightFirst",
	"BLEND", "SourceAlpha InvSourceAlpha",
	"RENDER", "lWater",
	4,
	"WaterPass"
)
--]]

--[[--]]
-- edge detection. could become something else
-- used to enhance painterly look
Global:AddRenderPass(
	0,
	"TARGET", "BackBuffer",
	"SOURCE", "0 0 0 Aux2",
	"MATERIAL", "pAdditiveSobel",
	"FULLSCREENQUAD", "1 1",
	4,
	"PostProcessEdgeDetect"
)
--[[
-- Feedback blurred version of last frame
Global:AddRenderPass(
	0,
	"TARGET", "Aux3",
	"SOURCE", "0 0 0 Aux0",
	"MATERIAL", "pFeedbacker",
	"FULLSCREENQUAD", "1 1",
	4,
	"Feedbacker"
)
--]]
--[[
-- motion blur. i think it is very nice looking,
-- but perhaps unnecessary, could have a more
-- fitting effect added
Global:AddRenderPass(
	0,
	"TARGET", "Aux2",
	"SOURCE", "0 0 0 Aux3",
	"SOURCE", "1 0 1 LightFirst",
	"MATERIAL", "pMotionBlur",
	"FULLSCREENQUAD", "1 1",
	5,
	"PostProcessMotionBlur"
)

-- motion blur not working, but need in other buffer
-- just copy over
Global:AddRenderPass(
    0,
    "TARGET", "BackBuffer",
    "SOURCE", "0 0 0 Aux3",
    "MATERIAL", "pDisplayBuffer",
    "FULLSCREENQUAD", "1 1",
    4,
    "bufferCopy"
)
--]]

--[[
-- SSAO of some kind, as a test.
Global:AddRenderPass(
	0,
	"TARGET", "Aux2",
	"SOURCE", "0 0 0 Aux3",
	"SOURCE", "1 0 0 LightFirst",
	"MATERIAL", "pAmbientOcclusion",
	"FULLSCREENQUAD", "1 1",
	5,
	"AmbientOcclusionPass"
)

--]]
Global:AddRenderPass(
	"gaLightRay",
	1,
	"TARGET", "BackBuffer",
	"SOURCE", "1 0 1 LightFirst", 
	"SOURCE", "0 0 0 Aux3",
	3,
	"LightRay"
)

--[[
-- renders to aux0 and aux1, half size buffers
-- that are gaussian blurred and added back to the
-- scene, last bit does tone mapping, faking hdr a bit.
Global:AddRenderPass(
	0,
	"TARGET", "Aux0",
	"SOURCE", "0 0 0 Aux2",
	"MATERIAL", "pDownsample",
	"FULLSCREENQUAD", "2 2",
	"TARGET", "Aux1",
	"SOURCE", "0 0 0 Aux0",
	"MATERIAL", "pBlurHorz",
	"FULLSCREENQUAD", "2 2",
	"TARGET", "Aux0",
	"SOURCE", "0 0 0 Aux1",
	"MATERIAL", "pBlurVert",
	"FULLSCREENQUAD", "2 2",
	"TARGET", "BackBuffer",
	"SOURCE", "0 0 0 Aux2",
	"SOURCE", "2 0 0 Aux0",
	"SOURCE", "1 0 1 LightFirst", --in slot 2 set 0th buffer of Geometry, only 1 buffer
	"MATERIAL", "pWeAreGears",
	"FULLSCREENQUAD", "1 1",
	18,
	"PostProcessGritty"
)
--]]
--Unprocessed, text and stuff.
Global:AddRenderPass(
    "gSplashLogos",
    "gDSMTitle",
	"Text",
	3,
	"TARGET", "BackBuffer",
	"BLEND", "SourceAlpha One",
	2,
	"LastPass"
)
--[[
-- debug pass to display a particular buffer
Global:AddRenderPass(
	0,
	"TARGET", "BackBuffer",
	"SOURCE", "0 0 0 ShadowAux0",
	"MATERIAL", "pDisplayBuffer",
	"FULLSCREENQUAD", "1 1",
	4,
	"DisplayBuffer"
)--]]
