Author Topic: Shadows in NWN1 - how do I fix shadow issues?  (Read 503 times)

Legacy_TheOneBlackRider

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Shadows in NWN1 - how do I fix shadow issues?
« on: August 18, 2015, 09:59:17 am »


               

I've been trying to get the shadows working ok on some objects, but (meanwhile) the creation of shadows really riddles me!


In this example, the model iteself is pretty complex (a well from The Witcher 1) and assigning a shadow render directly to the model meshes resulted in a weired chaotic shadow display (plus the engine tends to choke on them).

So, I created very simple shadow meshes (those meshes with no texture applied / redish ones): The mesh is not rendered, but creates shadows.


 


01_tw110.jpg


Now look at these simple pillars: Very few faces, all have the same smoothing group and: One pillar (the upper) casts a correct shadow, the other (the lower) not! Seems to be, that the engine doesn't recognize / ignores some of the faces...


 


(Edit: I don't know, if smoothing groups influence the calculation of shadows - I doubt it, but to be on the safe side, I set them all to the same value)


So, maybe someone can give me an explanation, on how shadows work / what causes this / how to fix this.

 



               
               

               
            

Legacy_MerricksDad

  • Hero Member
  • *****
  • Posts: 2105
  • Karma: +0/-0
Shadows in NWN1 - how do I fix shadow issues?
« Reply #1 on: August 18, 2015, 01:18:53 pm »


               

If you post your model we could immediately help you immediately and show you exactly what is wrong.


 


In the meantime, I can speculate;


 


When making shadows on models, I find that if there are multiple vertices at or near the same point, it can sometimes confuse itself in which direction the shadow should be cast. While building tilesets, I often forget to have the base ground shape be non-shadow-rendering. When I do this, the high complexity tends to make a shadow mess, often leaving an offset between where the shadow should be, and where the shadow actually is. The more complex the shape, the more issue it seems to make. I see you were going for low poly count on the legs, but if you could, actually count the vertices and see if there is maybe a loose vertex somewhere, or verts left over from separating it from the original model, if that is what you did.


 


I don't think you are using a skinned version of that shadow mesh, but something that can also happen is negative shadows. These occur when something pretty much impossible is created with a skin. Many skin shapes have this happen if a series of polygons create a self-touching concave shape. Often, the error returns a zero value, making the shadow polygon connect to point 0,0 on your map. Anything it paints over will be un-shadowed, and can cause other issues with rendering shininess and emitter particles. Another thing that can cause this is two or more faces sharing the same vertices, in order, or in a different order, so check for duplicate faces, either with a script that does so, or manually by making your model transparent and looking for brighter faces, or edges that cross each other.


 


If I had to make a suggestion before seeing your model code, I would suggest a simple select all vertices and then weld at 0.01 units. And if you have one, use the upgraded duplicate face finder, which I think is part of the nwMax upgrade by MDA.


 


Now, here's a strange thing that can happen. I know your top looks like a plain model from here, but if it is skinned for some reason, as if to use bones to create a jiggle not associated with wind/danglymesh, then your skinned non-shadow-rendering top can still cause negative shadow errors on surrounding objects. It makes no sense, because the shadows are turned off on the cap, but errors in any of the rendering can instill other meshes on the same model with mathematical errors. Check that the cap is not a skinned object, and if it is, try it as a non-skinned object, or otherwise clean up the complexity.



               
               

               
            

Legacy_NWN_baba yaga

  • Hero Member
  • *****
  • Posts: 1944
  • Karma: +0/-0
Shadows in NWN1 - how do I fix shadow issues?
« Reply #2 on: August 18, 2015, 04:40:56 pm »


               

Whatever the F*** bioware did with the shadows back then I dont know. They just seem to suck almost anytime you create a model that is not a "box". But if it is a "box" then detach all 6 faces from the box with 6 faces and yeah yadda yadda... that is greatly coded shadow mess '<img'>



               
               

               
            

Legacy_Zarathustra217

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +0/-0
Shadows in NWN1 - how do I fix shadow issues?
« Reply #3 on: August 18, 2015, 09:04:18 pm »


               In addition to MerricksDad said, also make sure the pivots of your shadow meshes are inside their geometry and somewhat in centre. Judging from your image, that entails splitting the mesh into several, one for each post.
               
               

               
            

Legacy_T0r0

  • Sr. Member
  • ****
  • Posts: 380
  • Karma: +0/-0
Shadows in NWN1 - how do I fix shadow issues?
« Reply #4 on: August 19, 2015, 12:16:53 am »


               

Clean models works wonders !



               
               

               
            

Legacy_TheOneBlackRider

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Shadows in NWN1 - how do I fix shadow issues?
« Reply #5 on: August 19, 2015, 10:00:39 am »


               

Thank you people! You pushed me into the right direction, so I made good progress.


 


I have CleanModel, but I really wanted to start to understand this a bit better or to what to pay attention to, so a shadow might work from the beginning.


 


Welding verts was a good point to start - I forgot about that, so thanks MerricksDad! In my case it is not a skinned or dangeled mesh, but since the source of those pillars was the original mesh, the chance of none welded verts was there. Well, there were none to weld (even in a bigger range).


I also checked for loose verts and backwards faces - none.


 


BTW. I didn't find the "duplicate face finder" - I'm using MDA's tool in Gmax. Is that a Max addition or am I just too blind (it was getting very late yesterday, while fiddling with the shadows).


 


Kind of frustrated at that point, I started to create a sample tile with this shadow mesh for you people to check out, what I'm missing. Since the part, where the original well was placed on, didn't fit into an NWN1 tileset (raised and more), I created a new (feature) override version for the ttr01 set. Now, things started to get weird for me:


1. The shadow of the pillar base differed from that of the original terrain.


2. The well roof didn't cast a shadow at all anymore, whatever I tried!


 


Since I had to lower the objects to cast a shadow on the ground of ttr01, I started to play with the height and found the following:


 


02_tw110.jpg


 


(Don't pay any attention to the texturing! It is very sloppy and just applied to have an orientation!)


When the pillars are touching the ground (or are above the ground), the casting of a shadow seems to be OK, which hints, that the mesh itself must be OK to calculate shadows. When lowered into the ground, the engine seems to have problems and creates new shadow artefacts! So, one reason for my issue might be the height position of the pillars.


 


But now for the roof: That was actually fixed by doing, what Zarathustra217 wrote: The pivot was not anywhere near the roof mesh. I centred it to the mesh and - tadaaaah - the shadow was back! (Not shown in the picture above.)


There after, I centred the pivot to the pillar group and this also improved things. So that might even get better, when each pillar gets its own pivot, which is centred INSIDE the pillar. I have not tested it, but this assumption is also supported by NWN_baba yaga approach (if I understood it correctly).


 


After these results, I was checking out something completely different and by accident stumbled upon the DLA custom content guide, which contains a section on shadows. It contains info on what you all already said (if I just would have found it earlier), but to make this post more complete, I'll add the DLA info to this post (Retrieved from "http://ccg.dladventu...ex.php/Shadows" via web.archive.org=WaybackMachine - it's somewhere on neverwintervault.org, but I forgot to copy the link...):


 


-------------


And in this guide is the answer to smoothing groups (see last DLA "note")!


-------------



Shadows


From NWN1 Custom Content Guide


To put it bluntly, shadows are a pain in the butt to check and fix, but when you understand how they operate in regards to the setup, it because a bit easier to do your modeling to account for this implementation.


The general rule of thumb to insure a model will cast a shadow properly is to draw a line from the pivot point of the mesh to the center and back of each face (poly) on the mesh (opposite the normals). No overlaps are allowed through other faces. So you can tell that NWN prefers convex objects.


 


Image:Shadows 01.jpg



A good easy example would be something like a box (cube), the pivot can be anywhere in the interior and the box will cast shadows properly.


Dark grey lines are from the pivot to the back of the face, the little lines poking from the face are the orientation of the normals.



Image:Shadows 02.jpg



Now, how about a slightly more complex object? Let's make it into a simple sword hilt and handle:



Image:Shadows 02a.jpg



Ut-ho, as we can see from the top view, there might be problems with the shadows, due to the bottom part of the hilt facing the other way. But with a simple move of the pivot closer to the center of the hilt, it works out ok:



Image:Shadows 03.jpg



And for really complex meshes with multiple layers of surfaces (barrels, trees) or is concave in nature? You can't do it with one pivot, so don't be afraid to split your mesh up into multiple objects. Take for instance, the standard NWN barrel:


As you can see, Bioware split the barrel walls into 4 parts so the lip of the walls at the top where the lid opens up will be able to cast a shadow properly when the barrel is 'opened'.


 


Note:



Objects with DanglyMesh (aka Flex) on them will cast shadows, but if you're dealing with a flat object like say the sail of a boat, it might be an idea to separate the sail into two objects.



Note:



Skinmesh objects will NOT cast shadows, but there is a simple trick here. Use the bones themselves. Set the trimeshproperties to not render but cast shadows. Oversize your bones and you can fake shadows fairly well with this approach while still being polygon conscious.



Note:



Extremely complicated large sized objects are better avoided altogether, as there is a limit to the number of objects a single model can have (you can't split a model of a rocket engine into zillions of pieces). A possible way around this, is to split the model into several smaller parts (less complicated models).



Note:



There's a little known, (Danmar says) loophole in the all faces must face away from the model's pivot point. And that loophole is that when there is _no_ smoothing data, each face is a not smoothed with its neighbors, then they will never cast bad shadows as a result.



Another solution is use a 'shadow proxy', that is, set the normal objects to be "Render=Yes, Shadow=No" then have a bunch of other (low poly) objects with "Render=No, Shadow=Yes" be the ones that actually cast the shadows. This also works out because the shadow casting tends to slow the game down, so by using a low poly object for the shadow casting, it potentially speeds up the game's frame rate.


--------------


Sadly, the included pictures are lost, but maybe somebody of you still has them on some old HD.


--------------


 


And in addition to the DLA guide this info from MDA's NWmax Panel - Mesh Tools:


• Check Shadows


performs a sanity check on the selected geom for possible shadow issues. Any geom that fails the check will have it's wire colour turned red. For this reason do not use red as a colour if you plan to use this function.


 


--------------


 


So, my sum up for now would be:


- Use simple meshes.


- If the original mesh is used for the shadow or it is the base for a shadow mesh, weld verts and check for back faces.


- Make sure, that the pivot is (centred) possibly inside the mesh, which is responsible for shadows.


- Pay attention to height between the ground and the object casting the shadow.


- Deactivate smoothing groups (if it's a shadow mesh only, where the mesh itself is not rendered / only there for letting the engine create a shadow).



               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
Shadows in NWN1 - how do I fix shadow issues?
« Reply #6 on: August 19, 2015, 01:59:17 pm »


               

Good find, but the only thing I choke on is the "deactivate smoothing groups". Great for minecraft, not so great for detailed models looking correct. The far better solution is Danmar's low poly shadow boxes.



               
               

               
            

Legacy_TheOneBlackRider

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Shadows in NWN1 - how do I fix shadow issues?
« Reply #7 on: August 19, 2015, 03:09:31 pm »


               


Good find, but the only thing I choke on is the "deactivate smoothing groups". Great for minecraft, not so great for detailed models looking correct. The far better solution is Danmar's low poly shadow boxes.




Well, it's RETRO, isn't it?? '<img'>


Of course, you're right. I was unclear! ':whistle:' I was refering to a non rendered shadow mesh as in my model in the first post. Changed in my former post.


               
               

               
            

Legacy_TheOneBlackRider

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Shadows in NWN1 - how do I fix shadow issues?
« Reply #8 on: August 20, 2015, 07:42:37 am »


               

Pstemarie just posted a link in another thread and that is the place, where I found the complete DLA ccg (cutom content guide), which contains the shadow information posted above:


 


The NWN University (Document, Help, PDF, Reference Guide, Tutorial, XLS Collection)


http://neverwinterva...-xls-collection



               
               

               
            

Legacy_TheOneBlackRider

  • Hero Member
  • *****
  • Posts: 512
  • Karma: +0/-0
Shadows in NWN1 - how do I fix shadow issues?
« Reply #9 on: August 31, 2015, 11:21:37 am »


               

Another (very usefull) finding on shadows by OTR:


http://forum.bioware...es-and-shadows/