diff options
Diffstat (limited to 'o3d/samples')
-rw-r--r-- | o3d/samples/displayfps.html | 7 | ||||
-rw-r--r-- | o3d/samples/o3d-webgl-samples/particles.html | 5 | ||||
-rw-r--r-- | o3d/samples/o3djs/canvas.js | 183 | ||||
-rw-r--r-- | o3d/samples/o3djs/effect.js | 153 | ||||
-rw-r--r-- | o3d/samples/o3djs/fps.js | 161 | ||||
-rw-r--r-- | o3d/samples/o3djs/particles.js | 18 | ||||
-rw-r--r-- | o3d/samples/o3djs/util.js | 5 |
7 files changed, 137 insertions, 395 deletions
diff --git a/o3d/samples/displayfps.html b/o3d/samples/displayfps.html index a67fbe07..2405819 100644 --- a/o3d/samples/displayfps.html +++ b/o3d/samples/displayfps.html @@ -111,10 +111,15 @@ function initStep2(clientElements) { g_client.height, g_client.renderGraphRoot); + var shaderFilePath = 'shaders/vertex-color.shader'; + if (g_client.clientInfo.glsl) { + shaderFilePath = 'shaders/vertex-color-glsl.shader' + } + // Create a material. var myMaterial = o3djs.material.createMaterialFromFile( g_pack, - 'shaders/vertex-color.shader', + shaderFilePath, g_viewInfo.performanceDrawList); // Draw a cube using the effect we have loaded. diff --git a/o3d/samples/o3d-webgl-samples/particles.html b/o3d/samples/o3d-webgl-samples/particles.html index 6a4f185..71938c3 100644 --- a/o3d/samples/o3d-webgl-samples/particles.html +++ b/o3d/samples/o3d-webgl-samples/particles.html @@ -102,11 +102,6 @@ function init() { window.g_timeMult = 1; window.g_clock = 0; - // Comment out the line below to run the sample in the browser JavaScript - // engine. This may be helpful for debugging. - o3djs.util.setMainEngine(o3djs.util.Engine.V8); - o3djs.particles.setLanguage('glsl'); - o3djs.webgl.makeClients(initStep2); } diff --git a/o3d/samples/o3djs/canvas.js b/o3d/samples/o3djs/canvas.js index 09bb413..5fe3aa3 100644 --- a/o3d/samples/o3djs/canvas.js +++ b/o3d/samples/o3djs/canvas.js @@ -114,145 +114,45 @@ o3djs.canvas.create = function(pack, root, viewInfo) { * bound to texSampler0. * @type {string} */ -o3djs.canvas.FX_STRING_CG = - 'float4x4 worldViewProjection : WORLDVIEWPROJECTION;\n' + - 'sampler texSampler0;\n' + - 'struct VertexShaderInput {\n' + - ' float4 position : POSITION;\n' + - ' float2 texcoord : TEXCOORD0;\n' + - '};\n'+ - 'struct PixelShaderInput {\n' + - ' float4 position : POSITION;\n' + - ' float2 texcoord : TEXCOORD0;\n' + - '};\n' + - 'PixelShaderInput vertexShaderFunction(VertexShaderInput input) {\n' + - ' PixelShaderInput output;\n' + - ' output.position = mul(input.position, worldViewProjection);\n' + - ' output.texcoord = input.texcoord;\n' + - ' return output;\n' + - '}\n' + - 'float4 pixelShaderFunction(PixelShaderInput input): COLOR {\n' + - ' return tex2D(texSampler0, input.texcoord);\n' + - '}\n' + - '// #o3d VertexShaderEntryPoint vertexShaderFunction\n' + - '// #o3d PixelShaderEntryPoint pixelShaderFunction\n' + - '// #o3d MatrixLoadOrder RowMajor\n'; - -// Auto-generated by convert.py. -o3djs.canvas.FX_STRING_GLSL = - '// glslv profile log:\n' + - '// 22 lines, 0 errors.\n' + - '\n' + - '// glslf profile log:\n' + - '// 22 lines, 0 errors.\n' + - '\n' + - '// glslv output by Cg compiler\n' + - '// cgc version 2.0.0010, build date Dec 12 2007\n' + - '// command line args: -profile glslv\n' + - '//vendor NVIDIA Corporation\n' + - '//version 2.0.0.10\n' + - '//profile glslv\n' + - '//program vertexShaderFunction\n' + - '//semantic worldViewProjection : WORLDVIEWPROJECTION\n' + - '//semantic texSampler0\n' + - '//var float4x4 worldViewProjection : WORLDVIEWPROJECTION : _ZZ2SworldViewProjection[0], 4 : -1 : 1\n' + - '//var sampler texSampler0 : : : -1 : 0\n' + - '//var float4 input.position : $vin.POSITION : POSITION : 0 : 1\n' + - '//var float2 input.texcoord : $vin.TEXCOORD0 : TEXCOORD0 : 0 : 1\n' + - '//var float4 vertexShaderFunction.position : $vout.POSITION : POSITION : -1 : 1\n' + - '//var float2 vertexShaderFunction.texcoord : $vout.TEXCOORD0 : TEXCOORD0 : -1 : 1\n' + - '\n' + - 'attribute vec4 position;\n' + - 'attribute vec4 texcoord0;\n' + - 'vec4 _glPositionTemp;\n' + - 'uniform vec4 dx_clipping;\n' + - '\n' + - 'struct VertexShaderInput {\n' + - ' vec4 position;\n' + - ' vec2 texcoord;\n' + - '};\n' + - '\n' + - 'struct PixelShaderInput {\n' + - ' vec4 position;\n' + - ' vec2 texcoord;\n' + - '};\n' + - '\n' + - 'PixelShaderInput _ZZ3Sret_0;\n' + - 'vec4 _ZZ3SrZh0003;\n' + - 'uniform mat4 worldviewprojection;\n' + - '\n' + - ' // main procedure, the original name was vertexShaderFunction\n' + - 'void main()\n' + - '{\n' + - '\n' + - '\n' + - ' _ZZ3SrZh0003 = position.x*worldviewprojection[0];\n' + - ' _ZZ3SrZh0003 = _ZZ3SrZh0003 + position.y*worldviewprojection[1];\n' + - ' _ZZ3SrZh0003 = _ZZ3SrZh0003 + position.z*worldviewprojection[2];\n' + - ' _ZZ3SrZh0003 = _ZZ3SrZh0003 + position.w*worldviewprojection[3];\n' + - ' _ZZ3Sret_0.position = _ZZ3SrZh0003;\n' + - ' _ZZ3Sret_0.texcoord = texcoord0.xy;\n' + - ' gl_TexCoord[0].xy = texcoord0.xy;\n' + - ' _glPositionTemp = _ZZ3SrZh0003; gl_Position = vec4(_glPositionTemp.x + _glPositionTemp.w * dx_clipping.x, dx_clipping.w * (_glPositionTemp.y + _glPositionTemp.w * dx_clipping.y), _glPositionTemp.z * 2 - _glPositionTemp.w, _glPositionTemp.w);\n' + - ' return;\n' + - '} // main end\n' + - '\n' + - '\n' + - '// #o3d SplitMarker\n' + - '// #o3d MatrixLoadOrder RowMajor\n' + - '\n' + - '// glslf output by Cg compiler\n' + - '// cgc version 2.0.0010, build date Dec 12 2007\n' + - '// command line args: -profile glslf\n' + - '//vendor NVIDIA Corporation\n' + - '//version 2.0.0.10\n' + - '//profile glslf\n' + - '//program pixelShaderFunction\n' + - '//semantic worldViewProjection : WORLDVIEWPROJECTION\n' + - '//semantic texSampler0\n' + - '//var float4x4 worldViewProjection : WORLDVIEWPROJECTION : , 4 : -1 : 0\n' + - '//var sampler texSampler0 : : _ZZ2StexSampler0 : -1 : 1\n' + - '//var float2 input.texcoord : $vin.TEXCOORD0 : TEXCOORD0 : 0 : 1\n' + - '//var float4 pixelShaderFunction : $vout.COLOR : COLOR : -1 : 1\n' + - '\n' + - '\n' + - '\n' + - 'struct VertexShaderInput {\n' + - ' vec2 texcoord;\n' + - '};\n' + - '\n' + - 'struct PixelShaderInput {\n' + - ' vec2 texcoord;\n' + - '};\n' + - '\n' + - 'vec4 _ZZ3Sret_0;\n' + - 'sampler2D _ZZ3SsZh0003;\n' + - 'uniform sampler texSampler0;\n' + - '\n' + - ' // main procedure, the original name was pixelShaderFunction\n' + - 'void main()\n' + - '{\n' + - '\n' + - '\n' + - ' _ZZ3SsZh0003 = sampler2D(texSampler0);\n' + - ' _ZZ3Sret_0 = texture2D(_ZZ3SsZh0003, gl_TexCoord[0].xy);\n' + - ' gl_FragColor = _ZZ3Sret_0;\n' + - ' return;\n' + - '} // main end\n' + - '\n'; - - -/** - * Sets the shader language used. Passing 'glsl' will cause all generated - * shader code to be in glsl. Passing anything else will result in the - * default o3d hlsl/cg based shader language. - * @param {string} language Shader language to use. - */ -o3djs.canvas.setLanguage = function(language) { - o3djs.canvas.FX_STRING = o3djs.canvas.FX_STRING_CG; - if (language == 'glsl') - o3djs.canvas.FX_STRING = o3djs.canvas.FX_STRING_GLSL; -} +o3djs.canvas.buildShaderString = function() { + var p = o3djs.effect; + var varyingDecls = p.BEGIN_OUT_STRUCT + + p.VARYING + p.FLOAT4 + ' ' + + p.VARYING_DECLARATION_PREFIX + 'position' + + p.semanticSuffix('POSITION') + ';\n' + + p.VARYING + p.FLOAT2 + ' ' + + p.VARYING_DECLARATION_PREFIX + 'texCoord' + + p.semanticSuffix('TEXCOORD0') + ';\n' + + p.END_STRUCT; + + return 'uniform ' + p.MATRIX4 + ' worldViewProjection' + + p.semanticSuffix('WORLDVIEWPROJECTION') + ';\n\n' + + p.BEGIN_IN_STRUCT + + p.ATTRIBUTE + p.FLOAT4 + ' position' + + p.semanticSuffix('POSITION') + ';\n' + + p.ATTRIBUTE + p.FLOAT2 + ' texCoord0' + + p.semanticSuffix('TEXCOORD0') + ';\n' + + p.END_STRUCT + + '\n' + + varyingDecls + + '\n' + + p.beginVertexShaderMain() + + ' ' + p.VERTEX_VARYING_PREFIX + 'position = ' + + p.mul(p.ATTRIBUTE_PREFIX + 'position', + 'worldViewProjection') + ';\n' + + ' ' + p.VERTEX_VARYING_PREFIX + 'texCoord = ' + + p.ATTRIBUTE_PREFIX + 'texCoord0;\n' + + p.endVertexShaderMain() + + '\n' + + p.pixelShaderHeader() + + 'uniform ' + p.SAMPLER + ' texSampler0;\n' + + p.repeatVaryingDecls(varyingDecls) + + p.beginPixelShaderMain() + + p.endPixelShaderMain(p.TEXTURE + '2D' + + '(texSampler0, ' + p.PIXEL_VARYING_PREFIX + 'texCoord)') + + p.entryPoints() + + p.matrixLoadOrder(); +}; /** @@ -289,7 +189,7 @@ o3djs.canvas.CanvasInfo = function(pack, root, viewInfo) { * @type {!o3d.Effect} */ this.effect_ = this.pack.createObject('Effect'); - this.effect_.loadFromFXString(o3djs.canvas.FX_STRING); + this.effect_.loadFromFXString(o3djs.canvas.buildShaderString()); /** * Material for canvases with transparent content @@ -536,6 +436,3 @@ o3djs.canvas.CanvasInfo.prototype.createQuad = function(width, }; -// For compatability with o3d code, the default language is o3d shading -// language. -o3djs.canvas.setLanguage('o3d'); diff --git a/o3d/samples/o3djs/effect.js b/o3d/samples/o3djs/effect.js index 37c74d2..8351473 100644 --- a/o3d/samples/o3djs/effect.js +++ b/o3d/samples/o3djs/effect.js @@ -65,6 +65,7 @@ o3djs.effect.TWO_COLOR_CHECKER_EFFECT_NAME = * @namespace */ o3djs.effect.o3d = { + LANGUAGE: 'o3d', FLOAT2: 'float2', FLOAT3: 'float3', FLOAT4: 'float4', @@ -78,6 +79,7 @@ o3djs.effect.o3d = { VERTEX_VARYING_PREFIX: 'output.', PIXEL_VARYING_PREFIX: 'input.', TEXTURE: 'tex', + SAMPLER: 'sampler', BEGIN_IN_STRUCT: 'struct InVertex {\n', BEGIN_OUT_STRUCT: 'struct OutVertex {\n', END_STRUCT: '};\n' @@ -92,6 +94,7 @@ o3djs.effect.o3d = { * @namespace */ o3djs.effect.glsl = { + LANGUAGE: 'glsl', FLOAT2: 'vec2', FLOAT3: 'vec3', FLOAT4: 'vec4', @@ -105,6 +108,7 @@ o3djs.effect.glsl = { VERTEX_VARYING_PREFIX: 'v_', PIXEL_VARYING_PREFIX: 'v_', TEXTURE: 'texture', + SAMPLER: 'sampler2D', BEGIN_IN_STRUCT: '', BEGIN_OUT_STRUCT: '', END_STRUCT: '', @@ -383,7 +387,18 @@ o3djs.effect.setLanguage = function(language) { o3djs.effect.TWO_COLOR_CHECKER_FXSTRING = o3djs.effect.buildCheckerShaderString(); -} +}; + +/** + * Gets the language set in the function setLanguage. Returns a string, either + * 'glsl' or 'o3d'. + */ +o3djs.effect.getLanguage = function() { + if (language_namespace == o3djs.effect.glsl) { + return 'glsl'; + } + return 'o3d'; +}; /** @@ -393,11 +408,10 @@ o3djs.effect.setLanguage = function(language) { * @param {boolean} specular Whether to include stuff for diffuse * calculations. * @param {boolean} bumpSampler Whether there is a bump sampler. - * @param {boolean} skinning Whether this mesh has a skin. * @return {string} The code for the declarations. */ o3djs.effect.buildAttributeDecls = - function(material, diffuse, specular, bumpSampler, skinning) { + function(material, diffuse, specular, bumpSampler) { var str = o3djs.effect.BEGIN_IN_STRUCT + o3djs.effect.ATTRIBUTE + o3djs.effect.FLOAT4 + ' ' + 'position' + o3djs.effect.semanticSuffix('POSITION') + ';\n'; @@ -405,12 +419,6 @@ o3djs.effect.buildAttributeDecls = str += o3djs.effect.ATTRIBUTE + o3djs.effect.FLOAT3 + ' ' + 'normal' + o3djs.effect.semanticSuffix('NORMAL') + ';\n'; } - if (skinning) { - str += o3djs.effect.ATTRIBUTE + o3djs.effect.FLOAT4 + ' influenceWeights' + - o3djs.effect.semanticSuffix('BLENDWEIGHT') + ';\n'; - str += o3djs.effect.ATTRIBUTE + o3djs.effect.FLOAT4 + ' influenceIndices' + - o3djs.effect.semanticSuffix('BLENDINDICES') + ';\n'; - } str += o3djs.effect.buildTexCoords(material, false) + o3djs.effect.buildBumpInputCoords(bumpSampler) + o3djs.effect.END_STRUCT; @@ -604,16 +612,13 @@ o3djs.effect.buildBumpInputCoords = function(bumpSampler) { o3djs.effect.buildBumpOutputCoords = function(bumpSampler) { var p = o3djs.effect; return bumpSampler ? - (' ' + p.VARYING + p.FLOAT3 + ' ' + - p.VARYING_DECLARATION_PREFIX + 'tangent' + - p.semanticSuffix( - 'TEXCOORD' + p.interpolant_++) + ';\n' + - ' ' + p.VARYING + p.FLOAT3 + ' ' + - p.VARYING_DECLARATION_PREFIX + 'binormal' + + (' ' + p.FLOAT3 + ' tangent' + p.semanticSuffix( 'TEXCOORD' + p.interpolant_++) + ';\n' + - ' ' + p.VARYING + p.FLOAT2 + ' ' + - p.VARYING_DECLARATION_PREFIX + 'bumpUV' + + ' ' + p.FLOAT3 + ' binormal' + + p.semanticSuffix('TEXCOORD' + + p.interpolant_++) + ';\n' + + ' ' + p.FLOAT2 + ' bumpUV' + p.semanticSuffix( 'TEXCOORD' + p.interpolant_++) + ';\n') : ''; }; @@ -641,7 +646,7 @@ o3djs.effect.buildCheckerShaderString = function() { p.END_STRUCT; return 'uniform ' + p.MATRIX4 + ' worldViewProjection' + - p.semanticSuffix('WORLDVIEWPROJECTION') + ';\n' + + p.semanticSuffix('WORLDVIEWPROJECTION') + ';\n' + 'uniform ' + p.MATRIX4 + ' worldInverseTranspose' + p.semanticSuffix('WORLDINVERSETRANSPOSE') + ';\n' + 'uniform ' + p.MATRIX4 + ' world' + @@ -701,7 +706,8 @@ o3djs.effect.buildCheckerShaderString = function() { ' outColor = directionalIntensity * check;\n' + p.endPixelShaderMain( p.FLOAT4 + '(outColor.rgb, check.a)') + - '\n' + p.entryPoints() + + '\n' + + p.entryPoints() + p.matrixLoadOrder(); }; @@ -831,21 +837,6 @@ o3djs.effect.buildStandardShaderString = function(material, var p = o3djs.effect; var bumpSampler = material.getParam('bumpSampler'); var bumpUVInterpolant; - var skinning; - - var maxSkinInfluences = 4; - - // Hardcode reasonable maximum for number of skinning uniforms. - // glsl: Table 6.19: minimum MAX_VERTEX_UNIFORM_VECTORS is 128. - // (DX9 requires a minimum of 256, so not a problem in o3d). - var maxSkinUniforms = 36 * 3; - if (o3djs.base.o3d && o3djs.base.o3d.SkinEval && - o3djs.base.o3d.SkinEval.getMaxNumBones) { - maxSkinUniforms = o3d.SkinEval.getMaxNumBones(material) * 3; - skinning = true; - } else { - skinning = false; - } /** * Extracts the texture type from a texture param. @@ -914,17 +905,6 @@ o3djs.effect.buildStandardShaderString = function(material, }; /** - * If skinning is enabled, builds the bone matrix uniform variables needed - * for skinning. Otherwise, returns the empty string. - * @return {string} The effect code for skinning uniforms. - */ - var buildSkinningUniforms = function() { - return skinning ? 'uniform ' + p.FLOAT4 + ' boneToWorld3x4' + - '[' + maxSkinUniforms + '];\n' + - 'uniform float usingSkinShader;\n' : ''; - }; - - /** * Builds uniform parameters for a given color input. If the material * has a sampler parameter, a sampler uniform is created, otherwise a * float4 color value is created. @@ -986,7 +966,6 @@ o3djs.effect.buildStandardShaderString = function(material, var buildConstantShaderString = function(material, descriptions) { descriptions.push('constant'); return buildCommonVertexUniforms() + - buildSkinningUniforms() + buildVertexDecls(material, false, false) + p.beginVertexShaderMain() + positionVertexShaderCode() + @@ -1014,7 +993,6 @@ o3djs.effect.buildStandardShaderString = function(material, descriptions.push('lambert'); return buildCommonVertexUniforms() + buildLightingUniforms() + - buildSkinningUniforms() + buildVertexDecls(material, true, false) + p.beginVertexShaderMain() + p.buildUVPassthroughs(material) + @@ -1062,7 +1040,6 @@ o3djs.effect.buildStandardShaderString = function(material, descriptions.push('phong'); return buildCommonVertexUniforms() + buildLightingUniforms() + - buildSkinningUniforms() + buildVertexDecls(material, true, true) + p.beginVertexShaderMain() + p.buildUVPassthroughs(material) + @@ -1121,7 +1098,6 @@ o3djs.effect.buildStandardShaderString = function(material, descriptions.push('phong'); return buildCommonVertexUniforms() + buildLightingUniforms() + - buildSkinningUniforms() + buildVertexDecls(material, true, true) + p.beginVertexShaderMain() + p.buildUVPassthroughs(material) + @@ -1172,27 +1148,9 @@ o3djs.effect.buildStandardShaderString = function(material, * @return {string} The code for the vertex shader. */ var positionVertexShaderCode = function() { - var attribute_position = p.ATTRIBUTE_PREFIX + 'position'; - if (skinning) { - return ' ' + p.FLOAT4 + ' weightedpos = ' + attribute_position + ';\n' + - ' for (int i = 0; i < ' + maxSkinInfluences + '; i++) {\n' + - ' ' + p.FLOAT4 + ' temp = ' + p.FLOAT4 + '(' + - 'dot(boneToWorld3x4[int(influenceIndices[i] * 3.0)], ' + - attribute_position + '),\n' + - ' dot(boneToWorld3x4[int(influenceIndices[i] * 3.0 + 1.0)], ' + - attribute_position + '),\n' + - ' dot(boneToWorld3x4[int(influenceIndices[i] * 3.0 + 2.0)], ' + - attribute_position + '),\n' + - ' 1.0);\n' + - ' weightedpos += usingSkinShader * influenceWeights[i] * ' + - '(temp - ' + attribute_position + ');\n' + - ' }\n' + - ' ' + p.VERTEX_VARYING_PREFIX + 'position = ' + - p.mul('weightedpos', 'worldViewProjection') + ';\n'; - } else { - return ' ' + p.VERTEX_VARYING_PREFIX + 'position = ' + - p.mul(attribute_position, 'worldViewProjection') + ';\n'; - } + return ' ' + p.VERTEX_VARYING_PREFIX + 'position = ' + + p.mul(p.ATTRIBUTE_PREFIX + + 'position', 'worldViewProjection') + ';\n'; }; /** @@ -1200,29 +1158,10 @@ o3djs.effect.buildStandardShaderString = function(material, * @return {string} The code for the vertex shader. */ var normalVertexShaderCode = function() { - var attribute_normal = p.ATTRIBUTE_PREFIX + 'normal'; - if (skinning) { - return ' ' + p.FLOAT3 + ' weightednorm = ' + attribute_normal + ';\n' + - ' for (int i = 0; i < ' + maxSkinInfluences + '; i++) {\n' + - ' ' + p.FLOAT3 + ' temp = ' + p.FLOAT3 + '(' + - 'dot(boneToWorld3x4[int(influenceIndices[i] * 3.0)].xyz, ' + - attribute_normal + '),\n' + - ' dot(boneToWorld3x4[int(influenceIndices[i] * 3.0 + 1.0)].xyz, ' + - attribute_normal + '),\n' + - ' dot(boneToWorld3x4[int(influenceIndices[i] * 3.0 + 2.0)].xyz, ' + - attribute_normal + '));\n' + - ' weightednorm += usingSkinShader * influenceWeights[i] * ' + - '(temp - ' + attribute_normal + ');\n' + - ' }\n' + - ' ' + p.VERTEX_VARYING_PREFIX + 'normal = ' + - p.mul(p.FLOAT4 + '(' + 'weightednorm' + ', 0)', - 'worldInverseTranspose') + '.xyz;\n'; - } else { - return ' ' + p.VERTEX_VARYING_PREFIX + 'normal = ' + - p.mul(p.FLOAT4 + '(' + - attribute_normal + ', 0)', 'worldInverseTranspose') + - '.xyz;\n'; - } + return ' ' + p.VERTEX_VARYING_PREFIX + 'normal = ' + + p.mul(p.FLOAT4 + '(' + + p.ATTRIBUTE_PREFIX + + 'normal, 0)', 'worldInverseTranspose') + '.xyz;\n'; }; /** @@ -1249,9 +1188,11 @@ o3djs.effect.buildStandardShaderString = function(material, /** * Builds the normal map part of the vertex shader. + * @param {boolean} opt_bumpSampler Whether there is a bump + * sampler. Default = false. * @return {string} The code for normal mapping in the vertex shader. */ - var bumpVertexShaderCode = function() { + var bumpVertexShaderCode = function(opt_bumpSampler) { return bumpSampler ? (' ' + p.VERTEX_VARYING_PREFIX + 'binormal = ' + p.mul(p.FLOAT4 + '(' + @@ -1268,27 +1209,21 @@ o3djs.effect.buildStandardShaderString = function(material, * @return {string} The code for normal computation in the pixel shader. */ var getNormalShaderCode = function() { - if (bumpSampler) { - var type = getSamplerType(bumpSampler); - var tex2D = p.TEXTURE + type; - return ( - p.MATRIX3 + ' tangentToWorld = ' + p.MATRIX3 + - '(' + p.PIXEL_VARYING_PREFIX + 'tangent,\n' + + return bumpSampler ? + (p.MATRIX3 + ' tangentToWorld = ' + p.MATRIX3 + + '(' + p.ATTRIBUTE_PREFIX + 'tangent,\n' + ' ' + - p.PIXEL_VARYING_PREFIX + 'binormal,\n' + + p.ATTRIBUTE_PREFIX + 'binormal,\n' + ' ' + - p.PIXEL_VARYING_PREFIX + 'normal);\n' + - p.FLOAT3 + ' tangentNormal = ' + tex2D + '(bumpSampler, ' + - p.PIXEL_VARYING_PREFIX + 'bumpUV.xy).xyz -\n' + + p.ATTRIBUTE_PREFIX + 'normal);\n' + + p.FLOAT3 + ' tangentNormal = ' + p.TEXTURE + '2D' + '(bumpSampler, ' + + p.ATTRIBUTE_PREFIX + 'bumpUV.xy).xyz -\n' + ' ' + p.FLOAT3 + '(0.5, 0.5, 0.5);\n' + p.FLOAT3 + ' normal = ' + p.mul('tangentNormal', 'tangentToWorld') + ';\n' + 'normal = normalize(' + p.PIXEL_VARYING_PREFIX + - 'normal);\n'); - } else { - return ' ' + p.FLOAT3 + ' normal = normalize(' + + 'normal);\n') : ' ' + p.FLOAT3 + ' normal = normalize(' + p.PIXEL_VARYING_PREFIX + 'normal);\n'; - } }; /** @@ -1302,7 +1237,7 @@ o3djs.effect.buildStandardShaderString = function(material, */ var buildVertexDecls = function(material, diffuse, specular) { return p.buildAttributeDecls( - material, diffuse, specular, bumpSampler, skinning) + + material, diffuse, specular, bumpSampler) + p.buildVaryingDecls( material, diffuse, specular, bumpSampler); }; diff --git a/o3d/samples/o3djs/fps.js b/o3d/samples/o3djs/fps.js index 39d80f4..c8e7888 100644 --- a/o3d/samples/o3djs/fps.js +++ b/o3d/samples/o3djs/fps.js @@ -38,6 +38,7 @@ o3djs.provide('o3djs.fps'); o3djs.require('o3djs.rendergraph'); o3djs.require('o3djs.canvas'); +o3djs.require('o3djs.effect'); o3djs.require('o3djs.math'); o3djs.require('o3djs.primitives'); @@ -65,134 +66,43 @@ o3djs.fps.PERF_BAR_COLORS = [ [1, 0, 0, 1]]; /** - * The shader code used by the pref quads. - * @type {string} + * Generate a shader to be used by the pref quads. + * @return {string} */ -o3djs.fps.CONST_COLOR_EFFECT_CG = - 'float4x4 worldViewProjection : WorldViewProjection;\n' + - 'float4 color;\n' + - 'struct a2v {\n' + - ' float4 pos : POSITION;\n' + - '};\n'+ - 'struct v2f {\n' + - ' float4 pos : POSITION;\n' + - '};\n' + - 'v2f vsMain(a2v IN) {\n' + - ' v2f OUT;\n' + - ' OUT.pos = mul(IN.pos, worldViewProjection);\n' + - ' return OUT;\n' + - '}\n' + - 'float4 psMain(v2f IN): COLOR {\n' + - ' return color;\n' + - '}\n' + - '// #o3d VertexShaderEntryPoint vsMain\n' + - '// #o3d PixelShaderEntryPoint psMain\n' + - '// #o3d MatrixLoadOrder RowMajor\n'; - -// Auto-generated by convert.py. -o3djs.fps.CONST_COLOR_EFFECT_GLSL = - '// glslv profile log:\n' + - '// 19 lines, 0 errors.\n' + +o3djs.fps.buildShaderString = function() { + var p = o3djs.effect; + + var varyingDecls = p.BEGIN_OUT_STRUCT + + p.VARYING + p.FLOAT4 + ' ' + + p.VARYING_DECLARATION_PREFIX + 'position' + + p.semanticSuffix('POSITION') + ';\n' + + p.END_STRUCT; + + return '' + + 'uniform ' + p.MATRIX4 + ' worldViewProjection' + + p.semanticSuffix('WORLDVIEWPROJECTION') + ';\n' + '\n' + - '// glslf profile log:\n' + - '// 19 lines, 0 errors.\n' + + p.BEGIN_IN_STRUCT + + p.ATTRIBUTE + p.FLOAT4 + ' position' + + p.semanticSuffix('POSITION') + ';\n' + + p.END_STRUCT + '\n' + - '// glslv output by Cg compiler\n' + - '// cgc version 2.0.0010, build date Dec 12 2007\n' + - '// command line args: -profile glslv\n' + - '//vendor NVIDIA Corporation\n' + - '//version 2.0.0.10\n' + - '//profile glslv\n' + - '//program vsMain\n' + - '//semantic worldViewProjection : WorldViewProjection\n' + - '//semantic color\n' + - '//var float4x4 worldViewProjection : WorldViewProjection : _ZZ2SworldViewProjection[0], 4 : -1 : 1\n' + - '//var float4 color : : : -1 : 0\n' + - '//var float4 IN.pos : $vin.POSITION : POSITION : 0 : 1\n' + - '//var float4 vsMain.pos : $vout.POSITION : POSITION : -1 : 1\n' + + varyingDecls + '\n' + - 'attribute vec4 position;\n' + - 'vec4 _glPositionTemp;\n' + - 'uniform vec4 dx_clipping;\n' + + p.beginVertexShaderMain() + + ' ' + p.VERTEX_VARYING_PREFIX + 'position = ' + + p.mul(p.ATTRIBUTE_PREFIX + 'position', + 'worldViewProjection') + ';\n' + + p.endVertexShaderMain() + '\n' + - 'struct a2v {\n' + - ' vec4 pos;\n' + - '};\n' + - '\n' + - 'struct v2f {\n' + - ' vec4 pos;\n' + - '};\n' + - '\n' + - 'v2f _ZZ3Sret_0;\n' + - 'vec4 _ZZ3SrZh0003;\n' + - 'uniform mat4 worldviewprojection;\n' + - '\n' + - ' // main procedure, the original name was vsMain\n' + - 'void main()\n' + - '{\n' + - '\n' + - '\n' + - ' _ZZ3SrZh0003 = position.x*worldviewprojection[0];\n' + - ' _ZZ3SrZh0003 = _ZZ3SrZh0003 + position.y*worldviewprojection[1];\n' + - ' _ZZ3SrZh0003 = _ZZ3SrZh0003 + position.z*worldviewprojection[2];\n' + - ' _ZZ3SrZh0003 = _ZZ3SrZh0003 + position.w*worldviewprojection[3];\n' + - ' _ZZ3Sret_0.pos = _ZZ3SrZh0003;\n' + - ' _glPositionTemp = _ZZ3SrZh0003; gl_Position = vec4(_glPositionTemp.x + _glPositionTemp.w * dx_clipping.x, dx_clipping.w * (_glPositionTemp.y + _glPositionTemp.w * dx_clipping.y), _glPositionTemp.z * 2 - _glPositionTemp.w, _glPositionTemp.w);\n' + - ' return;\n' + - '} // main end\n' + - '\n' + - '\n' + - '// #o3d SplitMarker\n' + - '// #o3d MatrixLoadOrder RowMajor\n' + - '\n' + - '// glslf output by Cg compiler\n' + - '// cgc version 2.0.0010, build date Dec 12 2007\n' + - '// command line args: -profile glslf\n' + - '//vendor NVIDIA Corporation\n' + - '//version 2.0.0.10\n' + - '//profile glslf\n' + - '//program psMain\n' + - '//semantic worldViewProjection : WorldViewProjection\n' + - '//semantic color\n' + - '//var float4x4 worldViewProjection : WorldViewProjection : , 4 : -1 : 0\n' + - '//var float4 color : : _ZZ2Scolor : -1 : 1\n' + - '//var float4 psMain : $vout.COLOR : COLOR : -1 : 1\n' + - '\n' + - '\n' + - '\n' + - 'struct a2v {\n' + - ' int dummy;\n' + - '};\n' + - '\n' + - 'struct v2f {\n' + - ' int dummy;\n' + - '};\n' + - '\n' + - 'vec4 _ZZ3Sret_0;\n' + - 'uniform vec4 color;\n' + - '\n' + - ' // main procedure, the original name was psMain\n' + - 'void main()\n' + - '{\n' + - '\n' + - '\n' + - ' _ZZ3Sret_0 = color;\n' + - ' gl_FragColor = color;\n' + - ' return;\n' + - '} // main end\n'; - - -/** - * Sets the shader language used. Passing 'glsl' will cause all generated - * shader code to be in glsl. Passing anything else will result in the - * default o3d hlsl/cg based shader language. - * @param {string} language Shader language to use. - */ -o3djs.fps.setLanguage = function(language) { - o3djs.fps.CONST_COLOR_EFFECT = o3djs.fps.CONST_COLOR_EFFECT_CG; - if (language == 'glsl') - o3djs.fps.CONST_COLOR_EFFECT = o3djs.fps.CONST_COLOR_EFFECT_GLSL; -} + p.pixelShaderHeader() + + 'uniform ' + p.FLOAT4 + ' color;\n' + + p.repeatVaryingDecls(varyingDecls) + + p.beginPixelShaderMain() + + p.endPixelShaderMain('color') + + p.entryPoints() + + p.matrixLoadOrder(); +}; /** @@ -328,7 +238,7 @@ o3djs.fps.FPSManager = function(pack, clientWidth, clientHeight, opt_parent) { // create a unit plane with a const color effect we can use to draw // rectangles. this.colorEffect_ = pack.createObject('Effect'); - this.colorEffect_.loadFromFXString(o3djs.fps.CONST_COLOR_EFFECT); + this.colorEffect_.loadFromFXString(o3djs.fps.buildShaderString()); this.colorMaterial_ = pack.createObject('Material'); this.colorMaterial_.effect = this.colorEffect_; this.colorMaterial_.drawList = this.viewInfo.zOrderedDrawList; @@ -574,6 +484,3 @@ o3djs.fps.ColorRect.prototype.setColor = function(color) { }; -// For compatability with o3d code, the default language is o3d shading -// language. -o3djs.fps.setLanguage('o3d'); diff --git a/o3d/samples/o3djs/particles.js b/o3d/samples/o3djs/particles.js index f6b7d4e..3874e30 100644 --- a/o3d/samples/o3djs/particles.js +++ b/o3d/samples/o3djs/particles.js @@ -39,6 +39,7 @@ o3djs.provide('o3djs.particles'); +o3djs.require('o3djs.effect'); o3djs.require('o3djs.math'); /** @@ -484,17 +485,16 @@ o3djs.particles.FX_STRINGS_GLSL = [ '\n' + '// #o3d MatrixLoadOrder RowMajor\n'}]; + /** - * Sets the shader language used. Passing 'glsl' will cause all generated - * shader code to be in glsl. Passing anything else will result in the - * default o3d hlsl/cg based shader language. - * @param {string} language Shader language to use. + * Sets the current shaders language to be in accordance with effect.js. */ -o3djs.particles.setLanguage = function(language) { +o3djs.particles.useCorrectShaders_ = function() { o3djs.particles.FX_STRINGS = o3djs.particles.FX_STRINGS_CG; - if (language == 'glsl') + if (o3djs.effect.LANGUAGE == 'glsl') { o3djs.particles.FX_STRINGS = o3djs.particles.FX_STRINGS_GLSL; -} + } +}; /** @@ -560,6 +560,7 @@ o3djs.particles.ParticleSystem = function(pack, var o3d = o3djs.base.o3d; var particleStates = []; var effects = []; + o3djs.particles.useCorrectShaders_(); for (var ee = 0; ee < o3djs.particles.FX_STRINGS.length; ++ee) { var info = o3djs.particles.FX_STRINGS[ee]; var effect = pack.createObject('Effect'); @@ -1507,6 +1508,3 @@ o3djs.particles.Trail.prototype.birthParticles = function(position) { }; -// For compatability with o3d code, the default language is o3d shading -// language. -o3djs.particles.setLanguage('o3d'); diff --git a/o3d/samples/o3djs/util.js b/o3d/samples/o3djs/util.js index d3542fa..24c09d0 100644 --- a/o3d/samples/o3djs/util.js +++ b/o3d/samples/o3djs/util.js @@ -39,6 +39,7 @@ o3djs.provide('o3djs.util'); o3djs.require('o3djs.io'); +o3djs.require('o3djs.effect'); o3djs.require('o3djs.event'); o3djs.require('o3djs.error'); @@ -817,6 +818,10 @@ o3djs.util.createClient = function(element, opt_features, opt_requestVersion) { element.appendChild(objElem); } + if (objElem.client.clientInfo.glsl) { + o3djs.effect.setLanguage('glsl'); + } + return objElem; }; |