Problem with trees.

Community Forums/General Help/Problem with trees.

Yue(Posted 2013) [#1]
I use Blitz3D, The problem is that when you get too close to the trees, which has a mask textures for transparency, low performance 60 FPS to 30, any suggestions?




Yasha(Posted 2013) [#2]
I think this sort of thing is caused by too much "overdraw" (I could be wrong, I'm not very good with graphics). Because the tree is made up of a lot of alpha'd quads, all of the quads need to be drawn as their pixels blend with those behind them (as opposed to solid quads which would simply hide whatever is behind them), so the machine has to go over and over the same bit of screen space many times, far more than it otherwise would.

I don't think there is any good way to deal with overdraw in plain Blitz3D: at the very least you need to adjust the rendering passes, and you probably want to do advanced things with shaders. So really you need to prevent it from happening at all by changing the design of the tree.

Ideas:

-- Reduce the number of leaf quads. Use a smaller number of larger quads. Potentially compensate by giving them bigger textures and better alignments.

-- Do more with opaque tree geometry, e.g. actually model out the branches. Opaque polygons are pretty fast even when there are lots of them.

-- Use one of the "tree systems" to be found elsewhere on this site (try the toolbox or code archives), that are already heavily optimised for B3D.


Gabriel(Posted 2013) [#3]
You have fillrate problems. Generally, you would solve this by:

1) Controlling the camera to avoid having lots of transparent pixels on the screen and particularly pixels which are overdrawn (ie: where you have one pixel which is transparent in more than one triangle, meaning that all have to be drawn.)

2) Adjusting your tree meshes so that they have less transparent pixels. Try to shape the meshes so that they fit much closer to the shape of the texture which is drawn on them. The fillrate savings will be much greater than the cost of rendering a few more triangles.

3) Reducing texture resolution, compressing textures, enabling mip-maps, reducing texture filtering to trilinear or even bilinear.



But focus on 1) and 2) as they will give you greater gains with a lower quality loss.

EDIT: Or more or less what Yasha said.


Kryzon(Posted 2013) [#4]
Another approach is to use masking (texture flag 4 in B3D).

Masking uses alpha-testing, which is simpler (and consequently faster) than the alpha-blending those leaves are using right now.
It'll look a bit more jagged, but similar to what you have now and faster to render. A lot of AAA games use alpha-testing for leaves.

The problem is masking in B3D only masks black texels, so you can use the following method to still use that same leaf texture without having to change it:
Local originalLeafTexture = LoadTexture( "leafs_with_alpha.png", 1+2 ) ;Texture you are using now, loaded with alpha channel.

Local maskedLeafTexture = CreateTexture( TextureWidth(originalLeafTexture), TextureHeight(originalLeafTexture), 1+4 ) ;Masked texture.

;******
MaskAlphaTexture( originalLeafTexture, maskedLeafTexture ) ;Process the original texture.
EntityTexture myTreeLeaves, maskedLeafTexture ;Apply masked texture to your tree leaves.
;******


;Based on function by Ross C.
Function MaskAlphaTexture( alphaTexture%, maskTexture% )
	Local argb%, alpha%
	
	For X% = 0 To TextureWidth(alphaTexture)-1
		For Y% = 0 To TextureHeight(alphaTexture)-1
			argb = ReadPixel( X, Y, TextureBuffer(alphaTexture) )
			
			alpha = (argb And $FF000000) Shr 24
			alpha = 0 + (alpha > 127)*255 ;Kinda like a ternary operation, snap alpha to either 0 or 255.
			
			argb = (alpha shl 24) Or (argb And $FFFFFF) ;Use the snapped alpha value as the new alpha value with the original RGB.
			
			WritePixel( X, Y, argb, TextureBuffer(maskTexture) ); Write modified ARGB to the masked texture.
		Next
	Next
End Function
(Untested.)


Yue(Posted 2013) [#5]





ok, take out the advice, annexed'm using this system for transparency. Do not use other because when the DOF is active, the trees do not look good, though quite the same happens with both methods, and better the tree and show how it goes.

Greetings.


Yue(Posted 2013) [#6]
yes, they had every reason to respect, again I created a tree with the recommended specifications and has not had problems in the performance.

:)



Edit: tree Finish.




Gabriel(Posted 2013) [#7]
Masking uses alpha-testing, which is simpler (and consequently faster) than the alpha-blending those leaves are using right now.

This is true on Desktop hardware, which is what Yue is using here, but just wanted to add that the opposite is true on mobile hardware. Alpha masking is actually slower on some mobile hardware than alpha blending. Counter-intuitive, I know, but worth knowing.


Yue(Posted 2013) [#8]
Desktop or windows full.


Kryzon(Posted 2013) [#9]
@Yue: I didn't fully grasp how you solved it, could you please elaborate on it?

@Gabriel: Counter-intuitive indeed. If I remember correctly you use Unity; There's this graphics programmer for that company that has some very interesting papers on his webpage: http://aras-p.info/texts/index.html


Yue(Posted 2013) [#10]
Hi Kryson, I solved the problem again rebuilding the tree, but the branches polygons are fewer in number and larger, the former was a pine tree and had many polygons in the branches where they were transparencies and that was the problem, so that sigiendo the tips in this thread, assuming that many pixels invisible were the cause of the problem I decided to build a tree with fewer branches (polygons), the princiipio thought it was because of the polygons, but the former pine presented without transparency there that problem.

Greetings.


RemiD(Posted 2013) [#11]
Another thing to try to decrease the render time of trees or of plants, is to make sure there are no tris intersecting others tris, this can be the case for branches or leaves.


Gabriel(Posted 2013) [#12]
@Kryzon: Good memory. Thanks for the link. I didn't know Aras had a collection of articles up.