Update of /cvsroot/jrman/drafts/src/org/jrman/shaders In directory sc8-pr-cvs1:/tmp/cvs-serv11999/src/org/jrman/shaders Modified Files: SurfaceShader.java DisplacementShader.java LightShader.java VolumeShader.java Added Files: VolumeDepthcue.java SurfacePlastic.java VolumeFog.java Log Message: Added plastic surface shader. Added fog and depthcue volume shaders. Better error handling. --- NEW FILE: VolumeDepthcue.java --- /* VolumeDepthcue.java Copyright (C) 2003 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.shaders; import javax.vecmath.Color3f; import org.jrman.grid.FloatGrid; import org.jrman.parser.Declaration; import org.jrman.parser.Parameter; import org.jrman.render.ShaderVariables; public class VolumeDepthcue extends VolumeShader { private final static Color3f OPAQUE = new Color3f(1f, 1f, 1f); private static FloatGrid fg1 = new FloatGrid(); protected void initDefaults() { float[][] mindistance = new float[1][]; mindistance[0] = new float[1]; mindistance[0][0] = 0f; Parameter param = new Parameter(new Declaration("mindistance", "uniform float"), mindistance); defaultParameters.put("mindistance", param); float[][] maxdistance = new float[1][]; maxdistance[0] = new float[1]; maxdistance[0][0] = 1f; param = new Parameter(new Declaration("maxdistance", "uniform float"), maxdistance); defaultParameters.put("maxdistance", param); Color3f[][] background = new Color3f[1][]; background[0] = new Color3f[1]; background[0][0] = new Color3f(0f, 0f, 0f); param = new Parameter(new Declaration("background", "uniform color"), background); defaultParameters.put("background", param); } public void shade(ShaderVariables sv, float near, float far) { super.shade(sv, near, far); Parameter param = (Parameter) getParameter(sv, "mindistance"); float[][] f = (float[][]) param.getData(); final float mindistance = f[0][0]; param = (Parameter) getParameter(sv, "maxdistance"); f = (float[][]) param.getData(); final float maxdistance = f[0][0]; param = (Parameter) getParameter(sv, "background"); Color3f[][] c = (Color3f[][]) param.getData(); final Color3f background = c[0][0]; fg1.depth(sv.P, near, far); fg1.sub(fg1, mindistance); fg1.div(fg1, maxdistance - mindistance); fg1.clamp(fg1, 0f, 1f); sv.Ci.mix(sv.Ci, background, fg1); sv.Oi.mix(sv.Oi, OPAQUE, fg1); } } --- NEW FILE: SurfacePlastic.java --- /* SurfaceMetal.java Copyright (C) 2003 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.shaders; import javax.vecmath.Color3f; import org.jrman.grid.Color3fGrid; import org.jrman.grid.Vector3fGrid; import org.jrman.parser.Declaration; import org.jrman.parser.Parameter; import org.jrman.render.ShaderVariables; public class SurfacePlastic extends SurfaceShader { private static Vector3fGrid vg1 = new Vector3fGrid(); private static Vector3fGrid vg2 = new Vector3fGrid(); private static Color3fGrid cg1 = new Color3fGrid(); private static Color3fGrid cg2 = new Color3fGrid(); private static Color3fGrid cg3 = new Color3fGrid(); protected void initDefaults() { float[][] Ka = new float[1][]; Ka[0] = new float[1]; Ka[0][0] = 1f; Parameter param = new Parameter(new Declaration("Ka", "uniform float"), Ka); defaultParameters.put("Ka", param); float[][] Kd = new float[1][]; Kd[0] = new float[1]; Kd[0][0] = 1f; param = new Parameter(new Declaration("Kd", "uniform float"), Kd); defaultParameters.put("Kd", param); float[][] Ks = new float[1][]; Ks[0] = new float[1]; Ks[0][0] = 1f; param = new Parameter(new Declaration("Ks", "uniform float"), Ks); defaultParameters.put("Ks", param); float[][] roughness = new float[1][]; roughness[0] = new float[1]; roughness[0][0] = .1f; param = new Parameter(new Declaration("roughness", "uniform float"), roughness); defaultParameters.put("roughness", param); Color3f[][] specularcolor = new Color3f[1][]; specularcolor[0] = new Color3f[1]; specularcolor[0][0] = new Color3f(1f, 1f, 1f); param = new Parameter(new Declaration("specularcolor", "uniform color"), specularcolor); defaultParameters.put("specularcolor", param); } public void shade(ShaderVariables sv) { super.shade(sv); Parameter param = (Parameter) getParameter(sv, "Ka"); float[][] f = (float[][]) param.getData(); final float Ka = f[0][0]; param = (Parameter) getParameter(sv, "Kd"); f = (float[][]) param.getData(); final float Kd = f[0][0]; param = (Parameter) getParameter(sv, "Ks"); f = (float[][]) param.getData(); final float Ks = f[0][0]; param = (Parameter) getParameter(sv, "roughness"); f = (float[][]) param.getData(); final float roughness = f[0][0]; param = (Parameter) getParameter(sv, "specularcolor"); Color3f[][] c = (Color3f[][]) param.getData(); final Color3f specularcolor = c[0][0]; vg1.normalize(sv.N); vg1.faceforward(vg1, sv.I); vg2.normalize(sv.I); vg2.negate(vg2); sv.Oi.set(sv.Os); ambient(sv, cg1); cg3.set(Ka); cg1.mul(cg1, cg3); diffuse(sv, vg1, cg2); cg3.set(Kd); cg2.mul(cg2, cg3); cg1.add(cg1, cg2); cg1.mul(cg1, sv.Cs); specular(sv, vg1, vg2, roughness, cg2); cg3.set(Ks); cg2.mul(cg2, cg3); cg3.set(specularcolor); cg2.mul(cg2, cg3); cg1.add(cg1, cg2); sv.Ci.mul(sv.Os, cg1); } } --- NEW FILE: VolumeFog.java --- /* VolumeDepthcue.java Copyright (C) 2003 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.shaders; import javax.vecmath.Color3f; import org.jrman.grid.FloatGrid; import org.jrman.parser.Declaration; import org.jrman.parser.Parameter; import org.jrman.render.ShaderVariables; public class VolumeFog extends VolumeShader { private final static Color3f OPAQUE = new Color3f(1f, 1f, 1f); private static FloatGrid fg1 = new FloatGrid(); protected void initDefaults() { float[][] distance = new float[1][]; distance[0] = new float[1]; distance[0][0] = 1f; Parameter param = new Parameter(new Declaration("distance", "uniform float"), distance); defaultParameters.put("distance", param); Color3f[][] background = new Color3f[1][]; background[0] = new Color3f[1]; background[0][0] = new Color3f(0f, 0f, 0f); param = new Parameter(new Declaration("background", "uniform color"), background); defaultParameters.put("background", param); } public void shade(ShaderVariables sv, float near, float far) { super.shade(sv, near, far); Parameter param = (Parameter) getParameter(sv, "distance"); float[][] f = (float[][]) param.getData(); final float distance = f[0][0]; param = (Parameter) getParameter(sv, "background"); Color3f[][] c = (Color3f[][]) param.getData(); final Color3f background = c[0][0]; fg1.length(sv.I); fg1.negate(fg1); fg1.div(fg1, distance); fg1.exp(fg1); fg1.sub(1f, fg1); sv.Ci.mix(sv.Ci, background, fg1); sv.Oi.mix(sv.Oi, OPAQUE, fg1); } } Index: SurfaceShader.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/shaders/SurfaceShader.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** SurfaceShader.java 21 May 2003 04:58:40 -0000 1.10 --- SurfaceShader.java 23 May 2003 06:47:01 -0000 1.11 *************** *** 72,77 **** else if (className.equals("SurfaceMatte")) result = new SurfaceMatte(); ! else if (className.equals("SurfaceMetal")) result = new SurfaceMetal(); else if (className.equals("SurfaceFakedlight")) result = new SurfaceFakedlight(); --- 72,79 ---- else if (className.equals("SurfaceMatte")) result = new SurfaceMatte(); ! else if (className.equals("SurfaceMetal") || className.equals("SurfaceShinymetal")) result = new SurfaceMetal(); + else if (className.equals("SurfacePlastic") || className.equals("SurfacePaintedplastic")) + result = new SurfacePlastic(); else if (className.equals("SurfaceFakedlight")) result = new SurfaceFakedlight(); *************** *** 81,85 **** } catch (Exception e) { System.out.println( ! "Unkown surface shader: " + name + ", replacing with fakedlight surface shader"); --- 83,87 ---- } catch (Exception e) { System.out.println( ! "Unknown surface shader: " + name + ", replacing with fakedlight surface shader"); Index: DisplacementShader.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/shaders/DisplacementShader.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DisplacementShader.java 20 May 2003 01:08:38 -0000 1.4 --- DisplacementShader.java 23 May 2003 06:47:01 -0000 1.5 *************** *** 50,54 **** .newInstance(); } catch (Exception e2) { ! throw new IllegalArgumentException("Unkown displacement shader: " + name); } } --- 50,54 ---- .newInstance(); } catch (Exception e2) { ! throw new IllegalArgumentException("Unknown displacement shader: " + name); } } Index: LightShader.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/shaders/LightShader.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** LightShader.java 21 May 2003 04:58:40 -0000 1.8 --- LightShader.java 23 May 2003 06:47:01 -0000 1.9 *************** *** 67,71 **** .newInstance(); } catch (Exception e2) { ! throw new IllegalArgumentException("Unkown light shader: " + name); } } --- 67,71 ---- .newInstance(); } catch (Exception e2) { ! throw new IllegalArgumentException("Unknown light shader: " + name); } } Index: VolumeShader.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/shaders/VolumeShader.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** VolumeShader.java 19 May 2003 08:15:28 -0000 1.4 --- VolumeShader.java 23 May 2003 06:47:01 -0000 1.5 *************** *** 23,26 **** --- 23,27 ---- import org.jrman.attributes.Attributes; + import org.jrman.render.ShaderVariables; public class VolumeShader extends Shader { *************** *** 30,34 **** Map parameters, Attributes attributes) { ! return null; // Just for now.... } --- 31,54 ---- Map parameters, Attributes attributes) { ! VolumeShader result; ! String className = ! "Volume" + name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase(); ! try { ! result = (VolumeShader) Class.forName(className).newInstance(); ! } catch (Exception e) { ! try { ! result = ! (VolumeShader) Class ! .forName("org.jrman.shaders." + className) ! .newInstance(); ! } catch (Exception e2) { ! throw new IllegalArgumentException("Unknown Volume shader: " + name); ! } ! } ! result.init(name, parameters, attributes); ! return result; ! } ! ! public void shade(ShaderVariables sv, float near, float far) { } |