private void setJade(final UIPanel panel) {
    panel.setTooltipText("A Jade-like texture");

    final Texture tex = new Texture2D();

    // Build up our function
    final Function3D primaryJade = new RidgeFunction3D(Functions.simplexNoise(), 6, 2.0, 2.207);
    final Function3D baseSecondaryJade = new CylinderFunction3D(2);
    final Function3D rotatedBaseSecondaryJade =
        Functions.rotateInput(
            baseSecondaryJade,
            new Matrix3().fromAngles(0, MathUtils.DEG_TO_RAD * 65, MathUtils.DEG_TO_RAD * 85));
    final Function3D perturbedBaseSecondaryJade =
        new TurbulenceFunction3D(rotatedBaseSecondaryJade, 1.0 / 4.0, 4, 4.0);
    final Function3D secondaryJade = Functions.scaleBias(perturbedBaseSecondaryJade, .25, 0);
    final Function3D combinedJade = Functions.add(primaryJade, secondaryJade);
    final Function3D finalJade = new TurbulenceFunction3D(combinedJade, 1 / 16.0, 2, 4.0);

    final ReadOnlyColorRGBA[] jadeColors = new ReadOnlyColorRGBA[256];
    jadeColors[0] = new ColorRGBA(24 / 255f, 146 / 255f, 102 / 255f, 1);
    jadeColors[127] = new ColorRGBA(78 / 255f, 154 / 255f, 115 / 255f, 1);
    jadeColors[159] = new ColorRGBA(128 / 255f, 204 / 255f, 165 / 255f, 1);
    jadeColors[175] = new ColorRGBA(78 / 255f, 154 / 255f, 115 / 255f, 1);
    jadeColors[255] = new ColorRGBA(29 / 255f, 135 / 255f, 102 / 255f, 1);
    GeneratedImageFactory.fillInColorTable(jadeColors);

    Image img = GeneratedImageFactory.createLuminance8Image(finalJade, wside, hside, 1);
    img = GeneratedImageFactory.createColorImageFromLuminance8(img, false, jadeColors);
    tex.setImage(img);
    tex.setTextureKey(TextureKey.getRTTKey(MinificationFilter.Trilinear));
    tex.setMagnificationFilter(MagnificationFilter.Bilinear);
    tex.setMinificationFilter(MinificationFilter.Trilinear);

    applyTexture(tex, panel);
  }
  private void setMandelbrot(final UIPanel panel) {
    panel.setTooltipText("The famous Mandelbrot fractal");

    final Texture tex = new Texture2D();

    // Build up our function
    final Function3D mandelBase = new MandelbrotFunction3D(256);
    final Function3D translatedMandel = Functions.translateInput(mandelBase, -.7, 0, 0);
    final Function3D finalMandel = Functions.scaleInput(translatedMandel, 1.5, 1.5, 1);

    final ReadOnlyColorRGBA[] colors = new ReadOnlyColorRGBA[256];
    colors[0] = ColorRGBA.BLUE;
    colors[10] = ColorRGBA.YELLOW;
    colors[25] = ColorRGBA.BLUE;
    colors[255] = ColorRGBA.BLACK;
    GeneratedImageFactory.fillInColorTable(colors);

    Image img =
        GeneratedImageFactory.createLuminance8Image(
            finalMandel, (int) (1.5 * wside), (int) (1.5 * hside), 1);
    img = GeneratedImageFactory.createColorImageFromLuminance8(img, false, colors);
    tex.setImage(img);
    tex.setTextureKey(TextureKey.getRTTKey(MinificationFilter.Trilinear));
    tex.setMagnificationFilter(MagnificationFilter.Bilinear);
    tex.setMinificationFilter(MinificationFilter.Trilinear);

    applyTexture(tex, panel);
  }
  private void setWoodGrain(final UIPanel panel) {
    panel.setTooltipText("Dark wood grain.");

    final Texture tex = new Texture2D();

    // Build up our function
    final Function3D baseWood = new CylinderFunction3D(18);
    final Function3D woodGrainNoise = new FbmFunction3D(Functions.simplexNoise(), 3, 40, 0.75, 2.3);
    final Function3D scaledBaseWoodGrain = Functions.scaleInput(woodGrainNoise, 1, .25, 1);
    final Function3D woodGrain = Functions.scaleBias(scaledBaseWoodGrain, .125, 0);
    final Function3D combinedWood = Functions.add(baseWood, woodGrain);
    final Function3D perturbedWood = new TurbulenceFunction3D(combinedWood, 1 / 256.0, 4, 4.0);
    final Function3D translatedWood = Functions.translateInput(perturbedWood, 0, 0, 1.5);
    final Function3D rotatedWood =
        Functions.rotateInput(
            translatedWood, new Matrix3().fromAngles(MathUtils.DEG_TO_RAD * 6, 0, 0));
    final Function3D finalWood = new TurbulenceFunction3D(rotatedWood, 1 / 512.0, 2, 2.0);

    final ReadOnlyColorRGBA[] woodColors = new ReadOnlyColorRGBA[256];
    woodColors[0] = new ColorRGBA(189 / 255f, 94 / 255f, 4 / 255f, 1);
    woodColors[127] = new ColorRGBA(144 / 255f, 48 / 255f, 6 / 255f, 1);
    woodColors[255] = new ColorRGBA(60 / 255f, 10 / 255f, 8 / 255f, 1);
    GeneratedImageFactory.fillInColorTable(woodColors);

    Image img = GeneratedImageFactory.createLuminance8Image(finalWood, wside, hside, 1);
    img = GeneratedImageFactory.createColorImageFromLuminance8(img, false, woodColors);
    tex.setImage(img);
    tex.setTextureKey(TextureKey.getRTTKey(MinificationFilter.Trilinear));
    tex.setMagnificationFilter(MagnificationFilter.Bilinear);
    tex.setMinificationFilter(MinificationFilter.Trilinear);

    applyTexture(tex, panel);
  }
  private void setColors(final UIPanel panel) {
    panel.setTooltipText("The 1-D color map used to colorize our gradient.");

    final Texture tex = new Texture2D();
    final Image img = GeneratedImageFactory.create1DColorImage(false, terrainColors);
    tex.setImage(img);
    tex.setTextureKey(
        TextureKey.getKey(null, false, TextureStoreFormat.RGB8, MinificationFilter.Trilinear));
    tex.setMagnificationFilter(MagnificationFilter.NearestNeighbor);
    tex.setMinificationFilter(MinificationFilter.Trilinear);

    applyTexture(tex, panel);
  }
Beispiel #5
0
 private String getLocalMeshTextureName(final Mesh mesh) {
   final String textureName;
   if (mesh.getLocalRenderState(StateType.Texture) != null) {
     final TextureState textureState = (TextureState) mesh.getLocalRenderState(StateType.Texture);
     if (textureState.isEnabled() && textureState.getTexture() != null) {
       final TextureKey tKey = textureState.getTexture().getTextureKey();
       final String tmpTextureName = tKey.getSource().getName();
       final int lastIndexOfUnixPathSeparator = tmpTextureName.lastIndexOf('/');
       final int lastIndexOfWindowsPathSeparator = tmpTextureName.lastIndexOf('\\');
       if (lastIndexOfUnixPathSeparator != -1) {
         textureName = tmpTextureName.substring(lastIndexOfUnixPathSeparator + 1);
       } else {
         if (lastIndexOfWindowsPathSeparator != -1) {
           textureName = tmpTextureName.substring(lastIndexOfWindowsPathSeparator + 1);
         } else {
           textureName = tmpTextureName;
         }
       }
       if (tKey.isFlipped()) {
         ObjExporter.logger.warning(
             "The texture "
                 + tmpTextureName
                 + " will have to be flipped manually when loading this OBJ file");
       } else {
         ObjExporter.logger.warning(
             "The texture "
                 + tmpTextureName
                 + " might need to be flipped manually when loading this OBJ file");
       }
     } else {
       textureName = null;
     }
   } else {
     textureName = null;
   }
   return textureName;
 }
  /**
   * <code>setupTexture</code> initializes a new Texture object for use with TextureRenderer.
   * Generates a valid gl texture id for this texture and inits the data type for the texture.
   */
  public void setupTexture(final Texture tex) {
    if (tex.getType() != Type.TwoDimensional) {
      throw new IllegalArgumentException("Unsupported type: " + tex.getType());
    }
    final RenderContext context = ContextManager.getCurrentContext();
    final TextureStateRecord record =
        (TextureStateRecord) context.getStateRecord(RenderState.StateType.Texture);

    // check if we are already setup... if so, throw error.
    if (tex.getTextureKey() == null) {
      tex.setTextureKey(TextureKey.getRTTKey(tex.getMinificationFilter()));
    } else if (tex.getTextureIdForContext(context.getGlContextRep()) != 0) {
      throw new Ardor3dException("Texture is already setup and has id.");
    }

    // Create the texture
    final IntBuffer ibuf = BufferUtils.createIntBuffer(1);
    GL11.glGenTextures(ibuf);
    final int textureId = ibuf.get(0);
    tex.setTextureIdForContext(context.getGlContextRep(), textureId);

    LwjglTextureStateUtil.doTextureBind(tex, 0, true);

    // Initialize our texture with some default data.
    final int internalFormat = LwjglTextureUtil.getGLInternalFormat(tex.getTextureStoreFormat());
    final int dataFormat =
        LwjglTextureUtil.getGLPixelFormatFromStoreFormat(tex.getTextureStoreFormat());
    final int pixelDataType =
        LwjglTextureUtil.getGLPixelDataType(tex.getRenderedTexturePixelDataType());

    GL11.glTexImage2D(
        GL11.GL_TEXTURE_2D,
        0,
        internalFormat,
        _width,
        _height,
        0,
        dataFormat,
        pixelDataType,
        (ByteBuffer) null);

    // Setup filtering and wrap
    final TextureRecord texRecord = record.getTextureRecord(textureId, tex.getType());
    LwjglTextureStateUtil.applyFilter(tex, texRecord, 0, record, context.getCapabilities());
    LwjglTextureStateUtil.applyWrap(tex, texRecord, 0, record, context.getCapabilities());

    logger.fine("setup pbuffer tex" + textureId + ": " + _width + "," + _height);
  }
  private void setTerrain(
      final UIPanel panel, final Function3D in, final boolean useFbm, final boolean useColor) {
    final Texture tex = new Texture2D();
    Function3D func = in;
    if (useFbm) {
      func = new FbmFunction3D(func, 5, 0.5, 0.5, 3.14);
    }
    Image img = GeneratedImageFactory.createLuminance8Image(func, wside, hside, 1);
    if (useColor) {
      img = GeneratedImageFactory.createColorImageFromLuminance8(img, false, terrainColors);
    }
    tex.setImage(img);
    tex.setTextureKey(TextureKey.getRTTKey(MinificationFilter.Trilinear));
    tex.setMagnificationFilter(MagnificationFilter.Bilinear);
    tex.setMinificationFilter(MinificationFilter.Trilinear);

    applyTexture(tex, panel);
  }
  private void setCheck(final UIPanel panel) {
    panel.setTooltipText("Simple Checkerboard pattern");

    final Texture tex = new Texture2D();

    // Build up our function
    final Function3D finalCheck = new CheckerFunction3D();

    final Image img =
        GeneratedImageFactory.createLuminance8Image(
            finalCheck, wside, hside, 1, 1, 9, 1, 9, 0, 0, -1, 1);
    tex.setImage(img);
    // No need for filtering on this one...
    tex.setTextureKey(TextureKey.getRTTKey(MinificationFilter.NearestNeighborNoMipMaps));
    tex.setMagnificationFilter(MagnificationFilter.NearestNeighbor);
    tex.setMinificationFilter(MinificationFilter.NearestNeighborNoMipMaps);

    applyTexture(tex, panel);
  }
Beispiel #9
0
  private void createTexture() {

    texture = new SharedTexture2D();
    texture.setWrap(Texture.WrapMode.BorderClamp);
    texture.setMinificationFilter(Texture.MinificationFilter.BilinearNoMipMaps);
    texture.setMagnificationFilter(Texture.MagnificationFilter.Bilinear);
    texture.setHasBorder(true);
    if (borderWhite) {
      texture.setBorderColor(ColorRGBA.WHITE);
    } else {
      texture.setBorderColor(ColorRGBA.BLACK_NO_ALPHA);
    }

    texture.setEnvironmentalMapMode(Texture.EnvironmentalMapMode.EyeLinear);
    texture.setTextureStoreFormat(TextureStoreFormat.Depth32);
    texture.setDepthCompareMode(DepthTextureCompareMode.RtoTexture);
    texture.setDepthCompareFunc(func);
    texture.setDepthMode(DepthTextureMode.Intensity);
    texture.setTextureKey(TextureKey.getRTTKey(Texture.MinificationFilter.BilinearNoMipMaps));
  }
  private void setVoronoi(final UIPanel panel) {
    panel.setTooltipText("Voronoi graph");

    final Texture tex = new Texture2D();

    final ReadOnlyColorRGBA[] colors = new ReadOnlyColorRGBA[256];
    colors[0] = ColorRGBA.BLUE;
    colors[255] = ColorRGBA.BLACK;
    GeneratedImageFactory.fillInColorTable(colors);

    Image img =
        GeneratedImageFactory.createLuminance8Image(
            new VoroniFunction3D(6, .5, true, 1), wside, hside, 1);
    img = GeneratedImageFactory.createColorImageFromLuminance8(img, false, colors);
    tex.setImage(img);
    tex.setTextureKey(TextureKey.getRTTKey(MinificationFilter.Trilinear));
    tex.setMagnificationFilter(MagnificationFilter.Bilinear);
    tex.setMinificationFilter(MinificationFilter.Trilinear);

    applyTexture(tex, panel);
  }
  private void setSlime(final UIPanel panel) {
    panel.setTooltipText(
        "Slime: Built with two bubble functions of different sizes\n"
            + "and blended with a mapping function.");
    panel.setTooltipPopTime(25);

    final Texture tex = new Texture2D();

    // Build up our function
    final Function3D largeSlimeBase =
        new CloudsFunction3D(Functions.simplexNoise(), 1, 4.0, 0.5, 2.12);
    final Function3D largeSlime = Functions.scaleBias(largeSlimeBase, 1, 0.5);
    final Function3D smallSlimeBase =
        new CloudsFunction3D(Functions.simplexNoise(), 1, 24.0, 0.5, 2.14);
    final Function3D smallSlime = Functions.scaleBias(smallSlimeBase, 0.5, 0);
    final RidgeFunction3D slimeMap = new RidgeFunction3D(Functions.simplexNoise(), 3, 2.0, 2.207);
    final MapperFunction3D slimeMapper = new MapperFunction3D(slimeMap, -1, 1);
    slimeMapper.addFunction(largeSlime, 0, 0, 0);
    slimeMapper.addFunction(smallSlime, .125, 1, 1);
    slimeMapper.addFunction(largeSlime, 1.75, 0, 0);
    final Function3D finalSlime = new TurbulenceFunction3D(slimeMapper, 1 / 32.0, 2, 8.0);

    final ReadOnlyColorRGBA[] slimeColors = new ReadOnlyColorRGBA[256];
    slimeColors[0] = new ColorRGBA(160 / 255f, 64 / 255f, 42 / 255f, 1);
    slimeColors[127] = new ColorRGBA(64 / 255f, 192 / 255f, 64 / 255f, 1);
    slimeColors[255] = new ColorRGBA(128 / 255f, 255 / 255f, 128 / 255f, 1);
    GeneratedImageFactory.fillInColorTable(slimeColors);

    Image img = GeneratedImageFactory.createLuminance8Image(finalSlime, wside, hside, 1);
    img = GeneratedImageFactory.createColorImageFromLuminance8(img, false, slimeColors);
    tex.setImage(img);
    tex.setTextureKey(TextureKey.getRTTKey(MinificationFilter.Trilinear));
    tex.setMagnificationFilter(MagnificationFilter.Bilinear);
    tex.setMinificationFilter(MinificationFilter.Trilinear);

    applyTexture(tex, panel);
  }