# Shadow Volume Artifact (Screenshot Included)

This topic is 4937 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Following Picture consists of two screens: Scr2 displays working volume shadows with torus (from SDKs .x file). Scr1 displays my character model (1500 tris). As you can see, the characters shadow is messed up. What could be the problem, when the torus has correct shadow ? The only thing Im changing is shader where the only difference is in declaration where there is also a texture coordinate (I know its not needed for shadows, but its OK for start since I dont need to create separate Stream). Torus doesnt have texture coordinates but this shouldnt be an issue, since the character model renders correctly in first pass. Any ideas what could be wrong ? Thanks

##### Share on other sites
When computing the shadow volume from your mesh, you need to take into account its vertex stride, in order to get each vertex position.
If your mesh has a UV coordinate, its vertex stride is bigger than if it hasn't...
Check the FVF declaration (or vertex declaration) when computing shadow volume in order to properly get vertices positions from the VB...

##### Share on other sites
But, isnt stride important only in fixed-function pipeline ? I mean, I dont have to set FVF for my character shader, since its DWORD [] Declaration has all that a shader needs , right ?
Besides, if it is a stride problem, how come that the character model is rendered correctly without shadow passes, i.e. when i render only the character ?
And another difference is that the torus is rendered with DrawIndexedPrimitive, while the character is rendered only with DrawPrimitive (i.e. no idices). But that shouldnt matter, right ?

##### Share on other sites
Ok, it took me a half an hour, but I created a separate VB (to make sure that stride isnt a problem)without texture coordinates from original data, therefore now Im using same FVF&Shader declaration as with what is present with torus (that works). Still the same problem, when I render torus, its ok, but when i render character, its shadow is same as in above picture - though the character is rendered properly, so it might be something with the mesh itself ? Or something completely different ?

##### Share on other sites
hi,

In the left screenshot, your mesh is simply not a closed shape (well, the artefacts are really similar to the ones you have when rendering a non closed mesh)
e.g. some edges are connected to only 1 face.
You've got 2 choices here : close your mesh using your favorite 3D software, or implementing an algorithm that add faces to close the mesh just after loading it.

.:: Paic Citron ::.

##### Share on other sites
Hm,thanks, but what is the problem with non-closed triangles (if that is really the problem), when Im using non-indexed rendering through DrawPrimitive ? I mean, vertex shader receives triangle after triangle, how can it know if some edge is shared by one/two/more triangles ? I obviosuly seem to misss some fundamental issue here. I already did some basic search on closed meshes here on gamedev, but only one topic discussed it a little further so far.

The only thing Im thinking of now is the difference in position for same vertex in different edges (although it might be a difference in a range of 0,0001), which could after projection be bigger and therefore visible.

Can anyone shed some light why that [closed tris] is problem ?

Thanks

##### Share on other sites
How big is the buffer for the shadow volume? It might work fine with a torus that only has 500 vertices, but then crap out when you're building a volume for something with 1500 for a pretty simple reason -- there isn't enough room in the buffer.

##### Share on other sites
hi again

question : how do you compute your shadow volume : do you compute it in software, are do you use a shader to do the extrusion of the vertices ?

And i'm pretty sure that the problem comes from the mesh which is not closed.

You can try something : model a simple closed shape with the program you used to model your character (a sphere then move some vertices for example) and then export it as .x the same way you did for your character and test the result.

If you don't see artefacts, that means that the problem comes from what I said (not a closed mesh)

.:: Paic Citron ::.

##### Share on other sites
Quote:
 Original post by EtnuHow big is the buffer for the shadow volume? It might work fine with a torus that only has 500 vertices, but then crap out when you're building a volume for something with 1500 for a pretty simple reason -- there isn't enough room in the buffer.
Hm, Im not sure what you are talking about, youre not talking about vertex buffer, right ? Because those are created separately for both torus and character. Its just render functions that I rename - i.e. either it renders torus or character, the rest of code remains unchanged so that i can easily find the source of problems.
If you mean some other buffer, maybe thats the problem, since Im not creating one, although its strange that torus casts shadows just OK (if this buffer is the problem, that is).

##### Share on other sites
Quote:
 Original post by paichi againquestion : how do you compute your shadow volume : do you compute it in software, are do you use a shader to do the extrusion of the vertices ?I will give more details after your answer ^^And i'm pretty sure that the problem comes from the mesh which is not closed.You can try something : model a simple closed shape with the program you used to model your character (a sphere then move some vertices for example) and then export it as .x the same way you did for your character and test the result.If you don't see artefacts, that means that the problem comes from what I said (not a closed mesh) .:: Paic Citron ::.

Within an hour the modeller should come to my place and well try exporting simpler objects first to .X file and then to our formats, although format is 99% problem-free. Well try parts of character and later whole character.

Regarding algorithm, I use shader to extrude the volume (move vertices along normal), first render it normally (to color buffer), then change the shader to extrude shader and render to stencil twice (increment, decrement). Of course there are plenty of render-state changes in-between. But the code is probably OK, since it works with torus, so the more probable answer is that the problem is in closed shape.

Ill report back as soon as we try different exported objects. Thanks.

##### Share on other sites
I had similar problem. My meshes were not closed too... I even tried this algorithm on boxes (which is far from closed)... very ugly results ;)

##### Share on other sites
Quote:
 Original post by BulmaI had similar problem. My meshes were not closed too... I even tried this algorithm on boxes (which is far from closed)... very ugly results ;)Now I use shadow mapping instead 0:-)
In the mean-time Ive searched gamedev with google (wow it works finally after the recent site changes, never worked before during last years) and everybody seems to offer same advice go with shadow maps. Just a quick question, shadow-maps dont care if a mesh is not closed ? Because weve got about 8 characters fully animated and imported into engine. I dont want to start exporting them again,that would be a nightmare. And thats considering that all holes would be closed in modelling program easilly, which doesnt seem to be the case based on what ive read so far...

##### Share on other sites
The DirectX 9.0c SDK (and perhaps earlier I'm not sure) shadow volume sample documentation explains how to modify your mesh so that it remains closed when extruded by the shader.