JavaFX材质的凹凸和规格贴图 [英] JavaFX material's bump and spec maps

查看:180
本文介绍了JavaFX材质的凹凸和规格贴图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当JavaFX8代码加载颜色,凹凸和规格贴图时,颜色和规格按预期工作,但凹凸贴图会导致奇怪的效果。这三个都是地球的墨卡托地图。通常,凹凸贴图不会添加任何3D效果。凹凸贴图仅使喜马拉雅山脉和安第斯山脉出现在地球上被点亮的一侧,作为带有光泽边框的黑色区域,并且在彩色地图上出现在阴影侧。我做错了什么?

 图片diffMap = null; 
Image bumpMap = null;
图像specMap = null;
diffMap = new Image(MoleculeSampleApp.class.getResource(Color Map1.jpg)。toExternalForm());
bumpMap = new Image(MoleculeSampleApp.class.getResource(Bump1.jpg)。toExternalForm());
specMap = new Image(MoleculeSampleApp.class.getResource(Spec Mask1.png)。toExternalForm());
final PhongMaterial earthMaterial = new PhongMaterial(Color.WHITE,diffMap,specMap,bumpMap,null);
earthMaterial.setDiffuseColor(Color.WHITE);
earthMaterial.setSpecularColor(Color.WHITE);

作为3D的新手,我首先想到的是应该有某种缩放像素颜色值将地图撞到海拔,我不知道。

解决方案

JavaFX的凹凸贴图是法线贴图,不是高度贴图,更多信息,请参阅:

  import javafx.animation。*; 
import javafx.application.Application;
import javafx.scene。*;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.scene.paint。*;
import javafx.scene.shape.Sphere;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
import javafx.util.Duration;

公共类EarthViewer扩展应用程序{

私有静态最终双EARTH_RADIUS = 400;
private static final double VIEWPORT_SIZE = 800;
私有静态最终双ROTATE_SECS = 30;

私有静态最终双倍MAP_WIDTH = 8192 / 2d;
私有静态最终双倍MAP_HEIGHT = 4092 / 2d;

private static final String DIFFUSE_MAP =
http://planetmaker.wthr.us/img/earth_gebco8_texture_8192x4096.jpg;
private static final String NORMAL_MAP =
http://planetmaker.wthr.us/img/earth_normalmap_flat_8192x4096.jpg;
private static final String SPECULAR_MAP =
http://planetmaker.wthr.us/img/earth_specularmap_flat_8192x4096.jpg;

private group buildScene(){
Sphere earth = new Sphere(EARTH_RADIUS);
earth.setTranslateX(VIEWPORT_SIZE / 2d);
earth.setTranslateY(VIEWPORT_SIZE / 2d);

PhongMaterial earthMaterial = new PhongMaterial();
earthMaterial.setDiffuseMap(
新图片(
DIFFUSE_MAP,
MAP_WIDTH,
MAP_HEIGHT,
true,
true

);
earthMaterial.setBumpMap(
new Image(
NORMAL_MAP,
MAP_WIDTH,
MAP_HEIGHT,
true,
true

);
earthMaterial.setSpecularMap(
new Image(
SPECULAR_MAP,
MAP_WIDTH,
MAP_HEIGHT,
true,
true

);

earth.setMaterial(
earthMaterial
);

返回新组(地球);
}

@Override
public void start(阶段阶段){
Group group = buildScene();

场景场景=新场景(
新StackPane(组),
VIEWPORT_SIZE,VIEWPORT_SIZE,
true,
SceneAntialiasing.BALANCED
) ;

scene.setFill(Color.rgb(10,10,40));

scene.setCamera(new PerspectiveCamera());

stage.setScene(场景);
stage.show();

stage.setFullScreen(true);

rotateAroundYAxis(group).play();
}

private RotateTransition rotateAroundYAxis(节点节点){
RotateTransition rotate = new RotateTransition(
Duration.seconds(ROTATE_SECS),
node
);
rotate.setAxis(Rotate.Y_AXIS);
rotate.setFromAngle(360);
rotate.setToAngle(0);
rotate.setInterpolator(Interpolator.LINEAR);
rotate.setCycleCount(RotateTransition.INDEFINITE);

返回旋转;
}

public static void main(String [] args){
launch(args);
}
}




正常吗?为什么????


JavaDoc指出 PhongMaterial bumpMapProperty 声明:


凹凸贴图这个PhongMaterial,是一个存储为RGB图像的法线贴图。


使用法线贴图而不是高度贴图因为


[法线贴图]更准确,因为它们可以模拟像素$
沿着一条线模拟像素
b $ b以任意方式向任何方向移动。


提供了法线贴图和高度贴图的简要说明维基百科凹凸贴图文章。


When JavaFX8 code loads the color, bump and spec maps, the color and spec work as expected, but bump map is causing strange effects. All three are Mercator maps of Earth. Generally, there is no 3d effect added by the bump map. Bump map only causes Himalaya and Andes appear on the lit side of the globe as black areas with shiny border and on the shaded side as they appear on the color map. What am I doing wrong?

Image diffMap = null;
Image bumpMap = null;
Image specMap = null;
diffMap = new Image(MoleculeSampleApp.class.getResource("Color Map1.jpg").toExternalForm());
bumpMap = new Image(MoleculeSampleApp.class.getResource("Bump1.jpg").toExternalForm());
specMap = new Image(MoleculeSampleApp.class.getResource("Spec Mask1.png").toExternalForm());
final PhongMaterial earthMaterial = new PhongMaterial(Color.WHITE, diffMap, specMap, bumpMap, null);
earthMaterial.setDiffuseColor(Color.WHITE);
earthMaterial.setSpecularColor(Color.WHITE);

Being new to 3d my first thought is that there should be some kind of scaling pixel color values of the bump map into elevation, which I am missing.

解决方案

Bump map for JavaFX is a normal map, not a height map, for more info see: normal map and height map info.

Here is a sample you can try.

The images for the maps are pretty large, so it might take a little while to download them before your scene shows.

Source I used for images was => Bored? Then Create a Planet

import javafx.animation.*;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.*;
import javafx.scene.shape.Sphere;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
import javafx.util.Duration;

public class EarthViewer extends Application {

  private static final double EARTH_RADIUS  = 400;
  private static final double VIEWPORT_SIZE = 800;
  private static final double ROTATE_SECS   = 30;

  private static final double MAP_WIDTH  = 8192 / 2d;
  private static final double MAP_HEIGHT = 4092 / 2d;

  private static final String DIFFUSE_MAP =
      "http://planetmaker.wthr.us/img/earth_gebco8_texture_8192x4096.jpg";
  private static final String NORMAL_MAP =
      "http://planetmaker.wthr.us/img/earth_normalmap_flat_8192x4096.jpg";
  private static final String SPECULAR_MAP =
      "http://planetmaker.wthr.us/img/earth_specularmap_flat_8192x4096.jpg";

  private Group buildScene() {
    Sphere earth = new Sphere(EARTH_RADIUS);
    earth.setTranslateX(VIEWPORT_SIZE / 2d);
    earth.setTranslateY(VIEWPORT_SIZE / 2d);

    PhongMaterial earthMaterial = new PhongMaterial();
    earthMaterial.setDiffuseMap(
      new Image(
        DIFFUSE_MAP,
        MAP_WIDTH,
        MAP_HEIGHT,
        true,
        true
      )
    );
    earthMaterial.setBumpMap(
      new Image(
        NORMAL_MAP,
        MAP_WIDTH,
        MAP_HEIGHT,
        true,
        true
      )
    );
    earthMaterial.setSpecularMap(
      new Image(
        SPECULAR_MAP,
        MAP_WIDTH,
        MAP_HEIGHT,
        true,
        true
      )
    );

    earth.setMaterial(
        earthMaterial
    );

    return new Group(earth);
  }

  @Override
  public void start(Stage stage) {
    Group group = buildScene();

    Scene scene = new Scene(
      new StackPane(group),
      VIEWPORT_SIZE, VIEWPORT_SIZE,
      true,
      SceneAntialiasing.BALANCED
    );

    scene.setFill(Color.rgb(10, 10, 40));

    scene.setCamera(new PerspectiveCamera());

    stage.setScene(scene);
    stage.show();

    stage.setFullScreen(true);

    rotateAroundYAxis(group).play();
  }

  private RotateTransition rotateAroundYAxis(Node node) {
    RotateTransition rotate = new RotateTransition(
      Duration.seconds(ROTATE_SECS), 
      node
    );
    rotate.setAxis(Rotate.Y_AXIS);
    rotate.setFromAngle(360);
    rotate.setToAngle(0);
    rotate.setInterpolator(Interpolator.LINEAR);
    rotate.setCycleCount(RotateTransition.INDEFINITE);

    return rotate;
  }

  public static void main(String[] args) {
    launch(args);
  }
}

Normal? Why????

The JavaDoc states for the PhongMaterial bumpMapProperty states:

The bump map of this PhongMaterial, which is a normal map stored as a RGB Image.

A normal map is used rather than a height map because:

[normal maps] are much more accurate, as rather than only simulating the pixel being away from the face along a line, they can simulate that pixel being moved at any direction, in an arbitrary way.

A brief description of both normal mapping and height mapping is provided in the wikipedia bump mapping article.

这篇关于JavaFX材质的凹凸和规格贴图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆