aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphil <[email protected]>2016-11-06 22:00:25 +1300
committerphil <[email protected]>2016-11-06 22:00:25 +1300
commitf3738c4c808b02f3cb1b5fc0d272047de6eddfe2 (patch)
tree775dc866f5c0c268e4ab6e80d7e64059f4471bb4
parent0ac05617e4442602e9468f4e1c7370085126bab5 (diff)
struct lightSource was always receiving all lights as enabled
Now it only receiving enabled lights and the variable enabled has been removed
-rw-r--r--src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java2
-rw-r--r--src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert1
-rw-r--r--src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert1
-rw-r--r--src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag1
-rw-r--r--src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert1
-rw-r--r--src/main/java/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.frag89
-rw-r--r--src/main/java/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.frag93
7 files changed, 89 insertions, 99 deletions
diff --git a/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java b/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java
index 8e97c77..513c939 100644
--- a/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java
+++ b/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/SimpleShaderAppearance.java
@@ -129,8 +129,8 @@ public class SimpleShaderAppearance extends ShaderAppearance
vertexProgram += " float shininess;\n";
vertexProgram += "};\n";
vertexProgram += "uniform material glFrontMaterial;\n";
+ vertexProgram += "struct lightSource\n";
vertexProgram += " {\n";
- vertexProgram += " int enabled;\n";
vertexProgram += " vec4 position;\n";
vertexProgram += " vec4 diffuse;\n";
vertexProgram += " vec4 specular;\n";
diff --git a/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert b/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert
index 354c004..e07965b 100644
--- a/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert
+++ b/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.vert
@@ -32,7 +32,6 @@ uniform material glFrontMaterial;
struct lightSource
{
- int enabled;
vec4 position;
vec4 diffuse;
vec4 specular;
diff --git a/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert b/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert
index 771afce..7470029 100644
--- a/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert
+++ b/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/gouraud.vert
@@ -71,7 +71,6 @@ uniform material glFrontMaterial;
struct lightSource
{
- int enabled;
vec4 position;
vec4 diffuse;
vec4 specular;
diff --git a/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag b/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag
index 7cb6388..40db2b4 100644
--- a/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag
+++ b/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/phong.frag
@@ -65,7 +65,6 @@ uniform material glFrontMaterial;
struct lightSource
{
- int enabled;
vec4 position;
vec4 diffuse;
vec4 specular;
diff --git a/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert b/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert
index 4c5f3c9..7b8ba97 100644
--- a/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert
+++ b/src/main/java/org/jdesktop/j3d/examples/gl2es2pipeline/simple.vert
@@ -71,7 +71,6 @@ uniform material glFrontMaterial;
struct lightSource
{
- int enabled;
vec4 position;
vec4 diffuse;
vec4 specular;
diff --git a/src/main/java/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.frag b/src/main/java/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.frag
index af65808..ec83557 100644
--- a/src/main/java/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.frag
+++ b/src/main/java/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2.frag
@@ -21,7 +21,6 @@ uniform material glFrontMaterial;
struct lightSource
{
- int enabled;
vec4 position;
vec4 diffuse;
vec4 specular;
@@ -44,52 +43,50 @@ void main()
for (int index = 0; index < numberOfLights; index++) // for all light sources
{
- if(glLightSource[index].enabled == 1)
+ if (0.0 == glLightSource[index].position.w) // directional light?
{
- if (0.0 == glLightSource[index].position.w) // directional light?
- {
- attenuation = 1.0; // no attenuation
- lightDirection = normalize(vec3(glLightSource[index].position));
-
- }
- else // point light or spotlight (or other kind of light)
- {
- vec3 positionToLightSource = vec3(glLightSource[index].position - position);
- float distance = length(positionToLightSource);
- lightDirection = normalize(positionToLightSource);
- attenuation = 1.0 / (glLightSource[index].constantAttenuation
- + glLightSource[index].linearAttenuation * distance
- + glLightSource[index].quadraticAttenuation * distance * distance);
-
- if (glLightSource[index].spotCutoff <= 90.0) // spotlight?
- {
- float clampedCosine = max(0.0, dot(-lightDirection, normalize(glLightSource[index].spotDirection)));
- if (clampedCosine < cos(radians(glLightSource[index].spotCutoff))) // outside of spotlight cone?
- {
- attenuation = 0.0;
- }
- else
- {
- attenuation = attenuation * pow(clampedCosine, glLightSource[index].spotExponent);
- }
- }
- }
-
- vec3 diffuseReflection = attenuation * vec3(glLightSource[index].diffuse) * vec3(glFrontMaterial.diffuse)* max(0.0, dot(normalDirection, lightDirection));
-
- vec3 specularReflection;
- if (dot(normalDirection, lightDirection) < 0.0) // light source on the wrong side?
- {
- specularReflection = vec3(0.0, 0.0, 0.0); // no specular reflection
- }
- else // light source on the right side
- {
- specularReflection = attenuation * vec3(glLightSource[index].specular) * vec3(glFrontMaterial.specular)
- * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), glFrontMaterial.shininess);
- }
-
- totalLighting = totalLighting + diffuseReflection + specularReflection;
- }
+ attenuation = 1.0; // no attenuation
+ lightDirection = normalize(vec3(glLightSource[index].position));
+
+ }
+ else // point light or spotlight (or other kind of light)
+ {
+ vec3 positionToLightSource = vec3(glLightSource[index].position - position);
+ float distance = length(positionToLightSource);
+ lightDirection = normalize(positionToLightSource);
+ attenuation = 1.0 / (glLightSource[index].constantAttenuation
+ + glLightSource[index].linearAttenuation * distance
+ + glLightSource[index].quadraticAttenuation * distance * distance);
+
+ if (glLightSource[index].spotCutoff <= 90.0) // spotlight?
+ {
+ float clampedCosine = max(0.0, dot(-lightDirection, normalize(glLightSource[index].spotDirection)));
+ if (clampedCosine < cos(radians(glLightSource[index].spotCutoff))) // outside of spotlight cone?
+ {
+ attenuation = 0.0;
+ }
+ else
+ {
+ attenuation = attenuation * pow(clampedCosine, glLightSource[index].spotExponent);
+ }
+ }
+ }
+
+ vec3 diffuseReflection = attenuation * vec3(glLightSource[index].diffuse) * vec3(glFrontMaterial.diffuse)* max(0.0, dot(normalDirection, lightDirection));
+
+ vec3 specularReflection;
+ if (dot(normalDirection, lightDirection) < 0.0) // light source on the wrong side?
+ {
+ specularReflection = vec3(0.0, 0.0, 0.0); // no specular reflection
+ }
+ else // light source on the right side
+ {
+ specularReflection = attenuation * vec3(glLightSource[index].specular) * vec3(glFrontMaterial.specular)
+ * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), glFrontMaterial.shininess);
+ }
+
+ totalLighting = totalLighting + diffuseReflection + specularReflection;
+
}
gl_FragColor = vec4(totalLighting, 1.0);
diff --git a/src/main/java/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.frag b/src/main/java/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.frag
index 2b1a258..dafaa69 100644
--- a/src/main/java/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.frag
+++ b/src/main/java/org/jdesktop/j3d/examples/sphere_motion/phong_gl2es2_texture.frag
@@ -24,7 +24,6 @@ uniform material glFrontMaterial;
struct lightSource
{
- int enabled;
vec4 position;
vec4 diffuse;
vec4 specular;
@@ -49,54 +48,52 @@ void main()
vec3 totalSpecularLighting;
for (int index = 0; index < numberOfLights; index++) // for all light sources
- {
- if(glLightSource[index].enabled == 1)
+ {
+ if (0.0 == glLightSource[index].position.w) // directional light?
{
- if (0.0 == glLightSource[index].position.w) // directional light?
- {
- attenuation = 1.0; // no attenuation
- lightDirection = normalize(vec3(glLightSource[index].position));
-
- }
- else // point light or spotlight (or other kind of light)
- {
- vec3 positionToLightSource = vec3(glLightSource[index].position - position);
- float distance = length(positionToLightSource);
- lightDirection = normalize(positionToLightSource);
- attenuation = 1.0 / (glLightSource[index].constantAttenuation
- + glLightSource[index].linearAttenuation * distance
- + glLightSource[index].quadraticAttenuation * distance * distance);
-
- if (glLightSource[index].spotCutoff <= 90.0) // spotlight?
- {
- float clampedCosine = max(0.0, dot(-lightDirection, normalize(glLightSource[index].spotDirection)));
- if (clampedCosine < cos(radians(glLightSource[index].spotCutoff))) // outside of spotlight cone?
- {
- attenuation = 0.0;
- }
- else
- {
- attenuation = attenuation * pow(clampedCosine, glLightSource[index].spotExponent);
- }
- }
- }
-
- vec3 diffuseReflection = attenuation * vec3(glLightSource[index].diffuse) * vec3(glFrontMaterial.diffuse)* max(0.0, dot(normalDirection, lightDirection));
-
- vec3 specularReflection;
- if (dot(normalDirection, lightDirection) < 0.0) // light source on the wrong side?
- {
- specularReflection = vec3(0.0, 0.0, 0.0); // no specular reflection
- }
- else // light source on the right side
- {
- specularReflection = attenuation * vec3(glLightSource[index].specular) * vec3(glFrontMaterial.specular)
- * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), glFrontMaterial.shininess);
- }
-
- totalDiffuseLighting = totalDiffuseLighting + diffuseReflection;
- totalSpecularLighting = totalSpecularLighting + specularReflection;
- }
+ attenuation = 1.0; // no attenuation
+ lightDirection = normalize(vec3(glLightSource[index].position));
+
+ }
+ else // point light or spotlight (or other kind of light)
+ {
+ vec3 positionToLightSource = vec3(glLightSource[index].position - position);
+ float distance = length(positionToLightSource);
+ lightDirection = normalize(positionToLightSource);
+ attenuation = 1.0 / (glLightSource[index].constantAttenuation
+ + glLightSource[index].linearAttenuation * distance
+ + glLightSource[index].quadraticAttenuation * distance * distance);
+
+ if (glLightSource[index].spotCutoff <= 90.0) // spotlight?
+ {
+ float clampedCosine = max(0.0, dot(-lightDirection, normalize(glLightSource[index].spotDirection)));
+ if (clampedCosine < cos(radians(glLightSource[index].spotCutoff))) // outside of spotlight cone?
+ {
+ attenuation = 0.0;
+ }
+ else
+ {
+ attenuation = attenuation * pow(clampedCosine, glLightSource[index].spotExponent);
+ }
+ }
+ }
+
+ vec3 diffuseReflection = attenuation * vec3(glLightSource[index].diffuse) * vec3(glFrontMaterial.diffuse)* max(0.0, dot(normalDirection, lightDirection));
+
+ vec3 specularReflection;
+ if (dot(normalDirection, lightDirection) < 0.0) // light source on the wrong side?
+ {
+ specularReflection = vec3(0.0, 0.0, 0.0); // no specular reflection
+ }
+ else // light source on the right side
+ {
+ specularReflection = attenuation * vec3(glLightSource[index].specular) * vec3(glFrontMaterial.specular)
+ * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), glFrontMaterial.shininess);
+ }
+
+ totalDiffuseLighting = totalDiffuseLighting + diffuseReflection;
+ totalSpecularLighting = totalSpecularLighting + specularReflection;
+
}
totalDiffuseLighting = totalDiffuseLighting * baseMap.rgb;