From 3b0abb20ad6e5da59e66cf701b07ff39ff3bd24c Mon Sep 17 00:00:00 2001 From: phil Date: Sat, 5 Nov 2016 10:15:22 +1300 Subject: fog example in default shader corrected --- .../gl2es2pipeline/fixed_function_shader.frag | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/classes/org/jdesktop') 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; } -- cgit v1.2.3