backup
[demo] / vk_shaders / default.f.glsl
diff --git a/vk_shaders/default.f.glsl b/vk_shaders/default.f.glsl
new file mode 100644 (file)
index 0000000..6f3e896
--- /dev/null
@@ -0,0 +1,48 @@
+#version 450
+
+layout(binding = 0) uniform sampler2D tex;
+layout(binding = 0) uniform samplerCube dstex;
+
+layout(std140, binding = 0) uniform shading_state {
+       vec4 diffuse;
+       vec4 specular;
+       float shininess;
+       float fog_density;
+} s;
+
+layout(location = 0) in vec3 pos;
+layout(location = 1) in vec2 tex_coord;
+layout(location = 2) in vec3 world_normal;
+
+// const float fog_density = 0.005;
+const vec3 sky_color = vec3(0.35, 0.5, 0.65);
+
+layout(location = 0) out vec4 color;
+
+void main()
+{
+       /*vec4 itexel = textureCube(dstex, normalize(world_normal)); */
+       vec4 itexel = texture(dstex, normalize(world_normal));
+
+/*     vec3 p = normalize(pos); // view space dir
+       vec3 n = normalize(normal);
+       vec3 l = normalize(ldir);
+
+       vec3 r = normalize(-reflect(l, n));
+       vec3 vdir = normalize(-p);
+
+       float cdiff = max(dot(l, n), 0.0);
+       float cspec = pow(max(dot(r, vdir), 0.0), shininess);
+*/
+
+       float dist = -pos.z;
+       float fog = clamp(exp(-s.fog_density * dist), 0.0, 1.0);
+
+       vec4 texel = texture(tex, tex_coord);
+
+       // vec3 object_color = (diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec) * itexel.xyz;
+       vec3 object_color = s.diffuse.xyz * texel.xyz * itexel.xyz;
+
+       color.xyz = mix(sky_color, object_color, fog);
+       color.w = 1.0;
+}