Hi Andre,
Thanks for the information.
With my testing, it indeed is related to far plane. But apparently, 100 is not the solution for all.
IndexedFaceSetFactory ifsf = new IndexedFaceSetFactory();
double [][] vertices = new double[][] {
{-.8f, .3f, .5f, 1},
{.3f, .3f, .5f, 1},
{.3f, -.8f, .5f, 1},
{.3f, -.8f, .5f, 1},
{-.8f, -.8f, .5f, 1},
{-.8f, .3f, .5f, 1},
{-.3f, .8f, .25f, 1},
{.8f, .8f, .25f, 1},
{.8f, -.3f, .25f, 1},
{.8f, -.3f, .25f, 1},
{-.3f, -.3f, .25f, 1},
{-.3f, .8f, .25f, 1},
{-.9f, -.5f, .75f, 1},
{-.5f, -.5f, .75f, 1},
{-.5f, -.9f, .75f, 1},
{-.5f, -.9f, .75f, 1},
{-.9f, -.9f, .75f, 1},
{-.9f, -.5f, .75f, 1}
};
int [][] faceIndices = new int [][] {
{0, 1, 2}, {3, 4, 5},
{6, 7, 8}, {9, 10, 11},
{12, 13, 14}, {15, 16, 17}
};
Color[] faceColor = new Color[]{new Color(0, 255, 0), new Color(0, 255, 0),
new Color(0, 0, 255), new Color(0, 0, 255), new Color(255, 0, 0), new Color(255, 0, 0)};
ifsf.setVertexCount( vertices.length );
ifsf.setVertexCoordinates( vertices );
ifsf.setFaceCount( faceIndices.length);
ifsf.setFaceIndices( faceIndices );
ifsf.setGenerateFaceNormals( true );
ifsf.setFaceColors(faceColor);
ifsf.update();
SceneGraphComponent sgc = SceneGraphUtility.createFullSceneGraphComponent("Cube");
sgc.setGeometry(ifsf.getIndexedFaceSet());
sgc.setAppearance(new Appearance());
Appearance app = sgc.getAppearance();
app.setAttribute(CommonAttributes.TRANSPARENCY_ENABLED, true);
app.setAttribute(CommonAttributes.POLYGON_SHADER+"."+CommonAttributes.TRANSPARENCY, .3);
return sgc;
When the far plane is 100, the result is bad
- far100.PNG (117.37 KiB) Viewed 1328 times
After I change it to 20, the result is good
- far20.PNG (101.87 KiB) Viewed 1328 times
And you mentioned "This doesn't have any effect for the perspective mode, because the transformation of the frustum to the NDC-Cube takes care of it. "
And currently, I'm kind of confused for this,
Because when I looked at the ORTHOGONAL projection matrix in P3.java
public static double[] makeOrthographicProjectionMatrix(double[] m, Rectangle2D viewport, double near, double far) {
// assert dim checks
double l = viewport.getMinX();
double r = viewport.getMaxX();
double b = viewport.getMinY();
double t = viewport.getMaxY();
if (m == null) m = new double[16];
Rn.setIdentityMatrix(m);
m[0] = 2/(r-l);
m[5] = 2/(t-b);
m[10] = -2/(far-near);
m[3] = -(r+l)/(r-l);
m[7] = -(t+b)/(t-b);
m[11] = -(far+near)/(far-near);
return m;
}
I think it's correct.
Is it really related to the NDC-Cube only?
Anyway, overall I can't see any difference between ORTHOGONAL and perspective in the DepthPeeling solution.
Probably you guys would have more insight thoughts about that.
Thanks.
Andre wrote:Hi cznlzq,
it took a while to understand the problem, why isn't it working for orthogonal perspective. It depends of the depth of the clipping planes. Because the transparency-shader starts rendering from the far clipping plane the exactness is high at the far clipping plane and low at the near clipping plane. This doesn't have any effect for the perspective mode, because the transformation of the frustum to the NDC-Cube takes care of it.
This bug only happens for the orthogonal case and you can get aware of it when you change the value of the far clipping plane to a lower number. We changed it from 1000 to 100 and got right working transparency.
We asked us, why the far clipping plane is that far away and found as answer, because of the Skybox which has a depth and is not infinity. This sounds like a bug for me but has probably a reason in the past...