Fixed wrong caching of lights programs for many lights

This commit is contained in:
Yaski
2012-08-20 21:01:05 +06:00
parent 1d40f648d7
commit f226a7c103

View File

@@ -1076,9 +1076,6 @@ package alternativa.engine3d.materials {
// Iterate groups // Iterate groups
var materialKey:int; var materialKey:int;
var program:StandardMaterialProgram; var program:StandardMaterialProgram;
var omniLightCount:int = 0;
var directionalLightCount:int = 0;
var spotLightCount:int = 0;
if (groupsCount == 0 && shadowGroupLength == 0) { if (groupsCount == 0 && shadowGroupLength == 0) {
// There is only Ambient light on the scene // There is only Ambient light on the scene
@@ -1121,9 +1118,14 @@ package alternativa.engine3d.materials {
// Form key // Form key
materialKey = (isFirstGroup) ? ((lightMap != null) ? LIGHT_MAP_BIT : 0) : 0; materialKey = (isFirstGroup) ? ((lightMap != null) ? LIGHT_MAP_BIT : 0) : 0;
materialKey |= (_normalMapSpace << NORMAL_MAP_SPACE_OFFSET) | ((glossinessMap != null) ? GLOSSINESS_MAP_BIT : 0) | ((specularMap != null) ? SPECULAR_MAP_BIT : 0); materialKey |= (_normalMapSpace << NORMAL_MAP_SPACE_OFFSET) | ((glossinessMap != null) ? GLOSSINESS_MAP_BIT : 0) | ((specularMap != null) ? SPECULAR_MAP_BIT : 0);
var omniLightCount:int = 0;
var directionalLightCount:int = 0;
var spotLightCount:int = 0;
for (j = 0; j < lightGroupLength; j++) { for (j = 0; j < lightGroupLength; j++) {
light = lightGroup[j]; light = lightGroup[j];
if (light is OmniLight) omniLightCount++; else if (light is DirectionalLight) directionalLightCount++; else if (light is SpotLight) spotLightCount++; if (light is OmniLight) omniLightCount++;
else if (light is DirectionalLight) directionalLightCount++;
else if (light is SpotLight) spotLightCount++;
} }
materialKey |= omniLightCount << OMNI_LIGHT_OFFSET; materialKey |= omniLightCount << OMNI_LIGHT_OFFSET;
materialKey |= directionalLightCount << DIRECTIONAL_LIGHT_OFFSET; materialKey |= directionalLightCount << DIRECTIONAL_LIGHT_OFFSET;
@@ -1170,7 +1172,9 @@ package alternativa.engine3d.materials {
materialKey = (isFirstGroup) ? ((lightMap != null) ? LIGHT_MAP_BIT : 0) : 0; materialKey = (isFirstGroup) ? ((lightMap != null) ? LIGHT_MAP_BIT : 0) : 0;
materialKey |= (_normalMapSpace << NORMAL_MAP_SPACE_OFFSET) | ((glossinessMap != null) ? GLOSSINESS_MAP_BIT : 0) | ((specularMap != null) ? SPECULAR_MAP_BIT : 0); materialKey |= (_normalMapSpace << NORMAL_MAP_SPACE_OFFSET) | ((glossinessMap != null) ? GLOSSINESS_MAP_BIT : 0) | ((specularMap != null) ? SPECULAR_MAP_BIT : 0);
materialKey |= light.shadow.type << SHADOW_OFFSET; materialKey |= light.shadow.type << SHADOW_OFFSET;
if (light is OmniLight) materialKey |= 1 << OMNI_LIGHT_OFFSET; else if (light is DirectionalLight) materialKey |= 1 << DIRECTIONAL_LIGHT_OFFSET; else if (light is SpotLight) materialKey |= 1 << SPOT_LIGHT_OFFSET; if (light is OmniLight) materialKey |= 1 << OMNI_LIGHT_OFFSET;
else if (light is DirectionalLight) materialKey |= 1 << DIRECTIONAL_LIGHT_OFFSET;
else if (light is SpotLight) materialKey |= 1 << SPOT_LIGHT_OFFSET;
// Для группы создаем программу и дроуюнит // Для группы создаем программу и дроуюнит
// Opaque pass // Opaque pass