You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
(116) |
May
(220) |
Jun
(52) |
Jul
(30) |
Aug
(35) |
Sep
(24) |
Oct
(49) |
Nov
(44) |
Dec
(70) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(21) |
Feb
(30) |
Mar
(9) |
Apr
(44) |
May
(2) |
Jun
|
Jul
(10) |
Aug
(20) |
Sep
(25) |
Oct
(12) |
Nov
(16) |
Dec
(4) |
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(4) |
Jul
(25) |
Aug
|
Sep
|
Oct
|
Nov
(26) |
Dec
(10) |
2006 |
Jan
(5) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(33) |
2007 |
Jan
(4) |
Feb
(57) |
Mar
(17) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Gerardo H. <ma...@us...> - 2004-09-16 04:16:51
|
Update of /cvsroot/jrman/drafts/src/org/jrman/render In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29936/src/org/jrman/render Modified Files: RendererHidden.java Log Message: Some memory optimizations. Index: RendererHidden.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/render/RendererHidden.java,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** RendererHidden.java 12 Sep 2004 00:10:48 -0000 1.64 --- RendererHidden.java 16 Sep 2004 04:16:42 -0000 1.65 *************** *** 505,508 **** --- 505,509 ---- "World parse time: " + Format.time(worldParseEnd - worldParseStart)); display("spheres", parser.getSphereCount()); + display("cylinders", parser.getCylinderCount()); display("toruses", parser.getTorusCount()); display("cones", parser.getConeCount()); |
From: Gerardo H. <ma...@us...> - 2004-09-12 23:27:07
|
Update of /cvsroot/jrman/drafts/sampleData In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3282/sampleData Modified Files: cubeScene.rib unit.rib Log Message: Updated rib files for scene with thousands of bikes. Index: cubeScene.rib =================================================================== RCS file: /cvsroot/jrman/drafts/sampleData/cubeScene.rib,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** cubeScene.rib 25 Nov 2003 06:00:50 -0000 1.6 --- cubeScene.rib 12 Sep 2004 23:26:57 -0000 1.7 *************** *** 1,7 **** ! Format 800 600 1 PixelSamples 4 4 Exposure 1 2.2 ! Display "cubeScene.tif" "framebuffer" "rgba" ! PixelFilter "box" 1 1 Projection "perspective" "fov" 50 ShadingRate 1 --- 1,7 ---- ! Format 4000 3000 1 PixelSamples 4 4 Exposure 1 2.2 ! Display "cubeScene.tif" "framebuffer" "rgb" ! PixelFilter "sinc" 2 2 Projection "perspective" "fov" 50 ShadingRate 1 *************** *** 10,13 **** --- 10,17 ---- Rotate 20 0 0 1 Rotate -30 1 0 0 + LightSource "ambientlight" 1 "intensity" [0.3 ] + LightSource "distantlight" 2 "intensity" [1 ] "lightcolor" [1 1 1] "from" [0 100 -200] "to" [0 0 0] + LightSource "distantlight" 3 "intensity" [0.6 ] "lightcolor" [0.4 0.5 0.4] "from" [200 10 0] "to" [0 0 0] + LightSource "distantlight" 4 "intensity" [1 ] "lightcolor" [1 1 1] "from" [-50 10 200] "to" [0 0 0] WorldBegin # red Index: unit.rib =================================================================== RCS file: /cvsroot/jrman/drafts/sampleData/unit.rib,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** unit.rib 12 Sep 2004 00:10:47 -0000 1.6 --- unit.rib 12 Sep 2004 23:26:57 -0000 1.7 *************** *** 1,5 **** AttributeBegin ! Scale .06 .06 .06 ! Procedural "DelayedReadArchive" ["bikeData.rib"] [-.5 .5 -.5 .5 -.5 .5] AttributeEnd #ObjectInstance 1 --- 1,6 ---- AttributeBegin ! Rotate 90 0 1 0 ! Scale .05 .05 .05 ! Procedural "DelayedReadArchive" ["bikeData.rib"] [-8 8 -8 8 -8 8] AttributeEnd #ObjectInstance 1 |
From: Gerardo H. <ma...@us...> - 2004-09-12 00:11:00
|
Update of /cvsroot/jrman/drafts/src/org/jrman/render In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31994/src/org/jrman/render Modified Files: RendererHidden.java Log Message: Implemented DelayedReadArchive. Index: RendererHidden.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/render/RendererHidden.java,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** RendererHidden.java 11 Sep 2004 17:36:27 -0000 1.63 --- RendererHidden.java 12 Sep 2004 00:10:48 -0000 1.64 *************** *** 108,111 **** --- 108,115 ---- private Transform oldObjectToCamera; + + private int row; + + private int column; public void init(Frame frame, World world, Parser parser) { *************** *** 126,130 **** public void addPrimitive(Primitive primitive) { ! internalAddPrimitive(primitive, 0, 0, false); } --- 130,134 ---- public void addPrimitive(Primitive primitive) { ! internalAddPrimitive(primitive, column, row, false); } *************** *** 320,325 **** Point2f rmin = rasterWindow.getMin(); int percentComplete = -1; ! for (int row = 0; row < bucketRows; row++) { ! for (int column = 0; column < bucketColumns; column++) { Bucket bucket = getBucket(column, row); bucket.sortPrimitives(); --- 324,329 ---- Point2f rmin = rasterWindow.getMin(); int percentComplete = -1; ! for (row = 0; row < bucketRows; row++) { ! for (column = 0; column < bucketColumns; column++) { Bucket bucket = getBucket(column, row); bucket.sortPrimitives(); |
From: Gerardo H. <ma...@us...> - 2004-09-12 00:11:00
|
Update of /cvsroot/jrman/drafts/src/org/jrman/primitive In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31994/src/org/jrman/primitive Added Files: DelayedReadArchive.java Log Message: Implemented DelayedReadArchive. --- NEW FILE: DelayedReadArchive.java --- /* DelayedReadArchive.java Copyright (C) 2004 Gerardo Horvilleur Martinez This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.jrman.primitive; import org.jrman.attributes.Attributes; import org.jrman.geom.BoundingVolume; import org.jrman.geom.Bounds3f; import org.jrman.parser.Parser; public class DelayedReadArchive extends Primitive { private final static Primitive[] emptyPrimitivesArray = new Primitive[0]; private Parser parser; private String filename; private Bounds3f boundingBox; public DelayedReadArchive(Parser parser, String filename, float xMin, float xMax, float yMin, float yMax, float zMin, float zMax, Attributes attributes) { super(null, attributes); this.parser = parser; this.filename = filename; boundingBox = new Bounds3f(xMin, xMax, yMin, yMax, zMin, zMax); } public BoundingVolume getBoundingVolume() { return boundingBox; } public Primitive[] split() { parser.pushAttributes(attributes); try { parser.parse(filename); } catch (Exception e) { System.out.println("Couldn't parse " + filename); e.printStackTrace(); } parser.popAttributes(); return emptyPrimitivesArray; } public boolean isReadyToBeDiced(int gridSize) { return false; } } |
From: Gerardo H. <ma...@us...> - 2004-09-12 00:11:00
|
Update of /cvsroot/jrman/drafts/src/org/jrman/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31994/src/org/jrman/parser Modified Files: Parser.java Log Message: Implemented DelayedReadArchive. Index: Parser.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/parser/Parser.java,v retrieving revision 1.95 retrieving revision 1.96 diff -C2 -d -r1.95 -r1.96 *** Parser.java 11 Sep 2004 18:10:01 -0000 1.95 --- Parser.java 12 Sep 2004 00:10:48 -0000 1.96 *************** *** 81,84 **** --- 81,85 ---- import org.jrman.primitive.Cone; import org.jrman.primitive.Cylinder; + import org.jrman.primitive.DelayedReadArchive; import org.jrman.primitive.Disk; import org.jrman.primitive.Hyperboloid; *************** *** 286,291 **** attributeStack.push(new MutableAttributes(currentAttributes)); } ! private void popAttributes() { currentAttributes = (MutableAttributes) attributeStack.pop(); currentAttributes.setModified(true); --- 287,298 ---- attributeStack.push(new MutableAttributes(currentAttributes)); } + + public void pushAttributes(Attributes attributes) { + attributeStack.push(new MutableAttributes(currentAttributes)); + currentAttributes = new MutableAttributes(attributes); + currentAttributes.setModified(true); + } ! public void popAttributes() { currentAttributes = (MutableAttributes) attributeStack.pop(); currentAttributes.setModified(true); *************** *** 1471,1474 **** --- 1478,1487 ---- } + public void addDelayedReadArchive(String filename, float xmin, float xmax, + float ymin, float ymax, float zmin, float zmax) { + renderer.addPrimitive(new DelayedReadArchive(this, filename, xmin, xmax, + ymin, ymax, zmin, zmax, getAttributes())); + } + public void makeTexture( String picturename, *************** *** 1540,1542 **** --- 1553,1556 ---- return torusCount; } + } |
From: Gerardo H. <ma...@us...> - 2004-09-12 00:11:00
|
Update of /cvsroot/jrman/drafts/src/org/jrman/parser/keywords In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31994/src/org/jrman/parser/keywords Modified Files: AbstractKeywordParser.java KeywordProcedural.java Log Message: Implemented DelayedReadArchive. Index: KeywordProcedural.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/parser/keywords/KeywordProcedural.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** KeywordProcedural.java 7 Apr 2003 08:24:25 -0000 1.2 --- KeywordProcedural.java 12 Sep 2004 00:10:47 -0000 1.3 *************** *** 27,36 **** // Expect procname match(st, TK_STRING); ! // Expect args parseArray(st); ! // Expect bounds parseArray(st); } --- 27,55 ---- // Expect procname match(st, TK_STRING); ! String s = st.sval; ! // Expect args parseArray(st); ! String[] args = new String[arraySize]; ! System.arraycopy(strings, 0, args, 0, arraySize); ! // Expect bounds parseArray(st); + if (arraySize != 6) + throw new Exception("Invalid number of arguments for bounding box: " + + arraySize); + float xmin = numbers[0]; + float xmax = numbers[1]; + float ymin = numbers[2]; + float ymax = numbers[3]; + float zmin = numbers[4]; + float zmax = numbers[5]; + if (s.equals("DelayedReadArchive")) { + if (args.length != 1) + throw new Exception("Invalid number of arguments for DelayedReadArchive: " + + args.length); + parser.addDelayedReadArchive(args[0], xmin, xmax, ymin, ymax, zmin, zmax); + } else + throw new Exception("Unknown procedural: " + s); } Index: AbstractKeywordParser.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/parser/keywords/AbstractKeywordParser.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** AbstractKeywordParser.java 29 Mar 2004 16:47:30 -0000 1.10 --- AbstractKeywordParser.java 12 Sep 2004 00:10:47 -0000 1.11 *************** *** 57,61 **** protected static int[] integers = new int[5000]; ! private static String[] strings = new String[10]; protected static int arraySize; --- 57,61 ---- protected static int[] integers = new int[5000]; ! protected static String[] strings = new String[10]; protected static int arraySize; |
From: Gerardo H. <ma...@us...> - 2004-09-12 00:11:00
|
Update of /cvsroot/jrman/drafts/sampleData In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31994/sampleData Modified Files: unit.rib Log Message: Implemented DelayedReadArchive. Index: unit.rib =================================================================== RCS file: /cvsroot/jrman/drafts/sampleData/unit.rib,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** unit.rib 22 May 2003 22:17:43 -0000 1.5 --- unit.rib 12 Sep 2004 00:10:47 -0000 1.6 *************** *** 1,2 **** ! ReadArchive "torusSphereUnit.rib" #ObjectInstance 1 --- 1,5 ---- ! AttributeBegin ! Scale .06 .06 .06 ! Procedural "DelayedReadArchive" ["bikeData.rib"] [-.5 .5 -.5 .5 -.5 .5] ! AttributeEnd #ObjectInstance 1 |
From: Gerardo H. <ma...@us...> - 2004-09-11 18:10:10
|
Update of /cvsroot/jrman/drafts/src/org/jrman/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31395/src/org/jrman/parser Modified Files: Parser.java Log Message: Misc imrpovements for using jrManGui in Mac OS X: - enabled aqua look & feel - fixed extra space empty argument - enabled ReadArchive from same directory as main rib file Index: Parser.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/parser/Parser.java,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** Parser.java 11 Sep 2004 17:36:28 -0000 1.94 --- Parser.java 11 Sep 2004 18:10:01 -0000 1.95 *************** *** 20,28 **** --- 20,32 ---- import java.io.BufferedReader; + import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.StreamTokenizer; + import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; + import java.util.Iterator; + import java.util.List; import java.util.Map; import java.util.Set; *************** *** 33,36 **** --- 37,41 ---- import javax.vecmath.Matrix4f; import javax.vecmath.Point3f; + import javax.vecmath.Point4f; import javax.vecmath.Vector3f; *************** *** 68,71 **** --- 73,77 ---- import org.jrman.parameters.VaryingArrayFloat; import org.jrman.parameters.VaryingScalarFloat; + import org.jrman.parameters.VaryingScalarHPoint; import org.jrman.parameters.VaryingScalarTuple3f; import org.jrman.parser.keywords.AbstractKeywordParser; *************** *** 92,106 **** import org.jrman.util.Constants; - import org.jrman.parameters.VaryingScalarHPoint; - - import javax.vecmath.Point4f; - - import java.util.List; - import java.util.ArrayList; - import java.util.Iterator; - public class Parser { private final static String KEYWORD_PREFIX = "org.jrman.parser.keywords.Keyword"; private boolean inAreaLightSource; --- 98,106 ---- import org.jrman.util.Constants; public class Parser { private final static String KEYWORD_PREFIX = "org.jrman.parser.keywords.Keyword"; + + private String currentDirectory; private boolean inAreaLightSource; *************** *** 200,205 **** --- 200,211 ---- } } + + public void setCurrentDirectory(String currentDirectory) { + this.currentDirectory = currentDirectory; + } public void parse(String filename) throws Exception { + if (currentDirectory != null) + filename = currentDirectory + File.separator + filename; FileReader fr = new FileReader(filename); Tokenizer st = new Tokenizer(new BufferedReader(fr)); |
From: Gerardo H. <ma...@us...> - 2004-09-11 18:10:09
|
Update of /cvsroot/jrman/drafts/src/org/jrman/ui In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31395/src/org/jrman/ui Modified Files: RenderRunnable.java Log Message: Misc imrpovements for using jrManGui in Mac OS X: - enabled aqua look & feel - fixed extra space empty argument - enabled ReadArchive from same directory as main rib file Index: RenderRunnable.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/ui/RenderRunnable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RenderRunnable.java 11 Feb 2004 16:16:51 -0000 1.1 --- RenderRunnable.java 11 Sep 2004 18:10:00 -0000 1.2 *************** *** 44,51 **** sb.append(optionsString).append(' ').append(fileName); // launch renderer passing the arguments ! /*TODO see if there's a way to change at this point the current directory ! * of the JVM to the parent directory of the current filename ! */ ! String[] tmp=sb.toString().split("\\s+"); JRMan.main(tmp); // signal file rendering completion and check for cancellation --- 44,48 ---- sb.append(optionsString).append(' ').append(fileName); // launch renderer passing the arguments ! String[] tmp=sb.toString().trim().split("\\s+"); JRMan.main(tmp); // signal file rendering completion and check for cancellation |
From: Gerardo H. <ma...@us...> - 2004-09-11 18:10:09
|
Update of /cvsroot/jrman/drafts/src/org/jrman/main In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31395/src/org/jrman/main Modified Files: JrManGUI.java JRMan.java Log Message: Misc imrpovements for using jrManGui in Mac OS X: - enabled aqua look & feel - fixed extra space empty argument - enabled ReadArchive from same directory as main rib file Index: JrManGUI.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/main/JrManGUI.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JrManGUI.java 11 Feb 2004 16:16:51 -0000 1.1 --- JrManGUI.java 11 Sep 2004 18:10:00 -0000 1.2 *************** *** 7,17 **** import java.awt.Frame; - import javax.swing.UIManager; - import javax.swing.UnsupportedLookAndFeelException; - import org.jrman.ui.MainFrame; - import com.jgoodies.plaf.plastic.Plastic3DLookAndFeel; - /** * The entry point for the basic GUI for jrMan --- 7,12 ---- *************** *** 33,36 **** --- 28,33 ---- */ public static void main(String[] args) { + // Removed Plastic3D look & feel to enable Aqua look & feel on Mac OS X + /* try { UIManager.setLookAndFeel(new Plastic3DLookAndFeel()); *************** *** 39,42 **** --- 36,40 ---- e.printStackTrace(); } + */ MainFrame gui= new MainFrame(); centerOnScreen(gui); Index: JRMan.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/main/JRMan.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** JRMan.java 11 Feb 2004 16:16:51 -0000 1.8 --- JRMan.java 11 Sep 2004 18:10:00 -0000 1.9 *************** *** 19,26 **** package org.jrman.main; import java.io.IOException; import java.util.Iterator; ! import org.apache.commons.cli.*; import org.jrman.parser.Parser; import org.jrman.util.Format; --- 19,32 ---- package org.jrman.main; + import java.io.File; import java.io.IOException; import java.util.Iterator; ! import org.apache.commons.cli.BasicParser; ! import org.apache.commons.cli.CommandLine; ! import org.apache.commons.cli.HelpFormatter; ! import org.apache.commons.cli.OptionBuilder; ! import org.apache.commons.cli.Options; ! import org.apache.commons.cli.ParseException; import org.jrman.parser.Parser; import org.jrman.util.Format; *************** *** 61,69 **** while (it.hasNext()) try { ! String filename= (String)it.next(); long start= System.currentTimeMillis(); Parser parser= new Parser(cmdLine); parser.begin(filename); ! parser.parse(filename); parser.end(); long end= System.currentTimeMillis(); --- 67,77 ---- while (it.hasNext()) try { ! String filename= (String) it.next(); long start= System.currentTimeMillis(); Parser parser= new Parser(cmdLine); parser.begin(filename); ! File file = new File(filename); ! parser.setCurrentDirectory(file.getParent()); ! parser.parse(file.getName()); parser.end(); long end= System.currentTimeMillis(); |
From: Gerardo H. <ma...@us...> - 2004-09-11 17:36:38
|
Update of /cvsroot/jrman/drafts/src/org/jrman/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25192/src/org/jrman/parser Modified Files: Parser.java Log Message: Improved stats. Index: Parser.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/parser/Parser.java,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** Parser.java 4 May 2004 06:59:58 -0000 1.93 --- Parser.java 11 Sep 2004 17:36:28 -0000 1.94 *************** *** 147,151 **** private static Point4f P = new Point4f(); ! public static class State { --- 147,173 ---- private static Point4f P = new Point4f(); ! ! private int sphereCount; ! ! private int torusCount; ! ! private int cylinderCount; ! ! private int coneCount; ! ! private int diskCount; ! ! private int paraboloidCount; ! ! private int hyperboloidCount; ! ! private int bilinearPatchCount; ! ! private int bicubicPatchCount; ! ! private int polygonCount; ! ! private int pointCount; ! public static class State { *************** *** 473,477 **** currentAttributes.setSpace(Space.WORLD); pushAttributes(); ! renderer = Renderer.createRenderer(frame, world); // Must be set after defining gridsize... SurfaceShader.setBetterHighlights(cmdLine.hasOption(JRMan.OPTION_QUALITY)); --- 495,499 ---- currentAttributes.setSpace(Space.WORLD); pushAttributes(); ! renderer = Renderer.createRenderer(frame, world, this); // Must be set after defining gridsize... SurfaceShader.setBetterHighlights(cmdLine.hasOption(JRMan.OPTION_QUALITY)); *************** *** 762,766 **** final float thetaMin = 0f; final float thetaMax = (float) Math.toRadians(tMax); ! if (!inObject) renderer.addPrimitive( new Sphere( --- 784,788 ---- final float thetaMin = 0f; final float thetaMax = (float) Math.toRadians(tMax); ! if (!inObject) { renderer.addPrimitive( new Sphere( *************** *** 772,780 **** parameters, getAttributes())); ! else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { return new Sphere( radius, --- 794,804 ---- parameters, getAttributes())); ! sphereCount++; ! } else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { + sphereCount++; return new Sphere( radius, *************** *** 802,806 **** final float phiMax = (float) Math.toRadians(pMax); final float thetaMax = (float) Math.toRadians(tMax); ! if (!inObject) renderer.addPrimitive( new Torus( --- 826,830 ---- final float phiMax = (float) Math.toRadians(pMax); final float thetaMax = (float) Math.toRadians(tMax); ! if (!inObject) { renderer.addPrimitive( new Torus( *************** *** 813,821 **** parameters, getAttributes())); ! else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { return new Torus( majorRadius, --- 837,847 ---- parameters, getAttributes())); ! torusCount++; ! } else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { + torusCount++; return new Torus( majorRadius, *************** *** 841,852 **** return; final float thetaMax = (float) Math.toRadians(tMax); ! if (!inObject) renderer.addPrimitive( new Cylinder(radius, zmin, zmax, 0f, thetaMax, parameters, getAttributes())); ! else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { return new Cylinder( radius, --- 867,880 ---- return; final float thetaMax = (float) Math.toRadians(tMax); ! if (!inObject) { renderer.addPrimitive( new Cylinder(radius, zmin, zmax, 0f, thetaMax, parameters, getAttributes())); ! cylinderCount++; ! } else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { + cylinderCount++; return new Cylinder( radius, *************** *** 870,874 **** return; final float thetaMax = (float) Math.toRadians(tMax); ! if (!inObject) renderer.addPrimitive( new Cone( --- 898,902 ---- return; final float thetaMax = (float) Math.toRadians(tMax); ! if (!inObject) { renderer.addPrimitive( new Cone( *************** *** 881,889 **** parameters, getAttributes())); ! else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { return new Cone( radius, --- 909,919 ---- parameters, getAttributes())); ! coneCount++; ! } else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { + coneCount++; return new Cone( radius, *************** *** 908,919 **** return; final float thetaMax = (float) Math.toRadians(tMax); ! if (!inObject) renderer.addPrimitive( new Disk(height, 0f, thetaMax, 0f, radius, parameters, getAttributes())); ! else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { return new Disk( height, --- 938,951 ---- return; final float thetaMax = (float) Math.toRadians(tMax); ! if (!inObject) { renderer.addPrimitive( new Disk(height, 0f, thetaMax, 0f, radius, parameters, getAttributes())); ! diskCount++; ! } else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { + coneCount++; return new Disk( height, *************** *** 929,942 **** } public void addBilinearPatch(final ParameterList parameters) { if (inAreaLightSource) return; ! if (!inObject) renderer.addPrimitive(new BilinearPatch(parameters, getAttributes())); ! else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { return new BilinearPatch( parameters, --- 961,1074 ---- } + public void addParaboloid( + final float radius, + final float zmin, + final float zmax, + float tMax, + final ParameterList parameters) { + if (inAreaLightSource) + return; + + final float thetaMin = 0f; + final float thetaMax = (float) Math.toRadians(tMax); + if (!inObject) { + renderer.addPrimitive( + new Paraboloid( + radius, + zmin, + zmax, + thetaMin, + thetaMax, + zmin, + zmax, + thetaMax, + parameters, + getAttributes())); + paraboloidCount++; + } else { + final Transform transform = currentAttributes.getTransform(); + currentObjectInstanceList + .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { + public Primitive create(Attributes attributes) { + paraboloidCount++; + return new Paraboloid( + radius, + zmin, + zmax, + thetaMin, + thetaMax, + zmin, + zmax, + thetaMax, + parameters, + createAttributes(transform, attributes)); + } + }); + } + } + + public void addHyperboloid( + final float x1, + final float y1, + final float z1, + final float x2, + final float y2, + final float z2, + final float tMax, + final ParameterList parameters) { + if (inAreaLightSource) + return; + + final float thetaMin = 0f; + final float thetaMax = (float) Math.toRadians(tMax); + if (!inObject) { + renderer.addPrimitive( + new Hyperboloid( + x1, + y1, + z1, + x2, + y2, + z2, + thetaMin, + thetaMax, + parameters, + getAttributes())); + hyperboloidCount++; + } else { + final Transform transform = currentAttributes.getTransform(); + currentObjectInstanceList + .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { + public Primitive create(Attributes attributes) { + hyperboloidCount++; + return new Hyperboloid( + x1, + y1, + z1, + x2, + y2, + z2, + thetaMin, + thetaMax, + parameters, + createAttributes(transform, attributes)); + } + }); + } + + } + public void addBilinearPatch(final ParameterList parameters) { if (inAreaLightSource) return; ! if (!inObject) { renderer.addPrimitive(new BilinearPatch(parameters, getAttributes())); ! bilinearPatchCount++; ! } else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { + bilinearPatchCount++; return new BilinearPatch( parameters, *************** *** 953,956 **** --- 1085,1089 ---- BicubicPatch patch = new BicubicPatch(parameters, getAttributes()); renderer.addPrimitive(patch); + bicubicPatchCount++; } else { final Transform transform = currentAttributes.getTransform(); *************** *** 958,961 **** --- 1091,1095 ---- .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { + bicubicPatchCount++; BicubicPatch patch = new BicubicPatch(parameters, createAttributes(transform, attributes)); *************** *** 1232,1243 **** return; setPolygonST(parameters); ! if (!inObject) renderer.addPrimitive( new PointsPolygons(nVertices, vertices, parameters, getAttributes())); ! else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { return new PointsPolygons( nVertices, --- 1366,1379 ---- return; setPolygonST(parameters); ! if (!inObject) { renderer.addPrimitive( new PointsPolygons(nVertices, vertices, parameters, getAttributes())); ! polygonCount += nVertices.length; ! } else { final Transform transform = currentAttributes.getTransform(); currentObjectInstanceList .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { + polygonCount += nVertices.length; return new PointsPolygons( nVertices, *************** *** 1273,1276 **** --- 1409,1414 ---- indexes[3] = i + 1; addBilinearPatch(parameters.selectValues(uniformIndex, indexes, indexes)); + polygonCount++; + bilinearPatchCount--; // TODO: fix this } } *************** *** 1286,1289 **** --- 1424,1428 ---- (UniformScalarFloat) parameters.getParameter("constantwidth"); parameters.removeParameter("constantwidth"); + // TODO: same space optimization as for PointsPolygon int[] uniformIndex = new int[1]; uniformIndex[0] = 0; *************** *** 1303,1308 **** final ParameterList param = parameters.selectValues(uniformIndex, indexes, indexes); ! if (!inObject) renderer.addPrimitive(new Point(w, p.x, p.y, p.z, param, getAttributes())); else { final Transform transform = currentAttributes.getTransform(); --- 1442,1449 ---- final ParameterList param = parameters.selectValues(uniformIndex, indexes, indexes); ! if (!inObject) { renderer.addPrimitive(new Point(w, p.x, p.y, p.z, param, getAttributes())); + pointCount++; + } else { final Transform transform = currentAttributes.getTransform(); *************** *** 1310,1313 **** --- 1451,1455 ---- .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { public Primitive create(Attributes attributes) { + pointCount++; return new Point( w, *************** *** 1323,1420 **** } - public void addParaboloid( - final float radius, - final float zmin, - final float zmax, - float tMax, - final ParameterList parameters) { - if (inAreaLightSource) - return; - - final float thetaMin = 0f; - final float thetaMax = (float) Math.toRadians(tMax); - if (!inObject) - renderer.addPrimitive( - new Paraboloid( - radius, - zmin, - zmax, - thetaMin, - thetaMax, - zmin, - zmax, - thetaMax, - parameters, - getAttributes())); - else { - final Transform transform = currentAttributes.getTransform(); - currentObjectInstanceList - .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { - public Primitive create(Attributes attributes) { - return new Paraboloid( - radius, - zmin, - zmax, - thetaMin, - thetaMax, - zmin, - zmax, - thetaMax, - parameters, - createAttributes(transform, attributes)); - } - }); - } - } - - public void addHyperboloid( - final float x1, - final float y1, - final float z1, - final float x2, - final float y2, - final float z2, - final float tMax, - final ParameterList parameters) { - if (inAreaLightSource) - return; - - final float thetaMin = 0f; - final float thetaMax = (float) Math.toRadians(tMax); - if (!inObject) - renderer.addPrimitive( - new Hyperboloid( - x1, - y1, - z1, - x2, - y2, - z2, - thetaMin, - thetaMax, - parameters, - getAttributes())); - else { - final Transform transform = currentAttributes.getTransform(); - currentObjectInstanceList - .addPrimitiveCreator(new ObjectInstanceList.PrimitiveCreator() { - public Primitive create(Attributes attributes) { - return new Hyperboloid( - x1, - y1, - z1, - x2, - y2, - z2, - thetaMin, - thetaMax, - parameters, - createAttributes(transform, attributes)); - } - }); - } - - } - public void makeTexture( String picturename, --- 1465,1468 ---- *************** *** 1439,1441 **** --- 1487,1536 ---- } + public void resetCounts() { + sphereCount = 0; + torusCount = 0; + cylinderCount = 0; + coneCount = 0; + diskCount = 0; + paraboloidCount = 0; + hyperboloidCount = 0; + bilinearPatchCount = 0; + bicubicPatchCount = 0; + polygonCount = 0; + pointCount = 0; + } + + public int getBicubicPatchCount() { + return bicubicPatchCount; + } + public int getBilinearPatchCount() { + return bilinearPatchCount; + } + public int getConeCount() { + return coneCount; + } + public int getCylinderCount() { + return cylinderCount; + } + public int getDiskCount() { + return diskCount; + } + public int getHyperboloidCount() { + return hyperboloidCount; + } + public int getParaboloidCount() { + return paraboloidCount; + } + public int getPointCount() { + return pointCount; + } + public int getPolygonCount() { + return polygonCount; + } + public int getSphereCount() { + return sphereCount; + } + public int getTorusCount() { + return torusCount; + } } |
From: Gerardo H. <ma...@us...> - 2004-09-11 17:36:37
|
Update of /cvsroot/jrman/drafts/src/org/jrman/render In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25192/src/org/jrman/render Modified Files: Renderer.java RendererHidden.java Sampler.java Log Message: Improved stats. Index: Sampler.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/render/Sampler.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** Sampler.java 2 Feb 2004 19:30:05 -0000 1.21 --- Sampler.java 11 Sep 2004 17:36:27 -0000 1.22 *************** *** 68,78 **** private boolean hasSamples; ! public static int rootCount; ! ! public static int pixelCount; ! ! public static int bucketSamplesCount; ! public static int modifiedSampleBucketsCount; public static class MaskElement { --- 68,74 ---- private boolean hasSamples; ! private int rootCount; ! private int pixelCount; public static class MaskElement { *************** *** 142,146 **** public void sampleBucket(Bucket bucket) { - bucketSamplesCount++; while (bucket.hasMoreMicropolygons()) { Micropolygon mp = bucket.getNextMicropolygon(); --- 138,141 ---- *************** *** 295,297 **** --- 290,298 ---- } + public int getPixelCount() { + return pixelCount; + } + public int getRootCount() { + return rootCount; + } } Index: Renderer.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/render/Renderer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Renderer.java 16 Apr 2003 09:19:35 -0000 1.2 --- Renderer.java 11 Sep 2004 17:36:27 -0000 1.3 *************** *** 22,25 **** --- 22,26 ---- import org.jrman.options.Hider; import org.jrman.parser.Frame; + import org.jrman.parser.Parser; import org.jrman.parser.World; import org.jrman.primitive.Primitive; *************** *** 31,35 **** protected World world; ! public static Renderer createRenderer(Frame frame, World world) { Renderer renderer = null; Hider hider = frame.getHider(); --- 32,38 ---- protected World world; ! protected Parser parser; ! ! public static Renderer createRenderer(Frame frame, World world, Parser parser) { Renderer renderer = null; Hider hider = frame.getHider(); *************** *** 38,42 **** else if (hider == Hider.NULL) renderer = new RendererNull(); ! renderer.init(frame, world); return renderer; } --- 41,45 ---- else if (hider == Hider.NULL) renderer = new RendererNull(); ! renderer.init(frame, world, parser); return renderer; } *************** *** 46,52 **** public abstract void render(); ! protected void init(Frame frame, World world) { this.frame = frame; this.world = world; } --- 49,56 ---- public abstract void render(); ! protected void init(Frame frame, World world, Parser parser) { this.frame = frame; this.world = world; + this.parser = parser; } Index: RendererHidden.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/render/RendererHidden.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** RendererHidden.java 2 Feb 2004 19:30:05 -0000 1.62 --- RendererHidden.java 11 Sep 2004 17:36:27 -0000 1.63 *************** *** 42,45 **** --- 42,46 ---- import org.jrman.parser.Frame; import org.jrman.parser.Global; + import org.jrman.parser.Parser; import org.jrman.parser.World; import org.jrman.primitive.Primitive; *************** *** 83,86 **** --- 84,89 ---- private int invisiblePatchCount; + + private int clippedPrimitivesCount; private long worldParseStart; *************** *** 106,111 **** private Transform oldObjectToCamera; ! public void init(Frame frame, World world) { ! super.init(frame, world); worldToCamera = Global.getTransform("camera"); Transform cameraToScreen = Global.getTransform("screen"); --- 109,114 ---- private Transform oldObjectToCamera; ! public void init(Frame frame, World world, Parser parser) { ! super.init(frame, world, parser); worldToCamera = Global.getTransform("camera"); Transform cameraToScreen = Global.getTransform("screen"); *************** *** 165,170 **** bve = bv; } ! if (clippingVolume.whereIs(bve) == Plane.Side.OUTSIDE) return true; Plane.Side side = bv.whichSideOf(eyePlane); if (side == Plane.Side.INSIDE) { --- 168,175 ---- bve = bv; } ! if (clippingVolume.whereIs(bve) == Plane.Side.OUTSIDE) { ! clippedPrimitivesCount++; return true; + } Plane.Side side = bv.whichSideOf(eyePlane); if (side == Plane.Side.INSIDE) { *************** *** 487,494 **** --- 492,514 ---- long end = System.currentTimeMillis(); float time = (end - start) / 1000f; + displayStats(gridCount, sampler, time); + } + + private void displayStats(int gridCount, Sampler sampler, float time) { if (frame.endOfFrameStatisticsEnabled()) { System.out.println("*** Frame Statistics ***"); System.out.println( "World parse time: " + Format.time(worldParseEnd - worldParseStart)); + display("spheres", parser.getSphereCount()); + display("toruses", parser.getTorusCount()); + display("cones", parser.getConeCount()); + display("disks", parser.getDiskCount()); + display("paraboloids", parser.getParaboloidCount()); + display("hyperboloids", parser.getHyperboloidCount()); + display("bilinear patches", parser.getBilinearPatchCount()); + display("bicubic patches", parser.getBicubicPatchCount()); + display("polygons", parser.getPolygonCount()); + display("points", parser.getPointCount()); + System.out.println("Clipped primitives: " + clippedPrimitivesCount); System.out.println("Total patches: " + primitivePatchCount); System.out.println("Patches/second: " + primitivePatchCount / time); *************** *** 496,501 **** System.out.println( "Patches culled: " + invisiblePatchCount * 100f / primitivePatchCount + "%"); ! System.out.println("Root count: " + Sampler.rootCount); ! System.out.println("Pixel count: " + Sampler.pixelCount); System.out.println( "gridCount = " --- 516,521 ---- System.out.println( "Patches culled: " + invisiblePatchCount * 100f / primitivePatchCount + "%"); ! System.out.println("Root count: " + sampler.getRootCount()); ! System.out.println("Pixel count: " + sampler.getPixelCount()); System.out.println( "gridCount = " *************** *** 508,525 **** System.out.println("Total micropolygons: " + Micropolygon.count); System.out.println("Micropolygons/second: " + Micropolygon.count / time); - System.out.println("Bucket samples: " + Sampler.bucketSamplesCount); - System.out.println( - "Modified bucket samples: " + Sampler.modifiedSampleBucketsCount); System.out.println("---------------------------------------------------"); primitivePatchCount = 0; invisiblePatchCount = 0; - Sampler.rootCount = 0; - Sampler.pixelCount = 0; gridCount = 0; Micropolygon.count = 0; ! Sampler.bucketSamplesCount = 0; ! Sampler.modifiedSampleBucketsCount = 0; } } private boolean isPrimitiveVisible(Primitive p, Sampler sampler) { --- 528,545 ---- System.out.println("Total micropolygons: " + Micropolygon.count); System.out.println("Micropolygons/second: " + Micropolygon.count / time); System.out.println("---------------------------------------------------"); + clippedPrimitivesCount = 0; primitivePatchCount = 0; invisiblePatchCount = 0; gridCount = 0; Micropolygon.count = 0; ! parser.resetCounts(); } } + + private void display(String primitiveName, int count) { + if (count != 0) + System.out.println("Total " + primitiveName + ": " + count); + } private boolean isPrimitiveVisible(Primitive p, Sampler sampler) { |
From: Gerardo H. <ma...@us...> - 2004-09-11 17:36:37
|
Update of /cvsroot/jrman/drafts/src/org/jrman/maps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25192/src/org/jrman/maps Modified Files: MipMap.java Log Message: Improved stats. Index: MipMap.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/maps/MipMap.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MipMap.java 14 Dec 2003 22:28:28 -0000 1.5 --- MipMap.java 11 Sep 2004 17:36:27 -0000 1.6 *************** *** 168,171 **** --- 168,172 ---- AffineTransformOp afop = new AffineTransformOp(af, AffineTransformOp.TYPE_BILINEAR); BufferedImage squareImage = afop.filter(image, null); + image = null; // Release memory byte[] data = new byte[size * size * 4]; for (int y = 0; y < size; y++) *************** *** 178,181 **** --- 179,183 ---- data[offset + 3] = (byte) (argb >> 24); } + squareImage = null; // Release memory SamplesFilter samplesFilter = filter.getSamplesFilter(); int width = Calc.ceil(filter.getHorizontalWidth() * 2); |
From: Elmer G. <ega...@us...> - 2004-08-05 21:21:08
|
Update of /cvsroot/jrman/drafts/nurbtest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25407/nurbtest Added Files: Main.java NurbSubdiv.java Nurbs.java SurfSample.java Log Message: Added Nurbs port. --- NEW FILE: NurbSubdiv.java --- /* * NurbSubdiv.c - Perform adaptive subdivision on a NURB surface. * * John Peterson * Port to java by Elmer Garduno */ import javax.vecmath.Point3f; import javax.vecmath.Point4f; import javax.vecmath.Vector3f; public class NurbSubdiv { /* Size, in pixels of facets produced */ private final static float SubdivTolerance = 2.0F ; /* Used to determine when things are too small. */ private final static float EPSILON = 0.0000001F; void DrawSubdivision( Nurbs surf ) { /* * Initialize the projected corners of the surface * and the normals. */ DIVW( surf.points[0][0], surf.c00.point ); DIVW( surf.points[0][surf.numU - 1], surf.c0n.point ); DIVW( surf.points[surf.numV - 1][0], surf.cn0.point ); DIVW( surf.points[surf.numV - 1][surf.numU - 1], surf.cnn.point ); GetNormal( surf, 0, 0 ); GetNormal( surf, 0, maxU(surf) ); GetNormal( surf, maxV(surf), 0 ); GetNormal( surf, maxV(surf), maxU(surf) ); DoSubdivision( surf, SubdivTolerance, true, 0 ); } private float MAX(float a, float b) { return ( a > b ) ? a : b ; } private int MAX(int a, int b) { return ( a > b ) ? a : b ; } private int MIN(int a, int b) { return ( a < b ) ? a : b ; } private final static int MAXORDER = 20; private void DIVW(Point4f rpt, Point3f pt ) { pt.x = rpt.x / rpt.w; pt.y = rpt.y / rpt.w; pt.z = rpt.z / rpt.w; } private void DIVPT(Point3f p, float dn ) { p.x /= dn; p.y /= dn; p.z /= dn; } private Point4f GETPT(int i, int crvInd, boolean dirflag, Nurbs n) { return dirflag ? n.points[crvInd][i] : n.points[i][crvInd]; } private int maxV(Nurbs surf) { return surf.numV - 1; } private int maxU(Nurbs surf) { return surf.numU - 1; } void ScreenProject( Point4f worldPt, Point3f screenPt ) { screenPt.x = worldPt.x / worldPt.w * 100 + 200; screenPt.y = worldPt.y / worldPt.w * 100 + 200; screenPt.z = worldPt.z / worldPt.w * 100 + 200; } /* * Compute the normal of a corner point of a mesh. The * base is the value of the point at the corner, indU and indV * are the mesh indices of that point (either 0 or numU|numV). */ void GetNormal( Nurbs n, int indV, int indU ) { Point3f tmpL = new Point3f(); Point3f tmpR = new Point3f(); /* "Left" and "Right" of the base point */ SurfSample crnr; if ( ((indU != 0) && (indV != 0)) || ((indU == 0) && (indV == 0))) { if (indU != 0) crnr = n.cnn; else crnr = n.c00; DIVW( n.points[indV][((indU != 0) ? (indU - 1) : 1)], tmpL ); DIVW( n.points[((indV != 0) ? (indV - 1) : 1)][indU], tmpR ); } else { if (indU != 0) crnr = n.c0n; else crnr = n.cn0; DIVW( n.points[indV][((indU != 0) ? (indU - 1) : 1)], tmpR ); DIVW( n.points[((indV != 0) ? (indV - 1) : 1)][indU], tmpL ); } V3Sub( tmpL, crnr.point, tmpL ); V3Sub( tmpR, crnr.point, tmpR ); V3Cross( tmpL, tmpR, crnr.normal ); AdjustNormal( crnr ); } /* * Normalize the normal in a sample. If it's degenerate, * flag it as such by setting the normLen to 0.0 */ void AdjustNormal( SurfSample samp ) { /* If it's not degenerate, do the normalization now */ samp.normLen = V3Length( samp.normal ); if (samp.normLen < EPSILON) samp.normLen = 0.0F; else DIVPT( samp.normal, samp.normLen ); } /* * The recursive subdivision algorithm. Test if the surface is flat. * If so, split it into triangles. Otherwise, split it into two halves, * and invoke the procedure on each half. */ void DoSubdivision( Nurbs n, float tolerance, boolean dirflag, int level ) { if (TestFlat( n, tolerance )) { EmitTriangles( n ); } else { if ( (! n.flatV && ! n.flatU) || (n.flatV && n.flatU) ) dirflag = ! dirflag; /* If twisted or curved in both directions, */ else /* then alternate subdivision direction */ { if (n.flatU) /* Only split in directions that aren't flat */ dirflag = false; else dirflag = true; } Nurbs left = new Nurbs(); Nurbs right = new Nurbs(); SplitSurface( n, left, right, dirflag ); DoSubdivision( left, tolerance, dirflag, level + 1 ); DoSubdivision( right, tolerance, dirflag, level + 1 ); } } /* * Split a surface into two halves. First inserts multiplicity k knots * in the center of the parametric range. After refinement, the two * resulting surfaces are copied into separate data structures. If the * parent surface had straight edges, the points of the children are * projected onto those edges. */ float[] newkv; int splitPt; void SplitSurface( Nurbs parent, Nurbs kid0, Nurbs kid1, boolean dirflag ) /* If true subdivided in U, else in V */ { /* * Add a multiplicty k knot to the knot vector in the direction * specified by dirflag, and refine the surface. This creates two * adjacent surfaces with c0 discontinuity at the seam. */ Nurbs tmp = new Nurbs(parent); /* Copy order, # of points, etc. */ if (dirflag) { tmp.numU = parent.numU + SplitKV( parent.kvU, maxU(parent), parent.orderU ); tmp.kvU = newkv; for (int i = 0; i < tmp.numV + tmp.orderV; i++) tmp.kvV[i] = parent.kvV[i]; } else { tmp.numV = parent.numV + SplitKV( parent.kvV, maxV(parent), parent.orderV ); tmp.kvV = newkv; for (int i = 0; i < tmp.numU + tmp.orderU; i++) tmp.kvU[i] = parent.kvU[i]; } tmp.updatePointsSize(); RefineSurface( parent, tmp, dirflag ); /* * Build the two child surfaces, and copy the data from the refined * version of the parent (tmp) into the two children */ /* First half */ kid0.copy(parent); /* copy various edge flags and orders */ kid0.numU = dirflag ? splitPt + 1 : parent.numU; kid0.numV = dirflag ? parent.numV : splitPt + 1; for (int i = 0; i < kid0.numV; i++) /* Copy the point and kv data */ for (int j = 0; j < kid0.numU; j++) kid0.points[i][j] = tmp.points[i][j]; for (int i = 0; i < kid0.orderU + kid0.numU; i++) kid0.kvU[i] = tmp.kvU[i]; for (int i = 0; i < kid0.orderV + kid0.numV; i++) kid0.kvV[i] = tmp.kvV[i]; /* Second half */ splitPt++; kid1.copy(parent); kid1.numU = dirflag ? tmp.numU - splitPt : parent.numU; kid1.numV = dirflag ? parent.numV : tmp.numV - splitPt; for (int i = 0; i < kid1.numV; i++) /* Copy the point and kv data */ for (int j = 0; j < kid1.numU; j++) kid1.points[i][j] = tmp.points[dirflag ? i: (i + splitPt) ][dirflag ? (j + splitPt) : j]; for (int i = 0; i < kid1.orderU + kid1.numU; i++) kid1.kvU[i] = tmp.kvU[dirflag ? (i + splitPt) : i]; for (int i = 0; i < kid1.orderV + kid1.numV; i++) kid1.kvV[i] = tmp.kvV[dirflag ? i : (i + splitPt)]; /* Construct new corners on the boundry between the two kids */ MakeNewCorners( parent, kid0, kid1, dirflag ); } /* * Build the new corners in the two new surfaces, computing both * point on the surface along with the normal. Prevent cracks that may occur. */ void MakeNewCorners( Nurbs parent, Nurbs kid0, Nurbs kid1, boolean dirflag ) { DIVW( kid0.points[maxV(kid0)][maxU(kid0)], kid0.cnn.point ); GetNormal( kid0, maxV(kid0), maxU(kid0) ); if (dirflag) { kid0.strUn = false; /* Must re-test new edge straightness */ DIVW( kid0.points[0][maxU(kid0)], kid0.c0n.point ); GetNormal( kid0, 0, maxU(kid0) ); /* * Normals must be re-calculated for kid1 in case the surface * was split at a c1 (or c0!) discontinutiy */ kid1.c00.point = kid0.c0n.point; GetNormal( kid1, 0, 0 ); kid1.cn0.point = kid0.cnn.point; GetNormal( kid1, maxV(kid1), 0 ); /* * Prevent cracks from forming by forcing the points on the seam to * lie along any straight edges. (Must do this BEFORE finding normals) */ if (parent.strV0) ProjectToLine( parent.c00.point, parent.c0n.point, kid0.c0n.point); if (parent.strVn) ProjectToLine( parent.cn0.point, parent.cnn.point, kid0.cnn.point ); kid1.c00.point = kid0.c0n.point; kid1.cn0.point = kid0.cnn.point; kid1.strU0 = false; } else { kid0.strVn = false; DIVW( kid0.points[maxV(kid0)][0], kid0.cn0.point ); GetNormal( kid0, maxV(kid0), 0 ); kid1.c00.point = kid0.cn0.point; GetNormal( kid1, 0, 0 ); kid1.c0n.point = kid0.cnn.point; GetNormal( kid1, 0, maxU(kid1) ); if (parent.strU0) ProjectToLine( parent.c00.point, parent.cn0.point, kid0.cn0.point ); if (parent.strUn) ProjectToLine( parent.c0n.point, parent.cnn.point, kid0.cnn.point ); kid1.c00.point = kid0.cn0.point; kid1.c0n.point = kid0.cnn.point; kid1.strV0 = false; } } /* * Given a line defined by firstPt and lastPt, project midPt onto * that line. Used for fixing "cracks". */ void ProjectToLine( Point3f firstPt, Point3f lastPt, Point3f midPt ) { Point3f v0 = new Point3f(); Point3f vm = new Point3f(); Point3f base = firstPt; V3Sub( lastPt, base, v0 ); V3Sub( midPt, base, vm ); float denom = V3SquaredLength( v0 ); float fraction = (denom == 0.0) ? 0.0F : (V3Dot( v0, vm ) / denom); midPt.x = base.x + fraction * v0.x; midPt.y = base.y + fraction * v0.y; midPt.z = base.z + fraction * v0.z; } /* * Split a knot vector at the center, by adding multiplicity k knots near * the middle of the parameter range. Tries to start with an existing knot, * but will add a new knot value if there's nothing in "the middle" (e.g., * a Bezier curve). */ int SplitKV( float[] srckv, int m, int k ) { int extra = 0; int last = (m + k); int middex = last / 2; float midVal = srckv[middex]; /* Search forward and backward to see if multiple knot is already there */ int i = middex + 1; int same = 1; while ((i < last) && (srckv[i] == midVal)) { i++; same++; } i = middex - 1; while ((i > 0) && (srckv[i] == midVal)) { i--; middex--; /* middex is start of multiple knot */ same++; } if (i <= 0) /* No knot in middle, must create it */ { midVal = (srckv[0] + srckv[last]) / 2.0F; middex = last / 2; while (srckv[middex + 1] < midVal) middex++; same = 0; } extra = k - same; newkv = new float[m + k + extra + 1]; if (same < k) /* Must add knots */ { for (i = 0; i <= middex; i++) newkv[i] = srckv[i]; for (i = middex+1; i <= middex+extra; i++) newkv[i] = midVal; for (i = middex + k - same + 1; i <= m + k + extra; i++) newkv[i] = srckv[i - extra]; } else { for (i = 0; i <= m + k; i++) newkv[i] = srckv[i]; } splitPt = (extra < k) ? middex - 1 : middex; return extra ; } /* * Check to see if a surface is flat. Tests are only performed on edges and * directions that aren't already straight. If an edge is flagged as straight * (from the parent surface) it is assumed it will stay that way. */ boolean TestFlat( Nurbs n, float tolerance ) { Point3f cp00 = new Point3f(); //by reference Point3f cp0n = new Point3f(); Point3f cpn0 = new Point3f(); Point3f cpnn = new Point3f(); Point3f planeEqn = new Point3f(); /* Check edge straightness */ if (!n.strU0) n.strU0 = IsCurveStraight( n, tolerance, 0, false ); if (!n.strUn) n.strUn = IsCurveStraight( n, tolerance, maxU(n), false ); if (!n.strV0) n.strV0 = IsCurveStraight( n, tolerance, 0, true ); if (!n.strVn) n.strVn = IsCurveStraight( n, tolerance, maxV(n), true ); /* Test to make sure control points are straight in U and V */ boolean straight = true; if ( !n.flatU && n.strV0 && n.strVn ) for (int i = 1; (i < maxV(n)) && (straight = IsCurveStraight( n, tolerance, i, true )); i++); if (straight && n.strV0 && n.strVn) n.flatU = true; straight = true; if ( !n.flatV && n.strU0 && n.strUn ) for (int i = 1; (i < maxU(n)) && (straight = IsCurveStraight( n, tolerance, i, false )); i++); if (straight && n.strU0 && n.strUn) n.flatV = true; if ( !n.flatV || !n.flatU ) return false; /* The surface can pass the above tests but still be twisted. */ ScreenProject( n.points[0][0], cp00 ); ScreenProject( n.points[0][maxU(n)], cp0n ); ScreenProject( n.points[maxV(n)][0], cpn0 ); ScreenProject( n.points[maxV(n)][maxU(n)], cpnn ); V3Sub( cp0n, cp00, cp0n ); /* Make edges into vectors */ V3Sub( cpn0, cp00, cpn0 ); /* * Compute the plane equation from two adjacent sides, and * measure the distance from the far point to the plane. If it's * larger than tolerance, the surface is twisted. */ V3Cross( cpn0, cp0n, planeEqn ); V3Normalize( planeEqn ); /* Normalize to keep adds in sync w/ mults */ float d = V3Dot( planeEqn, cp00 ); float dist = Math.abs( V3Dot( planeEqn, cpnn ) - d ); if ( dist > tolerance ) /* Surface is twisted */ return false; else return true; } boolean IsCurveStraight( Nurbs n, double tolerance, int crvInd, boolean dirflag ) /* If true, test in U direction, else test in V */ { Point3f p = new Point3f(); Point3f vec = new Point3f(); Point3f prod = new Point3f(); Point3f cp = new Point3f(); // by reference Point3f e0 = new Point3f(); /* Special case: lines are automatically straight. */ if ((dirflag ? n.numU : n.numV) == 2) return true; int last = (dirflag ? n.numU : n.numV) - 1; ScreenProject( GETPT( 0 , crvInd, dirflag, n), e0 ); /* Form an initial line to test the other points against (skiping degen lines) */ float linelen = 0.0F; for (int i = last; (i > 0) && (linelen < EPSILON); i--) { ScreenProject( GETPT( i , crvInd, dirflag, n), cp ); V3Sub( cp, e0, vec ); linelen = V3Length( vec ) ; } DIVPT( vec, linelen ); if (linelen > EPSILON) /* If no non-degenerate lines found, it's all degen */ for (int i = 1; i <= last; i++) { /* The cross product of the vector defining the * initial line with the vector of the current point * gives the distance to the line. */ ScreenProject( GETPT( i , crvInd, dirflag, n), cp ); V3Sub( cp, e0, p ); V3Cross( p, vec, prod ); float dist = V3Length( prod ); if (dist > tolerance) return false; } return true; } /* * If a normal has collapsed to zero (normLen == 0.0) then try * and fix it by looking at its neighbors. If all the neighbors * are sick, then re-compute them from the plane they form. * If that fails too, then we give up... */ void FixNormals( SurfSample s0, SurfSample s1, SurfSample s2 ) { boolean goodnorm = false; SurfSample[] V = new SurfSample[3]; Point3f norm = new Point3f(); int ok; V[0] = s0; V[1] = s1; V[2] = s2; /* Find a reasonable normal */ for (ok = 0; (ok < 3) && !(goodnorm = (V[ok].normLen > 0.0)); ok++); if (! goodnorm) /* All provided normals are zilch, try and invent one */ { norm.x = 0.0F; norm.y = 0.0F; norm.z = 0.0F; for (int i = 0; i < 3; i++) { int j = (i + 1) % 3; norm.x += (V[i].point.y - V[j].point.y) * (V[i].point.z + V[j].point.z); norm.y += (V[i].point.z - V[j].point.z) * (V[i].point.x + V[j].point.x); norm.z += (V[i].point.x - V[j].point.x) * (V[i].point.y + V[j].point.y); } float dist = V3Length( norm ); if (dist == 0.0) return; /* This sucker's hopeless... */ DIVPT( norm, dist ); for (int i = 0; i < 3; i++) { V[i].normal = norm; V[i].normLen = dist; } } else /* Replace a sick normal with a healthy one nearby */ { for (int i = 0; i < 3; i++) if ((i != ok) && (V[i].normLen == 0.0)) V[i].normal = V[ok].normal; } return; } void LineTo( int x, int y ) { System.out.println("L " + x +", " + y); } void MoveTo( int x, int y ) { System.out.println("M " + x +", " + y); } void LineTriangle( SurfSample v0, SurfSample v1, SurfSample v2 ) { MoveTo( (int) (v0.point.x * 100 + 200), (int) (v0.point.y * 100 + 200)); LineTo( (int) (v1.point.x * 100 + 200), (int) (v1.point.y * 100 + 200)); LineTo( (int) (v2.point.x * 100 + 200), (int) (v2.point.y * 100 + 200)); LineTo( (int) (v0.point.x * 100 + 200), (int) (v0.point.y * 100 + 200)); } void EmitTriangles( Nurbs n ) { Point3f vecnn = new Point3f(); Point3f vec0n = new Point3f(); /* Diagonal vectors */ /* * Measure the distance along the two diagonals to decide the best * way to cut the rectangle into triangles. */ V3Sub( n.c00.point, n.cnn.point, vecnn ); V3Sub( n.c0n.point, n.cn0.point, vec0n ); float len2nn = V3SquaredLength( vecnn ); /* Use these to reject triangles */ float len20n = V3SquaredLength( vec0n ); /* that are too small to render */ if (MAX(len2nn, len20n) < EPSILON) return; /* Triangles are too small to render */ /* * Assign the texture coordinates */ float u0 = n.kvU[n.orderU - 1]; float un = n.kvU[n.numU]; float v0 = n.kvV[n.orderV - 1]; float vn = n.kvV[n.numV]; n.c00.u = u0; n.c00.v = v0; n.c0n.u = un; n.c0n.v = v0; n.cn0.u = u0; n.cn0.v = vn; n.cnn.u = un; n.cnn.v = vn; /* * If any normals are sick, fix them now. */ if ((n.c00.normLen == 0.0) || (n.cnn.normLen == 0.0) || (n.cn0.normLen == 0.0)) FixNormals( n.c00, n.cnn, n.cn0 ); if (n.c0n.normLen == 0.0) FixNormals( n.c00, n.c0n, n.cnn); if ( len2nn < len20n ) { LineTriangle( n.c00, n.cnn, n.cn0 ); LineTriangle( n.c00, n.c0n, n.cnn ); } else { LineTriangle( n.c0n, n.cnn, n.cn0 ); LineTriangle( n.c0n, n.cn0, n.c00 ); } } float V3SquaredLength(Point3f a) { return ((a.x * a.x) + (a.y * a.y) + (a.z * a.z)); } float V3Length(Point3f a) { return (float) Math.sqrt(V3SquaredLength(a)); } float V3Dot(Point3f a, Point3f b) { return ((a.x * b.x) + (a.y * b.y) + (a.z * b.z)); } void V3Normalize(Point3f v) { float len = V3Length(v); if (len != 0.0) { v.x /= len; v.y /= len; v.z /= len; } } void V3Cross(Point3f a, Point3f b, Point3f c) { c.x = (a.y * b.z) - (a.z * b.y); c.y = (a.z * b.x) - (a.x * b.z); c.z = (a.x * b.y) - (a.y * b.x); } void V3Sub(Point3f a, Point3f b, Point3f c) { c.x = a.x - b.x; c.y = a.y - b.y; c.z = a.z - b.z; } /* * Given the original knot vector ukv, and a new knotvector vkv, compute * the "alpha matrix" used to generate the corresponding new control points. * This routines allocates the alpha matrix if it isn't allocated already. * * This is from Bartels, Beatty & Barsky, p. 407 */ float[][] CalcAlpha( float[] ukv, float[] wkv, int m, int n, int k) { float[] aval = new float[MAXORDER]; float[][] alpha = new float[k + 1][m + n + 1]; for (int j = 0; j <= m + n; j++) { int brkPoint = FindBreakPoint( wkv[j], ukv, m, k ); aval[0] = 1.0F; for (int r = 2; r <= k; r++) { int rm1 = r - 1; int last = MIN( rm1, brkPoint ); int i = brkPoint - last; if (last < rm1) aval[last] = aval[last] * (wkv[j + r - 1] - ukv[i]) / (ukv[i + r - 1] - ukv[i]); else aval[last] = 0.0F; for (int s = last - 1; s >= 0; s-- ) { i++; float omega = (wkv[j + r - 1] - ukv[i]) / (ukv[i + r - 1] - ukv[i]); aval[s + 1] = aval[s+1] + (1 - omega) * aval[s]; aval[s] = omega * aval[s]; } } int last = MIN( k - 1, brkPoint ); for (int i = 0; i <= k; i++) alpha[i][j] = 0.0F; for (int s = 0; s <= last; s++) alpha[last - s][j] = aval[s]; } return alpha; } /* * Apply the alpha matrix computed above to the rows (or columns) * of the surface. If dirflag is true do the U's (row), else do V's (col). */ void RefineSurface( Nurbs src, Nurbs dest, boolean dirflag ) { int maxj; int maxout; float[][] alpha; /* Compute the alpha matrix and indexing variables for the requested direction */ if (dirflag) { alpha = CalcAlpha( src.kvU, dest.kvU, src.numU - 1, dest.numU - src.numU, src.orderU); maxj = dest.numU; maxout = src.numV; //src?? } else { alpha = CalcAlpha( src.kvV, dest.kvV, src.numV - 1, dest.numV - src.numV, src.orderV); maxj = dest.numV; maxout = dest.numU; } /* Apply the alpha matrix to the original control points, generating new ones */ for (int out = 0; out < maxout; out++) for (int j = 0; j < maxj; j++) { int brkPoint; int i1; Point4f dp; Point4f sp; if (dirflag) { dp = dest.points[out][j]; brkPoint = FindBreakPoint( dest.kvU[j], src.kvU, src.numU-1, src.orderU ); i1 = MAX( brkPoint - src.orderU + 1, 0 ); sp = src.points[out][i1]; } else { dp = dest.points[j][out]; brkPoint = FindBreakPoint( dest.kvV[j], src.kvV, src.numV-1, src.orderV ); i1 = MAX( brkPoint - src.orderV + 1, 0 ); sp = src.points[i1][out]; } dp.x = 0.0F; dp.y = 0.0F; dp.z = 0.0F; dp.w = 0.0F; for (int i = i1; i <= brkPoint; i++) { double tmp = alpha[i - i1][j]; sp = (dirflag ? src.points[out][i] : src.points[i][out] ); dp.x += tmp * sp.x; dp.y += tmp * sp.y; dp.z += tmp * sp.z; dp.w += tmp * sp.w; } } } /* * Return the current knot the parameter u is less than or equal to. * Find this "breakpoint" allows the evaluation routines to concentrate on * only those control points actually effecting the curve around u.] * * m is the number of points on the curve (or surface direction) * k is the order of the curve (or surface direction) * kv is the knot vector ([0..m+k-1]) to find the break point in. */ int FindBreakPoint( float u, float[] kv, int m, int k ) { if (u == kv[m + 1]) /* Special case for closed interval */ return m; int i = m + k; while ((u < kv[i]) && (i > 0)) i--; return i ; } } --- NEW FILE: Main.java --- public class Main { public static void main(String[] args) { Nurbs torus = generateTorus( 1.3F, 0.3F ); new NurbSubdiv().DrawSubdivision( torus ); } static Nurbs generateTorus(float majorRadius, float minorRadius) { /* These define the shape of a unit torus centered about the origin. */ float xvalues[] = { 0.0F, -1.0F, -1.0F, -1.0F, 0.0F, 1.0F, 1.0F, 1.0F, 0.0F }; float yvalues[] = { 1.0F, 1.0F, 0.0F, -1.0F, -1.0F, -1.0F, 0.0F, 1.0F, 1.0F }; float zvalues[] = { 0.0F, 1.0F, 1.0F, 1.0F, 0.0F, -1.0F, -1.0F, -1.0F, 0.0F }; float offsets[] = { -1.0F, -1.0F, 0.0F, 1.0F, 1.0F, 1.0F, 0.0F, -1.0F, -1.0F }; /* Piecewise Bezier knot vector for a quadratic curve with four segments */ int knots[] = { 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4 }; float r2over2 = (float) Math.sqrt( 2.0F ) / 2.0F; Nurbs torus = new Nurbs(9, 9, 3, 3); /* A circle is formed from nine points */ /* Quadratic in both directions */ /* Set up the dimension and orders of the surface */ for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { float weight = (((j & 1) != 0) ? r2over2 : 1.0F) * (((i & 1) != 0) ? r2over2 : 1.0F); /* Notice how the weights are pre-multiplied with the x, y and z values */ torus.points[i][j].x = xvalues[j] * (majorRadius + offsets[i] * minorRadius) * weight; torus.points[i][j].y = yvalues[j] * (majorRadius + offsets[i] * minorRadius) * weight; torus.points[i][j].z = (zvalues[i] * minorRadius) * weight; torus.points[i][j].w = weight; } } /* The knot vectors define piecewise Bezier segments (the same in both U and V). */ for (int i = 0; i < torus.numU + torus.orderU; i++) torus.kvU[i] = torus.kvV[i] = knots[i]; return torus; } } --- NEW FILE: Nurbs.java --- import javax.vecmath.Point4f; public class Nurbs { /* Number of Points in the U and V directions, respectivly */ int numU; int numV; /* Order of the surface in U and V (must be >= 2, < MAXORDER) */ int orderU; int orderV; /* Knot vectors, indexed as [0..numU+orderU-1] and [0..numV+orderV-1] */ float[] kvU; float[] kvV; /* Control points, indexed as points[0..numV-1][0..numU-1] */ /* Note the w values are *premultiplied* with the x, y and z values */ Point4f[][] points; /* These fields are added to support subdivision */ boolean strV0; boolean strVn; /* Edge straightness flags for subdivision */ boolean strU0; boolean strUn; /* Surface flatness flags for subdivision */ boolean flatV; boolean flatU; /* Corner data structures for subdivision */ SurfSample c00 = new SurfSample(); SurfSample c0n = new SurfSample(); SurfSample cn0 = new SurfSample(); SurfSample cnn = new SurfSample(); public Nurbs() { } public Nurbs(int numV, int numU, int orderV, int orderU) { this.numV = numV; this.numU = numU; this.orderU = orderU; this.orderV = orderV; points = new Point4f[numV][numU]; for (int i = 0; i < numV; i ++) { for (int j = 0; j < numU; j++) { points[i][j] = new Point4f(); } } kvU = new float[numU + orderU]; kvV = new float[numV + orderV]; } public Nurbs(Nurbs parent) { copy(parent); } public void copy(Nurbs parent) { numU = parent.numU; numV = parent.numV; orderU = parent.orderU; orderV = parent.orderV; kvU = new float[numU + orderU]; kvV = new float[numV + orderV]; points = new Point4f[numV][numU]; for (int i = 0; i < numV; i ++) { for (int j = 0; j < numU; j++) { points[i][j] = new Point4f(); } } strV0 = parent.strV0; strVn = parent.strVn; strU0 = parent.strU0; strUn = parent.strUn; flatV = parent.flatV; flatU = parent.flatU; //c00 = new SurfSample(parent.c00); //c0n = new SurfSample(parent.c0n); //cn0 = new SurfSample(parent.cn0); //cnn = new SurfSample(parent.cnn); } public void updatePointsSize() { points = new Point4f[numV][numU]; for (int i = 0; i < numV; i ++) { for (int j = 0; j < numU; j++) { points[i][j] = new Point4f(); } } } } --- NEW FILE: SurfSample.java --- import javax.vecmath.Point3f; /* * Sampled point on a surface. This contains the point, normal and * surface coordinates (u,v). This structure is passed to the rendering * code for shading, etc. */ public class SurfSample { /* Point on surface, normal at that point */ Point3f point = new Point3f(); Point3f normal = new Point3f(); /* Used for normalizing normals */ float normLen; /* Parameters, e.g., used for texture mapping. */ float u; float v; /* Note the parameter's range is determined by the surface's knot vector, * i.e., u goes from kvU[orderU-1] to kvU[numU], and likewise for v */ } |
From: Elmer G. <ega...@us...> - 2004-08-05 21:19:18
|
Update of /cvsroot/jrman/drafts/nurbtest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25242/nurbtest Log Message: Directory /cvsroot/jrman/drafts/nurbtest added to the repository |
From: Gerardo H. <ma...@us...> - 2004-08-05 05:31:02
|
Update of /cvsroot/jrman/drafts/slcompiler In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21234 Modified Files: DefaultVisitor.java SLCompiler.java SLCompiler.jj SLCompiler.jjt SLCompilerTreeConstants.java SLCompilerVisitor.java TestsVisitor.java Removed Files: ASTprimary.java Log Message: Removed ASTprimary to make it easier to check for an lvalue on the left of an assignment operator. --- ASTprimary.java DELETED --- Index: SLCompiler.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SLCompiler.java 5 Aug 2004 05:24:51 -0000 1.9 --- SLCompiler.java 5 Aug 2004 05:30:52 -0000 1.10 *************** *** 1908,1965 **** final public void primary() throws ParseException { ! /*@bgen(jjtree) primary */ ! ASTprimary jjtn000 = new ASTprimary(JJTPRIMARY); ! boolean jjtc000 = true; ! jjtree.openNodeScope(jjtn000); ! try { ! switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { ! case INTEGER_LITERAL: ! case FLOATING_POINT_LITERAL: ! number(); ! break; ! case STRING_LITERAL: ! stringconstant(); ! break; ! case TEXTURE: ! case ENVIRONMENT: ! case SHADOW: ! texture(); ! break; ! default: ! jj_la1[41] = jj_gen; ! if (jj_2_8(2)) { ! procedurecall(); ! } else { ! switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { ! case IDENTIFIER: ! lvalue(); ! break; ! case LPAREN: ! single(); ! break; ! default: ! jj_la1[42] = jj_gen; ! jj_consume_token(-1); ! throw new ParseException(); ! } ! } ! } ! } catch (Throwable jjte000) { ! if (jjtc000) { ! jjtree.clearNodeScope(jjtn000); ! jjtc000 = false; } else { ! jjtree.popNode(); ! } ! if (jjte000 instanceof RuntimeException) { ! {if (true) throw (RuntimeException)jjte000;} ! } ! if (jjte000 instanceof ParseException) { ! {if (true) throw (ParseException)jjte000;} ! } ! {if (true) throw (Error)jjte000;} ! } finally { ! if (jjtc000) { ! jjtree.closeNodeScope(jjtn000, true); } } --- 1908,1941 ---- final public void primary() throws ParseException { ! switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { ! case INTEGER_LITERAL: ! case FLOATING_POINT_LITERAL: ! number(); ! break; ! case STRING_LITERAL: ! stringconstant(); ! break; ! case TEXTURE: ! case ENVIRONMENT: ! case SHADOW: ! texture(); ! break; ! default: ! jj_la1[41] = jj_gen; ! if (jj_2_8(2)) { ! procedurecall(); } else { ! switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { ! case IDENTIFIER: ! lvalue(); ! break; ! case LPAREN: ! single(); ! break; ! default: ! jj_la1[42] = jj_gen; ! jj_consume_token(-1); ! throw new ParseException(); ! } } } Index: DefaultVisitor.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/DefaultVisitor.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DefaultVisitor.java 5 Aug 2004 05:10:37 -0000 1.4 --- DefaultVisitor.java 5 Aug 2004 05:30:52 -0000 1.5 *************** *** 80,87 **** } - public Object visit(ASTprimary node, Object data) { - return node.childrenAccept(this, data); - } - public Object visit(ASTnumber node, Object data) { return node.childrenAccept(this, data); --- 80,83 ---- Index: SLCompilerTreeConstants.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompilerTreeConstants.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SLCompilerTreeConstants.java 5 Aug 2004 05:10:37 -0000 1.4 --- SLCompilerTreeConstants.java 5 Aug 2004 05:30:52 -0000 1.5 *************** *** 47,65 **** public int JJTOPERATORUNARYEXPRESSION = 42; public int JJTCASTEXPRESSION = 43; ! public int JJTPRIMARY = 44; ! public int JJTSTATEMENT = 45; ! public int JJTRETURNSTATEMENT = 46; ! public int JJTLOOPMODSTMT = 47; ! public int JJTLOOPMOD = 48; ! public int JJTIFSTATEMENT = 49; ! public int JJTWHILESTATEMENT = 50; ! public int JJTFORSTATEMENT = 51; ! public int JJTSOLARSTATEMENT = 52; ! public int JJTILLUMINATESTATEMENT = 53; ! public int JJTILLUMINANCESTATEMENT = 54; ! public int JJTEXPRESSIONLIST = 55; ! public int JJTVARIABLEDEFINITIONS = 56; ! public int JJTEXTERNSPEC = 57; ! public int JJTSTATEMENTS = 58; --- 47,64 ---- public int JJTOPERATORUNARYEXPRESSION = 42; public int JJTCASTEXPRESSION = 43; ! public int JJTSTATEMENT = 44; ! public int JJTRETURNSTATEMENT = 45; ! public int JJTLOOPMODSTMT = 46; ! public int JJTLOOPMOD = 47; ! public int JJTIFSTATEMENT = 48; ! public int JJTWHILESTATEMENT = 49; ! public int JJTFORSTATEMENT = 50; ! public int JJTSOLARSTATEMENT = 51; ! public int JJTILLUMINATESTATEMENT = 52; ! public int JJTILLUMINANCESTATEMENT = 53; ! public int JJTEXPRESSIONLIST = 54; ! public int JJTVARIABLEDEFINITIONS = 55; ! public int JJTEXTERNSPEC = 56; ! public int JJTSTATEMENTS = 57; *************** *** 109,113 **** "operatorUnaryExpression", "castExpression", - "primary", "statement", "returnStatement", --- 108,111 ---- Index: SLCompilerVisitor.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompilerVisitor.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SLCompilerVisitor.java 5 Aug 2004 05:10:37 -0000 1.4 --- SLCompilerVisitor.java 5 Aug 2004 05:30:52 -0000 1.5 *************** *** 47,51 **** public Object visit(ASToperatorUnaryExpression node, Object data); public Object visit(ASTcastExpression node, Object data); - public Object visit(ASTprimary node, Object data); public Object visit(ASTstatement node, Object data); public Object visit(ASTreturnStatement node, Object data); --- 47,50 ---- Index: SLCompiler.jjt =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.jjt,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SLCompiler.jjt 5 Aug 2004 05:24:51 -0000 1.9 --- SLCompiler.jjt 5 Aug 2004 05:30:52 -0000 1.10 *************** *** 615,619 **** } ! void primary(): {} { --- 615,619 ---- } ! void primary() #void: {} { Index: SLCompiler.jj =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.jj,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SLCompiler.jj 5 Aug 2004 05:24:51 -0000 1.9 --- SLCompiler.jj 5 Aug 2004 05:30:52 -0000 1.10 *************** *** 1769,1781 **** } ! void primary(): ! {/*@bgen(jjtree) primary */ ! ASTprimary jjtn000 = new ASTprimary(JJTPRIMARY); ! boolean jjtc000 = true; ! jjtree.openNodeScope(jjtn000); ! /*@egen*/} ! {/*@bgen(jjtree) primary */ ! try { ! /*@egen*/ number() | stringconstant() --- 1769,1775 ---- } ! void primary() : ! {} ! { number() | stringconstant() *************** *** 1783,1807 **** | LOOKAHEAD(2) procedurecall() | lvalue() ! | single()/*@bgen(jjtree)*/ ! } catch (Throwable jjte000) { ! if (jjtc000) { ! jjtree.clearNodeScope(jjtn000); ! jjtc000 = false; ! } else { ! jjtree.popNode(); ! } ! if (jjte000 instanceof RuntimeException) { ! throw (RuntimeException)jjte000; ! } ! if (jjte000 instanceof ParseException) { ! throw (ParseException)jjte000; ! } ! throw (Error)jjte000; ! } finally { ! if (jjtc000) { ! jjtree.closeNodeScope(jjtn000, true); ! } ! } ! /*@egen*/ } --- 1777,1781 ---- | LOOKAHEAD(2) procedurecall() | lvalue() ! | single() } Index: TestsVisitor.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/TestsVisitor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** TestsVisitor.java 5 Aug 2004 05:10:37 -0000 1.9 --- TestsVisitor.java 5 Aug 2004 05:30:52 -0000 1.10 *************** *** 170,177 **** } - public Object visit(ASTprimary node, Object data) { - return node.jjtGetChild(0).jjtAccept(this, data); - } - public Object visit(ASTsingle node, Object data) { String val = (String) node.jjtGetChild(0).jjtAccept(this, data); --- 170,173 ---- |
From: Gerardo H. <ma...@us...> - 2004-08-05 05:25:00
|
Update of /cvsroot/jrman/drafts/slcompiler In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20612 Modified Files: SLCompiler.java SLCompiler.jj SLCompiler.jjt Log Message: Added inner function definition. Index: SLCompiler.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SLCompiler.java 5 Aug 2004 05:10:37 -0000 1.8 --- SLCompiler.java 5 Aug 2004 05:24:51 -0000 1.9 *************** *** 21,25 **** JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); --- 21,25 ---- JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! // System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); [...1385 lines suppressed...] *** 3629,3633 **** final private void jj_rescan_token() { jj_rescan = true; ! for (int i = 0; i < 10; i++) { JJCalls p = jj_2_rtns[i]; do { --- 3673,3677 ---- final private void jj_rescan_token() { jj_rescan = true; ! for (int i = 0; i < 11; i++) { JJCalls p = jj_2_rtns[i]; do { *************** *** 3645,3648 **** --- 3689,3693 ---- case 8: jj_3_9(); break; case 9: jj_3_10(); break; + case 10: jj_3_11(); break; } } Index: SLCompiler.jjt =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.jjt,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SLCompiler.jjt 5 Aug 2004 05:10:37 -0000 1.8 --- SLCompiler.jjt 5 Aug 2004 05:24:51 -0000 1.9 *************** *** 50,54 **** JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); --- 50,54 ---- JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! // System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); *************** *** 631,634 **** --- 631,635 ---- statements() | LOOKAHEAD(3) variableDefinitions() ";" + | LOOKAHEAD(3) functionDefinition() | expression() ";" | returnStatement() ";" Index: SLCompiler.jj =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.jj,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** SLCompiler.jj 5 Aug 2004 05:10:37 -0000 1.8 --- SLCompiler.jj 5 Aug 2004 05:24:51 -0000 1.9 *************** *** 52,56 **** JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); --- 52,56 ---- JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! // System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); *************** *** 1817,1820 **** --- 1817,1821 ---- statements() | LOOKAHEAD(3) variableDefinitions() ";" + | LOOKAHEAD(3) functionDefinition() | expression() ";" | returnStatement() ";" |
From: Gerardo H. <ma...@us...> - 2004-08-05 05:25:00
|
Update of /cvsroot/jrman/drafts/slcompiler/shaders In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20612/shaders Modified Files: uberlight.sl Log Message: Added inner function definition. Index: uberlight.sl =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/shaders/uberlight.sl,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** uberlight.sl 5 Aug 2004 05:10:37 -0000 1.2 --- uberlight.sl 5 Aug 2004 05:24:51 -0000 1.3 *************** *** 213,218 **** // # include "rayserver.h" - // float sqr (float x) { return x*x; } - /* Superellipse soft clipping * Input: --- 213,216 ---- *************** *** 240,244 **** } else if (roundness > 0.9999) { /* Simple case of a circle */ - // still can't parse inner function definitions :( float sqr (float x) { return x*x; } float q = a * b / sqrt (sqr(b*x) + sqr(a*y)); --- 238,241 ---- |
From: Gerardo H. <ma...@us...> - 2004-08-05 05:10:52
|
Update of /cvsroot/jrman/drafts/slcompiler In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18932 Modified Files: DefaultVisitor.java JavaCharStream.java ParseException.java SLCompiler.java SLCompiler.jj SLCompiler.jjt SLCompilerTokenManager.java SLCompilerTreeConstants.java SLCompilerVisitor.java TestsVisitor.java Token.java TokenMgrError.java Added Files: ASTlvalue.java Log Message: Reorganized grammar. Index: SLCompilerTokenManager.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompilerTokenManager.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SLCompilerTokenManager.java 3 Aug 2004 03:24:37 -0000 1.3 --- SLCompilerTokenManager.java 5 Aug 2004 05:10:37 -0000 1.4 *************** *** 1276,1280 **** 0x4c0L, 0x0L, }; ! private JavaCharStream input_stream; private final int[] jjrounds = new int[48]; private final int[] jjstateSet = new int[96]; --- 1276,1280 ---- 0x4c0L, 0x0L, }; ! protected JavaCharStream input_stream; private final int[] jjrounds = new int[48]; private final int[] jjstateSet = new int[96]; *************** *** 1321,1325 **** } ! private final Token jjFillToken() { Token t = Token.newToken(jjmatchedKind); --- 1321,1325 ---- } ! protected Token jjFillToken() { Token t = Token.newToken(jjmatchedKind); *************** *** 1341,1345 **** int jjmatchedKind; ! public final Token getNextToken() { int kind; --- 1341,1345 ---- int jjmatchedKind; ! public Token getNextToken() { int kind; *************** *** 1465,1469 **** } ! final void SkipLexicalActions(Token matchedToken) { switch(jjmatchedKind) --- 1465,1469 ---- } ! void SkipLexicalActions(Token matchedToken) { switch(jjmatchedKind) Index: TokenMgrError.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/TokenMgrError.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TokenMgrError.java 1 Aug 2004 04:50:40 -0000 1.2 --- TokenMgrError.java 5 Aug 2004 05:10:37 -0000 1.3 *************** *** 1,3 **** ! /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 2.1 */ public class TokenMgrError extends Error { --- 1,3 ---- ! /* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */ public class TokenMgrError extends Error { *************** *** 93,97 **** * Note: You can customize the lexical error message by modifying this method. */ ! private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { return("Lexical error at line " + errorLine + ", column " + --- 93,97 ---- * Note: You can customize the lexical error message by modifying this method. */ ! protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { return("Lexical error at line " + errorLine + ", column " + --- NEW FILE: ASTlvalue.java --- /* Generated By:JJTree: Do not edit this line. ASTlvalue.java */ public class ASTlvalue extends SimpleNode { public ASTlvalue(int id) { super(id); } public ASTlvalue(SLCompiler p, int id) { super(p, id); } /** Accept the visitor. **/ public Object jjtAccept(SLCompilerVisitor visitor, Object data) { return visitor.visit(this, data); } } Index: Token.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/Token.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Token.java 1 Aug 2004 04:50:40 -0000 1.2 --- Token.java 5 Aug 2004 05:10:37 -0000 1.3 *************** *** 1,3 **** ! /* Generated By:JavaCC: Do not edit this line. Token.java Version 2.1 */ /** * Describes the input token stream. --- 1,3 ---- ! /* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */ /** * Describes the input token stream. *************** *** 52,56 **** * Returns the image. */ ! public final String toString() { return image; --- 52,56 ---- * Returns the image. */ ! public String toString() { return image; Index: SLCompiler.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SLCompiler.java 3 Aug 2004 04:43:20 -0000 1.7 --- SLCompiler.java 5 Aug 2004 05:10:37 -0000 1.8 *************** *** 21,25 **** JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); --- 21,25 ---- JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); [...3369 lines suppressed...] JJCalls p = jj_2_rtns[i]; do { *************** *** 4065,4079 **** case 8: jj_3_9(); break; case 9: jj_3_10(); break; - case 10: jj_3_11(); break; - case 11: jj_3_12(); break; - case 12: jj_3_13(); break; - case 13: jj_3_14(); break; - case 14: jj_3_15(); break; - case 15: jj_3_16(); break; - case 16: jj_3_17(); break; - case 17: jj_3_18(); break; - case 18: jj_3_19(); break; - case 19: jj_3_20(); break; - case 20: jj_3_21(); break; } } --- 3645,3648 ---- Index: SLCompiler.jj =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.jj,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SLCompiler.jj 3 Aug 2004 04:43:20 -0000 1.7 --- SLCompiler.jj 5 Aug 2004 05:10:37 -0000 1.8 *************** *** 21,25 **** options { STATIC = false; ! LOOKAHEAD = 1; JAVA_UNICODE_ESCAPE = true; } --- 21,26 ---- options { STATIC = false; ! LOOKAHEAD = 1; ! FORCE_LA_CHECK = false; JAVA_UNICODE_ESCAPE = true; } *************** *** 51,55 **** JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); --- 52,56 ---- JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); *************** *** 517,521 **** try { /*@egen*/ ! formalVariableDefinitions() [";"] (LOOKAHEAD(2) formalVariableDefinitions() ";")*/*@bgen(jjtree)*/ } catch (Throwable jjte000) { if (jjtc000) { --- 518,522 ---- try { /*@egen*/ ! formalVariableDefinitions() (LOOKAHEAD (2) ";" formalVariableDefinitions())* [";"]/*@bgen(jjtree)*/ } catch (Throwable jjte000) { if (jjtc000) { *************** *** 537,541 **** } } ! /*@egen*/ } --- 538,542 ---- } } ! /*@egen*/ } *************** *** 569,573 **** } } ! /*@egen*/ } --- 570,574 ---- } } ! /*@egen*/ } *************** *** 750,792 **** {} { ! conditionalExpression() } ! void primary(): ! {/*@bgen(jjtree) primary */ ! ASTprimary jjtn000 = new ASTprimary(JJTPRIMARY); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); /*@egen*/} ! {/*@bgen(jjtree) primary */ ! try { ! /*@egen*/ ! number() ! | stringconstant() ! | texture() ! | LOOKAHEAD(2) procedurecall() ! | LOOKAHEAD(2) identifier() [LOOKAHEAD(2) arrayindex()] [asgnop() expression()] ! | single()/*@bgen(jjtree)*/ ! } catch (Throwable jjte000) { ! if (jjtc000) { ! jjtree.clearNodeScope(jjtn000); ! jjtc000 = false; ! } else { ! jjtree.popNode(); ! } ! if (jjte000 instanceof RuntimeException) { ! throw (RuntimeException)jjte000; ! } ! if (jjte000 instanceof ParseException) { ! throw (ParseException)jjte000; ! } ! throw (Error)jjte000; ! } finally { ! if (jjtc000) { ! jjtree.closeNodeScope(jjtn000, true); ! } } /*@egen*/ - // assignexpression() | identifier() } --- 751,787 ---- {} { ! assignexpression() } ! void lvalue(): ! {/*@bgen(jjtree) lvalue */ ! ASTlvalue jjtn000 = new ASTlvalue(JJTLVALUE); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); /*@egen*/} ! {/*@bgen(jjtree) lvalue */ ! try { ! /*@egen*/ ! identifier() [LOOKAHEAD(2) arrayindex()]/*@bgen(jjtree)*/ ! } catch (Throwable jjte000) { ! if (jjtc000) { ! jjtree.clearNodeScope(jjtn000); ! jjtc000 = false; ! } else { ! jjtree.popNode(); ! } ! if (jjte000 instanceof RuntimeException) { ! throw (RuntimeException)jjte000; ! } ! if (jjte000 instanceof ParseException) { ! throw (ParseException)jjte000; } + throw (Error)jjte000; + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } /*@egen*/ } *************** *** 1106,1141 **** } - void assignexpression(): - {/*@bgen(jjtree) assignexpression */ - ASTassignexpression jjtn000 = new ASTassignexpression(JJTASSIGNEXPRESSION); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000); - /*@egen*/} - {/*@bgen(jjtree) assignexpression */ - try { - /*@egen*/ - identifier() [arrayindex()] asgnop() expression()/*@bgen(jjtree)*/ - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - throw (RuntimeException)jjte000; - } - if (jjte000 instanceof ParseException) { - throw (ParseException)jjte000; - } - throw (Error)jjte000; - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } - /*@egen*/ - } - void asgnop(): {/*@bgen(jjtree) asgnop */ --- 1101,1104 ---- *************** *** 1364,1367 **** --- 1327,1365 ---- } + void assignexpression() : + {} + {/*@bgen(jjtree) #assignexpression(> 1) */ + { + ASTassignexpression jjtn001 = new ASTassignexpression(JJTASSIGNEXPRESSION); + boolean jjtc001 = true; + jjtree.openNodeScope(jjtn001); + } + try { + /*@egen*/ + ( + conditionalExpression() (asgnop() conditionalExpression())* + )/*@bgen(jjtree)*/ + } catch (Throwable jjte001) { + if (jjtc001) { + jjtree.clearNodeScope(jjtn001); + jjtc001 = false; + } else { + jjtree.popNode(); + } + if (jjte001 instanceof RuntimeException) { + throw (RuntimeException)jjte001; + } + if (jjte001 instanceof ParseException) { + throw (ParseException)jjte001; + } + throw (Error)jjte001; + } finally { + if (jjtc001) { + jjtree.closeNodeScope(jjtn001, jjtree.nodeArity() > 1); + } + } + /*@egen*/ + } + void conditionalExpression() : *************** *** 1377,1381 **** ( conditionalOrExpression() ! [LOOKAHEAD(2) "?" expression() ":" conditionalExpression() ] )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1375,1379 ---- ( conditionalOrExpression() ! [ "?" expression() ":" conditionalExpression() ] )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1412,1416 **** /*@egen*/ ( ! conditionalAndExpression() (LOOKAHEAD(2) "||" conditionalAndExpression() )* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1410,1414 ---- /*@egen*/ ( ! conditionalAndExpression() ("||" conditionalAndExpression() )* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1447,1451 **** /*@egen*/ ( ! equalityExpression() (LOOKAHEAD(2) "&&" equalityExpression() )* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1445,1449 ---- /*@egen*/ ( ! equalityExpression() ("&&" equalityExpression() )* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1483,1487 **** ( relationalExpression() ! [LOOKAHEAD(2) ( t = "==" | t = "!=" ) relationalExpression() { jjtn001.type = t.image; }] )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1481,1485 ---- ( relationalExpression() ! [( t = "==" | t = "!=" ) relationalExpression() { jjtn001.type = t.image; }] )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1519,1526 **** ( additiveExpression() ! [LOOKAHEAD(2) ( t = "<" ! | t = ">" ! | t = "<=" ! | t = ">=" ) additiveExpression() { jjtn001.type = t.image; }] )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1517,1524 ---- ( additiveExpression() ! [ ( t = "<" ! | t = ">" ! | t = "<=" ! | t = ">=" ) additiveExpression() { jjtn001.type = t.image; }] )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1558,1562 **** ( crossExpression() ! (LOOKAHEAD(2) ( t = "+" | t = "-" ) crossExpression() { jjtn001.add(t.image); })* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1556,1560 ---- ( crossExpression() ! (( t = "+" | t = "-" ) crossExpression() { jjtn001.add(t.image); })* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1594,1598 **** ( multiplicativeExpression() ! (LOOKAHEAD(2) ( t = "^" ) multiplicativeExpression() { jjtn001.add(t.image); })* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1592,1596 ---- ( multiplicativeExpression() ! (t = "^" multiplicativeExpression() { jjtn001.add(t.image); })* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1630,1635 **** ( dotExpression() ! (LOOKAHEAD(2) ( t = "*" ! | t = "/" ) dotExpression() { jjtn001.add(t.image); })* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1628,1632 ---- ( dotExpression() ! (( t = "*" | t = "/" ) dotExpression() { jjtn001.add(t.image); })* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1667,1671 **** ( unaryExpression() ! [LOOKAHEAD(2) ( t = "." ) unaryExpression() { jjtn001.add(t.image); }] )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1664,1668 ---- ( unaryExpression() ! [t = "." unaryExpression() { jjtn001.add(t.image); }] )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1772,1775 **** --- 1769,1809 ---- } + void primary(): + {/*@bgen(jjtree) primary */ + ASTprimary jjtn000 = new ASTprimary(JJTPRIMARY); + boolean jjtc000 = true; + jjtree.openNodeScope(jjtn000); + /*@egen*/} + {/*@bgen(jjtree) primary */ + try { + /*@egen*/ + number() + | stringconstant() + | texture() + | LOOKAHEAD(2) procedurecall() + | lvalue() + | single()/*@bgen(jjtree)*/ + } catch (Throwable jjte000) { + if (jjtc000) { + jjtree.clearNodeScope(jjtn000); + jjtc000 = false; + } else { + jjtree.popNode(); + } + if (jjte000 instanceof RuntimeException) { + throw (RuntimeException)jjte000; + } + if (jjte000 instanceof ParseException) { + throw (ParseException)jjte000; + } + throw (Error)jjte000; + } finally { + if (jjtc000) { + jjtree.closeNodeScope(jjtn000, true); + } + } + /*@egen*/ + } + void statement() : {/*@bgen(jjtree) statement */ *************** *** 1782,1790 **** /*@egen*/ statements() ! | LOOKAHEAD(2) assignexpression() ";" ! | variableDefinitions() ";" ! | procedurecall() ";" | returnStatement() ";" ! | loopModStmt() | ifStatement() | loopControl()/*@bgen(jjtree)*/ --- 1816,1823 ---- /*@egen*/ statements() ! | LOOKAHEAD(3) variableDefinitions() ";" ! | expression() ";" | returnStatement() ";" ! | loopModStmt() ";" | ifStatement() | loopControl()/*@bgen(jjtree)*/ *************** *** 2216,2220 **** try { /*@egen*/ ! "{" ( blockStatement() )* "}"/*@bgen(jjtree)*/ } catch (Throwable jjte000) { if (jjtc000) { --- 2249,2253 ---- try { /*@egen*/ ! "{" ( statement() )* "}"/*@bgen(jjtree)*/ } catch (Throwable jjte000) { if (jjtc000) { *************** *** 2238,2248 **** /*@egen*/ } - - void blockStatement() : - {} - { - LOOKAHEAD(3) formals() - | statement() - } - - --- 2271,2272 ---- Index: JavaCharStream.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/JavaCharStream.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JavaCharStream.java 1 Aug 2004 04:50:40 -0000 1.2 --- JavaCharStream.java 5 Aug 2004 05:10:37 -0000 1.3 *************** *** 1,3 **** ! /* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 2.1 */ /** * An implementation of interface CharStream, where the stream is assumed to --- 1,3 ---- ! /* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 3.0 */ /** * An implementation of interface CharStream, where the stream is assumed to *************** *** 5,9 **** */ ! public final class JavaCharStream { public static final boolean staticFlag = false; --- 5,9 ---- */ ! public class JavaCharStream { public static final boolean staticFlag = false; *************** *** 59,80 **** int available; int tokenBegin; ! private int bufline[]; ! private int bufcolumn[]; ! private int column = 0; ! private int line = 1; ! private boolean prevCharIsCR = false; ! private boolean prevCharIsLF = false; ! private java.io.Reader inputStream; ! private char[] nextCharBuf; ! private char[] buffer; ! private int maxNextCharInd = 0; ! private int nextCharInd = -1; ! private int inBuf = 0; ! private final void ExpandBuff(boolean wrapAround) { char[] newbuffer = new char[bufsize + 2048]; --- 59,80 ---- int available; int tokenBegin; ! protected int bufline[]; ! protected int bufcolumn[]; ! protected int column = 0; ! protected int line = 1; ! protected boolean prevCharIsCR = false; ! protected boolean prevCharIsLF = false; ! protected java.io.Reader inputStream; ! protected char[] nextCharBuf; ! protected char[] buffer; ! protected int maxNextCharInd = 0; ! protected int nextCharInd = -1; ! protected int inBuf = 0; ! protected void ExpandBuff(boolean wrapAround) { char[] newbuffer = new char[bufsize + 2048]; *************** *** 124,128 **** } ! private final void FillBuff() throws java.io.IOException { int i; --- 124,128 ---- } ! protected void FillBuff() throws java.io.IOException { int i; *************** *** 156,160 **** } ! private final char ReadByte() throws java.io.IOException { if (++nextCharInd >= maxNextCharInd) --- 156,160 ---- } ! protected char ReadByte() throws java.io.IOException { if (++nextCharInd >= maxNextCharInd) *************** *** 164,168 **** } ! public final char BeginToken() throws java.io.IOException { if (inBuf > 0) --- 164,168 ---- } ! public char BeginToken() throws java.io.IOException { if (inBuf > 0) *************** *** 183,187 **** } ! private final void AdjustBuffSize() { if (available == bufsize) --- 183,187 ---- } ! protected void AdjustBuffSize() { if (available == bufsize) *************** *** 203,207 **** } ! private final void UpdateLineColumn(char c) { column++; --- 203,207 ---- } ! protected void UpdateLineColumn(char c) { column++; *************** *** 243,247 **** } ! public final char readChar() throws java.io.IOException { if (inBuf > 0) --- 243,247 ---- } ! public char readChar() throws java.io.IOException { if (inBuf > 0) *************** *** 340,344 **** */ ! public final int getColumn() { return bufcolumn[bufpos]; } --- 340,344 ---- */ ! public int getColumn() { return bufcolumn[bufpos]; } *************** *** 349,373 **** */ ! public final int getLine() { return bufline[bufpos]; } ! public final int getEndColumn() { return bufcolumn[bufpos]; } ! public final int getEndLine() { return bufline[bufpos]; } ! public final int getBeginColumn() { return bufcolumn[tokenBegin]; } ! public final int getBeginLine() { return bufline[tokenBegin]; } ! public final void backup(int amount) { inBuf += amount; --- 349,373 ---- */ ! public int getLine() { return bufline[bufpos]; } ! public int getEndColumn() { return bufcolumn[bufpos]; } ! public int getEndLine() { return bufline[bufpos]; } ! public int getBeginColumn() { return bufcolumn[tokenBegin]; } ! public int getBeginLine() { return bufline[tokenBegin]; } ! public void backup(int amount) { inBuf += amount; *************** *** 462,466 **** } ! public final String GetImage() { if (bufpos >= tokenBegin) --- 462,466 ---- } ! public String GetImage() { if (bufpos >= tokenBegin) *************** *** 471,475 **** } ! public final char[] GetSuffix(int len) { char[] ret = new char[len]; --- 471,475 ---- } ! public char[] GetSuffix(int len) { char[] ret = new char[len]; *************** *** 496,500 **** /** ! * Method to adjust line and column numbers for the start of a token.<BR> */ public void adjustBeginLineColumn(int newLine, int newCol) --- 496,500 ---- /** ! * Method to adjust line and column numbers for the start of a token. */ public void adjustBeginLineColumn(int newLine, int newCol) Index: DefaultVisitor.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/DefaultVisitor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DefaultVisitor.java 2 Aug 2004 05:45:21 -0000 1.3 --- DefaultVisitor.java 5 Aug 2004 05:10:37 -0000 1.4 *************** *** 252,255 **** --- 252,259 ---- } + public Object visit(ASTlvalue node, Object data) { + return node.childrenAccept(this, data); + } + } Index: SLCompilerTreeConstants.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompilerTreeConstants.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SLCompilerTreeConstants.java 2 Aug 2004 05:45:21 -0000 1.3 --- SLCompilerTreeConstants.java 5 Aug 2004 05:10:37 -0000 1.4 *************** *** 18,22 **** public int JJTDEFEXPRESSION = 13; public int JJTDEFINIT = 14; ! public int JJTPRIMARY = 15; public int JJTNUMBER = 16; public int JJTSTRINGCONSTANT = 17; --- 18,22 ---- public int JJTDEFEXPRESSION = 13; public int JJTDEFINIT = 14; ! public int JJTLVALUE = 15; public int JJTNUMBER = 16; public int JJTSTRINGCONSTANT = 17; *************** *** 29,39 **** public int JJTPROCEDURECALL = 24; public int JJTPROCARGUMENTS = 25; ! public int JJTASSIGNEXPRESSION = 26; ! public int JJTASGNOP = 27; ! public int JJTSINGLE = 28; ! public int JJTTRIPLE = 29; ! public int JJTSIXTEENTUPLE = 30; ! public int JJTTYPECAST = 31; ! public int JJTSPACETYPE = 32; public int JJTCONDITIONALEXPRESSION = 33; public int JJTCONDITIONALOREXPRESSION = 34; --- 29,39 ---- public int JJTPROCEDURECALL = 24; public int JJTPROCARGUMENTS = 25; ! public int JJTASGNOP = 26; ! public int JJTSINGLE = 27; ! public int JJTTRIPLE = 28; ! public int JJTSIXTEENTUPLE = 29; ! public int JJTTYPECAST = 30; ! public int JJTSPACETYPE = 31; ! public int JJTASSIGNEXPRESSION = 32; public int JJTCONDITIONALEXPRESSION = 33; public int JJTCONDITIONALOREXPRESSION = 34; *************** *** 47,64 **** public int JJTOPERATORUNARYEXPRESSION = 42; public int JJTCASTEXPRESSION = 43; ! public int JJTSTATEMENT = 44; ! public int JJTRETURNSTATEMENT = 45; ! public int JJTLOOPMODSTMT = 46; ! public int JJTLOOPMOD = 47; ! public int JJTIFSTATEMENT = 48; ! public int JJTWHILESTATEMENT = 49; ! public int JJTFORSTATEMENT = 50; ! public int JJTSOLARSTATEMENT = 51; ! public int JJTILLUMINATESTATEMENT = 52; ! public int JJTILLUMINANCESTATEMENT = 53; ! public int JJTEXPRESSIONLIST = 54; ! public int JJTVARIABLEDEFINITIONS = 55; ! public int JJTEXTERNSPEC = 56; ! public int JJTSTATEMENTS = 57; --- 47,65 ---- public int JJTOPERATORUNARYEXPRESSION = 42; public int JJTCASTEXPRESSION = 43; ! public int JJTPRIMARY = 44; ! public int JJTSTATEMENT = 45; ! public int JJTRETURNSTATEMENT = 46; ! public int JJTLOOPMODSTMT = 47; ! public int JJTLOOPMOD = 48; ! public int JJTIFSTATEMENT = 49; ! public int JJTWHILESTATEMENT = 50; ! public int JJTFORSTATEMENT = 51; ! public int JJTSOLARSTATEMENT = 52; ! public int JJTILLUMINATESTATEMENT = 53; ! public int JJTILLUMINANCESTATEMENT = 54; ! public int JJTEXPRESSIONLIST = 55; ! public int JJTVARIABLEDEFINITIONS = 56; ! public int JJTEXTERNSPEC = 57; ! public int JJTSTATEMENTS = 58; *************** *** 79,83 **** "defExpression", "defInit", ! "primary", "number", "stringconstant", --- 80,84 ---- "defExpression", "defInit", ! "lvalue", "number", "stringconstant", *************** *** 90,94 **** "procedurecall", "procArguments", - "assignexpression", "asgnop", "single", --- 91,94 ---- *************** *** 97,100 **** --- 97,101 ---- "typecast", "spacetype", + "assignexpression", "conditionalExpression", "conditionalOrExpression", *************** *** 108,111 **** --- 109,113 ---- "operatorUnaryExpression", "castExpression", + "primary", "statement", "returnStatement", Index: SLCompilerVisitor.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompilerVisitor.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SLCompilerVisitor.java 2 Aug 2004 05:45:21 -0000 1.3 --- SLCompilerVisitor.java 5 Aug 2004 05:10:37 -0000 1.4 *************** *** 18,22 **** public Object visit(ASTdefExpression node, Object data); public Object visit(ASTdefInit node, Object data); ! public Object visit(ASTprimary node, Object data); public Object visit(ASTnumber node, Object data); public Object visit(ASTstringconstant node, Object data); --- 18,22 ---- public Object visit(ASTdefExpression node, Object data); public Object visit(ASTdefInit node, Object data); ! public Object visit(ASTlvalue node, Object data); public Object visit(ASTnumber node, Object data); public Object visit(ASTstringconstant node, Object data); *************** *** 29,33 **** public Object visit(ASTprocedurecall node, Object data); public Object visit(ASTprocArguments node, Object data); - public Object visit(ASTassignexpression node, Object data); public Object visit(ASTasgnop node, Object data); public Object visit(ASTsingle node, Object data); --- 29,32 ---- *************** *** 36,39 **** --- 35,39 ---- public Object visit(ASTtypecast node, Object data); public Object visit(ASTspacetype node, Object data); + public Object visit(ASTassignexpression node, Object data); public Object visit(ASTconditionalExpression node, Object data); public Object visit(ASTconditionalOrExpression node, Object data); *************** *** 47,50 **** --- 47,51 ---- public Object visit(ASToperatorUnaryExpression node, Object data); public Object visit(ASTcastExpression node, Object data); + public Object visit(ASTprimary node, Object data); public Object visit(ASTstatement node, Object data); public Object visit(ASTreturnStatement node, Object data); Index: SLCompiler.jjt =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.jjt,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SLCompiler.jjt 3 Aug 2004 04:43:20 -0000 1.7 --- SLCompiler.jjt 5 Aug 2004 05:10:37 -0000 1.8 *************** *** 22,25 **** --- 22,26 ---- MULTI = true; LOOKAHEAD = 1; + FORCE_LA_CHECK = false; VISITOR = true; JAVA_UNICODE_ESCAPE = true; *************** *** 49,53 **** JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); --- 50,54 ---- JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); *************** *** 325,329 **** {} { ! formalVariableDefinitions() [";"] (LOOKAHEAD(2) formalVariableDefinitions() ";")* } --- 326,330 ---- {} { ! formalVariableDefinitions() (LOOKAHEAD (2) ";" formalVariableDefinitions())* [";"] } *************** *** 331,335 **** {} { ! [outputspec()] typespec() defExpressions() } --- 332,336 ---- {} { ! [outputspec()] typespec() defExpressions() } *************** *** 374,390 **** {} { ! conditionalExpression() } ! void primary(): {} ! { ! number() ! | stringconstant() ! | texture() ! | LOOKAHEAD(2) procedurecall() ! | LOOKAHEAD(2) identifier() [LOOKAHEAD(2) arrayindex()] [asgnop() expression()] ! | single() ! // assignexpression() | identifier() } --- 375,385 ---- {} { ! assignexpression() } ! void lvalue(): {} ! { ! identifier() [LOOKAHEAD(2) arrayindex()] } *************** *** 456,465 **** } - void assignexpression(): - {} - { - identifier() [arrayindex()] asgnop() expression() - } - void asgnop(): { Token t; } --- 451,454 ---- *************** *** 511,514 **** --- 500,511 ---- } + void assignexpression() #void: + {} + { + ( + conditionalExpression() (asgnop() conditionalExpression())* + ) #assignexpression(>1) + } + void conditionalExpression() #void : *************** *** 517,521 **** ( conditionalOrExpression() ! [LOOKAHEAD(2) "?" expression() ":" conditionalExpression() ] ) #conditionalExpression(>1) } --- 514,518 ---- ( conditionalOrExpression() ! [ "?" expression() ":" conditionalExpression() ] ) #conditionalExpression(>1) } *************** *** 525,529 **** { ( ! conditionalAndExpression() (LOOKAHEAD(2) "||" conditionalAndExpression() )* ) #conditionalOrExpression(>1) } --- 522,526 ---- { ( ! conditionalAndExpression() ("||" conditionalAndExpression() )* ) #conditionalOrExpression(>1) } *************** *** 533,537 **** { ( ! equalityExpression() (LOOKAHEAD(2) "&&" equalityExpression() )* ) #conditionalAndExpression(>1) } --- 530,534 ---- { ( ! equalityExpression() ("&&" equalityExpression() )* ) #conditionalAndExpression(>1) } *************** *** 542,546 **** ( relationalExpression() ! [LOOKAHEAD(2) ( t = "==" | t = "!=" ) relationalExpression() { jjtThis.type = t.image; }] ) #equalityExpression(>1) } --- 539,543 ---- ( relationalExpression() ! [( t = "==" | t = "!=" ) relationalExpression() { jjtThis.type = t.image; }] ) #equalityExpression(>1) } *************** *** 551,558 **** ( additiveExpression() ! [LOOKAHEAD(2) ( t = "<" ! | t = ">" ! | t = "<=" ! | t = ">=" ) additiveExpression() { jjtThis.type = t.image; }] ) #relationalExpression(>1) } --- 548,555 ---- ( additiveExpression() ! [ ( t = "<" ! | t = ">" ! | t = "<=" ! | t = ">=" ) additiveExpression() { jjtThis.type = t.image; }] ) #relationalExpression(>1) } *************** *** 563,567 **** ( crossExpression() ! (LOOKAHEAD(2) ( t = "+" | t = "-" ) crossExpression() { jjtThis.add(t.image); })* ) #additiveExpression(>1) } --- 560,564 ---- ( crossExpression() ! (( t = "+" | t = "-" ) crossExpression() { jjtThis.add(t.image); })* ) #additiveExpression(>1) } *************** *** 572,576 **** ( multiplicativeExpression() ! (LOOKAHEAD(2) ( t = "^" ) multiplicativeExpression() { jjtThis.add(t.image); })* ) #crossExpression(>1) } --- 569,573 ---- ( multiplicativeExpression() ! (t = "^" multiplicativeExpression() { jjtThis.add(t.image); })* ) #crossExpression(>1) } *************** *** 581,586 **** ( dotExpression() ! (LOOKAHEAD(2) ( t = "*" ! | t = "/" ) dotExpression() { jjtThis.add(t.image); })* ) #multiplicativeExpression(>1) } --- 578,582 ---- ( dotExpression() ! (( t = "*" | t = "/" ) dotExpression() { jjtThis.add(t.image); })* ) #multiplicativeExpression(>1) } *************** *** 591,595 **** ( unaryExpression() ! [LOOKAHEAD(2) ( t = "." ) unaryExpression() { jjtThis.add(t.image); }] ) #dotExpression(>1) } --- 587,591 ---- ( unaryExpression() ! [t = "." unaryExpression() { jjtThis.add(t.image); }] ) #dotExpression(>1) } *************** *** 619,631 **** } void statement() : {} { statements() ! | LOOKAHEAD(2) assignexpression() ";" ! | variableDefinitions() ";" ! | procedurecall() ";" | returnStatement() ";" ! | loopModStmt() | ifStatement() | loopControl() --- 615,637 ---- } + void primary(): + {} + { + number() + | stringconstant() + | texture() + | LOOKAHEAD(2) procedurecall() + | lvalue() + | single() + } + void statement() : {} { statements() ! | LOOKAHEAD(3) variableDefinitions() ";" ! | expression() ";" | returnStatement() ";" ! | loopModStmt() ";" | ifStatement() | loopControl() *************** *** 737,749 **** {} { ! "{" ( blockStatement() )* "}" ! } ! ! void blockStatement() #void : ! {} ! { ! LOOKAHEAD(3) formals() ! | statement() } - - --- 743,746 ---- {} { ! "{" ( statement() )* "}" } Index: TestsVisitor.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/TestsVisitor.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** TestsVisitor.java 3 Aug 2004 04:43:20 -0000 1.8 --- TestsVisitor.java 5 Aug 2004 05:10:37 -0000 1.9 *************** *** 153,163 **** public Object visit(ASTassignexpression node, Object data) { String var = (String) node.jjtGetChild(0).jjtAccept(this, data); ! String op = (String) node.jjtGetChild(1).jjtAccept(this, data); ! String val = (String) node.jjtGetChild(2).jjtAccept(this, data); ! if (op.equals("=")) ! code.add(var + " <- " + val); ! else { ! op = op.substring(0, 1); ! code.add(var + " <- " + var + " " + op + " " + val); } return var; --- 153,165 ---- public Object visit(ASTassignexpression node, Object data) { String var = (String) node.jjtGetChild(0).jjtAccept(this, data); ! if (node.jjtGetNumChildren() == 3) { ! String op = (String) node.jjtGetChild(1).jjtAccept(this, data); ! String val = (String) node.jjtGetChild(2).jjtAccept(this, data); ! if (op.equals("=")) ! code.add(var + " <- " + val); ! else { ! op = op.substring(0, 1); ! code.add(var + " <- " + var + " " + op + " " + val); ! } } return var; *************** *** 513,516 **** --- 515,522 ---- } + public Object visit(ASTlvalue node, Object data) { + return node.jjtGetChild(0).jjtAccept(this, data); + } + void showCode() { for (Iterator iter = code.iterator(); iter.hasNext(); ) Index: ParseException.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/ParseException.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ParseException.java 1 Aug 2004 04:50:40 -0000 1.2 --- ParseException.java 5 Aug 2004 05:10:37 -0000 1.3 *************** *** 1,3 **** ! /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 2.1 */ /** * This exception is thrown when parse errors are encountered. --- 1,3 ---- ! /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ /** * This exception is thrown when parse errors are encountered. |
From: Gerardo H. <ma...@us...> - 2004-08-05 05:10:50
|
Update of /cvsroot/jrman/drafts/slcompiler/shaders In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18932/shaders Modified Files: uberlight.sl Log Message: Reorganized grammar. Index: uberlight.sl =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/shaders/uberlight.sl,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** uberlight.sl 3 Aug 2004 03:24:37 -0000 1.1 --- uberlight.sl 5 Aug 2004 05:10:37 -0000 1.2 *************** *** 211,217 **** * PRMan together. */ ! #include "rayserver.h" ! /* Superellipse soft clipping --- 211,217 ---- * PRMan together. */ ! // # include "rayserver.h" + // float sqr (float x) { return x*x; } /* Superellipse soft clipping *************** *** 240,243 **** --- 240,244 ---- } else if (roundness > 0.9999) { /* Simple case of a circle */ + // still can't parse inner function definitions :( float sqr (float x) { return x*x; } float q = a * b / sqrt (sqr(b*x) + sqr(a*y)); *************** *** 397,412 **** */ point PL = transform ("shader", Ps); ! #ifdef BMRT ! /* If it's an area light, we want the point and normal of the light ! * geometry. If not an area light, BMRT guarantees P,N will be the ! * origin and z-axis of shader space. ! */ ! point from = P; ! vector axis = normalize(N); ! #else /* For PRMan, we've gotta do it the hard way */ point from = point "shader" (0,0,0); vector axis = normalize(vector "shader" (0,0,1)); ! #endif uniform float angle; if (lighttype == "spot") { /* Spot light */ --- 398,413 ---- */ point PL = transform ("shader", Ps); ! // #ifdef BMRT ! // /* If it's an area light, we want the point and normal of the light ! // * geometry. If not an area light, BMRT guarantees P,N will be the ! // * origin and z-axis of shader space. ! // */ ! // point from = P; ! // vector axis = normalize(N); ! // #else /* For PRMan, we've gotta do it the hard way */ point from = point "shader" (0,0,0); vector axis = normalize(vector "shader" (0,0,1)); ! // #endif uniform float angle; if (lighttype == "spot") { /* Spot light */ *************** *** 451,455 **** /* Apply noise */ if (noiseamp > 0) { ! #pragma nolint float n = noise (noisefreq * (PL+noiseoffset) * point(1,1,0)); n = smoothstep (0, 1, 0.5 + noiseamp * (n-0.5)); --- 452,456 ---- /* Apply noise */ if (noiseamp > 0) { ! // #pragma nolint float n = noise (noisefreq * (PL+noiseoffset) * point(1,1,0)); n = smoothstep (0, 1, 0.5 + noiseamp * (n-0.5)); *************** *** 467,483 **** shadoworigin = from; else shadoworigin = point "shader" (xcomp(PL), ycomp(PL), cuton); ! #if (defined(BMRT) || defined(RAYSERVER_H)) ! /* If we can, apply ray cast shadows. Force a ray trace if ! * we're in BMRT and the user wanted a shadow map. ! */ ! if (raytraceshadow != 0) { ! color vis = 0; ! uniform float i; ! for (i = 0; i < nshadowrays; i += 1) ! vis += visibility (Ps, shadoworigin+shadowcheat); ! vis /= nshadowrays; ! unoccluded *= (comp(vis,0)+comp(vis,1)+comp(vis,2))/3; ! } ! #endif /* Apply blocker fake shadows */ if (blockercoords != "") { --- 468,484 ---- shadoworigin = from; else shadoworigin = point "shader" (xcomp(PL), ycomp(PL), cuton); ! // # if (defined(BMRT) || defined(RAYSERVER_H)) ! // /* If we can, apply ray cast shadows. Force a ray trace if ! // * we're in BMRT and the user wanted a shadow map. ! // */ ! // if (raytraceshadow != 0) { ! // color vis = 0; ! // uniform float i; ! // for (i = 0; i < nshadowrays; i += 1) ! // vis += visibility (Ps, shadoworigin+shadowcheat); ! // vis /= nshadowrays; ! // unoccluded *= (comp(vis,0)+comp(vis,1)+comp(vis,2))/3; ! // } ! // #endif /* Apply blocker fake shadows */ if (blockercoords != "") { |
From: Gerardo H. <ma...@us...> - 2004-08-03 04:43:30
|
Update of /cvsroot/jrman/drafts/slcompiler In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9615 Modified Files: SLCompiler.java SLCompiler.jj SLCompiler.jjt TestsVisitor.java Log Message: More test code compilation. Large example with shaders/brushedmetal-p.sl (brushedmetal.sl preprocessed with cpp...) Index: SLCompiler.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SLCompiler.java 3 Aug 2004 03:24:36 -0000 1.6 --- SLCompiler.java 3 Aug 2004 04:43:20 -0000 1.7 *************** *** 21,25 **** JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); --- 21,25 ---- JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); Index: SLCompiler.jjt =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.jjt,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SLCompiler.jjt 3 Aug 2004 03:24:37 -0000 1.6 --- SLCompiler.jjt 3 Aug 2004 04:43:20 -0000 1.7 *************** *** 49,53 **** JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); --- 49,53 ---- JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); *************** *** 287,291 **** } ! void functionDefinition(): {} { --- 287,291 ---- } ! void functionDefinition(): // in-line function definitions?? {} { Index: SLCompiler.jj =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.jj,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SLCompiler.jj 3 Aug 2004 03:24:37 -0000 1.6 --- SLCompiler.jj 3 Aug 2004 04:43:20 -0000 1.7 *************** *** 51,55 **** JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); --- 51,55 ---- JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); *************** *** 341,345 **** } ! void functionDefinition(): {/*@bgen(jjtree) functionDefinition */ ASTfunctionDefinition jjtn000 = new ASTfunctionDefinition(JJTFUNCTIONDEFINITION); --- 341,345 ---- } ! void functionDefinition(): // in-line function definitions?? {/*@bgen(jjtree) functionDefinition */ ASTfunctionDefinition jjtn000 = new ASTfunctionDefinition(JJTFUNCTIONDEFINITION); Index: TestsVisitor.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/TestsVisitor.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TestsVisitor.java 3 Aug 2004 03:24:37 -0000 1.7 --- TestsVisitor.java 3 Aug 2004 04:43:20 -0000 1.8 *************** *** 22,112 **** public class TestsVisitor extends DefaultVisitor { - String currentType; - - String currentDetail = "uniform"; - - boolean inDeclaration; - - SymbolTable st = new SymbolTable(); - List code = new ArrayList(); - boolean waitingForShaderName; - - boolean waitingForFunctionName; - int tempCounter; public Object visit(ASTidentifier node, Object data) { - if (waitingForShaderName) { - st.put(node.name, new TypeInfo("shader", "none", currentType)); - waitingForShaderName = false; - } else if (waitingForFunctionName) { - st.put(node.name, new TypeInfo("function", "none", currentType)); - waitingForFunctionName = false; - } else if (inDeclaration) { - if (st.get(node.name) == null) - st.put(node.name, new TypeInfo("variable", currentDetail, currentType)); - else - System.out.println("Already defined: " + node.name); - } else if (st.get(node.name) == null) - System.out.println("Undefined: " + node.name); return node.name; } public Object visit(ASTtype node, Object data) { ! currentType = node.type; ! return data; } public Object visit(ASTdetail node, Object data) { ! currentDetail = node.type; ! return data; } public Object visit(ASTformalVariableDefinitions node, Object data) { ! inDeclaration = true; ! data = node.childrenAccept(this, data); ! currentDetail = "uniform"; ! inDeclaration = false; return data; } public Object visit(ASTdefExpression node, Object data) { if (node.jjtGetNumChildren() == 2) { - String var = (String) node.jjtGetChild(0).jjtAccept(this, data); String val = (String) node.jjtGetChild(1).jjtAccept(this, data); ! code.add(var + " <- " + val); ! } return data; } public Object visit(ASTdefInit node, Object data) { ! inDeclaration = false; ! data = node.jjtGetChild(0).jjtAccept(this, data); ! inDeclaration = true; ! return data; } public Object visit(ASTcompilationUnit node, Object data) { ! data = node.childrenAccept(this, data); ! System.out.println(st); ! return data; } public Object visit(ASTshaderDefinition node, Object data) { ! waitingForShaderName = true; ! return node.childrenAccept(this, data); } public Object visit(ASTshaderType node, Object data) { ! currentType = node.type; ! return data; } public Object visit(ASTfunctionDefinition node, Object data) { ! waitingForFunctionName = true; ! currentType = "float"; ! return node.childrenAccept(this, data); } --- 22,152 ---- public class TestsVisitor extends DefaultVisitor { List code = new ArrayList(); int tempCounter; public Object visit(ASTidentifier node, Object data) { return node.name; } public Object visit(ASTtype node, Object data) { ! return node.type; } public Object visit(ASTdetail node, Object data) { ! return node.type; ! } ! ! public Object visit(ASTtypespec node, Object data) { ! StringBuffer sb = new StringBuffer(); ! sb.append(node.jjtGetChild(0).jjtAccept(this, data)); ! if (node.jjtGetNumChildren() == 2) ! sb.append(' ').append(node.jjtGetChild(1).jjtAccept(this, data)); ! return sb.toString(); ! } ! ! public Object visit(ASToutputspec node, Object data) { ! return "output"; } public Object visit(ASTformalVariableDefinitions node, Object data) { ! StringBuffer sb = new StringBuffer(); ! int next = 0; ! Node nd = node.jjtGetChild(next++); ! if (nd instanceof ASToutputspec) { ! sb.append(nd.jjtAccept(this, data)).append(' '); ! nd = node.jjtGetChild(next++); ! } ! sb.append(nd.jjtAccept(this, data)); ! String type = sb.toString(); ! int n = node.jjtGetNumChildren(); ! while (next < n) ! node.jjtGetChild(next++).jjtAccept(this, type); ! return data; ! } ! ! public Object visit(ASTexternspec node, Object data) { ! return "extern"; ! } ! ! public Object visit(ASTvariableDefinitions node, Object data) { ! StringBuffer sb = new StringBuffer(); ! int next = 0; ! Node nd = node.jjtGetChild(next++); ! if (nd instanceof ASTexternspec) { ! sb.append(nd.jjtAccept(this, data)).append(' '); ! nd = node.jjtGetChild(next++); ! } ! sb.append(nd.jjtAccept(this, data)); ! String type = sb.toString(); ! int n = node.jjtGetNumChildren(); ! while (next < n) ! node.jjtGetChild(next++).jjtAccept(this, type); ! return data; ! } ! ! public Object visit(ASTreturnStatement node, Object data) { ! String val = (String) node.jjtGetChild(0).jjtAccept(this, data); ! code.add("return " + val); return data; } public Object visit(ASTdefExpression node, Object data) { + String type = (String) data; + String var = (String) node.jjtGetChild(0).jjtAccept(this, data); if (node.jjtGetNumChildren() == 2) { String val = (String) node.jjtGetChild(1).jjtAccept(this, data); ! code.add(data + ": " + var + " <- " + val); ! } else ! code.add(data + ": " + var); return data; } public Object visit(ASTdefInit node, Object data) { ! return node.jjtGetChild(0).jjtAccept(this, data); } public Object visit(ASTcompilationUnit node, Object data) { ! return node.childrenAccept(this, data); } public Object visit(ASTshaderDefinition node, Object data) { ! String type = (String) node.jjtGetChild(0).jjtAccept(this, data); ! String name = (String) node.jjtGetChild(1).jjtAccept(this, data); ! code.add("begin shader: " + type + " " + name); ! if (node.jjtGetNumChildren() == 4) { ! code.add("begin args:"); ! node.jjtGetChild(2).jjtAccept(this, data); ! code.add("end args"); ! } ! node.jjtGetChild(node.jjtGetNumChildren() - 1).jjtAccept(this, data); ! code.add("end shader: " + name + '\n'); ! return data; } public Object visit(ASTshaderType node, Object data) { ! return node.type; } public Object visit(ASTfunctionDefinition node, Object data) { ! int next = 0; ! String type = "float"; ! Node nd = node.jjtGetChild(next++); ! if (nd instanceof ASTtype) { ! type = (String) nd.jjtAccept(this, data); ! nd = node.jjtGetChild(next++); ! } ! String name = (String) nd.jjtAccept(this, data); ! code.add("begin function: " + type + " " + name); ! nd = node.jjtGetChild(next++); ! if (nd instanceof ASTformals) { ! code.add("begin args:"); ! nd.jjtAccept(this, data); ! code.add("end args"); ! nd = node.jjtGetChild(next); ! } ! nd.jjtAccept(this, data); ! code.add("end function: " + name + '\n'); ! return data; } *************** *** 391,394 **** --- 431,464 ---- } + public Object visit(ASTconditionalOrExpression node, Object data) { + int n = node.jjtGetNumChildren(); + String var1 = (String) node.jjtGetChild(0).jjtAccept(this, data); + String var2 = (String) node.jjtGetChild(1).jjtAccept(this, data); + String temp = "T" + tempCounter++; + code.add(temp + " <- " + var1 + " || " + var2); + for (int i = 2; i < n; i++) { + var2 = (String) node.jjtGetChild(i).jjtAccept(this, data); + String newTemp = "T" + tempCounter++; + code.add(newTemp + " <- " + temp + " || " + var2); + temp = newTemp; + } + return temp; + } + + public Object visit(ASTconditionalAndExpression node, Object data) { + int n = node.jjtGetNumChildren(); + String var1 = (String) node.jjtGetChild(0).jjtAccept(this, data); + String var2 = (String) node.jjtGetChild(1).jjtAccept(this, data); + String temp = "T" + tempCounter++; + code.add(temp + " <- " + var1 + " && " + var2); + for (int i = 2; i < n; i++) { + var2 = (String) node.jjtGetChild(i).jjtAccept(this, data); + String newTemp = "T" + tempCounter++; + code.add(newTemp + " <- " + temp + " && " + var2); + temp = newTemp; + } + return temp; + } + public Object visit(ASTequalityExpression node, Object data) { String a = (String) node.jjtGetChild(0).jjtAccept(this, data); |
From: Gerardo H. <ma...@us...> - 2004-08-03 04:43:30
|
Update of /cvsroot/jrman/drafts/slcompiler/shaders In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9615/shaders Added Files: brushedmetal-p.sl Log Message: More test code compilation. Large example with shaders/brushedmetal-p.sl (brushedmetal.sl preprocessed with cpp...) --- NEW FILE: brushedmetal-p.sl --- color LocIllumOrenNayar (normal N; vector V; float roughness;) { float sigma2 = roughness * roughness; float A = 1 - 0.5 * sigma2 / (sigma2 + 0.33); float B = 0.45 * sigma2 / (sigma2 + 0.09); float theta_r = acos (V . N); vector V_perp_N = normalize(V-N*(V.N)); color C = 0; extern point P; illuminance (P, N, PI/2) { extern vector L; extern color Cl; float nondiff = 0; lightsource ("__nondiffuse", nondiff); if (nondiff < 1) { vector LN = normalize(L); float cos_theta_i = LN . N; float cos_phi_diff = V_perp_N . normalize(LN - N*cos_theta_i); float theta_i = acos (cos_theta_i); float alpha = max (theta_i, theta_r); float beta = min (theta_i, theta_r); C += (1-nondiff) * Cl * cos_theta_i * (A + B * max(0,cos_phi_diff) * sin(alpha) * tan(beta)); } } return C; } float sqr (float x) { return x*x; } color LocIllumWardAnisotropic (normal N; vector V; vector xdir; float xroughness, yroughness;) { float cos_theta_r = clamp (N.V, 0.0001, 1); vector X = xdir / xroughness; vector Y = (N ^ xdir) / yroughness; color C = 0; extern point P; illuminance (P, N, PI/2) { extern vector L; extern color Cl; float nonspec = 0; lightsource ("__nonspecular", nonspec); if (nonspec < 1) { vector LN = normalize (L); float cos_theta_i = LN . N; if (cos_theta_i > 0.0) { vector H = normalize (V + LN); float rho = exp (-2 * (sqr(X.H) + sqr(Y.H)) / (1 + H.N)) / sqrt (cos_theta_i * cos_theta_r); C += Cl * ((1-nonspec) * cos_theta_i * rho); } } } return C / (4 * xroughness * yroughness); } color LocIllumGlossy ( normal N; vector V; float roughness, sharpness; ) { color C = 0; float w = .18 * (1-sharpness); extern point P; illuminance (P, N, PI/2) { extern vector L; extern color Cl; float nonspec = 0; lightsource ("__nonspecular", nonspec); if (nonspec < 1) { vector H = normalize(normalize(L)+V); C += Cl * ((1-nonspec) * smoothstep (.72-w, .72+w, pow(max(0,N.H), 1/roughness))); } } return C; } float raysphere (point E; vector I; float r; float eps; output float t0, t1; ) { float b = 2 * ((vector E) . I); float c = ((vector E) . (vector E)) - r*r; float discrim = b*b - 4*c; float solutions; if (discrim > 0) { discrim = sqrt(discrim); t0 = (-discrim - b) / 2; if (t0 > eps) { t1 = (discrim - b) / 2; solutions = 2; } else { t0 = (discrim - b) / 2; solutions = (t0 > eps) ? 1 : 0; } } else if (discrim == 0) { t0 = -b/2; solutions = (t0 > eps) ? 1 : 0; } else { solutions = 0; } return solutions; } color ReflMap ( string reflname; point P; float blur; output float alpha; ) { point Pndc = transform ("NDC", P); float x = xcomp(Pndc), y = 1-ycomp(Pndc); alpha = float texture (reflname[3], x, y, "blur", blur, "fill", 1); return color texture (reflname, x, y, "blur", blur); } color Environment ( string envname, envspace; uniform float envrad; point P; vector R; float blur; output float alpha;) { point Psp = transform (envspace, P); vector Rsp = normalize (vtransform (envspace, R)); uniform float r2 = envrad * envrad; if ((vector Psp).(vector Psp) > r2) Psp = point (envrad * normalize (vector Psp)); float t0, t1; if (raysphere (Psp, Rsp, envrad, 1.0e-4, t0, t1) > 0) Rsp = vector (Psp + t0 * Rsp); alpha = float environment (envname[3], Rsp, "blur", blur, "fill", 1); return color environment (envname, Rsp, "blur", blur); } color RayTrace (point P; vector Rdir; float Kr, blur, jitter; uniform float nsamples; output float alpha;) { return color 0; } color SampleEnvironment (point P; vector R; float Kr, blur; string envname, envspace; uniform float envrad, rayjitter, raysamples;) { color C = 0; float alpha; if (envname != "") { if (envspace == "NDC") C = ReflMap (envname, P, blur, alpha); else C = Environment (envname, envspace, envrad, P, R, blur, alpha); } return Kr * C; } color MaterialPlastic (normal Nf; color basecolor; float Ka, Kd, Ks, roughness;) { extern vector I; return basecolor * (Ka*ambient() + Kd*diffuse(Nf)) + Ks*specular(Nf,-normalize(I),roughness); } color MaterialMatte (normal Nf; color basecolor; float Ka, Kd;) { return basecolor * (Ka*ambient() + Kd*diffuse(Nf)); } color MaterialRoughMetal (normal Nf; color basecolor; float Ka, Kd, Ks, roughness;) { extern vector I; return basecolor * (Ka*ambient() + Kd*diffuse(Nf) + Ks*specular(Nf,-normalize(I),roughness)); } color MaterialThinPlastic (normal Nf; vector V; color basecolor; float Ka, Kd, Kt, Ks, roughness;) { return basecolor * (Ka*ambient() + Kd*diffuse(Nf) + Kt*diffuse(-Nf)) + Ks*specular(Nf,V,roughness); } color MaterialShinyPlastic (normal Nf; color basecolor; float Ka, Kd, Ks, roughness, Kr, blur, ior; uniform float twosided; string envname, envspace; uniform float envrad, rayjitter, raysamples; ) { extern vector I; extern point P; extern normal N; vector IN = normalize(I), V = -IN; float fkr, fkt; vector R, T; fresnel (IN, Nf, 1/ior, fkr, fkt, R, T); fkt = 1-fkr; if (twosided == 0 && N.I > 0) fkr = 0; return fkt * basecolor * (Ka*ambient() + Kd*diffuse(Nf)) + (Ks) * specular(Nf,V,roughness) + SampleEnvironment (P, R, fkr*Kr, blur, envname, envspace, envrad, rayjitter, raysamples); } color MaterialShinyMetal (normal Nf; color basecolor; float Ka, Kd, Ks, roughness, Kr, blur; uniform float twosided; string envname, envspace; uniform float envrad, rayjitter, raysamples;) { extern point P; extern vector I; extern normal N; float kr = Kr; if (twosided == 0 && N.I > 0) kr = 0; vector IN = normalize(I), V = -IN; vector R = reflect (IN, Nf); return basecolor * (Ka*ambient() + Kd*diffuse(Nf) + Ks*specular(Nf,V,roughness) + SampleEnvironment (P, R, kr, blur, envname, envspace, envrad, rayjitter, raysamples)); } color MaterialClay (normal Nf; color basecolor; float Ka, Kd, roughness;) { extern vector I; return basecolor * (Ka*ambient() + Kd*LocIllumOrenNayar(Nf,-normalize(I),roughness)); } color MaterialBrushedMetal (normal Nf; color basecolor; float Ka, Kd, Ks; vector xdir; float uroughness, vroughness;) { extern vector I; color spec = LocIllumWardAnisotropic (Nf, -normalize(I), xdir, uroughness, vroughness); return basecolor * (Ka*ambient() + Kd*diffuse(Nf) + Ks*spec); } color MaterialCeramic (normal Nf; color basecolor; float Ka, Kd, Ks, roughness, specsharpness;) { extern vector I; vector V = -normalize(I); return basecolor * (Ka*ambient() + Kd*diffuse(Nf)) + Ks * LocIllumGlossy (Nf, V, roughness/10, specsharpness); } color MaterialGlass (normal Nf; color basecolor; float Ka, Kd, Ks, roughness, Kr, reflblur; float Kt, refrblur, eta; color transmitcolor; uniform float refrrayjitter, refrraysamples; string envname, envspace; uniform float envrad, rayjitter, raysamples;) { extern point P; extern vector I; extern normal N; vector IN = normalize (I); vector Rfldir, Rfrdir; float kr, kt; fresnel (IN, Nf, (I.N < 0) ? 1.0/eta : eta, kr, kt, Rfldir, Rfrdir); kt = 1-kr; kr *= Kr; kt *= Kt; if (N.I > 0) kr = kt = 0; color Crefl = SampleEnvironment (P, normalize(Rfldir), kr, reflblur, envname, envspace, envrad, rayjitter, raysamples); color Crefr = SampleEnvironment (P, normalize(Rfrdir), kt, refrblur, envname, envspace, envrad, refrrayjitter, refrraysamples); return (basecolor * (Ka*ambient() + Kd*diffuse(Nf)) + (Crefl + Ks*LocIllumGlossy(Nf,-IN,roughness,0.5)) + transmitcolor * Crefr); } surface brushedmetal ( float Ka = 1, Kd = 0.1, Ks = .9; float uroughness = 0.15, vroughness = 0.5; ) { normal Nf = faceforward (normalize(N), I); Ci = MaterialBrushedMetal (Nf, Cs, Ka, Kd, Ks, normalize(dPdu), uroughness, vroughness); Oi = Os; Ci *= Oi; } |
Update of /cvsroot/jrman/drafts/slcompiler/shaders In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv595/shaders Modified Files: ambientlight.sl distantlight.sl pointlight.sl spotlight.sl Added Files: areacam.sl brushedmetal.sl bumptest.sl bumpy.sl cel.sl cellclouds.sl ceramictiles.sl clay.sl depthcue.sl displace.h emboss.sl fakedlight.sl filterwidth.h fog.sl gcloud.sl glass.sl glow.sl hypertexture.sl lensflare.sl locillum.h lumpy.sl material.h nizid.sl noises.h oak.h oak.sl oakplank.sl panorama.sl patterns.h project.h pshad.h randomcolors.sl rayserver.h raysphere.h reflections.h shadowedclouds.sl shadowspot.sl shiny.sl shinyplastic.sl simpletexmap.sl smoke.sl starball.sl supertexmap.sl texdust.sl turbulence.sl uberlight.sl whitted.sl woodblockprint.sl Log Message: Did some more work on the test compiler implementation. --- NEW FILE: project.h --- /*************************************************************************** * project.h - Routines for texture projection * * Author: Larry Gritz (gr...@ac...) * * Reference: * _Advanced RenderMan: Creating CGI for Motion Picture_, * by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999. * ***************************************************************************/ #ifndef PROJECT_H #define PROJECT_H 1 #ifndef FILTERWIDTH_H #include "filterwidth.h" #endif /* Project 3-D points onto a unit sphere centered at the origin */ void spherical_projection (point p; output float ss, tt, ds, dt;) { extern float du, dv; /* Used by the filterwidth macro */ vector V = normalize(vector p); ss = (-atan (ycomp(V), xcomp(V)) + PI) / (2*PI); tt = 0.5 - acos(zcomp(V)) / PI; ds = filterwidth (ss); if (ds > 0.5) ds = max (1-ds, MINFILTWIDTH); dt = filterwidth (tt); if (dt > 0.5) dt = max (1-dt, MINFILTWIDTH); } /* Project 3-D points onto a cylinder about the z-axis between z=0 and z=1 */ void cylindrical_projection (point p; output float ss, tt, ds, dt;) { extern float du, dv; /* Used by the filterwidth macro */ vector V = normalize(vector p); ss = (-atan (ycomp(V), xcomp(V)) + PI) / (2*PI); tt = zcomp(p); ds = filterwidth (ss); if (ds > 0.5) ds = max (1-ds, MINFILTWIDTH); dt = filterwidth (tt); } void ProjectTo2D (string projection; point P; string whichspace; matrix xform; output float ss, tt; output float ds, dt; ) { point Pproj; extern float du, dv; /* Used by the filterwidth macro */ if (projection == "st") { extern float s, t; Pproj = point (s, t, 0); } else { Pproj = transform (whichspace, P); } #pragma nolint 2 Pproj = transform (xform, Pproj); if (projection == "planar" || projection == "st") { ss = xcomp(Pproj); tt = ycomp(Pproj); ds = filterwidth (ss); dt = filterwidth (tt); } else if (projection == "perspective") { float z = max (zcomp(Pproj), 1.0e-6); /* avoid zero division */ ss = xcomp(Pproj) / z; tt = ycomp(Pproj) / z; ds = filterwidth (ss); dt = filterwidth (tt); } /* Special cases for the projections that may wrap */ else if (projection == "spherical") spherical_projection (Pproj, ss, tt, ds, dt); else if (projection == "cylindrical") cylindrical_projection (Pproj, ss, tt, ds, dt); } color GetColorTextureAndAlpha (string texturename; string projection; point P; string whichspace; matrix xform; float blur; uniform float alphachannel; output float alpha; ) { float ss, tt, ds, dt; ProjectTo2D (projection, P, whichspace, xform, ss, tt, ds, dt); ds *= 0.5; dt *= 0.5; color Ct = color texture (texturename, ss-ds, tt-dt, ss+ds, tt-dt, ss-ds, tt+dt, ss+ds, tt+dt, "blur", blur); alpha = float texture (texturename[alphachannel], ss-ds, tt-dt, ss+ds, tt-dt, ss-ds, tt+dt, ss+ds, tt+dt, "blur", blur, "fill", 1); return Ct; } float GetFloatTextureAndAlpha (string texturename; string projection; point P; string whichspace; matrix xform; float blur; uniform float alphachannel; output float alpha; ) { float ss, tt, ds, dt; ProjectTo2D (projection, P, whichspace, xform, ss, tt, ds, dt); ds *= 0.5; dt *= 0.5; float val = float texture (texturename, ss-ds, tt-dt, ss+ds, tt-dt, ss-ds, tt+dt, ss+ds, tt+dt, "blur", blur); alpha = float texture (texturename[alphachannel], ss-ds, tt-dt, ss+ds, tt-dt, ss-ds, tt+dt, ss+ds, tt+dt, "blur", blur, "fill", 1); return val; } color ApplyColorTextureOver (color basecolor; string texturename; string projection; point P; string whichspace; matrix xform; float blur; ) { float alpha; color Ct = GetColorTextureAndAlpha (texturename, projection, P, whichspace, xform, blur, 3, alpha); return Ct + (1-alpha)*basecolor; } float ApplyFloatTextureOver (float baseval; string texturename; string projection; point P; string whichspace; matrix xform; float blur; ) { float alpha; float x = GetFloatTextureAndAlpha (texturename, projection, P, whichspace, xform, blur, 3, alpha); return x + (1-alpha)*baseval; } /* Helper function to convert arrays of 16 floats to matrices */ matrix array_to_mx (float mx[16]) { return matrix (mx[0], mx[1], mx[2], mx[3], mx[4], mx[5], mx[6], mx[7], mx[8], mx[9], mx[10], mx[11], mx[12], mx[13], mx[14], mx[15]); } #endif /* PROJECT_H */ --- NEW FILE: glow.sl --- /* * glow(): from the Renderman Companion page 369 */ surface glow(float attenuation = 2) { float falloff = I.N; if (falloff < 0) { falloff = falloff * falloff / (I.I * N.N); falloff = pow(falloff, attenuation); Ci = Cs * falloff; Oi = falloff; } else Oi = 0; } --- NEW FILE: whitted.sl --- surface whitted( float eta = 1.5; /* index of refraction */ float Kr =.8; /* reflective coefficient */ float Kt =.2; /* transmissive coefficient */ float Ks =.2; /* specular coefficient */ float Kss = 2; /* specular exponent */ ) { normal Nn = faceforward(normalize(N), I); /* ambient term */ Ci = Kd * ambient(); /* diffuse and specular terms */ illuminance( P, Nn, PI/2 ) { /* diffuse */ Ci += Kd * Cl * (L . Nn); /* specular */ vector H = normalize(normalize(L)+I); Ci += Ks * Cl * pow(max(0,0, Nn.H), Kss); } /* reflection */ Ci += Ks * trace( reflect( I, Nn ) ); /* transmittance */ vector T = refract( I, Nn, (N.I)<0 ? eta : 1/eta ); if ( length(T) != 0.0 ) Ci += Kt * trace( T ); } --- NEW FILE: turbulence.sl --- surface turbulence(float Kd = .8, Ka = .2) { float a, scale, sum; point M; /* convert to texture coordinate system */ M = transform("marble", P); scale = 1; sum = 0; a = sqrt(area(M)); while (a < scale) { sum += scale * float noise(M / scale); scale *= 0.5; } Oi = sum; Ci = Cs * Oi * (Ka + Kd * I.N * I.N / (I.I * N.N)); } --- NEW FILE: oak.h --- /**************************************************************************** * oak.h - contains the oaktexture function, which is common to many * shader which make wood grain patterns. It looks very much * like oak, and can also pass for ... * *************************************************************************** * * Author: Larry Gritz, 1999 * * Contacts: lg...@pi... * * $Revision: 1.1 $ $Date: 2004/08/03 03:24:37 $ * ****************************************************************************/ #include "noises.h" /* oaktexture -- generate a pattern much like the rings and grain of * oak wood. Rings are centered on the z axis, so the caller should * position the space of Pshad so that the grain goes the way you want. * Note: this function takes derivatives, so it shouldn't be called * from within varying conditionals or loops. * Inputs: * Pshad, dPshad - sample point & its derivative * ringfreq - mean frequency of ring spacing * ringunevenness - 0=equally spaced rings, larger is unequally spaced * grainfreq - frequency of the fine grain * ringnoise, ringnoisefreq - general warping of the domain * trunkwobble, trunkwobblefreq - controls noise which wobbles the * axis of the trunk so that it's not perfectly on the z axis. * angularwobble, angularwobblefreq - warping indexed by angle about * the z axis. * ringy, grainy - overall scale on the degree to which rings and * grain are weighted. 0 turns one off, 1 makes full effect. * Return value: 0 when in the "background" light wood, 1 when in the * darkest part of a ring or grain. */ float oaktexture (point Pshad; float dPshad; float ringfreq, ringunevenness, grainfreq; float ringnoise, ringnoisefreq; float trunkwobble, trunkwobblefreq; float angularwobble, angularwobblefreq; float ringy, grainy;) { /* We shade based on Pshad, but we add several layers of warping: */ /* Some general warping of the domain */ vector offset = vfBm(Pshad*ringnoisefreq,dPshad*ringnoisefreq, 2, 4, 0.5); point Pring = Pshad + ringnoise*offset; /* The trunk isn't totally steady xy as you go up in z */ Pring += trunkwobble * vsnoise(zcomp(Pshad)*trunkwobblefreq) * vector(1,1,0); /* Calculate the radius from the center. */ float r2 = sqr(xcomp(Pring)) + sqr(ycomp(Pring)); float r = sqrt(r2) * ringfreq; /* Add some noise around the trunk */ r += angularwobble * smoothstep(0,5,r) * snoise (angularwobblefreq*(Pring)*vector(1,1,0.1)); /* Now add some noise so all rings are not equal width */ extern float du, dv; float dr = filterwidth(r); r += ringunevenness*filteredsnoise(r,dr); float inring = smoothpulsetrain (.1, .55, .7, .95, 1, r); point Pgrain = Pshad*grainfreq*vector(1,1,.05); float dPgrain = filterwidthp(Pgrain); float grain = 0; float i, amp=1; for (i = 0; i < 2; i += 1) { float grain1valid = 1-smoothstep(.2,.6,dPgrain); if (grain1valid > 0) { float g = grain1valid * snoise (Pgrain); g *= (0.3 + 0.7*inring); g = pow(clamp(0.8 - (g),0,1),2); g = grainy * smoothstep (0.5, 1, g); if (i == 0) inring *= (1-0.4*grain1valid); grain = max (grain, g); } Pgrain *= 2; dPgrain *= 2; amp *= 0.5; } return mix (inring*ringy, 1, grain); } --- NEW FILE: bumptest.sl --- displacement bumptest() { point P2 = transform("object", P); vector Nn = vtransform("object", N); float amp = cos(xcomp(P2) * 23) + cos(ycomp(P2) * 31) + cos(zcomp(P2) * 37); amp *= .01; P += amp * normalize(Nn); N= calculatenormal(P); } --- NEW FILE: noises.h --- /************************************************************************ * noises.h - various noise-based patterns * * Author: Larry Gritz (gr...@ac...) * * Reference: * _Advanced RenderMan: Creating CGI for Motion Picture_, * by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999. * * $Revision: 1.1 $ $Date: 2004/08/03 03:24:37 $ * ************************************************************************/ #ifndef NOISES_H #define NOISES_H 1 #ifndef FILTERWIDTH_H #include "filterwidth.h" /* Needed for filterwidth and friends */ #endif #ifndef PATTERNS_H #include "patterns.h" /* Needed for filteredabs */ #endif #ifndef snoise /* * Signed noise -- the original Perlin kind with range (-1,1) We prefer * signed noise to regular noise mostly because its average is zero. * We define three simple macros: * snoise(p) - Perlin noise on either a 1-D (float) or 3-D (point) domain. * snoisexy(x,y) - Perlin noise on a 2-D domain. * vsnoise(p) - vector-valued Perlin noise on either 1-D or 3-D domain. */ #define snoise(p) (2 * (float noise(p)) - 1) #define snoisexy(x,y) (2 * (float noise(x,y)) - 1) #define vsnoise(p) (2 * (vector noise(p)) - 1) #endif /* If we know the filter size, we can crudely antialias snoise by fading * to its average value at approximately the Nyquist limit. */ #define filteredsnoise(p,width) (snoise(p) * (1-smoothstep (0.2,0.75,width))) #define filteredvsnoise(p,width) (vsnoise(p) * (1-smoothstep (0.2,0.75,width))) /* fractional Brownian motion * Inputs: * p, filtwidth position and approximate inter-pixel spacing * octaves max # of octaves to calculate * lacunarity frequency spacing between successive octaves * gain scaling factor between successive octaves */ float fBm (point p; float filtwidth; uniform float octaves, lacunarity, gain) { uniform float amp = 1; varying point pp = p; varying float sum = 0, fw = filtwidth; uniform float i; for (i = 0; i < octaves; i += 1) { #pragma nolint sum += amp * filteredsnoise (pp, fw); amp *= gain; pp *= lacunarity; fw *= lacunarity; } return sum; } /* Typical use of fBm: */ #define fBm_default(p) fBm (p, filterwidthp(p), 4, 2, 0.5) /* A vector-valued antialiased fBm. */ vector vfBm (point p; float filtwidth; uniform float octaves, lacunarity, gain) { uniform float amp = 1; varying point pp = p; varying vector sum = 0; varying float fw = filtwidth; uniform float i; for (i = 0; i < octaves; i += 1) { #pragma nolint sum += amp * filteredvsnoise (pp, fw); amp *= gain; pp *= lacunarity; fw *= lacunarity; } return sum; } /* Typical use of vfBm: */ #define vfBm_default(p) vfBm (p, filterwidthp(p), 4, 2, 0.5) /* The stuff that Ken Musgrave calls "VLNoise" */ #define VLNoise(Pt,scale) (snoise(vsnoise(Pt)*scale+Pt)) #define filteredVLNoise(Pt,fwidth,scale) \ (filteredsnoise(filteredvsnoise(Pt,fwidth)*scale+Pt,fwidth)) float VLfBm (point p; float filtwidth; uniform float octaves, lacunarity, gain, scale) { uniform float amp = 1; varying point pp = p; varying float sum = 0; varying float fw = filtwidth; uniform float i; for (i = 0; i < octaves; i += 1) { #pragma nolint sum += amp * filteredVLNoise (pp, fw, scale); amp *= gain; pp *= lacunarity; fw *= lacunarity; } return sum; } /* Typical use of vfBm: */ #define VLfBm_default(p) VLfBm (p, filterwidthp(p), 4, 2, 0.5, 1.0) /* Antialiased turbulence. Watch out -- the abs() call introduces infinite * frequency content, which makes our antialiasing efforts much trickier! */ float turbulence (point p; float filtwidth; uniform float octaves, lacunarity, gain) { extern float du, dv; /* Needed for filterwidth macro */ uniform float amp = 1; varying point pp = p; varying float sum = 0, fw = filtwidth; uniform float i; for (i = 0; i < octaves; i += 1) { #pragma nolint float n = filteredsnoise (pp, fw); sum += amp * filteredabs (n, fw); amp *= gain; pp *= lacunarity; fw *= lacunarity; } return sum; } /* Typical use of turbulence: */ #define turbulence_default(p) turbulence (p, filterwidthp(p), 4, 2, 0.5) /*************************************************************************** * Voronoi cell noise (a.k.a. Worley noise) functions * * These functions assume that space is filled with "features" (points * of interest). There are interestingpatterns we can make by * figuring out which feature we are closest to, or to what extent * we're on the boundary between two features. Several varieties of * these computations are below, categorized by the dimension of their * domains, and the number of close features they are interested in. * * All these functions have similar inputs: * P - position to test (for 3-D varieties; 2-D varieties use ss,tt) * jitter - how much to jitter the cell center positions (1 is typical, * smaller values make a more regular pattern, larger values * make a more jagged pattern; use jitter >1 at your risk!). * And outputs: * f_n - distance to the nth nearest feature (f1 is closest, f2 is * the distance to the 2nd closest, etc.) * pos_n - the position of the nth nearest feature. For 2-D varieties, * these are instead spos_n and tpos_n. ***************************************************************************/ /* Voronoi cell noise (a.k.a. Worley noise) -- 3-D, 1-feature version. */ void voronoi_f1_3d (point P; float jitter; output float f1; output point pos1; ) { point thiscell = point (floor(xcomp(P))+0.5, floor(ycomp(P))+0.5, floor(zcomp(P))+0.5); f1 = 1000; uniform float i, j, k; for (i = -1; i <= 1; i += 1) { for (j = -1; j <= 1; j += 1) { for (k = -1; k <= 1; k += 1) { point testcell = thiscell + vector(i,j,k); point pos = testcell + jitter * (vector cellnoise (testcell) - 0.5); vector offset = pos - P; float dist = offset . offset; /* actually dist^2 */ if (dist < f1) { f1 = dist; pos1 = pos; } } } } f1 = sqrt(f1); } /* Voronoi cell noise (a.k.a. Worley noise) -- 3-D, 2-feature version. */ void voronoi_f1f2_3d (point P; float jitter; output float f1; output point pos1; output float f2; output point pos2; ) { point thiscell = point (floor(xcomp(P))+0.5, floor(ycomp(P))+0.5, floor(zcomp(P))+0.5); f1 = f2 = 1000; uniform float i, j, k; for (i = -1; i <= 1; i += 1) { for (j = -1; j <= 1; j += 1) { for (k = -1; k <= 1; k += 1) { point testcell = thiscell + vector(i,j,k); point pos = testcell + jitter * (vector cellnoise (testcell) - 0.5); vector offset = pos - P; float dist = offset . offset; /* actually dist^2 */ if (dist < f1) { f2 = f1; pos2 = pos1; f1 = dist; pos1 = pos; } else if (dist < f2) { f2 = dist; pos2 = pos; } } } } f1 = sqrt(f1); f2 = sqrt(f2); } /* Voronoi cell noise (a.k.a. Worley noise) -- 2-D, 1-feature version. */ void voronoi_f1_2d (float ss, tt; float jitter; output float f1; output float spos1, tpos1; ) { float sthiscell = floor(ss)+0.5, tthiscell = floor(tt)+0.5; f1 = 1000; uniform float i, j; for (i = -1; i <= 1; i += 1) { float stestcell = sthiscell + i; for (j = -1; j <= 1; j += 1) { float ttestcell = tthiscell + j; float spos = stestcell + jitter * (float cellnoise(stestcell, ttestcell) - 0.5); float tpos = ttestcell + jitter * (float cellnoise(stestcell+23, ttestcell-87) - 0.5); float soffset = spos - ss; float toffset = tpos - tt; float dist = soffset*soffset + toffset*toffset; if (dist < f1) { f1 = dist; spos1 = spos; tpos1 = tpos; } } } f1 = sqrt(f1); } /* Voronoi cell noise (a.k.a. Worley noise) -- 2-D, 2-feature version. */ void voronoi_f1f2_2d (float ss, tt; float jitter; output float f1; output float spos1, tpos1; output float f2; output float spos2, tpos2; ) { float sthiscell = floor(ss)+0.5, tthiscell = floor(tt)+0.5; f1 = f2 = 1000; uniform float i, j; for (i = -1; i <= 1; i += 1) { float stestcell = sthiscell + i; for (j = -1; j <= 1; j += 1) { float ttestcell = tthiscell + j; float spos = stestcell + jitter * (cellnoise(stestcell, ttestcell) - 0.5); float tpos = ttestcell + jitter * (cellnoise(stestcell+23, ttestcell-87) - 0.5); float soffset = spos - ss; float toffset = tpos - tt; float dist = soffset*soffset + toffset*toffset; if (dist < f1) { f2 = f1; spos2 = spos1; tpos2 = tpos1; f1 = dist; spos1 = spos; tpos1 = tpos; } else if (dist < f2) { f2 = dist; spos2 = spos; tpos2 = tpos; } } } f1 = sqrt(f1); f2 = sqrt(f2); } #endif /* NOISES_H */ --- NEW FILE: bumpy.sl --- displacement bumpy( float Km = 1; string texturename = "";) { float amp = Km * float texture(texturename, s, t); P += amp * normalize(N); N = calculatenormal(P); } --- NEW FILE: material.h --- /************************************************************************ * material.h - Functions which compute the light response of materials. * * Author: Larry Gritz (gr...@ac...) * * Reference: * _Advanced RenderMan: Creating CGI for Motion Picture_, * by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999. * * $Revision: 1.1 $ $Date: 2004/08/03 03:24:37 $ * ************************************************************************/ #ifndef MATERIAL_H #define MATERIAL_H #include "locillum.h" #include "reflections.h" /* Compute the color of the surface using a simple plastic-like BRDF. * Typical values are Ka=1, Kd=0.8, Ks=0.5, roughness=0.1. */ color MaterialPlastic (normal Nf; color basecolor; float Ka, Kd, Ks, roughness;) { extern vector I; return basecolor * (Ka*ambient() + Kd*diffuse(Nf)) + Ks*specular(Nf,-normalize(I),roughness); } /* Compute the color of the surface using a simple Lambertian BRDF. */ color MaterialMatte (normal Nf; color basecolor; float Ka, Kd;) { return basecolor * (Ka*ambient() + Kd*diffuse(Nf)); } /* Compute the color of the surface using a simple metal-like BRDF. To * give a metallic appearance, both diffuse and specular components are * scaled by the color of the metal. It is recommended that Kd < 0.1, * Ks > 0.5, and roughness > 0.15 to give a believable metallic appearance. */ color MaterialRoughMetal (normal Nf; color basecolor; float Ka, Kd, Ks, roughness;) { extern vector I; return basecolor * (Ka*ambient() + Kd*diffuse(Nf) + Ks*specular(Nf,-normalize(I),roughness)); } /* Compute the color of the surface using a simple thin plastic-like BRDF. * We call it _thin_ because it includes a transmisison component to allow * light from the _back_ of the surface to affect the appearance. Typical * values are Ka=1, Kd=0.8, Kt = 0.2, Ks=0.5, roughness=0.1. */ color MaterialThinPlastic (normal Nf; vector V; color basecolor; float Ka, Kd, Kt, Ks, roughness;) { return basecolor * (Ka*ambient() + Kd*diffuse(Nf) + Kt*diffuse(-Nf)) + Ks*specular(Nf,V,roughness); } /* Compute the color of the surface using a simple plastic-like BRDF, with * fresnel-attenuated coherent reflections. * If twosided is nonzero, both sides are shiny, but if you know that * the object has N facing outward, twosided==0 is a good optimization * (especially when using the ray server). */ color MaterialShinyPlastic (normal Nf; color basecolor; float Ka, Kd, Ks, roughness, Kr, blur, ior; uniform float twosided; DECLARE_ENVPARAMS; ) { extern vector I; extern point P; extern normal N; vector IN = normalize(I), V = -IN; float fkr, fkt; vector R, T; fresnel (IN, Nf, 1/ior, fkr, fkt, R, T); fkt = 1-fkr; if (twosided == 0 && N.I > 0) fkr = 0; return fkt * basecolor * (Ka*ambient() + Kd*diffuse(Nf)) + (Ks) * specular(Nf,V,roughness) + SampleEnvironment (P, R, fkr*Kr, blur, ENVPARAMS); } /* Compute the color of the surface using a simple metal-like BRDF. To * give a metallic appearance, both diffuse and specular components are * scaled by the color of the metal. It is recommended that Kd < 0.1, * Ks > 0.5, and roughness > 0.15 to give a believable metallic appearance. * If twosided is nonzero, both sides are shiny, but if you know that * the object has N facing outward, twosided==0 is a good optimization * (especially when using the ray server). */ color MaterialShinyMetal (normal Nf; color basecolor; float Ka, Kd, Ks, roughness, Kr, blur; uniform float twosided; DECLARE_ENVPARAMS;) { extern point P; extern vector I; extern normal N; float kr = Kr; if (twosided == 0 && N.I > 0) kr = 0; vector IN = normalize(I), V = -IN; vector R = reflect (IN, Nf); return basecolor * (Ka*ambient() + Kd*diffuse(Nf) + Ks*specular(Nf,V,roughness) + SampleEnvironment (P, R, kr, blur, ENVPARAMS)); } /* Compute the color of the surface of a very rough, totally nonspecular * material like clay. Use an Oren/Nayar BRDF for the diffuse term. */ color MaterialClay (normal Nf; color basecolor; float Ka, Kd, roughness;) { extern vector I; return basecolor * (Ka*ambient() + Kd*LocIllumOrenNayar(Nf,-normalize(I),roughness)); } /* Compute the color of the surface using an anisotropic BRDF. To * give a metallic appearance, both diffuse and specular components are * scaled by the color of the metal. It is recommended that Kd < 0.1, * Ks > 0.5, and roughness > 0.15 to give a believable metallic appearance. */ color MaterialBrushedMetal (normal Nf; color basecolor; float Ka, Kd, Ks; vector xdir; float uroughness, vroughness;) { extern vector I; color spec = LocIllumWardAnisotropic (Nf, -normalize(I), xdir, uroughness, vroughness); return basecolor * (Ka*ambient() + Kd*diffuse(Nf) + Ks*spec); } /* Compute the color of a ceramic object. Like plastic, but use a * "glossy" specular term. */ color MaterialCeramic (normal Nf; color basecolor; float Ka, Kd, Ks, roughness, specsharpness;) { extern vector I; vector V = -normalize(I); return basecolor * (Ka*ambient() + Kd*diffuse(Nf)) + Ks * LocIllumGlossy (Nf, V, roughness/10, specsharpness); } /* Compute the color of a glass-like surface with coherent reflections * and refractions. */ color MaterialGlass (normal Nf; color basecolor; float Ka, Kd, Ks, roughness, Kr, reflblur; float Kt, refrblur, eta; color transmitcolor; uniform float refrrayjitter, refrraysamples; DECLARE_ENVPARAMS;) { extern point P; extern vector I; extern normal N; vector IN = normalize (I); /* Compute the reflection & refraction directions and amounts */ vector Rfldir, Rfrdir; /* Smooth reflection/refraction directions */ float kr, kt; fresnel (IN, Nf, (I.N < 0) ? 1.0/eta : eta, kr, kt, Rfldir, Rfrdir); kt = 1-kr; /* Physically incorrect, but portable */ kr *= Kr; kt *= Kt; // # if (defined(BMRT) || defined(RAYSERVER_H)) // /* Speedup -- at deep ray levels, reflection is unimportant */ // if (raylevel() > 0) // kr = 0; // # endif #ifndef BMRT /* Speedup for PRMan -- don't shade back sides, but you HAVE to be sure * that normals correctly face outward. */ if (N.I > 0) kr = kt = 0; #endif /* Calculate the reflection & refraction color */ color Crefl = SampleEnvironment (P, normalize(Rfldir), kr, reflblur, ENVPARAMS); color Crefr = SampleEnvironment (P, normalize(Rfrdir), kt, refrblur, envname, envspace, envrad, refrrayjitter, refrraysamples); return (basecolor * (Ka*ambient() + Kd*diffuse(Nf)) + (Crefl + Ks*LocIllumGlossy(Nf,-IN,roughness,0.5)) + transmitcolor * Crefr); } #endif /* defined(MATERIAL_H) */ --- NEW FILE: patterns.h --- /************************************************************************ * patterns.h - Some handy functions for various patterns. Wherever * possible, antialiased versions will also be given. * * Author: Larry Gritz (gr...@ac...) * * Reference: * _Advanced RenderMan: Creating CGI for Motion Picture_, * by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999. * * $Revision: 1.1 $ $Date: 2004/08/03 03:24:37 $ * ************************************************************************/ #ifndef PATTERNS_H #define PATTERNS_H 1 #include "filterwidth.h" /* Handy square routine */ float sqr (float x) { return x*x; } /* Antialiased abs(). * Compute the box filter of abs(t) from x-dx/2 to x+dx/2. * Hinges on the realization that the indefinite integral of abs(x) is * sign(x) * 1/2 x*x; */ float filteredabs (float x, dx) { float integral (float t) { return sign(t) * 0.5 * t*t; } float x0 = x - 0.5*dx; float x1 = x0 + dx; return (integral(x1) - integral(x0)) / dx; } /* Antialiased smoothstep(e0,e1,x). * Compute the box filter of smoothstep(e0,e1,t) from x-dx/2 to x+dx/2. * Strategy: divide domain into 3 regions: t < e0, e0 <= t <= e1, * and t > e1. Region 1 has integral 0. Region 2 is computed by * analytically integrating smoothstep, which is -2t^3+3t^2. Region 3 * is trivially 1. */ float filteredsmoothstep (float e0, e1, x, dx) { float integral (float t) { return -0.5*t*t * (t*t + t); } /* Compute x0, x1 bounding region of integration, and normalize so that * e0==0, e1==1 */ float edgediff = e1 - e0; float x0 = (x-e0)/edgediff; float fw = dx / edgediff; x0 -= 0.5*fw; float x1 = x0 + fw; /* Region 1 always contributes nothing */ float int = 0; /* Region 2 - compute integral in region between 0 and 1 */ if (x0 < 1 && x1 > 0) int += integral(min(x1,1)) - integral(max(x0,0)); /* Region 3 - is 1.0 */ if (x1 > 1) int += x1-max(1,x0); return int / fw; } /* A 1-D pulse pattern: return 1 if edge0 <= x <= edge1, otherwise 0 */ float pulse (float edge0, edge1, x) { return step(edge0,x) - step(edge1,x); } float filteredpulse (float edge0, edge1, x, dx) { float x0 = x - dx/2; float x1 = x0 + dx; return max (0, (min(x1,edge1)-max(x0,edge0)) / dx); } /* A pulse train: a signal that repeats with a given period, and is * 0 when 0 <= mod(x,period) < edge, and 1 when mod(x,period) > edge. */ float pulsetrain (float edge, period, x) { return pulse (edge, period, mod(x,period)); } /* Filtered pulse train: it's not as simple as just returning the mod * of filteredpulse -- you have to take into account that the filter may * cover multiple pulses in the train. * Strategy: consider the function that is the integral of the pulse * train from 0 to x. Just subtract! */ float filteredpulsetrain (float edge, period, x, dx) { /* First, normalize so period == 1 and our domain of interest is > 0 */ float w = dx/period; float x0 = x/period - w/2; float x1 = x0+w; float nedge = edge / period; /* normalized edge value */ /* Definite integral of normalized pulsetrain from 0 to t */ float integral (float t) { extern float nedge; return ((1-nedge)*floor(t) + max(0,t-floor(t)-nedge)); } /* Now we want to integrate the normalized pulsetrain over [x0,x1] */ return (integral(x1) - integral(x0)) / w; } float smoothpulse (float e0, e1, e2, e3, x) { return smoothstep(e0,e1,x) - smoothstep(e2,e3,x); } float filteredsmoothpulse (float e0, e1, e2, e3, x, dx) { return filteredsmoothstep(e0,e1,x,dx) - filteredsmoothstep(e2,e3,x,dx); } /* A pulse train of smoothsteps: a signal that repeats with a given * period, and is 0 when 0 <= mod(x/period,1) < edge, and 1 when * mod(x/period,1) > edge. */ float smoothpulsetrain (float e0, e1, e2, e3, period, x) { return smoothpulse (e0, e1, e2, e3, mod(x,period)); } /* varyEach takes a computed color, then tweaks each indexed item * separately to add some variation. Hue, saturation, and lightness * are all independently controlled. Hue adds, but saturation and * lightness multiply. */ color varyEach (color Cin; float index, varyhue, varysat, varylum;) { /* Convert to "hsl" space, it's more convenient */ color Chsl = ctransform ("hsl", Cin); float h = comp(Chsl,0), s = comp(Chsl,1), l = comp(Chsl,2); /* Modify Chsl by adding Cvary scaled by our separate h,s,l controls */ h += varyhue * (cellnoise(index+3)-0.5); s *= 1 - varysat * (cellnoise(index-14)-0.5); l *= 1 - varylum * (cellnoise(index+37)-0.5); Chsl = color (mod(h,1), clamp(s,0,1), clamp(l,0,1)); /* Clamp hsl and transform back to rgb space */ return ctransform ("hsl", "rgb", clamp(Chsl,color 0, color 1)); } /* Given 2-D texture coordinates ss,tt and their filter widths ds, dt, * and the width and height of the grooves between tiles (assuming that * tile spacing is 1.0), figure out which (integer indexed) tile we are * on and what coordinates (on [0,1]) within our individual tile we are * shading. */ float tilepattern (float ss, tt, ds, dt; float groovewidth, grooveheight; output float swhichtile, twhichtile; output float stile, ttile;) { swhichtile = floor (ss); twhichtile = floor (tt); stile = ss - swhichtile; ttile = tt - twhichtile; return filteredpulsetrain (groovewidth, 1, ss+groovewidth/2, ds) * filteredpulsetrain (grooveheight, 1, tt+grooveheight/2, dt); } /* basic brick tiling pattern -- * inputs: * x, y positions on a 2-D surface * tilewidth, tileheight dimensions of each tile * rowstagger how much does each row stagger relative to * the previous row * rowstaggervary how much should rowstagger randomly vary * jaggedfreq, jaggedamp adds noise to the edge between the tiles * outputs: * row, column index which tile the sample is in * xtile, ytile position within this tile (0-1) */ void basicbrick (float x, y; uniform float tilewidth, tileheight; uniform float rowstagger, rowstaggervary; uniform float jaggedfreq, jaggedamp; output float column, row; output float xtile, ytile; ) { point PP; float scoord = x, tcoord = y; if (jaggedamp != 0.0) { /* Make the shapes of the bricks vary just a bit */ PP = point noise (x*jaggedfreq/tilewidth, y*jaggedfreq/tileheight); scoord += jaggedamp * xcomp (PP); tcoord += jaggedamp * ycomp (PP); } xtile = scoord / tilewidth; ytile = tcoord / tileheight; row = floor (ytile); /* which brick row? */ /* Shift the columns randomly by row */ xtile += mod (rowstagger * row, 1); xtile += rowstaggervary * (noise (row+0.5) - 0.5); column = floor (xtile); xtile -= column; ytile -= row; } #endif /* defined(PATTERNS_H) */ --- NEW FILE: randomcolors.sl --- surface randomcolors(float Ka = 1, Kd = 1) { point Nf = faceforward(normalize(N), I); Oi = Os; Ci = Os * random() * (Ka * ambient() + Kd * diffuse(Nf)); } --- NEW FILE: cellclouds.sl --- /**************************************************************************** * cellclouds - self-shadowing volumetric clouds * * Params: * Ka, Kd - the usual meaning * radius - object space radius of the sphere in which the volume resides * opacdensity - overall smoke density control as it affects its ability * to block light from behind it. * lightdensity - smoke density control as it affects light scattering * toward the viewer. * shadowdensity - smoke density control as it affects its ability to * shadow iteself. * stepsize - step size for integration * shadstepsize - step size for self-shadowing ray marching * noisefreq - frequency of the noise field that makes the volume * * Reference: * _Advanced RenderMan: Creating CGI for Motion Picture_, * by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999. * ****************************************************************************/ #include "noises.h" #include "filterwidth.h" #include "raysphere.h" float volumedensity (point Pobj; float radius, noisefreq, stepsize; output point cellcenter) { float density; voronoi_f1_3d (Pobj*noisefreq, 1, density, cellcenter); density = 1 - density; /* Increase Contrast */ density = pow(clamp(density,0,1), 7.28); /* Fade At Edges Of Sphere */ density *= 1 - smoothstep (0.8, 1, length(Pobj)/radius); return density; } color volumecolor (point Pcenter) { #pragma nolint return color "hsv" (cellnoise(Pcenter), 1, 1); } float volumeshadow (point Pobj; vector Lobj; float radius, density, noisefreq, stepsize) { float Oi = 0; float Llen = length(Lobj); vector Iobj = normalize(Lobj); float t0, t1; float hits = raysphere (Pobj, Lobj, radius, 1.0e-4, t0, t1); float end = (hits > 0) ? t0 : 0; /* distance to march */ end = min (end, Llen); float d = 0; float ss = min (stepsize, end-d); point cellcenter; float last_dtau = volumedensity (Pobj, radius, noisefreq, stepsize, cellcenter); while (d <= end) { /* Take a step and get the scattered light and density */ ss = clamp (ss, 0.005, end-d); d += ss; float dtau = volumedensity (Pobj + d*Iobj, radius, noisefreq, stepsize, cellcenter); float tau = density * ss/2 * (dtau + last_dtau); Oi += (1-Oi) * (1 - exp(-tau)); last_dtau = dtau; } return Oi; } color volumelight (point Pcur, Pobj; float radius, density, noisefreq, stepsize; point cellcenter) { color Lscatter = 0; illuminance (Pcur) { extern color Cl; extern vector L; color Cscat = Cl; if (density > 0) Cscat *= 1 - volumeshadow (Pobj, vtransform("object",L), radius, density, noisefreq, stepsize); Lscatter += Cscat; } return Lscatter * volumecolor(cellcenter); } surface cellclouds (float Ka = 0.127, Kd = 1; float radius = 10.0; float opacdensity = 1, lightdensity = 1, shadowdensity = 1; float stepsize = 0.1, shadstepsize = 0.5; float noisefreq = 2.0;) { Ci = Oi = 0; /* Do not shade the front of the sphere -- only the back! */ if (N.I > 0) { /* Find the segment to trace through. The far endpoint is simply * P. The other endpoint can be found by ray tracing against the * sphere (in the opposite direction). */ point Pobj = transform ("object", P); vector Iobj = normalize (vtransform ("object", I)); float t0, t1; float hits = raysphere (Pobj, -Iobj, radius, 1.0e-4, t0, t1); float end = (hits > 0) ? t0 : 0; /* distance to march */ point origin = Pobj - t0*Iobj; point Worigin = transform ("object", "current", origin); /* Integrate forwards from the start point */ float d = random()*stepsize; /* Calculate a reasonable step size */ float ss = min (stepsize, end-d); point Psamp = origin + d*Iobj; point cellcenter; float last_dtau = volumedensity (Psamp, radius, noisefreq, stepsize, cellcenter); color last_li = volumelight (transform ("object", "current", Psamp), Psamp, radius, shadowdensity, noisefreq, shadstepsize, cellcenter); while (d <= end) { /* Take a step and get the scattered light and density */ ss = clamp (ss, 0.005, end-d); d += ss; /* Get the scattered light and density */ Psamp = origin + d*Iobj; float dtau = volumedensity (Psamp, radius, noisefreq, stepsize, cellcenter); color li = volumelight (transform ("object", "current", Psamp), Psamp, radius, shadowdensity, noisefreq, shadstepsize, cellcenter); float tau = opacdensity * ss/2 * (dtau + last_dtau); color lighttau = lightdensity * ss/2 * (li*dtau + last_li*last_dtau); /* Composite with exponential extinction of background light */ Ci += (1-Oi) * lighttau; Oi += (1-Oi) * (1 - exp(-tau)); last_dtau = dtau; last_li = li; } } } --- NEW FILE: hypertexture.sl --- /**************************************************************************** * hypertexture.sl - self-shadowing solid clouds * * Parameters: * Ka, Kd, Ks - the usual meaning * radius - object space radius of the sphere in which the volume resides * opacdensity - overall smoke density control as it affects its ability * to block light from behind it. * lightdensity - smoke density control as it affects light scattering * toward the viewer. * shadowdensity - smoke density control as it affects its ability to * shadow iteself. * stepsize - step size for integration * shadstepsize - step size for self-shadowing ray marching * noisefreq - frequency of the noise field that makes the volume * thresh - threshold value for the solid boundary of the hypertexture * * Reference: * _Advanced RenderMan: Creating CGI for Motion Picture_, * by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999. * ****************************************************************************/ #include "noises.h" #include "filterwidth.h" #include "raysphere.h" float volumedensity (point Pobj; float radius, noisefreq, stepsize;) { float density = 0.5 + 0.5 * fBm(Pobj*noisefreq, stepsize*noisefreq, 3, 2, 0.6); /* Fade At Edges Of Sphere */ density *= 1 - smoothstep (0.8, 1, length(Pobj)/radius); return density; } color volumecolor (point Pobj; float stepsize) { #pragma nolint 2 return color (0.5 + 0.5*filteredsnoise(Pobj, stepsize), 0.75, 0.5 + 0.5*filteredsnoise(Pobj-10, stepsize)); } float volumeshadow (point Pobj; vector Lobj; float radius, density, noisefreq, stepsize, thresh) { float Oi = 0; float Llen = length(Lobj); vector Iobj = normalize(Lobj); float t0, t1; float hits = raysphere (Pobj, Lobj, radius, 1.0e-4, t0, t1); float end = (hits > 0) ? t0 : 0; /* distance to march */ end = min (end, Llen); float d = 0; float ss = min (stepsize, end-d); float last_dtau = volumedensity (Pobj, radius, noisefreq, stepsize); last_dtau = smoothstep (thresh, thresh+0.01, last_dtau); while (d <= end && Oi < 0.999) { /* Take a step and get the scattered light and density */ ss = clamp (ss, 0.005, end-d); d += ss; float dtau = volumedensity (Pobj + d*Iobj, radius, noisefreq, stepsize); dtau = smoothstep (thresh, thresh+0.01, dtau); float tau = density * ss/2 * (dtau + last_dtau); Oi += (1-Oi) * (1 - exp(-tau)); last_dtau = dtau; } return Oi; } normal compute_normal (point P; float den, noisefreq, sphererad, stepsize) { float density (point p) { extern float noisefreq, sphererad, stepsize; return volumedensity (p, sphererad, noisefreq, stepsize); } normal norm; if (length(P) > sphererad - 0.0051) norm = normal P; else norm = normal (density(P + vector (stepsize/10, 0, 0)) - den, density(P + vector (0, stepsize/10, 0)) - den, density(P + vector (0, 0, stepsize/10)) - den ); return normalize(norm); } color volumelight (point Pcur, Pobj; vector Icur; float density_here, Kd, Ks; float radius, density, noisefreq, stepsize, thresh) { normal N = compute_normal (Pobj, density_here, noisefreq, radius, stepsize); N = faceforward (ntransform ("object", "current", N), Icur); N = normalize(N); color Lscatter = 0; vector V = -normalize(Icur); illuminance (Pcur) { extern color Cl; extern vector L; color Cscat = Cl; if (density > 0) Cscat *= 1 - volumeshadow (Pobj, vtransform("object",L), radius, density, noisefreq, stepsize, thresh); vector LN = normalize(L); vector H = normalize (LN + V); Lscatter += Kd * Cscat * max (LN . N, 0) + Ks * Cscat * specularbrdf (LN, N, V, 0.1); } return Lscatter * volumecolor(Pobj, stepsize); } surface hypertexture (float Ka = 0.127, Kd = 1, Ks = 0.3; float radius = 10.0; float opacdensity = 1, lightdensity = 1, shadowdensity = 1; float stepsize = 0.1, shadstepsize = 0.5; float noisefreq = 2.0; float thresh = 0.5;) { Ci = Oi = 0; /* Do not shade the front of the sphere -- only the back! */ if (N.I > 0) { /* Find the segment to trace through. The far endpoint is simply * P. The other endpoint can be found by ray tracing against the * sphere (in the opposite direction). */ point Pobj = transform ("object", P); vector Iobj = normalize (vtransform ("object", I)); float t0, t1; float hits = raysphere (Pobj, -Iobj, radius, 1.0e-4, t0, t1); float end = (hits > 0) ? t0 : 0; /* distance to march */ point origin = Pobj - t0*Iobj; point Worigin = transform ("object", "current", origin); /* Integrate forwards from the start point */ float d = random()*stepsize; /* Calculate a reasonable step size */ float ss = min (stepsize, end-d); point Psamp = origin + d*Iobj; float last_dtau = volumedensity (Psamp, radius, noisefreq, stepsize); color last_li = volumelight (transform ("object", "current", Psamp), Psamp, I, last_dtau, Kd, Ks, radius, shadowdensity, noisefreq, shadstepsize, thresh); /* Sharpen at boundary */ last_dtau = smoothstep (thresh, thresh+0.01, last_dtau); while (d <= end && (comp(Oi,0)<0.1 || comp(Oi,1)<1 || comp(Oi,2)<1)) { /* Take a step and get the scattered light and density */ ss = clamp (ss, 0.005, end-d); d += ss; /* Get the scattered light and density */ Psamp = origin + d*Iobj; float dtau = volumedensity (Psamp, radius, noisefreq, stepsize); color li = 0; if (dtau > thresh) li = volumelight (transform ("object", "current", Psamp), Psamp, I, dtau, Kd, Ks, radius, shadowdensity, noisefreq, shadstepsize, thresh); dtau = smoothstep (thresh, thresh+0.01, dtau); float tau = opacdensity * ss/2 * (dtau + last_dtau); color lighttau = lightdensity * ss/2 * (li*dtau + last_li*last_dtau); lighttau = lightdensity * (li + last_li)/2; float alpha = 1 - exp(-tau); /* Composite with exponential extinction of background light */ Ci += (1-Oi) * lighttau * alpha; Oi += (1-Oi) * alpha; last_dtau = dtau; last_li = li; } } } --- NEW FILE: cel.sl --- /**************************************************************************** * cel.sl * * Description: generate flatly shaded objects that look like cartoon * "cel" paintings. * * Parameters: * Ka, Kd, Ks, roughness - the usual meaning * outlinethickness - scales the thickness of the silhouette outlines * *************************************************************************** * * Author: Larry Gritz (gr...@ac...), 1999 * * Reference: * _Advanced RenderMan: Creating CGI for Motion Picture_, * by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999. * * $Revision: 1.1 $ $Date: 2004/08/03 03:24:37 $ * ****************************************************************************/ #include "filterwidth.h" #include "material.h" color LocIllumCelDiffuse ( normal N; ) { color C = 0; extern point P; illuminance (P, N, PI/2) { /* Must declare because extern L & Cl because we're in a function */ extern vector L; extern color Cl; float nondiff = 0; lightsource ("__nondiffuse", nondiff); if (nondiff < 1) { C += Cl * ((1-nondiff) * smoothstep(0,0.1,N.normalize(L))); } } return C; } color MaterialCel (normal Nf; color Cs; float Ka, Kd, Ks, roughness, specsharpness;) { extern vector I; vector IN = normalize(I), V = -IN; return Cs * (Ka*ambient() + Kd*LocIllumCelDiffuse(Nf)) + Ks * LocIllumGlossy (Nf, V, roughness/10, specsharpness); } color CelOutline (normal N; float outlinethickness;) { extern float du, dv; extern color Ci, Oi; extern vector I; float angle = abs(normalize(N) . normalize(I)); float dangle = filterwidth(angle); float border = 1 - filterstep (5*outlinethickness, angle/dangle); Oi = mix (Oi, color 1, border); return mix (Ci, color 0, border); } surface cel ( float Ka = 1, Kd = 1, Ks = .5, roughness = 0.25; float outlinethickness = 1;) { normal Nf = faceforward(normalize(N),I); Ci = MaterialCel (Nf, Cs, Ka, Kd, Ks, roughness, 0.25); Oi = Os; Ci *= Oi; Ci = CelOutline (N, outlinethickness); } --- NEW FILE: rayserver.h --- /* rayserver.h - Shading Language (PRMan side) include file for ray server. * * These macros translate calls to trace(), visibility(), and * rayhittest() into calls to rayserver(). Each generates different * numbers of args, allowing rayserver() to be polymorphic. * * It is assumed that the rayserver() function itself is implemented * as a DSO shadeop. (See docs for PRMan 3.8 or later.) * * Note that the ray server expects its data in world space. * * Author: Larry Gritz (lg...@bm...) * * Reference: * Gritz, Larry, "Ray Tracing in PRMan (with a little help from * BMRT)". Appeared in: Apodaca and Gritz, eds., "Advanced * RenderMan: Beyond the Companion", SIGGRAPH '98 course notes * (Course #11), July 20, 1998. */ #ifndef RAYSERVER_H #define RAYSERVER_H #ifndef BMRT /* PRMan side only -- BMRT already knows these functions */ #define worldp(p) transform("world",p) #define worldv(v) vtransform("world",v) #define trace(p,d) rayserver(worldp(p), worldv(d)) #define visibility(from,to) rayserver(worldp(from), worldp(to)) #define rayhittest(p,d,phit,nhit) \ rayserver(worldp(p), worldv(d), phit,nhit) #define fulltrace(p,d,chit,hitdist,phit,nhit,pmiss,rmiss) \ rayserver(worldp(p),worldv(d), chit,hitdist,phit,nhit,pmiss,rmiss) #define areashadow(Ps,nsamples) rayserver(worldp(Ps), nsamples, __lightname) float raylevel () { return 0; } float isshadowray () { return 0; } #endif #endif --- NEW FILE: reflections.h --- /************************************************************************ * reflections.h - Functions which compute reflected light by either * ray tracing or environment mapping. * * Author: Larry Gritz (gr...@ac...) * * Reference: * _Advanced RenderMan: Creating CGI for Motion Picture_, * by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999. * * $Revision: 1.1 $ $Date: 2004/08/03 03:24:37 $ ************************************************************************/ #ifndef REFLECTIONS_H #define REFLECTIONS_H #include "filterwidth.h" #include "raysphere.h" /* ReflMap() - Use a reflection map for reflections in flat objects. * Inputs are: * reflname - filename of reflection map * P - origin of traced ray * blur - amount of additional blur to add to environment map * Outputs are: * return value - the color of incoming light * alpha - opacity of reflection map lookup in the direction R. * Warning - the texture call itself takes derivatives, causing * trouble if called inside a loop or varying conditional! Be cautious. */ color ReflMap ( string reflname; point P; float blur; output float alpha; ) { /* Transform to the space of the environment map */ point Pndc = transform ("NDC", P); float x = xcomp(Pndc), y = 1-ycomp(Pndc); alpha = float texture (reflname[3], x, y, "blur", blur, "fill", 1); return color texture (reflname, x, y, "blur", blur); } /* Environment() - A replacement for ordinary environment() lookups, this * function ray traces against an environment sphere of known, finite * radius. Inputs are: * envname - filename of environment map * envspace - name of space environment map was made in * envrad - approximate supposed radius of environment sphere * P, R - position and direction of traced ray * blur - amount of additional blur to add to environment map * Outputs are: * return value - the color of incoming environment light * alpha - opacity of environment map lookup in the direction R. * Warning - the environment call itself takes derivatives, causing * trouble if called inside a loop or varying conditional! Be cautious. */ color Environment ( string envname, envspace; uniform float envrad; point P; vector R; float blur; output float alpha;) { /* Transform to the space of the environment map */ point Psp = transform (envspace, P); vector Rsp = normalize (vtransform (envspace, R)); uniform float r2 = envrad * envrad; /* Clamp the position to be *inside* the environment sphere */ if ((vector Psp).(vector Psp) > r2) Psp = point (envrad * normalize (vector Psp)); float t0, t1; if (raysphere (Psp, Rsp, envrad, 1.0e-4, t0, t1) > 0) Rsp = vector (Psp + t0 * Rsp); alpha = float environment (envname[3], Rsp, "blur", blur, "fill", 1); return color environment (envname, Rsp, "blur", blur); } /* RayTrace() - A fancy ray trace routine, particularly suitable for * use with the "ray server." Tries to sample over the surface * element and over the varying ray spread due to surface curvature. * An ordinary call to trace would point sample the environment in a * very simplistic way. This function takes the size of the surface * facet and curvature of the surface into account, and lets you * sample the space with multiple rays. * * Inputs: * P - surface position * Rdir - the unit-length reflection direction. * blur - reflection blurriness; 0 = sharp reflection * jitter - when 1, fully jitter the stochastic ray directions. Lower * numbers jitter less, 0 doesn't jitter. Lowering jitter may help * alleviate "sparkling" due to animation with low nrays. * nsamples - number of rays with which to sample. Larger numbers will * yield better-sampled reflections, but will be more expensive. * Note that the function reduces this number for secondary rays, * assuming that the distribution from primary rays will be * sufficient! * Return value: the average of the trace calls. * * Warning!!! This function takes derivatives to find out the ray spread! * This can cause trouble if RayTrace() is called inside a loop or varying * conditional! Be cautious. */ color RayTrace (point P; vector Rdir; float Kr, blur, jitter; uniform float nsamples; output float alpha;) { //# if (defined(BMRT) || defined(RAYSERVER_H)) //float rand () { // extern float jitter; // return (raylevel()==0) ? (0.5 + jitter * (float random() - 0.5)) : 0.5; //} //extern float du, dv; //color C, Ct; //float hitdist; point Phit, Pmiss; vector Nhit, Rmiss; //float bluramt = blur + filterwidthp(Rdir); //uniform float nrays = (raylevel() == 0 ? max(1,ceil(sqrt(nsamples))) : 1); //vector Tu = Du(P) * (1.5 * du); /* overblur just a tad... */ //vector Tv = Dv(P) * (1.5 * dv); //if (Kr < 0.0001) { // C = 0; //} else if (bluramt > 0 || nrays > 1) { // /* Construct orthogonal components to Rdir */ // vector uoffset = blur * normalize (vector (zcomp(Rdir) - ycomp(Rdir), // xcomp(Rdir) - zcomp(Rdir), // ycomp(Rdir) - xcomp(Rdir))); // vector voffset = Rdir ^ uoffset; // uniform float i, j; // C = 0; alpha = 0; // for (i = 0; i < nrays; i += 1) { // for (j = 0; j < nrays; j += 1) { // /* Add a random offset to the smooth reflection vector */ // vector R = Rdir + ((i + rand())/nrays - 0.5) * uoffset + // ((j + rand())/nrays - 0.5) * voffset; // R = normalize(R); // point Pray = P + ((j + rand())/nrays - 0.5) * Tu + // ((i + rand())/nrays - 0.5) * Tv; // fulltrace (Pray, R, Ct, hitdist, Phit, Nhit, Pmiss, Rmiss); // C += Ct; // alpha += 1 - step(1.0e10,hitdist); // } // } // uniform float totrays = nrays*nrays; // C /= totrays; alpha /= totrays; //} else { // /* No blur or curvature, just do a simple trace */ // fulltrace (P, Rdir, C, hitdist, Phit, Nhit, Pmiss, Rmiss); // alpha = 1 - step(1.0e10,hitdist); //} //return C; //# else return color 0; //# endif } #define ENVPARAMS \ envname, envspace, envrad, rayjitter, raysamples #define DECLARE_ENVPARAMS \ string envname, envspace; \ uniform float envrad, rayjitter, raysamples #define DECLARE_DEFAULTED_ENVPARAMS \ string envname = "", envspace = "world"; \ uniform float envrad = 100, rayjitter = 0, raysamples = 1 color SampleEnvironment (point P; vector R; float Kr, blur; DECLARE_ENVPARAMS;) { color C = 0; float alpha; if (envname != "") { if (envspace == "NDC") C = ReflMap (envname, P, blur, alpha); else C = Environment (envname, envspace, envrad, P, R, blur, alpha); } // # if (defined(BMRT) || defined(RAYSERVER_H)) // color Cray = RayTrace (P, R, Kr, sqrt(blur), rayjitter, raysamples, alpha); // C = Cray + (1-alpha) * C; // # endif return Kr * C; } #endif /* defined(REFLECTIONS_H) */ --- NEW FILE: woodblockprint.sl --- /**************************************************************************** * woodblockprint.sl -- surface shader for carved wood block printing * * (c) Copyright 1998 by Fleeting Image Animation, Inc. * All rights reserved. * * Permission is hereby granted, without written agreement and without * license or royalty fees, to use, copy, modify, and distribute this * software and for any purpose, provided that the above copyright * notice appear in all copies of this software. * * Author: Scott F. Johnston * * Reference: * _Advanced RenderMan: Creating CGI for Motion Picture_, * by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999. * ****************************************************************************/ surface woodblockprint ( float freq = 2; float duty = 0.50; float normal_dropoff = 1.0; float dpscale = 0.1; color stripe_color = 0; float Ka = 0.2; float Kd = 0.8; float lo = 0.0; float hi = 1.0; string mapname = ""; float aspect = 1.0; ) { color diffuzeC; float diffuze; point Pscreen = transform("screen", P); vector dp = dpscale * vtransform("screen", dPdv); setzcomp(dp, 0); float lendp = mix (length(dp), length(dPdv), normal_dropoff); float logdp = log(freq * lendp, 2.0); float ilogdp = floor(logdp); float stripes = pow(2,ilogdp); float sawtooth = mod(v * stripes, 1); float triangle = abs(2.0 * sawtooth - 1.0); float transition = logdp - ilogdp; float transtriangle = abs((1 + transition) * triangle - transition); if (mapname != "") { float screenx = xcomp(Pscreen) / aspect; float screeny = ycomp(Pscreen); screenx = 0.5 * (screenx + 1.0); screeny = 1.0 - 0.5 * (screeny + 1.0); diffuze = float texture(mapname[0], screenx, screeny); } else { diffuzeC = Ka * ambient() + Kd * diffuse(faceforward(normalize(N),I)); diffuze = (comp(diffuzeC,0) + comp(diffuzeC,1) + comp(diffuzeC,2))/3.0; } diffuze = (diffuze - lo)/(hi - lo); float square = filterstep(duty * diffuze, transtriangle); color CC = mix(Cs, stripe_color, square); Oi = Os; Ci = Os * CC; } --- NEW FILE: depthcue.sl --- volume depthcue( float mindistance = 0, maxdistance = 1; color background = 0;) { float d; d = clamp((depth(P) - mindistance) / (maxdistance - mindistance), 0.0, 1.0); Ci = mix(Ci, background, d); Oi = mix(Oi, color(1, 1, 1), d); } Index: distantlight.sl =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/shaders/distantlight.sl,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** distantlight.sl 2 Aug 2004 01:57:00 -0000 1.1 --- distantlight.sl 3 Aug 2004 03:24:37 -0000 1.2 *************** *** 7,10 **** { solar(to - from, 0.0) ! CI = intensity * lightcolor; } \ No newline at end of file --- 7,10 ---- { solar(to - from, 0.0) ! Cl = intensity * lightcolor; } \ No newline at end of file --- NEW FILE: starball.sl --- /************************************************************************ * starball.sl - make a striped ball with a star pattern * * Reference: * _Advanced RenderMan: Creati... [truncated message content] |
From: Gerardo H. <ma...@us...> - 2004-08-03 03:24:46
|
Update of /cvsroot/jrman/drafts/slcompiler In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv595 Modified Files: JPP.java SLCompiler.java SLCompiler.jj SLCompiler.jjt SLCompilerTokenManager.java TestsVisitor.java Log Message: Did some more work on the test compiler implementation. Index: JPP.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/JPP.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JPP.java 31 Jul 2004 22:36:31 -0000 1.1 --- JPP.java 3 Aug 2004 03:24:36 -0000 1.2 *************** *** 17,21 **** * Copyright (C) 1999 Bull S.A. All Rights Reserved. * ! * Contributor(s): François Horn (rewrite for Jonathan). */ --- 17,23 ---- * Copyright (C) 1999 Bull S.A. All Rights Reserved. * ! * Contributor(s): François Horn (rewrite for Jonathan). ! * ! * Modified by Gerardo Horvilleur for jrMan. */ *************** *** 108,112 **** boolean run = true; ! while(run) { --- 110,114 ---- boolean run = true; ! while(run) { *************** *** 119,122 **** --- 121,126 ---- else if(c == -1) run = false; + else if (c == '\\') + state = 5; else sb.append((char) c); *************** *** 148,151 **** --- 152,160 ---- state = 3; break; + case 5: + if (c != '\n') + sb.append((char) c); + state = 1; + break; } } *************** *** 168,172 **** fCur.close(); nbCur = ((Integer) nbStack.pop()).intValue(); ! line = "# "+nbCur+" "+"\""+nameCur+"\""+" 2"; nameCur = (String) nameStack.pop(); fCur = (BufferedReader) fStack.pop(); --- 177,182 ---- fCur.close(); nbCur = ((Integer) nbStack.pop()).intValue(); ! // line = "# "+nbCur+" "+"\""+nameCur+"\""+" 2"; ! line = ""; nameCur = (String) nameStack.pop(); fCur = (BufferedReader) fStack.pop(); *************** *** 191,195 **** fCur = new BufferedReader(new FileReader(fiName)); nameCur = new String(fiName); ! line = "# "+nbCur+" "+"\""+fiName+"\""+" 1"; nbCur = 0; } --- 201,206 ---- fCur = new BufferedReader(new FileReader(fiName)); nameCur = new String(fiName); ! // line = "# "+nbCur+" "+"\""+fiName+"\""+" 1"; ! line = ""; nbCur = 0; } Index: SLCompiler.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SLCompiler.java 2 Aug 2004 05:45:21 -0000 1.5 --- SLCompiler.java 3 Aug 2004 03:24:36 -0000 1.6 *************** *** 5,8 **** --- 5,9 ---- import java.io.ByteArrayOutputStream; import java.io.InputStream; + import java.util.Vector; public class SLCompiler/*@bgen(jjtree)*/implements SLCompilerTreeConstants, SLCompilerConstants {/*@bgen(jjtree)*/ *************** *** 16,22 **** ByteArrayOutputStream out = new ByteArrayOutputStream(); [...2364 lines suppressed...] + final private boolean jj_3R_27() { + if (jj_scan_token(80)) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; + return false; + } + + final private boolean jj_3R_26() { + if (jj_scan_token(79)) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; + return false; + } + + final private boolean jj_3R_23() { + if (jj_scan_token(77)) return true; + if (jj_la == 0 && jj_scanpos == jj_lastpos) return false; + return false; + } + public SLCompilerTokenManager token_source; JavaCharStream jj_input_stream; Index: SLCompiler.jjt =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.jjt,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SLCompiler.jjt 2 Aug 2004 05:45:21 -0000 1.5 --- SLCompiler.jjt 3 Aug 2004 03:24:37 -0000 1.6 *************** *** 33,36 **** --- 33,37 ---- import java.io.ByteArrayOutputStream; import java.io.InputStream; + import java.util.Vector; public class SLCompiler { *************** *** 44,50 **** ByteArrayOutputStream out = new ByteArrayOutputStream(); ! JPP jpp = new JPP(in, out, new java.util.Vector(), new java.util.Hashtable()); jpp.preprocess(); ! SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); --- 45,53 ---- ByteArrayOutputStream out = new ByteArrayOutputStream(); ! Vector includeDirs = new Vector(); ! includeDirs.add("shaders"); ! JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); *************** *** 383,387 **** | LOOKAHEAD(2) identifier() [LOOKAHEAD(2) arrayindex()] [asgnop() expression()] | single() ! //assignExpression(), identifier() } --- 386,390 ---- | LOOKAHEAD(2) identifier() [LOOKAHEAD(2) arrayindex()] [asgnop() expression()] | single() ! // assignexpression() | identifier() } *************** *** 509,517 **** ! void conditionalExpression() : {} { conditionalOrExpression() [LOOKAHEAD(2) "?" expression() ":" conditionalExpression() ] } --- 512,522 ---- ! void conditionalExpression() #void : {} { + ( conditionalOrExpression() [LOOKAHEAD(2) "?" expression() ":" conditionalExpression() ] + ) #conditionalExpression(>1) } *************** *** 537,541 **** ( relationalExpression() ! (LOOKAHEAD(2) ( t = "==" | t = "!=" ) relationalExpression() { jjtThis.add(t.image); })* ) #equalityExpression(>1) } --- 542,546 ---- ( relationalExpression() ! [LOOKAHEAD(2) ( t = "==" | t = "!=" ) relationalExpression() { jjtThis.type = t.image; }] ) #equalityExpression(>1) } *************** *** 546,553 **** ( additiveExpression() ! (LOOKAHEAD(2) ( t = "<" | t = ">" | t = "<=" ! | t = ">=" ) additiveExpression() { jjtThis.add(t.image); })* ) #relationalExpression(>1) } --- 551,558 ---- ( additiveExpression() ! [LOOKAHEAD(2) ( t = "<" | t = ">" | t = "<=" ! | t = ">=" ) additiveExpression() { jjtThis.type = t.image; }] ) #relationalExpression(>1) } Index: SLCompilerTokenManager.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompilerTokenManager.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SLCompilerTokenManager.java 1 Aug 2004 04:50:40 -0000 1.2 --- SLCompilerTokenManager.java 3 Aug 2004 03:24:37 -0000 1.3 *************** *** 5,8 **** --- 5,9 ---- import java.io.ByteArrayOutputStream; import java.io.InputStream; + import java.util.Vector; public class SLCompilerTokenManager implements SLCompilerConstants Index: SLCompiler.jj =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.jj,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** SLCompiler.jj 2 Aug 2004 05:45:21 -0000 1.5 --- SLCompiler.jj 3 Aug 2004 03:24:37 -0000 1.6 *************** *** 32,35 **** --- 32,36 ---- import java.io.ByteArrayOutputStream; import java.io.InputStream; + import java.util.Vector; public class SLCompiler/*@bgen(jjtree)*/implements SLCompilerTreeConstants/*@egen*/ {/*@bgen(jjtree)*/ *************** *** 46,52 **** ByteArrayOutputStream out = new ByteArrayOutputStream(); ! JPP jpp = new JPP(in, out, new java.util.Vector(), new java.util.Hashtable()); jpp.preprocess(); ! SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); --- 47,55 ---- ByteArrayOutputStream out = new ByteArrayOutputStream(); ! Vector includeDirs = new Vector(); ! includeDirs.add("shaders"); ! JPP jpp = new JPP(in, out, includeDirs, new java.util.Hashtable()); jpp.preprocess(); ! System.out.write(out.toByteArray()); SLCompiler compiler = new SLCompiler(new ByteArrayInputStream(out.toByteArray())); compiler.compilationUnit(); *************** *** 785,789 **** } /*@egen*/ ! //assignExpression(), identifier() } --- 788,792 ---- } /*@egen*/ ! // assignexpression() | identifier() } *************** *** 1362,1395 **** ! void conditionalExpression() : ! {/*@bgen(jjtree) conditionalExpression */ ! ASTconditionalExpression jjtn000 = new ASTconditionalExpression(JJTCONDITIONALEXPRESSION); ! boolean jjtc000 = true; ! jjtree.openNodeScope(jjtn000); ! /*@egen*/} ! {/*@bgen(jjtree) conditionalExpression */ ! try { /*@egen*/ conditionalOrExpression() ! [LOOKAHEAD(2) "?" expression() ":" conditionalExpression() ]/*@bgen(jjtree)*/ ! } catch (Throwable jjte000) { ! if (jjtc000) { ! jjtree.clearNodeScope(jjtn000); ! jjtc000 = false; ! } else { ! jjtree.popNode(); ! } ! if (jjte000 instanceof RuntimeException) { ! throw (RuntimeException)jjte000; ! } ! if (jjte000 instanceof ParseException) { ! throw (ParseException)jjte000; ! } ! throw (Error)jjte000; ! } finally { ! if (jjtc000) { ! jjtree.closeNodeScope(jjtn000, true); ! } ! } /*@egen*/ } --- 1365,1401 ---- ! void conditionalExpression() : ! {} ! {/*@bgen(jjtree) #conditionalExpression(> 1) */ ! { ! ASTconditionalExpression jjtn001 = new ASTconditionalExpression(JJTCONDITIONALEXPRESSION); ! boolean jjtc001 = true; ! jjtree.openNodeScope(jjtn001); ! } ! try { /*@egen*/ + ( conditionalOrExpression() ! [LOOKAHEAD(2) "?" expression() ":" conditionalExpression() ] ! )/*@bgen(jjtree)*/ ! } catch (Throwable jjte001) { ! if (jjtc001) { ! jjtree.clearNodeScope(jjtn001); ! jjtc001 = false; ! } else { ! jjtree.popNode(); ! } ! if (jjte001 instanceof RuntimeException) { ! throw (RuntimeException)jjte001; ! } ! if (jjte001 instanceof ParseException) { ! throw (ParseException)jjte001; ! } ! throw (Error)jjte001; ! } finally { ! if (jjtc001) { ! jjtree.closeNodeScope(jjtn001, jjtree.nodeArity() > 1); ! } ! } /*@egen*/ } *************** *** 1477,1481 **** ( relationalExpression() ! (LOOKAHEAD(2) ( t = "==" | t = "!=" ) relationalExpression() { jjtn001.add(t.image); })* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1483,1487 ---- ( relationalExpression() ! [LOOKAHEAD(2) ( t = "==" | t = "!=" ) relationalExpression() { jjtn001.type = t.image; }] )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1513,1520 **** ( additiveExpression() ! (LOOKAHEAD(2) ( t = "<" | t = ">" | t = "<=" ! | t = ">=" ) additiveExpression() { jjtn001.add(t.image); })* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1519,1526 ---- ( additiveExpression() ! [LOOKAHEAD(2) ( t = "<" | t = ">" | t = "<=" ! | t = ">=" ) additiveExpression() { jjtn001.type = t.image; }] )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { Index: TestsVisitor.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/TestsVisitor.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TestsVisitor.java 2 Aug 2004 05:45:21 -0000 1.6 --- TestsVisitor.java 3 Aug 2004 03:24:37 -0000 1.7 *************** *** 128,135 **** } - public Object visit(ASTconditionalExpression node, Object data) { - return node.jjtGetChild(0).jjtAccept(this, data); - } - public Object visit(ASTprimary node, Object data) { return node.jjtGetChild(0).jjtAccept(this, data); --- 128,131 ---- *************** *** 395,398 **** --- 391,446 ---- } + public Object visit(ASTequalityExpression node, Object data) { + String a = (String) node.jjtGetChild(0).jjtAccept(this, data); + String b = (String) node.jjtGetChild(1).jjtAccept(this, data); + String cond = "bool" + tempCounter++; + code.add(cond + " <- " + a + " " + node.type + " " + b); + return cond; + } + + public Object visit(ASTrelationalExpression node, Object data) { + String a = (String) node.jjtGetChild(0).jjtAccept(this, data); + String b = (String) node.jjtGetChild(1).jjtAccept(this, data); + String cond = "bool" + tempCounter++; + code.add(cond + " <- " + a + " " + node.type + " " + b); + return cond; + } + + public Object visit(ASTwhileStatement node, Object data) { + code.add("begin while"); + String cond = (String) node.jjtGetChild(0).jjtAccept(this, data); + code.add("while cond: " + cond); + Object result = node.jjtGetChild(1).jjtAccept(this, data); + code.add("end while"); + return result; + } + + public Object visit(ASTifStatement node, Object data) { + code.add("begin if"); + String cond = (String) node.jjtGetChild(0).jjtAccept(this, data); + code.add("if cond: " + cond); + node.jjtGetChild(1).jjtAccept(this, data); + if (node.jjtGetNumChildren() == 3) { + code.add("if else"); + node.jjtGetChild(2).jjtAccept(this, data); + } + code.add("end if"); + return data; + } + + public Object visit(ASTconditionalExpression node, Object data) { + String temp = "T" + tempCounter++; + code.add("begin if"); + String cond = (String) node.jjtGetChild(0).jjtAccept(this, data); + code.add("if cond: " + cond); + String val = (String) node.jjtGetChild(1).jjtAccept(this, data); + code.add(temp + " <- " + val); + code.add("if else"); + val = (String) node.jjtGetChild(2).jjtAccept(this, data); + code.add(temp + " <- " + val); + code.add("end if"); + return temp; + } + void showCode() { for (Iterator iter = code.iterator(); iter.hasNext(); ) |
From: Gerardo H. <ma...@us...> - 2004-08-02 05:45:34
|
Update of /cvsroot/jrman/drafts/slcompiler In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3000 Modified Files: DefaultVisitor.java SLCompiler.java SLCompiler.jj SLCompiler.jjt SLCompilerTreeConstants.java SLCompilerVisitor.java TestsVisitor.java Added Files: ASTcrossExpression.java ASTdotExpression.java ASTstatement.java ASTstatements.java Removed Files: ASTdotOrPowerExpression.java Log Message: Fixed '^' and '.' priority. --- NEW FILE: ASTstatements.java --- /* Generated By:JJTree: Do not edit this line. ASTstatements.java */ public class ASTstatements extends SimpleNode { public ASTstatements(int id) { super(id); } public ASTstatements(SLCompiler p, int id) { super(p, id); } /** Accept the visitor. **/ public Object jjtAccept(SLCompilerVisitor visitor, Object data) { return visitor.visit(this, data); } } Index: SLCompilerTreeConstants.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompilerTreeConstants.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SLCompilerTreeConstants.java 2 Aug 2004 01:56:57 -0000 1.2 --- SLCompilerTreeConstants.java 2 Aug 2004 05:45:21 -0000 1.3 *************** *** 42,61 **** public int JJTRELATIONALEXPRESSION = 37; public int JJTADDITIVEEXPRESSION = 38; ! public int JJTMULTIPLICATIVEEXPRESSION = 39; ! public int JJTDOTORPOWEREXPRESSION = 40; ! public int JJTOPERATORUNARYEXPRESSION = 41; ! public int JJTCASTEXPRESSION = 42; ! public int JJTRETURNSTATEMENT = 43; ! public int JJTLOOPMODSTMT = 44; ! public int JJTLOOPMOD = 45; ! public int JJTIFSTATEMENT = 46; ! public int JJTWHILESTATEMENT = 47; ! public int JJTFORSTATEMENT = 48; ! public int JJTSOLARSTATEMENT = 49; ! public int JJTILLUMINATESTATEMENT = 50; ! public int JJTILLUMINANCESTATEMENT = 51; ! public int JJTEXPRESSIONLIST = 52; ! public int JJTVARIABLEDEFINITIONS = 53; ! public int JJTEXTERNSPEC = 54; --- 42,64 ---- public int JJTRELATIONALEXPRESSION = 37; public int JJTADDITIVEEXPRESSION = 38; ! public int JJTCROSSEXPRESSION = 39; ! public int JJTMULTIPLICATIVEEXPRESSION = 40; ! public int JJTDOTEXPRESSION = 41; ! public int JJTOPERATORUNARYEXPRESSION = 42; ! public int JJTCASTEXPRESSION = 43; ! public int JJTSTATEMENT = 44; ! public int JJTRETURNSTATEMENT = 45; ! public int JJTLOOPMODSTMT = 46; ! public int JJTLOOPMOD = 47; ! public int JJTIFSTATEMENT = 48; ! public int JJTWHILESTATEMENT = 49; ! public int JJTFORSTATEMENT = 50; ! public int JJTSOLARSTATEMENT = 51; ! public int JJTILLUMINATESTATEMENT = 52; ! public int JJTILLUMINANCESTATEMENT = 53; ! public int JJTEXPRESSIONLIST = 54; ! public int JJTVARIABLEDEFINITIONS = 55; ! public int JJTEXTERNSPEC = 56; ! public int JJTSTATEMENTS = 57; *************** *** 100,107 **** "relationalExpression", "additiveExpression", "multiplicativeExpression", ! "dotOrPowerExpression", "operatorUnaryExpression", "castExpression", "returnStatement", "loopModStmt", --- 103,112 ---- "relationalExpression", "additiveExpression", + "crossExpression", "multiplicativeExpression", ! "dotExpression", "operatorUnaryExpression", "castExpression", + "statement", "returnStatement", "loopModStmt", *************** *** 116,119 **** --- 121,125 ---- "variableDefinitions", "externspec", + "statements", }; } --- NEW FILE: ASTstatement.java --- /* Generated By:JJTree: Do not edit this line. ASTstatement.java */ public class ASTstatement extends SimpleNode { public ASTstatement(int id) { super(id); } public ASTstatement(SLCompiler p, int id) { super(p, id); } /** Accept the visitor. **/ public Object jjtAccept(SLCompilerVisitor visitor, Object data) { return visitor.visit(this, data); } } Index: SLCompiler.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SLCompiler.java 2 Aug 2004 01:56:56 -0000 1.4 --- SLCompiler.java 2 Aug 2004 05:45:21 -0000 1.5 *************** *** 1619,1623 **** jjtree.openNodeScope(jjtn001); try { ! multiplicativeExpression(); label_10: while (true) { --- 1619,1623 ---- jjtree.openNodeScope(jjtn001); try { ! crossExpression(); label_10: [...1927 lines suppressed...] *** 3975,3979 **** final private void jj_rescan_token() { jj_rescan = true; ! for (int i = 0; i < 20; i++) { JJCalls p = jj_2_rtns[i]; do { --- 4055,4059 ---- final private void jj_rescan_token() { jj_rescan = true; ! for (int i = 0; i < 21; i++) { JJCalls p = jj_2_rtns[i]; do { *************** *** 4001,4004 **** --- 4081,4085 ---- case 18: jj_3_19(); break; case 19: jj_3_20(); break; + case 20: jj_3_21(); break; } } Index: SLCompiler.jj =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.jj,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SLCompiler.jj 2 Aug 2004 01:56:56 -0000 1.4 --- SLCompiler.jj 2 Aug 2004 05:45:21 -0000 1.5 *************** *** 1551,1556 **** /*@egen*/ ( multiplicativeExpression() ! (LOOKAHEAD(2) ( t = "+" | t = "-" ) multiplicativeExpression() { jjtn001.add(t.image); })* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1551,1592 ---- /*@egen*/ ( + crossExpression() + (LOOKAHEAD(2) ( t = "+" | t = "-" ) crossExpression() { jjtn001.add(t.image); })* + )/*@bgen(jjtree)*/ + } catch (Throwable jjte001) { + if (jjtc001) { + jjtree.clearNodeScope(jjtn001); + jjtc001 = false; + } else { + jjtree.popNode(); + } + if (jjte001 instanceof RuntimeException) { + throw (RuntimeException)jjte001; + } + if (jjte001 instanceof ParseException) { + throw (ParseException)jjte001; + } + throw (Error)jjte001; + } finally { + if (jjtc001) { + jjtree.closeNodeScope(jjtn001, jjtree.nodeArity() > 1); + } + } + /*@egen*/ + } + + void crossExpression() : + { Token t; } + {/*@bgen(jjtree) #crossExpression(> 1) */ + { + ASTcrossExpression jjtn001 = new ASTcrossExpression(JJTCROSSEXPRESSION); + boolean jjtc001 = true; + jjtree.openNodeScope(jjtn001); + } + try { + /*@egen*/ + ( multiplicativeExpression() ! (LOOKAHEAD(2) ( t = "^" ) multiplicativeExpression() { jjtn001.add(t.image); })* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1587,1593 **** /*@egen*/ ( ! dotOrPowerExpression() (LOOKAHEAD(2) ( t = "*" ! | t = "/" ) dotOrPowerExpression() { jjtn001.add(t.image); })* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1623,1629 ---- /*@egen*/ ( ! dotExpression() (LOOKAHEAD(2) ( t = "*" ! | t = "/" ) dotExpression() { jjtn001.add(t.image); })* )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1613,1621 **** } ! void dotOrPowerExpression() : { Token t; } ! {/*@bgen(jjtree) #dotOrPowerExpression(> 1) */ { ! ASTdotOrPowerExpression jjtn001 = new ASTdotOrPowerExpression(JJTDOTORPOWEREXPRESSION); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); --- 1649,1657 ---- } ! void dotExpression() : { Token t; } ! {/*@bgen(jjtree) #dotExpression(> 1) */ { ! ASTdotExpression jjtn001 = new ASTdotExpression(JJTDOTEXPRESSION); boolean jjtc001 = true; jjtree.openNodeScope(jjtn001); *************** *** 1625,1630 **** ( unaryExpression() ! [LOOKAHEAD(2) ( t = "." ! | t = "^" ) unaryExpression() { jjtn001.add(t.image); }] )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { --- 1661,1665 ---- ( unaryExpression() ! [LOOKAHEAD(2) ( t = "." ) unaryExpression() { jjtn001.add(t.image); }] )/*@bgen(jjtree)*/ } catch (Throwable jjte001) { *************** *** 1731,1737 **** } ! void statement() : ! {} ! { statements() | LOOKAHEAD(2) assignexpression() ";" --- 1766,1778 ---- } ! void statement() : ! {/*@bgen(jjtree) statement */ ! ASTstatement jjtn000 = new ASTstatement(JJTSTATEMENT); ! boolean jjtc000 = true; ! jjtree.openNodeScope(jjtn000); ! /*@egen*/} ! {/*@bgen(jjtree) statement */ ! try { ! /*@egen*/ statements() | LOOKAHEAD(2) assignexpression() ";" *************** *** 1741,1745 **** | loopModStmt() | ifStatement() ! | loopControl() } --- 1782,1806 ---- | loopModStmt() | ifStatement() ! | loopControl()/*@bgen(jjtree)*/ ! } catch (Throwable jjte000) { ! if (jjtc000) { ! jjtree.clearNodeScope(jjtn000); ! jjtc000 = false; ! } else { ! jjtree.popNode(); ! } ! if (jjte000 instanceof RuntimeException) { ! throw (RuntimeException)jjte000; ! } ! if (jjte000 instanceof ParseException) { ! throw (ParseException)jjte000; ! } ! throw (Error)jjte000; ! } finally { ! if (jjtc000) { ! jjtree.closeNodeScope(jjtn000, true); ! } ! } ! /*@egen*/ } *************** *** 2140,2147 **** } ! void statements() : ! {} ! { ! "{" ( blockStatement() )* "}" } --- 2201,2234 ---- } ! void statements() : ! {/*@bgen(jjtree) statements */ ! ASTstatements jjtn000 = new ASTstatements(JJTSTATEMENTS); ! boolean jjtc000 = true; ! jjtree.openNodeScope(jjtn000); ! /*@egen*/} ! {/*@bgen(jjtree) statements */ ! try { ! /*@egen*/ ! "{" ( blockStatement() )* "}"/*@bgen(jjtree)*/ ! } catch (Throwable jjte000) { ! if (jjtc000) { ! jjtree.clearNodeScope(jjtn000); ! jjtc000 = false; ! } else { ! jjtree.popNode(); ! } ! if (jjte000 instanceof RuntimeException) { ! throw (RuntimeException)jjte000; ! } ! if (jjte000 instanceof ParseException) { ! throw (ParseException)jjte000; ! } ! throw (Error)jjte000; ! } finally { ! if (jjtc000) { ! jjtree.closeNodeScope(jjtn000, true); ! } ! } ! /*@egen*/ } --- NEW FILE: ASTcrossExpression.java --- /* Generated By:JJTree: Do not edit this line. ASTcrossExpression.java */ public class ASTcrossExpression extends SimpleNode { public ASTcrossExpression(int id) { super(id); } public ASTcrossExpression(SLCompiler p, int id) { super(p, id); } /** Accept the visitor. **/ public Object jjtAccept(SLCompilerVisitor visitor, Object data) { return visitor.visit(this, data); } } Index: DefaultVisitor.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/DefaultVisitor.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DefaultVisitor.java 2 Aug 2004 01:56:56 -0000 1.2 --- DefaultVisitor.java 2 Aug 2004 05:45:21 -0000 1.3 *************** *** 180,184 **** } ! public Object visit(ASTdotOrPowerExpression node, Object data) { return node.childrenAccept(this, data); } --- 180,188 ---- } ! public Object visit(ASTdotExpression node, Object data) { ! return node.childrenAccept(this, data); ! } ! ! public Object visit(ASTcrossExpression node, Object data) { return node.childrenAccept(this, data); } *************** *** 208,211 **** --- 212,223 ---- } + public Object visit(ASTstatement node, Object data) { + return node.childrenAccept(this, data); + } + + public Object visit(ASTstatements node, Object data) { + return node.childrenAccept(this, data); + } + public Object visit(ASTwhileStatement node, Object data) { return node.childrenAccept(this, data); --- NEW FILE: ASTdotExpression.java --- /* Generated By:JJTree: Do not edit this line. ASTdotExpression.java */ public class ASTdotExpression extends SimpleNode { public ASTdotExpression(int id) { super(id); } public ASTdotExpression(SLCompiler p, int id) { super(p, id); } /** Accept the visitor. **/ public Object jjtAccept(SLCompilerVisitor visitor, Object data) { return visitor.visit(this, data); } } Index: SLCompilerVisitor.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompilerVisitor.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SLCompilerVisitor.java 2 Aug 2004 01:56:57 -0000 1.2 --- SLCompilerVisitor.java 2 Aug 2004 05:45:21 -0000 1.3 *************** *** 42,49 **** public Object visit(ASTrelationalExpression node, Object data); public Object visit(ASTadditiveExpression node, Object data); public Object visit(ASTmultiplicativeExpression node, Object data); ! public Object visit(ASTdotOrPowerExpression node, Object data); public Object visit(ASToperatorUnaryExpression node, Object data); public Object visit(ASTcastExpression node, Object data); public Object visit(ASTreturnStatement node, Object data); public Object visit(ASTloopModStmt node, Object data); --- 42,51 ---- public Object visit(ASTrelationalExpression node, Object data); public Object visit(ASTadditiveExpression node, Object data); + public Object visit(ASTcrossExpression node, Object data); public Object visit(ASTmultiplicativeExpression node, Object data); ! public Object visit(ASTdotExpression node, Object data); public Object visit(ASToperatorUnaryExpression node, Object data); public Object visit(ASTcastExpression node, Object data); + public Object visit(ASTstatement node, Object data); public Object visit(ASTreturnStatement node, Object data); public Object visit(ASTloopModStmt node, Object data); *************** *** 58,60 **** --- 60,63 ---- public Object visit(ASTvariableDefinitions node, Object data); public Object visit(ASTexternspec node, Object data); + public Object visit(ASTstatements node, Object data); } Index: SLCompiler.jjt =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/SLCompiler.jjt,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SLCompiler.jjt 2 Aug 2004 01:56:57 -0000 1.4 --- SLCompiler.jjt 2 Aug 2004 05:45:21 -0000 1.5 *************** *** 557,583 **** { ( ! multiplicativeExpression() ! (LOOKAHEAD(2) ( t = "+" | t = "-" ) multiplicativeExpression() { jjtThis.add(t.image); })* ) #additiveExpression(>1) } void multiplicativeExpression() #void : { Token t; } { ( ! dotOrPowerExpression() (LOOKAHEAD(2) ( t = "*" ! | t = "/" ) dotOrPowerExpression() { jjtThis.add(t.image); })* ) #multiplicativeExpression(>1) } ! void dotOrPowerExpression() #void : { Token t; } { ( unaryExpression() ! [LOOKAHEAD(2) ( t = "." ! | t = "^" ) unaryExpression() { jjtThis.add(t.image); }] ! ) #dotOrPowerExpression(>1) } --- 557,591 ---- { ( ! crossExpression() ! (LOOKAHEAD(2) ( t = "+" | t = "-" ) crossExpression() { jjtThis.add(t.image); })* ) #additiveExpression(>1) } + void crossExpression() #void : + { Token t; } + { + ( + multiplicativeExpression() + (LOOKAHEAD(2) ( t = "^" ) multiplicativeExpression() { jjtThis.add(t.image); })* + ) #crossExpression(>1) + } + void multiplicativeExpression() #void : { Token t; } { ( ! dotExpression() (LOOKAHEAD(2) ( t = "*" ! | t = "/" ) dotExpression() { jjtThis.add(t.image); })* ) #multiplicativeExpression(>1) } ! void dotExpression() #void : { Token t; } { ( unaryExpression() ! [LOOKAHEAD(2) ( t = "." ) unaryExpression() { jjtThis.add(t.image); }] ! ) #dotExpression(>1) } *************** *** 606,610 **** } ! void statement() #void : {} { --- 614,618 ---- } ! void statement() : {} { *************** *** 721,725 **** } ! void statements() #void : {} { --- 729,733 ---- } ! void statements() : {} { Index: TestsVisitor.java =================================================================== RCS file: /cvsroot/jrman/drafts/slcompiler/TestsVisitor.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TestsVisitor.java 2 Aug 2004 01:56:57 -0000 1.5 --- TestsVisitor.java 2 Aug 2004 05:45:21 -0000 1.6 *************** *** 189,193 **** } ! public Object visit(ASTdotOrPowerExpression node, Object data) { int n = node.jjtGetNumChildren(); String var1 = (String) node.jjtGetChild(0).jjtAccept(this, data); --- 189,208 ---- } ! public Object visit(ASTdotExpression node, Object data) { ! int n = node.jjtGetNumChildren(); ! String var1 = (String) node.jjtGetChild(0).jjtAccept(this, data); ! String var2 = (String) node.jjtGetChild(1).jjtAccept(this, data); ! String temp = "T" + tempCounter++; ! code.add(temp + " <- " + var1 + " " + node.ops.get(0) + " " + var2); ! for (int i = 2; i < n; i++) { ! var2 = (String) node.jjtGetChild(i).jjtAccept(this, data); ! String newTemp = "T" + tempCounter++; ! code.add(newTemp + " <- " + temp + " " + node.ops.get(i - 1) + " " + var2); ! temp = newTemp; ! } ! return temp; ! } ! ! public Object visit(ASTcrossExpression node, Object data) { int n = node.jjtGetNumChildren(); String var1 = (String) node.jjtGetChild(0).jjtAccept(this, data); --- ASTdotOrPowerExpression.java DELETED --- |