Home » Community » Forums » » Cg Bumpmapping
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Cg Bumpmapping
Post Reply 
Never seen some code of transforming light into object-space - something that would interest me MOST

 User Rating: 1015    Report this Post to a Moderator | Link

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

 User Rating: 1052   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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)


 User Rating: 1099   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

And why the is vertex program not used? If hardware can do fragment part, it can also for shure do the vertex processing!

 User Rating: 1015    Report this Post to a Moderator | Link

quote:
Original post by Jolle
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


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.

 User Rating: 1020   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by terminate
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.



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.


 User Rating: 1020   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by 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!


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]

 User Rating: 1020   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

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.

 User Rating: 1020   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

quote:
Original post by surdules
[ However, given that the vertex transformations were extremely simple (just multiply each vertex with the modelview matrix), I decided to avoid the extra complexity.



?? And light vector transformation? Or are you doing it in software? I guess hardware be the better way.



 User Rating: 1015    Report this Post to a Moderator | Link

quote:
Original post by Anonymous Poster
?? And light vector transformation? Or are you doing it in software? I guess hardware be the better way.


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.

 User Rating: 1020   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

e bine sa vezi articole facute si de romani !

spor la treaba


 User Rating: 1506   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Multumesc :-)

Bafta multa,

Razvan.

 User Rating: 1020   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

So, where DO you transform the light into tangent space?

 User Rating: 1015    Report this Post to a Moderator | Link

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() );
}



 User Rating: 1022   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: