| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 | 590 |
| 591 | 591 |
| 592 /** | 592 /** |
| 593 * Builds bump output coords if needed. | 593 * Builds bump output coords if needed. |
| 594 * @param {boolean} bumpSampler Whether there is a bump sampler. | 594 * @param {boolean} bumpSampler Whether there is a bump sampler. |
| 595 * @return {string} The code for bump input coords. | 595 * @return {string} The code for bump input coords. |
| 596 */ | 596 */ |
| 597 o3djs.effect.buildBumpOutputCoords = function(bumpSampler) { | 597 o3djs.effect.buildBumpOutputCoords = function(bumpSampler) { |
| 598 var p = o3djs.effect; | 598 var p = o3djs.effect; |
| 599 return bumpSampler ? | 599 return bumpSampler ? |
| 600 (' ' + p.FLOAT3 + ' tangent' + | 600 (' ' + p.VARYING + p.FLOAT3 + ' ' + |
| 601 p.VARYING_DECLARATION_PREFIX + 'tangent' + |
| 601 p.semanticSuffix( | 602 p.semanticSuffix( |
| 602 'TEXCOORD' + p.interpolant_++) + ';\n' + | 603 'TEXCOORD' + p.interpolant_++) + ';\n' + |
| 603 ' ' + p.FLOAT3 + ' binormal' + | 604 ' ' + p.VARYING + p.FLOAT3 + ' ' + |
| 604 p.semanticSuffix('TEXCOORD' + | 605 p.VARYING_DECLARATION_PREFIX + 'binormal' + |
| 605 p.interpolant_++) + ';\n' + | 606 p.semanticSuffix( |
| 606 ' ' + p.FLOAT2 + ' bumpUV' + | 607 'TEXCOORD' + p.interpolant_++) + ';\n' + |
| 608 ' ' + p.VARYING + p.FLOAT2 + ' ' + |
| 609 p.VARYING_DECLARATION_PREFIX + 'bumpUV' + |
| 607 p.semanticSuffix( | 610 p.semanticSuffix( |
| 608 'TEXCOORD' + p.interpolant_++) + ';\n') : ''; | 611 'TEXCOORD' + p.interpolant_++) + ';\n') : ''; |
| 609 }; | 612 }; |
| 610 | 613 |
| 611 | 614 |
| 612 /** | 615 /** |
| 613 * Builds vertex and fragment shader string for a 2-color checker effect. | 616 * Builds vertex and fragment shader string for a 2-color checker effect. |
| 614 * @return {string} The effect code for the shader, ready to be parsed. | 617 * @return {string} The effect code for the shader, ready to be parsed. |
| 615 */ | 618 */ |
| 616 o3djs.effect.buildCheckerShaderString = function() { | 619 o3djs.effect.buildCheckerShaderString = function() { |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 * @return {string} The code for the vertex shader. | 1168 * @return {string} The code for the vertex shader. |
| 1166 */ | 1169 */ |
| 1167 var surfaceToViewVertexShaderCode = function() { | 1170 var surfaceToViewVertexShaderCode = function() { |
| 1168 return ' ' + p.VERTEX_VARYING_PREFIX + | 1171 return ' ' + p.VERTEX_VARYING_PREFIX + |
| 1169 'surfaceToView = (viewInverse[3] - ' + | 1172 'surfaceToView = (viewInverse[3] - ' + |
| 1170 p.mul(p.ATTRIBUTE_PREFIX + 'position', 'world') + ').xyz;\n'; | 1173 p.mul(p.ATTRIBUTE_PREFIX + 'position', 'world') + ').xyz;\n'; |
| 1171 }; | 1174 }; |
| 1172 | 1175 |
| 1173 /** | 1176 /** |
| 1174 * Builds the normal map part of the vertex shader. | 1177 * Builds the normal map part of the vertex shader. |
| 1175 * @param {boolean} opt_bumpSampler Whether there is a bump | |
| 1176 * sampler. Default = false. | |
| 1177 * @return {string} The code for normal mapping in the vertex shader. | 1178 * @return {string} The code for normal mapping in the vertex shader. |
| 1178 */ | 1179 */ |
| 1179 var bumpVertexShaderCode = function(opt_bumpSampler) { | 1180 var bumpVertexShaderCode = function() { |
| 1180 return bumpSampler ? | 1181 return bumpSampler ? |
| 1181 (' ' + p.VERTEX_VARYING_PREFIX + 'binormal = ' + | 1182 (' ' + p.VERTEX_VARYING_PREFIX + 'binormal = ' + |
| 1182 p.mul(p.FLOAT4 + '(' + | 1183 p.mul(p.FLOAT4 + '(' + |
| 1183 p.ATTRIBUTE_PREFIX + 'binormal, 0)', | 1184 p.ATTRIBUTE_PREFIX + 'binormal, 0)', |
| 1184 'worldInverseTranspose') + '.xyz;\n' + | 1185 'worldInverseTranspose') + '.xyz;\n' + |
| 1185 ' ' + p.VERTEX_VARYING_PREFIX + 'tangent = ' + | 1186 ' ' + p.VERTEX_VARYING_PREFIX + 'tangent = ' + |
| 1186 p.mul(p.FLOAT4 + | 1187 p.mul(p.FLOAT4 + |
| 1187 '(' + p.ATTRIBUTE_PREFIX + 'tangent, 0)', | 1188 '(' + p.ATTRIBUTE_PREFIX + 'tangent, 0)', |
| 1188 'worldInverseTranspose') + '.xyz;\n') : ''; | 1189 'worldInverseTranspose') + '.xyz;\n') : ''; |
| 1189 }; | 1190 }; |
| 1190 | 1191 |
| 1191 /** | 1192 /** |
| 1192 * Builds the normal calculation of the pixel shader. | 1193 * Builds the normal calculation of the pixel shader. |
| 1193 * @return {string} The code for normal computation in the pixel shader. | 1194 * @return {string} The code for normal computation in the pixel shader. |
| 1194 */ | 1195 */ |
| 1195 var getNormalShaderCode = function() { | 1196 var getNormalShaderCode = function() { |
| 1196 return bumpSampler ? | 1197 if (bumpSampler) { |
| 1197 (p.MATRIX3 + ' tangentToWorld = ' + p.MATRIX3 + | 1198 var type = getSamplerType(bumpSampler); |
| 1198 '(' + p.ATTRIBUTE_PREFIX + 'tangent,\n' + | 1199 var tex2D = p.TEXTURE + type; |
| 1200 return ( |
| 1201 p.MATRIX3 + ' tangentToWorld = ' + p.MATRIX3 + |
| 1202 '(' + p.PIXEL_VARYING_PREFIX + 'tangent,\n' + |
| 1199 ' ' + | 1203 ' ' + |
| 1200 p.ATTRIBUTE_PREFIX + 'binormal,\n' + | 1204 p.PIXEL_VARYING_PREFIX + 'binormal,\n' + |
| 1201 ' ' + | 1205 ' ' + |
| 1202 p.ATTRIBUTE_PREFIX + 'normal);\n' + | 1206 p.PIXEL_VARYING_PREFIX + 'normal);\n' + |
| 1203 p.FLOAT3 + ' tangentNormal = tex2D(bumpSampler, ' + | 1207 p.FLOAT3 + ' tangentNormal = ' + tex2D + '(bumpSampler, ' + |
| 1204 p.ATTRIBUTE_PREFIX + 'bumpUV.xy).xyz -\n' + | 1208 p.PIXEL_VARYING_PREFIX + 'bumpUV.xy).xyz -\n' + |
| 1205 ' ' + p.FLOAT3 + | 1209 ' ' + p.FLOAT3 + |
| 1206 '(0.5, 0.5, 0.5);\n' + p.FLOAT3 + ' normal = ' + | 1210 '(0.5, 0.5, 0.5);\n' + p.FLOAT3 + ' normal = ' + |
| 1207 p.mul('tangentNormal', 'tangentToWorld') + ';\n' + | 1211 p.mul('tangentNormal', 'tangentToWorld') + ';\n' + |
| 1208 'normal = normalize(' + p.PIXEL_VARYING_PREFIX + | 1212 'normal = normalize(' + p.PIXEL_VARYING_PREFIX + |
| 1209 'normal);\n') : ' ' + p.FLOAT3 + ' normal = normalize(' + | 1213 'normal);\n'); |
| 1214 } else { |
| 1215 return ' ' + p.FLOAT3 + ' normal = normalize(' + |
| 1210 p.PIXEL_VARYING_PREFIX + 'normal);\n'; | 1216 p.PIXEL_VARYING_PREFIX + 'normal);\n'; |
| 1217 } |
| 1211 }; | 1218 }; |
| 1212 | 1219 |
| 1213 /** | 1220 /** |
| 1214 * Builds the vertex declarations for a given material. | 1221 * Builds the vertex declarations for a given material. |
| 1215 * @param {!o3d.Material} material The material to inspect. | 1222 * @param {!o3d.Material} material The material to inspect. |
| 1216 * @param {boolean} diffuse Whether to include stuff for diffuse | 1223 * @param {boolean} diffuse Whether to include stuff for diffuse |
| 1217 * calculations. | 1224 * calculations. |
| 1218 * @param {boolean} specular Whether to include stuff for diffuse | 1225 * @param {boolean} specular Whether to include stuff for diffuse |
| 1219 * calculations. | 1226 * calculations. |
| 1220 * @return {string} The code for the vertex declarations. | 1227 * @return {string} The code for the vertex declarations. |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 effect.name = o3djs.effect.TWO_COLOR_CHECKER_EFFECT_NAME; | 1381 effect.name = o3djs.effect.TWO_COLOR_CHECKER_EFFECT_NAME; |
| 1375 return effect; | 1382 return effect; |
| 1376 }; | 1383 }; |
| 1377 | 1384 |
| 1378 | 1385 |
| 1379 // For compatability with o3d code, the default language is o3d shading | 1386 // For compatability with o3d code, the default language is o3d shading |
| 1380 // language. | 1387 // language. |
| 1381 o3djs.effect.setLanguage('o3d'); | 1388 o3djs.effect.setLanguage('o3d'); |
| 1382 | 1389 |
| 1383 | 1390 |
| OLD | NEW |