Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: samples/shaders/phong-vertex-anim-glsl.shader

Issue 2821003: o3d-webgl: vertex shader and vertex animation demo (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/o3d-webgl-samples/vertex-shader-animation.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2009, Google Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 // This shader expects to be passed vertices that are part of an x-z plane mesh
33 // because it assumes the normal for each vertex before being offset by the
34 // animation is 0, 1, 0.
35
36 uniform mat4 viewProjection;
37 uniform mat4 world;
38 uniform mat4 worldInverseTranspose;
39 uniform float time;
40
41 attribute vec4 position;
42
43 varying vec3 v_normal;
44 varying vec3 v_worldPosition;
45
46 void main() {
47 vec3 worldPosition = (world * position).xyz;
48
49 float animValue = time + (worldPosition.x + worldPosition.z) * 0.4;
50 float animSin = sin(animValue);
51 float animCos = cos(animValue);
52 vec4 position = vec4(
53 worldPosition.x,
54 worldPosition.y + animSin,
55 worldPosition.z,
56 1);
57 gl_Position = viewProjection * position;
58 vec3 normalTmp = normalize(vec3(animCos, abs(animSin), animCos));
59 v_normal = (worldInverseTranspose * vec4(normalTmp, 0)).xyz;
60 v_worldPosition = position.xyz;
61 }
62
63 // #o3d SplitMarker
64
65 uniform vec3 lightWorldPos;
66 uniform vec4 lightIntensity;
67 uniform vec4 ambientIntensity;
68 uniform vec4 emissive;
69 uniform vec4 ambient;
70 uniform vec4 diffuse;
71 uniform vec4 specular;
72 uniform float shininess;
73 uniform float time;
74 uniform mat4 viewInverse;
75
76 varying vec3 v_normal;
77 varying vec3 v_worldPosition;
78
79 vec4 lit(float l ,float h, float m) {
80 return vec4(1.0,
81 max(l, 0.0),
82 (l > 0.0) ? pow(max(0.0, h), m) : 0.0,
83 1.0);
84 }
85
86 void main() {
87 vec3 surfaceToLight = normalize(lightWorldPos - v_worldPosition);
88 vec3 worldNormal = normalize(v_normal);
89 vec3 surfaceToView = normalize(viewInverse[3].xyz - v_worldPosition);
90 vec3 halfVector = normalize(surfaceToLight + surfaceToView);
91 vec4 litResult = lit(dot(worldNormal, surfaceToLight),
92 dot(worldNormal, halfVector), shininess);
93 vec4 outColor = ambientIntensity * ambient;
94 outColor += lightIntensity * (diffuse * litResult.y +
95 specular * litResult.z);
96 outColor += emissive;
97 gl_FragColor = vec4(outColor.rgb, diffuse.a);
98 }
99
100 // #o3d MatrixLoadOrder RowMajor
OLDNEW
« no previous file with comments | « samples/o3d-webgl-samples/vertex-shader-animation.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698