From patchwork Wed Jul 13 15:02:21 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: 2682 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 90BA824357 for ; Wed, 13 Jul 2011 15:02:23 +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 402C3A180DE for ; Wed, 13 Jul 2011 15:02:23 +0000 (UTC) Received: by qwb8 with SMTP id 8so4125042qwb.11 for ; Wed, 13 Jul 2011 08:02:22 -0700 (PDT) Received: by 10.229.25.212 with SMTP id a20mr1045712qcc.148.1310569342661; Wed, 13 Jul 2011 08:02:22 -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 hl14cs24251qcb; Wed, 13 Jul 2011 08:02:22 -0700 (PDT) Received: by 10.227.205.12 with SMTP id fo12mr1106159wbb.70.1310569341630; Wed, 13 Jul 2011 08:02:21 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id ff9si30348436wbb.11.2011.07.13.08.02.21; Wed, 13 Jul 2011 08:02:21 -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 1Qh0xB-0006Rv-2E for ; Wed, 13 Jul 2011 15:02:21 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id 0BA682E8030 for ; Wed, 13 Jul 2011 15:02:21 +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: <20110713150221.2914.58191.launchpad@loganberry.canonical.com> Date: Wed, 13 Jul 2011 15:02:21 -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: a10d51706ec16c70dd4093861d048a984fa7e908 ------------------------------------------------------------ revno: 108 committer: Alexandros Frantzis branch nick: trunk timestamp: Wed 2011-07-13 18:01:07 +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:01:07 +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:01:07 +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 = 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); }