From 564f4d12d93813b5d680fc24d4f118c3886d96ed Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Tue, 20 Aug 2019 19:56:41 -0400
Subject: [PATCH] Parallax mapping!
---
ObjEditor.java | 12 ++++++
CameraPane.java | 48 +++++++++++++++++++----
GroupEditor.java | 5 ++
cMaterial.java | 13 ++++--
4 files changed, 65 insertions(+), 13 deletions(-)
diff --git a/CameraPane.java b/CameraPane.java
index 298bf09..e8611a1 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -1819,7 +1819,7 @@
display.modelParams7[0] = 0;
display.modelParams7[1] = 1000;
- display.modelParams7[2] = 0;
+ display.modelParams7[2] = material.parallax;
display.modelParams7[3] = 0;
//display.modelParams6[0] = 100; // criss de bug de bump
@@ -12593,7 +12593,7 @@
"PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
"PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
"PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
- "PARAM params7 = program.env[7];" + // noise power, opacity power
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
"PARAM options0 = program.env[63];" + // fog density, intensity, elevation
"PARAM options1 = program.env[62];" + // fog rgb color
"PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
@@ -12838,7 +12838,7 @@
"POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
// mar 2013 ??? "KIL alpha.a;" +
"MOV alpha, texSamp.aaaa;" + // y;" +
- "KIL alpha.a;" +
+ "KIL alpha.a;" + // not sure with parallax mapping
/*
"MUL temp.xy, temp, two;" +
"TXB bump, temp, texture[0], 2D;" +
@@ -12924,11 +12924,6 @@
"SUB bump0, bump0, half;" +
"ADD bump, bump, bump0;" +
- "MOV temp.x, texSamp.a;" +
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
- //"LRP texSamp0, params5.x, texSamp0, one;" +
- "MOV texSamp.a, temp.x;" +
-
// double-sided
/**/
(doublesided?"DP3 temp.z, normal, eye;" +
@@ -12958,6 +12953,41 @@
Normalize("U") +
// parallax mapping
+
+ "DP3 temp2.x, V, eye;" +
+ "DP3 temp2.y, U, eye;" +
+ "DP3 temp2.z, normal, eye;" +
+ "RCP temp2.z, temp2.z;" +
+
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
+ "RSQ temp2.w, temp2.w;" +
+ "RCP temp2.w, temp2.w;" +
+
+ "SUB temp2.w, temp2.w, half;" +
+// "SGE temp.x, temp2.w, eps.x;" +
+// "MUL temp2.w, temp2.w, temp.x;" +
+
+ //"MOV texSamp, U;" +
+
+ "MUL temp2.z, temp2.z, temp2.w;" +
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
+
+ "MUL temp2, temp2, temp2.z;" +
+
+ "MOV temp, fragment.texcoord[0];" +
+
+ "SUB temp, temp, temp2;" +
+
+ "TEX texSamp, temp, texture[0], 2D;" +
+ "POW texSamp.a, texSamp.a, params6.w;" + // punch through
+ "MOV alpha, texSamp.aaaa;" +
+
+// parallax mapping
+
+ "MOV temp.x, texSamp.a;" +
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
+ "MOV texSamp.a, temp.x;" +
//"MOV temp, fragment.texcoord[0];" +
//
@@ -13739,7 +13769,7 @@
/*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
/*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
/*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
//Object3D.cVector2[] vector2buffer;
diff --git a/GroupEditor.java b/GroupEditor.java
index f678dca..0ac356b 100644
--- a/GroupEditor.java
+++ b/GroupEditor.java
@@ -936,6 +936,8 @@
cGridBag currenttab;
//boolean added; // patch for jar
+ int totalcount = 0;
+
int tabcount = 0;
int colcount = 0;
int rowcount = 0;
@@ -974,6 +976,7 @@
}
AddTextureButton(path[0], path[1], path[2], ++texturecount, currenttab);
+ totalcount++;
if (++colcount >= columns)
{
@@ -999,6 +1002,8 @@
container.add(resourcecontainer);
Grafreed.ParseResources("textures", this);
+
+ // 935. System.out.println("Total = " + totalcount);
}
void SetupUI2(ObjEditor oe)
diff --git a/ObjEditor.java b/ObjEditor.java
index a9b5c11..3f3be5b 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -2682,6 +2682,12 @@
backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
colorSection.add(backlit);
+ cGridBag parallax = new cGridBag();
+ parallax.add(parallaxLabel = new JLabel("Parallax")); // , aConstraints);
+ parallaxLabel.setHorizontalAlignment(SwingConstants.TRAILING);
+ parallax.add(parallaxField = new cNumberSlider(this, 0.001, 0.5, -0.25)); // , aConstraints);
+ colorSection.add(parallax);
+
//panel.add(new JSeparator());
//panel.add(globalSection);
@@ -3733,6 +3739,7 @@
shadowField.setFloat(mat.shadow);
textureField.setFloat(mat.texture);
opacityField.setFloat(mat.opacity);
+ parallaxField.setFloat(mat.parallax + 0.25f);
fakedepthField.setFloat(mat.fakedepth);
shadowbiasField.setFloat(mat.shadowbias);
bumpField.setInteger(1); // dec 2013
@@ -4957,6 +4964,7 @@
current.shadow = (float) shadowField.getFloat();
current.texture = (float) textureField.getFloat();
current.opacity = (float) opacityField.getFloat();
+ current.parallax = (float) parallaxField.getFloat() - 0.25f;
current.fakedepth = (float) fakedepthField.getFloat();
current.shadowbias = (float) shadowbiasField.getFloat();
@@ -5011,6 +5019,8 @@
textureField.SetToolTipValue((mat.texture));
if (!Equal(opacityField.getFloat(), mat.opacity))
opacityField.SetToolTipValue((mat.opacity));
+ //if (!Equal(parallaxField.getFloat(), mat.parallax))
+ parallaxField.SetToolTipValue((mat.parallax));
if (!Equal(fakedepthField.getFloat(), mat.fakedepth))
fakedepthField.SetToolTipValue((mat.fakedepth));
if (!Equal(shadowbiasField.getFloat(), mat.shadowbias))
@@ -6267,6 +6277,8 @@
cNumberSlider textureField;
JLabel opacityLabel;
cNumberSlider opacityField;
+ JLabel parallaxLabel;
+ cNumberSlider parallaxField;
JLabel fakedepthLabel;
cNumberSlider fakedepthField;
JLabel shadowbiasLabel;
diff --git a/cMaterial.java b/cMaterial.java
index fe3d2ea..7f5463d 100644
--- a/cMaterial.java
+++ b/cMaterial.java
@@ -34,6 +34,7 @@
shadow = val;
texture = val;
opacity = val;
+ parallax = val;
fakedepth = val;
shadowbias = val;
}
@@ -71,6 +72,7 @@
shadow = mat.shadow;
texture = mat.texture;
opacity = mat.opacity;
+ parallax = mat.parallax;
fakedepth = mat.fakedepth;
shadowbias = mat.shadowbias;
@@ -105,16 +107,17 @@
shadow *= Factor(anchor.shadow, current.shadow);
texture *= Factor(anchor.texture, current.texture);
opacity *= Factor(anchor.opacity, current.opacity);
+// if (anchor.parallax == 0)
+// anchor.parallax = 0.001f;
+ //parallax *= Factor(anchor.parallax, current.parallax);
+ parallax = current.parallax;
fakedepth *= Factor(anchor.fakedepth, current.fakedepth);
shadowbias *= Factor(anchor.shadowbias, current.shadowbias);
}
float Factor(float anchor, float current)
{
- if (anchor <= 0)
- {
- assert anchor > 0;
- }
+ Grafreed.Assert(anchor > 0);
return current / anchor;
}
@@ -364,6 +367,8 @@
float sheen = 1f, subsurface = 0.001f, bump = 0.75f, aniso = 0.001f, anisoV = 0.001f;
float cameralight = 0.3f, diffuseness = 0.001f, shadow = 5f, texture = 1f, opacity = 1;
float fakedepth = 0.5f, shadowbias = 0.01f; // 0.001f;
+
+ float parallax = 0;
boolean multiply;
--
Gitblit v1.6.2