aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/org/jdesktop/j3d/examples/gl2es2pipeline')
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/Cube.java311
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/EnvironmentMappingGLSL.java60
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ObjLoadGLSL.java58
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/PhongShadingGLSL.java67
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SamplerTestGLSL.java54
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ShaderTestGLSL.java82
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java415
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SphereGLSL.java95
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/VertexAttrTestGLSL.java62
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/dimple.vert3
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag30
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert67
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert55
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag50
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.vert14
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert50
16 files changed, 960 insertions, 513 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/Cube.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/Cube.java
new file mode 100644
index 0000000..86f02ea
--- /dev/null
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/Cube.java
@@ -0,0 +1,311 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+package org.jdesktop.j3d.examples.gl2es2pipeline;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+import org.jogamp.java3d.GeometryArray;
+import org.jogamp.java3d.J3DBuffer;
+import org.jogamp.java3d.Shape3D;
+import org.jogamp.java3d.TriangleArray;
+
+/**
+ * @author Administrator
+ *
+ */
+public class Cube extends Shape3D
+{
+
+ private static final float[] verts = {
+ // front face
+ 1.0f, -1.0f, 1.0f, //1
+ 1.0f, 1.0f, 1.0f, //2
+ -1.0f, 1.0f, 1.0f, //3
+ 1.0f, -1.0f, 1.0f, //1
+ -1.0f, 1.0f, 1.0f, //3
+ -1.0f, -1.0f, 1.0f, //4
+ // back face
+ -1.0f, -1.0f, -1.0f, //1
+ -1.0f, 1.0f, -1.0f, //2
+ 1.0f, 1.0f, -1.0f, //3
+ -1.0f, -1.0f, -1.0f, //1
+ 1.0f, 1.0f, -1.0f, //3
+ 1.0f, -1.0f, -1.0f, //4
+ // right face
+ 1.0f, -1.0f, -1.0f, //1
+ 1.0f, 1.0f, -1.0f, //2
+ 1.0f, 1.0f, 1.0f, //3
+ 1.0f, -1.0f, -1.0f, //1
+ 1.0f, 1.0f, 1.0f, //3
+ 1.0f, -1.0f, 1.0f, //4
+ // left face
+ -1.0f, -1.0f, 1.0f, //1
+ -1.0f, 1.0f, 1.0f, //2
+ -1.0f, 1.0f, -1.0f, //3
+ -1.0f, -1.0f, 1.0f, //1
+ -1.0f, 1.0f, -1.0f, //3
+ -1.0f, -1.0f, -1.0f, //4
+ // top face
+ 1.0f, 1.0f, 1.0f, //1
+ 1.0f, 1.0f, -1.0f, //2
+ -1.0f, 1.0f, -1.0f, //3
+ 1.0f, 1.0f, 1.0f, //1
+ -1.0f, 1.0f, -1.0f, //3
+ -1.0f, 1.0f, 1.0f, //4
+ // bottom face
+ -1.0f, -1.0f, 1.0f, //1
+ -1.0f, -1.0f, -1.0f, //2
+ 1.0f, -1.0f, -1.0f, //3
+ -1.0f, -1.0f, 1.0f, //1
+ 1.0f, -1.0f, -1.0f, //3
+ 1.0f, -1.0f, 1.0f, };//4
+
+ private static final float[] colors = {
+ // front face (red)
+ 1.0f, 0.0f, 0.0f, //1
+ 1.0f, 0.0f, 0.0f, //2
+ 1.0f, 0.0f, 0.0f, //3
+ 1.0f, 0.0f, 0.0f, //1
+ 1.0f, 0.0f, 0.0f, //3
+ 1.0f, 0.0f, 0.0f, //4
+ // back face (green)
+ 0.0f, 1.0f, 0.0f, //1
+ 0.0f, 1.0f, 0.0f, //2
+ 0.0f, 1.0f, 0.0f, //3
+ 0.0f, 1.0f, 0.0f, //1
+ 0.0f, 1.0f, 0.0f, //3
+ 0.0f, 1.0f, 0.0f, //4
+ // right face (blue)
+ 0.0f, 0.0f, 1.0f, //1
+ 0.0f, 0.0f, 1.0f, //2
+ 0.0f, 0.0f, 1.0f, //3
+ 0.0f, 0.0f, 1.0f, //1
+ 0.0f, 0.0f, 1.0f, //3
+ 0.0f, 0.0f, 1.0f, //4
+ // left face (yellow)
+ 1.0f, 1.0f, 0.0f, //1
+ 1.0f, 1.0f, 0.0f, //2
+ 1.0f, 1.0f, 0.0f, //3
+ 1.0f, 1.0f, 0.0f, //1
+ 1.0f, 1.0f, 0.0f, //3
+ 1.0f, 1.0f, 0.0f, //4
+ // top face (magenta)
+ 1.0f, 0.0f, 1.0f, //1
+ 1.0f, 0.0f, 1.0f, //2
+ 1.0f, 0.0f, 1.0f, //3
+ 1.0f, 0.0f, 1.0f, //1
+ 1.0f, 0.0f, 1.0f, //3
+ 1.0f, 0.0f, 1.0f, //4
+ // bottom face (cyan)
+ 0.0f, 1.0f, 1.0f, //1
+ 0.0f, 1.0f, 1.0f, //2
+ 0.0f, 1.0f, 1.0f, //3
+ 0.0f, 1.0f, 1.0f, //1
+ 0.0f, 1.0f, 1.0f, //3
+ 0.0f, 1.0f, 1.0f, };//4
+
+ /**
+ * Constructs a color cube with unit scale. The corners of the
+ * color cube are [-1,-1,-1] and [1,1,1].
+ */
+ public Cube()
+ {
+ TriangleArray cube = new TriangleArray(36,
+ GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.USE_NIO_BUFFER | GeometryArray.BY_REFERENCE);
+
+ cube.setCoordRefBuffer(new J3DBuffer(makeFloatBuffer(verts)));
+ cube.setColorRefBuffer(new J3DBuffer(makeFloatBuffer(colors)));
+
+ this.setGeometry(cube);
+ this.setAppearance(new SimpleShaderAppearance());
+ }
+
+ /**
+ * Constructs a color cube with the specified scale. The corners of the
+ * color cube are [-scale,-scale,-scale] and [scale,scale,scale].
+ * @param scale the scale of the cube
+ */
+ public Cube(double scale)
+ {
+ TriangleArray cube = new TriangleArray(36,
+ GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.USE_NIO_BUFFER | GeometryArray.BY_REFERENCE);
+
+ float scaledVerts[] = new float[verts.length];
+ for (int i = 0; i < verts.length; i++)
+ scaledVerts[i] = verts[i] * (float) scale;
+
+ cube.setCoordRefBuffer(new J3DBuffer(makeFloatBuffer(scaledVerts)));
+ cube.setColorRefBuffer(new J3DBuffer(makeFloatBuffer(colors)));
+
+ this.setGeometry(cube);
+
+ this.setAppearance(new SimpleShaderAppearance());
+ }
+
+ public Cube(double scale, float r, float g, float b)
+ {
+ TriangleArray cube = new TriangleArray(36,
+ GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.USE_NIO_BUFFER | GeometryArray.BY_REFERENCE);
+
+ float scaledVerts[] = new float[verts.length];
+ for (int i = 0; i < verts.length; i++)
+ scaledVerts[i] = verts[i] * (float) scale;
+
+ cube.setCoordRefBuffer(new J3DBuffer(makeFloatBuffer(scaledVerts)));
+
+ float colorsSet[] = new float[36 * 3];
+ for (int i = 0; i < 36; i++)
+ {
+ colorsSet[i * 3 + 0] = r;
+ colorsSet[i * 3 + 1] = g;
+ colorsSet[i * 3 + 2] = b;
+ }
+
+ cube.setColorRefBuffer(new J3DBuffer(makeFloatBuffer(colorsSet)));
+
+ this.setGeometry(cube);
+ this.setAppearance(new SimpleShaderAppearance());
+ }
+
+ /**
+ * Constructs a color cube with the specified scale. The corners of the
+ * color cube are [-scale,-scale,-scale] and [scale,scale,scale].
+ * @param scale the scale of the cube
+ */
+ public Cube(double xScale, double yScale, double zScale)
+ {
+ TriangleArray cube = new TriangleArray(36,
+ GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.USE_NIO_BUFFER | GeometryArray.BY_REFERENCE);
+
+ float scaledVerts[] = new float[verts.length];
+ for (int i = 0; i < verts.length; i += 3)
+ {
+ scaledVerts[i + 0] = verts[i + 0] * (float) xScale;
+ scaledVerts[i + 1] = verts[i + 1] * (float) yScale;
+ scaledVerts[i + 2] = verts[i + 2] * (float) zScale;
+ }
+
+ cube.setCoordRefBuffer(new J3DBuffer(makeFloatBuffer(scaledVerts)));
+ cube.setColorRefBuffer(new J3DBuffer(makeFloatBuffer(colors)));
+
+ this.setGeometry(cube);
+ this.setAppearance(new SimpleShaderAppearance());
+ }
+
+ public Cube(double xScale, double yScale, double zScale, float r, float g, float b)
+ {
+ TriangleArray cube = new TriangleArray(36,
+ GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.USE_NIO_BUFFER | GeometryArray.BY_REFERENCE);
+
+ float scaledVerts[] = new float[verts.length];
+ for (int i = 0; i < verts.length; i += 3)
+ {
+ scaledVerts[i + 0] = verts[i + 0] * (float) xScale;
+ scaledVerts[i + 1] = verts[i + 1] * (float) yScale;
+ scaledVerts[i + 2] = verts[i + 2] * (float) zScale;
+ }
+
+ cube.setCoordRefBuffer(new J3DBuffer(makeFloatBuffer(scaledVerts)));
+
+ float colorsSet[] = new float[36 * 3];
+ for (int i = 0; i < 36; i++)
+ {
+ colorsSet[i * 3 + 0] = r;
+ colorsSet[i * 3 + 1] = g;
+ colorsSet[i * 3 + 2] = b;
+ }
+
+ cube.setColorRefBuffer(new J3DBuffer(makeFloatBuffer(colorsSet)));
+
+ this.setGeometry(cube);
+ this.setAppearance(new SimpleShaderAppearance());
+ }
+
+ public Cube(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax)
+ {
+ TriangleArray cube = new TriangleArray(36,
+ GeometryArray.COORDINATES | GeometryArray.COLOR_3 | GeometryArray.USE_NIO_BUFFER | GeometryArray.BY_REFERENCE);
+
+ float scaledVerts[] = new float[] {
+ // front face
+ xMax, yMin, zMax, //1
+ xMax, yMax, zMax, //2
+ xMin, yMax, zMax, //3
+ xMax, yMin, zMax, //1
+ xMin, yMax, zMax, //3
+ xMin, yMin, zMax, //4
+ // back face
+ xMin, yMin, zMin, //1
+ xMin, yMax, zMin, //2
+ xMax, yMax, zMin, //3
+ xMin, yMin, zMin, //1
+ xMax, yMax, zMin, //3
+ xMax, yMin, zMin, //4
+ // right face
+ xMax, yMin, zMin, //1
+ xMax, yMax, zMin, //2
+ xMax, yMax, zMax, //3
+ xMax, yMin, zMin, //1
+ xMax, yMax, zMax, //3
+ xMax, yMin, zMax, //4
+ // left face
+ xMin, yMin, zMax, //1
+ xMin, yMax, zMax, //2
+ xMin, yMax, zMin, //3
+ xMin, yMin, zMax, //1
+ xMin, yMax, zMin, //3
+ xMin, yMin, zMin, //4
+ // top face
+ xMax, yMax, zMax, //1
+ xMax, yMax, zMin, //2
+ xMin, yMax, zMin, //3
+ xMax, yMax, zMax, //1
+ xMin, yMax, zMin, //3
+ xMin, yMax, zMax, //4
+ // bottom face
+ xMin, yMin, zMax, //1
+ xMin, yMin, zMin, //2
+ xMax, yMin, zMin, //3
+ xMin, yMin, zMax, //1
+ xMax, yMin, zMin, //3
+ xMax, yMin, zMax, };//4
+
+ cube.setCoordRefBuffer(new J3DBuffer(makeFloatBuffer(scaledVerts)));
+ cube.setColorRefBuffer(new J3DBuffer(makeFloatBuffer(colors)));
+
+ this.setGeometry(cube);
+ this.setAppearance(new SimpleShaderAppearance());
+ }
+
+ public static FloatBuffer makeFloatBuffer(float[] arr)
+ {
+ ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
+ bb.order(ByteOrder.nativeOrder());
+ FloatBuffer fb = bb.asFloatBuffer();
+ fb.put(arr);
+ fb.position(0);
+ return fb;
+ }
+
+}
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/EnvironmentMappingGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/EnvironmentMappingGLSL.java
index 5eba8df..700df00 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/EnvironmentMappingGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/EnvironmentMappingGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed, licensed or
- * intended for use in the design, construction, operation or
- * maintenance of any nuclear facility.
- *
- * $Revision$
- * $Date$
- * $State$
*/
package org.jdesktop.j3d.examples.gl2es2pipeline;
@@ -48,9 +26,6 @@ import java.awt.GraphicsConfiguration;
import java.io.File;
import java.io.IOException;
import java.net.URL;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
import javax.swing.JOptionPane;
@@ -60,8 +35,6 @@ import org.jogamp.java3d.BoundingSphere;
import org.jogamp.java3d.BranchGroup;
import org.jogamp.java3d.Canvas3D;
import org.jogamp.java3d.GLSLShaderProgram;
-import org.jogamp.java3d.GeometryArray;
-import org.jogamp.java3d.J3DBuffer;
import org.jogamp.java3d.RotationInterpolator;
import org.jogamp.java3d.Shader;
import org.jogamp.java3d.ShaderAppearance;
@@ -76,7 +49,6 @@ import org.jogamp.java3d.Texture;
import org.jogamp.java3d.TextureUnitState;
import org.jogamp.java3d.Transform3D;
import org.jogamp.java3d.TransformGroup;
-import org.jogamp.java3d.TriangleStripArray;
import org.jogamp.java3d.utils.geometry.Sphere;
import org.jogamp.java3d.utils.image.TextureLoader;
import org.jogamp.java3d.utils.shader.StringIO;
@@ -191,6 +163,7 @@ public class EnvironmentMappingGLSL extends javax.swing.JFrame
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -251,6 +224,7 @@ public class EnvironmentMappingGLSL extends javax.swing.JFrame
System.setProperty("sun.awt.noerasebackground", "true");
System.setProperty("j3d.rend", "jogl2es2");
java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
public void run()
{
new EnvironmentMappingGLSL().setVisible(true);
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ObjLoadGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ObjLoadGLSL.java
index 709ff47..2708e58 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ObjLoadGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ObjLoadGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed, licensed or
- * intended for use in the design, construction, operation or
- * maintenance of any nuclear facility.
- *
- * $Revision$
- * $Date$
- * $State$
*/
package org.jdesktop.j3d.examples.gl2es2pipeline;
@@ -212,6 +190,7 @@ public class ObjLoadGLSL extends javax.swing.JFrame
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -263,7 +242,7 @@ public class ObjLoadGLSL extends javax.swing.JFrame
return canvas3d;
}
- private void usage()
+ private static void usage()
{
System.out.println("Usage: java ObjLoadGLSL [-s] [-S shaderName] [-n] [-t] [-c degrees] <.obj file>");
System.out.println(" -s Spin (no user interaction)");
@@ -289,7 +268,7 @@ public class ObjLoadGLSL extends javax.swing.JFrame
private void setShaderProgram(Group g, ShaderAppearance myApp)
{
- Enumeration e = g.getAllChildren();
+ Enumeration<?> e = g.getAllChildren();
while (e.hasMoreElements())
{
Node n = (Node) (e.nextElement());
@@ -429,6 +408,7 @@ public class ObjLoadGLSL extends javax.swing.JFrame
System.setProperty("sun.awt.noerasebackground", "true");
System.setProperty("j3d.rend","jogl2es2");
java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
public void run()
{
ObjLoadGLSL objLoadGLSL = new ObjLoadGLSL(args);
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/PhongShadingGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/PhongShadingGLSL.java
index 03fbd3d..fa5ba7a 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/PhongShadingGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/PhongShadingGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed, licensed or
- * intended for use in the design, construction, operation or
- * maintenance of any nuclear facility.
- *
- * $Revision$
- * $Date$
- * $State$
*/
package org.jdesktop.j3d.examples.gl2es2pipeline;
@@ -47,9 +25,6 @@ package org.jdesktop.j3d.examples.gl2es2pipeline;
import java.awt.GraphicsConfiguration;
import java.io.File;
import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
import javax.swing.JOptionPane;
@@ -63,8 +38,6 @@ import org.jogamp.java3d.Canvas3D;
import org.jogamp.java3d.ColoringAttributes;
import org.jogamp.java3d.DirectionalLight;
import org.jogamp.java3d.GLSLShaderProgram;
-import org.jogamp.java3d.GeometryArray;
-import org.jogamp.java3d.J3DBuffer;
import org.jogamp.java3d.Light;
import org.jogamp.java3d.Material;
import org.jogamp.java3d.PointLight;
@@ -78,7 +51,6 @@ import org.jogamp.java3d.SourceCodeShader;
import org.jogamp.java3d.SpotLight;
import org.jogamp.java3d.Transform3D;
import org.jogamp.java3d.TransformGroup;
-import org.jogamp.java3d.TriangleStripArray;
import org.jogamp.java3d.utils.geometry.Sphere;
import org.jogamp.java3d.utils.shader.StringIO;
import org.jogamp.java3d.utils.universe.SimpleUniverse;
@@ -160,7 +132,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
String vertexProgram = null;
String fragmentProgram = null;
Shader[] shaders = new Shader[2];
- String[] attrNames = { "numLights" };
+ //String[] attrNames = { "numLights" };
try
{
@@ -332,6 +304,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -397,6 +370,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
gouraudButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
gouraudButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
gouraudButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
gouraudButtonActionPerformed(evt);
@@ -413,6 +387,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
phongButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
phongButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
phongButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
phongButtonActionPerformed(evt);
@@ -441,6 +416,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
fileMenu.setText("File");
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
exitMenuItemActionPerformed(evt);
@@ -466,7 +442,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
sApp.setShaderProgram(gouraudSP);
}//GEN-LAST:event_gouraudButtonActionPerformed
- private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt)
+ private static void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_exitMenuItemActionPerformed
System.exit(0);
}//GEN-LAST:event_exitMenuItemActionPerformed
@@ -479,6 +455,7 @@ public class PhongShadingGLSL extends javax.swing.JFrame
System.setProperty("sun.awt.noerasebackground", "true");
System.setProperty("j3d.rend", "jogl2es2");
java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
public void run()
{
new PhongShadingGLSL().setVisible(true);
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SamplerTestGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SamplerTestGLSL.java
index 11bfeeb..1cb2904 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SamplerTestGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SamplerTestGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed, licensed or
- * intended for use in the design, construction, operation or
- * maintenance of any nuclear facility.
- *
- * $Revision$
- * $Date$
- * $State$
*/
package org.jdesktop.j3d.examples.gl2es2pipeline;
@@ -207,6 +185,7 @@ public class SamplerTestGLSL extends javax.swing.JFrame
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -267,6 +246,7 @@ public class SamplerTestGLSL extends javax.swing.JFrame
System.setProperty("sun.awt.noerasebackground", "true");
System.setProperty("j3d.rend","jogl2es2");
java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
public void run()
{
new SamplerTestGLSL().setVisible(true);
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ShaderTestGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ShaderTestGLSL.java
index 65f40bb..ac0282e 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ShaderTestGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/ShaderTestGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed, licensed or
- * intended for use in the design, construction, operation or
- * maintenance of any nuclear facility.
- *
- * $Revision$
- * $Date$
- * $State$
*/
package org.jdesktop.j3d.examples.gl2es2pipeline;
@@ -47,9 +25,6 @@ package org.jdesktop.j3d.examples.gl2es2pipeline;
import java.awt.GraphicsConfiguration;
import java.io.File;
import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
import javax.swing.JOptionPane;
@@ -59,8 +34,6 @@ import org.jogamp.java3d.BoundingSphere;
import org.jogamp.java3d.BranchGroup;
import org.jogamp.java3d.Canvas3D;
import org.jogamp.java3d.GLSLShaderProgram;
-import org.jogamp.java3d.GeometryArray;
-import org.jogamp.java3d.J3DBuffer;
import org.jogamp.java3d.Material;
import org.jogamp.java3d.PositionInterpolator;
import org.jogamp.java3d.Shader;
@@ -75,8 +48,6 @@ import org.jogamp.java3d.Shape3D;
import org.jogamp.java3d.SourceCodeShader;
import org.jogamp.java3d.Transform3D;
import org.jogamp.java3d.TransformGroup;
-import org.jogamp.java3d.TriangleStripArray;
-import org.jogamp.java3d.View;
import org.jogamp.java3d.utils.geometry.Sphere;
import org.jogamp.java3d.utils.shader.StringIO;
import org.jogamp.java3d.utils.universe.SimpleUniverse;
@@ -102,8 +73,8 @@ public class ShaderTestGLSL extends javax.swing.JFrame
static final String[] shaderAttrNames2 = { "BrickColor", "LightPosition" };
private SimpleUniverse univ = null;
- private View view;
- private BranchGroup transpObj;
+ //private View view;
+ //private BranchGroup transpObj;
private BranchGroup scene = null;
private int shaderSelected = DIMPLE_SHADER;
private float density = 16.0f;
@@ -140,7 +111,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
return m;
}
- private ShaderProgram createGLSLShaderProgram(int index)
+ private static ShaderProgram createGLSLShaderProgram(int index)
{
String vertexProgram = null;
String fragmentProgram = null;
@@ -348,6 +319,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -360,7 +332,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
// objects in the scene can be viewed.
viewingPlatform.setNominalViewingTransform();
- view = univ.getViewer().getView();
+ //view = univ.getViewer().getView();
return c;
}
@@ -413,6 +385,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
setTitle("Window Title");
addWindowListener(new java.awt.event.WindowAdapter() {
+ @Override
public void windowClosing(java.awt.event.WindowEvent evt)
{
exitForm(evt);
@@ -430,6 +403,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
densityButtonGroup.add(zeroButton);
zeroButton.setText("Zero");
zeroButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
zeroButtonActionPerformed(evt);
@@ -443,6 +417,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
densityButtonGroup.add(halfButton);
halfButton.setText("Half");
halfButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
halfButtonActionPerformed(evt);
@@ -459,6 +434,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
fullButton.setSelected(true);
fullButton.setText("Full");
fullButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
fullButtonActionPerformed(evt);
@@ -481,6 +457,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
goldButton.setSelected(true);
goldButton.setText("Gold");
goldButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
goldButtonActionPerformed(evt);
@@ -494,6 +471,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
colorButtonGroup.add(silverButton);
silverButton.setText("Silver");
silverButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
silverButtonActionPerformed(evt);
@@ -515,6 +493,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
DetachButton.setSelected(true);
DetachButton.setText("Detach");
DetachButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
DetachButtonActionPerformed(evt);
@@ -528,6 +507,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
sceneGraphButtonGroup.add(AttachButton);
AttachButton.setText("Create");
AttachButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
AttachButtonActionPerformed(evt);
@@ -543,6 +523,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
replaceSPButton.setText("Replace Shader");
replaceSPButton.setEnabled(false);
replaceSPButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
replaceSPButtonActionPerformed(evt);
@@ -569,6 +550,7 @@ public class ShaderTestGLSL extends javax.swing.JFrame
fileMenu.setText("File");
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
exitMenuItemActionPerformed(evt);
@@ -698,13 +680,13 @@ public class ShaderTestGLSL extends javax.swing.JFrame
}//GEN-LAST:event_zeroButtonActionPerformed
- private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt)
+ private static void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_exitMenuItemActionPerformed
System.exit(0);
}//GEN-LAST:event_exitMenuItemActionPerformed
/** Exit the Application */
- private void exitForm(java.awt.event.WindowEvent evt)
+ private static void exitForm(java.awt.event.WindowEvent evt)
{//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java
index f06f9e9..5b7be75 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java
@@ -1,3 +1,24 @@
+/*
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
package org.jdesktop.j3d.examples.gl2es2pipeline;
import org.jogamp.java3d.ColoringAttributes;
@@ -14,7 +35,6 @@ import org.jogamp.java3d.SourceCodeShader;
import org.jogamp.vecmath.Color3f;
/**
- * Note all of these are no lighting shaders, so materials are always ignored
* @author phil
*
*/
@@ -23,6 +43,8 @@ public class SimpleShaderAppearance extends ShaderAppearance
private static GLSLShaderProgram flatShaderProgram;
private static GLSLShaderProgram textureShaderProgram;
private static GLSLShaderProgram colorLineShaderProgram;
+ private static GLSLShaderProgram litFlatShaderProgram;
+ private static GLSLShaderProgram litTextureShaderProgram;
public static String alphaTestUniforms = "uniform int alphaTestEnabled;\n" + //
"uniform int alphaTestFunction;\n" + //
@@ -51,7 +73,7 @@ public class SimpleShaderAppearance extends ShaderAppearance
*/
public SimpleShaderAppearance()
{
- this(null, false);
+ this(null, false, false);
}
/**
@@ -60,7 +82,7 @@ public class SimpleShaderAppearance extends ShaderAppearance
*/
public SimpleShaderAppearance(Color3f color)
{
- this(color, false);
+ this(color, false, false);
}
/**
@@ -68,161 +90,364 @@ public class SimpleShaderAppearance extends ShaderAppearance
*/
public SimpleShaderAppearance(boolean hasTexture)
{
- this(null, hasTexture);
+ this(null, false, hasTexture);
+ }
+
+ public SimpleShaderAppearance(boolean lit, boolean hasTexture)
+ {
+ this(null, lit, hasTexture);
}
/** if color is not null then a line appearance
* otherwise simple poly appearance
* @param color
*/
- private SimpleShaderAppearance(Color3f color, boolean hasTexture)
+ private SimpleShaderAppearance(Color3f color, boolean lit, boolean hasTexture)
{
- if (hasTexture)
+ if (lit)
{
- RenderingAttributes ra = new RenderingAttributes();
- setRenderingAttributes(ra);
-
- if (textureShaderProgram == null)
+ String vertexProgram = "#version 120\n";
+ vertexProgram += "attribute vec4 glVertex;\n";
+ vertexProgram += "attribute vec4 glColor;\n";
+ vertexProgram += "attribute vec3 glNormal; \n";
+ if (hasTexture)
{
- textureShaderProgram = new GLSLShaderProgram() {
- @Override
- public String toString()
- {
- return "SimpleShaderAppearance textureShaderProgram";
- }
- };
- String vertexProgram = "#version 120\n";
- vertexProgram += "attribute vec4 glVertex;\n";
vertexProgram += "attribute vec2 glMultiTexCoord0;\n";
- vertexProgram += "uniform mat4 glModelViewProjectionMatrix;\n";
+ }
+ vertexProgram += "uniform mat4 glModelViewProjectionMatrix;\n";
+ vertexProgram += "uniform mat4 glModelViewMatrix;\n";
+ vertexProgram += "uniform mat3 glNormalMatrix;\n";
+ vertexProgram += "uniform int ignoreVertexColors;\n";
+ vertexProgram += "uniform vec4 glLightModelambient;\n";
+ vertexProgram += "struct material\n";
+ vertexProgram += "{\n";
+ vertexProgram += " int lightEnabled;\n";
+ vertexProgram += " vec4 ambient;\n";
+ vertexProgram += " vec4 diffuse;\n";
+ vertexProgram += " vec4 emission; \n";
+ vertexProgram += " vec3 specular;\n";
+ vertexProgram += " float shininess;\n";
+ vertexProgram += "};\n";
+ vertexProgram += "uniform material glFrontMaterial;\n";
+ vertexProgram += "struct lightSource\n";
+ vertexProgram += " {\n";
+ vertexProgram += " int enabled;\n";
+ vertexProgram += " vec4 position;\n";
+ vertexProgram += " vec4 diffuse;\n";
+ vertexProgram += " vec4 specular;\n";
+ vertexProgram += " float constantAttenuation, linearAttenuation, quadraticAttenuation;\n";
+ vertexProgram += " float spotCutoff, spotExponent;\n";
+ vertexProgram += " vec3 spotDirection;\n";
+ vertexProgram += " };\n";
+ vertexProgram += "\n";
+ vertexProgram += " uniform int numberOfLights;\n";
+ vertexProgram += " const int maxLights = 1;\n";
+ vertexProgram += " uniform lightSource glLightSource[maxLights];\n";
+ if (hasTexture)
+ {
vertexProgram += "varying vec2 glTexCoord0;\n";
- vertexProgram += "void main( void ){\n";
- vertexProgram += "gl_Position = glModelViewProjectionMatrix * glVertex;\n";
+ }
+ vertexProgram += "varying vec3 LightDir;\n";
+ vertexProgram += "varying vec3 ViewDir;\n";
+ vertexProgram += "varying vec3 N;\n";
+ vertexProgram += "varying vec4 A;\n";
+ vertexProgram += "varying vec4 C;\n";
+ vertexProgram += "varying vec4 D;\n";
+ vertexProgram += "varying vec3 emissive;\n";
+ vertexProgram += "varying vec3 specular;\n";
+ vertexProgram += "varying float shininess;\n";
+ vertexProgram += "void main( void ){\n";
+ vertexProgram += "gl_Position = glModelViewProjectionMatrix * glVertex;\n";
+ if (hasTexture)
+ {
vertexProgram += "glTexCoord0 = glMultiTexCoord0.st;\n";
- vertexProgram += "}";
+ }
+
+ vertexProgram += "N = normalize(glNormalMatrix * glNormal);\n";
+
+ vertexProgram += "vec3 v = vec3(glModelViewMatrix * glVertex);\n";
+
+ vertexProgram += "ViewDir = -v.xyz;\n";
+ vertexProgram += "LightDir = glLightSource[0].position.xyz;\n";
- String fragmentProgram = "#version 120\n";
- fragmentProgram += "precision mediump float;\n";
+ vertexProgram += "A = glLightModelambient * glFrontMaterial.ambient;\n";
+ vertexProgram += "if( ignoreVertexColors != 0) \n";
+ // objectColor should be used if it is no lighting, and reusing material diffuse appears wrong
+ vertexProgram += " C = vec4(1,1,1,1);//glFrontMaterial.diffuse; \n";
+ vertexProgram += "else \n";
+ vertexProgram += " C = glColor; \n";
+
+ vertexProgram += "D = glLightSource[0].diffuse * glFrontMaterial.diffuse;\n";
+
+ vertexProgram += "emissive = glFrontMaterial.emission.rgb;\n";
+ vertexProgram += "specular = glFrontMaterial.specular;\n";
+ vertexProgram += "shininess = glFrontMaterial.shininess;\n";
+ vertexProgram += "}";
+
+ String fragmentProgram = "#version 120\n";
+ fragmentProgram += "precision mediump float;\n";
+ if (hasTexture)
+ {
fragmentProgram += alphaTestUniforms;
+
fragmentProgram += "varying vec2 glTexCoord0;\n";
fragmentProgram += "uniform sampler2D BaseMap;\n";
- fragmentProgram += "void main( void ){\n ";
+ }
+
+ fragmentProgram += "in vec3 LightDir;\n";
+ fragmentProgram += "in vec3 ViewDir;\n";
+
+ fragmentProgram += "in vec3 N;\n";
+
+ fragmentProgram += "in vec4 A;\n";
+ fragmentProgram += "in vec4 C;\n";
+ fragmentProgram += "in vec4 D;\n";
+
+ fragmentProgram += "in vec3 emissive;\n";
+ fragmentProgram += "in vec3 specular;\n";
+ fragmentProgram += "in float shininess;\n";
+ fragmentProgram += "void main( void ){\n ";
+ if (hasTexture)
+ {
fragmentProgram += "vec4 baseMap = texture2D( BaseMap, glTexCoord0.st );\n";
+ }
+ if (hasTexture)
+ {
fragmentProgram += alphaTestMethod;
- fragmentProgram += "gl_FragColor = baseMap;\n";
- fragmentProgram += "}";
-
- textureShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
- textureShaderProgram.setShaderAttrNames(new String[] { "BaseMap" });
}
+ fragmentProgram += "vec3 normal = N;\n";
- setShaderProgram(textureShaderProgram);
+ fragmentProgram += "vec3 L = normalize(LightDir);\n";
+ fragmentProgram += "vec3 E = normalize(ViewDir);\n";
+ fragmentProgram += "vec3 R = reflect(-L, normal);\n";
+ fragmentProgram += "vec3 H = normalize( L + E );\n";
- ShaderAttributeSet shaderAttributeSet = new ShaderAttributeSet();
- shaderAttributeSet.put(new ShaderAttributeValue("BaseMap", new Integer(0)));
- setShaderAttributeSet(shaderAttributeSet);
+ fragmentProgram += "float NdotL = max( dot(normal, L), 0.0 );\n";
+ fragmentProgram += "float NdotH = max( dot(normal, H), 0.0 );\n";
+ fragmentProgram += "float EdotN = max( dot(normal, E), 0.0 );\n";
+ fragmentProgram += "float NdotNegL = max( dot(normal, -L), 0.0 );\n";
- }
- else
- {
- if (color != null)
+ fragmentProgram += "vec4 color;\n";
+ if (hasTexture)
+ {
+ fragmentProgram += "vec3 albedo = baseMap.rgb * C.rgb;\n";
+ }
+ else
{
- PolygonAttributes polyAtt = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0.0f);
- polyAtt.setPolygonOffset(0.1f);
- setPolygonAttributes(polyAtt);
- LineAttributes lineAtt = new LineAttributes(1, LineAttributes.PATTERN_SOLID, false);
- setLineAttributes(lineAtt);
+ fragmentProgram += "vec3 albedo = C.rgb;\n";
+ }
+ fragmentProgram += "vec3 diffuse = A.rgb + (D.rgb * NdotL);\n";
- ColoringAttributes colorAtt = new ColoringAttributes(color, ColoringAttributes.FASTEST);
- setColoringAttributes(colorAtt);
+ // 0.3 is just what the calc is
+ fragmentProgram += "vec3 spec = specular * pow(NdotH, 0.3*shininess);\n";
+ // D is not right it should be the light source spec color, probably just 1,1,1 but java3d has no spec on lights
+ //fragmentProgram += "spec *= D.rgb;\n";
- RenderingAttributes ra = new RenderingAttributes();
- ra.setIgnoreVertexColors(true);
- setRenderingAttributes(ra);
+ fragmentProgram += "color.rgb = albedo * (diffuse + emissive) + spec;\n";
+ if (hasTexture)
+ {
+ fragmentProgram += "color.a = C.a * baseMap.a;\n";
+ }
+ else
+ {
+ fragmentProgram += "color.a = C.a;\n";
+ }
- Material mat = new Material();
- setMaterial(mat);
+ fragmentProgram += "gl_FragColor = color;\n";
- if (colorLineShaderProgram == null)
+ fragmentProgram += "}";
+ if (hasTexture)
+ {
+ if (litTextureShaderProgram == null)
{
- colorLineShaderProgram = new GLSLShaderProgram() {
+ litTextureShaderProgram = new GLSLShaderProgram() {
@Override
public String toString()
{
- return "SimpleShaderAppearance colorLineShaderProgram";
+ return "SimpleShaderAppearance litTextureShaderProgram";
}
};
- String vertexProgram = "#version 120\n";
- vertexProgram += "attribute vec4 glVertex;\n";
- vertexProgram += "attribute vec4 glColor;\n";
- vertexProgram += "uniform int ignoreVertexColors;\n";
- vertexProgram += "uniform vec4 objectColor;\n";
- vertexProgram += "uniform mat4 glModelViewProjectionMatrix;\n";
- vertexProgram += "varying vec4 glFrontColor;\n";
- vertexProgram += "void main( void ){\n";
- vertexProgram += "gl_Position = glModelViewProjectionMatrix * glVertex;\n";
- vertexProgram += "if( ignoreVertexColors != 0 )\n";
- vertexProgram += " glFrontColor = objectColor;\n";
- vertexProgram += "else\n";
- vertexProgram += " glFrontColor = glColor;\n";
- vertexProgram += "}";
-
- String fragmentProgram = "#version 120\n";
- fragmentProgram += "precision mediump float;\n";
- fragmentProgram += "varying vec4 glFrontColor;\n";
- fragmentProgram += "void main( void ){\n";
- fragmentProgram += "gl_FragColor = glFrontColor;\n";
- fragmentProgram += "}";
+ litTextureShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
+ litTextureShaderProgram.setShaderAttrNames(new String[] { "BaseMap" });
- colorLineShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
}
- setShaderProgram(colorLineShaderProgram);
+ setShaderProgram(litTextureShaderProgram);
+ ShaderAttributeSet shaderAttributeSet = new ShaderAttributeSet();
+ shaderAttributeSet.put(new ShaderAttributeValue("BaseMap", new Integer(0)));
+ setShaderAttributeSet(shaderAttributeSet);
}
else
{
- RenderingAttributes ra = new RenderingAttributes();
- setRenderingAttributes(ra);
+ if (litFlatShaderProgram == null)
+ {
+ litFlatShaderProgram = new GLSLShaderProgram() {
+ @Override
+ public String toString()
+ {
+ return "SimpleShaderAppearance litFlatShaderProgram";
+ }
+ };
+ litFlatShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
- if (flatShaderProgram == null)
+ //System.out.println("vertexProgram " + vertexProgram);
+ //System.out.println("fragmentProgram " + fragmentProgram);
+
+ }
+
+ setShaderProgram(litFlatShaderProgram);
+
+ }
+ }
+ else
+ {
+ if (hasTexture)
+ {
+ if (textureShaderProgram == null)
{
- flatShaderProgram = new GLSLShaderProgram() {
+ textureShaderProgram = new GLSLShaderProgram() {
@Override
public String toString()
{
- return "SimpleShaderAppearance flatShaderProgram";
+ return "SimpleShaderAppearance textureShaderProgram";
}
};
String vertexProgram = "#version 120\n";
vertexProgram += "attribute vec4 glVertex;\n";
- vertexProgram += "attribute vec4 glColor;\n";
- vertexProgram += "uniform int ignoreVertexColors;\n";
- vertexProgram += "uniform vec4 objectColor;\n";
+ vertexProgram += "attribute vec2 glMultiTexCoord0;\n";
vertexProgram += "uniform mat4 glModelViewProjectionMatrix;\n";
- vertexProgram += "varying vec4 glFrontColor;\n";
+ vertexProgram += "varying vec2 glTexCoord0;\n";
vertexProgram += "void main( void ){\n";
vertexProgram += "gl_Position = glModelViewProjectionMatrix * glVertex;\n";
- vertexProgram += "if( ignoreVertexColors != 0 )\n";
- vertexProgram += " glFrontColor = objectColor;\n";
- vertexProgram += "else\n";
- vertexProgram += " glFrontColor = glColor;\n";
+ vertexProgram += "glTexCoord0 = glMultiTexCoord0.st;\n";
vertexProgram += "}";
String fragmentProgram = "#version 120\n";
fragmentProgram += "precision mediump float;\n";
- fragmentProgram += "varying vec4 glFrontColor;\n";
- fragmentProgram += "void main( void ){\n";
- fragmentProgram += "gl_FragColor = glFrontColor;\n";
+ fragmentProgram += alphaTestUniforms;
+ fragmentProgram += "varying vec2 glTexCoord0;\n";
+ fragmentProgram += "uniform sampler2D BaseMap;\n";
+ fragmentProgram += "void main( void ){\n ";
+ fragmentProgram += "vec4 baseMap = texture2D( BaseMap, glTexCoord0.st );\n";
+ fragmentProgram += alphaTestMethod;
+ fragmentProgram += "gl_FragColor = baseMap;\n";
fragmentProgram += "}";
- flatShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
+ textureShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
+ textureShaderProgram.setShaderAttrNames(new String[] { "BaseMap" });
+ }
+
+ setShaderProgram(textureShaderProgram);
+
+ ShaderAttributeSet shaderAttributeSet = new ShaderAttributeSet();
+ shaderAttributeSet.put(new ShaderAttributeValue("BaseMap", new Integer(0)));
+ setShaderAttributeSet(shaderAttributeSet);
+
+ }
+ else
+
+ {
+ if (color != null)
+ {
+ PolygonAttributes polyAtt = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0.0f);
+ polyAtt.setPolygonOffset(0.1f);
+ setPolygonAttributes(polyAtt);
+ LineAttributes lineAtt = new LineAttributes(1, LineAttributes.PATTERN_SOLID, false);
+ setLineAttributes(lineAtt);
+
+ ColoringAttributes colorAtt = new ColoringAttributes(color, ColoringAttributes.FASTEST);
+ setColoringAttributes(colorAtt);
+
+ RenderingAttributes ra = new RenderingAttributes();
+ ra.setIgnoreVertexColors(true);
+ setRenderingAttributes(ra);
+
+ Material mat = new Material();
+ setMaterial(mat);
+
+ if (colorLineShaderProgram == null)
+ {
+ colorLineShaderProgram = new GLSLShaderProgram() {
+ @Override
+ public String toString()
+ {
+ return "SimpleShaderAppearance colorLineShaderProgram";
+ }
+ };
+ String vertexProgram = "#version 120\n";
+ vertexProgram += "attribute vec4 glVertex;\n";
+ vertexProgram += "attribute vec4 glColor;\n";
+ vertexProgram += "uniform int ignoreVertexColors;\n";
+ vertexProgram += "uniform vec4 objectColor;\n";
+ vertexProgram += "uniform mat4 glModelViewProjectionMatrix;\n";
+ vertexProgram += "varying vec4 glFrontColor;\n";
+ vertexProgram += "void main( void ){\n";
+ vertexProgram += "gl_Position = glModelViewProjectionMatrix * glVertex;\n";
+ vertexProgram += "if( ignoreVertexColors != 0 )\n";
+ vertexProgram += " glFrontColor = objectColor;\n";
+ vertexProgram += "else\n";
+ vertexProgram += " glFrontColor = glColor;\n";
+ vertexProgram += "}";
+
+ String fragmentProgram = "#version 120\n";
+ fragmentProgram += "precision mediump float;\n";
+ fragmentProgram += "varying vec4 glFrontColor;\n";
+ fragmentProgram += "void main( void ){\n";
+ fragmentProgram += "gl_FragColor = glFrontColor;\n";
+ fragmentProgram += "}";
+
+ colorLineShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
+ }
+
+ setShaderProgram(colorLineShaderProgram);
}
+ else
+ {
+ RenderingAttributes ra = new RenderingAttributes();
+ setRenderingAttributes(ra);
+
+ if (flatShaderProgram == null)
+ {
+ flatShaderProgram = new GLSLShaderProgram() {
+ @Override
+ public String toString()
+ {
+ return "SimpleShaderAppearance flatShaderProgram";
+ }
+ };
+ String vertexProgram = "#version 120\n";
+ vertexProgram += "attribute vec4 glVertex;\n";
+ vertexProgram += "attribute vec4 glColor;\n";
+ vertexProgram += "uniform int ignoreVertexColors;\n";
+ vertexProgram += "uniform vec4 objectColor;\n";
+ vertexProgram += "uniform mat4 glModelViewProjectionMatrix;\n";
+ vertexProgram += "varying vec4 glFrontColor;\n";
+ vertexProgram += "void main( void ){\n";
+ vertexProgram += "gl_Position = glModelViewProjectionMatrix * glVertex;\n";
+ vertexProgram += "if( ignoreVertexColors != 0 )\n";
+ vertexProgram += " glFrontColor = objectColor;\n";
+ vertexProgram += "else\n";
+ vertexProgram += " glFrontColor = glColor;\n";
+ vertexProgram += "}";
- setShaderProgram(flatShaderProgram);
+ String fragmentProgram = "#version 120\n";
+ fragmentProgram += "precision mediump float;\n";
+ fragmentProgram += "varying vec4 glFrontColor;\n";
+ fragmentProgram += "void main( void ){\n";
+ fragmentProgram += "gl_FragColor = glFrontColor;\n";
+ fragmentProgram += "}";
+ flatShaderProgram.setShaders(makeShaders(vertexProgram, fragmentProgram));
+
+ }
+
+ setShaderProgram(flatShaderProgram);
+
+ }
}
+
}
}
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SphereGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SphereGLSL.java
index 61069f7..8a59c5f 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SphereGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/SphereGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed, licensed or
- * intended for use in the design, construction, operation or
- * maintenance of any nuclear facility.
- *
- * $Revision$
- * $Date$
- * $State$
*/
package org.jdesktop.j3d.examples.gl2es2pipeline;
@@ -198,8 +176,8 @@ public class SphereGLSL extends javax.swing.JFrame
caL1.setColor(lColor1);
caL2.setColor(lColor2);
- Appearance appL1 = makeGouraudShaderAppearance();
- Appearance appL2 = makeGouraudShaderAppearance();
+ Appearance appL1 = new SimpleShaderAppearance(false, false);
+ Appearance appL2 = new SimpleShaderAppearance(false, false);
appL1.setColoringAttributes(caL1);
appL2.setColoringAttributes(caL2);
@@ -285,41 +263,6 @@ public class SphereGLSL extends javax.swing.JFrame
return objRoot;
}
- /**
- * GL2ES2: this should be a trivial emissive color shader, but gouraud will do for now
- * @return
- */
- private Appearance makeGouraudShaderAppearance()
- {
- // Create a Sphere object, generate one copy of the sphere,
- // and add it into the scene graph.
- ShaderAppearance a = new ShaderAppearance();
- Material m = new Material();
- m.setLightingEnable(true);
- String vertexProgram = null;
- String fragmentProgram = null;
- try
- {
- vertexProgram = StringIO.readFully(
- new File(System.getProperty("user.dir") + "/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert"));
- fragmentProgram = StringIO.readFully(
- new File(System.getProperty("user.dir") + "/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.frag"));
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
- Shader[] shaders = new Shader[2];
- shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_VERTEX, vertexProgram);
- shaders[1] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL, Shader.SHADER_TYPE_FRAGMENT, fragmentProgram);
- ShaderProgram shaderProgram = new GLSLShaderProgram();
- shaderProgram.setShaders(shaders);
-
- a.setShaderProgram(shaderProgram);
- a.setMaterial(m);
- return a;
- }
-
private Canvas3D createUniverse()
{
// Get the preferred graphics configuration for the default screen
@@ -330,10 +273,11 @@ public class SphereGLSL extends javax.swing.JFrame
// Create simple universe with view branch
univ = new SimpleUniverse(canvas3d);
- BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
+ //BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -399,6 +343,7 @@ public class SphereGLSL extends javax.swing.JFrame
System.setProperty("sun.awt.noerasebackground", "true");
System.setProperty("j3d.rend", "jogl2es2");
java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
public void run()
{
SphereGLSL sphereGLSL = new SphereGLSL();
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/VertexAttrTestGLSL.java b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/VertexAttrTestGLSL.java
index 96bc0c9..f80ac11 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/VertexAttrTestGLSL.java
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/VertexAttrTestGLSL.java
@@ -1,45 +1,23 @@
/*
- * $RCSfile$
+ * Copyright (c) 2016 JogAmp Community. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
*
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any
- * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
- * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
- * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
- * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
- * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
- * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
- * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
- * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
- * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
- * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that this software is not designed, licensed or
- * intended for use in the design, construction, operation or
- * maintenance of any nuclear facility.
- *
- * $Revision$
- * $Date$
- * $State$
*/
package org.jdesktop.j3d.examples.gl2es2pipeline;
@@ -122,6 +100,7 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
// Add a ShaderErrorListener
univ.addShaderErrorListener(new ShaderErrorListener() {
+ @Override
public void errorOccurred(ShaderError error)
{
error.printVerbose();
@@ -272,6 +251,7 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
setTitle("VertexAttrTestGLSL");
addWindowListener(new java.awt.event.WindowAdapter() {
+ @Override
public void windowClosing(java.awt.event.WindowEvent evt)
{
exitForm(evt);
@@ -329,6 +309,7 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
createButton.setText("Create Geometry");
createButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
createButtonActionPerformed(evt);
@@ -341,6 +322,7 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
destroyButton.setText("Destroy Geometry");
destroyButton.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
destroyButtonActionPerformed(evt);
@@ -370,6 +352,7 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
fileMenu.setText("File");
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
+ @Override
public void actionPerformed(java.awt.event.ActionEvent evt)
{
exitMenuItemActionPerformed(evt);
@@ -404,13 +387,13 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
}
}//GEN-LAST:event_createButtonActionPerformed
- private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt)
+ private static void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_exitMenuItemActionPerformed
System.exit(0);
}//GEN-LAST:event_exitMenuItemActionPerformed
/** Exit the Application */
- private void exitForm(java.awt.event.WindowEvent evt)
+ private static void exitForm(java.awt.event.WindowEvent evt)
{//GEN-FIRST:event_exitForm
System.exit(0);
}//GEN-LAST:event_exitForm
@@ -423,6 +406,7 @@ public class VertexAttrTestGLSL extends javax.swing.JFrame
System.setProperty("sun.awt.noerasebackground", "true");
System.setProperty("j3d.rend","jogl2es2");
java.awt.EventQueue.invokeLater(new Runnable() {
+ @Override
public void run()
{
new VertexAttrTestGLSL().setVisible(true);
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/dimple.vert b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/dimple.vert
index 9b06148..ebbfdc9 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/dimple.vert
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/dimple.vert
@@ -18,7 +18,6 @@ uniform mat4 glModelViewMatrix;
uniform mat4 glModelViewProjectionMatrix;
uniform mat3 glNormalMatrix;
-uniform vec4 glFrontMaterialdiffuse;
uniform int ignoreVertexColors;
// GL2ES2: new output varyings, these replace gl_TexCoord[] and gl_FrontColor (along with A and D)
@@ -52,7 +51,7 @@ void main(void)
//gl_FrontColor = gl_Color;
if( ignoreVertexColors != 0)
- C = glFrontMaterialdiffuse;
+ C = vec4(1,1,1,1);
else
C = glColor;
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag
index bdc0fe0..d6f5e96 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag
@@ -7,12 +7,16 @@ uniform int alphaTestEnabled;
uniform int alphaTestFunction;
uniform float alphaTestValue;
-uniform int fogEnabled;
-uniform vec4 expColor;
-uniform float expDensity;
-uniform vec4 linearColor;
-uniform float linearStart;
-uniform float linearEnd;
+struct fogData
+{
+ int fogEnabled = -1;
+ vec3 expColor = new Vector3f();
+ float expDensity;
+ vec3 linearColor = new Vector3f();
+ float linearStart;
+ float linearEnd;
+};
+uniform fogData fogData;
//End of FFP inputs
in vec2 glTexCoord0;
@@ -85,7 +89,7 @@ void main( void )
color.rgb = albedo * (diffuse + emissive) + spec;
color.a = C.a * baseMap.a;
- if(fogEnabled == 1)
+ if(fogData.fogEnabled == 1)
{
//distance
float dist = 0.0;
@@ -94,21 +98,21 @@ void main( void )
//compute distance used in fog equations
dist = length(ViewDir);
- if(linearEnd > 0.0)//linear fog
+ if(fogData.linearEnd > 0.0)//linear fog
{
- fogFactor = (linearEnd - dist)/(linearEnd - linearStart);
+ fogFactor = (fogData.linearEnd - dist)/(fogData.linearEnd - fogData.linearStart);
fogFactor = clamp( fogFactor, 0.0, 1.0 );
//if you inverse color in glsl mix function you have to put 1.0 - fogFactor
- color = mix(linearColor, color, fogFactor);
+ color = mix(fogData.linearColor, color, fogFactor);
}
- else if( expDensity > 0.0)// exponential fog
+ else if( fogData.expDensity > 0.0)// exponential fog
{
- fogFactor = 1.0 /exp(dist * expDensity);
+ fogFactor = 1.0 /exp(dist * fogData.expDensity);
fogFactor = clamp( fogFactor, 0.0, 1.0 );
// mix function fogColor-(1-fogFactor) + lightColor-fogFactor
- color = mix(expColor, color, fogFactor);
+ color = mix(fogData.expColor, color, fogFactor);
}
}
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert
index 184620e..091e33b 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert
@@ -18,17 +18,36 @@ uniform mat4 glModelMatrix;
//uniform mat3 glNormalMatrix;
-//uniform vec4 glFrontMaterialambient;
-uniform vec4 glFrontMaterialdiffuse;
-uniform vec4 glFrontMaterialemission;
-uniform vec3 glFrontMaterialspecular;
-uniform float glFrontMaterialshininess;
+
uniform int ignoreVertexColors;
uniform vec4 glLightModelambient;
-uniform vec4 glLightSource0position;
-uniform vec4 glLightSource0diffuse;
+struct material
+{
+ int lightEnabled;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 emission;// note vec4 extra 1.0 sent through for ease
+ vec3 specular;
+ float shininess;
+};
+uniform material glFrontMaterial;
+
+struct lightSource
+{
+ int enabled;
+ vec4 position;
+ vec4 diffuse;
+ vec4 specular;
+ float constantAttenuation, linearAttenuation, quadraticAttenuation;
+ float spotCutoff, spotExponent;
+ vec3 spotDirection;
+};
+
+uniform int numberOfLights;
+const int maxLights = 1;
+uniform lightSource glLightSource[maxLights];
uniform mat4 textureTransform;
@@ -37,15 +56,17 @@ uniform mat4 textureTransform;
//uniform float alphaTestValue;
-//uniform int fogEnabled;
-//uniform vec4 expColor;
-//uniform float expDensity;
-//uniform vec4 linearColor;
-//uniform float linearStart;
-//uniform float linearEnd;
+ // struct fogData
+ // {
+ // int fogEnabled = -1;
+ // vec3 expColor = new Vector3f();
+ // float expDensity;
+ // vec3 linearColor = new Vector3f();
+ // float linearStart;
+ // float linearEnd;
+ // };
+ // uniform fogData fogData;
-//End of FFP inputs
-//The line above in not optional for parsing reasons
//Fixed function pipeline pre-calculated values not available
//vec3 halfVector = normalize(vec3(gl_LightSource[0].halfVector));
@@ -96,8 +117,8 @@ out float shininess;
void main( void )
{
- mat4 glModelViewMatrix = glViewMatrix*glModelMatrix;
- gl_Position = glProjectionMatrix*glModelViewMatrix * glVertex;//glModelViewProjectionMatrix * glVertex;
+ mat4 glModelViewMatrix = glViewMatrix * glModelMatrix;
+ gl_Position = glProjectionMatrix * glModelViewMatrix * glVertex;//glModelViewProjectionMatrix * glVertex;
glTexCoord0 = (textureTransform * vec4(glMultiTexCoord0,0,1)).st;
@@ -107,17 +128,17 @@ void main( void )
vec3 v = vec3(glModelViewMatrix * glVertex);
ViewDir = -v.xyz;
- LightDir = glLightSource0position.xyz;
+ LightDir = glLightSource[0].position.xyz;
A = glLightModelambient;
if( ignoreVertexColors != 0)
- C = glFrontMaterialdiffuse; // objectColor should be used if it is no lighting
+ C = vec4(1,1,1,1);//glFrontMaterialdiffuse; // objectColor should be used if it is no lighting
else
C = glColor;
- D = glLightSource0diffuse * glFrontMaterialdiffuse;
+ D = glLightSource[0].diffuse * glFrontMaterial.diffuse;
- emissive = glFrontMaterialemission.rgb;
- specular = glFrontMaterialspecular;
- shininess = glFrontMaterialshininess;
+ emissive = glFrontMaterial.emission.rgb;
+ specular = glFrontMaterial.specular;
+ shininess = glFrontMaterial.shininess;
}
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert
index 81d9c95..771afce 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert
@@ -54,16 +54,35 @@ uniform mat4 glModelViewMatrix;
uniform mat4 glModelViewProjectionMatrix;
uniform mat3 glNormalMatrix;
-uniform vec4 glFrontMaterialambient;
-uniform vec4 glFrontMaterialdiffuse;
-uniform vec4 glFrontMaterialemission;
-uniform vec3 glFrontMaterialspecular;
-uniform float glFrontMaterialshininess;
+
uniform vec4 glLightModelambient;
-uniform vec4 glLightSource0position;
-uniform vec4 glLightSource0diffuse;
+struct material
+{
+ int lightEnabled;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 emission;// note vec4 extra 1.0 sent through for ease
+ vec3 specular;
+ float shininess;
+};
+uniform material glFrontMaterial;
+
+struct lightSource
+{
+ int enabled;
+ vec4 position;
+ vec4 diffuse;
+ vec4 specular;
+ float constantAttenuation, linearAttenuation, quadraticAttenuation;
+ float spotCutoff, spotExponent;
+ vec3 spotDirection;
+};
+
+uniform int numberOfLights;
+const int maxLights = 1;
+uniform lightSource glLightSource[maxLights];
//GL2ES2: varying color data needs to be defined
varying vec4 glFrontColor;
@@ -76,17 +95,17 @@ void directionalLight0(
inout vec3 specular)
{
// Normalized light direction and half vector
- vec3 lightDirection = normalize(vec3(glLightSource0position));
+ vec3 lightDirection = normalize(vec3(glLightSource[0].position));
//GL2ES2: half vector must be calculated
//vec3 halfVector = normalize(vec3(gl_LightSource[0].halfVector));
//http://stackoverflow.com/questions/3744038/what-is-half-vector-in-modern-glsl
vec3 ecPos = vec3(glModelViewMatrix * glVertex);
vec3 ecL;
- if( glLightSource0position.w == 0.0)
- ecL = vec3(glLightSource0position.xyz);// no -ecPos in case of dir lights?
+ if( glLightSource[0].position.w == 0.0)
+ ecL = vec3(glLightSource[0].position.xyz);// no -ecPos in case of dir lights?
else
- ecL = vec3(glLightSource0position.xyz - ecPos);
+ ecL = vec3(glLightSource[0].position.xyz - ecPos);
vec3 L = normalize(ecL.xyz);
vec3 V = -ecPos.xyz;
vec3 halfVector = normalize(L + V);
@@ -102,12 +121,12 @@ void directionalLight0(
pf = 0.0;
}
else {
- pf = pow(nDotHV, glFrontMaterialshininess);
+ pf = pow(nDotHV, glFrontMaterial.shininess);
}
ambient += glLightModelambient;
- diffuse += glLightSource0diffuse * nDotVP;
- specular += glFrontMaterialspecular * pf;
+ diffuse += glLightSource[0].diffuse * nDotVP;
+ specular += glFrontMaterial.specular * pf;
}
@@ -125,13 +144,13 @@ void main()
directionalLight0(tnorm, amb, diff, spec);
//GL2ES2: sceneColor Derived. Ecm + Acm * Acs (Acs is normal glLightModelambient)
- vec4 sceneColor = glFrontMaterialemission + glFrontMaterialambient * glLightModelambient;
+ vec4 sceneColor = glFrontMaterial.emission + glFrontMaterial.ambient * glLightModelambient;
// Apply the result of the lighting equation
- vec4 outSecondaryColor = vec4(vec3(spec * glFrontMaterialspecular), 1.0);
+ vec4 outSecondaryColor = vec4(vec3(spec * glFrontMaterial.specular), 1.0);
vec4 outColor = vec4(vec3( sceneColor +
- amb * glFrontMaterialambient +
- diff * glFrontMaterialdiffuse), 1.0);
+ amb * glFrontMaterial.ambient +
+ diff * glFrontMaterial.diffuse), 1.0);
glFrontColor = outColor;
glFrontSecondaryColor = outSecondaryColor;
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag
index 230288a..7cb6388 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag
@@ -48,15 +48,35 @@
// GL2ES2: Java3D built-in uniforms, these are calculated and passsed in if declared here
uniform mat4 glModelViewMatrix;
-
-uniform vec4 glLightSource0position;
-uniform vec4 glLightSource0diffuse;
+
uniform vec4 glLightModelambient;
-uniform vec4 glFrontMaterialdiffuse;
-uniform float glFrontMaterialshininess;
-uniform vec3 glFrontMaterialspecular;
+struct material
+{
+ int lightEnabled;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 emission;
+ vec3 specular;
+ float shininess;
+};
+uniform material glFrontMaterial;
+
+struct lightSource
+{
+ int enabled;
+ vec4 position;
+ vec4 diffuse;
+ vec4 specular;
+ float constantAttenuation, linearAttenuation, quadraticAttenuation;
+ float spotCutoff, spotExponent;
+ vec3 spotDirection;
+};
+
+uniform int numberOfLights;
+const int maxLights = 1;
+uniform lightSource glLightSource[maxLights];
varying vec3 worldPos;
@@ -65,7 +85,7 @@ varying vec4 sceneColor;
void directionalLight0(in vec3 normal, inout vec4 ambient, inout vec4 diffuse, inout vec3 specular)
{
// Normalized light direction and half vector
- vec3 lightDirection = normalize(vec3(glLightSource0position));
+ vec3 lightDirection = normalize(vec3(glLightSource[0].position));
//GL2ES2: half vector must be calculated
@@ -73,10 +93,10 @@ void directionalLight0(in vec3 normal, inout vec4 ambient, inout vec4 diffuse,
//http://stackoverflow.com/questions/3744038/what-is-half-vector-in-modern-glsl
vec3 ecPos = vec3(glModelViewMatrix * vec4(worldPos,1.0));
vec3 ecL;
- if( glLightSource0position.w == 0.0)
- ecL = vec3(glLightSource0position.xyz);// no -ecPos in case of dir lights?
+ if( glLightSource[0].position.w == 0.0)
+ ecL = vec3(glLightSource[0].position.xyz);// no -ecPos in case of dir lights?
else
- ecL = vec3(glLightSource0position.xyz - ecPos);
+ ecL = vec3(glLightSource[0].position.xyz - ecPos);
vec3 L = normalize(ecL.xyz);
vec3 V = -ecPos.xyz;
vec3 halfVector = normalize(L + V);
@@ -93,17 +113,17 @@ void directionalLight0(in vec3 normal, inout vec4 ambient, inout vec4 diffuse,
pf = 0.0;
}
else {
- pf = pow(nDotHV, glFrontMaterialshininess);
+ pf = pow(nDotHV, glFrontMaterial.shininess);
}
// GL2ES2: ambient is part of light model
//ambient += gl_LightSource[0].ambient;
ambient += glLightModelambient;
- diffuse += glLightSource0diffuse * nDotVP;
+ diffuse += glLightSource[0].diffuse * nDotVP;
// GL2ES2: specular is part of material
//specular += gl_LightSource[0].specular * pf;
- specular += glFrontMaterialspecular * pf;
+ specular += glFrontMaterial.specular * pf;
}
@@ -123,12 +143,12 @@ void main()
// Apply the result of the lighting equation
- vec4 secondaryColor = vec4(spec * glFrontMaterialspecular, 1.0);
+ vec4 secondaryColor = vec4(spec * glFrontMaterial.specular, 1.0);
// GL2ES2: change to calc'ed sceneColor
//vec4 color = vec4(vec3(gl_FrontLightModelProduct.sceneColor +
vec4 color = vec4(vec3(sceneColor +
amb * glLightModelambient +
- diff * glFrontMaterialdiffuse), 1.0);
+ diff * glFrontMaterial.diffuse), 1.0);
gl_FragColor = color + secondaryColor;
}
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.vert b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.vert
index 6d3aeb2..780c2bd 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.vert
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/phong.vert
@@ -56,8 +56,16 @@ uniform mat3 glNormalMatrix;
uniform vec4 glLightModelambient;
-uniform vec4 glFrontMaterialambient;
-uniform vec4 glFrontMaterialemission;
+struct material
+{
+ int lightEnabled;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 emission;
+ vec3 specular;
+ float shininess;
+};
+uniform material glFrontMaterial;
// Per-pixel normal (output to fragment shader)
varying vec3 Normal;
@@ -70,7 +78,7 @@ void main()
{
//GL2ES2: sceneColor Derived. Ecm + Acm * Acs (Acs is normal glLightModelambient)
- sceneColor = glFrontMaterialemission + glFrontMaterialambient * glLightModelambient;
+ sceneColor = glFrontMaterial.emission + glFrontMaterial.ambient * glLightModelambient;
Normal = normalize(vec3(glNormalMatrix * glNormal));
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert
index 93a61bf..4c5f3c9 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert
@@ -55,16 +55,34 @@ uniform mat4 glModelViewMatrix;
uniform mat4 glModelViewProjectionMatrix;
uniform mat3 glNormalMatrix;
-uniform vec4 glFrontMaterialambient;
-uniform vec4 glFrontMaterialdiffuse;
-uniform vec4 glFrontMaterialemission;
-uniform vec3 glFrontMaterialspecular;
-uniform float glFrontMaterialshininess;
-
uniform vec4 glLightModelambient;
-uniform vec4 glLightSource0position;
-uniform vec4 glLightSource0diffuse;
+
+struct material
+{
+ int lightEnabled;
+ vec4 ambient;
+ vec4 diffuse;
+ vec4 emission;
+ vec3 specular;
+ float shininess;
+};
+uniform material glFrontMaterial;
+
+struct lightSource
+{
+ int enabled;
+ vec4 position;
+ vec4 diffuse;
+ vec4 specular;
+ float constantAttenuation, linearAttenuation, quadraticAttenuation;
+ float spotCutoff, spotExponent;
+ vec3 spotDirection;
+};
+
+uniform int numberOfLights;
+const int maxLights = 1;
+uniform lightSource glLightSource[maxLights];
//GL2ES2: varying color data needs to be defined
varying vec4 glFrontColor;
@@ -81,12 +99,12 @@ void directionalLight(
// (shouldn't they be pre-normalized?!)
//GL2ES2 notice not using the i parameter but hard coded to 0
- vec3 lightDirection = normalize(vec3(glLightSource0position));
+ vec3 lightDirection = normalize(vec3(glLightSource[0].position));
//GL2ES2: half vector must be calculated
//vec3 halfVector = normalize(vec3(gl_LightSource[0].halfVector));
vec3 worldPos = vec3(glModelViewMatrix * glVertex);
- vec3 L = normalize(glLightSource0position.xyz - worldPos);
+ vec3 L = normalize(glLightSource[0].position.xyz - worldPos);
vec3 V = vec3(0,0,1);//eye position
vec3 halfVector = (L + V);
@@ -103,12 +121,12 @@ void directionalLight(
pf = 0.0;
}
else {
- pf = pow(nDotHV, glFrontMaterialshininess);
+ pf = pow(nDotHV, glFrontMaterial.shininess);
}
ambient += glLightModelambient;
- diffuse += glLightSource0diffuse * nDotVP;
- specular += glFrontMaterialspecular * pf;
+ diffuse += glLightSource[0].diffuse * nDotVP;
+ specular += glFrontMaterial.specular * pf;
}
//GL2ES2: only a single light for now
@@ -136,13 +154,13 @@ void main()
}
//GL2ES2: sceneColor Derived. Ecm + Acm * Acs (Acs is normal glLightModelambient)
- vec4 sceneColor = glFrontMaterialemission + glFrontMaterialambient * glLightModelambient;
+ vec4 sceneColor = glFrontMaterial.emission + glFrontMaterial.ambient * glLightModelambient;
// Apply the result of the lighting equation
- vec4 outSecondaryColor = vec4(vec3(spec * glFrontMaterialspecular), 1.0);
+ vec4 outSecondaryColor = vec4(vec3(spec * glFrontMaterial.specular), 1.0);
vec3 color0 = vec3(sceneColor +
amb * glLightModelambient +
- diff * glFrontMaterialdiffuse);
+ diff * glFrontMaterial.diffuse);
// Generate a pseudo-random noise pattern
vec3 xyz = clamp((outPosition.xyz + 1.0) * 0.5, 0.0, 1.0);