summaryrefslogtreecommitdiffstats
path: root/src/GLSLShaderTest
diff options
context:
space:
mode:
authorjada <jada@28c7f869-5b4e-e670-f602-82bfaf57f300>2005-10-25 23:17:51 +0000
committerjada <jada@28c7f869-5b4e-e670-f602-82bfaf57f300>2005-10-25 23:17:51 +0000
commit514fe3f6240041c178ff9262d0b91e838fad1d3b (patch)
treeae8d882295043676419b6430f70b4641215a7d4f /src/GLSLShaderTest
parent4325f75ac43540221ba95d7ac925a1c9dc566152 (diff)
1) GLSLShaderTest :
Added new GLSL shader example program. No exit when exception is encountered. 2) PickTest : Update PickTest.java to use the new pickfast utility.
Diffstat (limited to 'src/GLSLShaderTest')
-rw-r--r--src/GLSLShaderTest/ObjLoadGLSL.java142
-rw-r--r--src/GLSLShaderTest/ShaderTestGLSL.form266
-rw-r--r--src/GLSLShaderTest/ShaderTestGLSL.java666
-rw-r--r--src/GLSLShaderTest/SphereGLSL.java6
-rw-r--r--src/GLSLShaderTest/aabrick.frag55
-rw-r--r--src/GLSLShaderTest/aabrick.vert42
-rw-r--r--src/GLSLShaderTest/dimple.frag20
-rw-r--r--src/GLSLShaderTest/dimple.vert9
8 files changed, 1115 insertions, 91 deletions
diff --git a/src/GLSLShaderTest/ObjLoadGLSL.java b/src/GLSLShaderTest/ObjLoadGLSL.java
index 12369cd..993aebf 100644
--- a/src/GLSLShaderTest/ObjLoadGLSL.java
+++ b/src/GLSLShaderTest/ObjLoadGLSL.java
@@ -96,22 +96,19 @@ public class ObjLoadGLSL extends Applet {
if (!noTriangulate) flags |= ObjectFile.TRIANGULATE;
if (!noStripify) flags |= ObjectFile.STRIPIFY;
ObjectFile f = new ObjectFile(flags,
- (float)(creaseAngle * Math.PI / 180.0));
+ (float)(creaseAngle * Math.PI / 180.0));
Scene s = null;
try {
- s = f.load(filename);
+ s = f.load(filename);
}
catch (FileNotFoundException e) {
- e.printStackTrace();
- System.exit(1);
+ throw new RuntimeException(e);
}
catch (ParsingErrorException e) {
- e.printStackTrace();
- System.exit(1);
+ throw new RuntimeException(e);
}
catch (IncorrectFormatException e) {
- e.printStackTrace();
- System.exit(1);
+ throw new RuntimeException(e);
}
// Set vertex and fragment shader program for all Shape3D nodes in scene
@@ -122,8 +119,7 @@ public class ObjLoadGLSL extends Applet {
fragmentProgram = StringIO.readFully(shaderName + ".frag");
}
catch (IOException e) {
- e.printStackTrace();
- System.exit(1);
+ throw new RuntimeException(e);
}
Shader[] shaders = new Shader[2];
shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL,
@@ -141,17 +137,17 @@ public class ObjLoadGLSL extends Applet {
bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
if (spin) {
- Transform3D yAxis = new Transform3D();
- Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE,
- 0, 0,
- 4000, 0, 0,
- 0, 0, 0);
-
- RotationInterpolator rotator =
- new RotationInterpolator(rotationAlpha, objTrans, yAxis,
- 0.0f, (float) Math.PI*2.0f);
- rotator.setSchedulingBounds(bounds);
- objTrans.addChild(rotator);
+ Transform3D yAxis = new Transform3D();
+ Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE,
+ 0, 0,
+ 4000, 0, 0,
+ 0, 0, 0);
+
+ RotationInterpolator rotator =
+ new RotationInterpolator(rotationAlpha, objTrans, yAxis,
+ 0.0f, (float) Math.PI*2.0f);
+ rotator.setSchedulingBounds(bounds);
+ objTrans.addChild(rotator);
}
// Set up the background
@@ -165,17 +161,17 @@ public class ObjLoadGLSL extends Applet {
private 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)");
- System.out.println(" -S Set shader name (default is 'simple')");
- System.out.println(" -n No triangulation");
- System.out.println(" -t No stripification");
- System.out.println(
- " -c Set crease angle for normal generation (default is 60 without");
- System.out.println(
- " smoothing group info, otherwise 180 within smoothing groups)");
- System.exit(0);
+ System.out.println(
+ "Usage: java ObjLoadGLSL [-s] [-S shaderName] [-n] [-t] [-c degrees] <.obj file>");
+ System.out.println(" -s Spin (no user interaction)");
+ System.out.println(" -S Set shader name (default is 'simple')");
+ System.out.println(" -n No triangulation");
+ System.out.println(" -t No stripification");
+ System.out.println(
+ " -c Set crease angle for normal generation (default is 60 without");
+ System.out.println(
+ " smoothing group info, otherwise 180 within smoothing groups)");
+ System.exit(0);
} // End of usage
@@ -188,14 +184,13 @@ public class ObjLoadGLSL extends Applet {
filename = new URL(path.toString() + "./galleon.obj");
}
catch (MalformedURLException e) {
- System.err.println(e);
- System.exit(1);
+ throw new RuntimeException(e);
}
}
setLayout(new BorderLayout());
GraphicsConfiguration config =
- SimpleUniverse.getPreferredConfiguration();
+ SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
add("Center", c);
@@ -282,46 +277,45 @@ public class ObjLoadGLSL extends Applet {
// Caled if running as a program
public ObjLoadGLSL(String[] args) {
- if (args.length != 0) {
- for (int i = 0 ; i < args.length ; i++) {
- if (args[i].startsWith("-")) {
- if (args[i].equals("-s")) {
- spin = true;
- } else if (args[i].equals("-n")) {
- noTriangulate = true;
- } else if (args[i].equals("-t")) {
- noStripify = true;
- } else if (args[i].equals("-c")) {
- if (i < args.length - 1) {
- creaseAngle = (new Double(args[++i])).doubleValue();
- } else usage();
- } else if (args[i].equals("-S")) {
- if (i < args.length - 1) {
- shaderName = args[++i];
- } else usage();
- } else {
- usage();
+ if (args.length != 0) {
+ for (int i = 0 ; i < args.length ; i++) {
+ if (args[i].startsWith("-")) {
+ if (args[i].equals("-s")) {
+ spin = true;
+ } else if (args[i].equals("-n")) {
+ noTriangulate = true;
+ } else if (args[i].equals("-t")) {
+ noStripify = true;
+ } else if (args[i].equals("-c")) {
+ if (i < args.length - 1) {
+ creaseAngle = (new Double(args[++i])).doubleValue();
+ } else usage();
+ } else if (args[i].equals("-S")) {
+ if (i < args.length - 1) {
+ shaderName = args[++i];
+ } else usage();
+ } else {
+ usage();
+ }
+ } else {
+ try {
+ if ((args[i].indexOf("file:") == 0) ||
+ (args[i].indexOf("http") == 0)) {
+ filename = new URL(args[i]);
+ }
+ else if (args[i].charAt(0) != '/') {
+ filename = new URL("file:./" + args[i]);
+ }
+ else {
+ filename = new URL("file:" + args[i]);
+ }
+ }
+ catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
- } else {
- try {
- if ((args[i].indexOf("file:") == 0) ||
- (args[i].indexOf("http") == 0)) {
- filename = new URL(args[i]);
- }
- else if (args[i].charAt(0) != '/') {
- filename = new URL("file:./" + args[i]);
- }
- else {
- filename = new URL("file:" + args[i]);
- }
- }
- catch (MalformedURLException e) {
- System.err.println(e);
- System.exit(1);
- }
- }
}
- }
}
@@ -341,6 +335,6 @@ public class ObjLoadGLSL extends Applet {
// as well as an applet
//
public static void main(String[] args) {
- new MainFrame(new ObjLoadGLSL(args), 700, 700);
+ new MainFrame(new ObjLoadGLSL(args), 700, 700);
}
}
diff --git a/src/GLSLShaderTest/ShaderTestGLSL.form b/src/GLSLShaderTest/ShaderTestGLSL.form
new file mode 100644
index 0000000..714273d
--- /dev/null
+++ b/src/GLSLShaderTest/ShaderTestGLSL.form
@@ -0,0 +1,266 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.2" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
+ <NonVisualComponents>
+ <Component class="javax.swing.ButtonGroup" name="densityButtonGroup">
+ </Component>
+ <Component class="javax.swing.ButtonGroup" name="colorButtonGroup">
+ </Component>
+ <Component class="javax.swing.ButtonGroup" name="sceneGraphButtonGroup">
+ </Component>
+ <Menu class="javax.swing.JMenuBar" name="jMenuBar1">
+ <SubComponents>
+ <Menu class="javax.swing.JMenu" name="fileMenu">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="File"/>
+ </Properties>
+ <SubComponents>
+ <MenuItem class="javax.swing.JMenuItem" name="exitMenuItem">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Exit"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="exitMenuItemActionPerformed"/>
+ </Events>
+ </MenuItem>
+ </SubComponents>
+ </Menu>
+ </SubComponents>
+ </Menu>
+ </NonVisualComponents>
+ <Properties>
+ <Property name="title" type="java.lang.String" value="Window Title"/>
+ </Properties>
+ <SyntheticProperties>
+ <SyntheticProperty name="menuBar" type="java.lang.String" value="jMenuBar1"/>
+ <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
+ </SyntheticProperties>
+ <Events>
+ <EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="exitForm"/>
+ </Events>
+ <AuxValues>
+ <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+ <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+ <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+ <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-85,0,0,2,0"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+ <SubComponents>
+ <Container class="javax.swing.JPanel" name="mainPanel">
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="Center"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+ <SubComponents>
+ <Container class="javax.swing.JPanel" name="guiPanel">
+ <Properties>
+ <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
+ <Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
+ <LineBorder/>
+ </Border>
+ </Property>
+ </Properties>
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="North"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
+ <SubComponents>
+ <Container class="javax.swing.JPanel" name="densityPanel">
+ <Properties>
+ <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
+ <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
+ <TitledBorder title="Density"/>
+ </Border>
+ </Property>
+ </Properties>
+ <AccessibilityProperties>
+ <Property name="AccessibleContext.accessibleName" type="java.lang.String" value="ShaderAttributeValue &#xa;"/>
+ </AccessibilityProperties>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JRadioButton" name="zeroButton">
+ <Properties>
+ <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
+ <ComponentRef name="densityButtonGroup"/>
+ </Property>
+ <Property name="text" type="java.lang.String" value="Zero"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="zeroButtonActionPerformed"/>
+ </Events>
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
+ <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
+ </Constraint>
+ </Constraints>
+ </Component>
+ <Component class="javax.swing.JRadioButton" name="halfButton">
+ <Properties>
+ <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
+ <ComponentRef name="densityButtonGroup"/>
+ </Property>
+ <Property name="text" type="java.lang.String" value="Half"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="halfButtonActionPerformed"/>
+ </Events>
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
+ <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
+ </Constraint>
+ </Constraints>
+ </Component>
+ <Component class="javax.swing.JRadioButton" name="fullButton">
+ <Properties>
+ <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
+ <ComponentRef name="densityButtonGroup"/>
+ </Property>
+ <Property name="selected" type="boolean" value="true"/>
+ <Property name="text" type="java.lang.String" value="Full"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="fullButtonActionPerformed"/>
+ </Events>
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
+ <GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
+ </Constraint>
+ </Constraints>
+ </Component>
+ </SubComponents>
+ </Container>
+ <Container class="javax.swing.JPanel" name="colorPanel">
+ <Properties>
+ <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
+ <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
+ <TitledBorder title="Color"/>
+ </Border>
+ </Property>
+ </Properties>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JRadioButton" name="goldButton">
+ <Properties>
+ <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
+ <ComponentRef name="colorButtonGroup"/>
+ </Property>
+ <Property name="selected" type="boolean" value="true"/>
+ <Property name="text" type="java.lang.String" value="Gold"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="goldButtonActionPerformed"/>
+ </Events>
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
+ <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
+ </Constraint>
+ </Constraints>
+ </Component>
+ <Component class="javax.swing.JRadioButton" name="silverButton">
+ <Properties>
+ <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
+ <ComponentRef name="colorButtonGroup"/>
+ </Property>
+ <Property name="text" type="java.lang.String" value="Silver"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="silverButtonActionPerformed"/>
+ </Events>
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
+ <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
+ </Constraint>
+ </Constraints>
+ </Component>
+ </SubComponents>
+ </Container>
+ <Container class="javax.swing.JPanel" name="sceneGraphPanel">
+ <Properties>
+ <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
+ <Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
+ <TitledBorder title="Scene Graph"/>
+ </Border>
+ </Property>
+ </Properties>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JToggleButton" name="DetachButton">
+ <Properties>
+ <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
+ <ComponentRef name="sceneGraphButtonGroup"/>
+ </Property>
+ <Property name="selected" type="boolean" value="true"/>
+ <Property name="text" type="java.lang.String" value="Detach"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="DetachButtonActionPerformed"/>
+ </Events>
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
+ <GridBagConstraints gridX="-1" gridY="-1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
+ </Constraint>
+ </Constraints>
+ </Component>
+ <Component class="javax.swing.JToggleButton" name="AttachButton">
+ <Properties>
+ <Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
+ <ComponentRef name="sceneGraphButtonGroup"/>
+ </Property>
+ <Property name="text" type="java.lang.String" value="Create"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="AttachButtonActionPerformed"/>
+ </Events>
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
+ <GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
+ </Constraint>
+ </Constraints>
+ </Component>
+ <Component class="javax.swing.JButton" name="replaceSPButton">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Replace Shader"/>
+ <Property name="enabled" type="boolean" value="false"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="replaceSPButtonActionPerformed"/>
+ </Events>
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
+ <GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
+ </Constraint>
+ </Constraints>
+ </Component>
+ </SubComponents>
+ </Container>
+ </SubComponents>
+ </Container>
+ <Container class="javax.swing.JPanel" name="drawingPanel">
+ <Properties>
+ <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
+ <Dimension value="[500, 500]"/>
+ </Property>
+ </Properties>
+ <Constraints>
+ <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription">
+ <BorderConstraints direction="Center"/>
+ </Constraint>
+ </Constraints>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
+ </Container>
+ </SubComponents>
+ </Container>
+ </SubComponents>
+</Form>
diff --git a/src/GLSLShaderTest/ShaderTestGLSL.java b/src/GLSLShaderTest/ShaderTestGLSL.java
new file mode 100644
index 0000000..b55650d
--- /dev/null
+++ b/src/GLSLShaderTest/ShaderTestGLSL.java
@@ -0,0 +1,666 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistribution of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - 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$
+ */
+
+import com.sun.j3d.utils.geometry.Sphere;
+import com.sun.j3d.utils.shader.StringIO;
+import com.sun.j3d.utils.universe.*;
+import javax.media.j3d.*;
+import javax.vecmath.*;
+import java.awt.GraphicsConfiguration;
+import java.io.IOException;
+
+public class ShaderTestGLSL extends javax.swing.JFrame {
+
+ static final int GOLD = 1;
+ static final int SILVER = 2;
+
+ static final int DIMPLE_SHADER = 1;
+ static final int BRICK_SHADER = 2;
+ static final int WOOD_SHADER = 3;
+ static final int POLKADOT3D_SHADER = 4;
+
+ static final String[] shaderAttrNames1 = {
+ "Density", "Size", "LightPosition", "Color"
+ };
+
+ static final String[] shaderAttrNames2 = {
+ "BrickColor", "LightPosition"
+ };
+
+ private SimpleUniverse u = null;
+ private View view;
+ private BranchGroup transpObj;
+ private BranchGroup scene = null;
+ private int shaderSelected = DIMPLE_SHADER;
+ private float density = 16.0f;
+ private int color = GOLD;
+
+ private Color3f eColor = new Color3f(0.2f, 0.2f, 0.2f);
+ private Color3f sColor = new Color3f(0.8f, 0.8f, 0.8f);
+ private Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f);
+ private Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
+ private Color3f gold = new Color3f(0.7f, 0.6f, 0.18f);
+ private Color3f silver = new Color3f(0.75f, 0.75f, 0.75f);
+
+ // Handlers for doing update
+ private ShaderAppearance sApp1 = null;
+ private ShaderAppearance sApp2 = null;
+ private ShaderAppearance sApp3 = null;
+ private ShaderAppearance sApp4 = null;
+ private ShaderProgram sp1 = null;
+ private ShaderProgram sp2 = null;
+ private ShaderProgram sp3 = null;
+ private ShaderProgram sp4 = null;
+ private ShaderAttributeSet sas1 = null;
+ private ShaderAttributeSet sas2 = null;
+ private ShaderAttributeObject sao1 = null;
+ private ShaderAttributeObject sao2 = null;
+ private Sphere sphere = null;
+ private Shape3D s3d = null;
+
+ private Material createMaterial() {
+ Material m;
+ m = new Material(objColor, eColor, objColor, sColor, 100.0f);
+ m.setLightingEnable(true);
+ return m;
+ }
+
+ private ShaderProgram createGLSLShaderProgram(int index) {
+ String vertexProgram = null;
+ String fragmentProgram = null;
+ try {
+ switch (index) {
+ case DIMPLE_SHADER:
+ vertexProgram = StringIO.readFully("./dimple.vert");
+ fragmentProgram = StringIO.readFully("./dimple.frag");
+ break;
+ case BRICK_SHADER:
+ vertexProgram = StringIO.readFully("./aabrick.vert");
+ fragmentProgram = StringIO.readFully("./aabrick.frag");
+ break;
+ case WOOD_SHADER:
+ vertexProgram = StringIO.readFully("./wood.vert");
+ fragmentProgram = StringIO.readFully("./wood.frag");
+ break;
+ case POLKADOT3D_SHADER:
+ vertexProgram = StringIO.readFully("./polkadot3d.vert");
+ fragmentProgram = StringIO.readFully("./polkadot3d.frag");
+ break;
+ default:
+ }
+ }
+ 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);
+ return shaderProgram;
+ }
+
+ private ShaderAttributeSet createShaderAttributeSet(int index) {
+ ShaderAttributeSet shaderAttributeSet = new ShaderAttributeSet();
+ ShaderAttributeObject shaderAttribute = null;
+
+ switch (index) {
+ case DIMPLE_SHADER:
+ // "Density", "Size", "Scale", "Color", "LightPosition"
+ shaderAttribute = new ShaderAttributeValue("Size", new Float(0.25));
+ shaderAttributeSet.put(shaderAttribute);
+ shaderAttribute = new ShaderAttributeValue("LightPosition",
+ new Point3f(0.0f, 0.0f, 0.5f));
+ shaderAttributeSet.put(shaderAttribute);
+
+ sao1 = new ShaderAttributeValue("Density", new Float(density));
+ sao1.setCapability(ShaderAttributeObject.ALLOW_VALUE_READ);
+ sao1.setCapability(ShaderAttributeObject.ALLOW_VALUE_WRITE);
+ shaderAttributeSet.put(sao1);
+
+ if(color == GOLD) {
+ sao2 = new ShaderAttributeValue("Color", gold);
+ }
+ else if (color == SILVER) {
+ sao2 = new ShaderAttributeValue("Color", silver);
+ }
+ sao2.setCapability(ShaderAttributeObject.ALLOW_VALUE_READ);
+ sao2.setCapability(ShaderAttributeObject.ALLOW_VALUE_WRITE);
+ shaderAttributeSet.put(sao2);
+ break;
+
+ case BRICK_SHADER:
+ // "BrickColor", "LightPosition"
+ shaderAttribute = new ShaderAttributeValue("BrickColor",
+ new Color3f(1.0f, 0.3f, 0.2f));
+ shaderAttributeSet.put(shaderAttribute);
+ shaderAttribute = new ShaderAttributeValue("LightPosition",
+ new Point3f(0.0f, 0.0f, 0.5f));
+ shaderAttributeSet.put(shaderAttribute);
+ break;
+ default:
+ assert false;
+ }
+ return shaderAttributeSet;
+ }
+
+ private ShaderAppearance createShaderAppearance() {
+ ShaderAppearance sApp = new ShaderAppearance();
+ sApp.setMaterial(createMaterial());
+ return sApp;
+ }
+
+
+ private BranchGroup createSubSceneGraph() {
+ // Create the sub-root of the branch graph
+ BranchGroup subRoot = new BranchGroup();
+
+ //
+ // Create 1 spheres with a GLSLShader and add it into the scene graph.
+ //
+ sApp1 = createShaderAppearance();
+ sApp1.setCapability(ShaderAppearance.ALLOW_SHADER_PROGRAM_READ);
+ sApp1.setCapability(ShaderAppearance.ALLOW_SHADER_PROGRAM_WRITE);
+ sApp1.setCapability(ShaderAppearance.ALLOW_SHADER_ATTRIBUTE_SET_READ);
+ sApp1.setCapability(ShaderAppearance.ALLOW_SHADER_ATTRIBUTE_SET_WRITE);
+
+ sp1 = createGLSLShaderProgram(1);
+ sp1.setShaderAttrNames(shaderAttrNames1);
+ sas1 = createShaderAttributeSet(1);
+ sas1.setCapability(ShaderAttributeSet.ALLOW_ATTRIBUTES_READ);
+ sas1.setCapability(ShaderAttributeSet.ALLOW_ATTRIBUTES_WRITE);
+ sApp1.setShaderProgram(sp1);
+ sApp1.setShaderAttributeSet(sas1);
+
+ // Setup Brick shader
+ sp2 = createGLSLShaderProgram(2);
+ sp2.setShaderAttrNames(shaderAttrNames2);
+ sas2 = createShaderAttributeSet(2);
+ sApp2 = createShaderAppearance();
+ sApp2.setShaderProgram(sp2);
+ sApp2.setShaderAttributeSet(sas2);
+
+ // Setup Wood shader
+ sp3 = createGLSLShaderProgram(3);
+ sApp3 = createShaderAppearance();
+ sApp3.setShaderProgram(sp3);
+
+ // Setup Polkadot3d shader
+ sp4 = createGLSLShaderProgram(4);
+ sApp4 = createShaderAppearance();
+ sApp4.setShaderProgram(sp4);
+
+ sphere = new Sphere(1.5f, Sphere.GENERATE_NORMALS, 200, null);
+ s3d = (Shape3D)sphere.getShape();
+ s3d.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
+ s3d.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
+ s3d.setAppearance(sApp1);
+
+ TransformGroup objTG;
+ Transform3D t = new Transform3D();
+ t.set(new Vector3d(0.0, 0.0, 0.0));
+ objTG = new TransformGroup(t);
+ objTG.addChild(sphere);
+ subRoot.addChild(objTG);
+
+ return subRoot;
+ }
+
+ private BranchGroup createSceneGraph(int selectedScene) {
+ // Create the root of the branch graph
+ BranchGroup objRoot = new BranchGroup();
+ objRoot.setCapability(BranchGroup.ALLOW_DETACH);
+
+ // Create a Transformgroup to scale all objects so they
+ // appear in the scene.
+ TransformGroup objScale = new TransformGroup();
+ Transform3D t3d = new Transform3D();
+ t3d.setScale(0.4);
+ objScale.setTransform(t3d);
+ objRoot.addChild(objScale);
+
+ // Create a bounds for the background and lights
+ BoundingSphere bounds =
+ new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
+
+ // Set up the background
+ Background bg = new Background(bgColor);
+ bg.setApplicationBounds(bounds);
+ objScale.addChild(bg);
+
+ objScale.addChild(createSubSceneGraph());
+
+ // Create a position interpolator and attach it to the view
+ // platform
+ TransformGroup vpTrans =
+ u.getViewingPlatform().getViewPlatformTransform();
+ Transform3D axisOfTranslation = new Transform3D();
+ Alpha transAlpha = new Alpha(-1,
+ Alpha.INCREASING_ENABLE |
+ Alpha.DECREASING_ENABLE,
+ 0, 0,
+ 5000, 0, 0,
+ 5000, 0, 0);
+ axisOfTranslation.rotY(-Math.PI/2.0);
+ PositionInterpolator translator =
+ new PositionInterpolator(transAlpha,
+ vpTrans,
+ axisOfTranslation,
+ 2.0f, 3.5f);
+ translator.setSchedulingBounds(bounds);
+ objScale.addChild(translator);
+
+ // Let Java 3D perform optimizations on this scene graph.
+ objRoot.compile();
+
+ return objRoot;
+ }
+
+ private Canvas3D initScene() {
+ GraphicsConfiguration config =
+ SimpleUniverse.getPreferredConfiguration();
+
+ Canvas3D c = new Canvas3D(config);
+
+ u = new SimpleUniverse(c);
+
+ ViewingPlatform viewingPlatform = u.getViewingPlatform();
+ // This will move the ViewPlatform back a bit so the
+ // objects in the scene can be viewed.
+ viewingPlatform.setNominalViewingTransform();
+
+ view = u.getViewer().getView();
+
+ return c;
+ }
+
+ /**
+ * Creates new form ShaderTestGLSL
+ */
+ public ShaderTestGLSL() {
+ // Initialize the GUI components
+ initComponents();
+
+ // Create the scene and add the Canvas3D to the drawing panel
+ Canvas3D c = initScene();
+ drawingPanel.add(c, java.awt.BorderLayout.CENTER);
+ }
+
+
+ // ----------------------------------------------------------------
+
+ /** This method is called from within the constructor to
+ * initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is
+ * always regenerated by the Form Editor.
+ */
+ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
+ private void initComponents() {
+ java.awt.GridBagConstraints gridBagConstraints;
+
+ densityButtonGroup = new javax.swing.ButtonGroup();
+ colorButtonGroup = new javax.swing.ButtonGroup();
+ sceneGraphButtonGroup = new javax.swing.ButtonGroup();
+ mainPanel = new javax.swing.JPanel();
+ guiPanel = new javax.swing.JPanel();
+ densityPanel = new javax.swing.JPanel();
+ zeroButton = new javax.swing.JRadioButton();
+ halfButton = new javax.swing.JRadioButton();
+ fullButton = new javax.swing.JRadioButton();
+ colorPanel = new javax.swing.JPanel();
+ goldButton = new javax.swing.JRadioButton();
+ silverButton = new javax.swing.JRadioButton();
+ sceneGraphPanel = new javax.swing.JPanel();
+ DetachButton = new javax.swing.JToggleButton();
+ AttachButton = new javax.swing.JToggleButton();
+ replaceSPButton = new javax.swing.JButton();
+ drawingPanel = new javax.swing.JPanel();
+ jMenuBar1 = new javax.swing.JMenuBar();
+ fileMenu = new javax.swing.JMenu();
+ exitMenuItem = new javax.swing.JMenuItem();
+
+ setTitle("Window Title");
+ addWindowListener(new java.awt.event.WindowAdapter() {
+ public void windowClosing(java.awt.event.WindowEvent evt) {
+ exitForm(evt);
+ }
+ });
+
+ mainPanel.setLayout(new java.awt.BorderLayout());
+
+ guiPanel.setLayout(new javax.swing.BoxLayout(guiPanel, javax.swing.BoxLayout.X_AXIS));
+
+ guiPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0)));
+ densityPanel.setLayout(new java.awt.GridBagLayout());
+
+ densityPanel.setBorder(new javax.swing.border.TitledBorder("Density"));
+ densityButtonGroup.add(zeroButton);
+ zeroButton.setText("Zero");
+ zeroButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ zeroButtonActionPerformed(evt);
+ }
+ });
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ densityPanel.add(zeroButton, gridBagConstraints);
+
+ densityButtonGroup.add(halfButton);
+ halfButton.setText("Half");
+ halfButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ halfButtonActionPerformed(evt);
+ }
+ });
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ densityPanel.add(halfButton, gridBagConstraints);
+
+ densityButtonGroup.add(fullButton);
+ fullButton.setSelected(true);
+ fullButton.setText("Full");
+ fullButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ fullButtonActionPerformed(evt);
+ }
+ });
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 2;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ densityPanel.add(fullButton, gridBagConstraints);
+
+ guiPanel.add(densityPanel);
+ densityPanel.getAccessibleContext().setAccessibleName("ShaderAttributeValue \n");
+
+ colorPanel.setLayout(new java.awt.GridBagLayout());
+
+ colorPanel.setBorder(new javax.swing.border.TitledBorder("Color"));
+ colorButtonGroup.add(goldButton);
+ goldButton.setSelected(true);
+ goldButton.setText("Gold");
+ goldButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ goldButtonActionPerformed(evt);
+ }
+ });
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ colorPanel.add(goldButton, gridBagConstraints);
+
+ colorButtonGroup.add(silverButton);
+ silverButton.setText("Silver");
+ silverButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ silverButtonActionPerformed(evt);
+ }
+ });
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ colorPanel.add(silverButton, gridBagConstraints);
+
+ guiPanel.add(colorPanel);
+
+ sceneGraphPanel.setLayout(new java.awt.GridBagLayout());
+
+ sceneGraphPanel.setBorder(new javax.swing.border.TitledBorder("Scene Graph"));
+ sceneGraphButtonGroup.add(DetachButton);
+ DetachButton.setSelected(true);
+ DetachButton.setText("Detach");
+ DetachButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ DetachButtonActionPerformed(evt);
+ }
+ });
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ sceneGraphPanel.add(DetachButton, gridBagConstraints);
+
+ sceneGraphButtonGroup.add(AttachButton);
+ AttachButton.setText("Create");
+ AttachButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ AttachButtonActionPerformed(evt);
+ }
+ });
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 1;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ sceneGraphPanel.add(AttachButton, gridBagConstraints);
+
+ replaceSPButton.setText("Replace Shader");
+ replaceSPButton.setEnabled(false);
+ replaceSPButton.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ replaceSPButtonActionPerformed(evt);
+ }
+ });
+
+ gridBagConstraints = new java.awt.GridBagConstraints();
+ gridBagConstraints.gridx = 0;
+ gridBagConstraints.gridy = 2;
+ gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
+ sceneGraphPanel.add(replaceSPButton, gridBagConstraints);
+
+ guiPanel.add(sceneGraphPanel);
+
+ mainPanel.add(guiPanel, java.awt.BorderLayout.NORTH);
+
+ drawingPanel.setLayout(new java.awt.BorderLayout());
+
+ drawingPanel.setPreferredSize(new java.awt.Dimension(500, 500));
+ mainPanel.add(drawingPanel, java.awt.BorderLayout.CENTER);
+
+ getContentPane().add(mainPanel, java.awt.BorderLayout.CENTER);
+
+ fileMenu.setText("File");
+ exitMenuItem.setText("Exit");
+ exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ exitMenuItemActionPerformed(evt);
+ }
+ });
+
+ fileMenu.add(exitMenuItem);
+
+ jMenuBar1.add(fileMenu);
+
+ setJMenuBar(jMenuBar1);
+
+ pack();
+ }
+ // </editor-fold>//GEN-END:initComponents
+
+ private void silverButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_silverButtonActionPerformed
+ color = SILVER;
+ if(scene != null) {
+ sao2.setValue(silver);
+ }
+ }//GEN-LAST:event_silverButtonActionPerformed
+
+ private void goldButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goldButtonActionPerformed
+ color = GOLD;
+ if(scene != null) {
+ sao2.setValue(gold);
+ }
+ }//GEN-LAST:event_goldButtonActionPerformed
+
+ private void replaceSPButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replaceSPButtonActionPerformed
+ if (shaderSelected != DIMPLE_SHADER) {
+ goldButton.setEnabled(false);
+ silverButton.setEnabled(false);
+ zeroButton.setEnabled(false);
+ halfButton.setEnabled(false);
+ fullButton.setEnabled(false);
+ }
+
+ switch(shaderSelected) {
+ case DIMPLE_SHADER:
+ s3d.setAppearance(sApp1);
+ goldButton.setEnabled(true);
+ silverButton.setEnabled(true);
+ zeroButton.setEnabled(true);
+ halfButton.setEnabled(true);
+ fullButton.setEnabled(true);
+ shaderSelected = BRICK_SHADER;
+ break;
+ case BRICK_SHADER:
+ s3d.setAppearance(sApp2);
+ shaderSelected = WOOD_SHADER;
+ break;
+ case WOOD_SHADER:
+ s3d.setAppearance(sApp3);
+ shaderSelected = POLKADOT3D_SHADER;
+ break;
+ case POLKADOT3D_SHADER:
+ s3d.setAppearance(sApp4);
+ shaderSelected = DIMPLE_SHADER;
+ break;
+ default:
+ assert false;
+ }
+
+ }//GEN-LAST:event_replaceSPButtonActionPerformed
+
+ private void fullButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fullButtonActionPerformed
+ density = 16.0f;
+ if (scene != null) {
+ sao1.setValue(new Float(density));
+ }
+ }//GEN-LAST:event_fullButtonActionPerformed
+
+ private void DetachButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DetachButtonActionPerformed
+ if (scene != null) {
+ scene.detach();
+ scene = null;
+ replaceSPButton.setEnabled(false);
+ goldButton.setEnabled(true);
+ silverButton.setEnabled(true);
+ zeroButton.setEnabled(true);
+ halfButton.setEnabled(true);
+ fullButton.setEnabled(true);
+ shaderSelected = DIMPLE_SHADER;
+ }
+ }//GEN-LAST:event_DetachButtonActionPerformed
+
+ private void AttachButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AttachButtonActionPerformed
+ if (scene == null) {
+ scene = createSceneGraph(1);
+ u.addBranchGraph(scene);
+ replaceSPButton.setEnabled(true);
+ shaderSelected = BRICK_SHADER;
+ }
+ }//GEN-LAST:event_AttachButtonActionPerformed
+
+ private void halfButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_halfButtonActionPerformed
+ density = 8.0f;
+ if(scene != null) {
+ sao1.setValue(new Float(density));
+ }
+ }//GEN-LAST:event_halfButtonActionPerformed
+
+ private void zeroButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zeroButtonActionPerformed
+ density = 0.0f;
+ if(scene != null) {
+ sao1.setValue(new Float(density));
+ }
+
+ }//GEN-LAST:event_zeroButtonActionPerformed
+
+ private 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) {//GEN-FIRST:event_exitForm
+ System.exit(0);
+ }//GEN-LAST:event_exitForm
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String args[]) {
+ new ShaderTestGLSL().setVisible(true);
+ }
+
+ // Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JToggleButton AttachButton;
+ private javax.swing.JToggleButton DetachButton;
+ private javax.swing.ButtonGroup colorButtonGroup;
+ private javax.swing.JPanel colorPanel;
+ private javax.swing.ButtonGroup densityButtonGroup;
+ private javax.swing.JPanel densityPanel;
+ private javax.swing.JPanel drawingPanel;
+ private javax.swing.JMenuItem exitMenuItem;
+ private javax.swing.JMenu fileMenu;
+ private javax.swing.JRadioButton fullButton;
+ private javax.swing.JRadioButton goldButton;
+ private javax.swing.JPanel guiPanel;
+ private javax.swing.JRadioButton halfButton;
+ private javax.swing.JMenuBar jMenuBar1;
+ private javax.swing.JPanel mainPanel;
+ private javax.swing.JButton replaceSPButton;
+ private javax.swing.ButtonGroup sceneGraphButtonGroup;
+ private javax.swing.JPanel sceneGraphPanel;
+ private javax.swing.JRadioButton silverButton;
+ private javax.swing.JRadioButton zeroButton;
+ // End of variables declaration//GEN-END:variables
+
+}
diff --git a/src/GLSLShaderTest/SphereGLSL.java b/src/GLSLShaderTest/SphereGLSL.java
index 87d589e..a96dca6 100644
--- a/src/GLSLShaderTest/SphereGLSL.java
+++ b/src/GLSLShaderTest/SphereGLSL.java
@@ -114,11 +114,7 @@ public class SphereGLSL extends Applet {
fragmentProgram = StringIO.readFully("./simple.frag");
}
catch (IOException e) {
- /*
- e.printStackTrace();
- System.exit(1);
- */
- System.err.println(e);
+ throw new RuntimeException(e);
}
Shader[] shaders = new Shader[2];
shaders[0] = new SourceCodeShader(Shader.SHADING_LANGUAGE_GLSL,
diff --git a/src/GLSLShaderTest/aabrick.frag b/src/GLSLShaderTest/aabrick.frag
new file mode 100644
index 0000000..7c9aab8
--- /dev/null
+++ b/src/GLSLShaderTest/aabrick.frag
@@ -0,0 +1,55 @@
+//
+// Fragment shader for antialiased procedural bricks
+//
+// Authors: Dave Baldwin, Randi Rost
+// based on a shader by Darwyn Peachey
+//
+// Copyright (c) 2002-2004 3Dlabs Inc. Ltd.
+//
+// See 3Dlabs-License.txt for license information
+//
+
+uniform vec3 BrickColor;
+//uniform vec3 MortarColor;
+//uniform vec2 BrickSize;
+//uniform vec2 BrickPct;
+//uniform vec2 MortarPct;
+
+//const vec3 BrickColor = vec3 (1, 0.3, 0.2);
+const vec3 MortarColor = vec3 (0.85, 0.86, 0.84);
+const vec2 BrickSize = vec2 (0.3, 0.15);
+const vec2 BrickPct = vec2 (0.9, 0.85);
+const vec2 MortarPct = vec2 (0.1, 0.15);
+
+varying vec2 MCposition;
+varying float LightIntensity;
+
+#define Integral(x, p, notp) ((floor(x)*(p)) + max(fract(x)-(notp), 0.0))
+
+void main(void)
+{
+ vec2 position, fw, useBrick;
+ vec3 color;
+
+ // Determine position within the brick pattern
+ position = MCposition / BrickSize;
+
+ // Adjust every other row by an offset of half a brick
+ if (fract(position.y * 0.5) > 0.5)
+ position.x += 0.5;
+
+ // Calculate filter size
+ //fw = fwidth(position); //fwidth not implemented on WildcatVP
+ fw = (abs(dFdx(MCposition)) + abs(dFdy(MCposition))) / BrickSize;
+
+ // Perform filtering by integrating the 2D pulse made by the
+ // brick pattern over the filter width and height
+ useBrick = (Integral(position + fw, BrickPct, MortarPct) -
+ Integral(position, BrickPct, MortarPct)) / fw;
+
+ // Determine final color
+ color = mix(MortarColor, BrickColor, useBrick.x * useBrick.y);
+ color *= LightIntensity;
+
+ gl_FragColor = vec4 (color, 1.0);
+}
diff --git a/src/GLSLShaderTest/aabrick.vert b/src/GLSLShaderTest/aabrick.vert
new file mode 100644
index 0000000..226dbe4
--- /dev/null
+++ b/src/GLSLShaderTest/aabrick.vert
@@ -0,0 +1,42 @@
+//
+// Vertex shader for antialiased procedural bricks
+//
+// Authors: Dave Baldwin, Steve Koren, Randi Rost
+// based on a shader by Darwyn Peachey
+//
+// Copyright (c) 2002-2004 3Dlabs Inc. Ltd.
+//
+// See 3Dlabs-License.txt for license information
+//
+
+uniform vec3 LightPosition;
+//const vec3 LightPosition = vec3 (0, 4, 4);
+
+const float SpecularContribution = 0.3;
+const float DiffuseContribution = 1.0 - SpecularContribution;
+
+varying float LightIntensity;
+varying vec2 MCposition;
+
+void main(void)
+{
+ vec3 ecPosition = vec3 (gl_ModelViewMatrix * gl_Vertex);
+ vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);
+ vec3 lightVec = normalize(LightPosition - ecPosition);
+ vec3 reflectVec = reflect(-lightVec, tnorm);
+ vec3 viewVec = normalize(-ecPosition);
+ float diffuse = max(dot(lightVec, tnorm), 0.0);
+ float spec = 0.0;
+
+ if (diffuse > 0.0)
+ {
+ spec = max(dot(reflectVec, viewVec), 0.0);
+ spec = pow(spec, 16.0);
+ }
+
+ LightIntensity = DiffuseContribution * diffuse +
+ SpecularContribution * spec;
+
+ MCposition = gl_Vertex.xy;
+ gl_Position = ftransform();
+}
diff --git a/src/GLSLShaderTest/dimple.frag b/src/GLSLShaderTest/dimple.frag
index 70d2982..282add7 100644
--- a/src/GLSLShaderTest/dimple.frag
+++ b/src/GLSLShaderTest/dimple.frag
@@ -11,20 +11,23 @@ varying vec3 LightDir;
varying vec3 EyeDir;
varying vec3 Normal;
-const vec3 color = vec3(0.7, 0.6, 0.18);
+//const vec3 Color = vec3(0.7, 0.6, 0.18);
//const float Density = 16.0;
//const float Size = 0.25;
-//uniform float Density;
-//uniform float Size;
-float Density = 27.6;
-float Size = 0.13025;
+uniform vec3 Color;
+uniform float Density;
+uniform float Size;
+// uniform float SpecularFactor;
+
+//float Density = 27.6;
+//float Size = 0.13025;
//uniform float Scale;
-const float SpecularFactor = 0.5;
+const float SpecularFactor = 0.4;
void main (void)
{
@@ -38,7 +41,7 @@ void main (void)
vec3 normDelta = vec3(-p.x, -p.y, 1.0);
- litColor = color * max(0.0, dot(normDelta, LightDir));
+ litColor = Color * max(0.0, dot(normDelta, LightDir));
float t = 2.0 * dot(LightDir, normDelta);
vec3 reflectDir = t * normDelta;
@@ -52,6 +55,7 @@ void main (void)
spec *= SpecularFactor;
litColor = min(litColor + spec, vec3(1.0));
- gl_FragColor = vec4(litColor, 1.0);
+ gl_FragColor = vec4(litColor, gl_Color.a);
+// gl_FragColor = vec4(litColor, 1.0);
// gl_FragColor = vec4(Scale);
}
diff --git a/src/GLSLShaderTest/dimple.vert b/src/GLSLShaderTest/dimple.vert
index 0707d71..e45796b 100644
--- a/src/GLSLShaderTest/dimple.vert
+++ b/src/GLSLShaderTest/dimple.vert
@@ -11,9 +11,9 @@ varying vec3 LightDir;
varying vec3 EyeDir;
varying vec3 Normal;
-//uniform vec3 LightPosition;
-//uniform float Scale;
-vec3 LightPosition = vec3(0.0, 0.0, 5.0);
+uniform vec3 LightPosition;
+// uniform float Scale;
+// vec3 LightPosition = vec3(0.0, 0.0, 5.0);
float Scale = 1.0;
void main(void)
@@ -23,7 +23,8 @@ void main(void)
vec3 eyeDir = vec3(pos);
// gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[0] = gl_Vertex;
-
+ gl_FrontColor = gl_Color;
+
vec3 n = normalize(gl_NormalMatrix * gl_Normal);
vec3 t = normalize(cross(vec3(1.141, 2.78, 3.14), n));
vec3 b = cross(n, t);