From patchwork Tue Jul 12 18:01:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Barker X-Patchwork-Id: 2673 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id F1D2123F55 for ; Tue, 12 Jul 2011 18:01:13 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id A09D8A1889B for ; Tue, 12 Jul 2011 18:01:13 +0000 (UTC) Received: by qwb8 with SMTP id 8so3553852qwb.11 for ; Tue, 12 Jul 2011 11:01:13 -0700 (PDT) Received: by 10.229.25.212 with SMTP id a20mr222125qcc.148.1310493673004; Tue, 12 Jul 2011 11:01:13 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs251241qcb; Tue, 12 Jul 2011 11:01:11 -0700 (PDT) Received: by 10.216.24.82 with SMTP id w60mr152813wew.99.1310493670432; Tue, 12 Jul 2011 11:01:10 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id g64si15835982wes.36.2011.07.12.11.01.10; Tue, 12 Jul 2011 11:01:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QghGf-0002VN-Kx for ; Tue, 12 Jul 2011 18:01:09 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 7B3BC2E84FB for ; Tue, 12 Jul 2011 18:01:09 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: glmark2 X-Launchpad-Branch: ~glmark2-dev/glmark2/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 106 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 106: Merge advanced lighting development branch into trunk. Message-Id: <20110712180109.27694.6154.launchpad@loganberry.canonical.com> Date: Tue, 12 Jul 2011 18:01:09 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13388"; Instance="initZopeless config overlay" X-Launchpad-Hash: 9b32691d8bbd01c1bf5b23bf2fb7a3c121a0e708 Merge authors: Jesse Barker (jesse-barker) ------------------------------------------------------------ revno: 106 [merge] committer: Jesse Barker branch nick: trunk timestamp: Tue 2011-07-12 10:58:48 -0700 message: Merge advanced lighting development branch into trunk. added: data/shaders/light-phong.frag data/shaders/light-phong.vert modified: data/shaders/light-advanced.frag src/main.cpp src/scene-shading.cpp --- lp:glmark2 https://code.launchpad.net/~glmark2-dev/glmark2/trunk You are subscribed to branch lp:glmark2. To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription === modified file 'data/shaders/light-advanced.frag' --- data/shaders/light-advanced.frag 2010-11-19 13:11:20 +0000 +++ data/shaders/light-advanced.frag 2011-07-12 17:53:10 +0000 @@ -2,35 +2,34 @@ precision mediump float; #endif -uniform vec3 LightSourceAmbient; -uniform vec3 LightSourceDiffuse; -uniform vec3 LightSourceSpecular; -uniform vec3 MaterialAmbient; -uniform vec3 MaterialDiffuse; -uniform vec3 MaterialSpecular; -uniform vec4 MaterialColor; - varying vec3 Normal; varying vec3 Light; varying vec3 HalfVector; void main(void) { + const vec4 LightSourceAmbient = vec4(0.1, 0.1, 0.1, 1.0); + const vec4 LightSourceDiffuse = vec4(0.8, 0.8, 0.8, 1.0); + const vec4 LightSourceSpecular = vec4(0.8, 0.8, 0.8, 1.0); + const vec4 MaterialAmbient = vec4(1.0, 1.0, 1.0, 1.0); + const vec4 MaterialDiffuse = vec4(0.0, 0.0, 1.0, 1.0); + const vec4 MaterialSpecular = vec4(1.0, 1.0, 1.0, 1.0); + const float MaterialShininess = 100.0; + vec3 N = normalize(Normal); vec3 L = normalize(Light); vec3 H = normalize(HalfVector); // Calculate the diffuse color according to Lambertian reflectance - vec3 diffuse = MaterialDiffuse * LightSourceDiffuse * max(dot(N, L), 0.0); + vec4 diffuse = MaterialDiffuse * LightSourceDiffuse * max(dot(N, L), 0.0); // Calculate the ambient color - vec3 ambient = MaterialAmbient * LightSourceAmbient; + vec4 ambient = MaterialAmbient * LightSourceAmbient; // Calculate the specular color according to the Blinn-Phong model - vec3 specular = MaterialSpecular * LightSourceSpecular * - pow(max(dot(N,H), 0.0), 100.0); + vec4 specular = MaterialSpecular * LightSourceSpecular * + pow(max(dot(N,H), 0.0), MaterialShininess); // Calculate the final color - gl_FragColor = vec4(ambient, 1.0) + vec4(specular, 1.0) + - vec4(diffuse, 1.0) * MaterialColor; + gl_FragColor = ambient + specular + diffuse; } === added file 'data/shaders/light-phong.frag' --- data/shaders/light-phong.frag 1970-01-01 00:00:00 +0000 +++ data/shaders/light-phong.frag 2011-07-12 17:53:10 +0000 @@ -0,0 +1,30 @@ +#ifdef GL_ES +precision mediump float; +#endif + +uniform vec4 LightSourcePosition; + +varying vec3 vertex_normal; +varying vec4 vertex_position; + +void main(void) +{ + const vec4 lightAmbient = vec4(0.1, 0.1, 0.1, 1.0); + const vec4 lightDiffuse = vec4(0.8, 0.8, 0.8, 1.0); + const vec4 lightSpecular = vec4(0.8, 0.8, 0.8, 1.0); + const vec4 matAmbient = vec4(1.0, 1.0, 1.0, 1.0); + const vec4 matDiffuse = vec4(0.0, 0.0, 1.0, 1.0); + const vec4 matSpecular = vec4(1.0, 1.0, 1.0, 1.0); + const float matShininess = 100.0; + vec3 eye_direction = normalize(-vertex_position.xyz); + vec3 light_direction = normalize(LightSourcePosition.xyz/LightSourcePosition.w - + vertex_position.xyz/vertex_position.w); + vec3 normalized_normal = normalize(vertex_normal); + vec3 reflection = reflect(-light_direction, normalized_normal); + float specularTerm = pow(max(0.0, dot(reflection, eye_direction)), matShininess); + float diffuseTerm = max(0.0, dot(normalized_normal, light_direction)); + vec4 specular = (lightSpecular * matSpecular); + vec4 ambient = (lightAmbient * matAmbient); + vec4 diffuse = (lightDiffuse * matDiffuse); + gl_FragColor = (specular * specularTerm) + ambient + (diffuse * diffuseTerm); +} === added file 'data/shaders/light-phong.vert' --- data/shaders/light-phong.vert 1970-01-01 00:00:00 +0000 +++ data/shaders/light-phong.vert 2011-07-12 17:53:10 +0000 @@ -0,0 +1,23 @@ +attribute vec3 position; +attribute vec3 normal; + +uniform mat4 ModelViewProjectionMatrix; +uniform mat4 NormalMatrix; +uniform mat4 ModelViewMatrix; + +varying vec3 vertex_normal; +varying vec4 vertex_position; + +void main(void) +{ + vec4 current_position = vec4(position, 1.0); + + // Transform the normal to eye coordinates + vertex_normal = normalize(vec3(NormalMatrix * vec4(normal, 1.0))); + + // Transform the current position to eye coordinates + vertex_position = ModelViewMatrix * current_position; + + // Transform the current position to clip coordinates + gl_Position = ModelViewProjectionMatrix * current_position; +} === modified file 'src/main.cpp' --- src/main.cpp 2011-07-08 13:46:32 +0000 +++ src/main.cpp 2011-07-12 17:53:10 +0000 @@ -46,6 +46,7 @@ "texture:texture-filter=linear", "texture:texture-filter=mipmap", "shading:shading=gouraud", + "shading:shading=blinn-phong-inf", "shading:shading=phong", "conditionals:vertex-steps=0:fragment-steps=0", "conditionals:vertex-steps=0:fragment-steps=5", === modified file 'src/scene-shading.cpp' --- src/scene-shading.cpp 2011-07-05 13:45:41 +0000 +++ src/scene-shading.cpp 2011-07-12 17:53:10 +0000 @@ -33,7 +33,7 @@ Scene(pCanvas, "shading") { mOptions["shading"] = Scene::Option("shading", "gouraud", - "[gouraud, phong]"); + "[gouraud, blinn-phong-inf, phong]"); } SceneShading::~SceneShading() @@ -74,15 +74,8 @@ { Scene::setup(); - static const LibMatrix::vec3 lightAmbient(0.1f, 0.1f, 0.1f); - static const LibMatrix::vec3 lightDiffuse(0.8f, 0.8f, 0.8f); - static const LibMatrix::vec3 lightSpecular(0.8f, 0.8f, 0.8f); static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f); - - static const LibMatrix::vec3 materialAmbient(1.0f, 1.0f, 1.0f); - static const LibMatrix::vec3 materialDiffuse(1.0f, 1.0f, 1.0f); - static const LibMatrix::vec3 materialSpecular(1.0f, 1.0f, 1.0f); - static const LibMatrix::vec4 materialColor(0.0f, 0.0f, 1.0f, 1.0f); + static const LibMatrix::vec4 materialDiffuse(0.0f, 0.0f, 1.0f, 1.0f); std::string vtx_shader_filename; std::string frg_shader_filename; @@ -92,10 +85,14 @@ vtx_shader_filename = GLMARK_DATA_PATH"/shaders/light-basic.vert"; frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-basic.frag"; } - else if (shading == "phong") { + else if (shading == "blinn-phong-inf") { vtx_shader_filename = GLMARK_DATA_PATH"/shaders/light-advanced.vert"; frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-advanced.frag"; } + else if (shading == "phong") { + vtx_shader_filename = GLMARK_DATA_PATH"/shaders/light-phong.vert"; + frg_shader_filename = GLMARK_DATA_PATH"/shaders/light-phong.frag"; + } if (!Scene::load_shaders_from_files(mProgram, vtx_shader_filename, frg_shader_filename)) @@ -111,17 +108,8 @@ mMesh.set_attrib_locations(attrib_locations); // Load lighting and material uniforms - mProgram.loadUniformVector(lightAmbient, "LightSourceAmbient"); mProgram.loadUniformVector(lightPosition, "LightSourcePosition"); - mProgram.loadUniformVector(lightDiffuse, "LightSourceDiffuse"); - mProgram.loadUniformVector(lightSpecular, "LightSourceSpecular"); - - mProgram.loadUniformVector(materialAmbient, "MaterialAmbient"); - mProgram.loadUniformVector(materialDiffuse, "MaterialDiffuse"); - mProgram.loadUniformVector(materialSpecular, "MaterialSpecular"); - mProgram.loadUniformVector(materialColor, "MaterialColor"); - - // Calculate and load the half vector + mProgram.loadUniformVector(materialDiffuse, "MaterialColor"); LibMatrix::vec3 halfVector(lightPosition[0], lightPosition[1], lightPosition[2]); halfVector.normalize(); halfVector += LibMatrix::vec3(0.0, 0.0, 1.0); @@ -179,6 +167,9 @@ normal_matrix.inverse().transpose(); mProgram.loadUniformMatrix(normal_matrix, "NormalMatrix"); + // Load the modelview matrix itself + mProgram.loadUniformMatrix(model_view.getCurrent(), "ModelViewMatrix"); + mMesh.render_vbo(); }