summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphil <[email protected]>2016-11-05 10:15:22 +1300
committerphil <[email protected]>2016-11-05 10:15:22 +1300
commit3b0abb20ad6e5da59e66cf701b07ff39ff3bd24c (patch)
tree259ae9e693f02c165c40027ce30e03689aa0b227
parent7a8ff3f043c5140e0f40a4df72fc27085b8e8b71 (diff)
fog example in default shader corrected
-rw-r--r--src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag
index d6f5e96..60076e6 100644
--- a/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag
+++ b/src/classes/org/jdesktop/j3d/examples/gl2es2pipeline/fixed_function_shader.frag
@@ -9,10 +9,10 @@ uniform float alphaTestValue;
struct fogData
{
- int fogEnabled = -1;
- vec3 expColor = new Vector3f();
+ int fogEnabled;
+ vec4 expColor;
float expDensity;
- vec3 linearColor = new Vector3f();
+ vec4 linearColor;
float linearStart;
float linearEnd;
};
@@ -89,32 +89,32 @@ void main( void )
color.rgb = albedo * (diffuse + emissive) + spec;
color.a = C.a * baseMap.a;
- if(fogData.fogEnabled == 1)
+ float fogFactor = 0.0;
+
+ if(fogData.fogEnabled == 1)
{
//distance
float dist = 0.0;
- float fogFactor = 0.0;
//compute distance used in fog equations
dist = length(ViewDir);
if(fogData.linearEnd > 0.0)//linear fog
{
- fogFactor = (fogData.linearEnd - dist)/(fogData.linearEnd - fogData.linearStart);
+ fogFactor = 1.0-((fogData.linearEnd - dist)/(fogData.linearEnd - fogData.linearStart));
fogFactor = clamp( fogFactor, 0.0, 1.0 );
-
- //if you inverse color in glsl mix function you have to put 1.0 - fogFactor
- color = mix(fogData.linearColor, color, fogFactor);
+ color = mix(color, fogData.linearColor, fogFactor);
}
else if( fogData.expDensity > 0.0)// exponential fog
{
- fogFactor = 1.0 /exp(dist * fogData.expDensity);
+ fogFactor = 1.0-(1.0 /exp(dist * fogData.expDensity));
fogFactor = clamp( fogFactor, 0.0, 1.0 );
-
- // mix function fogColor-(1-fogFactor) + lightColor-fogFactor
- color = mix(fogData.expColor, color, fogFactor);
- }
+ color = mix(color, fogData.expColor, fogFactor);
+ }
+ color.a = color.a + fogFactor;
}
+
+ glFragColor = color;
glFragColor = color;
}