Thread: RE: [Algorithms] Scaling Models
Brought to you by:
vexxed72
From: John W. <jo...@de...> - 2000-07-27 20:49:09
|
I sat down after I sent the message and came to the conclusion that in the general case I'd have to scale the normals too and perform a normalization per normal which is completely out of the question as the impact on the performance will be too excessive. I'm either going to do one of two things. 1) Ignore it and live with the slightly wrong lighting. I don't let the relative scales differ by too much as I don't trust the Mip-LOD functions when you get high U:V coverage ratios, so the effect shouldn't be too noticeable if at all. 2) make a copy of each model and recalculate the normals. The models which get scaled are quite low poly so the extra memory shouldn't be too much of a problem. I was planning to do this anyway to maximize the number of pols in the static VBs. I use the API to do the Local->Screen xforms but all the lighting xforms is completely in software so HW TnL isn't hampered. The API never sees the normals, I pass verts through in LVERTEX format. I was just wondering what D3D\OpenGL would do if I passed the normals through which is why I didn't mail to those groups. Thanks for the HW TnL warning though. JohnW -----Original Message----- From: Tom Hubina [SMTP:to...@3d...] Sent: 27 July 2000 21:15 To: gda...@li... Subject: Re: [Algorithms] Scaling Models At 05:06 PM 7/27/2000 +0100, you wrote: >If you set a scaling matrix as part of the transformation pipeline what >happens to the normals? >I currently use D3D\OpenGL to do the transformation but use my own lighting >code. If I set a scaling factor to each of the 3 axes the angles of most of >the faces in the model will change (unless the scaling factor is the same >for all three axes). An extreme example is when XSc=ZSc=1.0f; YSc=0.0f; All >normals will either become 0,0,0 (for triangles with a normal perpendicular >to the Yaxis) or 0,1,0 for all other normals. > >Rebuilding the normal list is not an option as the models are shared >multiple times with different scalings. > >Anybody else encountered this problem? And how does D3D\OpenGL cater for >this? In GL the normals are scaled and rotated by the modelview matrix (homogenous matrix stuff ... translations are ignored). GL allows you to normalize the transformed normals with: glEnable(GL_NORMALIZE); This does come with an added per-normal cost, but on T&L cards like the GeForce, the operation is done by the hardware so you don't lose the ability to use hardware transforms. I don't know if there is a similar operation under DX, but it seems likely. Something just dawned on me though, you use the API do the transforms, but you do your own lighting ... If you're querying the API for the results of the transformations you're really going to ruin performance on hardware T&L cards. If you don't need the transformed coordinates to do your lighting, then you probably don't need to send normals to the API at all. They're only used for lighting and some of the texture coordinate generation modes (spherical I think). Specific OpenGL and Direct3D issues should be taken to their respective mailing lists. Tom _______________________________________________ GDAlgorithms-list mailing list GDA...@li... http://lists.sourceforge.net/mailman/listinfo/gdalgorithms-list |
From: Peter W. <Pet...@vi...> - 2000-07-28 10:16:41
|
<snipped stuff about scaling and normals> Just out of interest, one thing I did a while back when I needed to treat both normals and vertex positions uniformly when applying an animation matrix to them was set the W component of the normals to 0, whilst leaving the W component of the positions at 1. This worked because the animation matrix never contained a scale, and I just wanted to not translate the normals. Is this a well-known technique that I just haven't run across before, and is there any theoretical basis for it? Peter Warden Visual Sciences |
From: Jim O. <j.o...@in...> - 2000-07-28 18:50:49
|
I think OpenGL handles normals in the same way (and if I am not mistaken, OpenGL also uses some sort of inverse transform on normals, instead of feeding them to the 'normal' pipeline, which I presume is to counter the effects of scaling etc. on the normals...) Jim Offerman Innovade - designing the designer ----- Original Message ----- From: "Peter Warden" <Pet...@vi...> To: <gda...@li...> Sent: Friday, July 28, 2000 12:18 PM Subject: RE: [Algorithms] Scaling Models > > <snipped stuff about scaling and normals> > > Just out of interest, one thing I did a while back when I needed to treat > both normals and vertex positions uniformly when applying an animation > matrix to them was set the W component of the normals to 0, whilst leaving > the W component of the positions at 1. This worked because the animation > matrix never contained a scale, and I just wanted to not translate the > normals. Is this a well-known technique that I just haven't run across > before, and is there any theoretical basis for it? > > Peter Warden > Visual Sciences > > _______________________________________________ > GDAlgorithms-list mailing list > GDA...@li... > http://lists.sourceforge.net/mailman/listinfo/gdalgorithms-list > |
From: <ro...@do...> - 2000-07-29 05:05:40
|
Jim Offerman wrote: >I think OpenGL handles normals in the same way (and if I am not mistaken, >OpenGL also uses some sort of inverse transform on normals, instead of >feeding them to the 'normal' pipeline, which I presume is to counter the >effects of scaling etc. on the normals...) > Actually it needs to apply the transpose of the inverse of the matrix to the normals, then renormalize, to be always correct. But this would be wasteful in the majority of the cases that the transformations are orthogonal. APIs need to have a provision for the programmer to hint whether of not the transformations are orthgonal. |
From: Tom H. <to...@3d...> - 2000-07-28 21:41:15
|
At 11:18 AM 7/28/2000 +0100, you wrote: ><snipped stuff about scaling and normals> > >Just out of interest, one thing I did a while back when I needed to treat >both normals and vertex positions uniformly when applying an animation >matrix to them was set the W component of the normals to 0, whilst leaving >the W component of the positions at 1. This worked because the animation >matrix never contained a scale, and I just wanted to not translate the >normals. Is this a well-known technique that I just haven't run across >before, and is there any theoretical basis for it? Yeah, the general term I see used for it is homogenous matrices. I set up my math libs to work with a class that describes a 4x4 homogenous matrix, a class that describes a 1x3 vector and a derived class that describes a 1x3 point. The matrix class has overloaded functions for multiplication where one takes a point and the other takes a vector. When a vector is used, the unspecified fourth component is assumed to be 0. When a point is used, the unspecified fourth component is assumed to be 1. In both cases the matrix math is simpler than a full transform since the constant allow some of the operations to be removed. I also have a 1x4 vector class for general transforms. I don't generally use scales on matrices this way (and the description is atrocious from a math standpoint) so Ron can correct me here as needed, but I seem to recall there being two ways to add a scale to a matrix. For a non-uniform scale you can monkey with the different components to get what ya need, or for a uniform scale you can insert the scale value directly into the lower right corner of the matrix. If you're doing a uniform scale, and using homogenous matrices as I've described above you wouldn't need to re-normalize the normal since the uniform scale would be ignored for vectors (since the 4th component is zero). Vectors will still be affected by the more traditional scales, and even if they're uniform, will need to be normalized before they can be used in most lighting and environment mapping situations. Tom |
From: <ro...@do...> - 2000-07-29 05:14:49
|
Tom Hubina wrote: >I don't generally use scales on matrices this way (and the description is >atrocious from a math standpoint) so Ron can correct me here as needed, but >I seem to recall there being two ways to add a scale to a matrix. For a >non-uniform scale you can monkey with the different components to get what >ya need, or for a uniform scale you can insert the scale value directly >into the lower right corner of the matrix. Yes, for the uniform scale this is a trick that works in the context of the 4x4 matrix, but it doesn't fall out until you do the projection. That is, you end up with points that have w != 1 before projecting. This is an ugly artifact of the 4x4 homogeneous formulation, which I detest. Part of its ugliness is that it doesn't generalize to the non uniform scale. >If you're doing a uniform scale, >and using homogenous matrices as I've described above you wouldn't need to >re-normalize the normal since the uniform scale would be ignored for >vectors (since the 4th component is zero). Vectors will still be affected >by the more traditional scales, and even if they're uniform, will need to >be normalized before they can be used in most lighting and environment >mapping situations. > And of course, in the case that the transformation contains within it a non-uniform scale, you are completely wrong unless you transpose(inverse(the upper 3x3)), before applying it to the normal vectors. See my response to the original post of this thread. |
From: <ro...@do...> - 2000-07-29 05:06:59
|
Peter Warden wrote: > ><snipped stuff about scaling and normals> > >Just out of interest, one thing I did a while back when I needed to treat >both normals and vertex positions uniformly when applying an animation >matrix to them was set the W component of the normals to 0, whilst leaving >the W component of the positions at 1. This worked because the animation >matrix never contained a scale, and I just wanted to not translate the >normals. Is this a well-known technique that I just haven't run across >before, and is there any theoretical basis for it? > This would be the correct way to treat the w components WHETHER OR NOT the transformation contains a scale. It is inherent in the meaning of "vector". See my response to the original post of this thread. |
From: <ro...@do...> - 2000-07-29 13:42:11
|
Peter Warden wrote: >Just out of interest, one thing I did a while back when I needed to treat >both normals and vertex positions uniformly when applying an animation >matrix to them was set the W component of the normals to 0, whilst leaving >the W component of the positions at 1. This worked because the animation >matrix never contained a scale, and I just wanted to not translate the >normals. Is this a well-known technique that I just haven't run across >before, and is there any theoretical basis for it? > This is the correct way to treat the w components WHETHER OR NOT the transformation contains a scale. You never need to "translate normals" because the translation of a vector (as opposed to the translation of a point) is always the vector itself. It is inherent in the meaning of "vector". See my response to the original post of this thread. |
From: <Chr...@Pl...> - 2000-07-30 21:44:51
|
Ron Levine wrote: >A frightening demonstration of the folly of relying on spell checkers, >rather than careful proof reading, in the wee small hours. Sorry to be an off-topic smartass, but I cannot resist: that should be *spelling* checker. A spell checker is something only a witch would use. Christer Ericson SCEA, Santa Monica |
From: Stephen J B. <sj...@li...> - 2000-08-01 12:58:59
|
On Sun, 30 Jul 2000 Chr...@pl... wrote: > Ron Levine wrote: > >A frightening demonstration of the folly of relying on spell checkers, > >rather than careful proof reading, in the wee small hours. > > Sorry to be an off-topic smartass, but I cannot resist: that should be > *spelling* checker. A spell checker is something only a witch would use. Seems fair... "He who lives by the pedantry shall die by the pedantry." Steve Baker (817)619-2657 (Vox/Vox-Mail) L3Com/Link Simulation & Training (817)619-2466 (Fax) Work: sj...@li... http://www.link.com Home: sjb...@ai... http://web2.airmail.net/sjbaker1 |