private void createScene(Geometry geometry, double scale) {
      Texture mapHeight = new Texture(texture);

      mapHeight.setAnisotropy(4);
      mapHeight.getRepeat().set(0.998, 0.998);
      mapHeight.getOffset().set(0.001, 0.001);
      mapHeight.setWrapS(TextureWrapMode.REPEAT);
      mapHeight.setWrapT(TextureWrapMode.REPEAT);
      mapHeight.setFormat(PixelFormat.RGB);

      Texture mapSpecular = new Texture(textureSpec);
      mapSpecular.getRepeat().set(0.998, 0.998);
      mapSpecular.getOffset().set(0.001, 0.001);
      mapSpecular.setWrapS(TextureWrapMode.REPEAT);
      mapSpecular.setWrapT(TextureWrapMode.REPEAT);
      mapSpecular.setFormat(PixelFormat.RGB);

      Texture mapColor = new Texture(textureCol);
      mapColor.getRepeat().set(0.998, 0.998);
      mapColor.getOffset().set(0.001, 0.001);
      mapColor.setWrapS(TextureWrapMode.REPEAT);
      mapColor.setWrapT(TextureWrapMode.REPEAT);
      mapColor.setFormat(PixelFormat.RGB);

      SkinSimpleShader shader = new SkinSimpleShader();

      Map<String, Uniform> uniforms = shader.getUniforms();

      uniforms.get("enableBump").setValue(true);
      uniforms.get("enableSpecular").setValue(true);

      uniforms.get("tBeckmann").setValue(composerBeckmann.getRenderTarget1());
      uniforms.get("tDiffuse").setValue(mapColor);

      uniforms.get("bumpMap").setValue(mapHeight);
      uniforms.get("specularMap").setValue(mapSpecular);

      ((Color) uniforms.get("ambient").getValue()).setHex(0xa0a0a0);
      ((Color) uniforms.get("diffuse").getValue()).setHex(0xa0a0a0);
      ((Color) uniforms.get("specular").getValue()).setHex(0xa0a0a0);

      uniforms.get("uRoughness").setValue(0.145);
      uniforms.get("uSpecularBrightness").setValue(0.75);

      uniforms.get("bumpScale").setValue(16.0);

      ((Vector4) uniforms.get("offsetRepeat").getValue()).set(0.001, 0.001, 0.998, 0.998);

      ShaderMaterial material = new ShaderMaterial(shader);
      material.setLights(true);

      mesh = new Mesh(geometry, material);

      mesh.getPosition().setY(-50);
      mesh.getScale().set(scale);

      mesh.setCastShadow(true);
      mesh.setReceiveShadow(true);

      getScene().add(mesh);
    }
Ejemplo n.º 2
0
  public void refreshUniforms(Camera camera, boolean isGammaInput) {
    if (!(this instanceof HasMaterialMap)) return;

    Map<String, Uniform> uniforms = getShader().getUniforms();

    uniforms.get("opacity").setValue(getOpacity());

    if (this instanceof HasColor) {
      if (isGammaInput)
        ((Color) uniforms.get("diffuse").getValue())
            .copyGammaToLinear(((HasColor) this).getColor());
      else uniforms.get("diffuse").setValue(((HasColor) this).getColor());
    }

    if (this instanceof HasMap) {
      uniforms.get("map").setValue(((HasMap) this).getMap());
    }

    if (this instanceof HasLightMap)
      uniforms.get("lightMap").setValue(((HasLightMap) this).getLightMap());

    if (this instanceof HasSpecularMap) {
      uniforms.get("specularMap").setValue(((HasSpecularMap) this).getSpecularMap());
    }

    if (this instanceof HasAlphaMap) {
      uniforms.get("alphaMap").setValue(((HasAlphaMap) this).getAlphaMap());
    }

    if (this instanceof HasBumpMap) {
      uniforms.get("bumpMap").setValue(((HasBumpMap) this).getBumpMap());
      uniforms.get("bumpScale").setValue(((HasBumpMap) this).getBumpScale());
    }

    if (this instanceof HasNormalMap) {
      uniforms.get("normalMap").setValue(((HasNormalMap) this).getNormalMap());
      uniforms.get("normalScale").setValue(((HasNormalMap) this).getNormalScale());
    }

    // uv repeat and offset setting priorities
    //  1. color map
    //  2. specular map
    //  3. normal map
    //  4. bump map
    //  5. alpha map
    Texture uvScaleMap = null;

    if (this instanceof HasMap) uvScaleMap = ((HasMap) this).getMap();
    if (uvScaleMap == null && this instanceof HasSpecularMap)
      uvScaleMap = ((HasSpecularMap) this).getSpecularMap();
    if (uvScaleMap == null && this instanceof HasNormalMap)
      uvScaleMap = ((HasNormalMap) this).getNormalMap();
    if (uvScaleMap == null && this instanceof HasBumpMap)
      uvScaleMap = ((HasBumpMap) this).getBumpMap();
    if (uvScaleMap == null && this instanceof HasAlphaMap)
      uvScaleMap = ((HasAlphaMap) this).getAlphaMap();

    if (uvScaleMap != null) {
      ((Vector4) uniforms.get("offsetRepeat").getValue())
          .set(
              uvScaleMap.getOffset().getX(),
              uvScaleMap.getOffset().getY(),
              uvScaleMap.getRepeat().getX(),
              uvScaleMap.getRepeat().getY());
    }

    if (this instanceof HasEnvMap) {
      HasEnvMap envMapMaterial = (HasEnvMap) this;

      uniforms.get("envMap").setValue(envMapMaterial.getEnvMap());
      uniforms
          .get("flipEnvMap")
          .setValue(
              (envMapMaterial.getEnvMap() != null
                      && envMapMaterial.getEnvMap().getClass() == RenderTargetCubeTexture.class)
                  ? 1.0
                  : -1.0);

      if (isGammaInput) uniforms.get("reflectivity").setValue(envMapMaterial.getReflectivity());
      else uniforms.get("reflectivity").setValue(envMapMaterial.getReflectivity());

      uniforms.get("refractionRatio").setValue(envMapMaterial.getRefractionRatio());
      uniforms.get("combine").setValue(envMapMaterial.getCombine().getValue());
      uniforms
          .get("useRefract")
          .setValue(
              (envMapMaterial.getEnvMap() != null
                      && envMapMaterial.getEnvMap().getMapping()
                          == Texture.MAPPING_MODE.CUBE_REFRACTION)
                  ? 1
                  : 0);
    }
  }