Skip to content

Commit

Permalink
Semi working
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcelo Politzer Couto committed May 26, 2016
1 parent 5e15878 commit 82ae86e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion assets/shaders/geometry-main.frag
Expand Up @@ -8,7 +8,7 @@ layout(location = 2) uniform mat4 N;

in vec4 f_pos;
in vec4 f_nor;
out vec4 o_data[3];
out vec4 o_data[2];

void main()
{
Expand Down
2 changes: 1 addition & 1 deletion assets/shaders/geometry-main.vert
Expand Up @@ -14,5 +14,5 @@ out vec4 f_nor;

void main() {
gl_Position = VP * M * v_pos;
f_nor = (N * v_nor);
f_nor = VP * N * v_nor;
}
12 changes: 5 additions & 7 deletions assets/shaders/shading-main.frag
Expand Up @@ -29,8 +29,7 @@ material_t materials[] = material_t[](
/* -------------------------------------------------------------------------- */
layout(location = 0) uniform vec4 u_eye;
layout(location = 1) uniform int debug_flag;
layout(location = 2) uniform mat4 iVP;
layout(location = 3) uniform mat4 V;
layout(location = 2) uniform mat4 iP;

layout(location = 9) uniform int nlights;
layout(location =10) uniform vec4 light[50];
Expand All @@ -51,11 +50,10 @@ void apply_light(vec3 pos, vec3 nor, vec4 col, vec3 light,
float llen = length (light - pos.xyz);
float att = 1.0/dot(vec3(1, llen, llen*llen), attenuation);

vec3 eye = normalize((u_eye / u_eye.w).xyz);
vec3 dif = vec3(0, 0, 0),
spc = vec3(0, 0, 0);

vec3 view = normalize(eye - normalize(pos));
vec3 view = normalize(pos);
float ndotl = max(dot(n,l), 0.0);

dif += att * materials[mi].diffuse * ndotl;
Expand All @@ -74,9 +72,9 @@ void main()
{
if (texture(Gdep, f_tex).r == 1) discard;

vec4 pos = iVP * vec4(f_pos, texture(Gdep, f_tex).r, 1);
vec4 nor = (2*texture(Gnor, f_tex)-1);
vec4 col = 2*texture(Gdif, f_tex)-1;
vec4 pos = iP * vec4(f_pos, texture(Gdep, f_tex).r, 1);
vec4 nor = 2*texture(Gnor, f_tex)-1;
vec4 col = texture(Gdif, f_tex);

int mi = 1;

Expand Down
6 changes: 2 additions & 4 deletions main.c
Expand Up @@ -362,7 +362,6 @@ static void setup_deferred_shading(uint32_t w, uint32_t h)
* (transparent pass is after shading) */
static void start_geometry_pass()
{
//glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);

Expand Down Expand Up @@ -452,15 +451,14 @@ static void start_shading_pass()
glUniform4fv(0, 1, tmp);

glUniform1i(1, _deffered_shading_debug);
glUniformMatrix4fv(2, 1, GL_TRUE, _gi.iVP.f);
glUniformMatrix4fv(3, 1, GL_TRUE, _gi.V.f);
glUniformMatrix4fv(2, 1, GL_TRUE, _gi.iP.f);
}

static void do_shading_pass()
{
tz_vec4 tmp_lights[50];
for (int i=0; i<_gi.nlights; ++i) {
tmp_lights[i] = _gi.light[i]; // in world
tmp_lights[i] = tz_mat4_mulv(&_gi.V, _gi.light[i]); // in world
}

glUniform1i(9, _gi.nlights);
Expand Down

0 comments on commit 82ae86e

Please sign in to comment.