From de4f66e0239a736bce24e09c9a0b49b5bb92d84b Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Tue, 23 Jul 2019 02:41:35 -0400 Subject: [PATCH] Min shader. --- CameraPane.java | 447 ++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 322 insertions(+), 125 deletions(-) diff --git a/CameraPane.java b/CameraPane.java index 1364b89..be97bb1 100644 --- a/CameraPane.java +++ b/CameraPane.java @@ -18,7 +18,10 @@ import javax.imageio.ImageIO; import javax.imageio.ImageWriteParam; import javax.imageio.ImageWriter; +import javax.imageio.ImageReadParam; +import javax.imageio.ImageReader; import javax.imageio.plugins.jpeg.JPEGImageWriteParam; +import javax.imageio.stream.ImageInputStream; import javax.imageio.stream.ImageOutputStream; import javax.imageio.ImageWriteParam; @@ -30,6 +33,7 @@ import java.nio.*; import gleem.linalg.Mat4f; +import javax.imageio.ImageTypeSpecifier; class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener { @@ -44,6 +48,39 @@ static boolean ABORTED = false; static int STEP = 1; + + private static BufferedImage CreateBim(byte[] bytes, int width, int height) + { + int[] pixels = new int[bytes.length/3]; + for (int i=pixels.length; --i>=0;) + { + int i3 = i*3; + pixels[i] = 0xFF; + pixels[i] <<= 8; + pixels[i] |= bytes[i3+2] & 0xFF; + pixels[i] <<= 8; + pixels[i] |= bytes[i3+1] & 0xFF; + pixels[i] <<= 8; + pixels[i] |= bytes[i3] & 0xFF; + } + /* + int r=0,g=0,b=0,a=0; + for (int i=0; i<width; i++) + for (int j=0; j<height; j++) + { + int index = j*width+i; + int p = pixels[index]; + a = ((p>>24) & 0xFF); + r = ((p>>16) & 0xFF); + g = ((p>>8) & 0xFF); + b = (p & 0xFF); + pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; + } + /**/ + BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); + rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); + return rendImage; + } /*static*/ private boolean CULLFACE = false; // true; /*static*/ boolean NEAREST = false; // true; @@ -60,7 +97,7 @@ //boolean REDUCETEXTURE = true; boolean CACHETEXTURE = true; boolean CLEANCACHE = false; // true; - boolean MIPMAP = true; // false; // true; + boolean MIPMAP = false; // true; // never works... boolean COMPRESSTEXTURE = false; boolean KOMPACTTEXTURE = false; // true; boolean RESIZETEXTURE = false; @@ -2405,6 +2442,21 @@ return currentGL; } + static private BufferedImage CreateBim(TextureData texturedata) + { + Grafreed.Assert(texturedata != null); + + int width = texturedata.getWidth(); + int height = texturedata.getHeight(); + + Buffer buffer = texturedata.getBuffer(); + ByteBuffer bytebuf = (ByteBuffer)buffer; + + byte[] bytes = bytebuf.array(); + + return CreateBim(bytes, width, height); + } + /**/ class CacheTexture { @@ -2413,18 +2465,20 @@ int resolution; - CacheTexture(com.sun.opengl.util.texture.Texture tex, int res) + CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res) { - texture = tex; + texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata); + texturedata = texdata; resolution = res; } } /**/ // TEXTURE static Texture texture; - static public java.util.Hashtable<String, CacheTexture> textures = new java.util.Hashtable<String, CacheTexture>(); - static public java.util.Hashtable<BufferedImage, CacheTexture> bimtextures = new java.util.Hashtable<BufferedImage, CacheTexture>(); - static public java.util.HashSet<String> usedtextures = new java.util.HashSet<String>(); + static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>(); + static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>(); + static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>(); + static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>(); int pigmentdepth = 0; public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536]; @@ -2432,10 +2486,10 @@ public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536]; //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE"; public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP"); - public static String NOISE_TEXTURE = "WHITE_NOISE"; + public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:"); // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL"); - com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump) + com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump) { TextureData texturedata = null; @@ -2454,16 +2508,16 @@ if (bump) texturedata = ConvertBump(texturedata, false); - com.sun.opengl.util.texture.Texture texture = - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); +// com.sun.opengl.util.texture.Texture texture = +// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); + //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); - return texture; + return texturedata; } - com.sun.opengl.util.texture.Texture GetBimTexture(BufferedImage name, boolean bump) + com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump) { TextureData texturedata = null; @@ -2471,7 +2525,7 @@ { texturedata = com.sun.opengl.util.texture.TextureIO.newTextureData( - name, + bim, true); } catch (Exception e) { @@ -2480,14 +2534,8 @@ if (bump) texturedata = ConvertBump(texturedata, false); - - com.sun.opengl.util.texture.Texture texture = - com.sun.opengl.util.texture.TextureIO.newTexture(texturedata); - - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT); - texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT); - - return texture; + + return texturedata; } boolean HUESMOOTH = true; // wrap around bug... true; @@ -7975,8 +8023,8 @@ pigment = null; } - ReleaseTexture(bump, true); - ReleaseTexture(pigment, false); + ReleaseTexture(tex, true); + ReleaseTexture(tex, false); } public void ReleasePigmentTexture(cTexture tex) // INTERFACE @@ -8005,7 +8053,7 @@ pigment = null; } - ReleaseTexture(pigment, false); + ReleaseTexture(tex, false); } public void ReleaseBumpTexture(cTexture tex) // INTERFACE @@ -8034,10 +8082,10 @@ bump = null; } - ReleaseTexture(bump, true); + ReleaseTexture(tex, true); } - void ReleaseTexture(String tex, boolean bump) + void ReleaseTexture(cTexture tex, boolean bump) { if (// DrawMode() != 0 || /*tex == null ||*/ ambientOcclusion ) // || !textureon) @@ -8048,7 +8096,7 @@ CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null; if (tex != null) - texture = textures.get(tex); + texture = bump ? texturebump.get(tex) : texturepigment.get(tex); // //assert( texture != null ); // if (texture == null) @@ -8198,13 +8246,13 @@ if (tex == null) { - BindTexture(null, null,false,resolution); + BindTexture(null,false,resolution); return; } String pigment = Object3D.GetPigment(tex); - usedtextures.add(pigment); + usedtextures.add(tex); //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) { @@ -8218,7 +8266,7 @@ } GetGL().glActiveTexture(GetGL().GL_TEXTURE0); - BindTexture(tex.pigmenttexture, pigment, false, resolution); + BindTexture(tex, false, resolution); } /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE @@ -8231,13 +8279,13 @@ if (tex == null) { - BindTexture(null, null,true,resolution); + BindTexture(null,true,resolution); return; } String bump = Object3D.GetBump(tex); - usedtextures.add(bump); + usedtextures.add(tex); //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES)) { @@ -8251,7 +8299,7 @@ } GetGL().glActiveTexture(GetGL().GL_TEXTURE2); - BindTexture(tex.bumptexture, bump, true, resolution); + BindTexture(tex, true, resolution); GetGL().glActiveTexture(GetGL().GL_TEXTURE0); } @@ -8275,13 +8323,19 @@ return fileExists; } - CacheTexture GetCacheTexture(java.awt.image.BufferedImage bim, String tex, boolean bump, int resolution) throws Exception + CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception { CacheTexture texturecache = null; if (tex != null) { - String texname = tex; + String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex); + byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata; + + if (texname.equals("") && texdata == null) + { + return null; + } String fallbackTextureName = defaultDirectory + "/Textures/" + texname; @@ -8291,29 +8345,46 @@ // else // if (!texname.startsWith("/")) // texname = "/Users/nbriere/Textures/" + texname; - if (!FileExists(tex)) + if (!FileExists(texname)) { texname = fallbackTextureName; } if (CACHETEXTURE) { - if (bim == null) - texturecache = textures.get(texname); // TEXTURE CACHE + if (texdata == null) + texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex); else - texturecache = bimtextures.get(bim); // TEXTURE CACHE + texturecache = bimtextures.get(texdata); } - if (texturecache == null || texturecache.resolution < resolution) + if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution) { TextureData texturedata = null; - if (bim == null) + if (texdata != null && textureon) { + BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); + try + { + bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); + } + catch (Exception e) + { + bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph); + } + + texturecache = new CacheTexture(GetBimTexture(bim, bump), -1); + bimtextures.put(texdata, texturecache); + + //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB); + + //Object bim2 = CreateBim(texturecache.texturedata); + //bim2 = bim; } else - if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) + if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals("")) { assert(!bump); // if (bump) @@ -8324,19 +8395,23 @@ // } // else // { - texturecache = textures.get(tex); + // texturecache = textures.get(texname); // suspicious if (texturecache == null) { texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); } + else + new Exception().printStackTrace(); // } } else - if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) + if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals("")) { assert(bump); - texturecache = textures.get(tex); + // texturecache = textures.get(texname); // suspicious if (texturecache == null) texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution); + else + new Exception().printStackTrace(); } else { //if (tex.equals("IMMORTAL")) @@ -8344,11 +8419,13 @@ // texture = GetResourceTexture("default.png"); //} else //{ - if (tex.equals("WHITE_NOISE")) + if (texname.endsWith("WHITE_NOISE")) { - texturecache = textures.get(tex); + // texturecache = textures.get(texname); // suspicious if (texturecache == null) texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution); + else + new Exception().printStackTrace(); } else { if (textureon) @@ -8407,14 +8484,14 @@ if (texturedata == null) throw new Exception(); - texturecache = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution); + texturecache = new CacheTexture(texturedata,resolution); //texture = GetTexture(tex, bump); } } //} } - if (/*CACHETEXTURE &&*/ texturecache != null && textureon) + if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon) { //return false; @@ -8436,52 +8513,17 @@ File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg"); if (!cachefile.exists()) { - // cache to disk - Buffer buffer = texturedata.getBuffer(); // getMipmapData(); - //buffers[0]. - - ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer(); - int[] pixels = new int[bytebuf.capacity()/3]; - - // squared size heuristic... - if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length)) + //if (texturedata.getWidth() == texturedata.getHeight()) { - for (int i=pixels.length; --i>=0;) - { - int i3 = i*3; - pixels[i] = 0xFF; - pixels[i] <<= 8; - pixels[i] |= bytebuf.get(i3+2) & 0xFF; - pixels[i] <<= 8; - pixels[i] |= bytebuf.get(i3+1) & 0xFF; - pixels[i] <<= 8; - pixels[i] |= bytebuf.get(i3) & 0xFF; - } - - /* - int r=0,g=0,b=0,a=0; - for (int i=0; i<width; i++) - for (int j=0; j<height; j++) - { - int index = j*width+i; - int p = pixels[index]; - a = ((p>>24) & 0xFF); - r = ((p>>16) & 0xFF); - g = ((p>>8) & 0xFF); - b = (p & 0xFF); - pixels[index] = (a<<24) | (b<<16) | (g<<8) | r; - } - /**/ - int width = (int)Math.sqrt(pixels.length); // squared - int height = width; - BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile); - rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width); + BufferedImage rendImage = CreateBim(texturedata); + ImageWriter writer = null; Iterator iter = ImageIO.getImageWritersByFormatName("jpg"); if (iter.hasNext()) { writer = (ImageWriter)iter.next(); } - float compressionQuality = 0.9f; + + float compressionQuality = 0.85f; try { ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile); @@ -8498,18 +8540,20 @@ } } } - + + Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment; + //System.out.println("Texture = " + tex); - if (textures.containsKey(texname)) + if (textures.containsKey(tex)) { - CacheTexture thetex = textures.get(texname); + CacheTexture thetex = textures.get(tex); thetex.texture.disable(); thetex.texture.dispose(); - textures.remove(texname); + textures.remove(tex); } //texture.texturedata = texturedata; - textures.put(texname, texturecache); + textures.put(tex, texturecache); // newtex = true; } @@ -8528,9 +8572,43 @@ return texturecache; } - com.sun.opengl.util.texture.Texture GetTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception + static void EmbedTextures(cTexture tex) { - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); + if (tex.pigmentdata == null) + { + //String texname = Object3D.GetPigment(tex); + + CacheTexture texturecache = texturepigment.get(tex); + + if (texturecache != null) + { + tex.pw = texturecache.texturedata.getWidth(); + tex.ph = texturecache.texturedata.getHeight(); + tex.pigmentdata = //CompressJPEG(CreateBim + ((ByteBuffer)texturecache.texturedata.getBuffer()).array() + ; + //, tex.pw, tex.ph), 0.5f); + } + } + + if (tex.bumpdata == null) + { + //String texname = Object3D.GetBump(tex); + + CacheTexture texturecache = texturebump.get(tex); + + if (texturecache != null) + { + tex.bw = texturecache.texturedata.getWidth(); + tex.bh = texturecache.texturedata.getHeight(); + tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f); + } + } + } + + com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception + { + CacheTexture texture = GetCacheTexture(tex, bump, resolution); if (bump) { @@ -8546,14 +8624,14 @@ return texture!=null?texture.texture:null; } - public com.sun.opengl.util.texture.TextureData GetTextureData(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception + public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception { - CacheTexture texture = GetCacheTexture(stream, tex, bump, resolution); + CacheTexture texture = GetCacheTexture(tex, bump, resolution); return texture!=null?texture.texturedata:null; } - boolean BindTexture(java.awt.image.BufferedImage stream, String tex, boolean bump, int resolution) throws Exception + boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception { if (/*tex == null ||*/ ambientOcclusion ) // || !textureon) { @@ -8562,7 +8640,7 @@ //boolean newtex = false; - com.sun.opengl.util.texture.Texture texture = GetTexture(stream, tex, bump, resolution); + com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution); if (texture == null) return false; @@ -8595,6 +8673,72 @@ return true; // Warning: not used. } + public static byte[] CompressJPEG(BufferedImage image, float quality) + { + try + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); + ImageWriter writer = writers.next(); + + ImageWriteParam param = writer.getDefaultWriteParam(); + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); + param.setCompressionQuality(quality); + + ImageOutputStream ios = ImageIO.createImageOutputStream(baos); + writer.setOutput(ios); + writer.write(null, new IIOImage(image, null, null), param); + + byte[] data = baos.toByteArray(); + writer.dispose(); + return data; + } + catch (Exception e) + { + e.printStackTrace(); + return null; + } + } + + public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException + { + ByteArrayInputStream baos = new ByteArrayInputStream(image); + Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg"); + ImageReader reader = writers.next(); + + BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); + + ImageReadParam param = reader.getDefaultReadParam(); + param.setDestination(bim); + //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB)); + + ImageInputStream ios = ImageIO.createImageInputStream(baos); + reader.setInput(ios); + BufferedImage bim2 = reader.read(0, param); + reader.dispose(); + +// WritableRaster raster = bim2.getRaster(); +// DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); +// byte[] bytes = data.getData(); +// +// int[] pixels = new int[bytes.length/3]; +// for (int i=pixels.length; --i>=0;) +// { +// int i3 = i*3; +// pixels[i] = 0xFF; +// pixels[i] <<= 8; +// pixels[i] |= bytes[i3+2] & 0xFF; +// pixels[i] <<= 8; +// pixels[i] |= bytes[i3+1] & 0xFF; +// pixels[i] <<= 8; +// pixels[i] |= bytes[i3] & 0xFF; +// } +// +// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w); + + return bim; + } + ShadowBuffer shadowPBuf; AntialiasBuffer antialiasPBuf; int MAXSTACK; @@ -11049,7 +11193,7 @@ try { - BindTexture(null, NOISE_TEXTURE, false, 2); + BindTexture(NOISE_TEXTURE, false, 2); } catch (Exception e) { @@ -11340,7 +11484,7 @@ } } - if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) + if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion) { //gl.glDepthFunc(GL.GL_LEQUAL); //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT); @@ -11348,24 +11492,21 @@ boolean texon = textureon; - if (RENDERPROGRAM > 0) - { - gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); - textureon = false; - } + gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB); + textureon = false; + //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB); //System.out.println("ALLO"); gl.glColorMask(false, false, false, false); DrawObject(gl); - if (RENDERPROGRAM > 0) - { - gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); - textureon = texon; - } + + gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB); + textureon = texon; + gl.glColorMask(true, true, true, true); gl.glDepthFunc(GL.GL_EQUAL); - //gl.glDepthMask(false); + gl.glDepthMask(false); } if (false) // DrawMode() == SHADOW) @@ -11705,20 +11846,32 @@ ReleaseTextures(DEFAULT_TEXTURES); if (CLEANCACHE) - for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();) + for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();) { - String tex = e.nextElement(); + cTexture tex = e.nextElement(); // System.out.println("Texture --------- " + tex); - if (tex.equals("WHITE_NOISE")) + if (tex.equals("WHITE_NOISE:")) continue; if (!usedtextures.contains(tex)) { + CacheTexture gettex = texturepigment.get(tex); // System.out.println("DISPOSE +++++++++++++++ " + tex); - textures.get(tex).texture.dispose(); - textures.remove(tex); + if (gettex != null) + { + gettex.texture.dispose(); + texturepigment.remove(tex); + } + + gettex = texturebump.get(tex); + // System.out.println("DISPOSE +++++++++++++++ " + tex); + if (gettex != null) + { + gettex.texture.dispose(); + texturebump.remove(tex); + } } } } @@ -12247,7 +12400,51 @@ //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0); String program = + // Min shader "!!ARBfp1.0\n" + + "PARAM zero123 = { 0.0, 1.0, 2.0, 3.0 };" + + "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" + + "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" + + "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" + + "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" + + "TEMP temp;" + + "TEMP light;" + + "TEMP ndotl;" + + "TEMP normal;" + + "TEMP depth;" + + + "MAD normal, fragment.color, zero123.z, -zero123.y;" + + + "MOV light, state.light[0].position;" + + "DP3 ndotl.x, light, normal;" + + + // shadow + "MOV temp, fragment.texcoord[1];" + + TextureFetch("depth", "temp", "1") + + //"TEX depth, fragment.texcoord[1], texture[1], 2D;" + + "SLT temp.x, fragment.texcoord[1].z, depth.z;" + + + + // No shadow when out of frustum + //"SGE temp.y, depth.z, zero123.y;" + + //"LRP temp.x, temp.y, zero123.y, temp.x;" + + + "MUL ndotl.x, ndotl.x, temp.x;" + + "MAX ndotl.x, ndotl.x, pow2.y;" + + + "TEX temp, fragment.texcoord[0], texture[0], 2D;" + + "MUL temp, temp, ndotl.x;" + + + "MUL temp, temp, zero123.z;" + + + "MOV temp.w, zero123.y;" + // reset alpha + + "MOV result.color, temp;" + + "END"; + + String program2 = + "!!ARBfp1.0\n" + + //"OPTION ARB_fragment_program_shadow;" + "PARAM light2cam0 = program.env[10];" + "PARAM light2cam1 = program.env[11];" + @@ -12362,8 +12559,7 @@ "TEMP shininess;" + "\n" + "MOV texSamp, one;" + - //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" + - + "MOV mapgrid.x, one2048th.x;" + "MOV temp, fragment.texcoord[1];" + /* @@ -12768,7 +12964,7 @@ "MAD shadow.x, buffer.x, frac.y, shadow.x;" + "") + - // display shadow only (bump == 0) + // display shadow only (fakedepth == 0) "SUB temp.x, half.x, shadow.x;" + "MOV temp.y, -params5.z;" + // params6.x;" + "SLT temp.z, temp.y, -one2048th.x;" + @@ -13260,7 +13456,7 @@ "SLT temp.x, temp.x, zero.x;" + // shadoweps "LRP " + shadow + ", temp.x, one, " + shadow + ";" + - // No shadow when out of frustrum + // No shadow when out of frustum "SGE temp.x, " + depth + ".z, one.z;" + "LRP " + shadow + ", temp.x, one, " + shadow + ";" + ""; @@ -14911,7 +15107,8 @@ // break; case 'T': CACHETEXTURE ^= true; - textures.clear(); + texturepigment.clear(); + texturebump.clear(); // repaint(); break; case 'Y': -- Gitblit v1.6.2