Пример #1
0
  /**
   * 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);
      }
    }
  }
Пример #2
0
  public DDSPreview(ProjectAssetManager assetManager) {
    this.assetManager = assetManager;

    Quad quadMesh = new Quad(4.5f, 4.5f);
    Quad quadMesh3D = new Quad(4.5f, 4.5f);
    quadMesh3D.scaleTextureCoordinates(new Vector2f(4, 4));
    quad = new Geometry("previewQuad", quadMesh);
    quad.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0));
    quad3D = new Geometry("previewQuad", quadMesh3D);
    quad3D.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0));
    material3D = new Material(assetManager, "com/jme3/gde/core/properties/preview/tex3DThumb.j3md");
    material3D.setFloat("InvDepth", 1f / 16f);
    material3D.setInt("Rows", 4);
    material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    SceneApplication.getApplication().addSceneListener(this);
  }
Пример #3
0
  private void setMatParams() {

    GeometryList l = viewPort.getQueue().getShadowQueueContent(ShadowMode.Receive);

    // iteration throught all the geometries of the list to gather the materials

    matCache.clear();
    for (int i = 0; i < l.size(); i++) {
      Material mat = l.get(i).getMaterial();
      // checking if the material has the post technique and adding it to the material cache
      if (mat.getMaterialDef().getTechniqueDef(postTechniqueName) != null) {
        if (!matCache.contains(mat)) {
          matCache.add(mat);
        }
      } else {
        needsfallBackMaterial = true;
      }
    }

    // iterating through the mat cache and setting the parameters
    for (Material mat : matCache) {

      mat.setFloat("ShadowMapSize", shadowMapSize);

      for (int j = 0; j < nbShadowMaps; j++) {
        mat.setMatrix4("LightViewProjectionMatrix" + j, lightViewProjectionsMatrices[j]);
      }
      for (int j = 0; j < nbShadowMaps; j++) {
        mat.setTexture("ShadowMap" + j, shadowMaps[j]);
      }
      mat.setBoolean("HardwareShadows", shadowCompareMode == CompareMode.Hardware);
      mat.setInt("FilterMode", edgeFilteringMode.getMaterialParamValue());
      mat.setFloat("PCFEdge", edgesThickness);
      mat.setFloat("ShadowIntensity", shadowIntensity);

      setMaterialParameters(mat);
    }

    // At least one material of the receiving geoms does not support the post shadow techniques
    // so we fall back to the forced material solution (transparent shadows won't be supported for
    // these objects)
    if (needsfallBackMaterial) {
      setPostShadowParams();
    }
  }
Пример #4
0
  /**
   * 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);
        }
      }
    }
  }