@@ -74,86 +74,80 @@ varying vec3 vNormal;
7474varying vec4 vPosWorld;
7575varying vec4 vPosView;
7676
77- vec4 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specularColor, vec3 lightColor)
77+ vec3 calculate_lighting(vec3 N, vec3 L, vec3 V, vec3 diffuseColor, vec3 specularColor, vec3 lightColor)
7878{
7979 vec3 H = normalize (V + L);
8080 float diffuse = max (0.0 , dot (N, L));
8181 float specular = max (0.0 , dot (N, H));
8282 specular = pow (specular, uSpecularPower);
8383
84- return vec4 ( lightColor * (diffuse * diffuseColor + specular * specularColor), 0.0 );
84+ return lightColor * (diffuse * diffuseColor + specular * specularColor);
8585}
8686
8787void main()
8888{
8989 if (uUseClippingPlanes)
9090 {
9191 float fPlaneValue;
92- if (uClippingPlaneCtrl0.x > 0.5 )
92+ if (uClippingPlaneCtrl0.x > 0.5 )
9393 {
9494 fPlaneValue = dot (vPosWorld, uClippingPlane0);
9595 fPlaneValue = uClippingPlaneCtrl0.z > 0.5 ? - fPlaneValue : fPlaneValue;
96- if (fPlaneValue < 0.0 )
97- discard ;
96+ if (fPlaneValue < 0.0 ) discard ;
9897 }
99- if (uClippingPlaneCtrl1.x > 0.5 )
98+ if (uClippingPlaneCtrl1.x > 0.5 )
10099 {
101100 fPlaneValue = dot (vPosWorld, uClippingPlane1);
102101 fPlaneValue = uClippingPlaneCtrl1.z > 0.5 ? - fPlaneValue : fPlaneValue;
103- if (fPlaneValue < 0.0 )
104- discard ;
102+ if (fPlaneValue < 0.0 ) discard ;
105103 }
106- if (uClippingPlaneCtrl2.x > 0.5 )
104+ if (uClippingPlaneCtrl2.x > 0.5 )
107105 {
108106 fPlaneValue = dot (vPosWorld, uClippingPlane2);
109107 fPlaneValue = uClippingPlaneCtrl2.z > 0.5 ? - fPlaneValue : fPlaneValue;
110- if (fPlaneValue < 0.0 )
111- discard ;
108+ if (fPlaneValue < 0.0 ) discard ;
112109 }
113- if (uClippingPlaneCtrl3.x > 0.5 )
110+ if (uClippingPlaneCtrl3.x > 0.5 )
114111 {
115112 fPlaneValue = dot (vPosWorld, uClippingPlane3);
116113 fPlaneValue = uClippingPlaneCtrl3.z > 0.5 ? - fPlaneValue : fPlaneValue;
117- if (fPlaneValue < 0.0 )
118- discard ;
114+ if (fPlaneValue < 0.0 ) discard ;
119115 }
120- if (uClippingPlaneCtrl4.x > 0.5 )
116+ if (uClippingPlaneCtrl4.x > 0.5 )
121117 {
122118 fPlaneValue = dot (vPosWorld, uClippingPlane4);
123119 fPlaneValue = uClippingPlaneCtrl4.z > 0.5 ? - fPlaneValue : fPlaneValue;
124- if (fPlaneValue < 0.0 )
125- discard ;
120+ if (fPlaneValue < 0.0 ) discard ;
126121 }
127- if (uClippingPlaneCtrl5.x > 0.5 )
122+ if (uClippingPlaneCtrl5.x > 0.5 )
128123 {
129124 fPlaneValue = dot (vPosWorld, uClippingPlane5);
130125 fPlaneValue = uClippingPlaneCtrl5.z > 0.5 ? - fPlaneValue : fPlaneValue;
131- if (fPlaneValue < 0.0 )
132- discard ;
126+ if (fPlaneValue < 0.0 ) discard ;
133127 }
134128 }
135129
136- vec3 diffuseColor = uDiffuseColor.rgb;
130+ vec3 diffuseColor = pow ( uDiffuseColor.rgb, vec3 ( 2.2 )) ;
137131 vec3 specularColor = uSpecularColor.rgb;
138132 vec3 ambientColor = uAmbientColor.rgb;
139133 float transparency = uTransparency;
140134
141135 vec3 normal = normalize (vNormal);
142- if (gl_FrontFacing ) normal = - normal;
136+ if (gl_FrontFacing ) normal = - normal;
143137 vec3 cameraVector = - normalize (vPosView.xyz);
144138
145139 gl_FragColor = vec4 (ambientColor * diffuseColor, transparency);
146- if (length (uLightDirectionView0) > 0.0 )
147- gl_FragColor += calculate_lighting(normal, uLightDirectionView0, cameraVector, diffuseColor, specularColor, uLightColor0);
148- if (length (uLightDirectionView1) > 0.0 )
149- gl_FragColor += calculate_lighting(normal, uLightDirectionView1, cameraVector, diffuseColor, specularColor, uLightColor1);
150- if (length (uLightDirectionView2) > 0.0 )
151- gl_FragColor += calculate_lighting(normal, uLightDirectionView2, cameraVector, diffuseColor, specularColor, uLightColor2);
152- if (length (uLightDirectionView3) > 0.0 )
153- gl_FragColor += calculate_lighting(normal, uLightDirectionView3, cameraVector, diffuseColor, specularColor, uLightColor3);
140+ if (length (uLightDirectionView0) > 0.0 ) gl_FragColor .rgb += calculate_lighting(normal,
141+ uLightDirectionView0, cameraVector, diffuseColor, specularColor, uLightColor0);
142+ if (length (uLightDirectionView1) > 0.0 ) gl_FragColor .rgb += calculate_lighting(normal,
143+ uLightDirectionView1, cameraVector, diffuseColor, specularColor, uLightColor1);
144+ if (length (uLightDirectionView2) > 0.0 ) gl_FragColor .rgb += calculate_lighting(normal,
145+ uLightDirectionView2, cameraVector, diffuseColor, specularColor, uLightColor2);
146+ if (length (uLightDirectionView3) > 0.0 ) gl_FragColor .rgb += calculate_lighting(normal,
147+ uLightDirectionView3, cameraVector, diffuseColor, specularColor, uLightColor3);
154148
155149 // calculate fog
156- if (uUseFog && uFogSettings.x > 0.0 )
150+ if (uUseFog && uFogSettings.x > 0.0 )
157151 {
158152 vec4 fp;
159153 fp.x = uFogSettings.x;
@@ -165,7 +159,9 @@ void main()
165159 fog_factor = (fp.z- fp.w)/ (fp.z- fp.y);
166160 fog_factor = 1.0 - clamp (fog_factor, 0.0 , 1.0 );
167161 fog_factor = 1.0 - exp (- pow (fog_factor* 2.5 , 2.0 ));
168- gl_FragColor .xyz = mix (clamp (gl_FragColor .xyz , 0.0 , 1.0 ),
169- clamp (uFogColor.xyz , 0.0 , 1.0 ), fog_factor);
162+ gl_FragColor .rgb = mix (clamp (gl_FragColor .rgb , 0.0 , 1.0 ),
163+ clamp (uFogColor.rgb , 0.0 , 1.0 ), fog_factor);
170164 }
165+
166+ gl_FragColor .rgb = pow (gl_FragColor .rgb, vec3 (1.0 / 2.2 ));
171167}
0 commit comments