From patchwork Wed Jul 13 15:05:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 2683 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 BF8A824357 for ; Wed, 13 Jul 2011 15:05:38 +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 8FF90A18727 for ; Wed, 13 Jul 2011 15:05:38 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so4127914qwb.11 for ; Wed, 13 Jul 2011 08:05:38 -0700 (PDT) Received: by 10.229.217.3 with SMTP id hk3mr1178529qcb.38.1310569538067; Wed, 13 Jul 2011 08:05:38 -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 hl14cs24376qcb; Wed, 13 Jul 2011 08:05:37 -0700 (PDT) Received: by 10.216.145.234 with SMTP id p84mr1027460wej.24.1310569536334; Wed, 13 Jul 2011 08:05:36 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id w54si12549891wec.141.2011.07.13.08.05.35; Wed, 13 Jul 2011 08:05:36 -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 1Qh10J-0007fv-OV for ; Wed, 13 Jul 2011 15:05:35 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id B27192E84F6 for ; Wed, 13 Jul 2011 15:05:35 +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: 108 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 108: Use uniforms in the fragment shader for the light and the half vector in light-advanced. Message-Id: <20110713150535.3163.6418.launchpad@loganberry.canonical.com> Date: Wed, 13 Jul 2011 15:05:35 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13405"; Instance="initZopeless config overlay" X-Launchpad-Hash: f9b90e04e36c71add049096c357371880465fcc5 ------------------------------------------------------------ revno: 108 committer: Alexandros Frantzis branch nick: trunk timestamp: Wed 2011-07-13 18:03:43 +0300 message: Use uniforms in the fragment shader for the light and the half vector in light-advanced. In the lighting model we are using here (Blinn-Phong with light at infinity, viewer at infinity), the light position/direction and the half vector is constant for the all the vertices/fragments. Therefore, there is no need to use a varying for them, we can access them as uniforms. modified: data/shaders/light-advanced.frag data/shaders/light-advanced.vert --- 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 2011-07-12 17:53:10 +0000 +++ data/shaders/light-advanced.frag 2011-07-13 15:03:43 +0000 @@ -2,9 +2,10 @@ precision mediump float; #endif +uniform vec4 LightSourcePosition; +uniform vec3 LightSourceHalfVector; + varying vec3 Normal; -varying vec3 Light; -varying vec3 HalfVector; void main(void) { @@ -17,8 +18,12 @@ const float MaterialShininess = 100.0; vec3 N = normalize(Normal); - vec3 L = normalize(Light); - vec3 H = normalize(HalfVector); + + // In the lighting model we are using here (Blinn-Phong with light at + // infinity, viewer at infinity), the light position/direction and the + // half vector is constant for the all the fragments. + vec3 L = normalize(LightSourcePosition.xyz); + vec3 H = normalize(LightSourceHalfVector); // Calculate the diffuse color according to Lambertian reflectance vec4 diffuse = MaterialDiffuse * LightSourceDiffuse * max(dot(N, L), 0.0); === modified file 'data/shaders/light-advanced.vert' --- data/shaders/light-advanced.vert 2010-07-09 13:34:12 +0000 +++ data/shaders/light-advanced.vert 2011-07-13 15:03:43 +0000 @@ -3,25 +3,14 @@ uniform mat4 ModelViewProjectionMatrix; uniform mat4 NormalMatrix; -uniform vec4 LightSourcePosition; -uniform vec3 LightSourceHalfVector; varying vec3 Normal; -varying vec3 Light; -varying vec3 HalfVector; void main(void) -{ +{ // Transform the normal to eye coordinates - Normal = normalize(vec3(NormalMatrix * vec4(normal, 1.0))); - - // The LightSourcePosition is actually its direction for directional light - Light = normalize(LightSourcePosition.xyz); - - // The HalfVector is used in the Blinn-Phong shading model for calculating - // specular lighting. - HalfVector = normalize(LightSourceHalfVector); + Normal = normalize(vec3(NormalMatrix * vec4(normal, 1.0))); // Transform the position to clip coordinates - gl_Position = ModelViewProjectionMatrix * vec4(position, 1.0); + gl_Position = ModelViewProjectionMatrix * vec4(position, 1.0); }