#version 450
uniform sampler2D tex;
+uniform samplerCube dstex;
uniform vec4 diffuse;
uniform vec4 specular;
uniform float shininess;
varying vec3 pos;
-varying vec3 normal;
-varying vec3 ldir;
+// varying vec3 normal;
+// varying vec3 ldir;
varying vec2 tex_coord;
+varying vec3 world_normal;
// const float fog_density = 0.005;
uniform float fog_density;
void main()
{
- vec3 p = normalize(pos); // view space dir
+ vec4 itexel = textureCube(dstex, normalize(world_normal));
+
+/* vec3 p = normalize(pos); // view space dir
vec3 n = normalize(normal);
vec3 l = normalize(ldir);
vec3 vdir = normalize(-p);
float cdiff = max(dot(l, n), 0.0);
- float cspec = pow(max(dot(r, vdir), 0.0), shininess);
+ 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);
- vec3 object_color = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
+ // vec3 object_color = (diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec) * itexel.xyz;
+ vec3 object_color = diffuse.xyz * texel.xyz * itexel.xyz;
color.xyz = mix(sky_color, object_color, fog);
color.w = 1.0;
uniform mat4 mview;
uniform mat4 mmviewproj;
+uniform mat4 mmod;
varying vec3 pos;
-varying vec3 normal;
-varying vec3 ldir;
+// varying vec3 normal;
+// varying vec3 ldir;
varying vec2 tex_coord;
+varying vec3 world_normal;
const vec3 lpos = vec3(-10.0, 100.0, 10.0);
gl_Position = mmviewproj * vec4(attr_pos, 1.0);
pos = (mview * vec4(attr_pos, 1.0)).xyz;
- ldir = (mview * vec4(lpos, 1.0)).xyz;
+ // ldir = (mview * vec4(lpos, 1.0)).xyz;
- mat3 normal_matrix = mat3(mview);
- normal = normal_matrix * attr_normal;
+ // mat3 normal_matrix = mat3(mview);
+ // normal = normal_matrix * attr_normal;
tex_coord = attr_tex;
+
+ world_normal = (mmod * vec4(attr_normal, 1.0)).xyz;
}
\ No newline at end of file
#version 450
uniform sampler2D tex;
+uniform samplerCube dstex;
uniform vec4 diffuse;
-uniform vec4 specular;
-uniform float shininess;
+// 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;
+// varying vec3 normal;
+// varying vec3 ldir;
varying vec2 tex_coord;
+varying vec3 world_normal;
out vec4 color;
void main()
{
- vec3 p = normalize(pos);
- vec3 n = normalize(normal);
- vec3 l = normalize(ldir);
+ vec4 itexel = textureCube(dstex, normalize(world_normal));
+ // vec3 p = normalize(pos);
+ // vec3 n = normalize(normal);
+ // vec3 l = normalize(ldir);
- vec3 r = normalize(-reflect(l, n));
- vec3 vdir = normalize(-p);
+ // 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 cdiff = max(dot(l, n), 0.0);
+ // float cspec = pow(max(dot(r, vdir), 0.0), shininess);
vec4 texel = texture2D(tex, tex_coord);
- vec3 object_color = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
-
+ // vec3 object_color = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
+ vec3 object_color = diffuse.xyz * texel.xyz * itexel.xyz;
float dist = -pos.z;
float fog = clamp(exp(-fog_density * dist), 0.0, 1.0);
uniform mat4 mview;
uniform mat4 mmviewproj;
+uniform mat4 mmod;
uniform float t;
const float half_height = 0.855;
varying vec3 pos;
-varying vec3 normal;
-varying vec3 ldir;
+// varying vec3 normal;
+// varying vec3 ldir;
varying vec2 tex_coord;
+varying vec3 world_normal;
-const vec3 lpos = vec3(0.0, 100.0, -10.0);
+// const vec3 lpos = vec3(0.0, 100.0, -10.0);
/* attributes */
layout(location = 1) in vec3 attr_pos;
gl_Position = mmviewproj * vec4(p, 1.0);
pos = (mview * vec4(p, 1.0)).xyz;
- ldir = (mview * vec4(lpos, 1.0)).xyz;
+ // ldir = (mview * vec4(lpos, 1.0)).xyz;
- mat3 normal_matrix = mat3(mview);
- normal = normal_matrix * n;
+ // mat3 normal_matrix = mat3(mview);
+ // normal = normal_matrix * n;
tex_coord = attr_tex;
+ world_normal = (mmod * vec4(attr_normal, 1.0)).xyz;
}
\ No newline at end of file
static Terrain terrain;
static TerrainParams p;
static Texture *skybox_tex;
+static Texture *irradiance_tex;
static Texture *terrain_tex;
static Material terrain_mat;
static Renderer *terrain_rend;
skybox_tex = gfx_create_texture();
skybox_tex->load("data/cubemap/cubemap.hdr");
- //irr_tex->load("data/cubemap/irradiance.hdr");
terrain_rend->set_sky_tex(skybox_tex);
+ irradiance_tex = gfx_create_texture();
+ irradiance_tex->load("data/cubemap/irradiance.hdr");
+ terrain_rend->set_diffuse_sky_tex(irradiance_tex);
+
if(!terrain_rend->create()) {
fprintf(stderr, "terrain fail\n");
return false;
delete cow_scene;
delete cow_rend;
+ delete skybox_tex;
+ delete irradiance_tex;
delete terrain_tex;
delete terrain_rend;
+
gfx_cleanup();
}
#include "global.h"
#include "morph_renderer.h"
+#include "object.h"
#include "scene.h"
#include "shader.h"
#include "shader_manager.h"
+#include "texture.h"
MorphRenderer::MorphRenderer()
{
mmviewproj_loc = sprog->get_uniform_location("mmviewproj");
mview_loc = sprog->get_uniform_location("mview");
+ mmod_loc = sprog->get_uniform_location("mmod");
+
+ dstex_loc = sprog->get_uniform_location("dstex");
+ if(dstex_loc != -1)
+ sprog->set_uniformi(dstex_loc, 1);
return true;
}
if(!sprog->link())
return;
+ if(dskytex) {
+ dskytex->bind(1);
+ }
+
sprog->use();
for(size_t i=0; i<scene->objects.size(); i++) {
float t = (sin(time_sec + 7.3 * noise(i * M_PI)) + 1) * 0.5;
if (t_loc != -1)
sprog->set_uniformf(t_loc, t);
+
+ if(mmod_loc != -1)
+ sprog->set_uniform_matrix(mmod_loc, scene->objects[i]->transform.upper3x3());
+
draw_object(scene->objects[i]);
}
}
\ No newline at end of file
mmviewproj_loc = sprog->get_uniform_location("mmviewproj");
mview_loc = sprog->get_uniform_location("mview");
+ mmod_loc = sprog->get_uniform_location("mmod");
+
+ /* skybox, irradiance map uniforms */
+
+ stex_loc = sprog->get_uniform_location("stex");
+ dstex_loc = sprog->get_uniform_location("dstex");
+
+ if(stex_loc != -1)
+ sprog->set_uniformi(stex_loc, 0);
+
+ if(dstex_loc != -1)
+ sprog->set_uniformi(dstex_loc, 1);
return true;
}
if(skytex) {
draw_skybox();
+
+ if(dskytex) {
+ dskytex->bind(1);
+ }
}
if(!sprog->link())
if(mview_loc != -1)
sprog->set_uniform_matrix(mview_loc, mview);
+ Mat4 mmod = object->transform.upper3x3();
+ if(mmod_loc != -1)
+ sprog->set_uniform_matrix(mmod_loc, mmod);
+
object->mesh->draw();
// debug
int shin_loc;
int mmviewproj_loc;
int mview_loc;
+ int mmod_loc;
int fog_loc;
+ int dstex_loc;
+ int stex_loc;
ShaderProgram *sprog;