Advertisement

Tiny stupid demo v2.0

Started by June 27, 2004 09:21 AM
14 comments, last by rodzilla 20 years, 5 months ago
yeah here:

*ok, first I didn't mean specular, I meant attenuation*

I think at least. :)



are you using Cg by any chance?
I get the feeling it might be issue with my card.. not sure why though... As I say I've had the same problem happen before, but that was because of Cg's buggy D3D compiler (it has issues with things that arn't float4)... converting the attenuation equation to use only float4s fixed this...


anywho..

for the shadowing, you might want to check out this paper I wrote last year (and the slides) - they explain a way I do optimal shadow volume gen when the mesh isn't 'good'.. :) - ie problems like you have. It's more appropriate for world geometry, but it still works fine with models.

kk. :)


[edit]

another thing you migth want to consider,
you almost always get a less complex, and always smaller, shadow volume if you project it from faces that are not in the light... This is perticuarly true for world geometry when the light is small (think about all the walls facing the light)..
to sum it up,
Doom3 does this for world geometry, so you should too. :)
how I know that doom3 does this is another story.
@RipTorn: The best way of figuring if there's a problem with attenuation is to compare PPL and OpenGL lighting. Since both use the same parameters, they should give the same result (except PPL is per-pixel ;*).

Thanx a lot for the article. I'll implement this approach as soon as I have time (this week is gonna be a busy one).

BTW, you can hit F12 while running the demo to save a screenshot ("shot.bmp").
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
Advertisement
Works well for me (Linux). One suggestion is that if the gfx card doesn't support the necessary extensions for PPL lighting, disable the option. When it started up, I thought lighting had been switched off ;).
@baldurk: I'll implement multiple rendering methods whenever I have time for this, so that PPL works on as many GFX cards as possible (what's yours BTW ?).

@RipTorn: I have a question about your article (in the algorithm page 4). The first loop seems to count how many times each edge has to be projected to build the shadow volume (while rendering the volume's caps). Why does the second part of the algorithm loop through triangles instead of looping through edges ?
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
As I said, it's aimed more at generating shadows off subsets of triangles... Where you usually get a subset from a space-partioner such as an octree or bsp. In this case, you don't have an efficient list of edges. You can still do a seperate loop through all your edges instead.

Just remember that that code does assume that the edge set is unique (it will just produce a brute force shadow otherwise), and that includes the requirement that edge {A,B} == {B,A}, so in such a case {B,A} would be removed.

I didn't go into any detail about how to get a unique set of edges, but it's not all that hard.. The trick comes in ordering the vertices stored in the edge when doing the compare for qsort... for edge {A,B}, if the pointer of B is > than A, treat the edge as {B,A} (in the compare function)..

ie: (this is hypothetical code btw, used as the compare function in qsort())

int compareEdge(const void * e1, const void * e2){   Vertex * v1_e1=((Edge*)e1)->vertex1;   Vertex * v1_e2=((Edge*)e1)->vertex2;   Vertex * v2_e1=((Edge*)e2)->vertex1;   Vertex * v2_e2=((Edge*)e2)->vertex2;   //swap vertices to get into order   if (v1_e1<v1_e2)   {      Vertex * v = v1_e1;      v1_e1=v1_e2;      v1_e2=v;   }   //swap vertices to get into order   if (v2_e1<v2_e2)   {      Vertex * v = v2_e1;      v2_e1=v2_e2;      v2_e2=v;   }   if (v1_e1>v2_e1)	return 1;   else      if (v1_e1<v2_e1)          return -1;   if (v1_e2>v2_e2)	return 1;   else      if (v1_e2<v2_e2)          return -1;   return 0;}


so:

qsort(edges,numedges,sizeof(Edge),&compareEdge);


would sort an array of edges into order, then you could just loop through and pick out the first of each (ie, where compareEdge() == 0 is a duplicate)

ie,

int count=0;Edge * uniqueEdges=new Edge[numedges];for (int n=0; n<numedges; n++)    if (n==0 || compareEdge(&edges[n-1],&edges[n])==0)       uniqueEdges[count++]=edges[n];


but you'd need to keep track of how they get reindexed into the new array so you can set/update pointers in the triangles.

pretty standard duplicate removal except for the condition about vertex ordering.. but hopfully that makes sense.
@Riptorn: Thanx for your answer...
I was still stuck in my "Astroboy's shadow" example... ;)
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)

This topic is closed to new replies.

Advertisement