From: <ma...@us...> - 2003-08-21 01:21:17
|
Update of /cvsroot/jrman/drafts/src/org/jrman/shaders In directory sc8-pr-cvs1:/tmp/cvs-serv14612/src/org/jrman/shaders Modified Files: SurfacePaintedplastic.java Added Files: LightShadowdistantlight.java Log Message: First shadows implementation. --- NEW FILE: LightShadowdistantlight.java --- /* LightDistantlight.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 javax.vecmath.Point3f; import javax.vecmath.Vector3f; import org.jrman.attributes.Space; import org.jrman.geom.Transform; import org.jrman.grid.Color3fGrid; import org.jrman.grid.FloatGrid; import org.jrman.grid.Point3fGrid; import org.jrman.grid.Vector3fGrid; import org.jrman.parser.Declaration; import org.jrman.parser.Global; import org.jrman.parser.Parameter; import org.jrman.render.ShaderVariables; public class LightShadowdistantlight extends LightShader { private static Vector3f vtmp = new Vector3f(); private static Point3f from = new Point3f(); private static Point3f to = new Point3f(); static Color3f c1 = new Color3f(); static Point3fGrid pg = new Point3fGrid(); static FloatGrid fg = new FloatGrid(); static Color3fGrid cg = new Color3fGrid(); protected void initDefaults() { float[][] intensity = new float[1][]; intensity[0] = new float[1]; intensity[0][0] = 1f; Parameter param = new Parameter(new Declaration("intensity", "uniform float"), intensity); defaultParameters.put("intensity", param); Color3f[][] lightcolor = new Color3f[1][]; lightcolor[0] = new Color3f[1]; lightcolor[0][0] = new Color3f(1f, 1f, 1f); param = new Parameter(new Declaration("lightcolor", "uniform color"), lightcolor); defaultParameters.put("lightcolor", param); Point3f[][] from = new Point3f[1][]; from[0] = new Point3f[1]; from[0][0] = new Point3f(0f, 0f, 0f); param = new Parameter(new Declaration("from", "uniform point"), from); defaultParameters.put("from", param); Point3f[][] to = new Point3f[1][]; to[0] = new Point3f[1]; to[0][0] = new Point3f(0f, 0f, 1f); param = new Parameter(new Declaration("to", "uniform point"), to); defaultParameters.put("to", param); float[][] bias = new float[1][]; bias[0] = new float[1]; bias[0][0] = .1f; param = new Parameter(new Declaration("bias", "uniform float"), bias); defaultParameters.put("bias", param); String[][] shadowmap = new String[1][]; shadowmap[0] = new String[1]; shadowmap[0][0] = ""; param = new Parameter(new Declaration("shadowmap", "string"), shadowmap); defaultParameters.put("shadowmap", param); } public boolean shade( final ShaderVariables sv, Point3fGrid P, Vector3fGrid N, float angle) { super.shade(sv, P, N, angle); Parameter param = (Parameter) getParameter(sv, "intensity"); float[][] f = (float[][]) param.getData(); final float intensity = f[0][0]; param = (Parameter) getParameter(sv, "lightcolor"); Color3f[][] c = (Color3f[][]) param.getData(); final Color3f lightColor = c[0][0]; Transform shaderTransform = attributes.getTransform(); if (attributes.getSpace() == Space.WORLD) shaderTransform = Global.getTransform("camera").concat(shaderTransform); param = (Parameter) getParameter(sv, "from"); Point3f[][] p = (Point3f[][]) param.getData(); shaderTransform.transformPoint(p[0][0], from); param = (Parameter) getParameter(sv, "to"); p = (Point3f[][]) param.getData(); shaderTransform.transformPoint(p[0][0], to); param = (Parameter) getParameter(sv, "bias"); f = (float[][]) param.getData(); final float bias = f[0][0]; param = (Parameter) getParameter(sv, "shadowmap"); String[][] s = (String[][]) param.getData(); final String shadowmap = s[0][0]; vtmp.sub(to, from); return solar(sv, P, N, angle, vtmp, 0f, new Statement() { public void execute(ShaderVariables sv) { c1.set(lightColor); c1.x *= intensity; c1.y *= intensity; c1.z *= intensity; sv.Cl.set(c1, tmpCond1); if (!shadowmap.equals("")) { pg.transform(sv.P, sv.cameraToWorld); fg.shadow(shadowmap, pg, bias); fg.sub(1f, fg); cg.set(fg); sv.Cl.mul(sv.Cl, cg); } } }); } } Index: SurfacePaintedplastic.java =================================================================== RCS file: /cvsroot/jrman/drafts/src/org/jrman/shaders/SurfacePaintedplastic.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SurfacePaintedplastic.java 1 Jun 2003 08:34:09 -0000 1.1 --- SurfacePaintedplastic.java 20 Aug 2003 20:41:21 -0000 1.2 *************** *** 1,4 **** /* ! SurfaceMetal.java Copyright (C) 2003 Gerardo Horvilleur Martinez --- 1,4 ---- /* ! SurfacePaintedPlasticl.java Copyright (C) 2003 Gerardo Horvilleur Martinez |