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

Side by Side Diff: samples/GoogleIO-2009/shaders/checker.shader

Issue 149438: Add Google IO sample. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 11 years, 5 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/GoogleIO-2009/assets/style.css ('k') | samples/GoogleIO-2009/step01.html » ('j') | 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 // The 4x4 world view projection matrix.
33 float4x4 worldViewProjection : WORLDVIEWPROJECTION;
34 float4x4 worldInverseTranspose : WORLDINVERSETRANSPOSE;
35 float4x4 world : WORLD;
36
37 // light position
38 float3 lightWorldPos;
39 float3 lightColor;
40
41 // input parameters for our vertex shader
42 struct VertexShaderInput {
43 float4 position : POSITION;
44 float4 normal : NORMAL;
45 float2 texcoord : TEXCOORD0;
46 };
47
48 // input parameters for our pixel shader
49 struct PixelShaderInput {
50 float4 position : POSITION;
51 float2 texcoord : TEXCOORD0;
52 float3 normal : TEXCOORD1;
53 float3 worldPosition : TEXCOORD2;
54 };
55
56 // function for getting the checker pattern
57 float4 checker(float2 uv) {
58 float checkSize = 10;
59 float fmodResult = fmod(floor(checkSize * uv.x) + floor(checkSize * uv.y),
60 2.0);
61 return (fmodResult < 1) ?
62 float4(0.4, 0.5, 0.5, 1) :
63 float4(0.6, 0.8, 0.8, 1);
64 }
65
66 /**
67 * Our vertex shader. In the vertex shader, we calculate the lighting.
68 * Then we'll combine it with our checker pattern input the pixel shader.
69 */
70 PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
71 PixelShaderInput output;
72
73 // Transform position into clip space.
74 output.position = mul(input.position, worldViewProjection);
75
76 // Transform normal into world space, where we can do lighting
77 // calculations even if the world transform contains scaling.
78 output.normal = mul(input.normal, worldInverseTranspose).xyz;
79
80 // Calculate surface position in world space.
81 output.worldPosition = mul(input.position, world).xyz;
82
83 output.texcoord = input.texcoord;
84
85 return output;
86 }
87
88 /**
89 * Our pixel shader. We take the lighting color we got from the vertex sahder
90 * and combine it with our checker pattern. We only need to use the x
91 * coordinate of our input.col because we gave it uniform color
92 */
93 float4 pixelShaderFunction(PixelShaderInput input): COLOR {
94 float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
95
96 float3 worldNormal = normalize(input.normal);
97
98 // Apply diffuse lighting in world space in case the world transform
99 // contains scaling.
100 float4 check = checker(input.texcoord);
101 float4 directionalIntensity = saturate(dot(worldNormal, surfaceToLight));
102 float4 outColor = directionalIntensity * check;
103 return float4(outColor.rgb, 1);
104 }
105
106 // Here we tell our effect file *which* functions are
107 // our vertex and pixel shaders.
108
109 // #o3d VertexShaderEntryPoint vertexShaderFunction
110 // #o3d PixelShaderEntryPoint pixelShaderFunction
111 // #o3d MatrixLoadOrder RowMajor
OLDNEW
« no previous file with comments | « samples/GoogleIO-2009/assets/style.css ('k') | samples/GoogleIO-2009/step01.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698