Changed the OpenGL part and the GLSL shaders to use UBO and
[demo] / gl_shaders / morphing.f.glsl
index 490efab..de6dda9 100644 (file)
@@ -1,31 +1,34 @@
 #version 450
 
-uniform sampler2D tex;
+#define SHADING_UNIFORMS 1
 
-uniform vec4 diffuse;
-uniform vec4 specular;
-uniform float shininess;
+layout(binding = 0) uniform sampler2D tex;
+layout(binding = 1) uniform samplerCube dstex;
 
-varying vec3 pos;
-varying vec3 normal;
-varying vec3 ldir;
-varying vec2 tex_coord;
+layout(std140, binding = SHADING_UNIFORMS) uniform fu {
+       vec4 diffuse;
+       vec4 specular;
+       float shininess;
+       float fog_density;
+} s;
 
-out vec4 color;
+/* varyings */
+layout(location = 4) in vec3 pos;
+layout(location = 5) in vec2 tex_coord;
+layout(location = 6) in vec3 world_normal; 
 
-void main()
-{
-       vec3 p = normalize(pos);
-       vec3 n = normalize(normal);
-       vec3 l = normalize(ldir);
-
-       vec3 r = normalize(-reflect(l, n));
-       vec3 vdir = normalize(-p);
+layout(location = 0) out vec4 color;
 
-       float cdiff = max(dot(l, n), 0.0);
-       float cspec = pow(max(dot(r, vdir), 0.0), shininess);
+const vec3 sky_color = vec3(0.35, 0.5, 0.65);
 
+void main()
+{
+       vec4 itexel = textureCube(dstex, normalize(world_normal));
        vec4 texel = texture2D(tex, tex_coord);
-       color.xyz = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
+       vec3 object_color = s.diffuse.xyz * texel.xyz * itexel.xyz;
+       float dist = -pos.z;
+       float fog = clamp(exp(-s.fog_density * dist), 0.0, 1.0);
+
+       color.xyz = mix(sky_color, object_color, fog);
        color.w = 1.0;
 }