summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorphil <[email protected]>2017-01-17 23:00:57 +1300
committerphil <[email protected]>2017-01-17 23:00:57 +1300
commit5af49b52b7367157613dac253c06ead0929b9942 (patch)
tree1f963b1c6ab314541738843ef6be06bdea7e6de4 /src
parent57180b6da144f70a85e376faedf581ee2352a304 (diff)
SimpleShaderAppearance now calculates max lights based on
gl_MaxVaryingVectors or fixes to 3 if version 120
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/jogamp/java3d/utils/shader/SimpleShaderAppearance.java44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/main/java/org/jogamp/java3d/utils/shader/SimpleShaderAppearance.java b/src/main/java/org/jogamp/java3d/utils/shader/SimpleShaderAppearance.java
index 2b7f2ce..1983b3b 100644
--- a/src/main/java/org/jogamp/java3d/utils/shader/SimpleShaderAppearance.java
+++ b/src/main/java/org/jogamp/java3d/utils/shader/SimpleShaderAppearance.java
@@ -78,13 +78,46 @@ import org.jogamp.vecmath.Vector4f;
public class SimpleShaderAppearance extends ShaderAppearance
{
- private static String versionString = "#version 120\n";
+ private static String versionString = "#version 100\n";
private static String outString = "varying";
private static String inString = "varying";
private static String fragColorDec = "";
private static String fragColorVar = "gl_FragColor";
private static String vertexAttributeInString = "attribute";
private static String texture2D = "texture2D";
+ private static String constMaxLights = " const int maxLights = (gl_MaxVaryingVectors - 6) / 3;\n";
+
+ // a wee discussion on the max varying versus lights issue
+ //https://www.khronos.org/opengles/sdk/docs/reference_cards/OpenGL-ES-2_0-Reference-card.pdf
+ //const mediump int gl_MaxVaryingVectors
+
+ //when given a 3 lights value, fragment
+ //Out of varying space. Mali-400 PP provides space for 12 varying vec4s, this shader uses 15 varying vec4s.
+
+ // when give 4
+ // shaderProgram = SimpleShaderAppearance shaderkey = 15
+ // shader = vertexProgram
+ //Detail Message
+ // --------------
+ // 0:1: L0006: Out of varying space. Mali-400 GP provides space for 16 varying vec4s, this shader uses 19 varying vec4s.
+ //fragment
+ //Out of varying space. Mali-400 PP provides space for 12 varying vec4s, this shader uses 18 varying vec4s.
+
+ // if (hasTexture)
+ // vertexProgram += outString + " vec2 glTexCoord0;\n";
+
+ //vertexProgram += outString + " vec3 ViewVec;\n";
+ //vertexProgram += outString + " vec3 N;\n";
+ //vertexProgram += outString + " vec4 A;\n";
+ //vertexProgram += outString + " vec4 C;\n";
+ //vertexProgram += outString + " vec3 emissive;\n";
+ //vertexProgram += outString + " vec4 lightsD[maxLights];\n";
+ //vertexProgram += outString + " vec3 lightsS[maxLights];\n";
+ //vertexProgram += outString + " vec3 lightsLightDir[maxLights];\n";
+ //vertexProgram += outString + " float shininess;\n";
+ // if shininess and glTexCoord are merged = 6 before lights each light = 3
+ // so 1 = 9!
+ // I've seen an 8! varying vec4 on a old android
public static void setVersionES100()
{
@@ -95,6 +128,7 @@ public class SimpleShaderAppearance extends ShaderAppearance
fragColorVar = "gl_FragColor";
vertexAttributeInString = "attribute";
texture2D = "texture2D";
+ constMaxLights = " const int maxLights = (gl_MaxVaryingVectors - 6) / 3;\n";
}
public static void setVersionES300()
@@ -106,6 +140,7 @@ public class SimpleShaderAppearance extends ShaderAppearance
fragColorVar = "glFragColor";
vertexAttributeInString = "in";
texture2D = "texture";
+ constMaxLights = " const int maxLights = (gl_MaxVaryingVectors - 6) / 3;\n";
}
public static void setVersion120()
@@ -117,6 +152,7 @@ public class SimpleShaderAppearance extends ShaderAppearance
fragColorVar = "gl_FragColor";
vertexAttributeInString = "attribute";
texture2D = "texture2D";
+ constMaxLights = " const int maxLights = 3;\n";//gl_MaxVaryingVectors does not exist
}
public static String alphaTestUniforms = "uniform int alphaTestEnabled;\n" + //
@@ -163,7 +199,7 @@ public class SimpleShaderAppearance extends ShaderAppearance
" };\n" + //
"\n" + //
" uniform int numberOfLights;\n" + //
- " const int maxLights = 3;\n" + //
+ constMaxLights + //
" uniform lightSource glLightSource[maxLights];\n"; //
private static HashMap<Integer, GLSLShaderProgram> shaderPrograms = new HashMap<Integer, GLSLShaderProgram>();
@@ -543,7 +579,7 @@ public class SimpleShaderAppearance extends ShaderAppearance
fragmentProgram += inString + " vec3 emissive;\n";
fragmentProgram += inString + " float shininess;\n";
- fragmentProgram += " const int maxLights = 3;\n";
+ fragmentProgram += constMaxLights;
fragmentProgram += inString + " vec4 lightsD[maxLights]; \n";
fragmentProgram += inString + " vec3 lightsS[maxLights]; \n";
fragmentProgram += inString + " vec3 lightsLightDir[maxLights]; \n";
@@ -673,6 +709,8 @@ public class SimpleShaderAppearance extends ShaderAppearance
vertexShaderSources.put(shaderProgram, vertexProgram);
fragmentShaderSources.put(shaderProgram, fragmentProgram);
+ //System.out.println(vertexProgram);
+ //System.out.println(fragmentProgram);
if (hasTexture)
{
if (texCoordGenModeObjLinear)