diff options
author | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 04:21:40 +0000 |
---|---|---|
committer | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-01 04:21:40 +0000 |
commit | 70c8e97a69ef8806b1812b2cd0ebe831f3792cb6 (patch) | |
tree | 4c5b5e5b71ce99f91910b3fd569443f0f07a4e72 /o3d/samples/texturesamplers.html | |
parent | 13a8961bf84b7132e2ae588ea644bf7b8012fe75 (diff) | |
download | chromium_src-70c8e97a69ef8806b1812b2cd0ebe831f3792cb6.zip chromium_src-70c8e97a69ef8806b1812b2cd0ebe831f3792cb6.tar.gz chromium_src-70c8e97a69ef8806b1812b2cd0ebe831f3792cb6.tar.bz2 |
Update samples to use more utility functions where
appropriate.
A few places used pseudoRandom. That is in math.js
now so they use that.
Other places there is now
o3djs.material.createBasicMaterial and
o3djs.material.createMaterialFromFile that save
10-20 lines per sample.
This CL will require new reference images.
There are 2 other things I'd like to consider.
#1) Changing every sample that uses shaders/texture-only.shader
to use o3djs.material.createConstantMaterial or some variation.
The problem with o3djs.material.createConstantMaterial is it
requires you pass it a texture if you want a constant textured
material. All the samples create the material first, then
later add the texture.
So, I could add a new o3djs.material.createTextureOnlyMaterial.
At the same time that would mean changing those samples from
setting stuff on 'texSampler0' to 'emissive'
#2) I'd like to change the shader builder so it stops
adding "Sampler" to textured materials. As it is if
the material uses a color it makes the param called "diffuse"
but if it's a texture it makes it "diffuseSampler".
That sucks because it means the code has to do crap like
var param = material.getParam('diffuse');
if (param) {
// it's a color
} else {
param = material.getParam('diffuseSampler');
if (param) {
// it's a texture.
}
}
If we stopped that silliness we could just do
var param = material.getParam('diffuse');
if (param) {
if (param.isA('o3d.ParamTexture')) {
// it's textured.
} else {
// it's not.
}
}
Unfortunately to fix this requires changing the o3dConverter
as well since it uses those conventions. Should we do this?
Review URL: http://codereview.chromium.org/182024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples/texturesamplers.html')
-rw-r--r-- | o3d/samples/texturesamplers.html | 32 |
1 files changed, 7 insertions, 25 deletions
diff --git a/o3d/samples/texturesamplers.html b/o3d/samples/texturesamplers.html index ebb76f4..c64d827 100644 --- a/o3d/samples/texturesamplers.html +++ b/o3d/samples/texturesamplers.html @@ -49,7 +49,7 @@ o3djs.require('o3djs.util'); o3djs.require('o3djs.math'); o3djs.require('o3djs.rendergraph'); o3djs.require('o3djs.primitives'); -o3djs.require('o3djs.effect'); +o3djs.require('o3djs.material'); o3djs.require('o3djs.event'); o3djs.require('o3djs.io'); @@ -63,7 +63,6 @@ var g_math; var g_client; var g_pack; var g_viewInfo; -var g_commonEffect; var g_eye; var g_target; var g_up; @@ -101,10 +100,6 @@ function initStep2(clientElements) { g_client.root, g_client.renderGraphRoot); - // Create and load the effect. - g_commonEffect = g_pack.createObject('Effect'); - o3djs.effect.loadEffect(g_commonEffect, 'shaders/texture-only.shader'); - // Create our projection matrix, with a vertical field of view of 45 degrees // a near clipping plane of 0.1 and far clipping plane of 100. var proj_matrix = g_math.matrix4.perspective( @@ -129,17 +124,10 @@ function initStep2(clientElements) { var index = yy * 3 + xx; // Create a new Material for the quad. - var material = g_pack.createObject('Material'); - - // Set the material's drawList - material.drawList = g_viewInfo.performanceDrawList; - material.effect = g_commonEffect; - - // Create Params on the material for all the uniform parameters needed by - // the effect. The one we are really interested in is the Param for the - // sampler which will be called "texSampler0" - // (the name it has in the shader string). - g_commonEffect.createUniformParameters(material); + var material = o3djs.material.createMaterialFromFile( + g_pack, + 'shaders/texture-only.shader', + g_viewInfo.performanceDrawList); // Create a quad and position it. var verts = o3djs.primitives.createPlaneVertices(1, 1, 1, 1); @@ -155,17 +143,11 @@ function initStep2(clientElements) { transform.translate([(xx - 1) * 1.2, 0, (0.5 - yy) * -1.2]); transform.addShape(shape); - // Find the material used by the shape. - var primitive = shape.elements[0]; - var material = primitive.material; - var p = material.params; - // Get the sampler param on the material. var samplerParam = material.getParam('texSampler0'); - // Create a new sampler for the material. - var sampler = g_pack.createObject('Sampler'); - samplerParam.value = sampler; + // Get the sampler on the sampler param. + var sampler = samplerParam.value; samplers[index] = sampler; transforms[index] = transform; } |