mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Fixed a couple of bugs in the calculation of the normal matrix
This commit is contained in:
@@ -73,6 +73,7 @@ float blinnPhongFactor(vec3 lightDir, vec3 lightPos, vec3 vecNormal, float shine
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Vertex in clip coordinates
|
||||
gl_Position = projmodelviewMatrix * inVertex;
|
||||
|
||||
// Vertex in eye coordinates
|
||||
@@ -99,8 +100,8 @@ void main() {
|
||||
falloff = one_float;
|
||||
lightDir = -lightNormal[i];
|
||||
} else {
|
||||
falloff = falloffFactor(lightPos, ecVertex, lightFalloffCoefficients[i]);
|
||||
lightDir = lightPos - ecVertex;
|
||||
falloff = falloffFactor(lightPos, ecVertex, lightFalloffCoefficients[i]);
|
||||
lightDir = normalize(lightPos - ecVertex);
|
||||
}
|
||||
|
||||
spotf = spotExp > zero_float ? spotFactor(lightPos, ecVertex, lightNormal[i],
|
||||
@@ -110,21 +111,24 @@ void main() {
|
||||
if (any(greaterThan(lightAmbient[i], zero_vec3))) {
|
||||
totalAmbient += lightAmbient[i] * falloff;
|
||||
}
|
||||
|
||||
if (any(greaterThan(lightDiffuse[i], zero_vec3))) {
|
||||
totalDiffuse += lightDiffuse[i] * falloff * spotf *
|
||||
lambertFactor(-lightDir, ecNormal);
|
||||
}
|
||||
|
||||
if (any(greaterThan(lightSpecular[i], zero_vec3))) {
|
||||
totalSpecular += lightSpecular[i] * falloff * spotf *
|
||||
blinnPhongFactor(-lightDir, lightPos, ecNormal, inShine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculating final color as result of all lights (plus emissive term)
|
||||
vertColor = vec4(totalAmbient, 1) * inAmbient +
|
||||
vec4(totalDiffuse, 1) * inColor +
|
||||
vec4(totalSpecular, 1) * inSpecular +
|
||||
inEmissive;
|
||||
|
||||
// Passing texture coordinates to the fragment shader
|
||||
vertTexcoord = inTexcoord;
|
||||
vertTexcoord = inTexcoord;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ float blinnPhongFactor(vec3 lightDir, vec3 lightPos, vec3 vecNormal, float shine
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Vertex in clip coordinates
|
||||
gl_Position = projmodelviewMatrix * inVertex;
|
||||
|
||||
// Vertex in eye coordinates
|
||||
@@ -97,7 +98,7 @@ void main() {
|
||||
falloff = one_float;
|
||||
lightDir = -lightNormal[i];
|
||||
} else {
|
||||
falloff = falloffFactor(lightPos, ecVertex, lightFalloffCoefficients[i]);
|
||||
falloff = falloffFactor(lightPos, ecVertex, lightFalloffCoefficients[i]);
|
||||
lightDir = normalize(lightPos - ecVertex);
|
||||
}
|
||||
|
||||
@@ -120,6 +121,7 @@ void main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Calculating final color as result of all lights (plus emissive term)
|
||||
vertColor = vec4(totalAmbient, 1) * inAmbient +
|
||||
vec4(totalDiffuse, 1) * inColor +
|
||||
vec4(totalSpecular, 1) * inSpecular +
|
||||
|
||||
@@ -1437,6 +1437,7 @@ public class PGraphicsAndroid3D extends PGraphics {
|
||||
// remove any additional modelview transformation (and less likely, projection
|
||||
// transformations) applied by the user after setting the camera and/or projection
|
||||
modelview.set(camera);
|
||||
modelviewInv.set(cameraInv);
|
||||
calcProjmodelview();
|
||||
}
|
||||
|
||||
@@ -1672,7 +1673,9 @@ public class PGraphicsAndroid3D extends PGraphics {
|
||||
}
|
||||
|
||||
// The normal matrix is the transpose of the inverse of the
|
||||
// modelview:
|
||||
// modelview (remember that gl matrices are column-major,
|
||||
// meaning that elements 0, 1, 2 are the first column,
|
||||
// 3, 4, 5 the second, etc.:
|
||||
glNormal[0] = modelviewInv.m00;
|
||||
glNormal[1] = modelviewInv.m01;
|
||||
glNormal[2] = modelviewInv.m02;
|
||||
@@ -2202,7 +2205,7 @@ public class PGraphicsAndroid3D extends PGraphics {
|
||||
}
|
||||
|
||||
if (flushMode == FLUSH_WHEN_FULL && !hints[DISABLE_TRANSFORM_CACHE]) {
|
||||
popMatrix();
|
||||
//popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7662,9 +7665,9 @@ public class PGraphicsAndroid3D extends PGraphics {
|
||||
fillVertices[index ] = x * mm.m20 + y * mm.m21 + z * mm.m22 + mm.m23;
|
||||
|
||||
index = 3 * fillVertexCount;
|
||||
fillNormals[index++] = nx * nm.m00 + ny * nm.m10 + nz * nm.m02;
|
||||
fillNormals[index++] = nx * nm.m01 + ny * nm.m11 + nz * nm.m12;
|
||||
fillNormals[index ] = nx * nm.m02 + ny * nm.m21 + nz * nm.m22;
|
||||
fillNormals[index++] = nx * nm.m00 + ny * nm.m10 + nz * nm.m20;
|
||||
fillNormals[index++] = nx * nm.m01 + ny * nm.m11 + nz * nm.m21;
|
||||
fillNormals[index ] = nx * nm.m02 + ny * nm.m12 + nz * nm.m22;
|
||||
} else {
|
||||
index = 3 * fillVertexCount;
|
||||
fillVertices[index++] = x;
|
||||
|
||||
Reference in New Issue
Block a user