fixed issues in shaders
authorEleni Maria Stea <estea@igalia.com>
Tue, 22 Aug 2017 16:20:42 +0000 (19:20 +0300)
committerEleni Maria Stea <estea@igalia.com>
Tue, 22 Aug 2017 16:20:42 +0000 (19:20 +0300)
Makefile
gl_shaders/default.f.glsl
gl_shaders/morphing.f.glsl
src/main.cc
src/morph_renderer.cc

index fce6d9a..adda4e1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -23,3 +23,16 @@ $(bin): $(obj)
 .PHONY: clean
 clean:
        rm -f $(obj) $(bin) $(dep)
+
+cmpath = data/cubemap
+.PHONY: irradiance_map
+irradiance_map:
+       cmft --inputFacePosX $(cmpath)/cubemap_px.hdr \
+                       --inputFacePosY $(cmpath)/cubemap_py.hdr \
+                       --inputFacePosZ $(cmpath)/cubemap_pz.hdr \
+                       --inputFaceNegX $(cmpath)/cubemap_nx.hdr \
+                       --inputFaceNegY $(cmpath)/cubemap_ny.hdr \
+                       --inputFaceNegZ $(cmpath)/cubemap_nz.hdr \
+                       --filter irradiance \
+                       --output0 $(cmpath)/irradiance_px.hdr \
+                       --output0params hdr,rgbe,facelist
index 88f0d69..f0f61d8 100644 (file)
@@ -13,7 +13,7 @@ varying vec2 tex_coord;
 
 // const float fog_density = 0.005;
 uniform float fog_density;
-const vec4 sky_color = vec4(0.35, 0.5, 0.65, 1.0);
+const vec3 sky_color = vec3(0.35, 0.5, 0.65);
 
 out vec4 color;
 
@@ -34,9 +34,8 @@ void main()
 
        vec4 texel = texture2D(tex, tex_coord);
 
-       vec4 object_color;
-       object_color.xyz = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
-       object_color.w = 1.0;
+       vec3 object_color = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
 
-       color = mix(sky_color, object_color, fog);
+       color.xyz = mix(sky_color, object_color, fog);
+       color.w = 1.0;
 }
index 490efab..df74c90 100644 (file)
@@ -6,6 +6,9 @@ uniform vec4 diffuse;
 uniform vec4 specular;
 uniform float shininess;
 
+uniform float fog_density;
+const vec3 sky_color = vec3(0.35, 0.5, 0.65);
+
 varying vec3 pos;
 varying vec3 normal;
 varying vec3 ldir;
@@ -26,6 +29,11 @@ void main()
        float cspec = pow(max(dot(r, vdir), 0.0), shininess);
 
        vec4 texel = texture2D(tex, tex_coord);
-       color.xyz = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
+       vec3 object_color = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
+
+       float dist = -pos.z;
+       float fog = clamp(exp(-fog_density * dist), 0.0, 1.0);
+
+       color.xyz = mix(sky_color, object_color, fog);
        color.w = 1.0;
 }
index c48b383..1734fc6 100644 (file)
@@ -185,6 +185,7 @@ static bool init(Gfx_API api)
 
        skybox_tex = gfx_create_texture();
        skybox_tex->load("data/cubemap/cubemap.hdr");
+       // skybox_tex->load("data/cubemap/irradiance.hdr");
        terrain_rend->set_sky_tex(skybox_tex);
 
        if(!terrain_rend->create()) {
@@ -330,5 +331,6 @@ static void display()
 
        cow_pos.y = terrain.get_height(cow_pos);
        cow_object->transform.translation(cow_pos);
+       cow_rend->fog_density = fog_density;
        cow_rend->draw();
 }
\ No newline at end of file
index 42d920d..601c335 100644 (file)
@@ -33,6 +33,7 @@ bool MorphRenderer::create()
        spec_loc = sprog->get_uniform_location("specular");
        shin_loc = sprog->get_uniform_location("shininess");
        t_loc = sprog->get_uniform_location("t");
+       fog_loc = sprog->get_uniform_location("fog_density");
 
        /* uniform locations for matrices */