projects
/
demo
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
f4ba93a
)
added morphing to the cow
author
Eleni Maria Stea
<estea@igalia.com>
Mon, 21 Aug 2017 15:20:33 +0000
(18:20 +0300)
committer
Eleni Maria Stea
<estea@igalia.com>
Mon, 21 Aug 2017 15:20:33 +0000
(18:20 +0300)
gl_shaders/default.v.glsl
patch
|
blob
|
history
gl_shaders/morphing.v.glsl
patch
|
blob
|
history
src/global.h
patch
|
blob
|
history
src/main.cc
patch
|
blob
|
history
src/morph_renderer.cc
patch
|
blob
|
history
src/morph_renderer.h
patch
|
blob
|
history
src/renderer.h
patch
|
blob
|
history
diff --git
a/gl_shaders/default.v.glsl
b/gl_shaders/default.v.glsl
index
38a19a4
..
455759d
100644
(file)
--- a/
gl_shaders/default.v.glsl
+++ b/
gl_shaders/default.v.glsl
@@
-26,4
+26,4
@@
void main()
mat3 normal_matrix = mat3(mview);
normal = normal_matrix * attr_normal;
tex_coord = attr_tex;
mat3 normal_matrix = mat3(mview);
normal = normal_matrix * attr_normal;
tex_coord = attr_tex;
-}
+}
\ No newline at end of file
diff --git
a/gl_shaders/morphing.v.glsl
b/gl_shaders/morphing.v.glsl
index
cbb3d9e
..
6f72aa7
100644
(file)
--- a/
gl_shaders/morphing.v.glsl
+++ b/
gl_shaders/morphing.v.glsl
@@
-3,12
+3,15
@@
uniform mat4 mview;
uniform mat4 mmviewproj;
uniform mat4 mview;
uniform mat4 mmviewproj;
+uniform float t;
+const float half_height = 0.855;
+
varying vec3 pos;
varying vec3 normal;
varying vec3 ldir;
varying vec2 tex_coord;
varying vec3 pos;
varying vec3 normal;
varying vec3 ldir;
varying vec2 tex_coord;
-const vec3 lpos = vec3(-10.0, 100.0, 10.0);
+const vec3 lpos = vec3(0.0, 100.0, -10.0);
/* attributes */
layout(location = 1) in vec3 attr_pos;
/* attributes */
layout(location = 1) in vec3 attr_pos;
@@
-17,12
+20,21
@@
layout(location = 3) in vec2 attr_tex;
void main()
{
void main()
{
- gl_Position = mmviewproj * vec4(attr_pos, 1.0);
+ vec3 sph_pos = normalize(vec3(attr_pos.x, attr_pos.y - half_height, attr_pos.z));
+
+ vec3 sph_normal = sph_pos;
+ sph_pos.y += half_height;
+
+ vec3 p = mix(attr_pos, sph_pos, t);
+ vec3 n = mix(attr_normal, sph_normal, t);
- pos = (mview * vec4(attr_pos, 1.0)).xyz;
+ gl_Position = mmviewproj * vec4(p, 1.0);
+
+ pos = (mview * vec4(p, 1.0)).xyz;
ldir = (mview * vec4(lpos, 1.0)).xyz;
mat3 normal_matrix = mat3(mview);
ldir = (mview * vec4(lpos, 1.0)).xyz;
mat3 normal_matrix = mat3(mview);
- normal = normal_matrix * attr_normal;
+ normal = normal_matrix * n;
+
tex_coord = attr_tex;
}
\ No newline at end of file
tex_coord = attr_tex;
}
\ No newline at end of file
diff --git
a/src/global.h
b/src/global.h
index
12aca5c
..
cbcbed6
100644
(file)
--- a/
src/global.h
+++ b/
src/global.h
@@
-7,5
+7,6
@@
extern ShaderManager *sdr_man;
extern Mat4 mprojection;
extern ShaderManager *sdr_man;
extern Mat4 mprojection;
+extern double time_sec;
#endif // GLOBAL_H_
\ No newline at end of file
#endif // GLOBAL_H_
\ No newline at end of file
diff --git
a/src/main.cc
b/src/main.cc
index
d4d4226
..
1246d2f
100644
(file)
--- a/
src/main.cc
+++ b/
src/main.cc
@@
-13,8
+13,8
@@
/* TODO: fix those */
#include "camera.h"
#include "mesh.h"
/* TODO: fix those */
#include "camera.h"
#include "mesh.h"
+#include "morph_renderer.h"
#include "object.h"
#include "object.h"
-#include "renderer.h"
#include "scene.h"
#include "terrain.h"
#include "texture.h"
#include "scene.h"
#include "terrain.h"
#include "texture.h"
@@
-43,9
+43,10
@@
GLFWwindow *win;
int win_w = 800;
int win_h = 600;
int win_w = 800;
int win_h = 600;
-
ShaderManager *sdr_man;
ShaderManager *sdr_man;
+double time_sec;
+
/* variables */
static bool move_camera;
/* variables */
static bool move_camera;
@@
-59,7
+60,7
@@
static OrbitCamera *camera;
static Scene *cow_scene;
static Object *cow_object;
static Scene *cow_scene;
static Object *cow_object;
-static Renderer *cow_rend;
+static MorphRenderer *cow_rend;
static Terrain terrain;
static Texture *skybox_tex;
static Terrain terrain;
static Texture *skybox_tex;
@@
-128,7
+129,7
@@
static bool init(Gfx_API api)
return false;
}
return false;
}
- cow_rend = new Renderer;
+ cow_rend = new MorphRenderer;
cow_rend->camera = camera;
cow_rend->scene = cow_scene;
cow_rend->camera = camera;
cow_rend->scene = cow_scene;
@@
-299,9
+300,9
@@
static void update(float dt)
static void display()
{
static float prev_tsec;
static void display()
{
static float prev_tsec;
- float tsec = glfwGetTime();
- float dt = tsec - prev_tsec;
- prev_tsec = tsec;
+ time_sec = glfwGetTime();
+ float dt = time_sec - prev_tsec;
+ prev_tsec = time_sec;
update(dt);
update(dt);
diff --git
a/src/morph_renderer.cc
b/src/morph_renderer.cc
index
f31b8fe
..
ae91625
100644
(file)
--- a/
src/morph_renderer.cc
+++ b/
src/morph_renderer.cc
@@
-30,6
+30,7
@@
bool MorphRenderer::create()
diff_loc = sprog->get_uniform_location("diffuse");
spec_loc = sprog->get_uniform_location("specular");
shin_loc = sprog->get_uniform_location("shininess");
diff_loc = sprog->get_uniform_location("diffuse");
spec_loc = sprog->get_uniform_location("specular");
shin_loc = sprog->get_uniform_location("shininess");
+ t_loc = sprog->get_uniform_location("t");
/* uniform locations for matrices */
/* uniform locations for matrices */
@@
-52,4
+53,14
@@
void MorphRenderer::draw() const
for(size_t i=0; i<scene->objects.size(); i++) {
draw_object(scene->objects[i]);
}
for(size_t i=0; i<scene->objects.size(); i++) {
draw_object(scene->objects[i]);
}
+}
+
+void MorphRenderer::draw_object(Object *object) const
+{
+ float t = (sin(time_sec) + 1) * 0.5;
+
+ if(t_loc != -1)
+ sprog->set_uniformf(t_loc, t);
+
+ Renderer::draw_object(object);
}
\ No newline at end of file
}
\ No newline at end of file
diff --git
a/src/morph_renderer.h
b/src/morph_renderer.h
index
3b5e567
..
aebb922
100644
(file)
--- a/
src/morph_renderer.h
+++ b/
src/morph_renderer.h
@@
-4,12
+4,17
@@
#include "renderer.h"
class MorphRenderer : public Renderer {
#include "renderer.h"
class MorphRenderer : public Renderer {
+protected:
+ int t_loc;
+
+ virtual void draw_object(Object *object) const override;
+
public:
MorphRenderer();
virtual ~MorphRenderer();
public:
MorphRenderer();
virtual ~MorphRenderer();
- virtual bool create();
- virtual void draw() const;
+ virtual bool create() override;
+ virtual void draw() const override;
};
#endif // MORPH_RENDERER_H_
\ No newline at end of file
};
#endif // MORPH_RENDERER_H_
\ No newline at end of file
diff --git
a/src/renderer.h
b/src/renderer.h
index
c3fb0bf
..
a14d69c
100644
(file)
--- a/
src/renderer.h
+++ b/
src/renderer.h
@@
-5,6
+5,7
@@
class OrbitCamera;
class Object;
class Scene;
class ShaderProgram;
class Object;
class Scene;
class ShaderProgram;
+class Texture;
class Renderer {
protected:
class Renderer {
protected: