=============
Update planes
=============

planetrf = 22* 14+

updatealltileplanes = planetrf * (15 + 15 + 256 * 2)

sum = 11924* 7588+


=============
transform everything else
=============

100 lights
1000 other spatials

trfaabb = 30* 27+

lighttrf = 900* 600+
otherspatialstrf = 30000* 27000+

=============
transform them for 2D checks
=============

mat4mulvec4 = 16* 12+

alllights = 3200* 2400+
otherspatial = 128000* 96000+



function create_tiles
	
end


algorithm cs aabb fr
	MAX_POINTS = 8

	pointsWorld[MAX_POINTS]

	if cs.type is pespective frustum
		pointsWorld[...] = get the 5 points
		n = 5
	else
		pointsWorld[...] = get the 8 aabb points
		n = 8
	end

	pointsNdc[MAX_POINTS]

	minZ, maxZ
	for i in (0, n)
		pointsNdc[i] = fr.projectionMat * pointsWorld[i]
		pointsNdc[i] /= pointsNdc[i].w

		update minZ and maxZ
	end

	edges = convexHull2D(pointsNdc, n)

	depth = log 2 TILES

	for edge in edges
		do_edge edge -1..1, -1..1 depth
	end
end

do_edge edge min max depth
	if min and max not inside min max
		return
	end

	if depth == 0
		mark visible
	endif

	center = (min + max) / 2
	inside[4] = false

	if center left of edge
		// right up
		p = max
		if p is left of edge
			inside[0] = true;
		end

		// center top
		p = center.x, max.y
		if p is left of edge
			inside[0] = true;
			inside[1] = true;
		end

		// left top
		p = min.x, max.y
		if p is left of edge
			inside[1] = true;
		end

		// blah blah
	else
		inside[all] = true
	end
 
	for all that are inside
		do_edge new_min new_max depth - 1
	end
end

