2013-10-27 1 views
1

JavaFX8 코드가 색상, 범프 및 스펙 맵을로드 할 때 색상 및 스펙이 예상대로 작동하지만 범프 맵이 이상한 효과를 일으 킵니다. 세 가지 모두 지구의 메르카토지도입니다. 일반적으로 범프 맵에는 3D 효과가 추가되지 않습니다. 범프 맵은 히말라야와 안데스가 글로브의 밝은면에 반짝이는 테두리가있는 검은 색 영역과 컬러 맵에 나타나는 음영이있는면으로 나타납니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 내 첫번째 생각을 3D로 새로운 웰빙JavaFX 머티리얼의 범프 및 스펙 맵

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); 

내가 놓친 거지 상승에 범프 맵의 픽셀의 색상 값을 스케일링의 일종이 있어야한다는 것입니다.

답변

2

JavaFX 용 범프 맵은 높이 맵이 아닌 일반 맵으로 자세한 내용은 normal map and height map info을 참조하십시오.

다음은 시도 할 수있는 샘플입니다. 이 장면이 보여 전에 다운로드 약간의 시간이 걸릴 수 있도록

enter image description here

지도에 대한 이미지는 매우 크다. 나는 이미지에 사용

소스 =>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); 
    } 
} 

정상입니까? 왜???? PhongMaterial bumpMapProperty 상태의

Javadoc의 상태 :

RGB 이미지로 저장 노멀 맵이다 PhongMaterial이, 상기 범프 맵.

노멀 맵이 아니라 높이 맵 because보다 사용

:

[노멀 맵]가 더 정확뿐만 아니라 전용 라인을 따라면에서 멀어지게되는 화소 시뮬레이션보다 픽셀 이 임의의 방향으로 어떤 방향 으로든 움직이는 것을 시뮬레이션 할 수 있습니다.

일반 매핑과 높이 매핑에 대한 간략한 설명은 wikipedia bump mapping 문서에서 제공됩니다.

+0

정상? 왜???? – ajeh

+0

범프 맵핑에 법선 맵이 사용되는 이유를 설명하는 답변이 업데이트되었습니다. – jewelsea

+0

당신은 아이러니를 놓쳤습니다! 노멀 맵을 사용하지만 매개 변수 '범프 맵'을 호출하는 것은 혼란 스럽습니다. 나는 범프 맵이 작동하지 않는 이유를 알아 내려고 애 쓰고 있었지만 매개 변수 '노멀 맵'을 호출하면 요구 사항이 무엇인지 알 수 있었을 것입니다. – ajeh