Rasterize voxels #4 Start Traverse - Experimental graphics technology - GameDev.net

Rasterize voxels #4 Start Traverse

Published January 15, 2020
Advertisement

Among the data that are prepared before rasterizing are the masks in X and Y for each coordinate, the limits in X and Y the shortest length and the distance from the origin to the child rectangle, array of sums.

This algorithm traverse the rectangle that the cube occupies and calculates for each point the first node found or the absence of a node. In the case that only a single octree is drawn, a z buffer is not necessary.

:drawiso | octree --
	minx miny xy>v >a	| position in the framebuffer for store pixels, A is a register for fill the pixels
	sw lenx - 2 <<		| advance for draw the rectangle, screen width minus lenx * 4 (dword)
	0 ( leny <?			| count from 0 to length in y (from top to botton)
		0 ( lenx <?		| count from 0 to length in x (left to right)
			rayoctree	| paint the pixel
			1 + ) drop	| increment y
		over a+			| add stride for next pixel row
		1 + ) 			| increment x 
	3drop ;	

The main word is responsible for traveling the octree calculating which children are available for the current coordinates. The way to go through the octree is recursive, but I need to make it iterative since I want to avoid the cost of returning when I find the node of the corresponding color.

:rayoctree | octree s y x -- octree s y x
	getyxmask0 0? ( drop 4 a+ ; )			| not box for start..end with not paint
	pick4 >b b@ and 0? ( drop 4 a+ ; )		| not children in the box..end with not paint
	pick2 16 << pick2 or 'xy !				| code x and y is one integer (16 upper bits for y, 16 lower bits for x)
	minz 'zz !								| store the z coordinate (need for z buffer)
	'stacko 'stacko> !						| initialize the auxiliary stack for iterative recursion
	fillchild	| norden					| convert the bitmask of children in childrens order
	1 ( len <?		| norden len			| start from 1 to max lenght (the node is less than one pixel)
		nextchild	| norden len			| calc next children
		0? ( 2drop 4 a+ ; )					| no more nodes..end with not paint
		) 2drop								| next node
	b> octcolor a!+ ;						| exit with color for less than one pixel..paint and finish

Some tricks are used in this word.

The xy variable store both coordinates at x and y, and the array of sums, because always be positive, can use a sort of SIMD with common operations and add,sub and shift in the same time for X and Y.

fillchild convert a bitmask of node AND bitmask of maskX AND bitmask of maskY with the calculated order in a sequence of children to visit, for example

all in binary

%01111010 maskX
%00111100 maskY
%11101100 current octree node

the nodes to visit are
%00101000 nodes 3 and 5 only

but the order of visit are 0 1 2 4 3 5 6 7 then this word generate the number to visit 3 and 5, add the 4 bit for mark node, nodes $b and $d, this bit add is for know when the traverse end.

$000000db  ; children to visit

With this number I can get the node to visit only with “$7 and” operation and for advance the children be “4 >>>” (shift right 4 bits), when this number is 0 then no more children left.

0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement