Welcome, Unregistered.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Reply
Old 12-Oct-2002, 04:49   #1
MrFloopy
Member
 
Join Date: May 2002
Location: Adelaide, South Australia
Posts: 270
Default Shadow Volumes via Vertex Shader

Hi all,

Am using a vertex shader for shadow volume extrusion and have hit a snag. When two vertices share a common position but not normal or texture coord, I create degenerate faces between them an this works fin for mist cases.

the problem is that the vertex shader calculates whether to extrude the vertex or not based on the vertex normal and not the face normal, this can create areas where a vertex should be extruded away but is not since it's shared vertex normal is not pointing away from the light.

Short of creating unique vertices for each face I cannot think od a solution to this.

Any ideas?
__________________
----------------------------------------------------
That's Floopy not Floppy.......
And it's Mr Floopy to you!
----------------------------------------------------
MrFloopy is offline   Reply With Quote
Old 12-Oct-2002, 11:09   #2
Hyp-X
Irregular
 
Join Date: Feb 2002
Posts: 1,170
Default Re: Shadow Volumes via Vertex Shader

Quote:
Originally Posted by MrFloopy
the problem is that the vertex shader calculates whether to extrude the vertex or not based on the vertex normal and not the face normal, this can create areas where a vertex should be extruded away but is not since it's shared vertex normal is not pointing away from the light.
Actually it's worse when the vertex is not shared as you'd get gaps in the shadow volume which can cause surprising light leaking effects.

Maybe you should tell why you want to calculate the volume with VS so you cat get an advice in the right direction.
Hyp-X is offline   Reply With Quote
Old 12-Oct-2002, 14:59   #3
MrFloopy
Member
 
Join Date: May 2002
Location: Adelaide, South Australia
Posts: 270
Default

Quote:
Actually it's worse when the vertex is not shared as you'd get gaps in the shadow volume which can cause surprising light leaking effects.
Not if you place degenerate tri's between shared edges with non-unique verts.

Quote:
Maybe you should tell why you want to calculate the volume with VS so you cat get an advice in the right direction
Because of the CPU saving. Am running lot's of physics at same time so any CPU time saved is very important (Yes, even to detriment to exact shadow volumes although the less artifacts present the better obviously). And lights in scene can be arbitrarily dynamic so calculating silouettes are to be avoided if possible.

It is quite robust if degenerate tri's are placed between every edge, however this should not be required in all cases. I am thinking that only certain edges that share non-unique verts need these degenerate tris between them. I guess it's a matter of what metric is required to determine which do and which don't
__________________
----------------------------------------------------
That's Floopy not Floppy.......
And it's Mr Floopy to you!
----------------------------------------------------
MrFloopy is offline   Reply With Quote
Old 12-Oct-2002, 15:29   #4
Hyp-X
Irregular
 
Join Date: Feb 2002
Posts: 1,170
Default

Quote:
Originally Posted by MrFloopy
Not if you place degenerate tri's between shared edges with non-unique verts.
Oops missed that.

Well, the correct shadow volumes needs the side triangles, so this is only achievable the way you described it (creating unique vertices for each face).

On the other hand the other solution might not be that bad - worth a try. It might depend on the surface complexity of the object.
Hyp-X is offline   Reply With Quote
Old 12-Oct-2002, 17:28   #5
MrFloopy
Member
 
Join Date: May 2002
Location: Adelaide, South Australia
Posts: 270
Default

Will give it a go. Will try based on a face to face angle factor. Probably worth a bit of extra shadow geometry.
__________________
----------------------------------------------------
That's Floopy not Floppy.......
And it's Mr Floopy to you!
----------------------------------------------------
MrFloopy is offline   Reply With Quote
Old 12-Oct-2002, 22:39   #6
Hyp-X
Irregular
 
Join Date: Feb 2002
Posts: 1,170
Default

My guess is that the most visible artifact would be "shadow popping", when a vertex turns from lit to non-lit the shape of the shadow casted on another surface might have a sudden change. Might be small if the angle between the neighbour faces is small.

This is the only way to do it when N-patches are enabled, but since N-patches make the mesh more smooth, it should lessen the popping effect.
Hyp-X is offline   Reply With Quote
Old 13-Oct-2002, 02:23   #7
MrFloopy
Member
 
Join Date: May 2002
Location: Adelaide, South Australia
Posts: 270
Default

Quote:
My guess is that the most visible artifact would be "shadow popping"
Yes it is, but by using a self shadowing term in the diffuse and specular pixel shader this is reduced somewhat.

Still biggest problem is as I described which can cause quite a few holes in the shadow (If you can have a hole in the absence of light )

I think a completely robust solution is probably not likely but considering the alternatives it still looks pretty impressive.
__________________
----------------------------------------------------
That's Floopy not Floppy.......
And it's Mr Floopy to you!
----------------------------------------------------
MrFloopy is offline   Reply With Quote
Old 14-Oct-2002, 14:33   #8
pcchen
Moderator
 
Join Date: Feb 2002
Location: Taiwan
Posts: 2,348
Default

I did some experiments a while ago to use vertex shader to mimic my CPU implementation of shadow volumes (which is quite robust). However, its overhead is too large (a quad for each edge). There are also some problems with vertex blending (it is quite troublesome to recompute the true normal of a triangle). I decided to keep using CPU to do everything including vertex blending and shadow volumes.
pcchen is offline   Reply With Quote
Old 03-Nov-2002, 08:57   #9
ector
Member
 
Join Date: Nov 2002
Location: Sweden
Posts: 111
Send a message via ICQ to ector
Default

I am using an approach, based on the Robust Shadow Volumes doc, where I find silhouettes in software using a somewhat fast algorithm with no need for an edge structure, and then do the final extrusion calculation in hardware by for each vertex passing in a number, 0 or 1, telling whether or not this vertex should be extruded to infinity or not. I've been thinking about how to move more calculations to the shader but so far I've not been successful. I have no idea if this algorithm is fast since I've only used it on fairly simple test scenes, but making, extruding and drawing shadow volumes from a 10000-poly object in realtime is no problem on my athlon 1800.. maybe doesn't say very much..

Anyway, here's my optimized shader (not as readable as it used to be anymore ) if anybody is interested:
Code:
; v0     = position
; v1     = extrudeAmount <- {0,1} (NOTE this is reversed, vertices you 
;                                   want to extrude should use 0, others 1)
;
; c0-3   = Transposed matrix
; c4     = Homogenous light position


;(Ax*Lw - Lx*Aw, Ay*Lw - Ly*Aw, Az*Lw-Lz*Aw, 0);
mul r1, v0, c4.wwww
mad r1, c4, -v0.wwww, r1

; lerp between v0,r1
add r2, v0, -r1
mad r0, r2, v1.xxxx, r1

; Transform position
m4x4 oPos, r0, c0
ector is offline   Reply With Quote
Old 04-Nov-2002, 02:25   #10
3dcgi
Senior Member
 
Join Date: Feb 2002
Posts: 2,020
Default

ector. I'm curious how your silhouette extraction is done. I've read about some methods before, but many needed a special data structure. Do you have a link to the algorithm or did you develop it yourself?

Thanks.
3dcgi is offline   Reply With Quote
Old 04-Nov-2002, 06:21   #11
ector
Member
 
Join Date: Nov 2002
Location: Sweden
Posts: 111
Send a message via ICQ to ector
Default

well, i'm actually using a completely rewritten version of the not very efficiently written algorithm Microsoft uses in the ShadowVolume sample in DX8SDK.. check out that sample for the algorithm.

Anyway it's basically:
maintain a list of edges.
go through all your triangles (since you need to do it anyway for capping).
for each front-facing triangle, apart from adding it to your list of cap polys, call AddEdge(v0,v1); AddEdge(v1,v2); AddEdge(v2,v0);

AddEdge is a function that takes an edge, and adds it to the edge list if it's not already there, OR REMOVES it from the list if it is! this will leave you with a list only containing silhouette edges.
To remove an item from this list, take the last one in the list and put it where the old one was so you won't have to shift around so much data.

I have made the observation that when you add a new edge, you only need to test for edges in the list going in the "opposite direction", if your mesh is correct.

Maybe an algorithm with connectivity information would be slightly faster, but I really like the simplicity of this and not having to keep track of an edge structure for each mesh.
ector is offline   Reply With Quote
Old 05-Nov-2002, 03:10   #12
3dcgi
Senior Member
 
Join Date: Feb 2002
Posts: 2,020
Default

Thanks for the explaination.
3dcgi is offline   Reply With Quote
Old 06-Nov-2002, 20:00   #13
Hyp-X
Irregular
 
Join Date: Feb 2002
Posts: 1,170
Default

Well, that algorithm can screw up on some meshes (you can count on artist to be innovative, and create such meshes! )

Also I don't think that "removing from the list" is a particularly fast operation, as it involves searching.

Keeping an edge buffer is actually moving this searching out of real time code.
Hyp-X is offline   Reply With Quote
Old 06-Nov-2002, 20:15   #14
arjan de lumens
Senior Member
 
Join Date: Feb 2002
Location: gjethus, Norway
Posts: 1,256
Default

To avoid searching through the entire edge list for every time an edge needs to be added/removed, you could use a hash table to store the edges. Which should give you a rather dramatic speedup for large-polycount models. Although you will have to experiment a little to find a good (fast and sufficiently random) hash function.
arjan de lumens is offline   Reply With Quote
Old 06-Nov-2002, 20:31   #15
MfA
Regular
 
Join Date: Feb 2002
Posts: 5,229
Send a message via ICQ to MfA
Default

If you go to that much trouble not taking connectivity into acount becomes a bit silly ... can't beat O(1).
MfA is offline   Reply With Quote
Old 06-Nov-2002, 20:33   #16
ector
Member
 
Join Date: Nov 2002
Location: Sweden
Posts: 111
Send a message via ICQ to ector
Default

>Also I don't think that "removing from the list" is a particularly fast
>operation, as it involves searching.
uhms.. see the note how I do it. it's very fast (I just move the last item in the list to where the hole is, since order doesn't matter)

>To avoid searching through the entire edge list for every time an edge >needs to be added/removed, you could use a hash table to store the >edges. Which should give you a rather dramatic speedup for large->polycount models. Although you will have to experiment a little to find a >good (fast and sufficiently random) hash function.

yeah, I've thought of this to and I'll do some research into it once this edge search becomes the bottleneck.. and for various reasons, I don't think it's the bottleneck right now. Besides, i'm shadowing a morphing 10 000 poly object in 60fps (on athlon 1800+ / GF2MX!).. so it's not THAT horribly slow
I know that with more advanced scenes this is still not going to be fast enough, but i'll worry about that when that time comes...
ector is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PowerVR families - shader capabilities Megadrive1988 3D Architectures & Chips 29 05-Aug-2005 00:43
ImgTech launches programmable shader graphics for mobiles marco Press Releases 0 29-Jul-2005 09:40
nvidia GPU at 1 Ghz in ps3? version Console Technology 36 02-May-2005 20:03
Driver Heaven: The Project - Serious rendering issues Jawed 3D Hardware, Software & Output Devices 45 06-Feb-2005 09:51
5700, 5600, 9600 'Pure' DX9 Performances Dave Baumann 3D Architectures & Chips 72 31-Oct-2003 00:55


All times are GMT +1. The time now is 06:02.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.