Fixed bump/normal maps.
parent
35d1e439a3
commit
ae4d0382dc
|
@ -34,7 +34,7 @@ MAD R3, R1.yzxw, R2.zxyw, -R3;
|
|||
|
||||
# Transform the light direction from object space into surface space
|
||||
DP3 R0.x, R2, c[16];
|
||||
DP3 R0.y, R3, c[16];
|
||||
DP3 R0.y, -R3, c[16];
|
||||
DP3 R0.z, R1, c[16];
|
||||
# Compress the light direction to fit in the primary color and output it
|
||||
MOV R5, c[40];
|
||||
|
|
|
@ -37,7 +37,7 @@ MAD binormal, iNormal.yzxw, t.zxyw, -binormal;
|
|||
|
||||
# Transform the light direction from object space into surface space
|
||||
DP3 light_surf.x, iTangent, lightDir;
|
||||
DP3 light_surf.y, binormal, lightDir;
|
||||
DP3 light_surf.y, -binormal, lightDir;
|
||||
DP3 light_surf.z, iNormal, lightDir;
|
||||
|
||||
# Compress the light direction to fit in the primary color and output it
|
||||
|
|
|
@ -52,7 +52,7 @@ MAD R3, R1.yzxw, R2.zxyw, -R3;
|
|||
|
||||
# Transform the light direction from object space into surface space
|
||||
DP3 R0.x, R2, c[16];
|
||||
DP3 R0.y, R3, c[16];
|
||||
DP3 R0.y, -R3, c[16];
|
||||
DP3 R0.z, R1, c[16];
|
||||
# Compress the light direction to fit in the primary color and output it
|
||||
MOV R5, c[40];
|
||||
|
|
|
@ -65,7 +65,7 @@ MAD binormal, iNormal.yzxw, t.zxyw, -binormal;
|
|||
|
||||
# Transform the light direction from object space into surface space
|
||||
DP3 light_surf.x, iTangent, lightDir;
|
||||
DP3 light_surf.y, binormal, lightDir;
|
||||
DP3 light_surf.y, -binormal, lightDir;
|
||||
DP3 light_surf.z, iNormal, lightDir;
|
||||
|
||||
# Compress the light direction to fit in the primary color and output it
|
||||
|
|
|
@ -574,7 +574,7 @@ void LODSphereMesh::renderSection(int phi0, int theta0,
|
|||
// Compute the tangent--required for bump mapping
|
||||
tangents[n3] = stheta;
|
||||
tangents[n3 + 1] = 0.0f;
|
||||
tangents[n3 + 2] = ctheta;
|
||||
tangents[n3 + 2] = -ctheta;
|
||||
|
||||
n2 += 2;
|
||||
n3 += 3;
|
||||
|
|
|
@ -1572,6 +1572,7 @@ static void renderBumpMappedMesh(const GLContext& context,
|
|||
// Set up the texture transformation--the light direction and the
|
||||
// viewer orientation both need to be considered.
|
||||
glMatrixMode(GL_TEXTURE);
|
||||
glScalef(-1.0f, 1.0f, 1.0f);
|
||||
glRotate(lightOrientation * ~orientation);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glx::glActiveTextureARB(GL_TEXTURE0_ARB);
|
||||
|
|
|
@ -741,14 +741,14 @@ void Texture::normalMap(float scale, bool wrap)
|
|||
int h01 = (int) pixels[(i1 * width + j0) * components];
|
||||
|
||||
float dx = (float) (h10 - h00) * (1.0f / 255.0f) * scale;
|
||||
float dy = (float) (h00 - h01) * (1.0f / 255.0f) * scale;
|
||||
float dy = (float) (h01 - h00) * (1.0f / 255.0f) * scale;
|
||||
|
||||
float mag = (float) sqrt(dx * dx + dy * dy + 1.0f);
|
||||
float rmag = 1.0f / mag;
|
||||
|
||||
int n = (i * width + j) * 4;
|
||||
npixels[n] = (unsigned char) (128 + 127 * dx * rmag);
|
||||
npixels[n + 1] = (unsigned char) (128 - 127 * dy * rmag);
|
||||
npixels[n + 1] = (unsigned char) (128 + 127 * dy * rmag);
|
||||
// npixels[n] = (unsigned char) (128 + 127 * dy * rmag);
|
||||
// npixels[n + 1] = (unsigned char) (128 - 127 * dx * rmag);
|
||||
// npixels[n] = (unsigned char) (128 - 127 * dx * rmag);
|
||||
|
|
Loading…
Reference in New Issue