diff options
author | Sven Göthel <[email protected]> | 2024-01-20 05:01:38 +0100 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-01-20 05:01:38 +0100 |
commit | c1531c3d99b19032040018b9414263b0d3000147 (patch) | |
tree | 93ad05df0398d430884350166a88371f82143947 /src/jogl | |
parent | 5cca51e32999a882e2a5f00cb45ecafc824ffd86 (diff) |
Graph Clipping: Use Frustum Clipping using AABBox -> Mv transformed Cube -> Frustum mapping + GraphUI Support
AABBox clipping naturally couldn't be transformed into 3D Model-View (Mv) Space,
as it is axis aligned and only provided 2 points (min/max).
Therefor we map the Group's AABBox to a 8-point Cube,
perform the Mv-transformation and then produce the 6-plane Frustum.
As before, we cull fully outside shapes within the Group's draw method
and perform fragment clipping with same Frustum planes in the shader.
With clipping enabled, the 3D z-axis getBounds() depth
will be slightly increased for functional Frustum operation.
This is also done for setFixedSize(Vec2f).
The Frustum planes are copied to the Graph shader
via float[4*6] -> uniform vec4 gcu_ClipFrustum[6]; // L, R, B, T, N, F each {n.x, n.y, n.z, d}
+++
Concludes related work of below commits
- 1040bed4ecc6f4598ea459f1073a9240583fc3c3
- 5cca51e32999a882e2a5f00cb45ecafc824ffd86
Diffstat (limited to 'src/jogl')
17 files changed, 158 insertions, 130 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java index 50fae4907..e9c185753 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RegionRenderer.java @@ -48,7 +48,7 @@ import com.jogamp.common.os.Platform; import com.jogamp.graph.curve.Region; import com.jogamp.math.Recti; import com.jogamp.math.Vec4f; -import com.jogamp.math.geom.AABBox; +import com.jogamp.math.geom.Frustum; import com.jogamp.math.util.PMVMatrix4f; /** @@ -314,10 +314,10 @@ public final class RegionRenderer { /** Returns pass2 AA sample count for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link #VBAA_RENDERING_BIT} or {@link Region#MSAA_RENDERING_BIT}. */ public final int getSampleCount() { return rs.getSampleCount(); } - /** Set the optional clipping {@link AABBox}, which shall be pre-multiplied with the Mv-matrix or null to disable. */ - public final void setClipBBox(final AABBox clipBBox) { rs.setClipBBox(clipBBox); } - /** Returns the optional Mv-premultiplied clipping {@link AABBox} or null if unused. */ - public final AABBox getClipBBox() { return rs.getClipBBox(); } + /** Set the optional clipping {@link Frustum}, which shall be pre-multiplied with the Mv-matrix or null to disable. */ + public final void setClipFrustum(final Frustum clipFrustum) { rs.setClipFrustum(clipFrustum); } + /** Returns the optional Mv-premultiplied clipping {@link Frustum} or null if unused. */ + public final Frustum getClipFrustum() { return rs.getClipFrustum(); } public final boolean isHintMaskSet(final int mask) { return rs.isHintMaskSet(mask); } @@ -419,7 +419,7 @@ public final class RegionRenderer { private static final String GLSL_PARAM_COMMENT_END = "// JogAmp Graph Parameter End\n\n"; private static final String GLSL_USE_COLOR_CHANNEL = "#define USE_COLOR_CHANNEL 1\n"; private static final String GLSL_USE_COLOR_TEXTURE = "#define USE_COLOR_TEXTURE 1\n"; - private static final String GLSL_USE_AABBOX_CLIPPING = "#define USE_AABBOX_CLIPPING 1\n"; + private static final String GLSL_USE_FRUSTUM_CLIPPING = "#define USE_FRUSTUM_CLIPPING 1\n"; private static final String GLSL_DEF_SAMPLE_COUNT = "#define SAMPLE_COUNT "; private static final String GLSL_CONST_SAMPLE_COUNT = "const float sample_count = "; private static final String GLSL_MAIN_BEGIN = "void main (void)\n{\n"; @@ -525,7 +525,7 @@ public final class RegionRenderer { final boolean isTwoPass; final boolean pass1; final ShaderModeSelector1 sms; - final boolean hasAABBoxClipping; // pass1 or pass2 + final boolean hasFrustumClipping; // pass1 or pass2 final boolean hasColorChannel; // pass1 only final boolean hasColorTexture; // pass1 only final String colorTexSeqID; @@ -534,12 +534,12 @@ public final class RegionRenderer { final String texLookupFuncName; final int hashValue; - ShaderKey(final int renderModes, final boolean pass1_, final int pass2Quality, final int sampleCount, final TextureSequence colorTexSeq, final boolean hasClipBBox) { + ShaderKey(final int renderModes, final boolean pass1_, final int pass2Quality, final int sampleCount, final TextureSequence colorTexSeq, final boolean hasClipFrustum) { isTwoPass = Region.isTwoPass( renderModes ); pass1 = pass1_; sms = pass1 ? ShaderModeSelector1.selectPass1(renderModes) : ShaderModeSelector1.selectPass2(renderModes, pass2Quality, sampleCount); - hasAABBoxClipping = hasClipBBox && ( ( !isTwoPass && pass1 ) || ( isTwoPass && !pass1 ) ); + hasFrustumClipping = hasClipFrustum && ( ( !isTwoPass && pass1 ) || ( isTwoPass && !pass1 ) ); hasColorChannel = pass1 && Region.hasColorChannel( renderModes ); hasColorTexture = pass1 && Region.hasColorTexture( renderModes ) && null != colorTexSeq; if( hasColorTexture ) { @@ -558,7 +558,7 @@ public final class RegionRenderer { // hash = ((hash << 5) - hash) + pass2Quality; // included in sms // hash = ((hash << 5) - hash) + sampleCount; // included in sms hash = ((hash << 5) - hash) + sms.ordinal(); - hash = ((hash << 5) - hash) + ( hasAABBoxClipping ? 1 : 0 ); + hash = ((hash << 5) - hash) + ( hasFrustumClipping ? 1 : 0 ); hash = ((hash << 5) - hash) + ( hasColorChannel ? 1 : 0 ); hash = ((hash << 5) - hash) + ( hasColorTexture ? 1 : 0 ); hash = ((hash << 5) - hash) + colorTexSeqHash; @@ -579,7 +579,7 @@ public final class RegionRenderer { // pass2Quality == o.pass2Quality && // included in sms // sampleCount == o.sampleCount && // included in sms sms.ordinal() == o.sms.ordinal() && - hasAABBoxClipping == o.hasAABBoxClipping && + hasFrustumClipping == o.hasFrustumClipping && hasColorChannel == o.hasColorChannel && hasColorTexture == o.hasColorTexture && colorTexSeqID.equals(o.colorTexSeqID); @@ -587,7 +587,7 @@ public final class RegionRenderer { @Override public String toString() { return "ShaderKey[hash 0x"+Integer.toHexString(hashValue)+", is2Pass "+isTwoPass+", pass1 "+pass1+ - ", has[clip "+hasAABBoxClipping+", colChan "+hasColorChannel+", colTex "+hasColorTexture+"], "+sms+"]"; + ", has[clip "+hasFrustumClipping+", colChan "+hasColorChannel+", colTex "+hasColorTexture+"], "+sms+"]"; } } private final HashMap<ShaderKey, ShaderProgram> shaderPrograms = new HashMap<ShaderKey, ShaderProgram>(); @@ -609,7 +609,7 @@ public final class RegionRenderer { * @see RenderState#getShaderProgram() */ public final boolean useShaderProgram(final GL2ES2 gl, final int renderModes, final boolean pass1, final TextureSequence colorTexSeq) { - final ShaderKey shaderKey = new ShaderKey(renderModes, pass1, getAAQuality(), getSampleCount(), colorTexSeq, null != getClipBBox()); + final ShaderKey shaderKey = new ShaderKey(renderModes, pass1, getAAQuality(), getSampleCount(), colorTexSeq, null != getClipFrustum()); /** if(DEBUG) { @@ -686,9 +686,9 @@ public final class RegionRenderer { posFp = rsFp.insertShaderSource(0, posFp, GLSL_USE_DISCARD); } - if( shaderKey.hasAABBoxClipping ) { - posVp = rsVp.insertShaderSource(0, posVp, GLSL_USE_AABBOX_CLIPPING); - posFp = rsFp.insertShaderSource(0, posFp, GLSL_USE_AABBOX_CLIPPING); + if( shaderKey.hasFrustumClipping ) { + posVp = rsVp.insertShaderSource(0, posVp, GLSL_USE_FRUSTUM_CLIPPING); + posFp = rsFp.insertShaderSource(0, posFp, GLSL_USE_FRUSTUM_CLIPPING); } if( shaderKey.hasColorChannel ) { @@ -708,11 +708,11 @@ public final class RegionRenderer { posFp = rsFp.insertShaderSource(0, posFp, GLSL_PARAM_COMMENT_END); try { - if( shaderKey.hasColorTexture || shaderKey.hasAABBoxClipping ) { - posFp = rsFp.insertShaderSource(0, posFp, AttributeNames.class, "functions.glsl"); - } posFp = rsFp.insertShaderSource(0, posFp, AttributeNames.class, "uniforms.glsl"); posFp = rsFp.insertShaderSource(0, posFp, AttributeNames.class, "varyings.glsl"); + if( shaderKey.hasColorTexture || shaderKey.hasFrustumClipping ) { + posFp = rsFp.insertShaderSource(0, posFp, AttributeNames.class, "functions.glsl"); + } } catch (final IOException ioe) { throw new RuntimeException("Failed to read: includes", ioe); } diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java index ed5bcb110..d6be9e07b 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/RenderState.java @@ -39,7 +39,7 @@ import jogamp.graph.curve.opengl.shader.UniformNames; import com.jogamp.graph.curve.Region; import com.jogamp.math.Vec4f; -import com.jogamp.math.geom.AABBox; +import com.jogamp.math.geom.Frustum; import com.jogamp.math.util.PMVMatrix4f; import com.jogamp.opengl.util.GLArrayDataWrapper; import com.jogamp.opengl.util.glsl.ShaderProgram; @@ -102,8 +102,9 @@ public class RenderState { private int aaQuality; /** Default pass2 AA sample count {@value} for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link Region#VBAA_RENDERING_BIT} or {@link Region#MSAA_RENDERING_BIT}. */ private int sampleCount; - /** Optional clipping {@link AABBox}, which shall be pre-multiplied with the Mv-matrix. Null if unused. */ - private AABBox clipBBox; + /** Optional clipping {@link Frustum}, which shall be pre-multiplied with the Mv-matrix. Null if unused. */ + private final Frustum clipFrustum; + private boolean useClipFrustum; private int hintBitfield; private ShaderProgram sp; @@ -205,7 +206,9 @@ public class RenderState { this.colorStaticBuffer = FloatBuffer.wrap(colorStatic); this.aaQuality = Region.DEFAULT_AA_QUALITY; this.sampleCount = Region.DEFAULT_AA_SAMPLE_COUNT; - this.clipBBox = null; + this.clipFrustum = new Frustum(); + this.useClipFrustum = false; + this.hintBitfield = 0; this.sp = null; } @@ -281,10 +284,17 @@ public class RenderState { /** Returns pass2 AA sample count for Graph Region AA {@link Region#getRenderModes() render-modes}: {@link #VBAA_RENDERING_BIT} or {@link Region#MSAA_RENDERING_BIT}. */ public final int getSampleCount() { return this.sampleCount; } - /** Set the optional clipping {@link AABBox}, which shall be pre-multiplied with the Mv-matrix or null to disable. */ - public final void setClipBBox(final AABBox clipBBox) { this.clipBBox = clipBBox; } - /** Returns the optional Mv-premultiplied clipping {@link AABBox} or null if unused. */ - public final AABBox getClipBBox() { return this.clipBBox; } + /** Set the optional clipping {@link Frustum}, which shall be pre-multiplied with the Mv-matrix or null to disable. */ + public final void setClipFrustum(final Frustum clipFrustum) { + if( null != clipFrustum ) { + this.clipFrustum.set(clipFrustum); + this.useClipFrustum=true; + } else { + this.useClipFrustum=false; + } + } + /** Returns the optional Mv-premultiplied clipping {@link Frustum} or null if unused. */ + public final Frustum getClipFrustum() { return useClipFrustum ? this.clipFrustum : null; } /** * diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java index ae4a734be..a6ba0e810 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java @@ -45,6 +45,7 @@ import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.math.Matrix4f; import com.jogamp.math.Recti; import com.jogamp.math.geom.AABBox; +import com.jogamp.math.geom.Frustum; import com.jogamp.math.util.SyncMatrices4f16; import com.jogamp.opengl.FBObject; import com.jogamp.opengl.FBObject.Attachment; @@ -66,8 +67,8 @@ public final class VBORegion2PMSAAES2 extends GLRegion { private final GLUniformData gcu_ColorTexUnit; private final float[] colorTexBBox; // minX/minY, maxX/maxY, texW/texH private final GLUniformData gcu_ColorTexBBox; // vec2 gcu_ColorTexBBox[3] -> boxMin[2], boxMax[2] and texSize[2] - private final float[] clipBBox; // minX/minY/minZ, maxX/maxY/maxZ - private final GLUniformData gcu_ClipBBox; // uniform vec3 gcu_ClipBBox[2]; // box-min[3], box-max[3] + private final float[/* 4*6 */] clipFrustum; // 6 frustum planes, each [n.x, n.y. n.z, d] + private final GLUniformData gcu_ClipFrustum; // uniform vec4 gcu_ClipFrustum[6]; // L, R, B, T, N, F private ShaderProgram spPass1 = null; // Pass-2: @@ -111,8 +112,8 @@ public final class VBORegion2PMSAAES2 extends GLRegion { colorTexBBox = null; gcu_ColorTexBBox = null; } - clipBBox = new float[6]; - gcu_ClipBBox = new GLUniformData(UniformNames.gcu_ClipBBox, 3, FloatBuffer.wrap(clipBBox)); + clipFrustum = new float[4*6]; + gcu_ClipFrustum = new GLUniformData(UniformNames.gcu_ClipFrustum, 4, FloatBuffer.wrap(clipFrustum)); gcu_PMVMatrix02 = new GLUniformData(UniformNames.gcu_PMVMatrix02, 4, 4, new SyncMatrices4f16( new Matrix4f[] { matP, matMv } )); // Pass 2: @@ -185,7 +186,7 @@ public final class VBORegion2PMSAAES2 extends GLRegion { final boolean hasColorTexture = Region.hasColorTexture( curRenderModes ) && null != colorTexSeq; final RenderState rs = renderer.getRenderState(); - final boolean hasAABBoxClipping = null != rs.getClipBBox() && ( ( !isTwoPass && pass1 ) || ( isTwoPass && !pass1 ) ); + final boolean hasFrustumClipping = null != rs.getClipFrustum() && ( ( !isTwoPass && pass1 ) || ( isTwoPass && !pass1 ) ); final boolean updateLocGlobal = renderer.useShaderProgram(gl, curRenderModes, pass1, colorTexSeq); final ShaderProgram sp = renderer.getRenderState().getShaderProgram(); @@ -230,8 +231,8 @@ public final class VBORegion2PMSAAES2 extends GLRegion { rsLocal.update(gl, rs, updateLocLocal, curRenderModes, true, false, true); rs.updateUniformDataLoc(gl, updateLocLocal, false /* updateData */, gcu_FboTexUnit, true); // FIXME always update if changing tex-unit } - if( hasAABBoxClipping && updateLocLocal ) { - rs.updateUniformLoc(gl, true, gcu_ClipBBox, true); + if( hasFrustumClipping && updateLocLocal ) { + rs.updateUniformLoc(gl, true, gcu_ClipFrustum, true); } } @@ -381,11 +382,10 @@ public final class VBORegion2PMSAAES2 extends GLRegion { } { - final AABBox cb = rs.getClipBBox(); - if( null != cb ) { - clipBBox[0] = cb.getMinX(); clipBBox[1] = cb.getMinY(); clipBBox[2] = cb.getMinZ(); - clipBBox[3] = cb.getMaxX(); clipBBox[4] = cb.getMaxY(); clipBBox[5] = cb.getMaxZ(); - gl.glUniform(gcu_ClipBBox); // Always update, since program maybe used by multiple regions + final Frustum f = rs.getClipFrustum(); + if( null != f ) { + f.getPlanes(clipFrustum, 0); + gl.glUniform(gcu_ClipFrustum); // Always update, since program maybe used by multiple regions } } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java index bf23f33e9..4585c4cab 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java @@ -46,6 +46,7 @@ import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.math.Matrix4f; import com.jogamp.math.Recti; import com.jogamp.math.geom.AABBox; +import com.jogamp.math.geom.Frustum; import com.jogamp.math.util.SyncMatrices4f16; import com.jogamp.opengl.FBObject; import com.jogamp.opengl.FBObject.Attachment; @@ -71,8 +72,8 @@ public final class VBORegion2PVBAAES2 extends GLRegion { private final GLUniformData gcu_ColorTexUnit; private final float[] colorTexBBox; // minX/minY, maxX/maxY, texW/texH private final GLUniformData gcu_ColorTexBBox; // vec2 gcu_ColorTexBBox[3] -> boxMin[2], boxMax[2] and texSize[2] - private final float[] clipBBox; // minX/minY/minZ, maxX/maxY/maxZ - private final GLUniformData gcu_ClipBBox; // uniform vec3 gcu_ClipBBox[2]; // box-min[3], box-max[3] + private final float[/* 4*6 */] clipFrustum; // 6 frustum planes, each [n.x, n.y. n.z, d] + private final GLUniformData gcu_ClipFrustum; // uniform vec4 gcu_ClipFrustum[6]; // L, R, B, T, N, F private ShaderProgram spPass1 = null; // Pass-2: @@ -96,6 +97,50 @@ public final class VBORegion2PVBAAES2 extends GLRegion { final int[] maxTexSize = new int[] { -1 } ; + public VBORegion2PVBAAES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit, + final int initialVerticesCount, final int initialIndicesCount) + { + super(glp, renderModes, colorTexSeq); + + rsLocal = new RenderState.ProgramLocal(); + + // Pass 1: + initBuffer(initialVerticesCount, initialIndicesCount); + + if( hasColorTexture() ) { + gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); + colorTexBBox = new float[6]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 2, FloatBuffer.wrap(colorTexBBox)); + } else { + gcu_ColorTexUnit = null; + colorTexBBox = null; + gcu_ColorTexBBox = null; + } + clipFrustum = new float[4*6]; + gcu_ClipFrustum = new GLUniformData(UniformNames.gcu_ClipFrustum, 4, FloatBuffer.wrap(clipFrustum)); + gcu_PMVMatrix02 = new GLUniformData(UniformNames.gcu_PMVMatrix02, 4, 4, new SyncMatrices4f16( new Matrix4f[] { matP, matMv } )); + + // Pass 2: + gcu_FboTexUnit = new GLUniformData(UniformNames.gcu_FboTexUnit, pass2TexUnit); + gcu_FboTexSize = new GLUniformData(UniformNames.gcu_FboTexSize, 2, FloatBuffer.wrap(new float[2])); + + indicesFbo = GLArrayDataServer.createData(3, GL.GL_UNSIGNED_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); + indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3); + indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3); + indicesFbo.seal(true); + + gca_FboTexCoordsAttr = GLArrayDataServer.createGLSL(AttributeNames.FBO_TEXCOORDS_ATTR_NAME, 2, GL.GL_FLOAT, + false, 4, GL.GL_STATIC_DRAW); + gca_FboTexCoordsAttr.putf(0); gca_FboTexCoordsAttr.putf(0); + gca_FboTexCoordsAttr.putf(0); gca_FboTexCoordsAttr.putf(1); + gca_FboTexCoordsAttr.putf(1); gca_FboTexCoordsAttr.putf(1); + gca_FboTexCoordsAttr.putf(1); gca_FboTexCoordsAttr.putf(0); + gca_FboTexCoordsAttr.seal(true); + + gca_FboVerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.FBO_VERTEX_ATTR_NAME, 3, GL.GL_FLOAT, + false, 4, GL.GL_STATIC_DRAW); + } + /** * <p> * Since multiple {@link Region}s may share one @@ -113,7 +158,7 @@ public final class VBORegion2PVBAAES2 extends GLRegion { final boolean hasColorTexture = Region.hasColorTexture( curRenderModes ) && null != colorTexSeq; final RenderState rs = renderer.getRenderState(); - final boolean hasAABBoxClipping = null != rs.getClipBBox() && ( ( !isTwoPass && pass1 ) || ( isTwoPass && !pass1 ) ); + final boolean hasFrustumClipping = null != rs.getClipFrustum() && ( ( !isTwoPass && pass1 ) || ( isTwoPass && !pass1 ) ); final boolean updateLocGlobal = renderer.useShaderProgram(gl, curRenderModes, pass1, colorTexSeq); final ShaderProgram sp = renderer.getRenderState().getShaderProgram(); @@ -159,55 +204,11 @@ public final class VBORegion2PVBAAES2 extends GLRegion { rs.updateUniformDataLoc(gl, updateLocLocal, false /* updateData */, gcu_FboTexUnit, true); // FIXME always update if changing tex-unit rs.updateUniformLoc(gl, updateLocLocal, gcu_FboTexSize, rs.getSampleCount() > 1); // maybe optimized away for sampleCount <= 1 } - if( hasAABBoxClipping && updateLocLocal ) { - rs.updateUniformLoc(gl, true, gcu_ClipBBox, true); + if( hasFrustumClipping && updateLocLocal ) { + rs.updateUniformLoc(gl, true, gcu_ClipFrustum, true); } } - public VBORegion2PVBAAES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, final int pass2TexUnit, - final int initialVerticesCount, final int initialIndicesCount) - { - super(glp, renderModes, colorTexSeq); - - rsLocal = new RenderState.ProgramLocal(); - - // Pass 1: - initBuffer(initialVerticesCount, initialIndicesCount); - - if( hasColorTexture() ) { - gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); - colorTexBBox = new float[6]; - gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 2, FloatBuffer.wrap(colorTexBBox)); - } else { - gcu_ColorTexUnit = null; - colorTexBBox = null; - gcu_ColorTexBBox = null; - } - clipBBox = new float[6]; - gcu_ClipBBox = new GLUniformData(UniformNames.gcu_ClipBBox, 3, FloatBuffer.wrap(clipBBox)); - gcu_PMVMatrix02 = new GLUniformData(UniformNames.gcu_PMVMatrix02, 4, 4, new SyncMatrices4f16( new Matrix4f[] { matP, matMv } )); - - // Pass 2: - gcu_FboTexUnit = new GLUniformData(UniformNames.gcu_FboTexUnit, pass2TexUnit); - gcu_FboTexSize = new GLUniformData(UniformNames.gcu_FboTexSize, 2, FloatBuffer.wrap(new float[2])); - - indicesFbo = GLArrayDataServer.createData(3, GL.GL_UNSIGNED_SHORT, 2, GL.GL_STATIC_DRAW, GL.GL_ELEMENT_ARRAY_BUFFER); - indicesFbo.puts((short) 0); indicesFbo.puts((short) 1); indicesFbo.puts((short) 3); - indicesFbo.puts((short) 1); indicesFbo.puts((short) 2); indicesFbo.puts((short) 3); - indicesFbo.seal(true); - - gca_FboTexCoordsAttr = GLArrayDataServer.createGLSL(AttributeNames.FBO_TEXCOORDS_ATTR_NAME, 2, GL.GL_FLOAT, - false, 4, GL.GL_STATIC_DRAW); - gca_FboTexCoordsAttr.putf(0); gca_FboTexCoordsAttr.putf(0); - gca_FboTexCoordsAttr.putf(0); gca_FboTexCoordsAttr.putf(1); - gca_FboTexCoordsAttr.putf(1); gca_FboTexCoordsAttr.putf(1); - gca_FboTexCoordsAttr.putf(1); gca_FboTexCoordsAttr.putf(0); - gca_FboTexCoordsAttr.seal(true); - - gca_FboVerticesAttr = GLArrayDataServer.createGLSL(AttributeNames.FBO_VERTEX_ATTR_NAME, 3, GL.GL_FLOAT, - false, 4, GL.GL_STATIC_DRAW); - } - @Override public void setTextureUnit(final int pass2TexUnit) { gcu_FboTexUnit.setData(pass2TexUnit); @@ -420,11 +421,10 @@ public final class VBORegion2PVBAAES2 extends GLRegion { gl.glUniform(gcu_FboTexSize); { - final AABBox cb = rs.getClipBBox(); - if( null != cb ) { - clipBBox[0] = cb.getMinX(); clipBBox[1] = cb.getMinY(); clipBBox[2] = cb.getMinZ(); - clipBBox[3] = cb.getMaxX(); clipBBox[4] = cb.getMaxY(); clipBBox[5] = cb.getMaxZ(); - gl.glUniform(gcu_ClipBBox); // Always update, since program maybe used by multiple regions + final Frustum f = rs.getClipFrustum(); + if( null != f ) { + f.getPlanes(clipFrustum, 0); + gl.glUniform(gcu_ClipFrustum); // Always update, since program maybe used by multiple regions } } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java index 3a568758c..c4e842791 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -40,7 +40,7 @@ import com.jogamp.graph.curve.Region; import com.jogamp.graph.curve.opengl.GLRegion; import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; -import com.jogamp.math.geom.AABBox; +import com.jogamp.math.geom.Frustum; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.texture.Texture; import com.jogamp.opengl.util.texture.TextureSequence; @@ -52,8 +52,8 @@ public final class VBORegionSPES2 extends GLRegion { private final GLUniformData gcu_ColorTexUnit; private final float[] colorTexBBox; // minX/minY, maxX/maxY, texW/texH private final GLUniformData gcu_ColorTexBBox; // vec2 gcu_ColorTexBBox[3] -> boxMin[2], boxMax[2] and texSize[2] - private final float[] clipBBox; // minX/minY/minZ, maxX/maxY/maxZ - private final GLUniformData gcu_ClipBBox; // uniform vec3 gcu_ClipBBox[2]; // box-min[3], box-max[3] + private final float[/* 4*6 */] clipFrustum; // 6 frustum planes, each [n.x, n.y. n.z, d] + private final GLUniformData gcu_ClipFrustum; // uniform vec4 gcu_ClipFrustum[6]; // L, R, B, T, N, F private ShaderProgram spPass1 = null; public VBORegionSPES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, @@ -74,8 +74,8 @@ public final class VBORegionSPES2 extends GLRegion { colorTexBBox = null; gcu_ColorTexBBox = null; } - clipBBox = new float[6]; - gcu_ClipBBox = new GLUniformData(UniformNames.gcu_ClipBBox, 3, FloatBuffer.wrap(clipBBox)); + clipFrustum = new float[4*6]; + gcu_ClipFrustum = new GLUniformData(UniformNames.gcu_ClipFrustum, 4, FloatBuffer.wrap(clipFrustum)); } @Override @@ -122,7 +122,7 @@ public final class VBORegionSPES2 extends GLRegion { final boolean hasColorTexture = Region.hasColorTexture( curRenderModes ) && null != colorTexSeq; final RenderState rs = renderer.getRenderState(); - final boolean hasAABBoxClipping = null != rs.getClipBBox(); + final boolean hasFrustumClipping = null != rs.getClipFrustum(); final boolean updateLocGlobal = renderer.useShaderProgram(gl, curRenderModes, true, colorTexSeq); final ShaderProgram sp = renderer.getRenderState().getShaderProgram(); @@ -139,8 +139,8 @@ public final class VBORegionSPES2 extends GLRegion { if( hasColorChannel && null != gca_ColorsAttr ) { rs.updateAttributeLoc(gl, true, gca_ColorsAttr, throwOnError); } - if( hasAABBoxClipping ) { - rs.updateUniformLoc(gl, true, gcu_ClipBBox, throwOnError); + if( hasFrustumClipping ) { + rs.updateUniformLoc(gl, true, gcu_ClipFrustum, throwOnError); } } rsLocal.update(gl, rs, updateLocLocal, curRenderModes, true, true, throwOnError); @@ -158,11 +158,10 @@ public final class VBORegionSPES2 extends GLRegion { useShaderProgram(gl, renderer, curRenderModes); { - final AABBox cb = renderer.getClipBBox(); - if( null != cb ) { - clipBBox[0] = cb.getMinX(); clipBBox[1] = cb.getMinY(); clipBBox[2] = cb.getMinZ(); - clipBBox[3] = cb.getMaxX(); clipBBox[4] = cb.getMaxY(); clipBBox[5] = cb.getMaxZ(); - gl.glUniform(gcu_ClipBBox); // Always update, since program maybe used by multiple regions + final Frustum f = renderer.getClipFrustum(); + if( null != f ) { + f.getPlanes(clipFrustum, 0); + gl.glUniform(gcu_ClipFrustum); // Always update, since program maybe used by multiple regions } } diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java index 4a66295f2..7a20fc2da 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/UniformNames.java @@ -6,7 +6,7 @@ public class UniformNames { public static final String gcu_Weight = "gcu_Weight"; public static final String gcu_ColorTexUnit = "gcu_ColorTexUnit"; public static final String gcu_ColorTexBBox = "gcu_ColorTexBBox"; - public static final String gcu_ClipBBox = "gcu_ClipBBox"; + public static final String gcu_ClipFrustum = "gcu_ClipFrustum"; public static final String gcu_PMVMatrix02 = "gcu_PMVMatrix02"; // gcu_PMVMatrix[3]; // P, Mv, and Mvi public static final String gcu_FboTexUnit = "gcu_FboTexUnit"; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl index c5850f5fa..edb3b553b 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl @@ -1,7 +1,7 @@ // Copyright 2010-2024 JogAmp Community. All rights reserved. -#ifdef USE_AABBOX_CLIPPING - if( is_inside(gcv_ClipBBoxCoord, gcu_ClipBBox[0], gcu_ClipBBox[1]) < 0.5 ) { +#ifdef USE_FRUSTUM_CLIPPING + if( isOutsideMvFrustum(gcv_ClipCoord) ) { #if USE_DISCARD discard; // discard freezes NV tegra2 compiler #else diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_weight.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_weight.glsl index e7172d834..9c8b6a4a5 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_weight.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_weight.glsl @@ -1,7 +1,7 @@ // Copyright 2010-2024 JogAmp Community. All rights reserved. -#ifdef USE_AABBOX_CLIPPING - if( is_inside(gcv_ClipBBoxCoord, gcu_ClipBBox[0], gcu_ClipBBox[1]) < 0.5 ) { +#ifdef USE_FRUSTUM_CLIPPING + if( isOutsideMvFrustum(gcv_ClipCoord) ) { #if USE_DISCARD discard; // discard freezes NV tegra2 compiler #else diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-msaa.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-msaa.glsl index 3d4cdc887..3b7291446 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-msaa.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-msaa.glsl @@ -1,6 +1,7 @@ // Pass-2: Dump Texture -#ifdef USE_AABBOX_CLIPPING - if( is_inside(gcv_ClipBBoxCoord, gcu_ClipBBox[0], gcu_ClipBBox[1]) < 0.5 ) { + +#ifdef USE_FRUSTUM_CLIPPING + if( isOutsideMvFrustum(gcv_ClipCoord) ) { #if USE_DISCARD discard; // discard freezes NV tegra2 compiler #else diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_even.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_even.glsl index 5e14a1a23..c71267be4 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_even.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_even.glsl @@ -1,10 +1,10 @@ // Pass-2: AA on Texture // Note: gcv_FboTexCoord is in center of sample pixels. -#ifdef USE_AABBOX_CLIPPING - if( is_inside(gcv_ClipBBoxCoord, gcu_ClipBBox[0], gcu_ClipBBox[1]) < 0.5 ) { +#ifdef USE_FRUSTUM_CLIPPING + if( isOutsideMvFrustum(gcv_ClipCoord) ) { #if USE_DISCARD - discard; // discard freezes NV tegra2 compiler + discard; // discard freezes NV tegra2 compiler #else mgl_FragColor = vec4(0); #endif diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_odd.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_odd.glsl index b7d2e0e4e..4fa3c601e 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_odd.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_bforce_odd.glsl @@ -1,8 +1,8 @@ // Pass-2: AA on Texture // Note: gcv_FboTexCoord is in center of sample pixels. -#ifdef USE_AABBOX_CLIPPING - if( is_inside(gcv_ClipBBoxCoord, gcu_ClipBBox[0], gcu_ClipBBox[1]) < 0.5 ) { +#ifdef USE_FRUSTUM_CLIPPING + if( isOutsideMvFrustum(gcv_ClipCoord) ) { #if USE_DISCARD discard; // discard freezes NV tegra2 compiler #else diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad3.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad3.glsl index da0306425..76b064420 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad3.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2-vbaa_flipquad3.glsl @@ -4,8 +4,8 @@ // // Same as flipquad - but w/ rgss coordinates -#ifdef USE_AABBOX_CLIPPING - if( is_inside(gcv_ClipBBoxCoord, gcu_ClipBBox[0], gcu_ClipBBox[1]) < 0.5 ) { +#ifdef USE_FRUSTUM_CLIPPING + if( isOutsideMvFrustum(gcv_ClipCoord) ) { #if USE_DISCARD discard; // discard freezes NV tegra2 compiler #else diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2.vp index dce78b9c8..5ee5fcb46 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2.vp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass2.vp @@ -14,8 +14,8 @@ void main(void) // gl_Position = gcu_PMVMatrix01[0] * gcu_PMVMatrix01[1] * vec4(gca_FboVertices, 1); gl_Position = gcu_PMVMatrix01[0] * gcu_PMVMatrix01[1] * gca_FboVertices; -#ifdef USE_AABBOX_CLIPPING - gcv_ClipBBoxCoord = (gcu_PMVMatrix01[1] * gca_FboVertices).xyz; // Mv +#ifdef USE_FRUSTUM_CLIPPING + gcv_ClipCoord = (gcu_PMVMatrix01[1] * gca_FboVertices).xyz; // Mv #endif gcv_FboTexCoord = gca_FboTexCoords; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-single.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-single.vp index 2f07ad7d0..bda10c432 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-single.vp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-single.vp @@ -24,8 +24,8 @@ void main(void) } #endif -#ifdef USE_AABBOX_CLIPPING - gcv_ClipBBoxCoord = (gcu_PMVMatrix01[1] * gca_Vertices).xyz; // Mv +#ifdef USE_FRUSTUM_CLIPPING + gcv_ClipCoord = (gcu_PMVMatrix01[1] * gca_Vertices).xyz; // Mv #endif #ifdef USE_COLOR_TEXTURE diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl index 41e65178e..3b36b021a 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl @@ -75,12 +75,30 @@ vec4 clip_coord(vec4 col_in, vec4 col_ex, vec3 coord, vec3 low, vec3 high) { * </p> */ float is_inside(vec2 coord, vec2 low, vec2 high) { - return v_mul( step(low, coord) ) * ( 1 - v_or( step(high+EPSILON, coord) ) ); + return v_mul( step(low-EPSILON, coord) ) * ( 1 - v_or( step(high+EPSILON, coord) ) ); } /** Branch-less clipping test using vec3 coordinates and low/high clipping. */ float is_inside(vec3 coord, vec3 low, vec3 high) { - return v_mul( step(low, coord) ) * ( 1 - v_or( step(high+EPSILON, coord) ) ); + return v_mul( step(low-EPSILON, coord) ) * ( 1 - v_or( step(high+EPSILON, coord) ) ); } +/** Return distance of plane {n, d} to given point p. */ +float planeDistance(vec3 n, float d, vec3 p) { + return dot(n, p) + d; +} + +#ifdef USE_FRUSTUM_CLIPPING + +bool isOutsideMvFrustum(vec3 p) { + return planeDistance(gcu_ClipFrustum[0].xyz, gcu_ClipFrustum[0].w, p) < 0 || + planeDistance(gcu_ClipFrustum[1].xyz, gcu_ClipFrustum[1].w, p) < 0 || + planeDistance(gcu_ClipFrustum[2].xyz, gcu_ClipFrustum[2].w, p) < 0 || + planeDistance(gcu_ClipFrustum[3].xyz, gcu_ClipFrustum[3].w, p) < 0 || + planeDistance(gcu_ClipFrustum[4].xyz, gcu_ClipFrustum[4].w, p) < 0 || + planeDistance(gcu_ClipFrustum[5].xyz, gcu_ClipFrustum[5].w, p) < 0; +} + +#endif // USE_FRUSTUM_CLIPPING + #endif // functions_glsl diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl index a9554528c..18c563fbb 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl @@ -10,8 +10,8 @@ uniform float gcu_Weight; #ifdef USE_COLOR_TEXTURE uniform vec2 gcu_ColorTexBBox[3]; // box-min[2], box-max[2] and tex-size[2] #endif -#ifdef USE_AABBOX_CLIPPING - uniform vec3 gcu_ClipBBox[2]; // box-min[3], box-max[3] +#ifdef USE_FRUSTUM_CLIPPING + uniform vec4 gcu_ClipFrustum[6]; // L, R, B, T, N, F each {n.x, n.y, n.z, d} #endif uniform mat4 gcu_PMVMatrix02[3]; // P, Mv, and Mvi diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl index 0e8d5b843..6139c9d8f 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl @@ -10,8 +10,8 @@ varying vec2 gcv_FboTexCoord; #ifdef USE_COLOR_TEXTURE varying vec2 gcv_ColorTexCoord; #endif -#ifdef USE_AABBOX_CLIPPING - varying vec3 gcv_ClipBBoxCoord; +#ifdef USE_FRUSTUM_CLIPPING + varying vec3 gcv_ClipCoord; #endif #ifdef USE_COLOR_CHANNEL |