|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Cg Bumpmapping |
|
![]() Anonymous Poster |
||||
|
||||
| Never seen some code of transforming light into object-space - something that would interest me MOST |
||||
|
||||
![]() Jolle Member since: 10/19/2002 From: Gbg, Sweden |
||||
|
|
||||
| Just do as you do when you want to transform the camera (and the view frustum) into object-space... at least, it works for me |
||||
|
||||
![]() terminate Member since: 6/1/2000 From: Las Vegas, NV, United States |
||||
|
|
||||
| Just a quick note, I will try to post more when I get home. Saying that the fragment programs will only execute on the nVidia cards on OpenGL isn't exactly true. What it should have said is "The fragment program will only work on nVidia Geforce3+ and Radeon 9500+ cards". When using Cg on an ATI Radeon 9500/9700, cgGetLatestProfile(CG_GL_FRAGMENT) will return CG_PROFILE_ARBFP1 which will in turn use the ARB_fragment_program extension. -Evan --------------------------- Those who dance are considered insane by those who cannot hear the music. Focus On: 3-D Models Evan Pipho (evan@codershq.com) |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| And why the is vertex program not used? If hardware can do fragment part, it can also for shure do the vertex processing! |
||||
|
||||
![]() surdules Member since: 4/15/2003 |
||||
|
|
||||
quote: Jolle is right--transformation from light to object-space should be very similar to transformation from camera to object-space. Can you post more details on what exactly you're trying to do? Razvan. |
||||
|
||||
![]() surdules Member since: 4/15/2003 |
||||
|
|
||||
quote: This is indeed accurate--apologies for the mistake in the article! A correction should be posted to the article momentarily. In the mean time, the "Hardware Environment" section should read like this: The code has been tested on a GeForce4 Ti 4200 video card. The code should run on a GeForce3 (or better) or a Radeon 9500 (or better) card. In general, Cg OpenGL requires a GPU with support for either ARB_vertex_program/ARB_fragment_program (GeForceFX (or better) or Radeon 9500 (or better) families) or NV_vertex_program/NV_texture_shader/NV_register_combiners (GeForce3 (or better) family). Razvan. |
||||
|
||||
![]() surdules Member since: 4/15/2003 |
||||
|
|
||||
quote: You're right: I could have used a vertex program to do the vertex transformations. However, given that the vertex transformations were extremely simple (just multiply each vertex with the modelview matrix), I decided to avoid the extra complexity. I am currently working on another Cg article specifically focused on (non-trivial) vertex programs. That article should dove-tail nicely off this one. Razvan. [edited by - surdules on April 15, 2003 7:02:35 PM] |
||||
|
||||
![]() surdules Member since: 4/15/2003 |
||||
|
|
||||
| For those interested in learning more about Cg, I highly recommend "The Cg Tutorial": http://developer.nvidia.com/view.asp?IO=cg_tutorial_home Razvan. |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
quote: ?? And light vector transformation? Or are you doing it in software? I guess hardware be the better way. |
||||
|
||||
![]() surdules Member since: 4/15/2003 |
||||
|
|
||||
quote: The light vector transformation is similarly simple: multiply the light position by a matrix. Yes, the matrix-vector multiplications are faster in hardware, but in this case it's overkill (the entire model has less than 15 vertices) and it would make the article longer and unnecessarily more complicated. I prefer to use vertex shaders for situations where it really matters (i.e. complex vertex transformations for a large number of vertices). Razvan. |
||||
|
||||
![]() Ilici Member since: 3/23/2003 From: Bucuresti, Romania |
||||
|
|
||||
| e bine sa vezi articole facute si de romani ! spor la treaba |
||||
|
||||
![]() surdules Member since: 4/15/2003 |
||||
|
|
||||
| Multumesc :-) Bafta multa, Razvan. |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| So, where DO you transform the light into tangent space? |
||||
|
||||
![]() vmh5 Member since: 1/13/2004 |
||||
|
|
||||
| Though this code was very helpful to me it needs some attention: The code that computes the tangent and binormal in the constructor of Triangle in triangle.cpp is incorrect. You can tell by how the lighting of the cube in shader mode changes as you rotate it that something a bit weird is going on. If you use something other than a cube the effects are far worse. The problem is that the tangent and binormal are not being computed at all: float denominator = (s1 * t2 - s2 * t1); if (denominator < EPSILON) { // If we cannot solve for t and b, use the IDENTITY Matrix m_objectToTangentSpace.push_back(Matrix::IDENTITY); } You want to check if the denominator is 0 (i.e. within epsilon of zero) not wether it's negative or not! Since it's always negative the tangent space vector is always identity. This is sort of OK with planes and cubes but not with other objects. fixing this to: if ( fabs(denominator) < EPSILON) reveals that the object to tangent space code is also incorrect. I changed it to the code below. Now the example also works for other geometry: float det = (s1 * t2 - s2 * t1); if ( fabs(det) < EPSILON) { // If we cannot solve for t and b, use the IDENTITY Matrix m_objectToTangentSpace.push_back(Matrix::IDENTITY); } else { const Vector& normal = getNormal( currentIndex ); Vector b = Vector( (-s2 * v1v0[Vector::X] + s1 * v2v0[Vector::X]) / det, (-s2 * v1v0[Vector::Y] + s1 * v2v0[Vector::Y]) / det, (-s2 * v1v0[Vector::Z] + s1 * v2v0[Vector::Z]) / det).normalize(); Vector t = normal.cross(b); m_objectToTangentSpace.push_back( Matrix(t, t.cross(normal), normal).invert() ); } |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|