Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

WIP: JDK-8217477: Implement attenuation-coefficients for PointLight #384

Draft
wants to merge 23 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ protected NGNode createPeerImpl(Node node) {
return pointLightAccessor.doCreatePeer(node);
}

@Override
protected void updatePeerImpl(Node node) {
super.updatePeerImpl(node);
pointLightAccessor.doUpdatePeer(node);
}

public static void setPointLightAccessor(final PointLightAccessor newAccessor) {
if (pointLightAccessor != null) {
throw new IllegalStateException();
Expand All @@ -66,7 +72,7 @@ public static void setPointLightAccessor(final PointLightAccessor newAccessor) {

public interface PointLightAccessor {
NGNode doCreatePeer(Node node);
void doUpdatePeer(Node node);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,85 @@
package com.sun.javafx.sg.prism;

/**
* TODO: 3D - Need documentation
* The peer of the {@code PointLight} class. Holds the default values of {@code PointLight}'s
* properties and updates the visuals via {@link NGNode#visualsChanged} when one of the current
* values changes. The peer receives its changes by {@code PointLight.doUpdatePeer} calls.
*/
public class NGPointLight extends NGLightBase {

/** Constant attenuation factor default value */
private static final double DEFAULT_CA = 1;
/** Linear attenuation factor default value */
private static final double DEFAULT_LA = 0;
/** Quadratic attenuation factor default value */
private static final double DEFAULT_QA = 0;
/** Max range default value */
private static final double DEFAULT_MAX_RANGE = Double.POSITIVE_INFINITY;

public NGPointLight() {
}

public static double getDefaultCa() {
return DEFAULT_CA;
}

public static double getDefaultLa() {
return DEFAULT_LA;
}

public static double getDefaultQa() {
return DEFAULT_QA;
}

public static double getDefaultMaxRange() {
return DEFAULT_MAX_RANGE;
}


private double ca = DEFAULT_CA;

public double getCa() {
return ca;
}

public void setCa(double ca) {
this.ca = ca;
visualsChanged();
}


private double la = DEFAULT_LA;

public double getLa() {
return la;
}

public void setLa(double la) {
this.la = la;
visualsChanged();
}


private double qa = DEFAULT_QA;

public double getQa() {
return qa;
}

public void setQa(double qa) {
this.qa = qa;
visualsChanged();
}


private double maxRange = DEFAULT_MAX_RANGE;

public double getMaxRange() {
return maxRange;
}

public void setMaxRange(double maxRange) {
this.maxRange = maxRange < 0 ? 0 : maxRange;
visualsChanged();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,18 @@ private void renderMeshView(Graphics g) {
int pointLightIdx = 0;
if (g.getLights() == null || g.getLights()[0] == null) {
// If no lights are in scene apply default light. Default light
// is a single point white point light at camera eye position.
// is a single white point light at camera eye position.
meshView.setAmbientLight(0.0f, 0.0f, 0.0f);
Vec3d cameraPos = g.getCameraNoClone().getPositionInWorld(null);
meshView.setPointLight(pointLightIdx++,
(float)cameraPos.x,
(float)cameraPos.y,
(float)cameraPos.z,
1.0f, 1.0f, 1.0f, 1.0f);
(float)cameraPos.x,
(float)cameraPos.y,
(float)cameraPos.z,
1.0f, 1.0f, 1.0f, 1.0f,
(float) NGPointLight.getDefaultCa(),
(float) NGPointLight.getDefaultLa(),
(float) NGPointLight.getDefaultQa(),
(float) NGPointLight.getDefaultMaxRange());
} else {
float ambientRed = 0.0f;
float ambientBlue = 0.0f;
Expand All @@ -132,7 +136,7 @@ private void renderMeshView(Graphics g) {
float gL = lightBase.getColor().getGreen();
float bL = lightBase.getColor().getBlue();
/* TODO: 3D
* There is a limit on the number of lights that can affect
* There is a limit on the number of point lights that can affect
* a 3D shape. (Currently we simply select the first 3)
* Thus it is important to select the most relevant lights.
*
Expand All @@ -155,7 +159,11 @@ private void renderMeshView(Graphics g) {
(float)lightWT.getMxt(),
(float)lightWT.getMyt(),
(float)lightWT.getMzt(),
rL, gL, bL, 1.0f);
rL, gL, bL, 1.0f,
(float) light.getCa(),
(float) light.getLa(),
(float) light.getQa(),
(float) light.getMaxRange());
}
} else if (lightBase instanceof NGAmbientLight) {
// Accumulate ambient lights
Expand All @@ -172,8 +180,11 @@ private void renderMeshView(Graphics g) {
}
// TODO: 3D Required for D3D implementation of lights, which is limited to 3
while (pointLightIdx < 3) {
// Reset any previously set lights
meshView.setPointLight(pointLightIdx++, 0, 0, 0, 0, 0, 0, 0);
// Reset any previously set lights
meshView.setPointLight(pointLightIdx++,
0, 0, 0, // x y z
0, 0, 0, 0, // r g b w
1, 0, 0, 0); // ca la qa maxRange
}

meshView.render(g);
Expand All @@ -193,8 +204,8 @@ public void setMesh(NGTriangleMesh triangleMesh) {
@Override
protected void renderContent(Graphics g) {
if (!Platform.isSupported(ConditionalFeature.SCENE3D) ||
material == null ||
g instanceof com.sun.prism.PrinterGraphics)
material == null ||
g instanceof com.sun.prism.PrinterGraphics)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import javafx.application.ConditionalFeature;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.geometry.Dimension2D;
import javafx.scene.Scene;
import javafx.scene.effect.BlurType;
import javafx.scene.image.Image;
import javafx.scene.image.PixelFormat;
Expand All @@ -51,19 +50,16 @@
import javafx.scene.shape.StrokeType;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -82,7 +78,6 @@
import com.sun.javafx.runtime.VersionInfo;
import com.sun.javafx.runtime.async.AsyncOperation;
import com.sun.javafx.runtime.async.AsyncOperationListener;
import com.sun.javafx.scene.SceneHelper;
import com.sun.javafx.scene.text.TextLayoutFactory;
import com.sun.javafx.sg.prism.NGCamera;
import com.sun.javafx.sg.prism.NGLightBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public interface MeshView {

public void setAmbientLight(float r, float g, float b);

public void setPointLight(int index,
float x, float y, float z,
float r, float g, float b, float w);
public void setPointLight(int index, float x, float y, float z,
float r, float g, float b, float w,
float ca, float la, float qa, float maxRange);

public void render(Graphics g);
}
Loading