Fixed autonormals and brightened the default lights.

This commit is contained in:
juniperoserra
2005-04-17 18:03:08 +00:00
parent 54c9c8ff6f
commit 38f71c8f63
2 changed files with 47 additions and 16 deletions

View File

@@ -1407,12 +1407,21 @@ public class PGraphics3 extends PGraphics {
float wz = v[VZ];
float shine = v[SHINE];
float nx;
float ny;
float nz;
if (!normalIsWorld) {
toWorldNormal(v[NX], v[NY], v[NZ], worldNormal);
nx = worldNormal[X];
ny = worldNormal[Y];
nz = worldNormal[Z];
}
float nx = worldNormal[X];
float ny = worldNormal[Y];
float nz = worldNormal[Z];
else {
nx = v[NX];
ny = v[NY];
nz = v[NZ];
}
// Since the camera space == world space,
// we can test for visibility by the dot product of
@@ -1725,6 +1734,7 @@ public class PGraphics3 extends PGraphics {
vertices[vIndex][NX] = norm[X];
vertices[vIndex][NY] = norm[Y];
vertices[vIndex][NZ] = norm[Z];
// The true at the end says the normal is already in world coordinates
calc_lighting_contribution(vIndex, tempLightingContribution, true);
copy_vertex_color_to_triangle(triIndex, vIndex, 0, tempLightingContribution);
@@ -2554,7 +2564,7 @@ public class PGraphics3 extends PGraphics {
normal(sphereX[i], sphereY[i], sphereZ[i]);
vertex(sphereX[i], sphereY[i], sphereZ[i]);
}
normal(0, -1, 0);
//normal(0, -1, 0);
vertex(0, -1, 0);
normal(sphereX[0], sphereY[0], sphereZ[0]);
vertex(sphereX[0], sphereY[0], sphereZ[0]);
@@ -3470,12 +3480,12 @@ public class PGraphics3 extends PGraphics {
lightFalloff(1, 0, 0);
lightSpecular(0, 0, 0);
ambientLight(colorModeX * 0.23f,
colorModeY * 0.23f,
colorModeZ * 0.23f);
directionalLight(colorModeX * 0.31f,
colorModeY * 0.31f,
colorModeZ * 0.31f,
ambientLight(colorModeX * 0.5f,
colorModeY * 0.5f,
colorModeZ * 0.5f);
directionalLight(colorModeX * 0.5f,
colorModeY * 0.5f,
colorModeZ * 0.5f,
0, 0, -1);
colorMode = colorModeSaved;

View File

@@ -352,6 +352,27 @@ public class PGraphicsGL extends PGraphics3 {
float b[] = vertices[triangles[i][VERTEX2]];
float c[] = vertices[triangles[i][VERTEX3]];
// This is only true when not textured. We really should pass SPECULAR
// straight through to triangle rendering.
float ar = min(1, triangleColors[i][0][TRI_DIFFUSE_R] +
triangleColors[i][0][TRI_SPECULAR_R]);
float ag = min(1, triangleColors[i][0][TRI_DIFFUSE_G] +
triangleColors[i][0][TRI_SPECULAR_G]);
float ab = min(1, triangleColors[i][0][TRI_DIFFUSE_B] +
triangleColors[i][0][TRI_SPECULAR_B]);
float br = min(1, triangleColors[i][1][TRI_DIFFUSE_R] +
triangleColors[i][1][TRI_SPECULAR_R]);
float bg = min(1, triangleColors[i][1][TRI_DIFFUSE_G] +
triangleColors[i][1][TRI_SPECULAR_G]);
float bb = min(1, triangleColors[i][1][TRI_DIFFUSE_B] +
triangleColors[i][1][TRI_SPECULAR_B]);
float cr = min(1, triangleColors[i][2][TRI_DIFFUSE_R] +
triangleColors[i][2][TRI_SPECULAR_R]);
float cg = min(1, triangleColors[i][2][TRI_DIFFUSE_G] +
triangleColors[i][2][TRI_SPECULAR_G]);
float cb = min(1, triangleColors[i][2][TRI_DIFFUSE_B] +
triangleColors[i][2][TRI_SPECULAR_B]);
int textureIndex = triangles[i][TEXTURE_INDEX];
if (textureIndex != -1) {
//System.out.println("texture drawing");
@@ -465,17 +486,17 @@ public class PGraphicsGL extends PGraphics3 {
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor4f(a[R], a[G], a[B], a[A]);
gl.glColor4f(ar, ag, ab, a[A]);
gl.glTexCoord2f(a[U] * uscale, a[V] * vscale);
gl.glNormal3f(a[NX], a[NY], a[NZ]);
gl.glVertex3f(a[VX], a[VY], a[VZ]);
gl.glColor4f(b[R], b[G], b[B], b[A]);
gl.glColor4f(br, bg, bb, b[A]);
gl.glTexCoord2f(b[U] * uscale, b[V] * vscale);
gl.glNormal3f(b[NX], b[NY], b[NZ]);
gl.glVertex3f(b[VX], b[VY], b[VZ]);
gl.glColor4f(c[R], c[G], c[B], c[A]);
gl.glColor4f(cr, cg, cb, c[A]);
gl.glTexCoord2f(c[U] * uscale, c[V] * vscale);
gl.glNormal3f(c[NX], c[NY], c[NZ]);
gl.glVertex3f(c[VX], c[VY], c[VZ]);
@@ -488,15 +509,15 @@ public class PGraphicsGL extends PGraphics3 {
} else {
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor4f(a[R], a[G], a[B], a[A]);
gl.glColor4f(ar, ag, ab, a[A]);
gl.glNormal3f(a[NX], a[NY], a[NZ]);
gl.glVertex3f(a[VX], a[VY], a[VZ]);
gl.glColor4f(b[R], b[G], b[B], b[A]);
gl.glColor4f(br, bg, bb, b[A]);
gl.glNormal3f(b[NX], b[NY], b[NZ]);
gl.glVertex3f(b[VX], b[VY], b[VZ]);
gl.glColor4f(c[R], c[G], c[B], c[A]);
gl.glColor4f(cr, cg, cb, c[A]);
gl.glNormal3f(c[NX], c[NY], c[NZ]);
gl.glVertex3f(c[VX], c[VY], c[VZ]);