projects
/
demo
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
9781406
)
added fog (need to set the fog params)
author
Eleni Maria Stea
<estea@igalia.com>
Mon, 21 Aug 2017 18:23:36 +0000
(21:23 +0300)
committer
Eleni Maria Stea
<estea@igalia.com>
Mon, 21 Aug 2017 18:23:36 +0000
(21:23 +0300)
gl_shaders/default.f.glsl
patch
|
blob
|
history
src/opengl/texture-gl.cc
patch
|
blob
|
history
src/opengl/texture-gl.h
patch
|
blob
|
history
src/renderer.cc
patch
|
blob
|
history
src/texture.h
patch
|
blob
|
history
src/vulkan/texture-vk.cc
patch
|
blob
|
history
src/vulkan/texture-vk.h
patch
|
blob
|
history
diff --git
a/gl_shaders/default.f.glsl
b/gl_shaders/default.f.glsl
index
490efab
..
17d4353
100644
(file)
--- a/
gl_shaders/default.f.glsl
+++ b/
gl_shaders/default.f.glsl
@@
-11,11
+11,14
@@
varying vec3 normal;
varying vec3 ldir;
varying vec2 tex_coord;
varying vec3 ldir;
varying vec2 tex_coord;
+const float fog_density = 0.005;
+const vec4 sky_color = vec4(0.35, 0.5, 0.65, 1.0);
+
out vec4 color;
void main()
{
out vec4 color;
void main()
{
- vec3 p = normalize(pos);
+ vec3 p = normalize(pos); // view space dir
vec3 n = normalize(normal);
vec3 l = normalize(ldir);
vec3 n = normalize(normal);
vec3 l = normalize(ldir);
@@
-25,7
+28,14
@@
void main()
float cdiff = max(dot(l, n), 0.0);
float cspec = pow(max(dot(r, vdir), 0.0), shininess);
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(-fog_density * dist), 0.0, 1.0);
+
vec4 texel = texture2D(tex, tex_coord);
vec4 texel = texture2D(tex, tex_coord);
- color.xyz = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
- color.w = 1.0;
+
+ vec4 object_color;
+ object_color.xyz = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
+ object_color.w = 1.0;
+
+ color = mix(sky_color, object_color, fog);
}
}
diff --git
a/src/opengl/texture-gl.cc
b/src/opengl/texture-gl.cc
index
157d0bb
..
80db3ad
100644
(file)
--- a/
src/opengl/texture-gl.cc
+++ b/
src/opengl/texture-gl.cc
@@
-56,10
+56,15
@@
void TextureGL::update()
glGenerateMipmap(target);
}
glGenerateMipmap(target);
}
-void TextureGL::bind()
+void TextureGL::bind(int texture_unit)
{
{
+ glActiveTexture(GL_TEXTURE0 + texture_unit);
+
unsigned int target = is_cubemap() ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
glBindTexture(target, tex);
unsigned int target = is_cubemap() ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
glBindTexture(target, tex);
+
+ //TODO: (not needed for now) if I ever use textures outside the Texture class
+ //glActiveTexture(GL_TEXTURE0);
}
void TextureGL::unbind()
}
void TextureGL::unbind()
diff --git
a/src/opengl/texture-gl.h
b/src/opengl/texture-gl.h
index
aa2b3db
..
0b495ed
100644
(file)
--- a/
src/opengl/texture-gl.h
+++ b/
src/opengl/texture-gl.h
@@
-13,7
+13,7
@@
public:
TextureGL();
virtual ~TextureGL();
TextureGL();
virtual ~TextureGL();
- virtual void bind() override;
+ virtual void bind(int texture_unit = 0) override;
virtual void unbind() override;
};
virtual void unbind() override;
};
diff --git
a/src/renderer.cc
b/src/renderer.cc
index
380cf69
..
e383efa
100644
(file)
--- a/
src/renderer.cc
+++ b/
src/renderer.cc
@@
-98,7
+98,7
@@
void Renderer::draw_object(Object *object) const
/* texture */
if(m->dtex)
/* texture */
if(m->dtex)
- m->dtex->bind();
+ m->dtex->bind(0);
/* setting uniforms for matrices */
/* setting uniforms for matrices */
diff --git
a/src/texture.h
b/src/texture.h
index
3a850f1
..
a1b52d8
100644
(file)
--- a/
src/texture.h
+++ b/
src/texture.h
@@
-24,7
+24,7
@@
public:
virtual bool is_cubemap() const;
virtual bool is_cubemap() const;
- virtual void bind() = 0;
+ virtual void bind(int texture_unit = 0) = 0;
virtual void unbind() = 0;
};
virtual void unbind() = 0;
};
diff --git
a/src/vulkan/texture-vk.cc
b/src/vulkan/texture-vk.cc
index
3c56ebd
..
1c9ad46
100644
(file)
--- a/
src/vulkan/texture-vk.cc
+++ b/
src/vulkan/texture-vk.cc
@@
-12,7
+12,7
@@
void TextureVK::update()
{
}
{
}
-void TextureVK::bind()
+void TextureVK::bind(int texture_unit)
{
}
{
}
diff --git
a/src/vulkan/texture-vk.h
b/src/vulkan/texture-vk.h
index
56da38d
..
5b93917
100644
(file)
--- a/
src/vulkan/texture-vk.h
+++ b/
src/vulkan/texture-vk.h
@@
-11,7
+11,7
@@
public:
TextureVK();
virtual ~TextureVK();
TextureVK();
virtual ~TextureVK();
- virtual void bind() override;
+ virtual void bind(int texture_unit = 0) override;
virtual void unbind() override;
};
virtual void unbind() override;
};