3D models, vertex normals, and lighting

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • 3D models, vertex normals, and lighting

      Hey all,

      I have an interesting situation and was wondering if anyone had any suggestions.

      I have a problem here that I am not sure how to solve and the solution may be software or something that can be done in 3DS Max.

      Problem: Calculating the vertex normals is taking too long and causes unexeptable load times. Soon to double when the new models come. If I use the normals from the .x file the image is dark and not as sharp. If I turn on ambient lighting the image is bright but still not sharp and is hard to see the details.

      Caveats: I am using .x files, so parsing manually into home grown objects, (thus not able to use DirectX_object->Normalize) but rendering in OpenGL. The vertex normal calculations are done after all the models and textures are loaded, its the last operation before the images are rendered.

      Is anyone familiar enough with 3DS Max to tell me if vertex normals can be calculated during the export to an X file?

      Are there some lighting techniques (a special combination of ambient/spot/specular) to acheive a sharper and brighter image?

      I am currently researching the possibility of using a script in Max if possible. During the export process there is an option pick a script to run on the file.

      Thanks!
    • RE: 3D models, vertex normals, and lighting

      Hmm, has never exported any .X-file from 3D studio Max myself, but I had some problems with .X-files. That format gets changed so much, so I have found many incompabilities with that format unfortunately. Though since the normals etc does not change between different versions, they should be correct.

      But it's easy to se if you have gotten the normals in the X-file, since it is a text-file and not a binary file. If they excist, it should be correct. It sounds wierd that the images is less sharp when you read the normals from file, that makes no sense to me...

      And the calculation of normals is not a very costly calculation, so it's wierd that it takes a lot of loading time. But I could be wrong, I have mostly used DirectX/HLSL, which takes care of most of these things "beneath the hood".

      Are you sure it's not the calculated normals that is incorrect instead? I think you can try to invert the calculated normals/change culling mode, since you for example maybe calculate them counter-clockwise, and 3DS Max calculated them clockwise. You should then get the same apperance as with the X-file's normals. Otherwise, either the calculated normals or the X-files normals are for some reason incorrect...

      Hope that helps :)
    • I appreciate your response.

      The normals in the .x file are mesh normals not vertex normals. I tried to use those to find the average but maybe the cullling was reversed. Its wierd cuz the image is fine when I use them its just to dark.

      The plug in that we use to export the file to .x format is Pandasoft.

      ::sigh:: I am so not the 3d expert. ;\

      Its funny cuz we are using .x files but rendering with OpenGL. So alot of the stuff that would be done using DX objects is done manually instead.
    • I'm not sure if I have understand what you want exactly. Do You want normals that isn't averaged of the adjacencient polygons? Because the .x-files normals is averaged in that way, and that's probably what you should use, if you want the shading to interpolate on the polygons correctly. I usually have the polygon normals and the vertex normals separately.

      To that loading-time problem, you could write a program that's converting the normals of the .x-file before parsing them in your game. Either in a exporting script to Max, or a separate program. Then you don't get any extra loading time at all.
      "There are of course many problems connected with life, of which some of the most popular are: Why are people born? Why do they die? Why do they want to spend so much of the intervening time wearing digital watches?"
      -Douglas Adams
    • Originally posted by steelblood_relic

      To that loading-time problem, you could write a program that's converting the normals of the .x-file before parsing them in your game. Either in a exporting script to Max, or a separate program. Then you don't get any extra loading time at all.


      Thats what I was really looking for. I am not a Max user I dont even have access to Max here to test plug-ins. So I was looking for an export script for Panda or a different plug-in that has a built in feature to do this. Any recomendations on what would work is very helpful, because I have to jump through giant firey hoops just to get one installed so I i'd like to get the right one on the first try :)


      In the meantime I am doing the calculations and storing them to a file to read at load time. I dont like this approach though because if the models change its just another step in the process that could cause ambiguity.

      The real ticket here would be doing it on the Max side of things.

      Thanks

      The post was edited 1 time, last by DragonCode ().

    • I'm nor sure about whether vertex normals exist in Max files - and I am a little curious about why these are taking too long to calculate (normal calculation is just a cross product and a vector normalize - so it's not that bad).

      That said...

      You could just calculate the normals once, and store them in a data file.... this kind of thing is pretty common in game development, where you have data that doesn't exist in the source file, but you need to calculate it on load time.

      Go ahead and calculate it, save it in a data file somewhere and on subsequent loads all you have to do is compare the dates of the normals file and the source mesh. If the source mesh is newer, recalculate the normals.
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • Originally posted by mrmike
      I'm nor sure about whether vertex normals exist in Max files - and I am a little curious about why these are taking too long to calculate (normal calculation is just a cross product and a vector normalize - so it's not that bad).


      We are using .X files exported from Max using Panda. So Max file -> export to .x file.

      I picked up this project after a couple years of dev time and it Loads the .x files manually and the data is then used in an OGL engine. I considered rewriting the entire thing to use DirectX, but can't due to time constraints.

      The algorithm we are using to calculate the normals may not be the most efficient and it doesn't take advantage of any hardware. I am going to investigate that but not until I have a short term solution.
      That said...


      You could just calculate the normals once, and store them in a data file.... this kind of thing is pretty common in game development, where you have data that doesn't exist in the source file, but you need to calculate it on load time.

      Go ahead and calculate it, save it in a data file somewhere and on subsequent loads all you have to do is compare the dates of the normals file and the source mesh. If the source mesh is newer, recalculate the normals.


      This is exactly what the short term solution we decided to go with is, and I am happy to see that it is not a ridiculous one. :)

      As a matter of fact I'm working on the parser right now and its blowing up in a destructor 8o but I am having a lot of fun with it!

      Thanks,

      - dragon
    • Originally posted by DragonCode
      The algorithm we are using to calculate the normals may not be the most efficient and it doesn't take advantage of any hardware. I am going to investigate that but not until I have a short term solution.
      That said...


      But still, it shouldn't be that slow, unless your processor is from the stone age. :)

      Have you ran the debugger on the code that calculate the normals so that you know that you calculate them correctly?

      Originally posted by DragonCode
      Thats what I was really looking for. I am not a Max user I dont even have access to Max here to test plug-ins. So I was looking for an export script for Panda or a different plug-in that has a built in feature to do this. Any recomendations on what would work is very helpful, because I have to jump through giant firey hoops just to get one installed so I i'd like to get the right one on the first try Smile


      If you don't want to put a lot of time in learning Max scripting, or if you can't for some reason write scripts for Max, my suggestion is that you make a program that reads an .x-file, calculates/converts the normals and save it to the file. You could also make a batch file to automate the process.
      "There are of course many problems connected with life, of which some of the most popular are: Why are people born? Why do they die? Why do they want to spend so much of the intervening time wearing digital watches?"
      -Douglas Adams
    • Hehe.... processor is definitely not a dirtbag. I think I may have too many iterations in the calculations loop, but thats for another investigation at a later time. It looks like I am doing the next best thing cuz thats 2 suggestions for what I decided to go with at the time I posted the original question.

      Calc -> save
      if(files are ok)
      read
      else
      calc and save

      Ive kicked around making it a seperate app to run on new models but I dont want to add an extra step for various logistical reason.

      I was wondering though, in the normal way of doing this, say you were using all DirectX, does DX usually do the calculations in hardware of the board supports it?

      Becasue the native DirectX viewer is lightning fast on the load of the .x files.

      Thanks for all the feedback!