Quads

Blitz3D Forums/Blitz3D Beginners Area/Quads

PoliteProgrammer(Posted 2006) [#1]
What exactly is a quad, and how are they used?
I've seen them mentioned many times, especially to get good looking glow effects, but I'm not sure what they actually are.


Stevie G(Posted 2006) [#2]
A quad is a basically a mesh consisting of 4 vertices & 2 triangles which form of a square/rectangle. You must create these yourself using the mesh commands, addvertex, addtriangle etc... It's very similar to a sprite but can be much much faster when using a single surface particle system.

Stevie


jfk EO-11110(Posted 2006) [#3]
If I remember correctly, there's a CreateQuad function in the archives, in the 3d FX section, an entry described as "sunbeams in dusty air" or similar.


YellBellzDotCom(Posted 2006) [#4]
I actually use a tweaked version of yours JFK EO-11110...
Function CreateQuad()
	;Compliments of jfk EO-11110
	mesh=CreateMesh()
	surf=CreateSurface(mesh)
	
	;Texture Coords
	;(0,0) ... (1,0)
  	;  .         .
  	;  .         .
  	;  .         .
	;(0,1) ... (1,1)
	
	v0=AddVertex(surf, 0,40,0, 0,1)
	v1=AddVertex(surf, 31,40,0, 1,1)
	v2=AddVertex(surf, 0,40,31, 0,0)
	v3=AddVertex(surf, 31,40,31, 1,0)
	
	AddTriangle(surf,v0,v2,v1)
	AddTriangle(surf,v1,v2,v3)
	UpdateNormals mesh
 	Return mesh
End Function


then use below to finish the quad
Shdw = CreateQuad()
ShdwTex = LoadTexture("Shadow.png",2) ;Used flag 2 for alpha
EntityTexture Shdw,ShdwTex
ScaleEntity Shdw,.5,1,.5
PositionEntity Shdw,EntityX(Sphere,True)-8,EntityY(Sphere,True)-44,EntityZ(Sphere,True)-8
EntityParent Shdw,Sphere ;make the shadow follow the movable object


But Im having a major problem aligning this quad to the terrain. I tried my same exact code with a flattened sphere mesh and it worked great.


Beaker(Posted 2006) [#5]
For completeness (more quad goodness):
quad functions


jfk EO-11110(Posted 2006) [#6]
not sure what if flattened sphere was deformed additionally. A simple quad does not allow to deform and therefor you cannot align it properly to any nonflat ground, be it a terrain or not. Well it works well when the quad is very small comapred to the terrain, at least smaller than one terrain grid tile.

For towel mesh shadows you should use a mesh wth several segments, so you can aligh the vertices in realtime to the heights of the underlying terrain locations.


Buggy(Posted 2007) [#7]
So what are the advantages of using quads over sprites? Are quads actually faster? What can you do with a quad that you can't with a sprite?


jfk EO-11110(Posted 2007) [#8]
-you cannot AddMesh multiple sprites together to a single surface entity, as you can with quads (this was mentioned before)

-spriteviewmode offers some easy and classic "sprite" alignements to the camera.


Buggy(Posted 2007) [#9]
Is there a speed difference between the two?


Jasu(Posted 2007) [#10]
Using quads is several times faster, depending on how complex your deforming algorithm is.

It's ok to use sprites when you use only 1-30 particles on screen at a time. If you plan to have more, single surface system is a good idea.

Sprites
+ Simple to code
- Is very slow when having a lot of particles

Quads on single surface
+ Fast
+ Can handle more particles than sprite system (amount of surfaces is more limited than amount of poly's)
- Tricky to code if you want rotation and facing the camera