From c3b27b1b6c571f31d10f38a6e5c9dac3464e5d78 Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Wed, 20 Feb 2019 23:35:17 +0100 Subject: [PATCH 01/23] Add ES2-attenuation Adding attenuation factors to the JavaFX 3D-API --- .../com/sun/javafx/sg/prism/NGLightBase.java | 28 +++++++++++++++++++ .../com/sun/javafx/sg/prism/NGShape3D.java | 9 ++++-- .../src/main/java/com/sun/prism/MeshView.java | 9 ++++++ .../java/com/sun/prism/es2/ES2Context.java | 9 ++++-- .../main/java/com/sun/prism/es2/ES2Light.java | 10 +++++++ .../java/com/sun/prism/es2/ES2MeshView.java | 16 ++++++++--- .../com/sun/prism/es2/ES2PhongShader.java | 1 + .../java/com/sun/prism/es2/GLContext.java | 12 ++++++-- .../src/main/java/javafx/scene/LightBase.java | 26 ++++++++++++++++- .../main/java/javafx/scene/PointLight.java | 1 + .../src/main/native-prism-es2/GLContext.c | 16 ++++++++++- 11 files changed, 122 insertions(+), 15 deletions(-) diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGLightBase.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGLightBase.java index 92ad490e0b..f665895def 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGLightBase.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGLightBase.java @@ -39,6 +39,12 @@ public class NGLightBase extends NGNode { private Color color = Color.WHITE; private boolean lightOn = true; private Affine3D worldTransform; + + /* + * FalcoTheBold: additional member variables for attenuations + range + */ + private float range; + private float constantAttenuation, linearAttenuation, quadraticAttenuation; protected NGLightBase() { } @@ -130,6 +136,28 @@ final boolean affects(NGShape3D n3d) { return false; } + public void setAttenuations(float ca, float la, float qa){ + constantAttenuation = ca; + linearAttenuation = la; + quadraticAttenuation = qa; + } + + public float getRange() { + return range; + } + + public float getConstantAttenuation() { + return constantAttenuation; + } + + public float getLinearAttenuation() { + return linearAttenuation; + } + + public float getQuadraticAttenuation() { + return quadraticAttenuation; + } + @Override public void release() { // TODO: 3D - Need to release native resources diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java index bc42b78b1a..e1c19181fb 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java @@ -106,6 +106,7 @@ private void renderMeshView(Graphics g) { } // Setup lights + //Modified: FalcoTheBold - retrieving attenuation values and add them to the point-light int pointLightIdx = 0; if (g.getLights() == null || g.getLights()[0] == null) { // If no lights are in scene apply default light. Default light @@ -116,7 +117,8 @@ private void renderMeshView(Graphics g) { (float)cameraPos.x, (float)cameraPos.y, (float)cameraPos.z, - 1.0f, 1.0f, 1.0f, 1.0f); + 1.0f, 1.0f, 1.0f, 1.0f, + 1.0f,1.0f,1.0f,1.0f); } else { float ambientRed = 0.0f; float ambientBlue = 0.0f; @@ -131,6 +133,7 @@ private void renderMeshView(Graphics g) { float rL = lightBase.getColor().getRed(); float gL = lightBase.getColor().getGreen(); float bL = lightBase.getColor().getBlue(); + /* TODO: 3D * There is a limit on the number of lights that can affect * a 3D shape. (Currently we simply select the first 3) @@ -155,7 +158,7 @@ private void renderMeshView(Graphics g) { (float)lightWT.getMxt(), (float)lightWT.getMyt(), (float)lightWT.getMzt(), - rL, gL, bL, 1.0f); + rL, gL, bL, 1.0f, lightBase.getRange(), lightBase.getConstantAttenuation(), lightBase.getLinearAttenuation(), lightBase.getQuadraticAttenuation()); } } else if (lightBase instanceof NGAmbientLight) { // Accumulate ambient lights @@ -173,7 +176,7 @@ 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); + meshView.setPointLight(pointLightIdx++, 0, 0, 0, 0, 0, 0, 0, 1.0f, 1.0f, 1.0f, 1.0f); } meshView.render(g); diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java index 489ad70e6b..ebf6aac350 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java @@ -49,6 +49,15 @@ public interface MeshView { public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w); + + /* + * FalcoTheBold: + * Added overloaded operation that takes the range and the attenuation coefficients + */ + public void setPointLight(int index, + float x, float y, float z, + float r, float g, float b, float w, + float range, float constantAttenuation, float linearAttenuation, float quadraticAttenuation); public void render(Graphics g); } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Context.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Context.java index 41f1e5b819..3f13c08da7 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Context.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Context.java @@ -448,9 +448,12 @@ void setWireframe(long nativeHandle, boolean wireframe) { void setAmbientLight(long nativeHandle, float r, float g, float b) { glContext.setAmbientLight(nativeHandle, r, g, b); } - - void setPointLight(long nativeHandle, int index, float x, float y, float z, float r, float g, float b, float w) { - glContext.setPointLight(nativeHandle, index, x, y, z, r, g, b, w); + + /* + * FacloTheBold: - new operator, added parameters for attenuation coefficients + */ + void setPointLight(long nativeHandle, int index, float x, float y, float z, float r, float g, float b, float w, float ra, float ca, float la, float qa) { + glContext.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, ra, ca, la, qa); } @Override diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Light.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Light.java index b593985914..e329685951 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Light.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Light.java @@ -32,8 +32,14 @@ class ES2Light { float x, y, z = 0; float r, g, b, w = 1; + float ca, la, qa = 1; + float range = 1; ES2Light(float ix, float iy, float iz, float ir, float ig, float ib, float iw) { + this(ix, iy, iz, ir, ig, ib, iw, 1, 1, 1, 1); + } + + ES2Light(float ix, float iy, float iz, float ir, float ig, float ib, float iw, float irange, float ica, float ila, float iqa) { x = ix; y = iy; z = iz; @@ -41,5 +47,9 @@ class ES2Light { g = ig; b = ib; w = iw; + range = irange; + ca = ica; + la = ila; + qa = iqa; } } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java index eaf70e2b94..0e8ad64196 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java @@ -102,12 +102,20 @@ float getAmbientLightBlue() { @Override public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w) { - // NOTE: We only support up to 3 point lights at the present + setPointLight(index, x, y, z, r, g, b, w, 1, 1, 1, 1); + } + + /* + * FalcoTheBold - transferred expressions from the old operator to the new overloaded operator + */ + @Override + public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float range, float constantAttenuation, float linearAttenuation, float quadraticAttenuation){ + // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { - lights[index] = new ES2Light(x, y, z, r, g, b, w); - context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w); + lights[index] = new ES2Light(x, y, z, r, g, b, w, range, constantAttenuation, linearAttenuation, quadraticAttenuation); + context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, range, constantAttenuation, linearAttenuation, quadraticAttenuation); } - } + } ES2Light[] getPointLights() { return lights; diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2PhongShader.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2PhongShader.java index a9c5360f23..552a40b0f6 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2PhongShader.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2PhongShader.java @@ -208,6 +208,7 @@ static void setShaderParamaters(ES2Shader shader, ES2MeshView meshView, ES2Conte if (light != null && light.w > 0) { shader.setConstant("lights[" + i + "].pos", light.x, light.y, light.z, light.w); shader.setConstant("lights[" + i + "].color", light.r, light.g, light.b); + shader.setConstant("lights[" + i + "].atten", light.range, light.ca, light.la, light.qa); i++; } } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLContext.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLContext.java index 9a38b5fa47..67cba39ae4 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLContext.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLContext.java @@ -251,8 +251,11 @@ private static native void nSetWireframe(long nativeCtxInfo, long nativeMeshView boolean wireframe); private static native void nSetAmbientLight(long nativeCtxInfo, long nativeMeshViewInfo, float r, float g, float b); + /* + * FalcoTheBold: - added additional parameters for the attenuation coefficients + */ private static native void nSetPointLight(long nativeCtxInfo, long nativeMeshViewInfo, - int index, float x, float y, float z, float r, float g, float b, float w); + int index, float x, float y, float z, float r, float g, float b, float w, float ra, float ca, float la, float qa); private static native void nRenderMeshView(long nativeCtxInfo, long nativeMeshViewInfo); private static native void nBlit(long nativeCtxInfo, int srcFBO, int dstFBO, int srcX0, int srcY0, int srcX1, int srcY1, @@ -808,8 +811,11 @@ void setAmbientLight(long nativeMeshViewInfo, float r, float g, float b) { nSetAmbientLight(nativeCtxInfo, nativeMeshViewInfo, r, g, b); } - void setPointLight(long nativeMeshViewInfo, int index, float x, float y, float z, float r, float g, float b, float w) { - nSetPointLight(nativeCtxInfo, nativeMeshViewInfo, index, x, y, z, r, g, b, w); + /* + * FalcoTheBold: - added parameters for the attenuation coefficients + */ + void setPointLight(long nativeMeshViewInfo, int index, float x, float y, float z, float r, float g, float b, float w, float ra, float ca, float la, float qa) { + nSetPointLight(nativeCtxInfo, nativeMeshViewInfo, index, x, y, z, r, g, b, w, ra, ca, la, qa); } void renderMeshView(long nativeMeshViewInfo) { diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java index 812fce3a34..4d0040f0e8 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java @@ -41,6 +41,7 @@ import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.beans.property.BooleanProperty; +import javafx.beans.property.DoubleProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleObjectProperty; @@ -98,11 +99,33 @@ public boolean doComputeContains(Node node, double localX, double localY) { } private Affine3D localToSceneTx = new Affine3D(); - + { // To initialize the class helper at the begining each constructor of this class LightBaseHelper.initHelper(this); } + + //FalcoTheBold + private final DoubleProperty range = new SimpleDoubleProperty(1f); + private final DoubleProperty constantAttentuation = new SimpleDoubleProperty(1f); + private final DoubleProperty linearAttentuation = new SimpleDoubleProperty(1f); + private final DoubleProperty quadraticAttentuation = new SimpleDoubleProperty(1f); + + public final DoubleProperty rangeProperty(){ + return range; + } + + public final DoubleProperty constantAttentuationProperty(){ + return constantAttentuation; + } + + public final DoubleProperty linearAttentuationProperty(){ + return linearAttentuation; + } + + public final DoubleProperty quadraticAttentuationProperty(){ + return quadraticAttentuation; + } /** * Creates a new instance of {@code LightBase} class with a default Color.WHITE light source. @@ -284,6 +307,7 @@ private void doMarkDirty(DirtyBits dirtyBit) { */ private void doUpdatePeer() { NGLightBase peer = getPeer(); + peer.setAttenuations(constantAttentuation.floatValue(), linearAttentuation.floatValue(), quadraticAttentuation.floatValue()); if (isDirty(DirtyBits.NODE_LIGHT)) { peer.setColor((getColor() == null) ? Toolkit.getPaintAccessor().getPlatformPaint(Color.WHITE) diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java b/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java index 98c0bf88a7..2277bf4063 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java @@ -40,6 +40,7 @@ * @since JavaFX 8.0 */ public class PointLight extends LightBase { + static { PointLightHelper.setPointLightAccessor(new PointLightHelper.PointLightAccessor() { @Override diff --git a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c index ba6bc1bd29..ffc3f7d1b6 100644 --- a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c +++ b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c @@ -2083,6 +2083,9 @@ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetMap pmInfo->maps[mapType] = texID; } +/* + * FalcoTheBold: modified MeshViewInfo to hold datas of the attenuation values + */ /* * Class: com_sun_prism_es2_GLContext * Method: nCreateES2MeshView @@ -2122,6 +2125,10 @@ JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_GLContext_nCreateES2MeshView meshViewInfo->pointLightPosition[1] = 0; meshViewInfo->pointLightPosition[2] = 0; meshViewInfo->pointLightWeight = 0; + meshViewInfo->pointLightRange = 1; + meshViewInfo->pointLightAttenuation[0] = 1; + meshViewInfo->pointLightAttenuation[1] = 1; + meshViewInfo->pointLightAttenuation[2] = 1; return ptr_to_jlong(meshViewInfo); } @@ -2258,6 +2265,9 @@ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetAmbientLight meshViewInfo->ambientLightColor[2] = b; } +/* + * FalcoTheBold: modified native operator to add attenuation coefficients + */ /* * Class: com_sun_prism_es2_GLContext * Method: nSetPointLight @@ -2265,7 +2275,7 @@ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetAmbientLight */ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetPointLight (JNIEnv *env, jclass class, jlong nativeCtxInfo, jlong nativeMeshViewInfo, - jint index, jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w) + jint index, jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w, jfloat range, jfloat ca, ifloat la, jfloat qa) { ContextInfo *ctxInfo = (ContextInfo *) jlong_to_ptr(nativeCtxInfo); MeshViewInfo *meshViewInfo = (MeshViewInfo *) jlong_to_ptr(nativeMeshViewInfo); @@ -2281,6 +2291,10 @@ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetPointLight meshViewInfo->pointLightColor[1] = g; meshViewInfo->pointLightColor[2] = b; meshViewInfo->pointLightWeight = w; + meshViewInfo->pointLightRange = range; + meshViewInfo->pointLightAttenuation[0] = ca; + meshViewInfo->pointLightAttenuation[1] = la; + meshViewInfo->pointLightAttenuation[2] = qa; } /* From f60baa52c25fc96250c1bc6c819663e6761bafbc Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Thu, 21 Feb 2019 07:20:01 +0100 Subject: [PATCH 02/23] Small fixes #1 Added SetRange opeator --- .../java/com/sun/javafx/sg/prism/NGLightBase.java | 12 ++++++++---- .../src/main/java/javafx/scene/LightBase.java | 1 + .../resources/com/sun/prism/es2/glsl/main1Light.frag | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGLightBase.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGLightBase.java index f665895def..c4487b730c 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGLightBase.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGLightBase.java @@ -136,16 +136,20 @@ final boolean affects(NGShape3D n3d) { return false; } + public void setRange(float range){ + this.range = range; + } + + public float getRange() { + return range; + } + public void setAttenuations(float ca, float la, float qa){ constantAttenuation = ca; linearAttenuation = la; quadraticAttenuation = qa; } - public float getRange() { - return range; - } - public float getConstantAttenuation() { return constantAttenuation; } diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java index 4d0040f0e8..2a5a3073a4 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java @@ -307,6 +307,7 @@ private void doMarkDirty(DirtyBits dirtyBit) { */ private void doUpdatePeer() { NGLightBase peer = getPeer(); + peer.setRange(range.floatValue()); peer.setAttenuations(constantAttentuation.floatValue(), linearAttentuation.floatValue(), quadraticAttentuation.floatValue()); if (isDirty(DirtyBits.NODE_LIGHT)) { peer.setColor((getColor() == null) ? diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag index 51ee88ca46..f7c606bab6 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag @@ -82,6 +82,7 @@ void main() vec3 l = normalize(lightTangentSpacePositions[0].xyz); d = clamp(dot(n,l), 0.0, 1.0)*(lights[0].color).rgb; s = pow(clamp(dot(-refl, l), 0.0, 1.0), power)*lights[0].color.rgb; + float att = 1.0 / (1.0 + a*dist + b*dist*dist)); vec3 rez = (ambientColor+d) * diffuse.xyz + s*specular.rgb; rez += apply_selfIllum().xyz; From 28ce43387c27dc49f28ffbb9cf9f553344bea536 Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Thu, 21 Feb 2019 19:01:19 +0100 Subject: [PATCH 03/23] Small fixes #2 - Added missing shader-files - Changed default values of attenuation-factors --- .../com/sun/javafx/sg/prism/NGShape3D.java | 4 ++-- .../main/java/com/sun/prism/es2/ES2Light.java | 6 +++--- .../java/com/sun/prism/es2/ES2MeshView.java | 2 +- .../src/main/java/javafx/scene/LightBase.java | 9 ++++---- .../src/main/native-prism-es2/GLContext.c | 4 ++-- .../com/sun/prism/es2/glsl/main.vert | 10 +++++++++ .../com/sun/prism/es2/glsl/main1Light.frag | 10 +++++++-- .../com/sun/prism/es2/glsl/main2Lights.frag | 17 ++++++++++++++- .../com/sun/prism/es2/glsl/main3Lights.frag | 21 ++++++++++++++++++- 9 files changed, 66 insertions(+), 17 deletions(-) diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java index e1c19181fb..37aecb8969 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java @@ -118,7 +118,7 @@ private void renderMeshView(Graphics g) { (float)cameraPos.y, (float)cameraPos.z, 1.0f, 1.0f, 1.0f, 1.0f, - 1.0f,1.0f,1.0f,1.0f); + 1.0f,1.0f,0.0f,0.0f); } else { float ambientRed = 0.0f; float ambientBlue = 0.0f; @@ -176,7 +176,7 @@ 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, 1.0f, 1.0f, 1.0f, 1.0f); + meshView.setPointLight(pointLightIdx++, 0, 0, 0, 0, 0, 0, 0, 1.0f, 1.0f, 0.0f, 0.0f); } meshView.render(g); diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Light.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Light.java index e329685951..220009c9d3 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Light.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Light.java @@ -32,11 +32,11 @@ class ES2Light { float x, y, z = 0; float r, g, b, w = 1; - float ca, la, qa = 1; - float range = 1; + float range, ca = 1.0f; + float la, qa = 0.0f; ES2Light(float ix, float iy, float iz, float ir, float ig, float ib, float iw) { - this(ix, iy, iz, ir, ig, ib, iw, 1, 1, 1, 1); + this(ix, iy, iz, ir, ig, ib, iw, 1.0f, 1.0f, 0.0f, 0.0f); } ES2Light(float ix, float iy, float iz, float ir, float ig, float ib, float iw, float irange, float ica, float ila, float iqa) { diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java index 0e8ad64196..1108c17839 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java @@ -102,7 +102,7 @@ float getAmbientLightBlue() { @Override public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w) { - setPointLight(index, x, y, z, r, g, b, w, 1, 1, 1, 1); + setPointLight(index, x, y, z, r, g, b, w, 1.0f, 1.0f, 0.0f, 0.0f); } /* diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java index 2a5a3073a4..bd610381b0 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java @@ -106,10 +106,10 @@ public boolean doComputeContains(Node node, double localX, double localY) { } //FalcoTheBold - private final DoubleProperty range = new SimpleDoubleProperty(1f); - private final DoubleProperty constantAttentuation = new SimpleDoubleProperty(1f); - private final DoubleProperty linearAttentuation = new SimpleDoubleProperty(1f); - private final DoubleProperty quadraticAttentuation = new SimpleDoubleProperty(1f); + private final DoubleProperty range = new SimpleDoubleProperty(1.0f); + private final DoubleProperty constantAttentuation = new SimpleDoubleProperty(1.0f); + private final DoubleProperty linearAttentuation = new SimpleDoubleProperty(0.0f); + private final DoubleProperty quadraticAttentuation = new SimpleDoubleProperty(0.0f); public final DoubleProperty rangeProperty(){ return range; @@ -307,7 +307,6 @@ private void doMarkDirty(DirtyBits dirtyBit) { */ private void doUpdatePeer() { NGLightBase peer = getPeer(); - peer.setRange(range.floatValue()); peer.setAttenuations(constantAttentuation.floatValue(), linearAttentuation.floatValue(), quadraticAttentuation.floatValue()); if (isDirty(DirtyBits.NODE_LIGHT)) { peer.setColor((getColor() == null) ? diff --git a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c index ffc3f7d1b6..4a60b6d238 100644 --- a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c +++ b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c @@ -2127,8 +2127,8 @@ JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_GLContext_nCreateES2MeshView meshViewInfo->pointLightWeight = 0; meshViewInfo->pointLightRange = 1; meshViewInfo->pointLightAttenuation[0] = 1; - meshViewInfo->pointLightAttenuation[1] = 1; - meshViewInfo->pointLightAttenuation[2] = 1; + meshViewInfo->pointLightAttenuation[1] = 0; + meshViewInfo->pointLightAttenuation[2] = 0; return ptr_to_jlong(meshViewInfo); } diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main.vert b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main.vert index ee8dca946d..884dcd29e2 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main.vert +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main.vert @@ -35,6 +35,7 @@ attribute vec4 tangent; struct Light { vec4 pos; vec3 color; + vec4 atten; }; //3 lights used @@ -43,6 +44,10 @@ uniform Light lights[3]; varying vec4 lightTangentSpacePositions[3]; varying vec2 oTexCoords; varying vec3 eyePos; +//FalcoTheBold - making worldPos reachable for other shaders +//varying vec4 worldPos; +//FalcoTheBold - attenuation distance calculation +//varying float dist; vec3 getLocalVector(vec3 global, vec3 tangentFrame[3]) { return vec3( dot(global,tangentFrame[1]), dot(global,tangentFrame[2]), dot(global,tangentFrame[0]) ); @@ -52,6 +57,8 @@ void main() { vec3 tangentFrame[3]; + //FalcoTheBold - Old: make worldPosition available for other shaders for the moment + //worldPos = worldMatrix * vec4(pos, 1.0); vec4 worldPos = worldMatrix * vec4(pos, 1.0); // Note: The breaking of a vector and scale computation statement into @@ -100,4 +107,7 @@ void main() //Send texcoords to Pixel Shader and calculate vertex position. oTexCoords = texCoords; gl_Position = mvpMatrix * vec4(pos,1.0); + + //FalcoTheBold - ToDo: prepare calculation for light-position relative to vertex-position in vertex-shader + //dist = lights[x].pos.xyz - worldPos.xyz; } diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag index f7c606bab6..e0880eca00 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag @@ -55,6 +55,7 @@ vec4 apply_selfIllum(); struct Light { vec4 pos; vec3 color; + vec4 atten; }; uniform vec3 ambientColor; @@ -62,6 +63,8 @@ uniform Light lights[3]; varying vec3 eyePos; varying vec4 lightTangentSpacePositions[3]; +//FalcoTheBold - made worldPos public attribute +//varying vec4 worldPos; void main() { @@ -82,9 +85,12 @@ void main() vec3 l = normalize(lightTangentSpacePositions[0].xyz); d = clamp(dot(n,l), 0.0, 1.0)*(lights[0].color).rgb; s = pow(clamp(dot(-refl, l), 0.0, 1.0), power)*lights[0].color.rgb; - float att = 1.0 / (1.0 + a*dist + b*dist*dist)); + + //FalcoTheBold - added attenuation calculation for a single light + float dist = (lights[0].pos.xyz - gl_Position) / lights[0].atten.range; + float att = 1.0 / (lights[0].atten.ca + lights[0].atten.la * dist + lights[0].atten.qa * (dist * dist))); - vec3 rez = (ambientColor+d) * diffuse.xyz + s*specular.rgb; + vec3 rez = (ambientColor+d) * (att * (diffuse.xyz + s*specular.rgb)); rez += apply_selfIllum().xyz; gl_FragColor = vec4(clamp(rez, 0.0, 1.0) , diffuse.a); diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag index 44f7cbd52e..fe4816c40b 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag @@ -55,6 +55,7 @@ vec4 apply_selfIllum(); struct Light { vec4 pos; vec3 color; + vec4 atten; }; uniform vec3 ambientColor; @@ -62,6 +63,8 @@ uniform Light lights[3]; varying vec3 eyePos; varying vec4 lightTangentSpacePositions[3]; +//FalcoTheBold - made worldPos public attribute +//varying vec4 worldPos; void main() { @@ -78,16 +81,28 @@ void main() vec3 refl = reflect(normalize(eyePos), n); vec4 specular = apply_specular(); float power = specular.a; + + //FalcoTheBold + float att; + float dist; vec3 l = normalize(lightTangentSpacePositions[0].xyz); d = clamp(dot(n,l), 0.0, 1.0)*(lights[0].color).rgb; s = pow(clamp(dot(-refl, l), 0.0, 1.0), power)*lights[0].color.rgb; + //FalcoTheBold - added attenuation for light nr.1 + dist = (lights[0].pos.xyz - gl_Position) / lights[0].atten.range; + att = 1.0 / (lights[0].atten.ca + lights[0].atten.la * dist + lights[0].atten.qa * (dist * dist))); + l = normalize(lightTangentSpacePositions[1].xyz); d += clamp(dot(n,l), 0.0, 1.0)*(lights[1].color).rgb; s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[1].color.rgb; - vec3 rez = (ambientColor+d) * diffuse.xyz + s*specular.rgb; + //FalcoTheBold - added attenuation for light nr.2 + dist = (lights[1].pos.xyz - gl_Position) / lights[1].atten.range; + att += 1.0 / (lights[1].atten.ca + lights[1].atten.la * dist + lights[1].atten.qa * (dist * dist))); + + vec3 rez = (ambientColor+d) * (att * (diffuse.xyz + s*specular.rgb)); rez += apply_selfIllum().xyz; gl_FragColor = vec4(clamp(rez, 0.0, 1.0) , diffuse.a); diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag index 012ae079d6..fe8cf2a80d 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag @@ -55,6 +55,7 @@ vec4 apply_selfIllum(); struct Light { vec4 pos; vec3 color; + vec4 atten; }; uniform vec3 ambientColor; @@ -62,6 +63,8 @@ uniform Light lights[3]; varying vec3 eyePos; varying vec4 lightTangentSpacePositions[3]; +//FalcoTheBold - made worldPos public attribute +//varying vec4 worldPos; void main() { @@ -78,20 +81,36 @@ void main() vec3 refl = reflect(normalize(eyePos), n); vec4 specular = apply_specular(); float power = specular.a; + + //FalcoTheBold + float att; + float dist; vec3 l = normalize(lightTangentSpacePositions[0].xyz); d = clamp(dot(n,l), 0.0, 1.0)*(lights[0].color).rgb; s = pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[0].color.rgb; + //FalcoTheBold - added attenuation for light nr.1 + dist = (lights[0].pos.xyz - gl_Position) / lights[0].atten.range; + att = 1.0 / (lights[0].atten.ca + lights[0].atten.la * dist + lights[0].atten.qa * (dist * dist))); + l = normalize(lightTangentSpacePositions[1].xyz); d += clamp(dot(n,l), 0.0, 1.0)*(lights[1].color).rgb; s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[1].color.rgb; + //FalcoTheBold - added attenuation for light nr.2 + dist = (lights[1].pos.xyz - gl_Position) / lights[1].atten.range; + att += 1.0 / (lights[1].atten.ca + lights[1].atten.la * dist + lights[1].atten.qa * (dist * dist))); + l = normalize(lightTangentSpacePositions[2].xyz); d += clamp(dot(n,l), 0.0, 1.0)*(lights[2].color).rgb; s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[2].color.rgb; - vec3 rez = (ambientColor+d) * diffuse.xyz + s*specular.rgb; + //FalcoTheBold - added attenuation for light nr.3 + dist = (lights[2].pos.xyz - gl_Position) / lights[2].atten.range; + att += 1.0 / (lights[2].atten.ca + lights[2].atten.la * dist + lights[2].atten.qa * (dist * dist))); + + vec3 rez = (ambientColor+d) * (att * (diffuse.xyz + s*specular.rgb)); rez += apply_selfIllum().xyz; gl_FragColor = vec4(clamp(rez, 0.0, 1.0) , diffuse.a); From d121fec071c7f08937fb8fed7284ac772a0d0629 Mon Sep 17 00:00:00 2001 From: FalcoTheBold <44414891+FalcoTheBold@users.noreply.github.com> Date: Wed, 6 Mar 2019 08:10:21 +0100 Subject: [PATCH 04/23] Fixes for AppVeyor-build --- D3DMeshView.java | 136 ++++++++++++++++++ LightBase.java | 360 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 496 insertions(+) create mode 100644 D3DMeshView.java create mode 100644 LightBase.java diff --git a/D3DMeshView.java b/D3DMeshView.java new file mode 100644 index 0000000000..7a105d5f48 --- /dev/null +++ b/D3DMeshView.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.prism.d3d; + +import com.sun.prism.Graphics; +import com.sun.prism.Material; +import com.sun.prism.impl.BaseMeshView; +import com.sun.prism.impl.Disposer; + +/** + * TODO: 3D - Need documentation + */ +class D3DMeshView extends BaseMeshView { + + static int count = 0; + private final D3DContext context; + private final long nativeHandle; + + // TODO: 3D - Need a mechanism to "decRefCount" Mesh and Material + // if we need to do eager clean up + final private D3DMesh mesh; + private D3DPhongMaterial material; + + private D3DMeshView(D3DContext context, long nativeHandle, D3DMesh mesh, + Disposer.Record disposerRecord) { + super(disposerRecord); + this.context = context; + this.mesh = mesh; + this.nativeHandle = nativeHandle; + count++; + } + + static D3DMeshView create(D3DContext context, D3DMesh mesh) { + long nativeHandle = context.createD3DMeshView(mesh.getNativeHandle()); + return new D3DMeshView(context, nativeHandle, mesh, new D3DMeshViewDisposerRecord(context, nativeHandle)); + } + + @Override + public void setCullingMode(int cullingMode) { + context.setCullingMode(nativeHandle, cullingMode); + } + + @Override + public void setMaterial(Material material) { + context.setMaterial(nativeHandle, + ((D3DPhongMaterial) material).getNativeHandle()); + this.material = (D3DPhongMaterial) material; + } + + @Override + public void setWireframe(boolean wireframe) { + context.setWireframe(nativeHandle, wireframe); + } + + @Override + public void setAmbientLight(float r, float g, float b) { + context.setAmbientLight(nativeHandle, r, g, b); + } + + @Override + public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w) { + setPointLight(index, x, y, z, r, g, b, w, 1.0f, 1.0f, 0.0f, 0.0f); + } + + @java.lang.Override + public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float range, float constantAttenuation, float linearAttenuation, float quadraticAttenuation) { + // NOTE: We only support up to 3 point lights at the present + if (index >= 0 && index <= 2) { + context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w); + } + } + + @Override + public void render(Graphics g) { + material.lockTextureMaps(); + context.renderMeshView(nativeHandle, g); + material.unlockTextureMaps(); + } + + @Override + public void dispose() { + // TODO: 3D - Need a mechanism to "decRefCount" Mesh and Material + material = null; + disposerRecord.dispose(); + count--; + } + + public int getCount() { + return count; + } + + static class D3DMeshViewDisposerRecord implements Disposer.Record { + + private final D3DContext context; + private long nativeHandle; + + D3DMeshViewDisposerRecord(D3DContext context, long nativeHandle) { + this.context = context; + this.nativeHandle = nativeHandle; + } + + void traceDispose() { + } + + public void dispose() { + if (nativeHandle != 0L) { + traceDispose(); + context.releaseD3DMeshView(nativeHandle); + nativeHandle = 0L; + } + } + } +} diff --git a/LightBase.java b/LightBase.java new file mode 100644 index 0000000000..ee6a3a316c --- /dev/null +++ b/LightBase.java @@ -0,0 +1,360 @@ +/* + * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javafx.scene; + +import com.sun.javafx.collections.TrackableObservableList; +import com.sun.javafx.geom.BaseBounds; +import com.sun.javafx.geom.BoxBounds; +import com.sun.javafx.geom.transform.Affine3D; +import com.sun.javafx.geom.transform.BaseTransform; +import com.sun.javafx.scene.DirtyBits; +import com.sun.javafx.scene.LightBaseHelper; +import com.sun.javafx.scene.NodeHelper; +import com.sun.javafx.scene.transform.TransformHelper; +import com.sun.javafx.sg.prism.NGLightBase; +import com.sun.javafx.tk.Toolkit; +import javafx.application.ConditionalFeature; +import javafx.application.Platform; +import javafx.beans.InvalidationListener; +import javafx.beans.Observable; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.collections.ListChangeListener.Change; +import javafx.collections.ObservableList; +import javafx.scene.paint.Color; +import javafx.scene.shape.Shape3D; +import com.sun.javafx.logging.PlatformLogger; + +/** + * The {@code LightBase} class provides definitions of common properties for + * objects that represent a form of Light source. These properties + * include: + *
    + *
  • The color that defines color of the light source. + *
+ * + * Note that this is a conditional feature. See + * {@link javafx.application.ConditionalFeature#SCENE3D ConditionalFeature.SCENE3D} + * for more information. + * + *

+ * An application should not extend the LightBase class directly. Doing so may lead to + * an UnsupportedOperationException being thrown. + *

+ * + * @since JavaFX 8.0 + */ +public abstract class LightBase extends Node { + static { + // This is used by classes in different packages to get access to + // private and package private methods. + LightBaseHelper.setLightBaseAccessor(new LightBaseHelper.LightBaseAccessor() { + @Override + public void doMarkDirty(Node node, DirtyBits dirtyBit) { + ((LightBase) node).doMarkDirty(dirtyBit); + } + + @Override + public void doUpdatePeer(Node node) { + ((LightBase) node).doUpdatePeer(); + } + + @Override + public BaseBounds doComputeGeomBounds(Node node, + BaseBounds bounds, BaseTransform tx) { + return ((LightBase) node).doComputeGeomBounds(bounds, tx); + } + + @Override + public boolean doComputeContains(Node node, double localX, double localY) { + return ((LightBase) node).doComputeContains(localX, localY); + } + }); + } + + private Affine3D localToSceneTx = new Affine3D(); + + { + // To initialize the class helper at the begining each constructor of this class + LightBaseHelper.initHelper(this); + } + + //FalcoTheBold + private final DoubleProperty range = new SimpleDoubleProperty(1.0f); + private final DoubleProperty constantAttentuation = new SimpleDoubleProperty(1.0f); + private final DoubleProperty linearAttentuation = new SimpleDoubleProperty(0.0f); + private final DoubleProperty quadraticAttentuation = new SimpleDoubleProperty(0.0f); + + public final DoubleProperty rangeProperty(){ + return range; + } + + public final DoubleProperty constantAttentuationProperty(){ + return constantAttentuation; + } + + public final DoubleProperty linearAttentuationProperty(){ + return linearAttentuation; + } + + public final DoubleProperty quadraticAttentuationProperty(){ + return quadraticAttentuation; + } + + /** + * Creates a new instance of {@code LightBase} class with a default Color.WHITE light source. + */ + protected LightBase() { + this(Color.WHITE); + } + + /** + * Creates a new instance of {@code LightBase} class using the specified color. + * + * @param color the color of the light source + */ + protected LightBase(Color color) { + if (!Platform.isSupported(ConditionalFeature.SCENE3D)) { + String logname = LightBase.class.getName(); + PlatformLogger.getLogger(logname).warning("System can't support " + + "ConditionalFeature.SCENE3D"); + } + + setColor(color); + this.localToSceneTransformProperty().addListener(observable -> + NodeHelper.markDirty(this, DirtyBits.NODE_LIGHT_TRANSFORM)); + } + + /** + * Specifies the color of light source. + * + * @defaultValue null + */ + private ObjectProperty color; + + public final void setColor(Color value) { + colorProperty().set(value); + } + + public final Color getColor() { + return color == null ? null : color.get(); + } + + public final ObjectProperty colorProperty() { + if (color == null) { + color = new SimpleObjectProperty(LightBase.this, "color") { + @Override + protected void invalidated() { + NodeHelper.markDirty(LightBase.this, DirtyBits.NODE_LIGHT); + } + }; + } + return color; + } + + /** + * Defines the light on or off. + * + * @defaultValue true + */ + private BooleanProperty lightOn; + + public final void setLightOn(boolean value) { + lightOnProperty().set(value); + } + + public final boolean isLightOn() { + return lightOn == null ? true : lightOn.get(); + } + + public final BooleanProperty lightOnProperty() { + if (lightOn == null) { + lightOn = new SimpleBooleanProperty(LightBase.this, "lightOn", true) { + @Override + protected void invalidated() { + NodeHelper.markDirty(LightBase.this, DirtyBits.NODE_LIGHT); + } + }; + } + return lightOn; + } + + private ObservableList scope; + + /** + * Gets the list of nodes that specifies the + * hierarchical scope of this Light. If the scope list is empty, + * the Light node has universe scope: all nodes under it's scene + * are affected by it. If the scope list is non-empty, only those + * 3D Shape nodes in the scope list and under the Group nodes in the + * scope list are affected by this Light node. + * @return the list of nodes that specifies the hierarchical scope of this + * Light + */ + public ObservableList getScope() { + if (scope == null) { + scope = new TrackableObservableList() { + + @Override + protected void onChanged(Change c) { + NodeHelper.markDirty(LightBase.this, DirtyBits.NODE_LIGHT_SCOPE); + while (c.next()) { + for (Node node : c.getRemoved()) { + // Update the removed nodes + if (node instanceof Parent || node instanceof Shape3D) { + markChildrenDirty(node); + } + } + for (Node node : c.getAddedSubList()) { + if (node instanceof Parent || node instanceof Shape3D) { + markChildrenDirty(node); + } + } + } + } + }; + } + return scope; + } + + @Override + void scenesChanged(final Scene newScene, final SubScene newSubScene, + final Scene oldScene, final SubScene oldSubScene) { + // This light is owned by the Scene/SubScene, and thus must change + // accordingly. Note lights can owned by either a Scene or SubScene, + // but not both. + if (oldSubScene != null) { + oldSubScene.removeLight(this); + } else if (oldScene != null) { + oldScene.removeLight(this); + } + if (newSubScene != null) { + newSubScene.addLight(this); + } else if (newScene != null) { + newScene.addLight(this); + } + } + + private void markOwnerDirty() { + // if the light is part of the scene/subScene, we will need to notify + // the owner to mark the entire scene/subScene dirty. + SubScene subScene = getSubScene(); + if (subScene != null) { + subScene.markContentDirty(); + } else { + Scene scene = getScene(); + if (scene != null) { + scene.setNeedsRepaint(); + } + } + } + + private void markChildrenDirty(Node node) { + if (node instanceof Shape3D) { + // Dirty using a lightweight DirtyBits.NODE_DRAWMODE bit + NodeHelper.markDirty(((Shape3D) node), DirtyBits.NODE_DRAWMODE); + } else if (node instanceof Parent) { + for (Node child : ((Parent) node).getChildren()) { + markChildrenDirty(child); + } + } + } + + /* + * Note: This method MUST only be called via its accessor method. + */ + private void doMarkDirty(DirtyBits dirtyBit) { + if ((scope == null) || getScope().isEmpty()) { + // This light affect the entire scene/subScene + markOwnerDirty(); + } else if (dirtyBit != DirtyBits.NODE_LIGHT_SCOPE) { + // Skip NODE_LIGHT_SCOPE dirty since it is processed on scope change. + ObservableList tmpScope = getScope(); + for (int i = 0, max = tmpScope.size(); i < max; i++) { + markChildrenDirty(tmpScope.get(i)); + } + } + } + + /* + * Note: This method MUST only be called via its accessor method. + */ + private void doUpdatePeer() { + NGLightBase peer = getPeer(); + peer.setAttenuations(constantAttentuation.floatValue(), linearAttentuation.floatValue(), quadraticAttentuation.floatValue()); + if (isDirty(DirtyBits.NODE_LIGHT)) { + peer.setColor((getColor() == null) ? + Toolkit.getPaintAccessor().getPlatformPaint(Color.WHITE) + : Toolkit.getPaintAccessor().getPlatformPaint(getColor())); + peer.setLightOn(isLightOn()); + } + + if (isDirty(DirtyBits.NODE_LIGHT_SCOPE)) { + if (scope != null) { + ObservableList tmpScope = getScope(); + if (tmpScope.isEmpty()) { + peer.setScope(null); + } else { + Object ngList[] = new Object[tmpScope.size()]; + for (int i = 0; i < tmpScope.size(); i++) { + Node n = tmpScope.get(i); + ngList[i] = n.getPeer(); + } + peer.setScope(ngList); + } + } + } + + if (isDirty(DirtyBits.NODE_LIGHT_TRANSFORM)) { + localToSceneTx.setToIdentity(); + TransformHelper.apply(getLocalToSceneTransform(), localToSceneTx); + // TODO: 3D - For now, we are treating the scene as world. This may need to change + // for the fixed eye position case. + peer.setWorldTransform(localToSceneTx); + } + } + + /* + * Note: This method MUST only be called via its accessor method. + */ + private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx) { + // TODO: 3D - Check is this the right default + return new BoxBounds(); + } + + /* + * Note: This method MUST only be called via its accessor method. + */ + private boolean doComputeContains(double localX, double localY) { + // TODO: 3D - Check is this the right default + return false; + } + +} From 624a9471b6e5716900c85be60877dffd88fc7f0e Mon Sep 17 00:00:00 2001 From: FalcoTheBold <44414891+FalcoTheBold@users.noreply.github.com> Date: Wed, 6 Mar 2019 08:10:40 +0100 Subject: [PATCH 05/23] Delete LightBase.java --- LightBase.java | 360 ------------------------------------------------- 1 file changed, 360 deletions(-) delete mode 100644 LightBase.java diff --git a/LightBase.java b/LightBase.java deleted file mode 100644 index ee6a3a316c..0000000000 --- a/LightBase.java +++ /dev/null @@ -1,360 +0,0 @@ -/* - * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package javafx.scene; - -import com.sun.javafx.collections.TrackableObservableList; -import com.sun.javafx.geom.BaseBounds; -import com.sun.javafx.geom.BoxBounds; -import com.sun.javafx.geom.transform.Affine3D; -import com.sun.javafx.geom.transform.BaseTransform; -import com.sun.javafx.scene.DirtyBits; -import com.sun.javafx.scene.LightBaseHelper; -import com.sun.javafx.scene.NodeHelper; -import com.sun.javafx.scene.transform.TransformHelper; -import com.sun.javafx.sg.prism.NGLightBase; -import com.sun.javafx.tk.Toolkit; -import javafx.application.ConditionalFeature; -import javafx.application.Platform; -import javafx.beans.InvalidationListener; -import javafx.beans.Observable; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.DoubleProperty; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.property.SimpleDoubleProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.collections.ListChangeListener.Change; -import javafx.collections.ObservableList; -import javafx.scene.paint.Color; -import javafx.scene.shape.Shape3D; -import com.sun.javafx.logging.PlatformLogger; - -/** - * The {@code LightBase} class provides definitions of common properties for - * objects that represent a form of Light source. These properties - * include: - *
    - *
  • The color that defines color of the light source. - *
- * - * Note that this is a conditional feature. See - * {@link javafx.application.ConditionalFeature#SCENE3D ConditionalFeature.SCENE3D} - * for more information. - * - *

- * An application should not extend the LightBase class directly. Doing so may lead to - * an UnsupportedOperationException being thrown. - *

- * - * @since JavaFX 8.0 - */ -public abstract class LightBase extends Node { - static { - // This is used by classes in different packages to get access to - // private and package private methods. - LightBaseHelper.setLightBaseAccessor(new LightBaseHelper.LightBaseAccessor() { - @Override - public void doMarkDirty(Node node, DirtyBits dirtyBit) { - ((LightBase) node).doMarkDirty(dirtyBit); - } - - @Override - public void doUpdatePeer(Node node) { - ((LightBase) node).doUpdatePeer(); - } - - @Override - public BaseBounds doComputeGeomBounds(Node node, - BaseBounds bounds, BaseTransform tx) { - return ((LightBase) node).doComputeGeomBounds(bounds, tx); - } - - @Override - public boolean doComputeContains(Node node, double localX, double localY) { - return ((LightBase) node).doComputeContains(localX, localY); - } - }); - } - - private Affine3D localToSceneTx = new Affine3D(); - - { - // To initialize the class helper at the begining each constructor of this class - LightBaseHelper.initHelper(this); - } - - //FalcoTheBold - private final DoubleProperty range = new SimpleDoubleProperty(1.0f); - private final DoubleProperty constantAttentuation = new SimpleDoubleProperty(1.0f); - private final DoubleProperty linearAttentuation = new SimpleDoubleProperty(0.0f); - private final DoubleProperty quadraticAttentuation = new SimpleDoubleProperty(0.0f); - - public final DoubleProperty rangeProperty(){ - return range; - } - - public final DoubleProperty constantAttentuationProperty(){ - return constantAttentuation; - } - - public final DoubleProperty linearAttentuationProperty(){ - return linearAttentuation; - } - - public final DoubleProperty quadraticAttentuationProperty(){ - return quadraticAttentuation; - } - - /** - * Creates a new instance of {@code LightBase} class with a default Color.WHITE light source. - */ - protected LightBase() { - this(Color.WHITE); - } - - /** - * Creates a new instance of {@code LightBase} class using the specified color. - * - * @param color the color of the light source - */ - protected LightBase(Color color) { - if (!Platform.isSupported(ConditionalFeature.SCENE3D)) { - String logname = LightBase.class.getName(); - PlatformLogger.getLogger(logname).warning("System can't support " - + "ConditionalFeature.SCENE3D"); - } - - setColor(color); - this.localToSceneTransformProperty().addListener(observable -> - NodeHelper.markDirty(this, DirtyBits.NODE_LIGHT_TRANSFORM)); - } - - /** - * Specifies the color of light source. - * - * @defaultValue null - */ - private ObjectProperty color; - - public final void setColor(Color value) { - colorProperty().set(value); - } - - public final Color getColor() { - return color == null ? null : color.get(); - } - - public final ObjectProperty colorProperty() { - if (color == null) { - color = new SimpleObjectProperty(LightBase.this, "color") { - @Override - protected void invalidated() { - NodeHelper.markDirty(LightBase.this, DirtyBits.NODE_LIGHT); - } - }; - } - return color; - } - - /** - * Defines the light on or off. - * - * @defaultValue true - */ - private BooleanProperty lightOn; - - public final void setLightOn(boolean value) { - lightOnProperty().set(value); - } - - public final boolean isLightOn() { - return lightOn == null ? true : lightOn.get(); - } - - public final BooleanProperty lightOnProperty() { - if (lightOn == null) { - lightOn = new SimpleBooleanProperty(LightBase.this, "lightOn", true) { - @Override - protected void invalidated() { - NodeHelper.markDirty(LightBase.this, DirtyBits.NODE_LIGHT); - } - }; - } - return lightOn; - } - - private ObservableList scope; - - /** - * Gets the list of nodes that specifies the - * hierarchical scope of this Light. If the scope list is empty, - * the Light node has universe scope: all nodes under it's scene - * are affected by it. If the scope list is non-empty, only those - * 3D Shape nodes in the scope list and under the Group nodes in the - * scope list are affected by this Light node. - * @return the list of nodes that specifies the hierarchical scope of this - * Light - */ - public ObservableList getScope() { - if (scope == null) { - scope = new TrackableObservableList() { - - @Override - protected void onChanged(Change c) { - NodeHelper.markDirty(LightBase.this, DirtyBits.NODE_LIGHT_SCOPE); - while (c.next()) { - for (Node node : c.getRemoved()) { - // Update the removed nodes - if (node instanceof Parent || node instanceof Shape3D) { - markChildrenDirty(node); - } - } - for (Node node : c.getAddedSubList()) { - if (node instanceof Parent || node instanceof Shape3D) { - markChildrenDirty(node); - } - } - } - } - }; - } - return scope; - } - - @Override - void scenesChanged(final Scene newScene, final SubScene newSubScene, - final Scene oldScene, final SubScene oldSubScene) { - // This light is owned by the Scene/SubScene, and thus must change - // accordingly. Note lights can owned by either a Scene or SubScene, - // but not both. - if (oldSubScene != null) { - oldSubScene.removeLight(this); - } else if (oldScene != null) { - oldScene.removeLight(this); - } - if (newSubScene != null) { - newSubScene.addLight(this); - } else if (newScene != null) { - newScene.addLight(this); - } - } - - private void markOwnerDirty() { - // if the light is part of the scene/subScene, we will need to notify - // the owner to mark the entire scene/subScene dirty. - SubScene subScene = getSubScene(); - if (subScene != null) { - subScene.markContentDirty(); - } else { - Scene scene = getScene(); - if (scene != null) { - scene.setNeedsRepaint(); - } - } - } - - private void markChildrenDirty(Node node) { - if (node instanceof Shape3D) { - // Dirty using a lightweight DirtyBits.NODE_DRAWMODE bit - NodeHelper.markDirty(((Shape3D) node), DirtyBits.NODE_DRAWMODE); - } else if (node instanceof Parent) { - for (Node child : ((Parent) node).getChildren()) { - markChildrenDirty(child); - } - } - } - - /* - * Note: This method MUST only be called via its accessor method. - */ - private void doMarkDirty(DirtyBits dirtyBit) { - if ((scope == null) || getScope().isEmpty()) { - // This light affect the entire scene/subScene - markOwnerDirty(); - } else if (dirtyBit != DirtyBits.NODE_LIGHT_SCOPE) { - // Skip NODE_LIGHT_SCOPE dirty since it is processed on scope change. - ObservableList tmpScope = getScope(); - for (int i = 0, max = tmpScope.size(); i < max; i++) { - markChildrenDirty(tmpScope.get(i)); - } - } - } - - /* - * Note: This method MUST only be called via its accessor method. - */ - private void doUpdatePeer() { - NGLightBase peer = getPeer(); - peer.setAttenuations(constantAttentuation.floatValue(), linearAttentuation.floatValue(), quadraticAttentuation.floatValue()); - if (isDirty(DirtyBits.NODE_LIGHT)) { - peer.setColor((getColor() == null) ? - Toolkit.getPaintAccessor().getPlatformPaint(Color.WHITE) - : Toolkit.getPaintAccessor().getPlatformPaint(getColor())); - peer.setLightOn(isLightOn()); - } - - if (isDirty(DirtyBits.NODE_LIGHT_SCOPE)) { - if (scope != null) { - ObservableList tmpScope = getScope(); - if (tmpScope.isEmpty()) { - peer.setScope(null); - } else { - Object ngList[] = new Object[tmpScope.size()]; - for (int i = 0; i < tmpScope.size(); i++) { - Node n = tmpScope.get(i); - ngList[i] = n.getPeer(); - } - peer.setScope(ngList); - } - } - } - - if (isDirty(DirtyBits.NODE_LIGHT_TRANSFORM)) { - localToSceneTx.setToIdentity(); - TransformHelper.apply(getLocalToSceneTransform(), localToSceneTx); - // TODO: 3D - For now, we are treating the scene as world. This may need to change - // for the fixed eye position case. - peer.setWorldTransform(localToSceneTx); - } - } - - /* - * Note: This method MUST only be called via its accessor method. - */ - private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx) { - // TODO: 3D - Check is this the right default - return new BoxBounds(); - } - - /* - * Note: This method MUST only be called via its accessor method. - */ - private boolean doComputeContains(double localX, double localY) { - // TODO: 3D - Check is this the right default - return false; - } - -} From f7a6e709dc09ff5dcc30bf9efce4e5152e466e9c Mon Sep 17 00:00:00 2001 From: FalcoTheBold <44414891+FalcoTheBold@users.noreply.github.com> Date: Wed, 6 Mar 2019 08:10:49 +0100 Subject: [PATCH 06/23] Delete D3DMeshView.java --- D3DMeshView.java | 136 ----------------------------------------------- 1 file changed, 136 deletions(-) delete mode 100644 D3DMeshView.java diff --git a/D3DMeshView.java b/D3DMeshView.java deleted file mode 100644 index 7a105d5f48..0000000000 --- a/D3DMeshView.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.prism.d3d; - -import com.sun.prism.Graphics; -import com.sun.prism.Material; -import com.sun.prism.impl.BaseMeshView; -import com.sun.prism.impl.Disposer; - -/** - * TODO: 3D - Need documentation - */ -class D3DMeshView extends BaseMeshView { - - static int count = 0; - private final D3DContext context; - private final long nativeHandle; - - // TODO: 3D - Need a mechanism to "decRefCount" Mesh and Material - // if we need to do eager clean up - final private D3DMesh mesh; - private D3DPhongMaterial material; - - private D3DMeshView(D3DContext context, long nativeHandle, D3DMesh mesh, - Disposer.Record disposerRecord) { - super(disposerRecord); - this.context = context; - this.mesh = mesh; - this.nativeHandle = nativeHandle; - count++; - } - - static D3DMeshView create(D3DContext context, D3DMesh mesh) { - long nativeHandle = context.createD3DMeshView(mesh.getNativeHandle()); - return new D3DMeshView(context, nativeHandle, mesh, new D3DMeshViewDisposerRecord(context, nativeHandle)); - } - - @Override - public void setCullingMode(int cullingMode) { - context.setCullingMode(nativeHandle, cullingMode); - } - - @Override - public void setMaterial(Material material) { - context.setMaterial(nativeHandle, - ((D3DPhongMaterial) material).getNativeHandle()); - this.material = (D3DPhongMaterial) material; - } - - @Override - public void setWireframe(boolean wireframe) { - context.setWireframe(nativeHandle, wireframe); - } - - @Override - public void setAmbientLight(float r, float g, float b) { - context.setAmbientLight(nativeHandle, r, g, b); - } - - @Override - public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w) { - setPointLight(index, x, y, z, r, g, b, w, 1.0f, 1.0f, 0.0f, 0.0f); - } - - @java.lang.Override - public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float range, float constantAttenuation, float linearAttenuation, float quadraticAttenuation) { - // NOTE: We only support up to 3 point lights at the present - if (index >= 0 && index <= 2) { - context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w); - } - } - - @Override - public void render(Graphics g) { - material.lockTextureMaps(); - context.renderMeshView(nativeHandle, g); - material.unlockTextureMaps(); - } - - @Override - public void dispose() { - // TODO: 3D - Need a mechanism to "decRefCount" Mesh and Material - material = null; - disposerRecord.dispose(); - count--; - } - - public int getCount() { - return count; - } - - static class D3DMeshViewDisposerRecord implements Disposer.Record { - - private final D3DContext context; - private long nativeHandle; - - D3DMeshViewDisposerRecord(D3DContext context, long nativeHandle) { - this.context = context; - this.nativeHandle = nativeHandle; - } - - void traceDispose() { - } - - public void dispose() { - if (nativeHandle != 0L) { - traceDispose(); - context.releaseD3DMeshView(nativeHandle); - nativeHandle = 0L; - } - } - } -} From 370a588b12f9c39df49780e2d06c874e4038e610 Mon Sep 17 00:00:00 2001 From: FalcoTheBold <44414891+FalcoTheBold@users.noreply.github.com> Date: Wed, 6 Mar 2019 08:11:47 +0100 Subject: [PATCH 07/23] Fixes for AppVeyor-build --- .../javafx.graphics/src/main/java/javafx/scene/LightBase.java | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java index bd610381b0..ee6a3a316c 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java @@ -44,6 +44,7 @@ import javafx.beans.property.DoubleProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleObjectProperty; import javafx.collections.ListChangeListener.Change; import javafx.collections.ObservableList; From 8e8eb2f610064d11978454da33a379f84317051c Mon Sep 17 00:00:00 2001 From: FalcoTheBold <44414891+FalcoTheBold@users.noreply.github.com> Date: Wed, 6 Mar 2019 08:13:17 +0100 Subject: [PATCH 08/23] Fixes for AppVeyor-build #2 --- .../src/main/java/com/sun/prism/d3d/D3DMeshView.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java index 08b0056747..7a105d5f48 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java @@ -82,6 +82,11 @@ public void setAmbientLight(float r, float g, float b) { @Override public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w) { + setPointLight(index, x, y, z, r, g, b, w, 1.0f, 1.0f, 0.0f, 0.0f); + } + + @java.lang.Override + public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float range, float constantAttenuation, float linearAttenuation, float quadraticAttenuation) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w); From 93a0fa50f8090557b1e449ce1f006700517094bf Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Wed, 6 Mar 2019 09:30:55 +0100 Subject: [PATCH 09/23] [Test] Sources for Java-side --- .idea/misc.xml | 8 +- .../sun/javafx/scene/PointLightHelper.java | 7 + .../com/sun/javafx/sg/prism/NGLightBase.java | 32 ----- .../com/sun/javafx/sg/prism/NGPointLight.java | 68 ++++++++++ .../com/sun/javafx/sg/prism/NGShape3D.java | 36 ++++-- .../main/java/com/sun/javafx/tk/Toolkit.java | 5 - .../src/main/java/com/sun/prism/MeshView.java | 15 +-- .../java/com/sun/prism/d3d/D3DMeshView.java | 10 +- .../java/com/sun/prism/es2/ES2MeshView.java | 13 +- .../src/main/java/javafx/scene/LightBase.java | 48 +++---- .../main/java/javafx/scene/PointLight.java | 120 +++++++++++++++++- 11 files changed, 246 insertions(+), 116 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index ac8fa666b5..bce43c2594 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,11 +1,7 @@ - - - - + - - + \ No newline at end of file diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/scene/PointLightHelper.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/scene/PointLightHelper.java index fac2ef6d3d..d22a2ffe95 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/scene/PointLightHelper.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/scene/PointLightHelper.java @@ -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(); @@ -66,6 +72,7 @@ public static void setPointLightAccessor(final PointLightAccessor newAccessor) { public interface PointLightAccessor { NGNode doCreatePeer(Node node); + void doUpdatePeer(Node node); } } diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGLightBase.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGLightBase.java index c4487b730c..92ad490e0b 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGLightBase.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGLightBase.java @@ -39,12 +39,6 @@ public class NGLightBase extends NGNode { private Color color = Color.WHITE; private boolean lightOn = true; private Affine3D worldTransform; - - /* - * FalcoTheBold: additional member variables for attenuations + range - */ - private float range; - private float constantAttenuation, linearAttenuation, quadraticAttenuation; protected NGLightBase() { } @@ -136,32 +130,6 @@ final boolean affects(NGShape3D n3d) { return false; } - public void setRange(float range){ - this.range = range; - } - - public float getRange() { - return range; - } - - public void setAttenuations(float ca, float la, float qa){ - constantAttenuation = ca; - linearAttenuation = la; - quadraticAttenuation = qa; - } - - public float getConstantAttenuation() { - return constantAttenuation; - } - - public float getLinearAttenuation() { - return linearAttenuation; - } - - public float getQuadraticAttenuation() { - return quadraticAttenuation; - } - @Override public void release() { // TODO: 3D - Need to release native resources diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java index 3495aeaece..b3839972d3 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java @@ -30,6 +30,74 @@ */ public class NGPointLight extends NGLightBase { + private static final double DEFAULT_C = 1; + private static final double DEFAULT_LC = 0; + private static final double DEFAULT_QC = 0; + private static final double DEFAULT_RANGE = Double.POSITIVE_INFINITY; + + public static double getDefaultC() { + return DEFAULT_C; + } + + public static double getDefaultLc() { + return DEFAULT_LC; + } + + public static double getDefaultQc() { + return DEFAULT_QC; + } + + public static double getDefaultRange() { + return DEFAULT_RANGE; + } + + private double c = DEFAULT_C; + + public double getC() { + return c; + } + + public void setC(double c) { + this.c = c; + visualsChanged(); + } + + + private double lc = DEFAULT_LC; + + public double getLc() { + return lc; + } + + public void setLc(double lc) { + this.lc = lc; + visualsChanged(); + } + + + private double qc = DEFAULT_QC; + + public double getQc() { + return qc; + } + + public void setQc(double qc) { + this.qc = qc; + visualsChanged(); + } + + + private double range = DEFAULT_RANGE; + + public double getRange() { + return range; + } + + public void setRange(double range) { + this.range = range < 0 ? 0 : range; + visualsChanged(); + } + public NGPointLight() { } diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java index 37aecb8969..ec066e607a 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java @@ -106,19 +106,21 @@ private void renderMeshView(Graphics g) { } // Setup lights - //Modified: FalcoTheBold - retrieving attenuation values and add them to the point-light 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, - 1.0f,1.0f,0.0f,0.0f); + (float)cameraPos.x, + (float)cameraPos.y, + (float)cameraPos.z, + 1.0f, 1.0f, 1.0f, 1.0f, + (float) NGPointLight.getDefaultC(), + (float) NGPointLight.getDefaultLc(), + (float) NGPointLight.getDefaultQc(), + (float) NGPointLight.getDefaultRange()); } else { float ambientRed = 0.0f; float ambientBlue = 0.0f; @@ -133,9 +135,8 @@ private void renderMeshView(Graphics g) { float rL = lightBase.getColor().getRed(); 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. * @@ -158,7 +159,11 @@ private void renderMeshView(Graphics g) { (float)lightWT.getMxt(), (float)lightWT.getMyt(), (float)lightWT.getMzt(), - rL, gL, bL, 1.0f, lightBase.getRange(), lightBase.getConstantAttenuation(), lightBase.getLinearAttenuation(), lightBase.getQuadraticAttenuation()); + rL, gL, bL, 1.0f, + (float) light.getC(), + (float) light.getLc(), + (float) light.getQc(), + (float) light.getRange()); } } else if (lightBase instanceof NGAmbientLight) { // Accumulate ambient lights @@ -175,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, 1.0f, 1.0f, 0.0f, 0.0f); + // Reset any previously set lights + meshView.setPointLight(pointLightIdx++, + 0, 0, 0, // x y z + 0, 0, 0, 0, // r g b + 1, 0, 0, 0); // c lc qc range } meshView.render(g); @@ -196,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; } diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/Toolkit.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/Toolkit.java index 86e101e959..eccd613846 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/Toolkit.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/tk/Toolkit.java @@ -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; @@ -51,11 +50,9 @@ 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; @@ -63,7 +60,6 @@ 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; @@ -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; diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java index ebf6aac350..66e3942999 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java @@ -47,17 +47,8 @@ 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); - - /* - * FalcoTheBold: - * Added overloaded operation that takes the range and the attenuation coefficients - */ - public void setPointLight(int index, - float x, float y, float z, - float r, float g, float b, float w, - float range, float constantAttenuation, float linearAttenuation, float quadraticAttenuation); - + float x, float y, float z, + float r, float g, float b, float w, + float c, float cl, float cq, float range); public void render(Graphics g); } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java index 7a105d5f48..6c098669b6 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java @@ -45,7 +45,7 @@ class D3DMeshView extends BaseMeshView { private D3DPhongMaterial material; private D3DMeshView(D3DContext context, long nativeHandle, D3DMesh mesh, - Disposer.Record disposerRecord) { + Disposer.Record disposerRecord) { super(disposerRecord); this.context = context; this.mesh = mesh; @@ -81,12 +81,7 @@ public void setAmbientLight(float r, float g, float b) { } @Override - public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w) { - setPointLight(index, x, y, z, r, g, b, w, 1.0f, 1.0f, 0.0f, 0.0f); - } - - @java.lang.Override - public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float range, float constantAttenuation, float linearAttenuation, float quadraticAttenuation) { + public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float c, float lc, float qc, float range) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w); @@ -133,4 +128,5 @@ public void dispose() { } } } + } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java index 1108c17839..a9326e14cb 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java @@ -99,21 +99,16 @@ float getAmbientLightGreen() { float getAmbientLightBlue() { return ambientLightBlue; } - - @Override - public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w) { - setPointLight(index, x, y, z, r, g, b, w, 1.0f, 1.0f, 0.0f, 0.0f); - } /* * FalcoTheBold - transferred expressions from the old operator to the new overloaded operator */ @Override - public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float range, float constantAttenuation, float linearAttenuation, float quadraticAttenuation){ - // NOTE: We only support up to 3 point lights at the present + public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float c, float lc, float qc, float range) { + // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { - lights[index] = new ES2Light(x, y, z, r, g, b, w, range, constantAttenuation, linearAttenuation, quadraticAttenuation); - context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, range, constantAttenuation, linearAttenuation, quadraticAttenuation); + lights[index] = new ES2Light(x, y, z, r, g, b, w, range, c, lc, qc); + context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, range, c, lc, qc); } } diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java index ee6a3a316c..0bb02ba097 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java @@ -73,8 +73,8 @@ */ public abstract class LightBase extends Node { static { - // This is used by classes in different packages to get access to - // private and package private methods. + // This is used by classes in different packages to get access to + // private and package private methods. LightBaseHelper.setLightBaseAccessor(new LightBaseHelper.LightBaseAccessor() { @Override public void doMarkDirty(Node node, DirtyBits dirtyBit) { @@ -88,7 +88,7 @@ public void doUpdatePeer(Node node) { @Override public BaseBounds doComputeGeomBounds(Node node, - BaseBounds bounds, BaseTransform tx) { + BaseBounds bounds, BaseTransform tx) { return ((LightBase) node).doComputeGeomBounds(bounds, tx); } @@ -100,33 +100,11 @@ public boolean doComputeContains(Node node, double localX, double localY) { } private Affine3D localToSceneTx = new Affine3D(); - + { // To initialize the class helper at the begining each constructor of this class LightBaseHelper.initHelper(this); } - - //FalcoTheBold - private final DoubleProperty range = new SimpleDoubleProperty(1.0f); - private final DoubleProperty constantAttentuation = new SimpleDoubleProperty(1.0f); - private final DoubleProperty linearAttentuation = new SimpleDoubleProperty(0.0f); - private final DoubleProperty quadraticAttentuation = new SimpleDoubleProperty(0.0f); - - public final DoubleProperty rangeProperty(){ - return range; - } - - public final DoubleProperty constantAttentuationProperty(){ - return constantAttentuation; - } - - public final DoubleProperty linearAttentuationProperty(){ - return linearAttentuation; - } - - public final DoubleProperty quadraticAttentuationProperty(){ - return quadraticAttentuation; - } /** * Creates a new instance of {@code LightBase} class with a default Color.WHITE light source. @@ -144,7 +122,7 @@ protected LightBase(Color color) { if (!Platform.isSupported(ConditionalFeature.SCENE3D)) { String logname = LightBase.class.getName(); PlatformLogger.getLogger(logname).warning("System can't support " - + "ConditionalFeature.SCENE3D"); + + "ConditionalFeature.SCENE3D"); } setColor(color); @@ -262,6 +240,20 @@ void scenesChanged(final Scene newScene, final SubScene newSubScene, } } + /** + * For use by implementing subclasses. Treat as protected. + * + * Creates and returns a SimpleDoubleProperty with an invalidation scheme. + */ + DoubleProperty getLightDoubleProperty(String name, double initialValue) { + return new SimpleDoubleProperty(this, name, initialValue) { + @Override + protected void invalidated() { + NodeHelper.markDirty(LightBase.this, DirtyBits.NODE_LIGHT); + } + }; + } + private void markOwnerDirty() { // if the light is part of the scene/subScene, we will need to notify // the owner to mark the entire scene/subScene dirty. @@ -308,7 +300,6 @@ private void doMarkDirty(DirtyBits dirtyBit) { */ private void doUpdatePeer() { NGLightBase peer = getPeer(); - peer.setAttenuations(constantAttentuation.floatValue(), linearAttentuation.floatValue(), quadraticAttentuation.floatValue()); if (isDirty(DirtyBits.NODE_LIGHT)) { peer.setColor((getColor() == null) ? Toolkit.getPaintAccessor().getPlatformPaint(Color.WHITE) @@ -356,5 +347,4 @@ private boolean doComputeContains(double localX, double localY) { // TODO: 3D - Check is this the right default return false; } - } diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java b/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java index 2277bf4063..599cc82e1d 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java @@ -26,10 +26,10 @@ package javafx.scene; import com.sun.javafx.scene.DirtyBits; -import com.sun.javafx.scene.NodeHelper; import com.sun.javafx.scene.PointLightHelper; import com.sun.javafx.sg.prism.NGNode; import com.sun.javafx.sg.prism.NGPointLight; +import javafx.beans.property.DoubleProperty; import javafx.scene.paint.Color; /** @@ -40,13 +40,17 @@ * @since JavaFX 8.0 */ public class PointLight extends LightBase { - static { PointLightHelper.setPointLightAccessor(new PointLightHelper.PointLightAccessor() { @Override public NGNode doCreatePeer(Node node) { return ((PointLight) node).doCreatePeer(); } + + @Override + public void doUpdatePeer(Node node) { + ((PointLight) node).doUpdatePeer(); + } }); } @@ -71,10 +75,122 @@ public PointLight(Color color) { super(color); } + /** + * The range of this {@code PointLight}. A pixel is affected by this light i.f.f. its + * distance to the light source is less than or equal to the light's range. + * Any negative value will treated as {@code 0}. + *

+ * Lower {@code range} values can give better performance as pixels outside the range of the light + * will not require complex calculation. For a realistic effect, {@code range} should be set to + * a distance at which the attenuation is close to 0 as this will give a soft cutoff. + *

+ * Nodes that are inside the light's range can still be excluded from the light's effect + * by removing them from its {@link #getScope() scope}. If a node is known to always be + * outside of the light's range, it is more performant to exclude it from its scope. + * + * @defaultValue {@code Double.POSITIVE_INFINITY} + * @since 13 + */ + private DoubleProperty range; + + public final void setRange(double value) { + rangeProperty().set(value); + } + + private static final double DEFAULT_RANGE = NGPointLight.getDefaultRange(); + + public final double getRange() { + return range == null ? DEFAULT_RANGE : range.get(); + } + + public final DoubleProperty rangeProperty() { + if (range == null) { + range = getLightDoubleProperty("range", DEFAULT_RANGE); + } + return range; + } + + /** + * The constant attenuation coefficient. This is the term {@code c} in the attenuation formula: + *

+ * attn = 1 / (c + lc * dist + qc * dist^2) + * + * @defaultValue {@code 1} + * @since 13 + */ + private DoubleProperty constantAttenuation; + + public final void setConstantAttenuation(double value) { + constantAttenuationProperty().set(value); + } + + private static final double DEFAULT_CONSTANT_ATTENUATION = NGPointLight.getDefaultC(); + + public final double getConstantAttenuation() { + return constantAttenuation == null ? DEFAULT_CONSTANT_ATTENUATION : constantAttenuation.get(); + } + + public final DoubleProperty constantAttenuationProperty() { + if (constantAttenuation == null) { + constantAttenuation = getLightDoubleProperty("constantAttenuation", DEFAULT_CONSTANT_ATTENUATION); + } + return constantAttenuation; + } + + + private DoubleProperty linearAttenuation; + + public final void setLinearAttenuation(double value) { + linearAttenuationProperty().set(value); + } + + private static final double DEFAULT_LINEAR_CONSTANT = NGPointLight.getDefaultLc(); + + public final double getLinearAttenuation() { + return linearAttenuation == null ? DEFAULT_LINEAR_CONSTANT : linearAttenuation.get(); + } + + public final DoubleProperty linearAttenuationProperty() { + if (linearAttenuation == null) { + linearAttenuation = getLightDoubleProperty("linearAttenuation", DEFAULT_LINEAR_CONSTANT); + } + return linearAttenuation; + } + + + private DoubleProperty quadraticAttenuation; + + public final void setQuadraticAttenuation(double value) { + quadraticAttenuationProperty().set(value); + } + + private static final double DEFAULT_QUADRATIC_CONSTANT = NGPointLight.getDefaultQc(); + + public final double getQuadraticAttenuation() { + return quadraticAttenuation == null ? DEFAULT_QUADRATIC_CONSTANT : quadraticAttenuation.get(); + } + + public final DoubleProperty quadraticAttenuationProperty() { + if (quadraticAttenuation == null) { + quadraticAttenuation = getLightDoubleProperty("quadraticAttenuation", DEFAULT_QUADRATIC_CONSTANT); + } + return quadraticAttenuation; + } + /* * Note: This method MUST only be called via its accessor method. */ private NGNode doCreatePeer() { return new NGPointLight(); } + + private void doUpdatePeer() { + if (isDirty(DirtyBits.NODE_LIGHT)) { + NGPointLight peer = getPeer(); + peer.setC(getConstantAttenuation()); + peer.setLc(getLinearAttenuation()); + peer.setQc(getQuadraticAttenuation()); + peer.setRange(getRange()); + } + } } From 18e58fec4ae06adcd9addad7f8f52e4122743399 Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Wed, 6 Mar 2019 10:19:57 +0100 Subject: [PATCH 10/23] Small fixes #3 - added missing members for native MeshView-struct - changed 'la' to correct data-type in native setPointLight-operation --- modules/javafx.graphics/src/main/native-prism-es2/GLContext.c | 2 +- .../javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c index 4a60b6d238..4ccab8c2ed 100644 --- a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c +++ b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c @@ -2275,7 +2275,7 @@ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetAmbientLight */ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetPointLight (JNIEnv *env, jclass class, jlong nativeCtxInfo, jlong nativeMeshViewInfo, - jint index, jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w, jfloat range, jfloat ca, ifloat la, jfloat qa) + jint index, jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w, jfloat range, jfloat ca, jfloat la, jfloat qa) { ContextInfo *ctxInfo = (ContextInfo *) jlong_to_ptr(nativeCtxInfo); MeshViewInfo *meshViewInfo = (MeshViewInfo *) jlong_to_ptr(nativeMeshViewInfo); diff --git a/modules/javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h b/modules/javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h index aede70b041..3d0402730f 100644 --- a/modules/javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h +++ b/modules/javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h @@ -380,6 +380,10 @@ struct MeshViewInfoRec { GLfloat pointLightWeight; GLfloat pointLightPosition[3]; GLfloat pointLightColor[3]; + + GLfloat pointLightRange; + GLfloat pointLightAttenuation[3]; + GLboolean cullEnable; GLenum cullMode; GLenum fillMode; From 3556ec77c3dbb3a4ce43a2d55fcebf37183aeff1 Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Mon, 11 Mar 2019 08:29:19 +0100 Subject: [PATCH 11/23] IIncluded Java+D3D-patch --- .../com/sun/javafx/sg/prism/NGPointLight.java | 82 +++++++------- .../com/sun/javafx/sg/prism/NGShape3D.java | 22 ++-- .../src/main/java/com/sun/prism/MeshView.java | 3 +- .../java/com/sun/prism/d3d/D3DContext.java | 98 ++++++++--------- .../java/com/sun/prism/d3d/D3DMeshView.java | 6 +- .../java/com/sun/prism/es2/ES2MeshView.java | 7 +- .../src/main/java/javafx/scene/LightBase.java | 1 + .../main/java/javafx/scene/PointLight.java | 101 +++++++++++------ .../src/main/native-prism-d3d/D3DContext.cc | 6 +- .../src/main/native-prism-d3d/D3DLight.cc | 8 ++ .../src/main/native-prism-d3d/D3DLight.h | 3 + .../src/main/native-prism-d3d/D3DMeshView.cc | 32 ++++-- .../src/main/native-prism-d3d/D3DMeshView.h | 6 +- .../main/native-prism-d3d/D3DPhongMaterial.h | 102 +++++++++++++----- .../main/native-prism-d3d/hlsl/psConstants.h | 3 +- .../src/main/native-prism-d3d/hlsl/psMath.h | 19 +++- 16 files changed, 317 insertions(+), 182 deletions(-) diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java index b3839972d3..1c125b1928 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java @@ -26,79 +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 { - private static final double DEFAULT_C = 1; - private static final double DEFAULT_LC = 0; - private static final double DEFAULT_QC = 0; - private static final double DEFAULT_RANGE = Double.POSITIVE_INFINITY; + /** 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 static double getDefaultC() { - return DEFAULT_C; + public NGPointLight() { + } + + public static double getDefaultCa() { + return DEFAULT_CA; } - public static double getDefaultLc() { - return DEFAULT_LC; + public static double getDefaultLa() { + return DEFAULT_LA; } - public static double getDefaultQc() { - return DEFAULT_QC; + public static double getDefaultQa() { + return DEFAULT_QA; } - public static double getDefaultRange() { - return DEFAULT_RANGE; + public static double getDefaultMaxRange() { + return DEFAULT_MAX_RANGE; } - private double c = DEFAULT_C; - public double getC() { - return c; + private double ca = DEFAULT_CA; + + public double getCa() { + return ca; } - public void setC(double c) { - this.c = c; + public void setCa(double ca) { + this.ca = ca; visualsChanged(); } - private double lc = DEFAULT_LC; + private double la = DEFAULT_LA; - public double getLc() { - return lc; + public double getLa() { + return la; } - public void setLc(double lc) { - this.lc = lc; + public void setLa(double la) { + this.la = la; visualsChanged(); } - private double qc = DEFAULT_QC; + private double qa = DEFAULT_QA; - public double getQc() { - return qc; + public double getQa() { + return qa; } - public void setQc(double qc) { - this.qc = qc; + public void setQa(double qa) { + this.qa = qa; visualsChanged(); } - private double range = DEFAULT_RANGE; + private double maxRange = DEFAULT_MAX_RANGE; - public double getRange() { - return range; + public double getMaxRange() { + return maxRange; } - public void setRange(double range) { - this.range = range < 0 ? 0 : range; + public void setMaxRange(double maxRange) { + this.maxRange = maxRange < 0 ? 0 : maxRange; visualsChanged(); } - - public NGPointLight() { - } - -} +} \ No newline at end of file diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java index ec066e607a..98ccc27bb9 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java @@ -117,10 +117,10 @@ private void renderMeshView(Graphics g) { (float)cameraPos.y, (float)cameraPos.z, 1.0f, 1.0f, 1.0f, 1.0f, - (float) NGPointLight.getDefaultC(), - (float) NGPointLight.getDefaultLc(), - (float) NGPointLight.getDefaultQc(), - (float) NGPointLight.getDefaultRange()); + (float) NGPointLight.getDefaultCa(), + (float) NGPointLight.getDefaultLa(), + (float) NGPointLight.getDefaultQa(), + (float) NGPointLight.getDefaultMaxRange()); } else { float ambientRed = 0.0f; float ambientBlue = 0.0f; @@ -160,10 +160,10 @@ private void renderMeshView(Graphics g) { (float)lightWT.getMyt(), (float)lightWT.getMzt(), rL, gL, bL, 1.0f, - (float) light.getC(), - (float) light.getLc(), - (float) light.getQc(), - (float) light.getRange()); + (float) light.getCa(), + (float) light.getLa(), + (float) light.getQa(), + (float) light.getMaxRange()); } } else if (lightBase instanceof NGAmbientLight) { // Accumulate ambient lights @@ -183,8 +183,8 @@ private void renderMeshView(Graphics g) { // Reset any previously set lights meshView.setPointLight(pointLightIdx++, 0, 0, 0, // x y z - 0, 0, 0, 0, // r g b - 1, 0, 0, 0); // c lc qc range + 0, 0, 0, 0, // r g b w + 1, 0, 0, 0); // ca la qa maxRange } meshView.render(g); @@ -228,4 +228,4 @@ public void release() { // TODO: 3D - Need to release native resources // material, mesh and meshview have native backing that need clean up. } -} +} \ No newline at end of file diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java index 66e3942999..ab12b7a6dc 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java @@ -49,6 +49,7 @@ public interface MeshView { public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, - float c, float cl, float cq, float range); + float ca, float la, float qa, float maxRange); + public void render(Graphics g); } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java index 3dc9080e10..a4e6b347b9 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java @@ -233,10 +233,10 @@ protected State updateRenderTarget(RenderTarget target, NGCamera camera, // Set projection view matrix res = nSetProjViewMatrix(pContext, depthTest, - projViewTx.get(0), projViewTx.get(1), projViewTx.get(2), projViewTx.get(3), - projViewTx.get(4), projViewTx.get(5), projViewTx.get(6), projViewTx.get(7), - projViewTx.get(8), projViewTx.get(9), projViewTx.get(10), projViewTx.get(11), - projViewTx.get(12), projViewTx.get(13), projViewTx.get(14), projViewTx.get(15)); + projViewTx.get(0), projViewTx.get(1), projViewTx.get(2), projViewTx.get(3), + projViewTx.get(4), projViewTx.get(5), projViewTx.get(6), projViewTx.get(7), + projViewTx.get(8), projViewTx.get(9), projViewTx.get(10), projViewTx.get(11), + projViewTx.get(12), projViewTx.get(13), projViewTx.get(14), projViewTx.get(15)); validate(res); cameraPos = camera.getPositionInWorld(cameraPos); @@ -293,17 +293,17 @@ protected void updateShaderTransform(Shader shader, BaseTransform xform) { res = nResetTransform(pContext); } else if (perspectiveTransform.isIdentity()) { res = nSetTransform(pContext, - xform.getMxx(), xform.getMxy(), xform.getMxz(), xform.getMxt(), - xform.getMyx(), xform.getMyy(), xform.getMyz(), xform.getMyt(), - xform.getMzx(), xform.getMzy(), xform.getMzz(), xform.getMzt(), - 0.0, 0.0, 0.0, 1.0); + xform.getMxx(), xform.getMxy(), xform.getMxz(), xform.getMxt(), + xform.getMyx(), xform.getMyy(), xform.getMyz(), xform.getMyt(), + xform.getMzx(), xform.getMzy(), xform.getMzz(), xform.getMzt(), + 0.0, 0.0, 0.0, 1.0); } else { scratchTx.setIdentity().mul(xform).mul(perspectiveTransform); res = nSetTransform(pContext, - scratchTx.get(0), scratchTx.get(1), scratchTx.get(2), scratchTx.get(3), - scratchTx.get(4), scratchTx.get(5), scratchTx.get(6), scratchTx.get(7), - scratchTx.get(8), scratchTx.get(9), scratchTx.get(10), scratchTx.get(11), - scratchTx.get(12), scratchTx.get(13), scratchTx.get(14), scratchTx.get(15)); + scratchTx.get(0), scratchTx.get(1), scratchTx.get(2), scratchTx.get(3), + scratchTx.get(4), scratchTx.get(5), scratchTx.get(6), scratchTx.get(7), + scratchTx.get(8), scratchTx.get(9), scratchTx.get(10), scratchTx.get(11), + scratchTx.get(12), scratchTx.get(13), scratchTx.get(14), scratchTx.get(15)); } validate(res); } @@ -374,28 +374,28 @@ D3DFrameStats getFrameStats(boolean reset, D3DFrameStats result) { */ private static native int nSetRenderTarget(long pContext, long pDest, boolean depthBuffer, boolean msaa); private static native int nSetTexture(long pContext, long pTex, int texUnit, - boolean linear, int wrapMode); + boolean linear, int wrapMode); private static native int nResetTransform(long pContext); private static native int nSetTransform(long pContext, - double m00, double m01, double m02, double m03, - double m10, double m11, double m12, double m13, - double m20, double m21, double m22, double m23, - double m30, double m31, double m32, double m33); + double m00, double m01, double m02, double m03, + double m10, double m11, double m12, double m13, + double m20, double m21, double m22, double m23, + double m30, double m31, double m32, double m33); private static native void nSetWorldTransformToIdentity(long pContext); private static native void nSetWorldTransform(long pContext, - double m00, double m01, double m02, double m03, - double m10, double m11, double m12, double m13, - double m20, double m21, double m22, double m23, - double m30, double m31, double m32, double m33); + double m00, double m01, double m02, double m03, + double m10, double m11, double m12, double m13, + double m20, double m21, double m22, double m23, + double m30, double m31, double m32, double m33); private static native int nSetCameraPosition(long pContext, double x, double y, double z); private static native int nSetProjViewMatrix(long pContext, boolean isOrtho, - double m00, double m01, double m02, double m03, - double m10, double m11, double m12, double m13, - double m20, double m21, double m22, double m23, - double m30, double m31, double m32, double m33); + double m00, double m01, double m02, double m03, + double m10, double m11, double m12, double m13, + double m20, double m21, double m22, double m23, + double m30, double m31, double m32, double m33); private static native int nResetClipRect(long pContext); private static native int nSetClipRect(long pContext, - int x1, int y1, int x2, int y2); + int x1, int y1, int x2, int y2); private static native int nSetBlendEnabled(long pContext, int mode); private static native int nSetDeviceParametersFor2D(long pContext); private static native int nSetDeviceParametersFor3D(long pContext); @@ -403,32 +403,33 @@ private static native int nSetClipRect(long pContext, private static native long nCreateD3DMesh(long pContext); private static native void nReleaseD3DMesh(long pContext, long nativeHandle); private static native boolean nBuildNativeGeometryShort(long pContext, long nativeHandle, - float[] vertexBuffer, int vertexBufferLength, short[] indexBuffer, int indexBufferLength); + float[] vertexBuffer, int vertexBufferLength, short[] indexBuffer, int indexBufferLength); private static native boolean nBuildNativeGeometryInt(long pContext, long nativeHandle, - float[] vertexBuffer, int vertexBufferLength, int[] indexBuffer, int indexBufferLength); + float[] vertexBuffer, int vertexBufferLength, int[] indexBuffer, int indexBufferLength); private static native long nCreateD3DPhongMaterial(long pContext); private static native void nReleaseD3DPhongMaterial(long pContext, long nativeHandle); private static native void nSetDiffuseColor(long pContext, long nativePhongMaterial, - float r, float g, float b, float a); + float r, float g, float b, float a); private static native void nSetSpecularColor(long pContext, long nativePhongMaterial, - boolean set, float r, float g, float b, float a); + boolean set, float r, float g, float b, float a); private static native void nSetMap(long pContext, long nativePhongMaterial, - int mapType, long texID); + int mapType, long texID); private static native long nCreateD3DMeshView(long pContext, long nativeMesh); private static native void nReleaseD3DMeshView(long pContext, long nativeHandle); private static native void nSetCullingMode(long pContext, long nativeMeshView, - int cullingMode); + int cullingMode); private static native void nSetMaterial(long pContext, long nativeMeshView, - long nativePhongMaterialInfo); + long nativePhongMaterialInfo); private static native void nSetWireframe(long pContext, long nativeMeshView, - boolean wireframe); + boolean wireframe); private static native void nSetAmbientLight(long pContext, long nativeMeshView, - float r, float g, float b); + float r, float g, float b); private static native void nSetPointLight(long pContext, long nativeMeshView, - int index, float x, float y, float z, float r, float g, float b, float w); + int index, float x, float y, float z, float r, float g, float b, float w, + float ca, float la, float qa, float maxRange); private static native void nRenderMeshView(long pContext, long nativeMeshView); private static native int nDrawIndexedQuads(long pContext, - float coords[], byte colors[], int numVertices); + float coords[], byte colors[], int numVertices); /* @@ -436,11 +437,11 @@ private static native int nDrawIndexedQuads(long pContext, * @param nDstRTT can be NULL if a valide render target is set */ private static native void nBlit(long pContext, long nSrcRTT, long nDstRTT, - int srcX0, int srcY0, int srcX1, int srcY1, - int dstX0, int dstY0, int dstX1, int dstY1); + int srcX0, int srcY0, int srcX1, int srcY1, + int dstX0, int dstY0, int dstX1, int dstY1); private static native boolean nGetFrameStats(long pContext, - D3DFrameStats returnValue, boolean bReset); + D3DFrameStats returnValue, boolean bReset); private static native boolean nIsRTTVolatile(long contextHandle); @@ -483,13 +484,13 @@ void releaseD3DMesh(long nativeHandle) { } boolean buildNativeGeometry(long nativeHandle, float[] vertexBuffer, int vertexBufferLength, - short[] indexBuffer, int indexBufferLength) { + short[] indexBuffer, int indexBufferLength) { return nBuildNativeGeometryShort(pContext, nativeHandle, vertexBuffer, vertexBufferLength, indexBuffer, indexBufferLength); } boolean buildNativeGeometry(long nativeHandle, float[] vertexBuffer, int vertexBufferLength, - int[] indexBuffer, int indexBufferLength) { + int[] indexBuffer, int indexBufferLength) { return nBuildNativeGeometryInt(pContext, nativeHandle, vertexBuffer, vertexBufferLength, indexBuffer, indexBufferLength); } @@ -543,15 +544,16 @@ void setMaterial(long nativeMeshView, long nativePhongMaterial) { } void setWireframe(long nativeMeshView, boolean wireframe) { - nSetWireframe(pContext, nativeMeshView, wireframe); + nSetWireframe(pContext, nativeMeshView, wireframe); } void setAmbientLight(long nativeMeshView, float r, float g, float b) { nSetAmbientLight(pContext, nativeMeshView, r, g, b); } - void setPointLight(long nativeMeshView, int index, float x, float y, float z, float r, float g, float b, float w) { - nSetPointLight(pContext, nativeMeshView, index, x, y, z, r, g, b, w); + void setPointLight(long nativeMeshView, int index, float x, float y, float z, + float r, float g, float b, float w, float ca, float la, float qa, float maxRange) { + nSetPointLight(pContext, nativeMeshView, index, x, y, z, r, g, b, w, ca, la, qa, maxRange); } @Override @@ -603,7 +605,7 @@ public void blit(RTTexture srcRTT, RTTexture dstRTT, long dstNativeHandle = dstRTT == null ? 0L : ((D3DTexture)dstRTT).getNativeSourceHandle(); long srcNativeHandle = ((D3DTexture)srcRTT).getNativeSourceHandle(); nBlit(pContext, srcNativeHandle, dstNativeHandle, - srcX0, srcY0, srcX1, srcY1, - dstX0, dstY0, dstX1, dstY1); + srcX0, srcY0, srcX1, srcY1, + dstX0, dstY0, dstX1, dstY1); } -} +} \ No newline at end of file diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java index 6c098669b6..85c0eed1aa 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java @@ -81,10 +81,11 @@ public void setAmbientLight(float r, float g, float b) { } @Override - public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float c, float lc, float qc, float range) { + 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) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { - context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w); + context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, ca, la, qa, maxRange); } } @@ -128,5 +129,4 @@ public void dispose() { } } } - } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java index a9326e14cb..912dbcb2fa 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java @@ -104,11 +104,12 @@ float getAmbientLightBlue() { * FalcoTheBold - transferred expressions from the old operator to the new overloaded operator */ @Override - public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float c, float lc, float qc, float range) { + 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) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { - lights[index] = new ES2Light(x, y, z, r, g, b, w, range, c, lc, qc); - context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, range, c, lc, qc); + lights[index] = new ES2Light(x, y, z, r, g, b, w, maxRange, ca, la, qa); + context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, maxRange, ca, la, qa); } } diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java index 0bb02ba097..53ed2bc92e 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java @@ -347,4 +347,5 @@ private boolean doComputeContains(double localX, double localY) { // TODO: 3D - Check is this the right default return false; } + } diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java b/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java index 599cc82e1d..49006f2c3e 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java @@ -29,15 +29,32 @@ import com.sun.javafx.scene.PointLightHelper; import com.sun.javafx.sg.prism.NGNode; import com.sun.javafx.sg.prism.NGPointLight; + import javafx.beans.property.DoubleProperty; import javafx.scene.paint.Color; +import javafx.scene.paint.PhongMaterial; /** - * Defines a point light source object. A light source that has a - * fixed point in space and radiates light equally in all directions - * away from itself. + * A light source that radiates light equally in all directions away from itself. The location of the light + * source is a single point in space. Any pixel within the range of the light will be illuminated by it, + * unless it belongs to a {@code Shape3D} outside of its {@code scope}. + *

+ * The light's intensity can be set to decrease over distance by attenuating it. The attenuation formula + *

+ * {@code attn = 1 / (ca + la * dist + qa * dist^2)} + *

+ * defines 3 coefficients: {@code ca}, {@code la}, and {@code qa}, which control the constant, linear, and + * quadratic behaviors of intensity falloff over distance, respectively. The effective color of the light + * at a given point in space is {@code color * attn}. It is possible, albeit unrealistic, to specify negative + * values to attenuation coefficients. This allows the resulting attenuation factor to be negative, which + * results in the light's color being subtracted from the material instead of added to it, thus creating a + * "shadow caster". + *

+ * For a realistic effect, {@code maxRange} should be set to a distance at which the attenuation is close to 0 + * as this will give a soft cutoff. * * @since JavaFX 8.0 + * @see PhongMaterial */ public class PointLight extends LightBase { static { @@ -55,12 +72,12 @@ public void doUpdatePeer(Node node) { } { - // To initialize the class helper at the begining each constructor of this class + // To initialize the class helper at the beginning each constructor of this class PointLightHelper.initHelper(this); } /** - * Creates a new instance of {@code PointLight} class with a default Color.WHITE light source. + * Creates a new instance of {@code PointLight} class with a default {@code Color.WHITE} light source. */ public PointLight() { super(); @@ -76,13 +93,13 @@ public PointLight(Color color) { } /** - * The range of this {@code PointLight}. A pixel is affected by this light i.f.f. its - * distance to the light source is less than or equal to the light's range. - * Any negative value will treated as {@code 0}. + * The maximum range of this {@code PointLight}. For a pixel to be affected by this light, its distance to + * the light source must be less than or equal to the light's maximum range. Any negative value will treated + * as 0. *

- * Lower {@code range} values can give better performance as pixels outside the range of the light - * will not require complex calculation. For a realistic effect, {@code range} should be set to - * a distance at which the attenuation is close to 0 as this will give a soft cutoff. + * Lower {@code maxRange} values can give better performance as pixels outside the range of the light + * will not require complex calculation. The attenuation formula can be used to calculate a realistic + * {@code maxRange} value by finding the where the attenuation is close enough to 0. *

* Nodes that are inside the light's range can still be excluded from the light's effect * by removing them from its {@link #getScope() scope}. If a node is known to always be @@ -91,29 +108,31 @@ public PointLight(Color color) { * @defaultValue {@code Double.POSITIVE_INFINITY} * @since 13 */ - private DoubleProperty range; + private DoubleProperty maxRange; - public final void setRange(double value) { - rangeProperty().set(value); + public final void setMaxRange(double value) { + maxRangeProperty().set(value); } - private static final double DEFAULT_RANGE = NGPointLight.getDefaultRange(); + private static final double DEFAULT_MAX_RANGE = NGPointLight.getDefaultMaxRange(); - public final double getRange() { - return range == null ? DEFAULT_RANGE : range.get(); + public final double getMaxRange() { + return maxRange == null ? DEFAULT_MAX_RANGE : maxRange.get(); } - public final DoubleProperty rangeProperty() { - if (range == null) { - range = getLightDoubleProperty("range", DEFAULT_RANGE); + public final DoubleProperty maxRangeProperty() { + if (maxRange == null) { + maxRange = getLightDoubleProperty("maxRange", DEFAULT_MAX_RANGE); } - return range; + return maxRange; } /** - * The constant attenuation coefficient. This is the term {@code c} in the attenuation formula: + * The constant attenuation coefficient. This is the term {@code ca} in the attenuation formula: + *

+ * {@code attn = 1 / (ca + la * dist + qa * dist^2)} *

- * attn = 1 / (c + lc * dist + qc * dist^2) + * where {@code dist} is the distance between the light source and the pixel. * * @defaultValue {@code 1} * @since 13 @@ -124,7 +143,7 @@ public final void setConstantAttenuation(double value) { constantAttenuationProperty().set(value); } - private static final double DEFAULT_CONSTANT_ATTENUATION = NGPointLight.getDefaultC(); + private static final double DEFAULT_CONSTANT_ATTENUATION = NGPointLight.getDefaultCa(); public final double getConstantAttenuation() { return constantAttenuation == null ? DEFAULT_CONSTANT_ATTENUATION : constantAttenuation.get(); @@ -137,14 +156,23 @@ public final DoubleProperty constantAttenuationProperty() { return constantAttenuation; } - + /** + * The linear attenuation coefficient. This is the term {@code la} in the attenuation formula: + *

+ * {@code attn = 1 / (ca + la * dist + qa * dist^2)} + *

+ * where {@code dist} is the distance between the light source and the pixel. + * + * @defaultValue {@code 0} + * @since 13 + */ private DoubleProperty linearAttenuation; public final void setLinearAttenuation(double value) { linearAttenuationProperty().set(value); } - private static final double DEFAULT_LINEAR_CONSTANT = NGPointLight.getDefaultLc(); + private static final double DEFAULT_LINEAR_CONSTANT = NGPointLight.getDefaultLa(); public final double getLinearAttenuation() { return linearAttenuation == null ? DEFAULT_LINEAR_CONSTANT : linearAttenuation.get(); @@ -157,14 +185,23 @@ public final DoubleProperty linearAttenuationProperty() { return linearAttenuation; } - + /** + * The quadratic attenuation coefficient. This is the term {@code qa} in the attenuation formula: + *

+ * {@code attn = 1 / (ca + la * dist + qa * dist^2)} + *

+ * where {@code dist} is the distance between the light source and the pixel. + * + * @defaultValue {@code 0} + * @since 13 + */ private DoubleProperty quadraticAttenuation; public final void setQuadraticAttenuation(double value) { quadraticAttenuationProperty().set(value); } - private static final double DEFAULT_QUADRATIC_CONSTANT = NGPointLight.getDefaultQc(); + private static final double DEFAULT_QUADRATIC_CONSTANT = NGPointLight.getDefaultQa(); public final double getQuadraticAttenuation() { return quadraticAttenuation == null ? DEFAULT_QUADRATIC_CONSTANT : quadraticAttenuation.get(); @@ -187,10 +224,10 @@ private NGNode doCreatePeer() { private void doUpdatePeer() { if (isDirty(DirtyBits.NODE_LIGHT)) { NGPointLight peer = getPeer(); - peer.setC(getConstantAttenuation()); - peer.setLc(getLinearAttenuation()); - peer.setQc(getQuadraticAttenuation()); - peer.setRange(getRange()); + peer.setCa(getConstantAttenuation()); + peer.setLa(getLinearAttenuation()); + peer.setQa(getQuadraticAttenuation()); + peer.setMaxRange(getMaxRange()); } } } diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc b/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc index bdcb107ae2..a7c2f37846 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc @@ -516,13 +516,13 @@ JNIEXPORT void JNICALL Java_com_sun_prism_d3d_D3DContext_nSetAmbientLight */ JNIEXPORT void JNICALL Java_com_sun_prism_d3d_D3DContext_nSetPointLight (JNIEnv *env, jclass, jlong ctx, jlong nativeMeshView, jint index, - jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w) + jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w, + jfloat ca, jfloat la, jfloat qa, jfloat range) { TraceLn(NWT_TRACE_INFO, "D3DContext_nSetPointLight"); D3DMeshView *meshView = (D3DMeshView *) jlong_to_ptr(nativeMeshView); RETURN_IF_NULL(meshView); - - meshView->setPointLight(index, x, y, z, r, g, b, w); + meshView->setPointLight(index, x, y, z, r, g, b, w, ca, la, qa, range); } /* diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.cc b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.cc index 8edc6aa1b3..8d3e11f84e 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.cc +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.cc @@ -43,6 +43,10 @@ D3DLight::D3DLight() { position[2] = 0; position[3] = 0; // padding since SetPixelShaderConstantF only takes vec4f; position[3] is unused w = 0; + attenuation[0] = 1; + attenuation[1] = 0; + attenuation[2] = 0; + attenuation[3] = 0; } void D3DLight::setColor(float r, float g, float b) { @@ -56,3 +60,7 @@ void D3DLight::setPosition(float x, float y, float z) { position[1] = y; position[2] = z; } + +/*void D3DLight::setRange(float r) { + range = r; +}*/ diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h index 2d0cf9177d..a601af1f29 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h @@ -36,9 +36,11 @@ class D3DLight { virtual ~D3DLight(); void setColor(float r, float g, float b); void setPosition(float x, float y, float z); +// void setRange(float r); float position[4]; // Only need x, y, z. The last float is needed for padding when upload to shader. float color[3]; float w; + float attenuation[4]; // ca, la, qa, range private: @@ -46,3 +48,4 @@ class D3DLight { #endif /* D3DLIGHT_H */ + diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.cc b/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.cc index 522dfac0a5..f1ffcb4d1d 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.cc +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.cc @@ -73,7 +73,8 @@ void D3DMeshView::setAmbientLight(float r, float g, float b) { } void D3DMeshView::setPointLight(int index, float x, float y, float z, - float r, float g, float b, float w) { + float r, float g, float b, float w, + float ca, float la, float qa, float range) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { lights[index].position[0] = x; @@ -83,6 +84,10 @@ void D3DMeshView::setPointLight(int index, float x, float y, float z, lights[index].color[1] = g; lights[index].color[2] = b; lights[index].w = w; + lights[index].attenuation[0] = ca; + lights[index].attenuation[1] = la; + lights[index].attenuation[2] = qa; + lights[index].attenuation[3] = range; lightsDirty = TRUE; } } @@ -154,19 +159,30 @@ void D3DMeshView::render() { return; } - float lightsColor[12]; - for (int i = 0, j = 0; i < 3; i++) { + float lightsColor[12]; // 3 lights x (3 color + 1 padding) + float lightsAttenuation[12]; // 3 lights x (3 attenuation factors + 1 range) + for (int i = 0, c = 0, r = 0; i < 3; i++) { float w = lights[i].w; - lightsColor[j++] = lights[i].color[0] * w; - lightsColor[j++] = lights[i].color[1] * w; - lightsColor[j++] = lights[i].color[2] * w; - lightsColor[j++] = 1; + lightsColor[c++] = lights[i].color[0] * w; + lightsColor[c++] = lights[i].color[1] * w; + lightsColor[c++] = lights[i].color[2] * w; + lightsColor[c++] = 1; + + lightsAttenuation[r++] = lights[i].attenuation[0]; + lightsAttenuation[r++] = lights[i].attenuation[1]; + lightsAttenuation[r++] = lights[i].attenuation[2]; + lightsAttenuation[r++] = lights[i].attenuation[3]; } status = SUCCEEDED(device->SetPixelShaderConstantF(PSR_LIGHTCOLOR, lightsColor, 3)); if (!status) { cout << "D3DMeshView.render() - SetPixelShaderConstantF (PSR_LIGHTCOLOR) failed !!!" << endl; return; } + status = SUCCEEDED(device->SetPixelShaderConstantF(PSR_LIGHT_ATTENUATION, lightsAttenuation, 3)); + if (!status) { + cout << "D3DMeshView.render() - SetPixelShaderConstantF (PSR_LIGHT_ATTENUATION) failed !!!" << endl; + return; + } int bm = pShader->getBumpMode(material->isBumpMap()); int sm = pShader->getSpecularMode(material->isSpecularMap(), material->isSpecularColor()); @@ -208,4 +224,4 @@ void D3DMeshView::render() { SUCCEEDED(device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mesh->getNumVertices(), 0, (mesh->getNumIndices()/3))); -} +} \ No newline at end of file diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.h index 6ab7206869..00d97af13e 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.h @@ -40,7 +40,8 @@ class D3DMeshView { void setWireframe(bool wf); void setAmbientLight(float r, float g, float b); void setPointLight(int index, float x, float y, float z, - float r, float g, float b, float w); + float r, float g, float b, float w, + float ca, float la, float qa, float range); void computeNumLights(); void render(); @@ -50,11 +51,10 @@ class D3DMeshView { D3DPhongMaterial *material; D3DLight lights[3]; float ambientLightColor[3]; - int numLights; + int numLights; bool lightsDirty; int cullMode; bool wireframe; }; #endif /* D3DMESHVIEW_H */ - diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h index 060c482694..d397cf751f 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h @@ -23,38 +23,88 @@ * questions. */ -#ifndef D3DPHONGMATERIAL_H -#define D3DPHONGMATERIAL_H +#ifndef D3DPHONGSHADER_H +#define D3DPHONGSHADER_H -#include "D3DContext.h" +// VSR implies Vertex Shader Registers +#define VSR_VIEWPROJMATRIX 0 // 4 total +#define VSR_CAMERAPOS 4 // 1 total +// lighting +// 5 lights (3 in use, 2 reserved) +// with 2 registers = 10 registers +#define VSR_LIGHTS 10 +// 8 ambient points + 2 coords : 10 registers +#define VSR_AMBIENTCOLOR 20 +// world +#define VSR_WORLDMATRIX 30 -// See MaterialPhong.h, MaterialPhongShaders.h +// PSR implies Pixel Shader Registers +// we have 224 float constants for ps 3.0 +#define PSR_DIFFUSECOLOR 0 +#define PSR_SPECULARCOLOR 1 +#define PSR_LIGHTCOLOR 4 // 3 lights + 2 reserve +#define PSR_LIGHT_ATTENUATION 9 // 3 lights + 2 reserve -#define DIFFUSE 0 -#define SPECULAR 1 -#define BUMP 2 -#define SELFILLUMINATION 3 +// SR implies Sampler Registers +#define SR_DIFFUSEMAP 0 +#define SR_SPECULARMAP 1 +#define SR_BUMPHEIGHTMAP 2 +#define SR_SELFILLUMMAP 3 -class D3DPhongMaterial { +enum SpecType { + SpecNone, + SpecTexture, // map only w/o alpha + SpecColor, // color w/o map + SpecMix, // map & color + SpecTotal +}; + +enum BumpType { + BumpNone, + BumpSpecified, + BumpTotal +}; + +typedef const DWORD * ShaderFunction; +ShaderFunction vsMtl1_Obj(); +ShaderFunction psMtl1(), psMtl1_i(), +psMtl1_s1n(), psMtl1_s2n(), psMtl1_s3n(), +psMtl1_s1t(), psMtl1_s2t(), psMtl1_s3t(), +psMtl1_s1c(), psMtl1_s2c(), psMtl1_s3c(), +psMtl1_s1m(), psMtl1_s2m(), psMtl1_s3m(), + +psMtl1_b1n(), psMtl1_b2n(), psMtl1_b3n(), +psMtl1_b1t(), psMtl1_b2t(), psMtl1_b3t(), +psMtl1_b1c(), psMtl1_b2c(), psMtl1_b3c(), +psMtl1_b1m(), psMtl1_b2m(), psMtl1_b3m(), + +psMtl1_s1ni(), psMtl1_s2ni(), psMtl1_s3ni(), +psMtl1_s1ti(), psMtl1_s2ti(), psMtl1_s3ti(), +psMtl1_s1ci(), psMtl1_s2ci(), psMtl1_s3ci(), +psMtl1_s1mi(), psMtl1_s2mi(), psMtl1_s3mi(), + +psMtl1_b1ni(), psMtl1_b2ni(), psMtl1_b3ni(), +psMtl1_b1ti(), psMtl1_b2ti(), psMtl1_b3ti(), +psMtl1_b1ci(), psMtl1_b2ci(), psMtl1_b3ci(), +psMtl1_b1mi(), psMtl1_b2mi(), psMtl1_b3mi(); + +class D3DPhongShader { public: - D3DPhongMaterial(D3DContext *pCtx); - virtual ~D3DPhongMaterial(); - void setDiffuseColor(float r, float g, float b, float a); - float *getDiffuseColor(); - void setSpecularColor(bool set, float r, float g, float b, float a); - float *getSpecularColor(); - void setMap(int mapID, IDirect3DBaseTexture9 *texMap); - bool isBumpMap(); - bool isSpecularMap(); - bool isSpecularColor(); - bool isSelfIllumMap(); - IDirect3DBaseTexture9 * getMap(int type); + D3DPhongShader(IDirect3DDevice9 *dev); + virtual ~D3DPhongShader(); + IDirect3DVertexShader9 *getVertexShader(); + int getBumpMode(bool isBumpMap); + int getSpecularMode(bool isSpecularMap, bool isSpecularColor); + HRESULT setPixelShader(int numLights, int specularMode, int bumpMode, int selfIllumMode); + +static const int SelfIlllumTotal = 2; +static const int maxLights = 3; private: - D3DContext *context; - float diffuseColor[4], specularColor[4]; - IDirect3DBaseTexture9 *map[4]; - bool specularColorSet; + IDirect3DDevice9 *device; + IDirect3DVertexShader9 *vertexShader; + IDirect3DPixelShader9 *pixelShader0, *pixelShader0_si; + IDirect3DPixelShader9 *pixelShaders[SelfIlllumTotal][BumpTotal][SpecTotal][maxLights]; }; -#endif /* D3DPHONGMATERIAL_H */ +#endif /* D3DPHONGSHADER_H */ diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h index 8e02cb2a40..fcb7f171f0 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h @@ -30,5 +30,6 @@ static const int numMaxLights = 5; float4 gDiffuseColor : register(c0); float4 gSpecularColor : register(c1); // specular power is in the alpha float4 gLightColor[numMaxLights] : register(c4); // [c4 .. c8] +float4 gLightAttenuation[numMaxLights] : register(c9); // [c9 .. c13] -float4 gSomethingElse : register(c9); +float4 gSomethingElse : register(c14); diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h index 7b96bd2fa1..10aa582976 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h @@ -63,9 +63,18 @@ void phong( in out float3 d, in out float3 s, int _s, int _e) { float3 refl = reflect(e, n); - for (int i=_s; i<_e; i++) { - float3 l = normalize(L[i].xyz); - d += saturate(dot(n,l))*gLightColor[i].xyz; - s += pow(saturate(dot(-refl, l)), power)*gLightColor[i].xyz; + for (int i = _s; i < _e; i++) { + float range = gLightAttenuation[i].w; + float dist = length(L[i].xyz); + if (dist <= range) { + float ca = gLightAttenuation[i].x; + float la = gLightAttenuation[i].y; + float qa = gLightAttenuation[i].z; + float attn = 1.0 / (ca + la * dist + qa * dist * dist); + + float3 l = normalize(L[i].xyz); + d += saturate(dot(n, l)) * gLightColor[i].xyz * attn; + s += pow(saturate(dot(-refl, l)), power) * gLightColor[i].xyz * attn; + } } -} +} \ No newline at end of file From 0a5d380c510eed291aaa449f04cc39f26cfa6c3b Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Mon, 11 Mar 2019 08:30:34 +0100 Subject: [PATCH 12/23] Revert "IIncluded Java+D3D-patch" This reverts commit 3556ec77c3dbb3a4ce43a2d55fcebf37183aeff1. --- .../com/sun/javafx/sg/prism/NGPointLight.java | 82 +++++++------- .../com/sun/javafx/sg/prism/NGShape3D.java | 22 ++-- .../src/main/java/com/sun/prism/MeshView.java | 3 +- .../java/com/sun/prism/d3d/D3DContext.java | 98 +++++++++-------- .../java/com/sun/prism/d3d/D3DMeshView.java | 6 +- .../java/com/sun/prism/es2/ES2MeshView.java | 7 +- .../src/main/java/javafx/scene/LightBase.java | 1 - .../main/java/javafx/scene/PointLight.java | 101 ++++++----------- .../src/main/native-prism-d3d/D3DContext.cc | 6 +- .../src/main/native-prism-d3d/D3DLight.cc | 8 -- .../src/main/native-prism-d3d/D3DLight.h | 3 - .../src/main/native-prism-d3d/D3DMeshView.cc | 32 ++---- .../src/main/native-prism-d3d/D3DMeshView.h | 6 +- .../main/native-prism-d3d/D3DPhongMaterial.h | 102 +++++------------- .../main/native-prism-d3d/hlsl/psConstants.h | 3 +- .../src/main/native-prism-d3d/hlsl/psMath.h | 19 +--- 16 files changed, 182 insertions(+), 317 deletions(-) diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java index 1c125b1928..b3839972d3 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java @@ -26,85 +26,79 @@ package com.sun.javafx.sg.prism; /** - * 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. + * TODO: 3D - Need documentation */ 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; + private static final double DEFAULT_C = 1; + private static final double DEFAULT_LC = 0; + private static final double DEFAULT_QC = 0; + private static final double DEFAULT_RANGE = Double.POSITIVE_INFINITY; - public NGPointLight() { - } - - public static double getDefaultCa() { - return DEFAULT_CA; + public static double getDefaultC() { + return DEFAULT_C; } - public static double getDefaultLa() { - return DEFAULT_LA; + public static double getDefaultLc() { + return DEFAULT_LC; } - public static double getDefaultQa() { - return DEFAULT_QA; + public static double getDefaultQc() { + return DEFAULT_QC; } - public static double getDefaultMaxRange() { - return DEFAULT_MAX_RANGE; + public static double getDefaultRange() { + return DEFAULT_RANGE; } + private double c = DEFAULT_C; - private double ca = DEFAULT_CA; - - public double getCa() { - return ca; + public double getC() { + return c; } - public void setCa(double ca) { - this.ca = ca; + public void setC(double c) { + this.c = c; visualsChanged(); } - private double la = DEFAULT_LA; + private double lc = DEFAULT_LC; - public double getLa() { - return la; + public double getLc() { + return lc; } - public void setLa(double la) { - this.la = la; + public void setLc(double lc) { + this.lc = lc; visualsChanged(); } - private double qa = DEFAULT_QA; + private double qc = DEFAULT_QC; - public double getQa() { - return qa; + public double getQc() { + return qc; } - public void setQa(double qa) { - this.qa = qa; + public void setQc(double qc) { + this.qc = qc; visualsChanged(); } - private double maxRange = DEFAULT_MAX_RANGE; + private double range = DEFAULT_RANGE; - public double getMaxRange() { - return maxRange; + public double getRange() { + return range; } - public void setMaxRange(double maxRange) { - this.maxRange = maxRange < 0 ? 0 : maxRange; + public void setRange(double range) { + this.range = range < 0 ? 0 : range; visualsChanged(); } -} \ No newline at end of file + + public NGPointLight() { + } + +} diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java index 98ccc27bb9..ec066e607a 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java @@ -117,10 +117,10 @@ private void renderMeshView(Graphics g) { (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()); + (float) NGPointLight.getDefaultC(), + (float) NGPointLight.getDefaultLc(), + (float) NGPointLight.getDefaultQc(), + (float) NGPointLight.getDefaultRange()); } else { float ambientRed = 0.0f; float ambientBlue = 0.0f; @@ -160,10 +160,10 @@ private void renderMeshView(Graphics g) { (float)lightWT.getMyt(), (float)lightWT.getMzt(), rL, gL, bL, 1.0f, - (float) light.getCa(), - (float) light.getLa(), - (float) light.getQa(), - (float) light.getMaxRange()); + (float) light.getC(), + (float) light.getLc(), + (float) light.getQc(), + (float) light.getRange()); } } else if (lightBase instanceof NGAmbientLight) { // Accumulate ambient lights @@ -183,8 +183,8 @@ private void renderMeshView(Graphics g) { // 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 + 0, 0, 0, 0, // r g b + 1, 0, 0, 0); // c lc qc range } meshView.render(g); @@ -228,4 +228,4 @@ public void release() { // TODO: 3D - Need to release native resources // material, mesh and meshview have native backing that need clean up. } -} \ No newline at end of file +} diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java index ab12b7a6dc..66e3942999 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java @@ -49,7 +49,6 @@ public interface MeshView { 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); - + float c, float cl, float cq, float range); public void render(Graphics g); } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java index a4e6b347b9..3dc9080e10 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java @@ -233,10 +233,10 @@ protected State updateRenderTarget(RenderTarget target, NGCamera camera, // Set projection view matrix res = nSetProjViewMatrix(pContext, depthTest, - projViewTx.get(0), projViewTx.get(1), projViewTx.get(2), projViewTx.get(3), - projViewTx.get(4), projViewTx.get(5), projViewTx.get(6), projViewTx.get(7), - projViewTx.get(8), projViewTx.get(9), projViewTx.get(10), projViewTx.get(11), - projViewTx.get(12), projViewTx.get(13), projViewTx.get(14), projViewTx.get(15)); + projViewTx.get(0), projViewTx.get(1), projViewTx.get(2), projViewTx.get(3), + projViewTx.get(4), projViewTx.get(5), projViewTx.get(6), projViewTx.get(7), + projViewTx.get(8), projViewTx.get(9), projViewTx.get(10), projViewTx.get(11), + projViewTx.get(12), projViewTx.get(13), projViewTx.get(14), projViewTx.get(15)); validate(res); cameraPos = camera.getPositionInWorld(cameraPos); @@ -293,17 +293,17 @@ protected void updateShaderTransform(Shader shader, BaseTransform xform) { res = nResetTransform(pContext); } else if (perspectiveTransform.isIdentity()) { res = nSetTransform(pContext, - xform.getMxx(), xform.getMxy(), xform.getMxz(), xform.getMxt(), - xform.getMyx(), xform.getMyy(), xform.getMyz(), xform.getMyt(), - xform.getMzx(), xform.getMzy(), xform.getMzz(), xform.getMzt(), - 0.0, 0.0, 0.0, 1.0); + xform.getMxx(), xform.getMxy(), xform.getMxz(), xform.getMxt(), + xform.getMyx(), xform.getMyy(), xform.getMyz(), xform.getMyt(), + xform.getMzx(), xform.getMzy(), xform.getMzz(), xform.getMzt(), + 0.0, 0.0, 0.0, 1.0); } else { scratchTx.setIdentity().mul(xform).mul(perspectiveTransform); res = nSetTransform(pContext, - scratchTx.get(0), scratchTx.get(1), scratchTx.get(2), scratchTx.get(3), - scratchTx.get(4), scratchTx.get(5), scratchTx.get(6), scratchTx.get(7), - scratchTx.get(8), scratchTx.get(9), scratchTx.get(10), scratchTx.get(11), - scratchTx.get(12), scratchTx.get(13), scratchTx.get(14), scratchTx.get(15)); + scratchTx.get(0), scratchTx.get(1), scratchTx.get(2), scratchTx.get(3), + scratchTx.get(4), scratchTx.get(5), scratchTx.get(6), scratchTx.get(7), + scratchTx.get(8), scratchTx.get(9), scratchTx.get(10), scratchTx.get(11), + scratchTx.get(12), scratchTx.get(13), scratchTx.get(14), scratchTx.get(15)); } validate(res); } @@ -374,28 +374,28 @@ D3DFrameStats getFrameStats(boolean reset, D3DFrameStats result) { */ private static native int nSetRenderTarget(long pContext, long pDest, boolean depthBuffer, boolean msaa); private static native int nSetTexture(long pContext, long pTex, int texUnit, - boolean linear, int wrapMode); + boolean linear, int wrapMode); private static native int nResetTransform(long pContext); private static native int nSetTransform(long pContext, - double m00, double m01, double m02, double m03, - double m10, double m11, double m12, double m13, - double m20, double m21, double m22, double m23, - double m30, double m31, double m32, double m33); + double m00, double m01, double m02, double m03, + double m10, double m11, double m12, double m13, + double m20, double m21, double m22, double m23, + double m30, double m31, double m32, double m33); private static native void nSetWorldTransformToIdentity(long pContext); private static native void nSetWorldTransform(long pContext, - double m00, double m01, double m02, double m03, - double m10, double m11, double m12, double m13, - double m20, double m21, double m22, double m23, - double m30, double m31, double m32, double m33); + double m00, double m01, double m02, double m03, + double m10, double m11, double m12, double m13, + double m20, double m21, double m22, double m23, + double m30, double m31, double m32, double m33); private static native int nSetCameraPosition(long pContext, double x, double y, double z); private static native int nSetProjViewMatrix(long pContext, boolean isOrtho, - double m00, double m01, double m02, double m03, - double m10, double m11, double m12, double m13, - double m20, double m21, double m22, double m23, - double m30, double m31, double m32, double m33); + double m00, double m01, double m02, double m03, + double m10, double m11, double m12, double m13, + double m20, double m21, double m22, double m23, + double m30, double m31, double m32, double m33); private static native int nResetClipRect(long pContext); private static native int nSetClipRect(long pContext, - int x1, int y1, int x2, int y2); + int x1, int y1, int x2, int y2); private static native int nSetBlendEnabled(long pContext, int mode); private static native int nSetDeviceParametersFor2D(long pContext); private static native int nSetDeviceParametersFor3D(long pContext); @@ -403,33 +403,32 @@ private static native int nSetClipRect(long pContext, private static native long nCreateD3DMesh(long pContext); private static native void nReleaseD3DMesh(long pContext, long nativeHandle); private static native boolean nBuildNativeGeometryShort(long pContext, long nativeHandle, - float[] vertexBuffer, int vertexBufferLength, short[] indexBuffer, int indexBufferLength); + float[] vertexBuffer, int vertexBufferLength, short[] indexBuffer, int indexBufferLength); private static native boolean nBuildNativeGeometryInt(long pContext, long nativeHandle, - float[] vertexBuffer, int vertexBufferLength, int[] indexBuffer, int indexBufferLength); + float[] vertexBuffer, int vertexBufferLength, int[] indexBuffer, int indexBufferLength); private static native long nCreateD3DPhongMaterial(long pContext); private static native void nReleaseD3DPhongMaterial(long pContext, long nativeHandle); private static native void nSetDiffuseColor(long pContext, long nativePhongMaterial, - float r, float g, float b, float a); + float r, float g, float b, float a); private static native void nSetSpecularColor(long pContext, long nativePhongMaterial, - boolean set, float r, float g, float b, float a); + boolean set, float r, float g, float b, float a); private static native void nSetMap(long pContext, long nativePhongMaterial, - int mapType, long texID); + int mapType, long texID); private static native long nCreateD3DMeshView(long pContext, long nativeMesh); private static native void nReleaseD3DMeshView(long pContext, long nativeHandle); private static native void nSetCullingMode(long pContext, long nativeMeshView, - int cullingMode); + int cullingMode); private static native void nSetMaterial(long pContext, long nativeMeshView, - long nativePhongMaterialInfo); + long nativePhongMaterialInfo); private static native void nSetWireframe(long pContext, long nativeMeshView, - boolean wireframe); + boolean wireframe); private static native void nSetAmbientLight(long pContext, long nativeMeshView, - float r, float g, float b); + float r, float g, float b); private static native void nSetPointLight(long pContext, long nativeMeshView, - int index, float x, float y, float z, float r, float g, float b, float w, - float ca, float la, float qa, float maxRange); + int index, float x, float y, float z, float r, float g, float b, float w); private static native void nRenderMeshView(long pContext, long nativeMeshView); private static native int nDrawIndexedQuads(long pContext, - float coords[], byte colors[], int numVertices); + float coords[], byte colors[], int numVertices); /* @@ -437,11 +436,11 @@ private static native int nDrawIndexedQuads(long pContext, * @param nDstRTT can be NULL if a valide render target is set */ private static native void nBlit(long pContext, long nSrcRTT, long nDstRTT, - int srcX0, int srcY0, int srcX1, int srcY1, - int dstX0, int dstY0, int dstX1, int dstY1); + int srcX0, int srcY0, int srcX1, int srcY1, + int dstX0, int dstY0, int dstX1, int dstY1); private static native boolean nGetFrameStats(long pContext, - D3DFrameStats returnValue, boolean bReset); + D3DFrameStats returnValue, boolean bReset); private static native boolean nIsRTTVolatile(long contextHandle); @@ -484,13 +483,13 @@ void releaseD3DMesh(long nativeHandle) { } boolean buildNativeGeometry(long nativeHandle, float[] vertexBuffer, int vertexBufferLength, - short[] indexBuffer, int indexBufferLength) { + short[] indexBuffer, int indexBufferLength) { return nBuildNativeGeometryShort(pContext, nativeHandle, vertexBuffer, vertexBufferLength, indexBuffer, indexBufferLength); } boolean buildNativeGeometry(long nativeHandle, float[] vertexBuffer, int vertexBufferLength, - int[] indexBuffer, int indexBufferLength) { + int[] indexBuffer, int indexBufferLength) { return nBuildNativeGeometryInt(pContext, nativeHandle, vertexBuffer, vertexBufferLength, indexBuffer, indexBufferLength); } @@ -544,16 +543,15 @@ void setMaterial(long nativeMeshView, long nativePhongMaterial) { } void setWireframe(long nativeMeshView, boolean wireframe) { - nSetWireframe(pContext, nativeMeshView, wireframe); + nSetWireframe(pContext, nativeMeshView, wireframe); } void setAmbientLight(long nativeMeshView, float r, float g, float b) { nSetAmbientLight(pContext, nativeMeshView, r, g, b); } - void setPointLight(long nativeMeshView, int index, float x, float y, float z, - float r, float g, float b, float w, float ca, float la, float qa, float maxRange) { - nSetPointLight(pContext, nativeMeshView, index, x, y, z, r, g, b, w, ca, la, qa, maxRange); + void setPointLight(long nativeMeshView, int index, float x, float y, float z, float r, float g, float b, float w) { + nSetPointLight(pContext, nativeMeshView, index, x, y, z, r, g, b, w); } @Override @@ -605,7 +603,7 @@ public void blit(RTTexture srcRTT, RTTexture dstRTT, long dstNativeHandle = dstRTT == null ? 0L : ((D3DTexture)dstRTT).getNativeSourceHandle(); long srcNativeHandle = ((D3DTexture)srcRTT).getNativeSourceHandle(); nBlit(pContext, srcNativeHandle, dstNativeHandle, - srcX0, srcY0, srcX1, srcY1, - dstX0, dstY0, dstX1, dstY1); + srcX0, srcY0, srcX1, srcY1, + dstX0, dstY0, dstX1, dstY1); } -} \ No newline at end of file +} diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java index 85c0eed1aa..6c098669b6 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java @@ -81,11 +81,10 @@ public void setAmbientLight(float r, float g, float b) { } @Override - 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 setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float c, float lc, float qc, float range) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { - context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, ca, la, qa, maxRange); + context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w); } } @@ -129,4 +128,5 @@ public void dispose() { } } } + } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java index 912dbcb2fa..a9326e14cb 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java @@ -104,12 +104,11 @@ float getAmbientLightBlue() { * FalcoTheBold - transferred expressions from the old operator to the new overloaded operator */ @Override - 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 setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float c, float lc, float qc, float range) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { - lights[index] = new ES2Light(x, y, z, r, g, b, w, maxRange, ca, la, qa); - context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, maxRange, ca, la, qa); + lights[index] = new ES2Light(x, y, z, r, g, b, w, range, c, lc, qc); + context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, range, c, lc, qc); } } diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java index 53ed2bc92e..0bb02ba097 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java @@ -347,5 +347,4 @@ private boolean doComputeContains(double localX, double localY) { // TODO: 3D - Check is this the right default return false; } - } diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java b/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java index 49006f2c3e..599cc82e1d 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java @@ -29,32 +29,15 @@ import com.sun.javafx.scene.PointLightHelper; import com.sun.javafx.sg.prism.NGNode; import com.sun.javafx.sg.prism.NGPointLight; - import javafx.beans.property.DoubleProperty; import javafx.scene.paint.Color; -import javafx.scene.paint.PhongMaterial; /** - * A light source that radiates light equally in all directions away from itself. The location of the light - * source is a single point in space. Any pixel within the range of the light will be illuminated by it, - * unless it belongs to a {@code Shape3D} outside of its {@code scope}. - *

- * The light's intensity can be set to decrease over distance by attenuating it. The attenuation formula - *

- * {@code attn = 1 / (ca + la * dist + qa * dist^2)} - *

- * defines 3 coefficients: {@code ca}, {@code la}, and {@code qa}, which control the constant, linear, and - * quadratic behaviors of intensity falloff over distance, respectively. The effective color of the light - * at a given point in space is {@code color * attn}. It is possible, albeit unrealistic, to specify negative - * values to attenuation coefficients. This allows the resulting attenuation factor to be negative, which - * results in the light's color being subtracted from the material instead of added to it, thus creating a - * "shadow caster". - *

- * For a realistic effect, {@code maxRange} should be set to a distance at which the attenuation is close to 0 - * as this will give a soft cutoff. + * Defines a point light source object. A light source that has a + * fixed point in space and radiates light equally in all directions + * away from itself. * * @since JavaFX 8.0 - * @see PhongMaterial */ public class PointLight extends LightBase { static { @@ -72,12 +55,12 @@ public void doUpdatePeer(Node node) { } { - // To initialize the class helper at the beginning each constructor of this class + // To initialize the class helper at the begining each constructor of this class PointLightHelper.initHelper(this); } /** - * Creates a new instance of {@code PointLight} class with a default {@code Color.WHITE} light source. + * Creates a new instance of {@code PointLight} class with a default Color.WHITE light source. */ public PointLight() { super(); @@ -93,13 +76,13 @@ public PointLight(Color color) { } /** - * The maximum range of this {@code PointLight}. For a pixel to be affected by this light, its distance to - * the light source must be less than or equal to the light's maximum range. Any negative value will treated - * as 0. + * The range of this {@code PointLight}. A pixel is affected by this light i.f.f. its + * distance to the light source is less than or equal to the light's range. + * Any negative value will treated as {@code 0}. *

- * Lower {@code maxRange} values can give better performance as pixels outside the range of the light - * will not require complex calculation. The attenuation formula can be used to calculate a realistic - * {@code maxRange} value by finding the where the attenuation is close enough to 0. + * Lower {@code range} values can give better performance as pixels outside the range of the light + * will not require complex calculation. For a realistic effect, {@code range} should be set to + * a distance at which the attenuation is close to 0 as this will give a soft cutoff. *

* Nodes that are inside the light's range can still be excluded from the light's effect * by removing them from its {@link #getScope() scope}. If a node is known to always be @@ -108,31 +91,29 @@ public PointLight(Color color) { * @defaultValue {@code Double.POSITIVE_INFINITY} * @since 13 */ - private DoubleProperty maxRange; + private DoubleProperty range; - public final void setMaxRange(double value) { - maxRangeProperty().set(value); + public final void setRange(double value) { + rangeProperty().set(value); } - private static final double DEFAULT_MAX_RANGE = NGPointLight.getDefaultMaxRange(); + private static final double DEFAULT_RANGE = NGPointLight.getDefaultRange(); - public final double getMaxRange() { - return maxRange == null ? DEFAULT_MAX_RANGE : maxRange.get(); + public final double getRange() { + return range == null ? DEFAULT_RANGE : range.get(); } - public final DoubleProperty maxRangeProperty() { - if (maxRange == null) { - maxRange = getLightDoubleProperty("maxRange", DEFAULT_MAX_RANGE); + public final DoubleProperty rangeProperty() { + if (range == null) { + range = getLightDoubleProperty("range", DEFAULT_RANGE); } - return maxRange; + return range; } /** - * The constant attenuation coefficient. This is the term {@code ca} in the attenuation formula: - *

- * {@code attn = 1 / (ca + la * dist + qa * dist^2)} + * The constant attenuation coefficient. This is the term {@code c} in the attenuation formula: *

- * where {@code dist} is the distance between the light source and the pixel. + * attn = 1 / (c + lc * dist + qc * dist^2) * * @defaultValue {@code 1} * @since 13 @@ -143,7 +124,7 @@ public final void setConstantAttenuation(double value) { constantAttenuationProperty().set(value); } - private static final double DEFAULT_CONSTANT_ATTENUATION = NGPointLight.getDefaultCa(); + private static final double DEFAULT_CONSTANT_ATTENUATION = NGPointLight.getDefaultC(); public final double getConstantAttenuation() { return constantAttenuation == null ? DEFAULT_CONSTANT_ATTENUATION : constantAttenuation.get(); @@ -156,23 +137,14 @@ public final DoubleProperty constantAttenuationProperty() { return constantAttenuation; } - /** - * The linear attenuation coefficient. This is the term {@code la} in the attenuation formula: - *

- * {@code attn = 1 / (ca + la * dist + qa * dist^2)} - *

- * where {@code dist} is the distance between the light source and the pixel. - * - * @defaultValue {@code 0} - * @since 13 - */ + private DoubleProperty linearAttenuation; public final void setLinearAttenuation(double value) { linearAttenuationProperty().set(value); } - private static final double DEFAULT_LINEAR_CONSTANT = NGPointLight.getDefaultLa(); + private static final double DEFAULT_LINEAR_CONSTANT = NGPointLight.getDefaultLc(); public final double getLinearAttenuation() { return linearAttenuation == null ? DEFAULT_LINEAR_CONSTANT : linearAttenuation.get(); @@ -185,23 +157,14 @@ public final DoubleProperty linearAttenuationProperty() { return linearAttenuation; } - /** - * The quadratic attenuation coefficient. This is the term {@code qa} in the attenuation formula: - *

- * {@code attn = 1 / (ca + la * dist + qa * dist^2)} - *

- * where {@code dist} is the distance between the light source and the pixel. - * - * @defaultValue {@code 0} - * @since 13 - */ + private DoubleProperty quadraticAttenuation; public final void setQuadraticAttenuation(double value) { quadraticAttenuationProperty().set(value); } - private static final double DEFAULT_QUADRATIC_CONSTANT = NGPointLight.getDefaultQa(); + private static final double DEFAULT_QUADRATIC_CONSTANT = NGPointLight.getDefaultQc(); public final double getQuadraticAttenuation() { return quadraticAttenuation == null ? DEFAULT_QUADRATIC_CONSTANT : quadraticAttenuation.get(); @@ -224,10 +187,10 @@ private NGNode doCreatePeer() { private void doUpdatePeer() { if (isDirty(DirtyBits.NODE_LIGHT)) { NGPointLight peer = getPeer(); - peer.setCa(getConstantAttenuation()); - peer.setLa(getLinearAttenuation()); - peer.setQa(getQuadraticAttenuation()); - peer.setMaxRange(getMaxRange()); + peer.setC(getConstantAttenuation()); + peer.setLc(getLinearAttenuation()); + peer.setQc(getQuadraticAttenuation()); + peer.setRange(getRange()); } } } diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc b/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc index a7c2f37846..bdcb107ae2 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc @@ -516,13 +516,13 @@ JNIEXPORT void JNICALL Java_com_sun_prism_d3d_D3DContext_nSetAmbientLight */ JNIEXPORT void JNICALL Java_com_sun_prism_d3d_D3DContext_nSetPointLight (JNIEnv *env, jclass, jlong ctx, jlong nativeMeshView, jint index, - jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w, - jfloat ca, jfloat la, jfloat qa, jfloat range) + jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w) { TraceLn(NWT_TRACE_INFO, "D3DContext_nSetPointLight"); D3DMeshView *meshView = (D3DMeshView *) jlong_to_ptr(nativeMeshView); RETURN_IF_NULL(meshView); - meshView->setPointLight(index, x, y, z, r, g, b, w, ca, la, qa, range); + + meshView->setPointLight(index, x, y, z, r, g, b, w); } /* diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.cc b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.cc index 8d3e11f84e..8edc6aa1b3 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.cc +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.cc @@ -43,10 +43,6 @@ D3DLight::D3DLight() { position[2] = 0; position[3] = 0; // padding since SetPixelShaderConstantF only takes vec4f; position[3] is unused w = 0; - attenuation[0] = 1; - attenuation[1] = 0; - attenuation[2] = 0; - attenuation[3] = 0; } void D3DLight::setColor(float r, float g, float b) { @@ -60,7 +56,3 @@ void D3DLight::setPosition(float x, float y, float z) { position[1] = y; position[2] = z; } - -/*void D3DLight::setRange(float r) { - range = r; -}*/ diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h index a601af1f29..2d0cf9177d 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h @@ -36,11 +36,9 @@ class D3DLight { virtual ~D3DLight(); void setColor(float r, float g, float b); void setPosition(float x, float y, float z); -// void setRange(float r); float position[4]; // Only need x, y, z. The last float is needed for padding when upload to shader. float color[3]; float w; - float attenuation[4]; // ca, la, qa, range private: @@ -48,4 +46,3 @@ class D3DLight { #endif /* D3DLIGHT_H */ - diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.cc b/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.cc index f1ffcb4d1d..522dfac0a5 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.cc +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.cc @@ -73,8 +73,7 @@ void D3DMeshView::setAmbientLight(float r, float g, float b) { } void D3DMeshView::setPointLight(int index, float x, float y, float z, - float r, float g, float b, float w, - float ca, float la, float qa, float range) { + float r, float g, float b, float w) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { lights[index].position[0] = x; @@ -84,10 +83,6 @@ void D3DMeshView::setPointLight(int index, float x, float y, float z, lights[index].color[1] = g; lights[index].color[2] = b; lights[index].w = w; - lights[index].attenuation[0] = ca; - lights[index].attenuation[1] = la; - lights[index].attenuation[2] = qa; - lights[index].attenuation[3] = range; lightsDirty = TRUE; } } @@ -159,30 +154,19 @@ void D3DMeshView::render() { return; } - float lightsColor[12]; // 3 lights x (3 color + 1 padding) - float lightsAttenuation[12]; // 3 lights x (3 attenuation factors + 1 range) - for (int i = 0, c = 0, r = 0; i < 3; i++) { + float lightsColor[12]; + for (int i = 0, j = 0; i < 3; i++) { float w = lights[i].w; - lightsColor[c++] = lights[i].color[0] * w; - lightsColor[c++] = lights[i].color[1] * w; - lightsColor[c++] = lights[i].color[2] * w; - lightsColor[c++] = 1; - - lightsAttenuation[r++] = lights[i].attenuation[0]; - lightsAttenuation[r++] = lights[i].attenuation[1]; - lightsAttenuation[r++] = lights[i].attenuation[2]; - lightsAttenuation[r++] = lights[i].attenuation[3]; + lightsColor[j++] = lights[i].color[0] * w; + lightsColor[j++] = lights[i].color[1] * w; + lightsColor[j++] = lights[i].color[2] * w; + lightsColor[j++] = 1; } status = SUCCEEDED(device->SetPixelShaderConstantF(PSR_LIGHTCOLOR, lightsColor, 3)); if (!status) { cout << "D3DMeshView.render() - SetPixelShaderConstantF (PSR_LIGHTCOLOR) failed !!!" << endl; return; } - status = SUCCEEDED(device->SetPixelShaderConstantF(PSR_LIGHT_ATTENUATION, lightsAttenuation, 3)); - if (!status) { - cout << "D3DMeshView.render() - SetPixelShaderConstantF (PSR_LIGHT_ATTENUATION) failed !!!" << endl; - return; - } int bm = pShader->getBumpMode(material->isBumpMap()); int sm = pShader->getSpecularMode(material->isSpecularMap(), material->isSpecularColor()); @@ -224,4 +208,4 @@ void D3DMeshView::render() { SUCCEEDED(device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mesh->getNumVertices(), 0, (mesh->getNumIndices()/3))); -} \ No newline at end of file +} diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.h index 00d97af13e..6ab7206869 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.h @@ -40,8 +40,7 @@ class D3DMeshView { void setWireframe(bool wf); void setAmbientLight(float r, float g, float b); 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 range); + float r, float g, float b, float w); void computeNumLights(); void render(); @@ -51,10 +50,11 @@ class D3DMeshView { D3DPhongMaterial *material; D3DLight lights[3]; float ambientLightColor[3]; - int numLights; + int numLights; bool lightsDirty; int cullMode; bool wireframe; }; #endif /* D3DMESHVIEW_H */ + diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h index d397cf751f..060c482694 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h @@ -23,88 +23,38 @@ * questions. */ -#ifndef D3DPHONGSHADER_H -#define D3DPHONGSHADER_H +#ifndef D3DPHONGMATERIAL_H +#define D3DPHONGMATERIAL_H -// VSR implies Vertex Shader Registers -#define VSR_VIEWPROJMATRIX 0 // 4 total -#define VSR_CAMERAPOS 4 // 1 total -// lighting -// 5 lights (3 in use, 2 reserved) -// with 2 registers = 10 registers -#define VSR_LIGHTS 10 -// 8 ambient points + 2 coords : 10 registers -#define VSR_AMBIENTCOLOR 20 -// world -#define VSR_WORLDMATRIX 30 +#include "D3DContext.h" -// PSR implies Pixel Shader Registers -// we have 224 float constants for ps 3.0 -#define PSR_DIFFUSECOLOR 0 -#define PSR_SPECULARCOLOR 1 -#define PSR_LIGHTCOLOR 4 // 3 lights + 2 reserve -#define PSR_LIGHT_ATTENUATION 9 // 3 lights + 2 reserve +// See MaterialPhong.h, MaterialPhongShaders.h -// SR implies Sampler Registers -#define SR_DIFFUSEMAP 0 -#define SR_SPECULARMAP 1 -#define SR_BUMPHEIGHTMAP 2 -#define SR_SELFILLUMMAP 3 +#define DIFFUSE 0 +#define SPECULAR 1 +#define BUMP 2 +#define SELFILLUMINATION 3 -enum SpecType { - SpecNone, - SpecTexture, // map only w/o alpha - SpecColor, // color w/o map - SpecMix, // map & color - SpecTotal -}; - -enum BumpType { - BumpNone, - BumpSpecified, - BumpTotal -}; - -typedef const DWORD * ShaderFunction; -ShaderFunction vsMtl1_Obj(); -ShaderFunction psMtl1(), psMtl1_i(), -psMtl1_s1n(), psMtl1_s2n(), psMtl1_s3n(), -psMtl1_s1t(), psMtl1_s2t(), psMtl1_s3t(), -psMtl1_s1c(), psMtl1_s2c(), psMtl1_s3c(), -psMtl1_s1m(), psMtl1_s2m(), psMtl1_s3m(), - -psMtl1_b1n(), psMtl1_b2n(), psMtl1_b3n(), -psMtl1_b1t(), psMtl1_b2t(), psMtl1_b3t(), -psMtl1_b1c(), psMtl1_b2c(), psMtl1_b3c(), -psMtl1_b1m(), psMtl1_b2m(), psMtl1_b3m(), - -psMtl1_s1ni(), psMtl1_s2ni(), psMtl1_s3ni(), -psMtl1_s1ti(), psMtl1_s2ti(), psMtl1_s3ti(), -psMtl1_s1ci(), psMtl1_s2ci(), psMtl1_s3ci(), -psMtl1_s1mi(), psMtl1_s2mi(), psMtl1_s3mi(), - -psMtl1_b1ni(), psMtl1_b2ni(), psMtl1_b3ni(), -psMtl1_b1ti(), psMtl1_b2ti(), psMtl1_b3ti(), -psMtl1_b1ci(), psMtl1_b2ci(), psMtl1_b3ci(), -psMtl1_b1mi(), psMtl1_b2mi(), psMtl1_b3mi(); - -class D3DPhongShader { +class D3DPhongMaterial { public: - D3DPhongShader(IDirect3DDevice9 *dev); - virtual ~D3DPhongShader(); - IDirect3DVertexShader9 *getVertexShader(); - int getBumpMode(bool isBumpMap); - int getSpecularMode(bool isSpecularMap, bool isSpecularColor); - HRESULT setPixelShader(int numLights, int specularMode, int bumpMode, int selfIllumMode); - -static const int SelfIlllumTotal = 2; -static const int maxLights = 3; + D3DPhongMaterial(D3DContext *pCtx); + virtual ~D3DPhongMaterial(); + void setDiffuseColor(float r, float g, float b, float a); + float *getDiffuseColor(); + void setSpecularColor(bool set, float r, float g, float b, float a); + float *getSpecularColor(); + void setMap(int mapID, IDirect3DBaseTexture9 *texMap); + bool isBumpMap(); + bool isSpecularMap(); + bool isSpecularColor(); + bool isSelfIllumMap(); + IDirect3DBaseTexture9 * getMap(int type); private: - IDirect3DDevice9 *device; - IDirect3DVertexShader9 *vertexShader; - IDirect3DPixelShader9 *pixelShader0, *pixelShader0_si; - IDirect3DPixelShader9 *pixelShaders[SelfIlllumTotal][BumpTotal][SpecTotal][maxLights]; + D3DContext *context; + float diffuseColor[4], specularColor[4]; + IDirect3DBaseTexture9 *map[4]; + bool specularColorSet; }; -#endif /* D3DPHONGSHADER_H */ +#endif /* D3DPHONGMATERIAL_H */ diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h index fcb7f171f0..8e02cb2a40 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h @@ -30,6 +30,5 @@ static const int numMaxLights = 5; float4 gDiffuseColor : register(c0); float4 gSpecularColor : register(c1); // specular power is in the alpha float4 gLightColor[numMaxLights] : register(c4); // [c4 .. c8] -float4 gLightAttenuation[numMaxLights] : register(c9); // [c9 .. c13] -float4 gSomethingElse : register(c14); +float4 gSomethingElse : register(c9); diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h index 10aa582976..7b96bd2fa1 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h @@ -63,18 +63,9 @@ void phong( in out float3 d, in out float3 s, int _s, int _e) { float3 refl = reflect(e, n); - for (int i = _s; i < _e; i++) { - float range = gLightAttenuation[i].w; - float dist = length(L[i].xyz); - if (dist <= range) { - float ca = gLightAttenuation[i].x; - float la = gLightAttenuation[i].y; - float qa = gLightAttenuation[i].z; - float attn = 1.0 / (ca + la * dist + qa * dist * dist); - - float3 l = normalize(L[i].xyz); - d += saturate(dot(n, l)) * gLightColor[i].xyz * attn; - s += pow(saturate(dot(-refl, l)), power) * gLightColor[i].xyz * attn; - } + for (int i=_s; i<_e; i++) { + float3 l = normalize(L[i].xyz); + d += saturate(dot(n,l))*gLightColor[i].xyz; + s += pow(saturate(dot(-refl, l)), power)*gLightColor[i].xyz; } -} \ No newline at end of file +} From 444cc945e12f1bda4d3bfd208ec2a4de0173d90c Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Mon, 11 Mar 2019 08:33:06 +0100 Subject: [PATCH 13/23] Revert "Small fixes #3" This reverts commit 18e58fec4ae06adcd9addad7f8f52e4122743399. --- modules/javafx.graphics/src/main/native-prism-es2/GLContext.c | 2 +- .../javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c index 4ccab8c2ed..4a60b6d238 100644 --- a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c +++ b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c @@ -2275,7 +2275,7 @@ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetAmbientLight */ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetPointLight (JNIEnv *env, jclass class, jlong nativeCtxInfo, jlong nativeMeshViewInfo, - jint index, jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w, jfloat range, jfloat ca, jfloat la, jfloat qa) + jint index, jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w, jfloat range, jfloat ca, ifloat la, jfloat qa) { ContextInfo *ctxInfo = (ContextInfo *) jlong_to_ptr(nativeCtxInfo); MeshViewInfo *meshViewInfo = (MeshViewInfo *) jlong_to_ptr(nativeMeshViewInfo); diff --git a/modules/javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h b/modules/javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h index 3d0402730f..aede70b041 100644 --- a/modules/javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h +++ b/modules/javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h @@ -380,10 +380,6 @@ struct MeshViewInfoRec { GLfloat pointLightWeight; GLfloat pointLightPosition[3]; GLfloat pointLightColor[3]; - - GLfloat pointLightRange; - GLfloat pointLightAttenuation[3]; - GLboolean cullEnable; GLenum cullMode; GLenum fillMode; From a7d8b91d9999e35d266ef1d6e439ccbe4ba0f9b9 Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Mon, 11 Mar 2019 08:34:58 +0100 Subject: [PATCH 14/23] Revert "Revert "IIncluded Java+D3D-patch"" This reverts commit 0a5d380c510eed291aaa449f04cc39f26cfa6c3b. --- .../com/sun/javafx/sg/prism/NGPointLight.java | 82 +++++++------- .../com/sun/javafx/sg/prism/NGShape3D.java | 22 ++-- .../src/main/java/com/sun/prism/MeshView.java | 3 +- .../java/com/sun/prism/d3d/D3DContext.java | 98 ++++++++--------- .../java/com/sun/prism/d3d/D3DMeshView.java | 6 +- .../java/com/sun/prism/es2/ES2MeshView.java | 7 +- .../src/main/java/javafx/scene/LightBase.java | 1 + .../main/java/javafx/scene/PointLight.java | 101 +++++++++++------ .../src/main/native-prism-d3d/D3DContext.cc | 6 +- .../src/main/native-prism-d3d/D3DLight.cc | 8 ++ .../src/main/native-prism-d3d/D3DLight.h | 3 + .../src/main/native-prism-d3d/D3DMeshView.cc | 32 ++++-- .../src/main/native-prism-d3d/D3DMeshView.h | 6 +- .../main/native-prism-d3d/D3DPhongMaterial.h | 102 +++++++++++++----- .../main/native-prism-d3d/hlsl/psConstants.h | 3 +- .../src/main/native-prism-d3d/hlsl/psMath.h | 19 +++- 16 files changed, 317 insertions(+), 182 deletions(-) diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java index b3839972d3..1c125b1928 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java @@ -26,79 +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 { - private static final double DEFAULT_C = 1; - private static final double DEFAULT_LC = 0; - private static final double DEFAULT_QC = 0; - private static final double DEFAULT_RANGE = Double.POSITIVE_INFINITY; + /** 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 static double getDefaultC() { - return DEFAULT_C; + public NGPointLight() { + } + + public static double getDefaultCa() { + return DEFAULT_CA; } - public static double getDefaultLc() { - return DEFAULT_LC; + public static double getDefaultLa() { + return DEFAULT_LA; } - public static double getDefaultQc() { - return DEFAULT_QC; + public static double getDefaultQa() { + return DEFAULT_QA; } - public static double getDefaultRange() { - return DEFAULT_RANGE; + public static double getDefaultMaxRange() { + return DEFAULT_MAX_RANGE; } - private double c = DEFAULT_C; - public double getC() { - return c; + private double ca = DEFAULT_CA; + + public double getCa() { + return ca; } - public void setC(double c) { - this.c = c; + public void setCa(double ca) { + this.ca = ca; visualsChanged(); } - private double lc = DEFAULT_LC; + private double la = DEFAULT_LA; - public double getLc() { - return lc; + public double getLa() { + return la; } - public void setLc(double lc) { - this.lc = lc; + public void setLa(double la) { + this.la = la; visualsChanged(); } - private double qc = DEFAULT_QC; + private double qa = DEFAULT_QA; - public double getQc() { - return qc; + public double getQa() { + return qa; } - public void setQc(double qc) { - this.qc = qc; + public void setQa(double qa) { + this.qa = qa; visualsChanged(); } - private double range = DEFAULT_RANGE; + private double maxRange = DEFAULT_MAX_RANGE; - public double getRange() { - return range; + public double getMaxRange() { + return maxRange; } - public void setRange(double range) { - this.range = range < 0 ? 0 : range; + public void setMaxRange(double maxRange) { + this.maxRange = maxRange < 0 ? 0 : maxRange; visualsChanged(); } - - public NGPointLight() { - } - -} +} \ No newline at end of file diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java index ec066e607a..98ccc27bb9 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java @@ -117,10 +117,10 @@ private void renderMeshView(Graphics g) { (float)cameraPos.y, (float)cameraPos.z, 1.0f, 1.0f, 1.0f, 1.0f, - (float) NGPointLight.getDefaultC(), - (float) NGPointLight.getDefaultLc(), - (float) NGPointLight.getDefaultQc(), - (float) NGPointLight.getDefaultRange()); + (float) NGPointLight.getDefaultCa(), + (float) NGPointLight.getDefaultLa(), + (float) NGPointLight.getDefaultQa(), + (float) NGPointLight.getDefaultMaxRange()); } else { float ambientRed = 0.0f; float ambientBlue = 0.0f; @@ -160,10 +160,10 @@ private void renderMeshView(Graphics g) { (float)lightWT.getMyt(), (float)lightWT.getMzt(), rL, gL, bL, 1.0f, - (float) light.getC(), - (float) light.getLc(), - (float) light.getQc(), - (float) light.getRange()); + (float) light.getCa(), + (float) light.getLa(), + (float) light.getQa(), + (float) light.getMaxRange()); } } else if (lightBase instanceof NGAmbientLight) { // Accumulate ambient lights @@ -183,8 +183,8 @@ private void renderMeshView(Graphics g) { // Reset any previously set lights meshView.setPointLight(pointLightIdx++, 0, 0, 0, // x y z - 0, 0, 0, 0, // r g b - 1, 0, 0, 0); // c lc qc range + 0, 0, 0, 0, // r g b w + 1, 0, 0, 0); // ca la qa maxRange } meshView.render(g); @@ -228,4 +228,4 @@ public void release() { // TODO: 3D - Need to release native resources // material, mesh and meshview have native backing that need clean up. } -} +} \ No newline at end of file diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java index 66e3942999..ab12b7a6dc 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java @@ -49,6 +49,7 @@ public interface MeshView { public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, - float c, float cl, float cq, float range); + float ca, float la, float qa, float maxRange); + public void render(Graphics g); } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java index 3dc9080e10..a4e6b347b9 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java @@ -233,10 +233,10 @@ protected State updateRenderTarget(RenderTarget target, NGCamera camera, // Set projection view matrix res = nSetProjViewMatrix(pContext, depthTest, - projViewTx.get(0), projViewTx.get(1), projViewTx.get(2), projViewTx.get(3), - projViewTx.get(4), projViewTx.get(5), projViewTx.get(6), projViewTx.get(7), - projViewTx.get(8), projViewTx.get(9), projViewTx.get(10), projViewTx.get(11), - projViewTx.get(12), projViewTx.get(13), projViewTx.get(14), projViewTx.get(15)); + projViewTx.get(0), projViewTx.get(1), projViewTx.get(2), projViewTx.get(3), + projViewTx.get(4), projViewTx.get(5), projViewTx.get(6), projViewTx.get(7), + projViewTx.get(8), projViewTx.get(9), projViewTx.get(10), projViewTx.get(11), + projViewTx.get(12), projViewTx.get(13), projViewTx.get(14), projViewTx.get(15)); validate(res); cameraPos = camera.getPositionInWorld(cameraPos); @@ -293,17 +293,17 @@ protected void updateShaderTransform(Shader shader, BaseTransform xform) { res = nResetTransform(pContext); } else if (perspectiveTransform.isIdentity()) { res = nSetTransform(pContext, - xform.getMxx(), xform.getMxy(), xform.getMxz(), xform.getMxt(), - xform.getMyx(), xform.getMyy(), xform.getMyz(), xform.getMyt(), - xform.getMzx(), xform.getMzy(), xform.getMzz(), xform.getMzt(), - 0.0, 0.0, 0.0, 1.0); + xform.getMxx(), xform.getMxy(), xform.getMxz(), xform.getMxt(), + xform.getMyx(), xform.getMyy(), xform.getMyz(), xform.getMyt(), + xform.getMzx(), xform.getMzy(), xform.getMzz(), xform.getMzt(), + 0.0, 0.0, 0.0, 1.0); } else { scratchTx.setIdentity().mul(xform).mul(perspectiveTransform); res = nSetTransform(pContext, - scratchTx.get(0), scratchTx.get(1), scratchTx.get(2), scratchTx.get(3), - scratchTx.get(4), scratchTx.get(5), scratchTx.get(6), scratchTx.get(7), - scratchTx.get(8), scratchTx.get(9), scratchTx.get(10), scratchTx.get(11), - scratchTx.get(12), scratchTx.get(13), scratchTx.get(14), scratchTx.get(15)); + scratchTx.get(0), scratchTx.get(1), scratchTx.get(2), scratchTx.get(3), + scratchTx.get(4), scratchTx.get(5), scratchTx.get(6), scratchTx.get(7), + scratchTx.get(8), scratchTx.get(9), scratchTx.get(10), scratchTx.get(11), + scratchTx.get(12), scratchTx.get(13), scratchTx.get(14), scratchTx.get(15)); } validate(res); } @@ -374,28 +374,28 @@ D3DFrameStats getFrameStats(boolean reset, D3DFrameStats result) { */ private static native int nSetRenderTarget(long pContext, long pDest, boolean depthBuffer, boolean msaa); private static native int nSetTexture(long pContext, long pTex, int texUnit, - boolean linear, int wrapMode); + boolean linear, int wrapMode); private static native int nResetTransform(long pContext); private static native int nSetTransform(long pContext, - double m00, double m01, double m02, double m03, - double m10, double m11, double m12, double m13, - double m20, double m21, double m22, double m23, - double m30, double m31, double m32, double m33); + double m00, double m01, double m02, double m03, + double m10, double m11, double m12, double m13, + double m20, double m21, double m22, double m23, + double m30, double m31, double m32, double m33); private static native void nSetWorldTransformToIdentity(long pContext); private static native void nSetWorldTransform(long pContext, - double m00, double m01, double m02, double m03, - double m10, double m11, double m12, double m13, - double m20, double m21, double m22, double m23, - double m30, double m31, double m32, double m33); + double m00, double m01, double m02, double m03, + double m10, double m11, double m12, double m13, + double m20, double m21, double m22, double m23, + double m30, double m31, double m32, double m33); private static native int nSetCameraPosition(long pContext, double x, double y, double z); private static native int nSetProjViewMatrix(long pContext, boolean isOrtho, - double m00, double m01, double m02, double m03, - double m10, double m11, double m12, double m13, - double m20, double m21, double m22, double m23, - double m30, double m31, double m32, double m33); + double m00, double m01, double m02, double m03, + double m10, double m11, double m12, double m13, + double m20, double m21, double m22, double m23, + double m30, double m31, double m32, double m33); private static native int nResetClipRect(long pContext); private static native int nSetClipRect(long pContext, - int x1, int y1, int x2, int y2); + int x1, int y1, int x2, int y2); private static native int nSetBlendEnabled(long pContext, int mode); private static native int nSetDeviceParametersFor2D(long pContext); private static native int nSetDeviceParametersFor3D(long pContext); @@ -403,32 +403,33 @@ private static native int nSetClipRect(long pContext, private static native long nCreateD3DMesh(long pContext); private static native void nReleaseD3DMesh(long pContext, long nativeHandle); private static native boolean nBuildNativeGeometryShort(long pContext, long nativeHandle, - float[] vertexBuffer, int vertexBufferLength, short[] indexBuffer, int indexBufferLength); + float[] vertexBuffer, int vertexBufferLength, short[] indexBuffer, int indexBufferLength); private static native boolean nBuildNativeGeometryInt(long pContext, long nativeHandle, - float[] vertexBuffer, int vertexBufferLength, int[] indexBuffer, int indexBufferLength); + float[] vertexBuffer, int vertexBufferLength, int[] indexBuffer, int indexBufferLength); private static native long nCreateD3DPhongMaterial(long pContext); private static native void nReleaseD3DPhongMaterial(long pContext, long nativeHandle); private static native void nSetDiffuseColor(long pContext, long nativePhongMaterial, - float r, float g, float b, float a); + float r, float g, float b, float a); private static native void nSetSpecularColor(long pContext, long nativePhongMaterial, - boolean set, float r, float g, float b, float a); + boolean set, float r, float g, float b, float a); private static native void nSetMap(long pContext, long nativePhongMaterial, - int mapType, long texID); + int mapType, long texID); private static native long nCreateD3DMeshView(long pContext, long nativeMesh); private static native void nReleaseD3DMeshView(long pContext, long nativeHandle); private static native void nSetCullingMode(long pContext, long nativeMeshView, - int cullingMode); + int cullingMode); private static native void nSetMaterial(long pContext, long nativeMeshView, - long nativePhongMaterialInfo); + long nativePhongMaterialInfo); private static native void nSetWireframe(long pContext, long nativeMeshView, - boolean wireframe); + boolean wireframe); private static native void nSetAmbientLight(long pContext, long nativeMeshView, - float r, float g, float b); + float r, float g, float b); private static native void nSetPointLight(long pContext, long nativeMeshView, - int index, float x, float y, float z, float r, float g, float b, float w); + int index, float x, float y, float z, float r, float g, float b, float w, + float ca, float la, float qa, float maxRange); private static native void nRenderMeshView(long pContext, long nativeMeshView); private static native int nDrawIndexedQuads(long pContext, - float coords[], byte colors[], int numVertices); + float coords[], byte colors[], int numVertices); /* @@ -436,11 +437,11 @@ private static native int nDrawIndexedQuads(long pContext, * @param nDstRTT can be NULL if a valide render target is set */ private static native void nBlit(long pContext, long nSrcRTT, long nDstRTT, - int srcX0, int srcY0, int srcX1, int srcY1, - int dstX0, int dstY0, int dstX1, int dstY1); + int srcX0, int srcY0, int srcX1, int srcY1, + int dstX0, int dstY0, int dstX1, int dstY1); private static native boolean nGetFrameStats(long pContext, - D3DFrameStats returnValue, boolean bReset); + D3DFrameStats returnValue, boolean bReset); private static native boolean nIsRTTVolatile(long contextHandle); @@ -483,13 +484,13 @@ void releaseD3DMesh(long nativeHandle) { } boolean buildNativeGeometry(long nativeHandle, float[] vertexBuffer, int vertexBufferLength, - short[] indexBuffer, int indexBufferLength) { + short[] indexBuffer, int indexBufferLength) { return nBuildNativeGeometryShort(pContext, nativeHandle, vertexBuffer, vertexBufferLength, indexBuffer, indexBufferLength); } boolean buildNativeGeometry(long nativeHandle, float[] vertexBuffer, int vertexBufferLength, - int[] indexBuffer, int indexBufferLength) { + int[] indexBuffer, int indexBufferLength) { return nBuildNativeGeometryInt(pContext, nativeHandle, vertexBuffer, vertexBufferLength, indexBuffer, indexBufferLength); } @@ -543,15 +544,16 @@ void setMaterial(long nativeMeshView, long nativePhongMaterial) { } void setWireframe(long nativeMeshView, boolean wireframe) { - nSetWireframe(pContext, nativeMeshView, wireframe); + nSetWireframe(pContext, nativeMeshView, wireframe); } void setAmbientLight(long nativeMeshView, float r, float g, float b) { nSetAmbientLight(pContext, nativeMeshView, r, g, b); } - void setPointLight(long nativeMeshView, int index, float x, float y, float z, float r, float g, float b, float w) { - nSetPointLight(pContext, nativeMeshView, index, x, y, z, r, g, b, w); + void setPointLight(long nativeMeshView, int index, float x, float y, float z, + float r, float g, float b, float w, float ca, float la, float qa, float maxRange) { + nSetPointLight(pContext, nativeMeshView, index, x, y, z, r, g, b, w, ca, la, qa, maxRange); } @Override @@ -603,7 +605,7 @@ public void blit(RTTexture srcRTT, RTTexture dstRTT, long dstNativeHandle = dstRTT == null ? 0L : ((D3DTexture)dstRTT).getNativeSourceHandle(); long srcNativeHandle = ((D3DTexture)srcRTT).getNativeSourceHandle(); nBlit(pContext, srcNativeHandle, dstNativeHandle, - srcX0, srcY0, srcX1, srcY1, - dstX0, dstY0, dstX1, dstY1); + srcX0, srcY0, srcX1, srcY1, + dstX0, dstY0, dstX1, dstY1); } -} +} \ No newline at end of file diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java index 6c098669b6..85c0eed1aa 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DMeshView.java @@ -81,10 +81,11 @@ public void setAmbientLight(float r, float g, float b) { } @Override - public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float c, float lc, float qc, float range) { + 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) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { - context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w); + context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, ca, la, qa, maxRange); } } @@ -128,5 +129,4 @@ public void dispose() { } } } - } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java index a9326e14cb..912dbcb2fa 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java @@ -104,11 +104,12 @@ float getAmbientLightBlue() { * FalcoTheBold - transferred expressions from the old operator to the new overloaded operator */ @Override - public void setPointLight(int index, float x, float y, float z, float r, float g, float b, float w, float c, float lc, float qc, float range) { + 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) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { - lights[index] = new ES2Light(x, y, z, r, g, b, w, range, c, lc, qc); - context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, range, c, lc, qc); + lights[index] = new ES2Light(x, y, z, r, g, b, w, maxRange, ca, la, qa); + context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, maxRange, ca, la, qa); } } diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java index 0bb02ba097..53ed2bc92e 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/LightBase.java @@ -347,4 +347,5 @@ private boolean doComputeContains(double localX, double localY) { // TODO: 3D - Check is this the right default return false; } + } diff --git a/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java b/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java index 599cc82e1d..49006f2c3e 100644 --- a/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java +++ b/modules/javafx.graphics/src/main/java/javafx/scene/PointLight.java @@ -29,15 +29,32 @@ import com.sun.javafx.scene.PointLightHelper; import com.sun.javafx.sg.prism.NGNode; import com.sun.javafx.sg.prism.NGPointLight; + import javafx.beans.property.DoubleProperty; import javafx.scene.paint.Color; +import javafx.scene.paint.PhongMaterial; /** - * Defines a point light source object. A light source that has a - * fixed point in space and radiates light equally in all directions - * away from itself. + * A light source that radiates light equally in all directions away from itself. The location of the light + * source is a single point in space. Any pixel within the range of the light will be illuminated by it, + * unless it belongs to a {@code Shape3D} outside of its {@code scope}. + *

+ * The light's intensity can be set to decrease over distance by attenuating it. The attenuation formula + *

+ * {@code attn = 1 / (ca + la * dist + qa * dist^2)} + *

+ * defines 3 coefficients: {@code ca}, {@code la}, and {@code qa}, which control the constant, linear, and + * quadratic behaviors of intensity falloff over distance, respectively. The effective color of the light + * at a given point in space is {@code color * attn}. It is possible, albeit unrealistic, to specify negative + * values to attenuation coefficients. This allows the resulting attenuation factor to be negative, which + * results in the light's color being subtracted from the material instead of added to it, thus creating a + * "shadow caster". + *

+ * For a realistic effect, {@code maxRange} should be set to a distance at which the attenuation is close to 0 + * as this will give a soft cutoff. * * @since JavaFX 8.0 + * @see PhongMaterial */ public class PointLight extends LightBase { static { @@ -55,12 +72,12 @@ public void doUpdatePeer(Node node) { } { - // To initialize the class helper at the begining each constructor of this class + // To initialize the class helper at the beginning each constructor of this class PointLightHelper.initHelper(this); } /** - * Creates a new instance of {@code PointLight} class with a default Color.WHITE light source. + * Creates a new instance of {@code PointLight} class with a default {@code Color.WHITE} light source. */ public PointLight() { super(); @@ -76,13 +93,13 @@ public PointLight(Color color) { } /** - * The range of this {@code PointLight}. A pixel is affected by this light i.f.f. its - * distance to the light source is less than or equal to the light's range. - * Any negative value will treated as {@code 0}. + * The maximum range of this {@code PointLight}. For a pixel to be affected by this light, its distance to + * the light source must be less than or equal to the light's maximum range. Any negative value will treated + * as 0. *

- * Lower {@code range} values can give better performance as pixels outside the range of the light - * will not require complex calculation. For a realistic effect, {@code range} should be set to - * a distance at which the attenuation is close to 0 as this will give a soft cutoff. + * Lower {@code maxRange} values can give better performance as pixels outside the range of the light + * will not require complex calculation. The attenuation formula can be used to calculate a realistic + * {@code maxRange} value by finding the where the attenuation is close enough to 0. *

* Nodes that are inside the light's range can still be excluded from the light's effect * by removing them from its {@link #getScope() scope}. If a node is known to always be @@ -91,29 +108,31 @@ public PointLight(Color color) { * @defaultValue {@code Double.POSITIVE_INFINITY} * @since 13 */ - private DoubleProperty range; + private DoubleProperty maxRange; - public final void setRange(double value) { - rangeProperty().set(value); + public final void setMaxRange(double value) { + maxRangeProperty().set(value); } - private static final double DEFAULT_RANGE = NGPointLight.getDefaultRange(); + private static final double DEFAULT_MAX_RANGE = NGPointLight.getDefaultMaxRange(); - public final double getRange() { - return range == null ? DEFAULT_RANGE : range.get(); + public final double getMaxRange() { + return maxRange == null ? DEFAULT_MAX_RANGE : maxRange.get(); } - public final DoubleProperty rangeProperty() { - if (range == null) { - range = getLightDoubleProperty("range", DEFAULT_RANGE); + public final DoubleProperty maxRangeProperty() { + if (maxRange == null) { + maxRange = getLightDoubleProperty("maxRange", DEFAULT_MAX_RANGE); } - return range; + return maxRange; } /** - * The constant attenuation coefficient. This is the term {@code c} in the attenuation formula: + * The constant attenuation coefficient. This is the term {@code ca} in the attenuation formula: + *

+ * {@code attn = 1 / (ca + la * dist + qa * dist^2)} *

- * attn = 1 / (c + lc * dist + qc * dist^2) + * where {@code dist} is the distance between the light source and the pixel. * * @defaultValue {@code 1} * @since 13 @@ -124,7 +143,7 @@ public final void setConstantAttenuation(double value) { constantAttenuationProperty().set(value); } - private static final double DEFAULT_CONSTANT_ATTENUATION = NGPointLight.getDefaultC(); + private static final double DEFAULT_CONSTANT_ATTENUATION = NGPointLight.getDefaultCa(); public final double getConstantAttenuation() { return constantAttenuation == null ? DEFAULT_CONSTANT_ATTENUATION : constantAttenuation.get(); @@ -137,14 +156,23 @@ public final DoubleProperty constantAttenuationProperty() { return constantAttenuation; } - + /** + * The linear attenuation coefficient. This is the term {@code la} in the attenuation formula: + *

+ * {@code attn = 1 / (ca + la * dist + qa * dist^2)} + *

+ * where {@code dist} is the distance between the light source and the pixel. + * + * @defaultValue {@code 0} + * @since 13 + */ private DoubleProperty linearAttenuation; public final void setLinearAttenuation(double value) { linearAttenuationProperty().set(value); } - private static final double DEFAULT_LINEAR_CONSTANT = NGPointLight.getDefaultLc(); + private static final double DEFAULT_LINEAR_CONSTANT = NGPointLight.getDefaultLa(); public final double getLinearAttenuation() { return linearAttenuation == null ? DEFAULT_LINEAR_CONSTANT : linearAttenuation.get(); @@ -157,14 +185,23 @@ public final DoubleProperty linearAttenuationProperty() { return linearAttenuation; } - + /** + * The quadratic attenuation coefficient. This is the term {@code qa} in the attenuation formula: + *

+ * {@code attn = 1 / (ca + la * dist + qa * dist^2)} + *

+ * where {@code dist} is the distance between the light source and the pixel. + * + * @defaultValue {@code 0} + * @since 13 + */ private DoubleProperty quadraticAttenuation; public final void setQuadraticAttenuation(double value) { quadraticAttenuationProperty().set(value); } - private static final double DEFAULT_QUADRATIC_CONSTANT = NGPointLight.getDefaultQc(); + private static final double DEFAULT_QUADRATIC_CONSTANT = NGPointLight.getDefaultQa(); public final double getQuadraticAttenuation() { return quadraticAttenuation == null ? DEFAULT_QUADRATIC_CONSTANT : quadraticAttenuation.get(); @@ -187,10 +224,10 @@ private NGNode doCreatePeer() { private void doUpdatePeer() { if (isDirty(DirtyBits.NODE_LIGHT)) { NGPointLight peer = getPeer(); - peer.setC(getConstantAttenuation()); - peer.setLc(getLinearAttenuation()); - peer.setQc(getQuadraticAttenuation()); - peer.setRange(getRange()); + peer.setCa(getConstantAttenuation()); + peer.setLa(getLinearAttenuation()); + peer.setQa(getQuadraticAttenuation()); + peer.setMaxRange(getMaxRange()); } } } diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc b/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc index bdcb107ae2..a7c2f37846 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DContext.cc @@ -516,13 +516,13 @@ JNIEXPORT void JNICALL Java_com_sun_prism_d3d_D3DContext_nSetAmbientLight */ JNIEXPORT void JNICALL Java_com_sun_prism_d3d_D3DContext_nSetPointLight (JNIEnv *env, jclass, jlong ctx, jlong nativeMeshView, jint index, - jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w) + jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w, + jfloat ca, jfloat la, jfloat qa, jfloat range) { TraceLn(NWT_TRACE_INFO, "D3DContext_nSetPointLight"); D3DMeshView *meshView = (D3DMeshView *) jlong_to_ptr(nativeMeshView); RETURN_IF_NULL(meshView); - - meshView->setPointLight(index, x, y, z, r, g, b, w); + meshView->setPointLight(index, x, y, z, r, g, b, w, ca, la, qa, range); } /* diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.cc b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.cc index 8edc6aa1b3..8d3e11f84e 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.cc +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.cc @@ -43,6 +43,10 @@ D3DLight::D3DLight() { position[2] = 0; position[3] = 0; // padding since SetPixelShaderConstantF only takes vec4f; position[3] is unused w = 0; + attenuation[0] = 1; + attenuation[1] = 0; + attenuation[2] = 0; + attenuation[3] = 0; } void D3DLight::setColor(float r, float g, float b) { @@ -56,3 +60,7 @@ void D3DLight::setPosition(float x, float y, float z) { position[1] = y; position[2] = z; } + +/*void D3DLight::setRange(float r) { + range = r; +}*/ diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h index 2d0cf9177d..a601af1f29 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h @@ -36,9 +36,11 @@ class D3DLight { virtual ~D3DLight(); void setColor(float r, float g, float b); void setPosition(float x, float y, float z); +// void setRange(float r); float position[4]; // Only need x, y, z. The last float is needed for padding when upload to shader. float color[3]; float w; + float attenuation[4]; // ca, la, qa, range private: @@ -46,3 +48,4 @@ class D3DLight { #endif /* D3DLIGHT_H */ + diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.cc b/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.cc index 522dfac0a5..f1ffcb4d1d 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.cc +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.cc @@ -73,7 +73,8 @@ void D3DMeshView::setAmbientLight(float r, float g, float b) { } void D3DMeshView::setPointLight(int index, float x, float y, float z, - float r, float g, float b, float w) { + float r, float g, float b, float w, + float ca, float la, float qa, float range) { // NOTE: We only support up to 3 point lights at the present if (index >= 0 && index <= 2) { lights[index].position[0] = x; @@ -83,6 +84,10 @@ void D3DMeshView::setPointLight(int index, float x, float y, float z, lights[index].color[1] = g; lights[index].color[2] = b; lights[index].w = w; + lights[index].attenuation[0] = ca; + lights[index].attenuation[1] = la; + lights[index].attenuation[2] = qa; + lights[index].attenuation[3] = range; lightsDirty = TRUE; } } @@ -154,19 +159,30 @@ void D3DMeshView::render() { return; } - float lightsColor[12]; - for (int i = 0, j = 0; i < 3; i++) { + float lightsColor[12]; // 3 lights x (3 color + 1 padding) + float lightsAttenuation[12]; // 3 lights x (3 attenuation factors + 1 range) + for (int i = 0, c = 0, r = 0; i < 3; i++) { float w = lights[i].w; - lightsColor[j++] = lights[i].color[0] * w; - lightsColor[j++] = lights[i].color[1] * w; - lightsColor[j++] = lights[i].color[2] * w; - lightsColor[j++] = 1; + lightsColor[c++] = lights[i].color[0] * w; + lightsColor[c++] = lights[i].color[1] * w; + lightsColor[c++] = lights[i].color[2] * w; + lightsColor[c++] = 1; + + lightsAttenuation[r++] = lights[i].attenuation[0]; + lightsAttenuation[r++] = lights[i].attenuation[1]; + lightsAttenuation[r++] = lights[i].attenuation[2]; + lightsAttenuation[r++] = lights[i].attenuation[3]; } status = SUCCEEDED(device->SetPixelShaderConstantF(PSR_LIGHTCOLOR, lightsColor, 3)); if (!status) { cout << "D3DMeshView.render() - SetPixelShaderConstantF (PSR_LIGHTCOLOR) failed !!!" << endl; return; } + status = SUCCEEDED(device->SetPixelShaderConstantF(PSR_LIGHT_ATTENUATION, lightsAttenuation, 3)); + if (!status) { + cout << "D3DMeshView.render() - SetPixelShaderConstantF (PSR_LIGHT_ATTENUATION) failed !!!" << endl; + return; + } int bm = pShader->getBumpMode(material->isBumpMap()); int sm = pShader->getSpecularMode(material->isSpecularMap(), material->isSpecularColor()); @@ -208,4 +224,4 @@ void D3DMeshView::render() { SUCCEEDED(device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, mesh->getNumVertices(), 0, (mesh->getNumIndices()/3))); -} +} \ No newline at end of file diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.h index 6ab7206869..00d97af13e 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DMeshView.h @@ -40,7 +40,8 @@ class D3DMeshView { void setWireframe(bool wf); void setAmbientLight(float r, float g, float b); void setPointLight(int index, float x, float y, float z, - float r, float g, float b, float w); + float r, float g, float b, float w, + float ca, float la, float qa, float range); void computeNumLights(); void render(); @@ -50,11 +51,10 @@ class D3DMeshView { D3DPhongMaterial *material; D3DLight lights[3]; float ambientLightColor[3]; - int numLights; + int numLights; bool lightsDirty; int cullMode; bool wireframe; }; #endif /* D3DMESHVIEW_H */ - diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h index 060c482694..d397cf751f 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h @@ -23,38 +23,88 @@ * questions. */ -#ifndef D3DPHONGMATERIAL_H -#define D3DPHONGMATERIAL_H +#ifndef D3DPHONGSHADER_H +#define D3DPHONGSHADER_H -#include "D3DContext.h" +// VSR implies Vertex Shader Registers +#define VSR_VIEWPROJMATRIX 0 // 4 total +#define VSR_CAMERAPOS 4 // 1 total +// lighting +// 5 lights (3 in use, 2 reserved) +// with 2 registers = 10 registers +#define VSR_LIGHTS 10 +// 8 ambient points + 2 coords : 10 registers +#define VSR_AMBIENTCOLOR 20 +// world +#define VSR_WORLDMATRIX 30 -// See MaterialPhong.h, MaterialPhongShaders.h +// PSR implies Pixel Shader Registers +// we have 224 float constants for ps 3.0 +#define PSR_DIFFUSECOLOR 0 +#define PSR_SPECULARCOLOR 1 +#define PSR_LIGHTCOLOR 4 // 3 lights + 2 reserve +#define PSR_LIGHT_ATTENUATION 9 // 3 lights + 2 reserve -#define DIFFUSE 0 -#define SPECULAR 1 -#define BUMP 2 -#define SELFILLUMINATION 3 +// SR implies Sampler Registers +#define SR_DIFFUSEMAP 0 +#define SR_SPECULARMAP 1 +#define SR_BUMPHEIGHTMAP 2 +#define SR_SELFILLUMMAP 3 -class D3DPhongMaterial { +enum SpecType { + SpecNone, + SpecTexture, // map only w/o alpha + SpecColor, // color w/o map + SpecMix, // map & color + SpecTotal +}; + +enum BumpType { + BumpNone, + BumpSpecified, + BumpTotal +}; + +typedef const DWORD * ShaderFunction; +ShaderFunction vsMtl1_Obj(); +ShaderFunction psMtl1(), psMtl1_i(), +psMtl1_s1n(), psMtl1_s2n(), psMtl1_s3n(), +psMtl1_s1t(), psMtl1_s2t(), psMtl1_s3t(), +psMtl1_s1c(), psMtl1_s2c(), psMtl1_s3c(), +psMtl1_s1m(), psMtl1_s2m(), psMtl1_s3m(), + +psMtl1_b1n(), psMtl1_b2n(), psMtl1_b3n(), +psMtl1_b1t(), psMtl1_b2t(), psMtl1_b3t(), +psMtl1_b1c(), psMtl1_b2c(), psMtl1_b3c(), +psMtl1_b1m(), psMtl1_b2m(), psMtl1_b3m(), + +psMtl1_s1ni(), psMtl1_s2ni(), psMtl1_s3ni(), +psMtl1_s1ti(), psMtl1_s2ti(), psMtl1_s3ti(), +psMtl1_s1ci(), psMtl1_s2ci(), psMtl1_s3ci(), +psMtl1_s1mi(), psMtl1_s2mi(), psMtl1_s3mi(), + +psMtl1_b1ni(), psMtl1_b2ni(), psMtl1_b3ni(), +psMtl1_b1ti(), psMtl1_b2ti(), psMtl1_b3ti(), +psMtl1_b1ci(), psMtl1_b2ci(), psMtl1_b3ci(), +psMtl1_b1mi(), psMtl1_b2mi(), psMtl1_b3mi(); + +class D3DPhongShader { public: - D3DPhongMaterial(D3DContext *pCtx); - virtual ~D3DPhongMaterial(); - void setDiffuseColor(float r, float g, float b, float a); - float *getDiffuseColor(); - void setSpecularColor(bool set, float r, float g, float b, float a); - float *getSpecularColor(); - void setMap(int mapID, IDirect3DBaseTexture9 *texMap); - bool isBumpMap(); - bool isSpecularMap(); - bool isSpecularColor(); - bool isSelfIllumMap(); - IDirect3DBaseTexture9 * getMap(int type); + D3DPhongShader(IDirect3DDevice9 *dev); + virtual ~D3DPhongShader(); + IDirect3DVertexShader9 *getVertexShader(); + int getBumpMode(bool isBumpMap); + int getSpecularMode(bool isSpecularMap, bool isSpecularColor); + HRESULT setPixelShader(int numLights, int specularMode, int bumpMode, int selfIllumMode); + +static const int SelfIlllumTotal = 2; +static const int maxLights = 3; private: - D3DContext *context; - float diffuseColor[4], specularColor[4]; - IDirect3DBaseTexture9 *map[4]; - bool specularColorSet; + IDirect3DDevice9 *device; + IDirect3DVertexShader9 *vertexShader; + IDirect3DPixelShader9 *pixelShader0, *pixelShader0_si; + IDirect3DPixelShader9 *pixelShaders[SelfIlllumTotal][BumpTotal][SpecTotal][maxLights]; }; -#endif /* D3DPHONGMATERIAL_H */ +#endif /* D3DPHONGSHADER_H */ diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h index 8e02cb2a40..fcb7f171f0 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psConstants.h @@ -30,5 +30,6 @@ static const int numMaxLights = 5; float4 gDiffuseColor : register(c0); float4 gSpecularColor : register(c1); // specular power is in the alpha float4 gLightColor[numMaxLights] : register(c4); // [c4 .. c8] +float4 gLightAttenuation[numMaxLights] : register(c9); // [c9 .. c13] -float4 gSomethingElse : register(c9); +float4 gSomethingElse : register(c14); diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h index 7b96bd2fa1..10aa582976 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h @@ -63,9 +63,18 @@ void phong( in out float3 d, in out float3 s, int _s, int _e) { float3 refl = reflect(e, n); - for (int i=_s; i<_e; i++) { - float3 l = normalize(L[i].xyz); - d += saturate(dot(n,l))*gLightColor[i].xyz; - s += pow(saturate(dot(-refl, l)), power)*gLightColor[i].xyz; + for (int i = _s; i < _e; i++) { + float range = gLightAttenuation[i].w; + float dist = length(L[i].xyz); + if (dist <= range) { + float ca = gLightAttenuation[i].x; + float la = gLightAttenuation[i].y; + float qa = gLightAttenuation[i].z; + float attn = 1.0 / (ca + la * dist + qa * dist * dist); + + float3 l = normalize(L[i].xyz); + d += saturate(dot(n, l)) * gLightColor[i].xyz * attn; + s += pow(saturate(dot(-refl, l)), power) * gLightColor[i].xyz * attn; + } } -} +} \ No newline at end of file From 5d25b788c91ddf07c62bc15c6d43992c4a8f110e Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Mon, 11 Mar 2019 08:36:17 +0100 Subject: [PATCH 15/23] Revert "Revert "Small fixes #3"" This reverts commit 444cc945e12f1bda4d3bfd208ec2a4de0173d90c. --- modules/javafx.graphics/src/main/native-prism-es2/GLContext.c | 2 +- .../javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c index 4a60b6d238..4ccab8c2ed 100644 --- a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c +++ b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c @@ -2275,7 +2275,7 @@ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetAmbientLight */ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetPointLight (JNIEnv *env, jclass class, jlong nativeCtxInfo, jlong nativeMeshViewInfo, - jint index, jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w, jfloat range, jfloat ca, ifloat la, jfloat qa) + jint index, jfloat x, jfloat y, jfloat z, jfloat r, jfloat g, jfloat b, jfloat w, jfloat range, jfloat ca, jfloat la, jfloat qa) { ContextInfo *ctxInfo = (ContextInfo *) jlong_to_ptr(nativeCtxInfo); MeshViewInfo *meshViewInfo = (MeshViewInfo *) jlong_to_ptr(nativeMeshViewInfo); diff --git a/modules/javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h b/modules/javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h index aede70b041..3d0402730f 100644 --- a/modules/javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h +++ b/modules/javafx.graphics/src/main/native-prism-es2/PrismES2Defs.h @@ -380,6 +380,10 @@ struct MeshViewInfoRec { GLfloat pointLightWeight; GLfloat pointLightPosition[3]; GLfloat pointLightColor[3]; + + GLfloat pointLightRange; + GLfloat pointLightAttenuation[3]; + GLboolean cullEnable; GLenum cullMode; GLenum fillMode; From 21a610bae1f74d1f3be46056a90c0b69ea7542df Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Mon, 11 Mar 2019 08:54:54 +0100 Subject: [PATCH 16/23] Update D3DPhongMaterial --- .../src/main/native-prism-d3d/D3DPhongMaterial.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h index d397cf751f..dc09e6ff79 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h @@ -65,7 +65,7 @@ enum BumpType { BumpTotal }; -typedef const DWORD * ShaderFunction; +typedef const DWORD *ShaderFunction; ShaderFunction vsMtl1_Obj(); ShaderFunction psMtl1(), psMtl1_i(), psMtl1_s1n(), psMtl1_s2n(), psMtl1_s3n(), @@ -107,4 +107,4 @@ static const int maxLights = 3; IDirect3DPixelShader9 *pixelShaders[SelfIlllumTotal][BumpTotal][SpecTotal][maxLights]; }; -#endif /* D3DPHONGSHADER_H */ +#endif /* D3DPHONGSHADER_H */ \ No newline at end of file From ab0eb82c3dd11d4eb9324c03c5fde4c17c698f2a Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Mon, 11 Mar 2019 09:07:37 +0100 Subject: [PATCH 17/23] Updated D3D-files --- .../main/native-prism-d3d/D3DPhongMaterial.h | 149 +++++++++--------- .../main/native-prism-d3d/D3DPhongShader.h | 6 +- 2 files changed, 80 insertions(+), 75 deletions(-) diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h index dc09e6ff79..71a2c19ef8 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h @@ -23,88 +23,93 @@ * questions. */ -#ifndef D3DPHONGSHADER_H -#define D3DPHONGSHADER_H +#include +#include "D3DPhongMaterial.h" -// VSR implies Vertex Shader Registers -#define VSR_VIEWPROJMATRIX 0 // 4 total -#define VSR_CAMERAPOS 4 // 1 total -// lighting -// 5 lights (3 in use, 2 reserved) -// with 2 registers = 10 registers -#define VSR_LIGHTS 10 -// 8 ambient points + 2 coords : 10 registers -#define VSR_AMBIENTCOLOR 20 -// world -#define VSR_WORLDMATRIX 30 +using std::cout; +using std::cerr; +using std::endl; -// PSR implies Pixel Shader Registers -// we have 224 float constants for ps 3.0 -#define PSR_DIFFUSECOLOR 0 -#define PSR_SPECULARCOLOR 1 -#define PSR_LIGHTCOLOR 4 // 3 lights + 2 reserve -#define PSR_LIGHT_ATTENUATION 9 // 3 lights + 2 reserve +// Destructor definition +D3DPhongMaterial::~D3DPhongMaterial() { + context = NULL; + // The freeing of texture native resources is handled by its Java layer. + map[DIFFUSE] = NULL; + map[SPECULAR] = NULL; + map[BUMP] = NULL; + map[SELFILLUMINATION] = NULL; +} -// SR implies Sampler Registers -#define SR_DIFFUSEMAP 0 -#define SR_SPECULARMAP 1 -#define SR_BUMPHEIGHTMAP 2 -#define SR_SELFILLUMMAP 3 +D3DPhongMaterial::D3DPhongMaterial(D3DContext *ctx) { + context = ctx; + diffuseColor[0] = 0; + diffuseColor[1] = 0; + diffuseColor[2] = 0; + diffuseColor[3] = 0; + specularColorSet = false; + specularColor[0] = 1; + specularColor[1] = 1; + specularColor[2] = 1; + specularColor[3] = 32; + map[DIFFUSE] = NULL; + map[SPECULAR] = NULL; + map[BUMP] = NULL; + map[SELFILLUMINATION] = NULL; +} -enum SpecType { - SpecNone, - SpecTexture, // map only w/o alpha - SpecColor, // color w/o map - SpecMix, // map & color - SpecTotal -}; +void D3DPhongMaterial::setDiffuseColor(float r, float g, float b, float a) { + diffuseColor[0] = r; + diffuseColor[1] = g; + diffuseColor[2] = b; + diffuseColor[3] = a; +} -enum BumpType { - BumpNone, - BumpSpecified, - BumpTotal -}; +float * D3DPhongMaterial::getDiffuseColor() { + return diffuseColor; +} -typedef const DWORD *ShaderFunction; -ShaderFunction vsMtl1_Obj(); -ShaderFunction psMtl1(), psMtl1_i(), -psMtl1_s1n(), psMtl1_s2n(), psMtl1_s3n(), -psMtl1_s1t(), psMtl1_s2t(), psMtl1_s3t(), -psMtl1_s1c(), psMtl1_s2c(), psMtl1_s3c(), -psMtl1_s1m(), psMtl1_s2m(), psMtl1_s3m(), +void D3DPhongMaterial::setSpecularColor(bool set, float r, float g, float b, float a) { + specularColorSet = set; + specularColor[0] = r; + specularColor[1] = g; + specularColor[2] = b; + specularColor[3] = a; +} -psMtl1_b1n(), psMtl1_b2n(), psMtl1_b3n(), -psMtl1_b1t(), psMtl1_b2t(), psMtl1_b3t(), -psMtl1_b1c(), psMtl1_b2c(), psMtl1_b3c(), -psMtl1_b1m(), psMtl1_b2m(), psMtl1_b3m(), +float * D3DPhongMaterial::getSpecularColor() { + return specularColor; +} -psMtl1_s1ni(), psMtl1_s2ni(), psMtl1_s3ni(), -psMtl1_s1ti(), psMtl1_s2ti(), psMtl1_s3ti(), -psMtl1_s1ci(), psMtl1_s2ci(), psMtl1_s3ci(), -psMtl1_s1mi(), psMtl1_s2mi(), psMtl1_s3mi(), +bool D3DPhongMaterial::isBumpMap() { + return map[BUMP] ? true : false; +} -psMtl1_b1ni(), psMtl1_b2ni(), psMtl1_b3ni(), -psMtl1_b1ti(), psMtl1_b2ti(), psMtl1_b3ti(), -psMtl1_b1ci(), psMtl1_b2ci(), psMtl1_b3ci(), -psMtl1_b1mi(), psMtl1_b2mi(), psMtl1_b3mi(); +bool D3DPhongMaterial::isSpecularMap() { + return map[SPECULAR] ? true : false; +} -class D3DPhongShader { -public: - D3DPhongShader(IDirect3DDevice9 *dev); - virtual ~D3DPhongShader(); - IDirect3DVertexShader9 *getVertexShader(); - int getBumpMode(bool isBumpMap); - int getSpecularMode(bool isSpecularMap, bool isSpecularColor); - HRESULT setPixelShader(int numLights, int specularMode, int bumpMode, int selfIllumMode); +bool D3DPhongMaterial::isSelfIllumMap() { + return map[SELFILLUMINATION] ? true : false; +} -static const int SelfIlllumTotal = 2; -static const int maxLights = 3; +bool D3DPhongMaterial::isSpecularColor() { + return specularColorSet; +} -private: - IDirect3DDevice9 *device; - IDirect3DVertexShader9 *vertexShader; - IDirect3DPixelShader9 *pixelShader0, *pixelShader0_si; - IDirect3DPixelShader9 *pixelShaders[SelfIlllumTotal][BumpTotal][SpecTotal][maxLights]; -}; +IDirect3DBaseTexture9 * D3DPhongMaterial::getMap(int type) { + // Within the range of DIFFUSE, SPECULAR, BUMP, SELFILLUMINATION + if (type >= 0 && type <= 3) { + return map[type]; + } + cerr << "D3DPhongMaterial::getMap -- type is out of range - type = " << type << endl; + return NULL; +} -#endif /* D3DPHONGSHADER_H */ \ No newline at end of file +void D3DPhongMaterial::setMap(int mapID, IDirect3DBaseTexture9 *texMap) { + // Within the range of DIFFUSE, SPECULAR, BUMP, SELFILLUMINATION + if (mapID >= 0 && mapID <= 3) { + map[mapID] = texMap; + } else { + cerr << "D3DPhongMaterial::getMap -- mapID is out of range - mapID = " << mapID << endl; + } +} \ No newline at end of file diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongShader.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongShader.h index efe080f7d5..d397cf751f 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongShader.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongShader.h @@ -39,10 +39,11 @@ #define VSR_WORLDMATRIX 30 // PSR implies Pixel Shader Registers -// we have 32 constants for ps 2.0 +// we have 224 float constants for ps 3.0 #define PSR_DIFFUSECOLOR 0 #define PSR_SPECULARCOLOR 1 -#define PSR_LIGHTCOLOR 4 +#define PSR_LIGHTCOLOR 4 // 3 lights + 2 reserve +#define PSR_LIGHT_ATTENUATION 9 // 3 lights + 2 reserve // SR implies Sampler Registers #define SR_DIFFUSEMAP 0 @@ -107,4 +108,3 @@ static const int maxLights = 3; }; #endif /* D3DPHONGSHADER_H */ - From 4d6dd6572642781ad5d89aa4d0bf918b2f081d11 Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Mon, 11 Mar 2019 09:16:32 +0100 Subject: [PATCH 18/23] Update D3DPhongMaterial.h --- .../main/native-prism-d3d/D3DPhongMaterial.h | 125 +++++------------- 1 file changed, 35 insertions(+), 90 deletions(-) diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h index 71a2c19ef8..060c482694 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DPhongMaterial.h @@ -23,93 +23,38 @@ * questions. */ -#include -#include "D3DPhongMaterial.h" - -using std::cout; -using std::cerr; -using std::endl; - -// Destructor definition -D3DPhongMaterial::~D3DPhongMaterial() { - context = NULL; - // The freeing of texture native resources is handled by its Java layer. - map[DIFFUSE] = NULL; - map[SPECULAR] = NULL; - map[BUMP] = NULL; - map[SELFILLUMINATION] = NULL; -} - -D3DPhongMaterial::D3DPhongMaterial(D3DContext *ctx) { - context = ctx; - diffuseColor[0] = 0; - diffuseColor[1] = 0; - diffuseColor[2] = 0; - diffuseColor[3] = 0; - specularColorSet = false; - specularColor[0] = 1; - specularColor[1] = 1; - specularColor[2] = 1; - specularColor[3] = 32; - map[DIFFUSE] = NULL; - map[SPECULAR] = NULL; - map[BUMP] = NULL; - map[SELFILLUMINATION] = NULL; -} - -void D3DPhongMaterial::setDiffuseColor(float r, float g, float b, float a) { - diffuseColor[0] = r; - diffuseColor[1] = g; - diffuseColor[2] = b; - diffuseColor[3] = a; -} - -float * D3DPhongMaterial::getDiffuseColor() { - return diffuseColor; -} - -void D3DPhongMaterial::setSpecularColor(bool set, float r, float g, float b, float a) { - specularColorSet = set; - specularColor[0] = r; - specularColor[1] = g; - specularColor[2] = b; - specularColor[3] = a; -} - -float * D3DPhongMaterial::getSpecularColor() { - return specularColor; -} - -bool D3DPhongMaterial::isBumpMap() { - return map[BUMP] ? true : false; -} - -bool D3DPhongMaterial::isSpecularMap() { - return map[SPECULAR] ? true : false; -} - -bool D3DPhongMaterial::isSelfIllumMap() { - return map[SELFILLUMINATION] ? true : false; -} - -bool D3DPhongMaterial::isSpecularColor() { - return specularColorSet; -} - -IDirect3DBaseTexture9 * D3DPhongMaterial::getMap(int type) { - // Within the range of DIFFUSE, SPECULAR, BUMP, SELFILLUMINATION - if (type >= 0 && type <= 3) { - return map[type]; - } - cerr << "D3DPhongMaterial::getMap -- type is out of range - type = " << type << endl; - return NULL; -} - -void D3DPhongMaterial::setMap(int mapID, IDirect3DBaseTexture9 *texMap) { - // Within the range of DIFFUSE, SPECULAR, BUMP, SELFILLUMINATION - if (mapID >= 0 && mapID <= 3) { - map[mapID] = texMap; - } else { - cerr << "D3DPhongMaterial::getMap -- mapID is out of range - mapID = " << mapID << endl; - } -} \ No newline at end of file +#ifndef D3DPHONGMATERIAL_H +#define D3DPHONGMATERIAL_H + +#include "D3DContext.h" + +// See MaterialPhong.h, MaterialPhongShaders.h + +#define DIFFUSE 0 +#define SPECULAR 1 +#define BUMP 2 +#define SELFILLUMINATION 3 + +class D3DPhongMaterial { +public: + D3DPhongMaterial(D3DContext *pCtx); + virtual ~D3DPhongMaterial(); + void setDiffuseColor(float r, float g, float b, float a); + float *getDiffuseColor(); + void setSpecularColor(bool set, float r, float g, float b, float a); + float *getSpecularColor(); + void setMap(int mapID, IDirect3DBaseTexture9 *texMap); + bool isBumpMap(); + bool isSpecularMap(); + bool isSpecularColor(); + bool isSelfIllumMap(); + IDirect3DBaseTexture9 * getMap(int type); + +private: + D3DContext *context; + float diffuseColor[4], specularColor[4]; + IDirect3DBaseTexture9 *map[4]; + bool specularColorSet; +}; + +#endif /* D3DPHONGMATERIAL_H */ From 196d0cf085189a24df8fb4b4ecc77efff2a8b026 Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Wed, 13 Mar 2019 15:53:21 +0100 Subject: [PATCH 19/23] ES2 Attenuation-logic changes --- .idea/misc.xml | 4 +- .../sun/javafx/scene/PointLightHelper.java | 1 - .../com/sun/prism/es2/glsl/main.vert | 22 ++------- .../com/sun/prism/es2/glsl/main1Light.frag | 43 +++++++++-------- .../com/sun/prism/es2/glsl/main2Lights.frag | 38 +++++---------- .../com/sun/prism/es2/glsl/main3Lights.frag | 46 +++++-------------- 6 files changed, 52 insertions(+), 102 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index bce43c2594..6548e9d6d2 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - + - \ No newline at end of file + diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/scene/PointLightHelper.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/scene/PointLightHelper.java index d22a2ffe95..098b4f7cf8 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/scene/PointLightHelper.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/scene/PointLightHelper.java @@ -76,4 +76,3 @@ public interface PointLightAccessor { } } - diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main.vert b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main.vert index 884dcd29e2..f950e59bcb 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main.vert +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main.vert @@ -35,7 +35,7 @@ attribute vec4 tangent; struct Light { vec4 pos; vec3 color; - vec4 atten; + vec4 atten; }; //3 lights used @@ -44,10 +44,6 @@ uniform Light lights[3]; varying vec4 lightTangentSpacePositions[3]; varying vec2 oTexCoords; varying vec3 eyePos; -//FalcoTheBold - making worldPos reachable for other shaders -//varying vec4 worldPos; -//FalcoTheBold - attenuation distance calculation -//varying float dist; vec3 getLocalVector(vec3 global, vec3 tangentFrame[3]) { return vec3( dot(global,tangentFrame[1]), dot(global,tangentFrame[2]), dot(global,tangentFrame[0]) ); @@ -55,15 +51,12 @@ vec3 getLocalVector(vec3 global, vec3 tangentFrame[3]) { void main() { - vec3 tangentFrame[3]; - - //FalcoTheBold - Old: make worldPosition available for other shaders for the moment - //worldPos = worldMatrix * vec4(pos, 1.0); + vec3 tangentFrame[3]; vec4 worldPos = worldMatrix * vec4(pos, 1.0); // Note: The breaking of a vector and scale computation statement into - // 2 separate statements is intentional to workaround a shader - // compiler bug on the Freescale iMX6 platform. See RT-37789 for details. + // 2 separate statements is intentional to workaround a shader + // compiler bug on the Freescale iMX6 platform. See RT-37789 for details. vec3 t1 = tangent.xyz * tangent.yzx; t1 *= 2.0; vec3 t2 = tangent.zxy * tangent.www; @@ -80,9 +73,7 @@ void main() tangentFrame[2] = vec3(r1.z, r2.y, t4.x); tangentFrame[2] *= (tangent.w>=0.0) ? 1.0 : -1.0; - mat3 sWorldMatrix = mat3(worldMatrix[0].xyz, - worldMatrix[1].xyz, - worldMatrix[2].xyz); + mat3 sWorldMatrix = mat3(worldMatrix[0].xyz, worldMatrix[1].xyz, worldMatrix[2].xyz); //Translate the tangent frame to world space. tangentFrame[0] = sWorldMatrix * tangentFrame[0]; @@ -107,7 +98,4 @@ void main() //Send texcoords to Pixel Shader and calculate vertex position. oTexCoords = texCoords; gl_Position = mvpMatrix * vec4(pos,1.0); - - //FalcoTheBold - ToDo: prepare calculation for light-position relative to vertex-position in vertex-shader - //dist = lights[x].pos.xyz - worldPos.xyz; } diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag index e0880eca00..ee10202d80 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag @@ -55,7 +55,7 @@ vec4 apply_selfIllum(); struct Light { vec4 pos; vec3 color; - vec4 atten; + vec4 atten; }; uniform vec3 ambientColor; @@ -63,35 +63,34 @@ uniform Light lights[3]; varying vec3 eyePos; varying vec4 lightTangentSpacePositions[3]; -//FalcoTheBold - made worldPos public attribute -//varying vec4 worldPos; void main() { - gl_FragColor = vec4(0.0,0.0,0.0,1.0); - vec4 diffuse = apply_diffuse(); + float dist = (lights[0].pos.xyz - gl_Position); + if(dist <= lights[0].atten.range){ + gl_FragColor = vec4(0.0,0.0,0.0,1.0); + vec4 diffuse = apply_diffuse(); - if (diffuse.a == 0.0) discard; + if (diffuse.a == 0.0) discard; - vec3 n = apply_normal(); + vec3 n = apply_normal(); - vec3 d = vec3(0.0); - vec3 s = vec3(0.0); + vec3 d = vec3(0.0); + vec3 s = vec3(0.0); - vec3 refl = reflect(normalize(eyePos), n); - vec4 specular = apply_specular(); - float power = specular.a; + vec3 refl = reflect(normalize(eyePos), n); + vec4 specular = apply_specular(); + float power = specular.a; - vec3 l = normalize(lightTangentSpacePositions[0].xyz); - d = clamp(dot(n,l), 0.0, 1.0)*(lights[0].color).rgb; - s = pow(clamp(dot(-refl, l), 0.0, 1.0), power)*lights[0].color.rgb; - - //FalcoTheBold - added attenuation calculation for a single light - float dist = (lights[0].pos.xyz - gl_Position) / lights[0].atten.range; - float att = 1.0 / (lights[0].atten.ca + lights[0].atten.la * dist + lights[0].atten.qa * (dist * dist))); + vec3 l = normalize(lightTangentSpacePositions[0].xyz); + d = clamp(dot(n,l), 0.0, 1.0)*(lights[0].color).rgb; + s = pow(clamp(dot(-refl, l), 0.0, 1.0), power)*lights[0].color.rgb; - vec3 rez = (ambientColor+d) * (att * (diffuse.xyz + s*specular.rgb)); - rez += apply_selfIllum().xyz; + float att = 1.0 / (lights[0].atten.ca + lights[0].atten.la * dist + lights[0].atten.qa * (dist * dist))); - gl_FragColor = vec4(clamp(rez, 0.0, 1.0) , diffuse.a); + vec3 rez = (ambientColor+d) * (att * (diffuse.xyz + s*specular.rgb)); + rez += apply_selfIllum().xyz; + + gl_FragColor = vec4(clamp(rez, 0.0, 1.0) , diffuse.a); + } } diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag index fe4816c40b..2dbc8c89d6 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag @@ -55,7 +55,7 @@ vec4 apply_selfIllum(); struct Light { vec4 pos; vec3 color; - vec4 atten; + vec4 atten; }; uniform vec3 ambientColor; @@ -63,8 +63,6 @@ uniform Light lights[3]; varying vec3 eyePos; varying vec4 lightTangentSpacePositions[3]; -//FalcoTheBold - made worldPos public attribute -//varying vec4 worldPos; void main() { @@ -81,29 +79,17 @@ void main() vec3 refl = reflect(normalize(eyePos), n); vec4 specular = apply_specular(); float power = specular.a; - - //FalcoTheBold - float att; - float dist; - - vec3 l = normalize(lightTangentSpacePositions[0].xyz); - d = clamp(dot(n,l), 0.0, 1.0)*(lights[0].color).rgb; - s = pow(clamp(dot(-refl, l), 0.0, 1.0), power)*lights[0].color.rgb; - - //FalcoTheBold - added attenuation for light nr.1 - dist = (lights[0].pos.xyz - gl_Position) / lights[0].atten.range; - att = 1.0 / (lights[0].atten.ca + lights[0].atten.la * dist + lights[0].atten.qa * (dist * dist))); - - l = normalize(lightTangentSpacePositions[1].xyz); - d += clamp(dot(n,l), 0.0, 1.0)*(lights[1].color).rgb; - s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[1].color.rgb; - - //FalcoTheBold - added attenuation for light nr.2 - dist = (lights[1].pos.xyz - gl_Position) / lights[1].atten.range; - att += 1.0 / (lights[1].atten.ca + lights[1].atten.la * dist + lights[1].atten.qa * (dist * dist))); - - vec3 rez = (ambientColor+d) * (att * (diffuse.xyz + s*specular.rgb)); - rez += apply_selfIllum().xyz; + for(int i=0;i<2;++i){ + float dist = (lights[i].pos.xyz - gl_Position); + if(dist <= lights[i].atten.range){ + vec3 l = normalize(lightTangentSpacePositions[i].xyz); + d += clamp(dot(n,l), 0.0, 1.0)*(lights[i].color).rgb; + s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[i].color.rgb; + float att = 1.0 / (lights[i]].atten.ca + lights[i].atten.la * dist + lights[i].atten.qa * (dist * dist))); + vec3 rez = (ambientColor+d) * (att * (diffuse.xyz + s*specular.rgb)); + } + } + rez += apply_selfIllum().xyz; gl_FragColor = vec4(clamp(rez, 0.0, 1.0) , diffuse.a); } diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag index fe8cf2a80d..dad45555cf 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag @@ -55,7 +55,7 @@ vec4 apply_selfIllum(); struct Light { vec4 pos; vec3 color; - vec4 atten; + vec4 atten; }; uniform vec3 ambientColor; @@ -63,8 +63,6 @@ uniform Light lights[3]; varying vec3 eyePos; varying vec4 lightTangentSpacePositions[3]; -//FalcoTheBold - made worldPos public attribute -//varying vec4 worldPos; void main() { @@ -81,37 +79,17 @@ void main() vec3 refl = reflect(normalize(eyePos), n); vec4 specular = apply_specular(); float power = specular.a; - - //FalcoTheBold - float att; - float dist; - - vec3 l = normalize(lightTangentSpacePositions[0].xyz); - d = clamp(dot(n,l), 0.0, 1.0)*(lights[0].color).rgb; - s = pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[0].color.rgb; - - //FalcoTheBold - added attenuation for light nr.1 - dist = (lights[0].pos.xyz - gl_Position) / lights[0].atten.range; - att = 1.0 / (lights[0].atten.ca + lights[0].atten.la * dist + lights[0].atten.qa * (dist * dist))); - - l = normalize(lightTangentSpacePositions[1].xyz); - d += clamp(dot(n,l), 0.0, 1.0)*(lights[1].color).rgb; - s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[1].color.rgb; - - //FalcoTheBold - added attenuation for light nr.2 - dist = (lights[1].pos.xyz - gl_Position) / lights[1].atten.range; - att += 1.0 / (lights[1].atten.ca + lights[1].atten.la * dist + lights[1].atten.qa * (dist * dist))); - - l = normalize(lightTangentSpacePositions[2].xyz); - d += clamp(dot(n,l), 0.0, 1.0)*(lights[2].color).rgb; - s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[2].color.rgb; - - //FalcoTheBold - added attenuation for light nr.3 - dist = (lights[2].pos.xyz - gl_Position) / lights[2].atten.range; - att += 1.0 / (lights[2].atten.ca + lights[2].atten.la * dist + lights[2].atten.qa * (dist * dist))); - - vec3 rez = (ambientColor+d) * (att * (diffuse.xyz + s*specular.rgb)); - rez += apply_selfIllum().xyz; + for(int i=0;i<3;++i){ + float dist = (lights[i].pos.xyz - gl_Position); + if(dist <= lights[i].atten.range){ + vec3 l = normalize(lightTangentSpacePositions[i].xyz); + d += clamp(dot(n,l), 0.0, 1.0)*(lights[i].color).rgb; + s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[i].color.rgb; + float att = 1.0 / (lights[i]].atten.ca + lights[i].atten.la * dist + lights[i].atten.qa * (dist * dist))); + vec3 rez = (ambientColor+d) * (att * (diffuse.xyz + s*specular.rgb)); + } + } + rez += apply_selfIllum().xyz; gl_FragColor = vec4(clamp(rez, 0.0, 1.0) , diffuse.a); } From 58be282b30a0a1fedeb3974aa82ed79d619e15b9 Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Thu, 14 Mar 2019 15:09:29 +0100 Subject: [PATCH 20/23] Formatting changes - Tabs to spaces - line at end of sources - removal of "Falco"-comments - changed policy of line separator --- .../com/sun/javafx/sg/prism/NGPointLight.java | 2 +- .../com/sun/javafx/sg/prism/NGShape3D.java | 2 +- .../src/main/java/com/sun/prism/MeshView.java | 3 +-- .../java/com/sun/prism/d3d/D3DContext.java | 2 +- .../java/com/sun/prism/es2/ES2Context.java | 10 +++++----- .../main/java/com/sun/prism/es2/ES2Light.java | 18 +++++++++--------- .../java/com/sun/prism/es2/ES2MeshView.java | 7 ++----- .../main/java/com/sun/prism/es2/GLContext.java | 6 ------ .../src/main/native-prism-d3d/hlsl/psMath.h | 2 +- .../src/main/native-prism-es2/GLContext.c | 18 +++++------------- 10 files changed, 26 insertions(+), 44 deletions(-) diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java index 1c125b1928..66303d2092 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGPointLight.java @@ -107,4 +107,4 @@ public void setMaxRange(double maxRange) { this.maxRange = maxRange < 0 ? 0 : maxRange; visualsChanged(); } -} \ No newline at end of file +} diff --git a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java index 98ccc27bb9..80cac380f5 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java +++ b/modules/javafx.graphics/src/main/java/com/sun/javafx/sg/prism/NGShape3D.java @@ -228,4 +228,4 @@ public void release() { // TODO: 3D - Need to release native resources // material, mesh and meshview have native backing that need clean up. } -} \ No newline at end of file +} diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java index ab12b7a6dc..d831d37d23 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/MeshView.java @@ -46,8 +46,7 @@ public interface MeshView { public void setAmbientLight(float r, float g, float b); - public void setPointLight(int index, - float x, float y, float z, + 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); diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java index a4e6b347b9..e6ba86ffc1 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/d3d/D3DContext.java @@ -608,4 +608,4 @@ public void blit(RTTexture srcRTT, RTTexture dstRTT, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1); } -} \ No newline at end of file +} diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Context.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Context.java index 3f13c08da7..8dd3994d34 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Context.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Context.java @@ -448,11 +448,11 @@ void setWireframe(long nativeHandle, boolean wireframe) { void setAmbientLight(long nativeHandle, float r, float g, float b) { glContext.setAmbientLight(nativeHandle, r, g, b); } - - /* - * FacloTheBold: - new operator, added parameters for attenuation coefficients - */ - void setPointLight(long nativeHandle, int index, float x, float y, float z, float r, float g, float b, float w, float ra, float ca, float la, float qa) { + + /* + * FacloTheBold: - new operator, added parameters for attenuation coefficients + */ + void setPointLight(long nativeHandle, int index, float x, float y, float z, float r, float g, float b, float w, float ra, float ca, float la, float qa) { glContext.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, ra, ca, la, qa); } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Light.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Light.java index 220009c9d3..1fd58272fa 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Light.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Light.java @@ -32,14 +32,14 @@ class ES2Light { float x, y, z = 0; float r, g, b, w = 1; - float range, ca = 1.0f; - float la, qa = 0.0f; + float range, ca = 1.0f; + float la, qa = 0.0f; ES2Light(float ix, float iy, float iz, float ir, float ig, float ib, float iw) { - this(ix, iy, iz, ir, ig, ib, iw, 1.0f, 1.0f, 0.0f, 0.0f); + this(ix, iy, iz, ir, ig, ib, iw, 1.0f, 1.0f, 0.0f, 0.0f); } - - ES2Light(float ix, float iy, float iz, float ir, float ig, float ib, float iw, float irange, float ica, float ila, float iqa) { + + ES2Light(float ix, float iy, float iz, float ir, float ig, float ib, float iw, float irange, float ica, float ila, float iqa) { x = ix; y = iy; z = iz; @@ -47,9 +47,9 @@ class ES2Light { g = ig; b = ib; w = iw; - range = irange; - ca = ica; - la = ila; - qa = iqa; + range = irange; + ca = ica; + la = ila; + qa = iqa; } } diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java index 912dbcb2fa..e4f8dd01d4 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2MeshView.java @@ -99,10 +99,7 @@ float getAmbientLightGreen() { float getAmbientLightBlue() { return ambientLightBlue; } - - /* - * FalcoTheBold - transferred expressions from the old operator to the new overloaded operator - */ + @Override 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) { @@ -111,7 +108,7 @@ public void setPointLight(int index, float x, float y, float z, float r, float g lights[index] = new ES2Light(x, y, z, r, g, b, w, maxRange, ca, la, qa); context.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, maxRange, ca, la, qa); } - } + } ES2Light[] getPointLights() { return lights; diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLContext.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLContext.java index 67cba39ae4..b394040da0 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLContext.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/GLContext.java @@ -251,9 +251,6 @@ private static native void nSetWireframe(long nativeCtxInfo, long nativeMeshView boolean wireframe); private static native void nSetAmbientLight(long nativeCtxInfo, long nativeMeshViewInfo, float r, float g, float b); - /* - * FalcoTheBold: - added additional parameters for the attenuation coefficients - */ private static native void nSetPointLight(long nativeCtxInfo, long nativeMeshViewInfo, int index, float x, float y, float z, float r, float g, float b, float w, float ra, float ca, float la, float qa); private static native void nRenderMeshView(long nativeCtxInfo, long nativeMeshViewInfo); @@ -811,9 +808,6 @@ void setAmbientLight(long nativeMeshViewInfo, float r, float g, float b) { nSetAmbientLight(nativeCtxInfo, nativeMeshViewInfo, r, g, b); } - /* - * FalcoTheBold: - added parameters for the attenuation coefficients - */ void setPointLight(long nativeMeshViewInfo, int index, float x, float y, float z, float r, float g, float b, float w, float ra, float ca, float la, float qa) { nSetPointLight(nativeCtxInfo, nativeMeshViewInfo, index, x, y, z, r, g, b, w, ra, ca, la, qa); } diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h index 10aa582976..f65de0bcd6 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/hlsl/psMath.h @@ -77,4 +77,4 @@ void phong( s += pow(saturate(dot(-refl, l)), power) * gLightColor[i].xyz * attn; } } -} \ No newline at end of file +} diff --git a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c index 4ccab8c2ed..b009d2503e 100644 --- a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c +++ b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c @@ -2083,10 +2083,6 @@ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetMap pmInfo->maps[mapType] = texID; } -/* - * FalcoTheBold: modified MeshViewInfo to hold datas of the attenuation values - */ -/* * Class: com_sun_prism_es2_GLContext * Method: nCreateES2MeshView * Signature: (JJ)J @@ -2125,7 +2121,7 @@ JNIEXPORT jlong JNICALL Java_com_sun_prism_es2_GLContext_nCreateES2MeshView meshViewInfo->pointLightPosition[1] = 0; meshViewInfo->pointLightPosition[2] = 0; meshViewInfo->pointLightWeight = 0; - meshViewInfo->pointLightRange = 1; + meshViewInfo->pointLightRange = 1; meshViewInfo->pointLightAttenuation[0] = 1; meshViewInfo->pointLightAttenuation[1] = 0; meshViewInfo->pointLightAttenuation[2] = 0; @@ -2265,9 +2261,6 @@ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetAmbientLight meshViewInfo->ambientLightColor[2] = b; } -/* - * FalcoTheBold: modified native operator to add attenuation coefficients - */ /* * Class: com_sun_prism_es2_GLContext * Method: nSetPointLight @@ -2291,10 +2284,10 @@ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetPointLight meshViewInfo->pointLightColor[1] = g; meshViewInfo->pointLightColor[2] = b; meshViewInfo->pointLightWeight = w; - meshViewInfo->pointLightRange = range; - meshViewInfo->pointLightAttenuation[0] = ca; - meshViewInfo->pointLightAttenuation[1] = la; - meshViewInfo->pointLightAttenuation[2] = qa; + meshViewInfo->pointLightRange = range; + meshViewInfo->pointLightAttenuation[0] = ca; + meshViewInfo->pointLightAttenuation[1] = la; + meshViewInfo->pointLightAttenuation[2] = qa; } /* @@ -2353,4 +2346,3 @@ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nRenderMeshView ctxInfo->glBindBuffer(GL_ARRAY_BUFFER, 0); ctxInfo->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } - From 7261cfca905450d9919545f3e90d7c217ff5bb3c Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Thu, 14 Mar 2019 16:19:25 +0100 Subject: [PATCH 21/23] Update GLContext.c --- modules/javafx.graphics/src/main/native-prism-es2/GLContext.c | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c index b009d2503e..6e1c30831b 100644 --- a/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c +++ b/modules/javafx.graphics/src/main/native-prism-es2/GLContext.c @@ -2083,6 +2083,7 @@ JNIEXPORT void JNICALL Java_com_sun_prism_es2_GLContext_nSetMap pmInfo->maps[mapType] = texID; } +/* * Class: com_sun_prism_es2_GLContext * Method: nCreateES2MeshView * Signature: (JJ)J From a44f13fc74675e008d78fb7088730a8d8c8ffea5 Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Mon, 18 Mar 2019 11:48:16 +0100 Subject: [PATCH 22/23] Reworked shader-sources --- .../src/main/java/com/sun/prism/es2/ES2Context.java | 3 --- .../javafx.graphics/src/main/native-prism-d3d/D3DLight.h | 2 -- .../resources/com/sun/prism/es2/glsl/main1Light.frag | 9 ++++----- .../resources/com/sun/prism/es2/glsl/main2Lights.frag | 9 +++++---- .../resources/com/sun/prism/es2/glsl/main3Lights.frag | 9 +++++---- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Context.java b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Context.java index 8dd3994d34..eccad0ab55 100644 --- a/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Context.java +++ b/modules/javafx.graphics/src/main/java/com/sun/prism/es2/ES2Context.java @@ -449,9 +449,6 @@ void setAmbientLight(long nativeHandle, float r, float g, float b) { glContext.setAmbientLight(nativeHandle, r, g, b); } - /* - * FacloTheBold: - new operator, added parameters for attenuation coefficients - */ void setPointLight(long nativeHandle, int index, float x, float y, float z, float r, float g, float b, float w, float ra, float ca, float la, float qa) { glContext.setPointLight(nativeHandle, index, x, y, z, r, g, b, w, ra, ca, la, qa); } diff --git a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h index a601af1f29..7e85301b9e 100644 --- a/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h +++ b/modules/javafx.graphics/src/main/native-prism-d3d/D3DLight.h @@ -47,5 +47,3 @@ class D3DLight { }; #endif /* D3DLIGHT_H */ - - diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag index ee10202d80..084af33b81 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main1Light.frag @@ -83,12 +83,11 @@ void main() float power = specular.a; vec3 l = normalize(lightTangentSpacePositions[0].xyz); - d = clamp(dot(n,l), 0.0, 1.0)*(lights[0].color).rgb; - s = pow(clamp(dot(-refl, l), 0.0, 1.0), power)*lights[0].color.rgb; + float att = 1.0 / (lights[0].atten.ca + lights[0].atten.la * dist + lights[0].atten.qa * (dist * dist)); + d = clamp(dot(n,l), 0.0, 1.0)*(lights[0].color).rgb * att; + s = pow(clamp(dot(-refl, l), 0.0, 1.0), power)*lights[0].color.rgb * att; - float att = 1.0 / (lights[0].atten.ca + lights[0].atten.la * dist + lights[0].atten.qa * (dist * dist))); - - vec3 rez = (ambientColor+d) * (att * (diffuse.xyz + s*specular.rgb)); + vec3 rez = (ambientColor+d) * (diffuse.xyz + s*specular.rgb); rez += apply_selfIllum().xyz; gl_FragColor = vec4(clamp(rez, 0.0, 1.0) , diffuse.a); diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag index 2dbc8c89d6..800579bbe0 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag @@ -75,6 +75,7 @@ void main() vec3 d = vec3(0.0); vec3 s = vec3(0.0); + vec3 rez = vec3(0.0); vec3 refl = reflect(normalize(eyePos), n); vec4 specular = apply_specular(); @@ -84,10 +85,10 @@ void main() float dist = (lights[i].pos.xyz - gl_Position); if(dist <= lights[i].atten.range){ vec3 l = normalize(lightTangentSpacePositions[i].xyz); - d += clamp(dot(n,l), 0.0, 1.0)*(lights[i].color).rgb; - s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[i].color.rgb; - float att = 1.0 / (lights[i]].atten.ca + lights[i].atten.la * dist + lights[i].atten.qa * (dist * dist))); - vec3 rez = (ambientColor+d) * (att * (diffuse.xyz + s*specular.rgb)); + float att = 1.0 / (lights[i]].atten.ca + lights[i].atten.la * dist + lights[i].atten.qa * (dist * dist)); + d += clamp(dot(n,l), 0.0, 1.0)*(lights[i].color).rgb * att; + s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[i].color.rgb *att; + rez = (ambientColor+d) * (diffuse.xyz + s*specular.rgb); } } rez += apply_selfIllum().xyz; diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag index dad45555cf..669ce5e6d1 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag @@ -75,6 +75,7 @@ void main() vec3 d = vec3(0.0); vec3 s = vec3(0.0); + vec3 rez = vec3(0.0); vec3 refl = reflect(normalize(eyePos), n); vec4 specular = apply_specular(); @@ -84,10 +85,10 @@ void main() float dist = (lights[i].pos.xyz - gl_Position); if(dist <= lights[i].atten.range){ vec3 l = normalize(lightTangentSpacePositions[i].xyz); - d += clamp(dot(n,l), 0.0, 1.0)*(lights[i].color).rgb; - s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[i].color.rgb; - float att = 1.0 / (lights[i]].atten.ca + lights[i].atten.la * dist + lights[i].atten.qa * (dist * dist))); - vec3 rez = (ambientColor+d) * (att * (diffuse.xyz + s*specular.rgb)); + float att = 1.0 / (lights[i]].atten.ca + lights[i].atten.la * dist + lights[i].atten.qa * (dist * dist)); + d += clamp(dot(n,l), 0.0, 1.0)*(lights[i].color).rgb * att; + s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[i].color.rgb *att; + rez = (ambientColor+d) * (diffuse.xyz + s*specular.rgb); } } rez += apply_selfIllum().xyz; From 354776afb3d43d62cc0907241e1a86492cb869dc Mon Sep 17 00:00:00 2001 From: FalcoTheBold Date: Tue, 19 Mar 2019 16:01:06 +0100 Subject: [PATCH 23/23] Shader-sources: removed extra brackets --- .../src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag | 2 +- .../src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag index 800579bbe0..3cc34c5c98 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main2Lights.frag @@ -85,7 +85,7 @@ void main() float dist = (lights[i].pos.xyz - gl_Position); if(dist <= lights[i].atten.range){ vec3 l = normalize(lightTangentSpacePositions[i].xyz); - float att = 1.0 / (lights[i]].atten.ca + lights[i].atten.la * dist + lights[i].atten.qa * (dist * dist)); + float att = 1.0 / (lights[i].atten.ca + lights[i].atten.la * dist + lights[i].atten.qa * (dist * dist)); d += clamp(dot(n,l), 0.0, 1.0)*(lights[i].color).rgb * att; s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[i].color.rgb *att; rez = (ambientColor+d) * (diffuse.xyz + s*specular.rgb); diff --git a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag index 669ce5e6d1..6cf25813c4 100644 --- a/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag +++ b/modules/javafx.graphics/src/main/resources/com/sun/prism/es2/glsl/main3Lights.frag @@ -85,7 +85,7 @@ void main() float dist = (lights[i].pos.xyz - gl_Position); if(dist <= lights[i].atten.range){ vec3 l = normalize(lightTangentSpacePositions[i].xyz); - float att = 1.0 / (lights[i]].atten.ca + lights[i].atten.la * dist + lights[i].atten.qa * (dist * dist)); + float att = 1.0 / (lights[i].atten.ca + lights[i].atten.la * dist + lights[i].atten.qa * (dist * dist)); d += clamp(dot(n,l), 0.0, 1.0)*(lights[i].color).rgb * att; s += pow(clamp(dot(-refl, l), 0.0, 1.0), power) * lights[i].color.rgb *att; rez = (ambientColor+d) * (diffuse.xyz + s*specular.rgb);