From 02127f8772c83c5e53f66a9ad8267d4b343f8007 Mon Sep 17 00:00:00 2001 From: "petersont@chromium.org" Date: Fri, 17 Jul 2009 21:07:42 +0000 Subject: Added a new sample which implements basic shadow mapping. Review URL: http://codereview.chromium.org/155401 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21000 0039d316-1c4b-4281-b951-d872f2087c98 --- o3d/DEPS | 2 +- o3d/core/cross/gl/renderer_gl.cc | 5 + o3d/samples/MANIFEST | 1 + o3d/samples/o3djs/debug.js | 24 +- o3d/samples/shadow-map.html | 627 +++++++++++++++++++++++++++++++++++++ o3d/tests/selenium/sample_list.txt | 1 + 6 files changed, 655 insertions(+), 5 deletions(-) create mode 100755 o3d/samples/shadow-map.html (limited to 'o3d') diff --git a/o3d/DEPS b/o3d/DEPS index b1c2625..1964999 100644 --- a/o3d/DEPS +++ b/o3d/DEPS @@ -2,7 +2,7 @@ vars = { "chromium_trunk": "http://src.chromium.org/svn/trunk", "nixysa_rev": "28", - "o3d_code_rev": "95", + "o3d_code_rev": "96", } deps = { diff --git a/o3d/core/cross/gl/renderer_gl.cc b/o3d/core/cross/gl/renderer_gl.cc index 8638607..dbd34fd 100644 --- a/o3d/core/cross/gl/renderer_gl.cc +++ b/o3d/core/cross/gl/renderer_gl.cc @@ -1567,6 +1567,11 @@ bool RendererGL::SaveScreen(const String& file_name) { MakeCurrentLazy(); Bitmap::Ref bitmap = Bitmap::Ref(new Bitmap(service_locator())); bitmap->Allocate(Texture::ARGB8, width(), height(), 1, false); + + // Note: glReadPixels captures the alpha component of the frame buffer as well + // as the color components, the browser usually ignores the alpha channel when + // drawing to the screen, so unless the alpha is 1, the png image generated + // might exhibit suprise translucency. ::glReadPixels(0, 0, width(), height(), GL_BGRA, GL_UNSIGNED_BYTE, bitmap->image_data()); bool result = bitmap->SaveToPNGFile((file_name + ".png").c_str()); diff --git a/o3d/samples/MANIFEST b/o3d/samples/MANIFEST index ef3a61c..72145b8 100644 --- a/o3d/samples/MANIFEST +++ b/o3d/samples/MANIFEST @@ -283,6 +283,7 @@ shaders/texture-only.shader shaders/toon.shader shaders/vertex-color.shader shaders/yuv2rgb.shader +shadow-map.html simpleviewer/assets/cube.o3dtgz simpleviewer/simpleviewer.html trends/assets/clouds.jpg diff --git a/o3d/samples/o3djs/debug.js b/o3d/samples/o3djs/debug.js index 9589c50..2f4be54 100644 --- a/o3d/samples/o3djs/debug.js +++ b/o3d/samples/o3djs/debug.js @@ -263,6 +263,25 @@ o3djs.debug.VertexInfo.prototype.Offset = { }; /** + * Computes the number of vertices in this vertex info. + * @return {number} The number of vertices. + */ +o3djs.debug.VertexInfo.prototype.numVertices = function() { + return this.vertices.length / 3; +}; + + +/** + * Given the number of a vertex returns the index in the array where + * the coordinates of that vertex vertexIndex. + * @param {number} vertexNumber The vertex number. + * @return {number} The index where that vertex begins. + */ +o3djs.debug.VertexInfo.prototype.vertexIndex = function(vertexNumber) { + return vertexNumber * 3; +} + +/** * Adds a vertex. * @param {number} positionX The x position of the vertex. * @param {number} positionY The y position of the vertex. @@ -298,6 +317,7 @@ o3djs.debug.VertexInfo.prototype.createShape = function( this.indices); }; + /** * Reorients the vertex positions of this vertexInfo by the * given matrix. In other words it multiplies each vertex by the @@ -306,10 +326,6 @@ o3djs.debug.VertexInfo.prototype.createShape = function( */ o3djs.debug.VertexInfo.prototype.reorient = function(matrix) { var math = o3djs.math; - // Assume if it has a length it's not a Matrix4 - if (matrix.length) { - matrix = math.matrix4.copy(matrix); - } var numVerts = this.numVertices(); for (var v = 0; v < numVerts; ++v) { var index = this.vertexIndex(v); diff --git a/o3d/samples/shadow-map.html b/o3d/samples/shadow-map.html new file mode 100755 index 0000000..a7bb6e9 --- /dev/null +++ b/o3d/samples/shadow-map.html @@ -0,0 +1,627 @@ + + + + + + + + +Shadow Mapping + + + + + + + + + + + +

Shadow Maps

+This sample implements a basic shadow map. +
+ +
+ +Use A, S, D, W, I and O to move the light. +Press spacebar to see the shadow map. + + diff --git a/o3d/tests/selenium/sample_list.txt b/o3d/tests/selenium/sample_list.txt index de0f665..6a8dc5d 100644 --- a/o3d/tests/selenium/sample_list.txt +++ b/o3d/tests/selenium/sample_list.txt @@ -101,6 +101,7 @@ medium simpletexture screenshot pdiff_threshold(5100) medium skinning screenshot pdiff_threshold(500) medium sobel screenshot pdiff_threshold(1400) medium stencil_example screenshot(0) screenshot(100) screenshot(7777) pdiff_threshold(4800) pdiff_threshold_win(20800) +medium shadow-map screenshot pdiff_threshold(10000) small texturesamplers screenshot pdiff_threshold(32200) pdiff_threshold_win(37100) medium tutorial-primitive screenshot pdiff_threshold(1200) pdiff_threshold_mac(10400) large vertex-shader screenshot timeout(45000) pdiff_threshold(1400) except(*iexplore) -- cgit v1.1