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 993 matching lines...) Loading... |
1004 var eye = [0, 0, 0]; | 1004 var eye = [0, 0, 0]; |
1005 var target = [0, 0, 0]; | 1005 var target = [0, 0, 0]; |
1006 g_cameraInfo.getEyeAndTarget(eye, target); | 1006 g_cameraInfo.getEyeAndTarget(eye, target); |
1007 g_shadowPassViewInfo.drawContext.view = | 1007 g_shadowPassViewInfo.drawContext.view = |
1008 g_viewInfo.drawContext.view = g_math.matrix4.lookAt(eye, target, [0, 0, 1]); | 1008 g_viewInfo.drawContext.view = g_math.matrix4.lookAt(eye, target, [0, 0, 1]); |
1009 | 1009 |
1010 updateMaterials(); | 1010 updateMaterials(); |
1011 } | 1011 } |
1012 | 1012 |
1013 | 1013 |
| 1014 function setOptionalParam(material, name, value) { |
| 1015 var param = material.getParam(name); |
| 1016 if (param) { |
| 1017 param.value = value; |
| 1018 } |
| 1019 } |
| 1020 |
| 1021 |
1014 function initMaterials() { | 1022 function initMaterials() { |
1015 g_materials = { | 1023 g_materials = { |
1016 'solid':{}, | 1024 'solid':{}, |
1017 'felt':{}, | 1025 'felt':{}, |
1018 'wood':{}, | 1026 'wood':{}, |
1019 'cushion':{}, | 1027 'cushion':{}, |
1020 'billiard':{}, | 1028 'billiard':{}, |
1021 'ball':{}, | 1029 'ball':{}, |
1022 'shadowPlane':{}}; | 1030 'shadowPlane':{}}; |
1023 | 1031 |
(...skipping 14 matching lines...) Loading... |
1038 effect.loadPixelShaderFromString(pixelShaderString + mainString); | 1046 effect.loadPixelShaderFromString(pixelShaderString + mainString); |
1039 | 1047 |
1040 material.effect = effect; | 1048 material.effect = effect; |
1041 effect.createUniformParameters(material); | 1049 effect.createUniformParameters(material); |
1042 material.drawList = g_viewInfo.performanceDrawList; | 1050 material.drawList = g_viewInfo.performanceDrawList; |
1043 | 1051 |
1044 var eye = [0, 0, 0]; | 1052 var eye = [0, 0, 0]; |
1045 var target = [0, 0, 0]; | 1053 var target = [0, 0, 0]; |
1046 g_cameraInfo.getEyeAndTarget(eye, target); | 1054 g_cameraInfo.getEyeAndTarget(eye, target); |
1047 | 1055 |
1048 material.getParam('factor').value = 2 / g_tableWidth; | 1056 setOptionalParam(material, 'factor', 2 / g_tableWidth); |
1049 material.getParam('lightWorldPosition').value = g_light; | 1057 setOptionalParam(material, 'lightWorldPosition', g_light); |
1050 material.getParam('eyeWorldPosition').value = eye; | 1058 setOptionalParam(material, 'eyeWorldPosition', eye); |
1051 } | 1059 } |
1052 | 1060 |
1053 g_solidMaterial = g_materials['solid']; | 1061 g_solidMaterial = g_materials['solid']; |
1054 g_solidMaterial.drawList = g_hudViewInfo.zOrderedDrawList; | 1062 g_solidMaterial.drawList = g_hudViewInfo.zOrderedDrawList; |
1055 | 1063 |
1056 g_materials['shadowPlane'].drawList = g_shadowPassViewInfo.zOrderedDrawList; | 1064 g_materials['shadowPlane'].drawList = g_shadowPassViewInfo.zOrderedDrawList; |
1057 | 1065 |
1058 g_shadowSampler = g_pack.createObject('Sampler'); | 1066 g_shadowSampler = g_pack.createObject('Sampler'); |
1059 g_shadowSampler.texture = g_shadowTexture; | 1067 g_shadowSampler.texture = g_shadowTexture; |
1060 g_materials['felt'].getParam('textureSampler').value = g_shadowSampler; | 1068 g_materials['felt'].getParam('textureSampler').value = g_shadowSampler; |
1061 | 1069 |
1062 o3djs.io.loadBitmaps(g_pack, | 1070 o3djs.io.loadBitmaps(g_pack, |
1063 o3djs.util.getAbsoluteURI('../assets/poolballs.png'), | 1071 o3djs.util.getAbsoluteURI('../assets/poolballs.png'), |
1064 finishLoadingBitmaps); | 1072 finishLoadingBitmaps); |
1065 } | 1073 } |
1066 | 1074 |
1067 | 1075 |
1068 function updateMaterials() { | 1076 function updateMaterials() { |
1069 for (name in g_materials) { | 1077 for (name in g_materials) { |
1070 var eye = [0, 0, 0]; | 1078 var eye = [0, 0, 0]; |
1071 var target = [0, 0, 0]; | 1079 var target = [0, 0, 0]; |
1072 g_cameraInfo.getEyeAndTarget(eye, target); | 1080 g_cameraInfo.getEyeAndTarget(eye, target); |
1073 g_materials[name].getParam('eyeWorldPosition').value = eye; | 1081 setOptionalParam(g_materials[name], 'eyeWorldPosition', eye); |
1074 } | 1082 } |
1075 } | 1083 } |
1076 | 1084 |
1077 | 1085 |
1078 /** | 1086 /** |
1079 * Gets called back when the bitmap has loaded. | 1087 * Gets called back when the bitmap has loaded. |
1080 */ | 1088 */ |
1081 function finishLoadingBitmaps(bitmaps, exception) { | 1089 function finishLoadingBitmaps(bitmaps, exception) { |
1082 var bitmap = bitmaps[0]; | 1090 var bitmap = bitmaps[0]; |
1083 | 1091 |
(...skipping 1040 matching lines...) Loading... |
2124 } | 2132 } |
2125 | 2133 |
2126 </textarea> | 2134 </textarea> |
2127 <!-- End of effect --> | 2135 <!-- End of effect --> |
2128 </div> | 2136 </div> |
2129 | 2137 |
2130 </body> | 2138 </body> |
2131 </html> | 2139 </html> |
2132 | 2140 |
2133 | 2141 |
OLD | NEW |