示例#1
0
  private Spatial getSpatial(String name) {
    Node node = new Node(name);
    //        load picture
    Picture pic = new Picture(name);
    Texture2D tex = (Texture2D) assetManager.loadTexture("Textures/" + name + ".png");
    pic.setTexture(assetManager, tex, true);

    //        adjust picture
    float width = tex.getImage().getWidth();
    float height = tex.getImage().getHeight();
    pic.setWidth(width);
    pic.setHeight(height);
    pic.move(-width / 2f, -height / 2f, 0);

    //        add a material to the picture
    Material picMat = new Material(assetManager, "Common/MatDefs/Gui/Gui.j3md");
    picMat.getAdditionalRenderState().setBlendMode(BlendMode.AlphaAdditive);
    node.setMaterial(new Material());

    //        set the radius of the spatial
    //        (using width only as a simple approximation)
    // node.setUserData("radius", width/2);

    //        attach the picture to the node and return it
    node.attachChild(pic);
    return node;
  }
 protected void loadTextures(AssetManager manager) {
   normalTexture =
       (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/water_normalmap.png");
   dudvTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/dudv_map.jpg");
   normalTexture.setWrap(WrapMode.Repeat);
   dudvTexture.setWrap(WrapMode.Repeat);
 }
  public RenderImageJme(Texture2D texture) {
    if (texture.getImage() == null) {
      throw new IllegalArgumentException("texture.getImage() cannot be null");
    }

    this.texture = texture;
    this.image = texture.getImage();
    width = image.getWidth();
    height = image.getHeight();
  }
  public RenderImageJme(String filename, boolean linear, NiftyJmeDisplay display) {
    TextureKey key = new TextureKey(filename, true);

    key.setAnisotropy(0);
    key.setGenerateMips(false);

    texture = (Texture2D) display.getAssetManager().loadTexture(key);
    texture.setMagFilter(linear ? MagFilter.Bilinear : MagFilter.Nearest);
    texture.setMinFilter(linear ? MinFilter.BilinearNoMipMaps : MinFilter.NearestNoMipMaps);
    image = texture.getImage();

    width = image.getWidth();
    height = image.getHeight();
  }
  /**
   * iterate through the filter list and renders filters
   *
   * @param r
   * @param sceneFb
   */
  private void renderFilterChain(Renderer r, FrameBuffer sceneFb) {
    Texture2D tex = filterTexture;
    FrameBuffer buff = sceneFb;
    boolean msDepth = depthTexture != null && depthTexture.getImage().getMultiSamples() > 1;
    for (int i = 0; i < filters.size(); i++) {
      Filter filter = filters.get(i);
      if (filter.isEnabled()) {
        if (filter.getPostRenderPasses() != null) {
          for (Iterator<Filter.Pass> it1 = filter.getPostRenderPasses().iterator();
              it1.hasNext(); ) {
            Filter.Pass pass = it1.next();
            pass.beforeRender();
            if (pass.requiresSceneAsTexture()) {
              pass.getPassMaterial().setTexture("Texture", tex);
              if (tex.getImage().getMultiSamples() > 1) {
                pass.getPassMaterial().setInt("NumSamples", tex.getImage().getMultiSamples());
              } else {
                pass.getPassMaterial().clearParam("NumSamples");
              }
            }
            if (pass.requiresDepthAsTexture()) {
              pass.getPassMaterial().setTexture("DepthTexture", depthTexture);
              if (msDepth) {
                pass.getPassMaterial()
                    .setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples());
              } else {
                pass.getPassMaterial().clearParam("NumSamplesDepth");
              }
            }
            renderProcessing(r, pass.getRenderFrameBuffer(), pass.getPassMaterial());
          }
        }

        filter.postFrame(renderManager, viewPort, buff, sceneFb);

        Material mat = filter.getMaterial();
        if (msDepth && filter.isRequiresDepthTexture()) {
          mat.setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples());
        }

        if (filter.isRequiresSceneTexture()) {
          mat.setTexture("Texture", tex);
          if (tex.getImage().getMultiSamples() > 1) {
            mat.setInt("NumSamples", tex.getImage().getMultiSamples());
          } else {
            mat.clearParam("NumSamples");
          }
        }

        buff = outputBuffer;
        if (i != lastFilterIndex) {
          buff = filter.getRenderFrameBuffer();
          tex = filter.getRenderedTexture();
        }
        renderProcessing(r, buff, mat);
      }
    }
  }
  /**
   * Sets the filtering mode for shadow edges see {@link EdgeFilteringMode} for more info
   *
   * @param EdgeFilteringMode
   */
  public final void setEdgeFilteringMode(EdgeFilteringMode filterMode) {
    if (filterMode == null) {
      throw new NullPointerException();
    }

    if (this.edgeFilteringMode == filterMode) {
      return;
    }

    this.edgeFilteringMode = filterMode;
    postshadowMat.setInt("FilterMode", filterMode.getMaterialParamValue());
    postshadowMat.setFloat("PCFEdge", edgesThickness);
    if (shadowCompareMode == CompareMode.Hardware) {
      for (Texture2D shadowMap : shadowMaps) {
        if (filterMode == EdgeFilteringMode.Bilinear) {
          shadowMap.setMagFilter(MagFilter.Bilinear);
          shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
        } else {
          shadowMap.setMagFilter(MagFilter.Nearest);
          shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
        }
      }
    }
  }
  /**
   * sets the shadow compare mode see {@link CompareMode} for more info
   *
   * @param compareMode
   */
  public final void setShadowCompareMode(CompareMode compareMode) {
    if (compareMode == null) {
      throw new IllegalArgumentException("Shadow compare mode cannot be null");
    }

    this.shadowCompareMode = compareMode;
    for (Texture2D shadowMap : shadowMaps) {
      if (compareMode == CompareMode.Hardware) {
        shadowMap.setShadowCompareMode(ShadowCompareMode.LessOrEqual);
        if (edgeFilteringMode == EdgeFilteringMode.Bilinear) {
          shadowMap.setMagFilter(MagFilter.Bilinear);
          shadowMap.setMinFilter(MinFilter.BilinearNoMipMaps);
        } else {
          shadowMap.setMagFilter(MagFilter.Nearest);
          shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
        }
      } else {
        shadowMap.setShadowCompareMode(ShadowCompareMode.Off);
        shadowMap.setMagFilter(MagFilter.Nearest);
        shadowMap.setMinFilter(MinFilter.NearestNoMipMaps);
      }
    }
    postshadowMat.setBoolean("HardwareShadows", compareMode == CompareMode.Hardware);
  }