summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2010-03-23 17:54:15 -0700
committerEric Anholt <eric@anholt.net>2010-03-23 17:54:15 -0700
commitbe1d1798e01d08be07b9e223fff7db6f0765e9ee (patch)
tree566aa492f735e533cd535a9c100887937deb623a
parent4522ad56b53efdbe0e20209ec857d63206b843bf (diff)
glsl-orangebook-ch06-bump: New testcase for the Orange Book bumpmapping shader.
This regressed on i965 at some point, so I wanted to test it.
-rw-r--r--tests/all.tests1
-rw-r--r--tests/shaders/CMakeLists.txt1
-rw-r--r--tests/shaders/glsl-orangebook-ch06-bump.c120
-rw-r--r--tests/shaders/glsl-orangebook-ch06-bump.frag41
-rw-r--r--tests/shaders/glsl-orangebook-ch06-bump.vert38
5 files changed, 201 insertions, 0 deletions
diff --git a/tests/all.tests b/tests/all.tests
index d989bde1..478f51bc 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -162,6 +162,7 @@ add_plain_test(shaders, 'glsl-fs-mix')
add_plain_test(shaders, 'glsl-fs-mix-constant')
add_plain_test(shaders, 'glsl-fs-sqrt-branch')
add_plain_test(shaders, 'glsl-fs-sqrt-zero')
+add_plain_test(shaders, 'glsl-orangebook-ch06-bump')
add_plain_test(shaders, 'glsl-vs-arrays')
add_plain_test(shaders, 'glsl-vs-functions')
add_plain_test(shaders, 'glsl-vs-if')
diff --git a/tests/shaders/CMakeLists.txt b/tests/shaders/CMakeLists.txt
index d049321f..908f6d28 100644
--- a/tests/shaders/CMakeLists.txt
+++ b/tests/shaders/CMakeLists.txt
@@ -43,6 +43,7 @@ add_executable (glsl-arb-fragment-coord-conventions glsl-arb-fragment-coord-conv
add_executable (glsl-arb-fragment-coord-conventions-define glsl-arb-fragment-coord-conventions-define.c)
add_executable (glsl-bug-22603 glsl-bug-22603.c)
add_executable (glsl-dlist-getattriblocation glsl-dlist-getattriblocation.c)
+add_executable (glsl-orangebook-ch06-bump glsl-orangebook-ch06-bump.c)
add_executable (glsl-reload-source glsl-reload-source.c)
add_executable (glsl-unused-varying glsl-unused-varying.c)
add_executable (glsl-uniform-update glsl-uniform-update.c)
diff --git a/tests/shaders/glsl-orangebook-ch06-bump.c b/tests/shaders/glsl-orangebook-ch06-bump.c
new file mode 100644
index 00000000..59624fd5
--- /dev/null
+++ b/tests/shaders/glsl-orangebook-ch06-bump.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ * Eric Anholt <eric@anholt.net>
+ *
+ */
+
+/** @file glsl-orangebook-ch06-bump.c
+ *
+ * Tests that the Orange Book's chapter 6 shader for procedural bumpmapping
+ * works correctly.
+ */
+
+#include "piglit-util.h"
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+static int bump_density_location, bump_size_location;
+static int specular_factor_location, surface_color_location;
+static int light_position_location, tangent_attrib;
+static GLint prog;
+
+enum piglit_result
+piglit_display(void)
+{
+ GLboolean pass = GL_TRUE;
+ static const float surface_color[3] = {0.7, 0.6, 0.18};
+ static const float specular_highlight[3] = {1.0, 1.0, 0.674};
+ static const float bump_dark[3] = {0.662, 0.568, 0.168};
+ static const float bump_light[3] = {0.937, 0.839, 0.443};
+ float light_position[3] = {0.0, 0.0, 1.0};
+ float w = piglit_width;
+ float h = piglit_height;
+ float bump_x = w * 7 / 8;
+ float bump_y = h * 7 / 8;
+
+ piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
+
+ glClearColor(0.5, 0.5, 0.5, 0.5);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glUniform1f(bump_density_location, 4);
+ glUniform1f(bump_size_location, 0.15);
+ glUniform1f(specular_factor_location, 0.5);
+ glUniform3fv(surface_color_location, 1, surface_color);
+ glUniform3fv(light_position_location, 1, light_position);
+
+ glTranslatef(0, 0, -0.5);
+ glNormal3f(0.0, 0.0, 1.0);
+ glVertexAttrib3f(tangent_attrib, 1.0, 0.0, 0.0);
+ piglit_draw_rect_tex(0, 0, piglit_width, piglit_height,
+ 0, 0, 1, 1);
+
+ /* Corners of the image: A fully-specular point, and a fully-non-specular point. */
+ pass &= piglit_probe_pixel_rgb(0, 0, specular_highlight);
+ pass &= piglit_probe_pixel_rgb(piglit_width - 1, piglit_height - 1, surface_color);
+
+ /* Look at the top right bump -- does it have a lit part and an unlit part? */
+ pass &= piglit_probe_pixel_rgb(bump_x + w / 16, bump_y + h / 16, bump_dark);
+ pass &= piglit_probe_pixel_rgb(bump_x - w / 16, bump_y - h / 16, bump_light);
+
+ glutSwapBuffers();
+
+ return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLint vs, fs;
+
+ if (!GLEW_VERSION_2_0) {
+ printf("Requires OpenGL 2.0\n");
+ piglit_report_result(PIGLIT_SKIP);
+ }
+
+ vs = piglit_compile_shader(GL_VERTEX_SHADER,
+ "shaders/glsl-orangebook-ch06-bump.vert");
+ fs = piglit_compile_shader(GL_FRAGMENT_SHADER,
+ "shaders/glsl-orangebook-ch06-bump.frag");
+
+ prog = piglit_link_simple_program(vs, fs);
+
+ glUseProgram(prog);
+
+ bump_density_location = glGetUniformLocation(prog, "BumpDensity");
+ bump_size_location = glGetUniformLocation(prog, "BumpSize");
+ specular_factor_location = glGetUniformLocation(prog, "SpecularFactor");
+ surface_color_location = glGetUniformLocation(prog, "SurfaceColor");
+ light_position_location = glGetUniformLocation(prog, "LightPosition");
+ assert(bump_density_location != -1);
+ assert(bump_size_location != -1);
+ assert(specular_factor_location != -1);
+ assert(surface_color_location != -1);
+ assert(light_position_location != -1);
+
+ tangent_attrib = glGetAttribLocation(prog, "Tangent");
+ assert(tangent_attrib != -1);
+}
diff --git a/tests/shaders/glsl-orangebook-ch06-bump.frag b/tests/shaders/glsl-orangebook-ch06-bump.frag
new file mode 100644
index 00000000..063576f5
--- /dev/null
+++ b/tests/shaders/glsl-orangebook-ch06-bump.frag
@@ -0,0 +1,41 @@
+//
+// Fragment shader for procedural bumps
+//
+// Authors: John Kessenich, Randi Rost
+//
+// Copyright (c) 2002-2006 3Dlabs Inc. Ltd.
+//
+// See 3Dlabs-License.txt for license information
+//
+
+varying vec3 LightDir;
+varying vec3 EyeDir;
+
+uniform vec3 SurfaceColor; // = (0.7, 0.6, 0.18)
+uniform float BumpDensity; // = 16.0
+uniform float BumpSize; // = 0.15
+uniform float SpecularFactor; // = 0.5
+
+void main()
+{
+ vec3 litColor;
+ vec2 c = BumpDensity * gl_TexCoord[0].st;
+ vec2 p = fract(c) - vec2(0.5);
+
+ float d, f;
+ d = p.x * p.x + p.y * p.y;
+ f = 1.0 / sqrt(d + 1.0);
+
+ if (d >= BumpSize)
+ { p = vec2(0.0); f = 1.0; }
+
+ vec3 normDelta = vec3(p.x, p.y, 1.0) * f;
+ litColor = SurfaceColor * max(dot(normDelta, LightDir), 0.0);
+ vec3 reflectDir = reflect(LightDir, normDelta);
+
+ float spec = max(dot(EyeDir, reflectDir), 0.0);
+ spec *= SpecularFactor;
+ litColor = min(litColor + spec, vec3(1.0));
+
+ gl_FragColor = vec4(litColor, 1.0);
+}
diff --git a/tests/shaders/glsl-orangebook-ch06-bump.vert b/tests/shaders/glsl-orangebook-ch06-bump.vert
new file mode 100644
index 00000000..d3d19f62
--- /dev/null
+++ b/tests/shaders/glsl-orangebook-ch06-bump.vert
@@ -0,0 +1,38 @@
+//
+// Vertex shader for procedural bumps
+//
+// Authors: Randi Rost, John Kessenich
+//
+// Copyright (c) 2002-2006 3Dlabs Inc. Ltd.
+//
+// See 3Dlabs-License.txt for license information
+//
+
+varying vec3 LightDir;
+varying vec3 EyeDir;
+
+uniform vec3 LightPosition;
+
+attribute vec3 Tangent;
+
+void main()
+{
+ EyeDir = vec3(gl_ModelViewMatrix * gl_Vertex);
+ gl_Position = ftransform();
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+
+ vec3 n = normalize(gl_NormalMatrix * gl_Normal);
+ vec3 t = normalize(gl_NormalMatrix * Tangent);
+ vec3 b = cross(n, t);
+
+ vec3 v;
+ v.x = dot(LightPosition, t);
+ v.y = dot(LightPosition, b);
+ v.z = dot(LightPosition, n);
+ LightDir = normalize(v);
+
+ v.x = dot(EyeDir, t);
+ v.y = dot(EyeDir, b);
+ v.z = dot(EyeDir, n);
+ EyeDir = normalize(v);
+}