summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
authorgman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-29 22:48:59 +0000
committergman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-29 22:48:59 +0000
commit27409cfb27b972cce0bc3e96f0afe729553d1c40 (patch)
tree263db28c6e8d63e4aa7d95b3c510766116be0857 /o3d
parenta079da32ff1691e8131080db4579175dfc38361d (diff)
downloadchromium_src-27409cfb27b972cce0bc3e96f0afe729553d1c40.zip
chromium_src-27409cfb27b972cce0bc3e96f0afe729553d1c40.tar.gz
chromium_src-27409cfb27b972cce0bc3e96f0afe729553d1c40.tar.bz2
Added a toon shader to shader-test
Still needs an outline shader. Because we can't do atomic commits the screenshot for this is in another CL Review URL: http://codereview.chromium.org/126208 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19541 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r--o3d/DEPS2
-rw-r--r--o3d/DEPS_gyp2
-rw-r--r--o3d/samples/shader-test.html61
-rwxr-xr-xo3d/samples/shaders/toon.shader98
4 files changed, 135 insertions, 28 deletions
diff --git a/o3d/DEPS b/o3d/DEPS
index 3730ce1..cbb9670 100644
--- a/o3d/DEPS
+++ b/o3d/DEPS
@@ -2,7 +2,7 @@ vars = {
"chromium_trunk":
"http://src.chromium.org/svn/trunk",
"nixysa_rev": "25",
- "o3d_code_rev": "77",
+ "o3d_code_rev": "84",
}
deps = {
diff --git a/o3d/DEPS_gyp b/o3d/DEPS_gyp
index 3f31b83..4f63a1b 100644
--- a/o3d/DEPS_gyp
+++ b/o3d/DEPS_gyp
@@ -3,7 +3,7 @@ vars = {
"http://src.chromium.org/svn/trunk",
"nixysa_rev": "25",
"chromium_rev": "19057",
- "o3d_code_rev": "77",
+ "o3d_code_rev": "84",
}
deps = {
diff --git a/o3d/samples/shader-test.html b/o3d/samples/shader-test.html
index a437370..812d067 100644
--- a/o3d/samples/shader-test.html
+++ b/o3d/samples/shader-test.html
@@ -85,21 +85,24 @@ var g_shaderSelection = 0;
var g_rotateOn = true;
var g_o3dWidth; // width of our client area
var g_o3dHeight; // height of our client area
-var g_shaders = ['diffuse',
- 'checker',
- 'bump',
- 'bump',
- 'texture-only',
- 'texture-colormult',
- 'tangent',
- 'binormal',
- 'normal',
- 'solid-color',
- 'vertex-color',
- 'phong-with-colormult'];
+var g_shaders = [
+ {file: 'diffuse', name: 'Diffuse'},
+ {file: 'checker', name: 'Checker'},
+ {file: 'bump', name: 'Bump'},
+ {file: 'bump', name: 'Bump With Texture'},
+ {file: 'texture-only', name: 'Texture Only'},
+ {file: 'texture-colormult', name: 'Texture with Color Multiplier'},
+ {file: 'tangent', name: 'Tangent'},
+ {file: 'binormal', name: 'Binormal'},
+ {file: 'normal', name: 'Normal'},
+ {file: 'solid-color', name: 'Solid Color'},
+ {file: 'vertex-color', name: 'Vertex Color'},
+ {file: 'phong-with-colormult', name: 'Blinn-Phong with Color Multiplier'},
+ {file: 'toon', name: 'Toon'}];
var g_effects = [];
var g_bumpTextureSampler;
var g_bumpBumpsSampler;
+var g_colorRampSampler;
// Our view and projection matrices
// The view matrix transforms objects from world space to view space.
@@ -263,6 +266,7 @@ function applyShader(pack, shaderNumber) {
setParam(material, 'AmbientSampler', g_bumpTextureSampler);
setParam(material, 'DiffuseSampler', g_bumpTextureSampler);
setParam(material, 'texSampler0', g_bumpTextureSampler);
+ setParam(material, 'colorRamp', g_colorRampSampler);
var timeParam = material.getParam('inputTime');
if (timeParam) {
@@ -312,12 +316,29 @@ function initStep2(clientElements) {
var paramObject = g_pack.createObject('ParamObject');
g_currentTimeParam = paramObject.createParam('timeParam','ParamFloat');
- // Load effects
+ // Load effects and fill out options.
+ options = ''
for(var s = 0; s < g_shaders.length; s++) {
g_effects[s] = g_pack.createObject('Effect');
- var shaderString = 'shaders/' + g_shaders[s] + '.shader';
+ var shaderString = 'shaders/' + g_shaders[s].file + '.shader';
o3djs.effect.loadEffect(g_effects[s], shaderString);
+ options += '<option value="' + s + '"' + (s == 0 ? ' selected' : '') +
+ '>' + g_shaders[s].name + '</option>';
}
+ document.getElementById('shaderSelect').innerHTML = options;
+
+ var rampWidth = 64;
+ var texture = g_pack.createTexture2D(
+ rampWidth, 1, g_o3d.Texture.XRGB8, 1, false);
+ var pixels = [];
+ for (var ii = 0; ii < rampWidth; ++ii) {
+ var level = ii > rampWidth * 0.5 ? 1 : 0.3;
+ pixels.push(level, level, level);
+ }
+ texture.set(0, pixels);
+ g_colorRampSampler = g_pack.createObject('Sampler');
+ g_colorRampSampler.texture = texture;
+ g_colorRampSampler.addressModeU = g_o3d.Sampler.CLAMP;
var loader = o3djs.loader.createLoader(initStep3);
loader.loadTexture(g_pack, 'assets/normalmap.dds',
@@ -386,18 +407,6 @@ This example is useful for testing a shader or checking a scene. Clicking on the
<!-- End of O3D plugin -->
<p>
<select id='shaderSelect' name='shaderSelect' onChange='changeShader()'>
-<option value='0' selected>Diffuse</option>
-<option value='1'>Checker</option>
-<option value='2'>Bump</option>
-<option value='3'>Bump With Texture</option>
-<option value='4'>Texture Only</option>
-<option value='5'>Texture with Color Multiplier</option>
-<option value='6'>Tangent</option>
-<option value='7'>Binormal</option>
-<option value='8'>Normal</option>
-<option value='9'>Solid Color</option>
-<option value='10'>Vertex Color</option>
-<option value='11'>Blinn-Phong with Color Multiplier</option>
</select>
</body>
</html>
diff --git a/o3d/samples/shaders/toon.shader b/o3d/samples/shaders/toon.shader
new file mode 100755
index 0000000..8f2caec
--- /dev/null
+++ b/o3d/samples/shaders/toon.shader
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// The 4x4 world view projection matrix.
+float4x4 worldViewProjection : WorldViewProjection;
+float4x4 worldInverseTranspose : WorldInverseTranspose;
+float4x4 world : World;
+
+float4 ambientIntensity;
+float4 lightIntensity;
+float4 ambient;
+float4 diffuse;
+float3 lightWorldPos;
+
+sampler colorRamp;
+
+// input parameters for our vertex shader
+struct VertexShaderInput {
+ float4 position : POSITION; // Position vector of vertex
+ float4 normal : NORMAL;
+};
+
+// input parameters for our pixel shader
+struct PixelShaderInput {
+ float4 position : POSITION;
+ float3 normal : TEXCOORD0;
+ float3 worldPosition : TEXCOORD1;
+};
+
+/**
+ * Our vertex shader.
+ */
+PixelShaderInput vertexShaderFunction(VertexShaderInput input) {
+ PixelShaderInput output;
+
+ // Transform position into clip space.
+ output.position = mul(input.position, worldViewProjection);
+
+ // Transform normal into world space, where we can do lighting
+ // calculations even if the world transform contains scaling.
+ output.normal = mul(input.normal, worldInverseTranspose).xyz;
+
+ // Calculate surface position in world space.
+ output.worldPosition = mul(input.position, world).xyz;
+
+ return output;
+}
+
+/**
+ * Our pixel shader.
+ */
+float4 pixelShaderFunction(PixelShaderInput input): COLOR {
+ float3 surfaceToLight = normalize(lightWorldPos - input.worldPosition);
+
+ float3 worldNormal = normalize(input.normal);
+
+ // Apply diffuse lighting in world space in case the world transform
+ // contains scaling.
+ float4 directionalIntensity = lightIntensity *
+ tex2D(colorRamp, float2(saturate(dot(worldNormal, surfaceToLight)), 0.5));
+ float4 outColor = ambientIntensity * ambient + directionalIntensity * diffuse;
+ return float4(outColor.rgb, diffuse.a);
+}
+
+// Here we tell our effect file *which* functions are
+// our vertex and pixel shaders.
+
+// #o3d VertexShaderEntryPoint vertexShaderFunction
+// #o3d PixelShaderEntryPoint pixelShaderFunction
+// #o3d MatrixLoadOrder RowMajor