FatalXC

10-11-2002, 04:42 AM

Hi,

I've nearly got my per pixel specular term complete. Currently it does:

4 * ((N dot H')^2 - 0.75) * attenuation * gloss * light filter * light color

which gives a nice specular term. The problem is though, as you move around the scene the specular highlight sort of warps around polygon edges.

I am using a normalization cube map to normalize the H vector.

I think the problem is the transformation of the H vector into tangent space. here is the code that computes a polygons orthonormalbasis:

const void Polygon3d::calculateONB()

{

const Vec3 v1 = vertex(0) - vertex(1);

const Vec3 t1 = Vec3(vertex(0).u(), vertex(0).v(), 0.0f) - Vec3(vertex(1).u(), vertex(1).v(), 0.0f);

const Vec3 v2 = vertex(2) - vertex(1);

const Vec3 t2 = Vec3(vertex(2).u(), vertex(two).v(), 0.0f) - Vec3(vertex(1).u(), vertex(1).v(), 0.0f);

const Vec3 ddx = Vec3(v1.x(), t1.x(), t1.y()).cross(Vec3(v2.x(), t2.x(), t2.y()));

const Vec3 ddy = Vec3(v1.y(), t1.x(), t1.y()).cross(Vec3(v2.y(), t2.x(), t2.y()));

const Vec3 ddz = Vec3(v1.z(), t1.x(), t1.y()).cross(Vec3(v2.z(), t2.x(), t2.y()));

m_onb.tangent() = Vec3(-ddx.y() / ddx.x(), -ddy.y() / ddy.x(), -ddz.y() / ddz.x()).normalized();

m_onb.binormal() = Vec3(-ddx.z() / ddx.x(), -ddy.z() / ddy.x(), -ddz.z() / ddz.x()).normalized();

m_onb.normal() = plane().n();

}

The H vector is then calculated per vertex as:

Vec3 halfAngle = (lightPos - poly->vertex(j)).normalized() + ((cameraPos - poly->vertex(j)).normalized());

and transformed into tangent space like this:

s = halfAngle.dot(poly->onb().tangent());

t = halfAngle.dot(poly->onb().binormal());

r = halfAngle.dot(poly->onb().normal());

s,t,r are then used as texture coordinates for the normal cube map

If someone could shed some light (pun intended) on the situation, I would be most greatful. This is the last little bit of the lighting equation I have left to finish, before moving on to bigger and better things !! :-)

The diffuse bump mapping and attenuation looks fine, ie doesn't have any obvious artifacts.

Thank you,

Richard

[This message has been edited by FatalXC (edited 10-11-2002).]

I've nearly got my per pixel specular term complete. Currently it does:

4 * ((N dot H')^2 - 0.75) * attenuation * gloss * light filter * light color

which gives a nice specular term. The problem is though, as you move around the scene the specular highlight sort of warps around polygon edges.

I am using a normalization cube map to normalize the H vector.

I think the problem is the transformation of the H vector into tangent space. here is the code that computes a polygons orthonormalbasis:

const void Polygon3d::calculateONB()

{

const Vec3 v1 = vertex(0) - vertex(1);

const Vec3 t1 = Vec3(vertex(0).u(), vertex(0).v(), 0.0f) - Vec3(vertex(1).u(), vertex(1).v(), 0.0f);

const Vec3 v2 = vertex(2) - vertex(1);

const Vec3 t2 = Vec3(vertex(2).u(), vertex(two).v(), 0.0f) - Vec3(vertex(1).u(), vertex(1).v(), 0.0f);

const Vec3 ddx = Vec3(v1.x(), t1.x(), t1.y()).cross(Vec3(v2.x(), t2.x(), t2.y()));

const Vec3 ddy = Vec3(v1.y(), t1.x(), t1.y()).cross(Vec3(v2.y(), t2.x(), t2.y()));

const Vec3 ddz = Vec3(v1.z(), t1.x(), t1.y()).cross(Vec3(v2.z(), t2.x(), t2.y()));

m_onb.tangent() = Vec3(-ddx.y() / ddx.x(), -ddy.y() / ddy.x(), -ddz.y() / ddz.x()).normalized();

m_onb.binormal() = Vec3(-ddx.z() / ddx.x(), -ddy.z() / ddy.x(), -ddz.z() / ddz.x()).normalized();

m_onb.normal() = plane().n();

}

The H vector is then calculated per vertex as:

Vec3 halfAngle = (lightPos - poly->vertex(j)).normalized() + ((cameraPos - poly->vertex(j)).normalized());

and transformed into tangent space like this:

s = halfAngle.dot(poly->onb().tangent());

t = halfAngle.dot(poly->onb().binormal());

r = halfAngle.dot(poly->onb().normal());

s,t,r are then used as texture coordinates for the normal cube map

If someone could shed some light (pun intended) on the situation, I would be most greatful. This is the last little bit of the lighting equation I have left to finish, before moving on to bigger and better things !! :-)

The diffuse bump mapping and attenuation looks fine, ie doesn't have any obvious artifacts.

Thank you,

Richard

[This message has been edited by FatalXC (edited 10-11-2002).]