summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2011-03-23 01:54:33 -0700
committerKenneth Graunke <kenneth@whitecape.org>2011-03-23 02:22:51 -0700
commit2d53c1ff17dac068855607f2722cbd078ef1fca2 (patch)
tree99d263cffb7820b2865afad8e867e623523b2d30
parentd133fb5f644ad6f4edd3526ebc064a39f414f0b6 (diff)
DRIVER BUGSdriverbugs
-rwxr-xr-xsrc/main.cpp43
-rwxr-xr-xsrc/phong.frag7
-rwxr-xr-xsrc/phong.vert13
3 files changed, 49 insertions, 14 deletions
diff --git a/src/main.cpp b/src/main.cpp
index cf56f38..e934eca 100755
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,8 +36,10 @@ static bool done = false;
static int win_width, win_height;
static GLuint main_fbo;
-static GLuint main_fbo_tex;
-static GLuint main_fbo_depth_tex;
+static GLuint color_tex;
+static GLuint depth_tex;
+static GLuint es_pos_tex;
+static GLuint es_normal_tex;
static GLuint prog;
static GLuint sampler_slot;
@@ -46,8 +48,10 @@ static void
Redisplay()
{
// Render scene to FBO
- glCullFace(GL_BACK);
glBindFramebuffer(GL_FRAMEBUFFER, main_fbo);
+ // ...but first, turn on MRT:
+ GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
+ glDrawBuffers(3, buffers);
glClearColor(0.3, 0.3, 0.3, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Scene::Reshape(win_width, win_height);
@@ -57,7 +61,7 @@ Redisplay()
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glUseProgram(prog);
- glBindTexture(GL_TEXTURE_2D, main_fbo_tex);
+ glBindTexture(GL_TEXTURE_2D, color_tex);
glUniform1i(sampler_slot, 0);
GLfloat quad[4][2] = {{-1, 1}, {-1, -1}, {1, 1}, {1, -1}};
@@ -125,23 +129,42 @@ Reshape(int width, int height)
glGenFramebuffers(1, &main_fbo);
glBindFramebuffer(GL_FRAMEBUFFER, main_fbo);
- glGenTextures(1, &main_fbo_tex);
- glBindTexture(GL_TEXTURE_2D, main_fbo_tex);
+ glGenTextures(1, &color_tex);
+ glBindTexture(GL_TEXTURE_2D, color_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, main_fbo_tex, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color_tex, 0);
- glGenTextures(1, &main_fbo_depth_tex);
- glBindTexture(GL_TEXTURE_2D, main_fbo_depth_tex);
+ glGenTextures(1, &es_pos_tex);
+ glBindTexture(GL_TEXTURE_2D, es_pos_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, es_pos_tex, 0);
+
+ glGenTextures(1, &es_normal_tex);
+ glBindTexture(GL_TEXTURE_2D, es_normal_tex);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, es_normal_tex, 0);
+
+
+ glGenTextures(1, &depth_tex);
+ glBindTexture(GL_TEXTURE_2D, depth_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, main_fbo_depth_tex, 0);
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_tex, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
printf("main FBO not complete\n");
diff --git a/src/phong.frag b/src/phong.frag
index 0ca8241..801a9ce 100755
--- a/src/phong.frag
+++ b/src/phong.frag
@@ -2,6 +2,9 @@
varying vec3 light_ss;
varying vec3 eye_ss;
+varying vec3 pos_es;
+varying vec3 normal_es;
+
const vec3 base_color = vec3(1.0, 0.7, 0.0);
/* Specular exponent.
@@ -19,5 +22,7 @@ void main(void)
vec4 light = step(0.0, dot(n, l)) * vec4(diff + vec3(spec), 1.0);
- gl_FragColor = light;
+ gl_FragData[0] = light;
+ gl_FragData[1] = vec4(pos_es, 1);
+ gl_FragData[2] = vec4(normal_es, 1);
}
diff --git a/src/phong.vert b/src/phong.vert
index 9a83ba8..356e953 100755
--- a/src/phong.vert
+++ b/src/phong.vert
@@ -17,19 +17,26 @@ varying vec3 light_ss;
// ???
varying vec3 eye_ss;
+varying vec3 pos_es;
+varying vec3 normal_es;
+
void main(void)
{
gl_Position = mvp * gl_Vertex;
+ vec3 vertex_pos_es = vec3(mv * gl_Vertex);
+ vec3 norm_es = vec3(mv * normal);
+
vec3 tangent_es = vec3(mv * tangent);
- vec3 normal_es = vec3(mv * normal);
- vec3 bitangent_es = cross(normal_es, tangent_es);
+ vec3 bitangent_es = cross(norm_es, tangent_es);
mat3 tbn = mat3(tangent_es, bitangent_es, normal_es);
- vec3 vertex_pos_es = vec3(mv * gl_Vertex);
vec3 light_direction_es = vec3(light_pos_es) - vertex_pos_es;
/* Surface space vectors for lighting */
light_ss = normalize(light_direction_es * tbn);
eye_ss = -normalize(vertex_pos_es * tbn);
+ pos_es = vertex_pos_es;
+ normal_es = norm_es;
+
}