jumping = PlayerCanJump()
function fif(test, if_true, if_false)
  if test then return if_true else return if_false end
end

hifi = GetQualityLevel() > 2 -- GetQualityLevel returns 1,2,or 3
function ifhifi(if_true, if_false)
  if hifi then return if_true else return if_false end
end

skinvars = GetSkinProperties()
trackWidth = skinvars["trackwidth"]
--trackWidth = fif(jumping, 11.5, 7)

SetScene{
	glowpasses = ifhifi(4,0),
	glowspread = ifhifi(0.5,0),
	radialblur_strength = .5,
--	radialblur_strength = fif(jumping,2,0),
	--environment = "city",
	watertype = 2,
	water = jumping, --only use the water cubes in wakeboard mode
	watertint = {r=255,g=255,b=255,a=234},
	watertexture = "WaterCubesBlue_BlackTop_WhiteLowerTier.png",--texture used to color the dynamic "digital water" surface
	towropes = jumping,--use the tow ropes if jumping
	airdebris_count = ifhifi(500,100),
	airdebris_density = ifhifi(10,2),
	--usedefaultrails=false,
	useblackgrid=false,
	twistmode= jumping and "cork" or "cork_flatish" -- use a flatter track when we're not in a jumping mode
	--skywirecolor={r=255,g=0,b=0}
}

SetBlockFlashes{
	texture="hit2.jpg"
}

if not jumping then
	SetBlocks{
		colorblocks={
			mesh = "DoubleLozenge.obj",
			shader = "RimLight",
			texture = "DoubleLozenge.png",
		    height = 0,
		    float_on_water = false,
		    scale = {1,1,1}
		},
		greyblocks={
			mesh = "doublespike.obj",
			shader = "RimLight",
			texture = "doublespike.png"
		}
	}
end

if jumping then
	SetPlayer{
		--showsurfer = true,
		--showboard = true,
		cameramode = "first_jumpthird",
		--cameramode_air = "third",--"first_jumptrickthird", --start in first, go to third for jumps and tricks

		camfirst={ --sets the camera position when in first person mode. Can change this while the game is running.
			pos={0,2.7,-3.50475},
			rot={20.49113,0,0},
			strafefactor = 1
		},
		camthird={ --sets the two camera positions for 3rd person mode. lerps out towards pos2 when the song is less intense
			pos={0,2.7,-3.50475},
			rot={20.49113,0,0},
			strafefactor = 0.75,
			pos2={0,2.8,-3.50475},
			rot2={20.49113,0,0},
			strafefactorFar = 1},
		surfer={ --set all the models used to represent the surfer
			arms={
				--mesh="arm.obj",
				shader="RimLightHatchedSurfer",
				shadercolors={
					_Color={colorsource="highway", scaletype="intensity", minscaler=3, maxscaler=6, param="_Threshold", paramMin=2, paramMax=2},
					_RimColor={0,63,192}
				},
				texture="FullLeftArm_1024_wAO.png"
			},
			board={
				--mesh="wakeboard.obj",
				shader=ifhifi("RimLightHatchedSurferExternal","VertexColorUnlitTinted"), -- don't use the transparency shader in lofi mode. less fillrate needed that way
				renderqueue=3999,
				shadercolors={ --each color in the shader can be set to a static color, or change every frame like the arm model above
					_Color={colorsource="highway", scaletype="intensity", minscaler=5, maxscaler=5},
					_RimColor={0,0,0}
				},
				shadersettings={
					_Threshold=11
				},
				texture="board_internalOutline.png"
			},
			body={
				--mesh="surferbot.obj",
				shader="RimLightHatchedSurferExternal", -- don't use the transparency shader in lofi mode. less fillrate needed that way
				renderqueue=3000,
				shadercolors={
					_Color={colorsource="highway", scaletype="intensity", minscaler=3, maxscaler=3},
					_RimColor={0,0,0}
				},
				shadersettings={
					_Threshold=1.7
				},
				texture="robot_HighContrast.png"
			}
		}
	}
else
	SetPlayer{
		--showsurfer = false,
		--showboard = false,
		cameramode = "third",
	--	cameramode_air = "first",--"first_jumptrickthird", --start in first, go to third for jumps and tricks

		camfirst={
			pos={0,1.84,-0.8},
			rot={20,0,0}},
		camthird={
			pos={0,2,-0.5},
			rot={30,0,0},
			strafefactorFar = .75,
			pos2={0,5,-4},
			rot2={30,0,0},
			strafefactorFar = 1,
			transitionspeed = 1,
			puzzleoffset=-0.65,
			puzzleoffset2=-1.5},
		vehicle={ --livecoding not supported here
			min_hover_height= 0.23,
			max_hover_height = 0.8,
			use_water_rooster = false,
            smooth_tilting = true,
            smooth_tilting_speed = 10,
            smooth_tilting_max_offset = -20,
			pos={x=0,y=0,z=0},
			mesh="ninjamono.obj",
			shader="VertexColorUnlitTinted",
			layer = 14,
			renderqueue = 2000,
			shadercolors={
				_Color = {colorsource="highway", scaletype="intensity", minscaler=1, maxscaler=1.5}},
			texture="ninjaMono.png",
			scale = {x=1,y=1,z=1},
			thrusters = {crossSectionShape={{-.35,-.35,0},{-.5,0,0},{-.35,.35,0},{0,.5,0},{.35,.35,0},{.5,0,0},{.35,-.35,0}},
						perShapeNodeColorScalers={.5,1,1,1,1,1,.5},
						--shader="VertexColorUnlitTinted",
						shader="VertexColorUnlitTintedAddSmooth",
						layer = 14,
						renderqueue = 3999,
						colorscaler = 2,
						extrusions=22,
						stretch=-0.1191,
						updateseconds = 0.025,
						instances={
							{pos={0,.46,-1.28},rot={0,0,0},scale={1,1,1}},
							{pos={.175,0.21,-1.297},rot={0,0,58.713},scale={.7,.7,.7}},
							{pos={-.175,0.21,-1.297},rot={0,0,313.7366},scale={.7,.7,.7}}
						}}
		}
	}
end

SetSkybox{ --this shows how to set up a skybox. There's also a dynamic sky system that's used by the audiosprint skin. It could be used here too.
	skysphere="skyline.jpg"
}

SetTrackColors{ --enter any number of colors here. The track will use the first ones on less intense sections and interpolate all the way to the last one on the most intense sections of the track
    {r=214, g=0, b=254},
    {r=0, g=176, b=255},
    {r=0, g=184, b=0},
    {r=255, g=255, b=0},
	{r=255, g=0, b=0}
}

SetBlockColors{ --this is only used for puzzle modes (which you don't have yet) with multiple colors of blocks
    {r=93, g=8, b=132},
	{r=1.0, g=0.27, b=0.2},
    {r=0.047, g=0.5098, b=0.94},
    {r=1.0, g=0.85, b=0.4157},
	{r=0, g=0.29, b=0.08},
    {r=1,g=0,b=0}
}

SetRings{ --setup the tracks tunnel rings. the airtexture is the tunnel used when you're up in a jump
	texture="Classic_OnBlack.png",
	--texture="Classic_OnBlack",
	shader="VertexColorUnlitTintedAddSmooth",
	layer = 13, -- on layer13, these objects won't be part of the glow effect
	size=22,
	percentringed=.2,--ifhifi(2,.01),-- .2,
	airtexture="Bits.png",
	airshader="VertexColorUnlitTintedAddSmoothNoDepth",
	airsize=16
}

wakeHeight = 2
if jumping then wakeHeight=2 else wakeHeight = 0 end
SetWake{ --setup the spray coming from the two pulling "boats"
	height = wakeHeight,
	fallrate = 0.95,
	shader = "VertexColorUnlitTinted",
	layer = 13, -- looks better not rendered in background when water surface is not type 2
	bottomcolor = {r=0,g=0,b=100},
	topcolor = "highway"
}

CreateObject{
	name="EndCookie",
	tracknode="end",
	gameobject={
		transform={pos={0,0,126},scale={scaletype="intensity",min={55,99,900},max={66,120,900}}},
		mesh="danishCookie_boxes.obj",
		shader="RimLightHatched",
		shadercolors={
			_Color={0,0,0},
			_RimColor={1,1,1}
		}
	}
}

CreateObject{ --creates a uniquely named prototype (prefab) that can be used later in the script or by the mod script. The audiosprint mod uses prototypes created in it's skin script
	name="BuildingCloneMe",
	gameobject={
		pos={x=0,y=0,z=0},
		--mesh="skyscraper42.obj",
		mesh="skyscraper_withbase.obj",
		--shader="VertexColorUnlitTintedAlpha",
		shader="Diffuse",
		diffuseinair = true,
		shadercolors={
			--_Color={r=255,g=255,b=255}
			--_Color="highwaysmooth"
			--_Color = {colorsource="highway", scaletype="intensity", minscaler=6, maxscaler=6}
			_Color = {colorsource="highway", scaletype="intensity", minscaler=2, maxscaler=2}
		},
		texture="White.png",
		--texture="skyscraper.png",
		scale = {x=1,y=1,z=1}
	}
}

track = GetTrack()--get the track data from the game engine

if buildingNodes == nil then
	buildingNodes = {} --the track is made of nodes, each one with a position and rotation. This table will hold the indices of track nods that should have a skyscraper rendered at them (with some offset)
	offsets = {}
	buildingNodesToo = {}
	offsetsToo = {}
	for i=1,#track do
		if i%80==0 then
			buildingNodes[#buildingNodes+1] = i
			local xOffset = 150 + 1650*math.random()
			if math.random() > 0.5 then xOffset = xOffset * -1 end
			offsets[#offsets+1] = {xOffset,-100,0}
		end

--		if (i+40)%120==0 then
--			buildingNodesToo[#buildingNodesToo+1] = i
--			local xOffset = 150 + 1650*math.random()
--			if math.random() > 0.5 then xOffset = xOffset * -1 end
--			offsetsToo[#offsetsToo+1] = {xOffset,-100,0}
--		end
	end

	BatchRenderEveryFrame{prefabName="BuildingCloneMe", --tell the game to render these prefabs in a batch (with Graphics.DrawMesh) every frame
							locations=buildingNodes,
                    		rotateWithTrack=false,
                    		maxShown=50,
                    		maxDistanceShown=2000,
							offsets=offsets,
							collisionLayer = 1,--will collision test with other batch-rendered objects on the same layer. set less than 0 for no other-object collision testing
							testAndHideIfCollideWithTrack=true --if true, it checks each render location against a ray down the center of the track for collision. Any hits are not rendered
						}

--	BatchRenderEveryFrame{prefabName="BuildingCloneMeToo", --tell the game to render these prefabs in a batch (with Graphics.DrawMesh) every frame
--							locations=buildingNodesToo,
--                    		rotateWithTrack=false,
--                    		maxShown=50,
--                    		maxDistanceShown=2000,
--							offsets=offsetsToo,
--							collisionLayer = 1,--will collision test with other batch-rendered objects on the same layer. set less than 0 for no other-object collision testing
--							testAndHideIfCollideWithTrack=true --if true, it checks each render location against a ray down the center of the track for collision. Any hits are not rendered
--						}
end

CreateObject{--skywires, the red lines in the sky. A railed object is attached to the track and moves along it with the player.
	railoffset=0,
	floatonwaterwaves = false,
	gameobject={
		name="scriptSkyWires",
		pos={x=0,y=0,z=0},
		mesh="skywires.obj",
		renderqueue=1000,
		layer=ifhifi(18,13), -- in low detail the glow camera (layer 18) is disabled, so move the skywires to the main camera's layer (13)
		shader="VertexColorUnlitTintedSkywire",
		shadercolors={
			_Color={r=200,g=200,b=200}
		},
		texture="White.png",
		scale = {x=1,y=1,z=1},
		lookat = "end"
	}
}

--RAILS. rails are the bulk of the graphics in audiosurf. Each one is a 2D shape extruded down the length of the track.

if not jumping then
	local laneDividers = skinvars["lanedividers"]
	for i=1,#laneDividers do
		CreateRail{ -- lane line
			positionOffset={
				x=laneDividers[i],
				y=0.1},
			crossSectionShape={
				{x=-.07,y=0},
				{x=.07,y=0}},
			perShapeNodeColorScalers={
				1,
				1},
			colorMode="static",
			color = {r=255,g=255,b=255},
			flatten=false,
			nodeskip = 2,
			wrapnodeshape = false,
			shader="VertexColorUnlitTinted"
		}
	end
end

CreateRail{--big cliff
	positionOffset={
		x=0,
		y=0},
	crossSectionShape={
		{x=11,y=-2},
		{x=22,y=-11},
		{x=22,y=-40},
		{x=-22,y=-40},
		{x=-22,y=-11},
		{x=-11,y=-2}
		},
	perShapeNodeColorScalers={
		1,
		1,
		.4,
		.4,
		1,
		1},
	colorMode="highway",
	color = {r=255,g=255,b=255},
	flatten=false,
	wrapnodeshape = true,
	texture="cliffRails.png",
	fullfuture = true,--ifhifi(true,false),
	stretch = 3,
	calculatenormals = true,
	shader="Cliff"
}

if not jumping then
	CreateRail{--road surface
		positionOffset={
			x=0,
			y=0},
		crossSectionShape={
			{x=-trackWidth,y=0},
			{x=trackWidth,y=0}},
		perShapeNodeColorScalers={
			1,
			1},
		colorMode="static",
		color = {r=0,g=0,b=0,a=225},
		flatten=false,
		--texture="cliffRails.png",
		shader="VertexColorUnlitTintedAlpha"
	}
end

CreateRail{--left rail
	positionOffset={
		x=-trackWidth - .2,
		y=0},
	crossSectionShape={
		{x=-.65,y=0.5},
		{x=.3,y=0.5},
		{x=.3,y=-3},
		{x=-.65,y=-3}},
	perShapeNodeColorScalers={
		.5,
		1,
		0,
		0},
	colorMode="highway",
	color = {r=255,g=255,b=255},
	flatten=false,
	--texture="cliffRails.png",
	shader="ProximityEmissionVertexColor",
	shadercolors={_Color={r=0,g=0,b=0}},
	shadersettings={_StartDistance=3.92, _FullDistance=11.9}
}

CreateRail{--right rail
	positionOffset={
		x=trackWidth + .2,
		y=0},
	crossSectionShape={
		{x=-.65,y=0.5},
		{x=.3,y=0.5},
		{x=.3,y=-3},
		{x=-.65,y=-3}},
	perShapeNodeColorScalers={
		.5,
		1,
		0,
		0},
	colorMode="highway",
	color = {r=255,g=255,b=255},
	flatten=false,
	--texture="cliffRails.png",
	shader="ProximityEmissionVertexColor",
	shadercolors={_Color={r=0,g=0,b=0}},
	shadersettings={_StartDistance=3.92, _FullDistance=11.9}
}

if jumping then
	CreateRail{--left aurora core
		positionOffset={
			x=-18,
			y=33},
		crossSectionShape={
			{x=-13,y=.5},
			{x=-9,y=.5},
			{x=-9,y=-.5},
			{x=-13,y=-.5}},
		perShapeNodeColorScalers={
			1,
			1,
			1,
			1},
		colorMode="highway",
		color = {r=255,g=255,b=255},
		flatten=true,
		texture="White.png",
		shader="VertexColorUnlitTinted"
	}

	CreateRail{--right aurora core
		positionOffset={
			x=18,
			y=33},
		crossSectionShape={
			{x=9,y=.5},
			{x=13,y=.5},
			{x=13,y=-.5},
			{x=9,y=-.5}},
		perShapeNodeColorScalers={
			1,
			1,
			1,
			1},
		colorMode="highway",
		color = {r=255,g=255,b=255},
		flatten=true,
		texture="White.png",
		shader="VertexColorUnlitTinted"
	}

	auroraExtent = ifhifi(77, 22)
	CreateRail{--left aurora
		positionOffset={
			x=-18,
			y=33},
		crossSectionShape={
			{x=-auroraExtent,y=.5},
			{x=-11,y=.5},
			{x=-11,y=-.5},
			{x=-auroraExtent,y=-.5}},
		perShapeNodeColorScalers={
			0,
			1,
			1,
			0},
		colorMode="aurora",
		color = {r=255,g=255,b=255},
		flatten=true,
	    layer=13,
		texture="White.png",
		shader="VertexColorUnlitTintedAddSmoothNoCull"
	}

	CreateRail{--right aurora
		positionOffset={
			x=18,
			y=33},
		crossSectionShape={
			{x=11,y=.5},
			{x=auroraExtent,y=.5},
			{x=auroraExtent,y=-.5},
			{x=11,y=-.5}},
		perShapeNodeColorScalers={
			1,
			0,
			0,
			1},
		colorMode="aurora",
		color = {r=255,g=255,b=255},
		flatten=true,
	    layer=13,
		texture="White.png",
		shader="VertexColorUnlitTintedAddSmoothNoCull"
	}
end