From 0f4fa9dc4191aaee9661c1e6d73725436ae64ac2 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Tue, 23 Jul 2019 03:30:10 -0400
Subject: [PATCH] Complete min shader.

---
 CameraPane.java |   68 ++++++++++++++++++++++++++++------
 1 files changed, 56 insertions(+), 12 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index ffbe72c..69d4882 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -12400,7 +12400,52 @@
         //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
 
         String program =
+                // Min shader
                 "!!ARBfp1.0\n" +
+                "PARAM zero123      = { 0.0, 1.0, 2.0, 1.25 };" +
+                "PARAM pow2      = { 0.5, 0.25, 0.125, 0.0 };" +
+                "PARAM one      = { 1.0, 1.0, 1.0, 1.0 };" +
+                "PARAM eps      = { 0.001, 0.001, 0.001, 1.0 };" +
+                "PARAM infinity  = { 100000000, 100000000, 100000000, 1.0 };" +
+                "TEMP temp;" +
+                "TEMP light;" +
+                "TEMP ndotl;" +
+                "TEMP normal;" +
+                "TEMP depth;" +
+                
+                "MAD normal, fragment.color, zero123.z, -zero123.y;" +
+                
+                "MOV light, state.light[0].position;" +
+                "DP3 ndotl.x, light, normal;" +
+
+                // shadow
+                "MOV temp, fragment.texcoord[1];" +
+                TextureFetch("depth", "temp", "1") +
+                //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
+                "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
+                
+
+                // No shadow when out of frustum
+                //"SGE temp.y, depth.z, zero123.y;" +
+                //"LRP temp.x, temp.y, zero123.y, temp.x;" +
+                
+                "MUL ndotl.x, ndotl.x, temp.x;" +
+                "MAX ndotl.x, ndotl.x, pow2.y;" +
+                
+                "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
+                "LRP temp, zero123.w, temp, one;" + // texture proportion
+                "MUL temp, temp, ndotl.x;" +
+                
+                "MUL temp, temp, zero123.z;" +
+                
+                "MOV temp.w, zero123.y;" + // reset alpha
+                
+                "MOV result.color, temp;" +
+                "END";
+        
+        String program2 =
+                "!!ARBfp1.0\n" +
+                
                 //"OPTION ARB_fragment_program_shadow;" +
                 "PARAM light2cam0   = program.env[10];" +
                 "PARAM light2cam1   = program.env[11];" +
@@ -12515,8 +12560,7 @@
                 "TEMP shininess;" +
                 "\n" +
                 "MOV texSamp, one;" +
-                //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
-
+                
                 "MOV mapgrid.x, one2048th.x;" +
                 "MOV temp, fragment.texcoord[1];" +
                 /*
@@ -12921,7 +12965,7 @@
                 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
                 "") +
 
-           // display shadow only (bump == 0)
+           // display shadow only (fakedepth == 0)
          "SUB temp.x, half.x, shadow.x;" +
          "MOV temp.y, -params5.z;" + // params6.x;" +
          "SLT temp.z, temp.y, -one2048th.x;" +
@@ -13353,20 +13397,20 @@
         return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
                 "SGE " + src + ".w, " + src + ".x, eps.x;" +
                 "SGE " + src + ".z, " + src + ".y, eps.x;" +
+                "SLT " + dest + ".x, " + src + ".x, one.x;" +
+                "SLT " + dest + ".y, " + src + ".y, one.x;" +
                 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
-                "SLT " + src + ".z, " + src + ".x, one.x;" +
-                "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
-                "SLT " + src + ".z, " + src + ".y, one.x;" +
-                "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
+                "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
+                "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
                 //"SWZ buffer, temp, w,w,w,w;";
-                "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
+                //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
                 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
                 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
                 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
-                "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
+                //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
 
-    //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
-    //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
+    //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
+    "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
     }
 
     String Shadow(String depth, String shadow)
@@ -13413,7 +13457,7 @@
                 "SLT temp.x, temp.x, zero.x;" + // shadoweps
                 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
 
-                // No shadow when out of frustrum
+                // No shadow when out of frustum
                 "SGE temp.x, " + depth + ".z, one.z;" +
                 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
                 "";

--
Gitblit v1.6.2