From: Elmer G. <ega...@us...> - 2005-12-14 01:08:57
|
Update of /cvsroot/jrman/drafts/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20743/src Added Files: DisplacementDisp_textured.java Log Message: Added missing file --- NEW FILE: DisplacementDisp_textured.java --- /* DisplacementDisp_textured.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. */ import org.jrman.grid.FloatGrid; import org.jrman.grid.Point3fGrid; import org.jrman.grid.Vector3fGrid; import org.jrman.parameters.Declaration; import org.jrman.parameters.UniformScalarFloat; import org.jrman.parameters.UniformScalarString; import org.jrman.render.ShaderVariables; import org.jrman.shaders.DisplacementShader; public class DisplacementDisp_textured extends DisplacementShader { private static FloatGrid fg1 = new FloatGrid(); private static Vector3fGrid Nn = new Vector3fGrid(); private static Point3fGrid P2 = new Point3fGrid(); protected void initDefaults() { defaultParameters.addParameter( new UniformScalarFloat(new Declaration("Km", "uniform float"), 1f)); defaultParameters.addParameter( new UniformScalarString(new Declaration("texturename", "string"), "")); defaultParameters.addParameter( new UniformScalarFloat(new Declaration("blur", "uniform float"), 0f)); } public void shade(ShaderVariables sv) { super.shade(sv); UniformScalarFloat paramKm = (UniformScalarFloat) getParameter(sv, "Km"); float Km = paramKm.getValue(); UniformScalarFloat paramMinU = (UniformScalarFloat) getParameter(sv, "min_u"); float min_u = paramMinU.getValue(); UniformScalarFloat paramMaxU = (UniformScalarFloat) getParameter(sv, "max_u"); float max_u = paramMaxU.getValue(); UniformScalarFloat paramMinV = (UniformScalarFloat) getParameter(sv, "min_v"); float min_v = paramMinV.getValue(); UniformScalarFloat paramMaxV = (UniformScalarFloat) getParameter(sv, "max_v"); float max_v = paramMaxV.getValue(); UniformScalarString paramTexturename = (UniformScalarString) getParameter(sv, "mapname"); String texturename = paramTexturename.getValue(); UniformScalarFloat paramBlur = (UniformScalarFloat) getParameter(sv, "blur"); float blur = paramBlur.getValue(); sv.u.sub(sv.u, min_u); sv.u.div(sv.u, (max_u - min_u)); sv.v.sub(sv.v, min_v); sv.v.div(sv.v, (max_v - min_v)); if (!texturename.equals("")) fg1.texture(texturename, sv.u, sv.v, blur, 0); else fg1.set(0f); fg1.mul(fg1, 2f); fg1.sub(fg1, 1f); fg1.mul(fg1, Km); Nn.normalize(sv.N); P2.set(fg1); P2.mul(P2, Nn); sv.P.add(P2, sv.P); calculatenormal(sv, sv.P, sv.N); } } |