From patchwork Thu Jun 28 16:20:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesse Barker X-Patchwork-Id: 9689 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 AFE6F23E37 for ; Thu, 28 Jun 2012 16:20:18 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id 5EA9DA18BF5 for ; Thu, 28 Jun 2012 16:20:18 +0000 (UTC) Received: by yenq6 with SMTP id q6so2194506yen.11 for ; Thu, 28 Jun 2012 09:20:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :content-type:mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state; bh=I/Z2mVkLVlfTxumD1ZF5sQf8/0uECwnY2z1l1srCVns=; b=nz2F+qGQJZzxNH+BFtQQLlglKdfoyhIRitEV9CxkY8WxfdDM0IoJV6A3MR0FYaTsQq yTFJ8d8rKgf5vh1uR6eJMYLeVMRAFc19zMDmBsNBpZnfvG7LWcNQ6fMkdESFS5bhNLRe M+3kHd0Z1oPqQa+C9ftB53OdEXgPADKSOr4g0uKm0lrPhwF0mygXNiWCnTPD6HcxncvB 8LvcV9xlH2fPY5K29R6+Li/IqZfkmFk7PIBkg8hb2wrHqSNBjaSmlwaTcoOqffzSb8Yk gSdaPh9rHb0XpqK3ZnwvobD5J0HLRF9IdXePpjHzMxFHBDbGXM6J2Me3MI6W16hxA5Tj RnEA== Received: by 10.50.163.99 with SMTP id yh3mr302861igb.53.1340900417466; Thu, 28 Jun 2012 09:20:17 -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.231.24.148 with SMTP id v20csp46160ibb; Thu, 28 Jun 2012 09:20:16 -0700 (PDT) Received: by 10.216.240.72 with SMTP id d50mr1432767wer.29.1340900415668; Thu, 28 Jun 2012 09:20:15 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id 55si27724246wet.130.2012.06.28.09.20.15 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 28 Jun 2012 09:20:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1SkHS3-00081J-3S for ; Thu, 28 Jun 2012 16:20:15 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 0A3AFE00F3 for ; Thu, 28 Jun 2012 16:20:15 +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: 227 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~glmark2-dev/glmark2/trunk] Rev 227: Merge of lp:~glmark2-dev/glmark2/texgen Message-Id: <20120628162015.27727.57099.launchpad@ackee.canonical.com> Date: Thu, 28 Jun 2012 16:20:15 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="15505"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 7aad49a7c2949f8412b0e4328a733c9fa1ee2044 X-Gm-Message-State: ALoCoQkAcOq6GTTP3oT6q2AKEWzbnWUXa+IklOuJV375novF7cETf293M8NQQHDoRZBT4sD+8ko6 Merge authors: Jesse Barker (jesse-barker) ------------------------------------------------------------ revno: 227 [merge] committer: Jesse Barker branch nick: trunk timestamp: Thu 2012-06-28 09:16:43 -0700 message: Merge of lp:~glmark2-dev/glmark2/texgen SceneTexture: Add an option to compute the texture coordinates in the shader rather than supplying them as a vertex attribute. This also includes a new shader to support this. added: data/shaders/light-basic-texgen.vert modified: src/scene-texture.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 === added file 'data/shaders/light-basic-texgen.vert' --- data/shaders/light-basic-texgen.vert 1970-01-01 00:00:00 +0000 +++ data/shaders/light-basic-texgen.vert 2012-06-26 22:41:07 +0000 @@ -0,0 +1,30 @@ +attribute vec3 position; +attribute vec3 normal; + +uniform mat4 ModelViewProjectionMatrix; +uniform mat4 NormalMatrix; +uniform vec3 CenterPoint; + +varying vec4 Color; +varying vec2 TextureCoord; + +void main(void) +{ + // Transform the normal to eye coordinates + vec3 N = normalize(vec3(NormalMatrix * vec4(normal, 1.0))); + + // The LightSourcePosition is actually its direction for directional light + vec3 L = normalize(LightSourcePosition.xyz); + + // Multiply the diffuse value by the vertex color (which is fixed in this case) + // to get the actual color that we will use to draw this vertex with + float diffuse = max(dot(N, L), 0.0); + Color = vec4(diffuse * MaterialDiffuse.rgb, MaterialDiffuse.a); + + // Compute the texture coordinate and as a varying + vec3 vnorm = normalize(position - CenterPoint); + TextureCoord = asin(vnorm.xy) / PI + 0.5; + + // Transform the position to clip coordinates + gl_Position = ModelViewProjectionMatrix * vec4(position, 1.0); +} === modified file 'src/scene-texture.cpp' --- src/scene-texture.cpp 2012-05-22 12:26:43 +0000 +++ src/scene-texture.cpp 2012-06-26 22:41:07 +0000 @@ -78,6 +78,8 @@ optionDesc += "]"; options_["texture"] = Scene::Option("texture", "crate-base", optionDesc); + options_["texgen"] = Scene::Option("texgen", "false", + "Whether to generate texcoords in the shader"); } SceneTexture::~SceneTexture() @@ -106,6 +108,7 @@ Scene::setup(); static const std::string vtx_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic.vert"); + static const std::string vtx_shader_texgen_filename(GLMARK_DATA_PATH"/shaders/light-basic-texgen.vert"); static const std::string frg_shader_filename(GLMARK_DATA_PATH"/shaders/light-basic-tex.frag"); static const std::string frg_shader_bilinear_filename(GLMARK_DATA_PATH"/shaders/light-basic-tex-bilinear.frag"); static const LibMatrix::vec4 lightPosition(20.0f, 20.0f, 10.0f, 1.0f); @@ -138,7 +141,15 @@ min_filter, mag_filter, 0); // Load shaders - ShaderSource vtx_source(vtx_shader_filename); + bool doTexGen(options_["texgen"].value == "true"); + ShaderSource vtx_source; + if (doTexGen) { + vtx_source.append_file(vtx_shader_texgen_filename); + vtx_source.add_const("PI", static_cast(M_PI)); + } + else { + vtx_source.append_file(vtx_shader_filename); + } ShaderSource frg_source; if (filter == "linear-shader") { frg_source.append_file(frg_shader_bilinear_filename); @@ -196,7 +207,14 @@ if (model.needTexcoords()) model.calculate_texcoords(); model.calculate_normals(); - model.convert_to_mesh(mesh_); + // Tell the converter which attributes we care about + std::vector > attribs; + attribs.push_back(std::pair(Model::AttribTypePosition, 3)); + attribs.push_back(std::pair(Model::AttribTypeNormal, 3)); + if (!doTexGen) { + attribs.push_back(std::pair(Model::AttribTypeTexcoord, 2)); + } + model.convert_to_mesh(mesh_, attribs); mesh_.build_vbo(); // Calculate a projection matrix that is a good fit for the model @@ -219,7 +237,12 @@ std::vector attrib_locations; attrib_locations.push_back(program_["position"].location()); attrib_locations.push_back(program_["normal"].location()); - attrib_locations.push_back(program_["texcoord"].location()); + if (doTexGen) { + program_["CenterPoint"] = centerVec_; + } + else { + attrib_locations.push_back(program_["texcoord"].location()); + } mesh_.set_attrib_locations(attrib_locations); currentFrame_ = 0;