Fallback materials to simpler

This commit is contained in:
Yaski
2012-07-31 00:28:22 +06:00
parent 1cbd3cad2b
commit 094bbcd5b7
4 changed files with 90 additions and 3 deletions

View File

@@ -4,8 +4,8 @@
* You may add additional accurate notices of copyright ownership. * You may add additional accurate notices of copyright ownership.
* *
* It is desirable to notify that Covered Software was "Powered by AlternativaPlatform" with link to http://www.alternativaplatform.com/ * It is desirable to notify that Covered Software was "Powered by AlternativaPlatform" with link to http://www.alternativaplatform.com/
* */ *
*/
package alternativa.engine3d.core { package alternativa.engine3d.core {
import alternativa.engine3d.alternativa3d; import alternativa.engine3d.alternativa3d;
@@ -46,7 +46,9 @@ package alternativa.engine3d.core {
alternativa3d var camera:Camera3D; alternativa3d var camera:Camera3D;
alternativa3d var drawUnits:Vector.<DrawUnit> = new Vector.<DrawUnit>(); alternativa3d var drawUnits:Vector.<DrawUnit> = new Vector.<DrawUnit>();
alternativa3d var isConstrainedMode:Boolean = false;
protected var _context3D:Context3D; protected var _context3D:Context3D;
protected var _contextProperties:RendererContext3DProperties; protected var _contextProperties:RendererContext3DProperties;
@@ -187,6 +189,7 @@ package alternativa.engine3d.core {
properties[value] = _contextProperties; properties[value] = _contextProperties;
} }
_context3D = value; _context3D = value;
isConstrainedMode = _context3D.driverInfo.lastIndexOf("(Baseline Constrained)") >= 0;
} }
} }

View File

@@ -310,6 +310,15 @@ package alternativa.engine3d.materials {
"mov v0, a0" "mov v0, a0"
], "passLightMapUVProcedure"); ], "passLightMapUVProcedure");
/**
* @private
*/
alternativa3d static var fallbackTextureMaterial:TextureMaterial = new TextureMaterial();
/**
* @private
*/
alternativa3d static var fallbackLightMapMaterial:LightMapMaterial = new LightMapMaterial();
private var _normalMapSpace:int = NormalMapSpace.TANGENT_RIGHT_HANDED; private var _normalMapSpace:int = NormalMapSpace.TANGENT_RIGHT_HANDED;
/** /**
@@ -815,6 +824,31 @@ package alternativa.engine3d.materials {
if (_normalMap != null && _normalMap._texture == null) return; if (_normalMap != null && _normalMap._texture == null) return;
if (_reflectionMap != null && _reflectionMap._texture == null) return; if (_reflectionMap != null && _reflectionMap._texture == null) return;
if (_lightMap != null && _lightMap._texture == null) return; if (_lightMap != null && _lightMap._texture == null) return;
if (camera.renderer.isConstrainedMode) {
// fallback to simpler material
if (lightMap == null) {
fallbackTextureMaterial.diffuseMap = diffuseMap;
fallbackTextureMaterial.opacityMap = opacityMap;
fallbackTextureMaterial.alphaThreshold = alphaThreshold;
fallbackTextureMaterial.alpha = alpha;
fallbackTextureMaterial.opaquePass = opaquePass;
fallbackTextureMaterial.transparentPass = transparentPass;
fallbackTextureMaterial.collectDraws(camera, surface, geometry, lights, lightsLength, useShadow, objectRenderPriority);
} else {
fallbackLightMapMaterial.diffuseMap = diffuseMap;
fallbackLightMapMaterial.lightMap = lightMap;
fallbackLightMapMaterial.lightMapChannel = lightMapChannel;
fallbackLightMapMaterial.opacityMap = opacityMap;
fallbackLightMapMaterial.alphaThreshold = alphaThreshold;
fallbackLightMapMaterial.alpha = alpha;
fallbackLightMapMaterial.opaquePass = opaquePass;
fallbackLightMapMaterial.transparentPass = transparentPass;
fallbackLightMapMaterial.collectDraws(camera, surface, geometry, lights, lightsLength, useShadow, objectRenderPriority);
}
return;
}
var object:Object3D = surface.object; var object:Object3D = surface.object;
// Program // Program

View File

@@ -307,6 +307,15 @@ package alternativa.engine3d.materials {
"mov v0, a0" "mov v0, a0"
], "passLightMapUVProcedure"); ], "passLightMapUVProcedure");
/**
* @private
*/
alternativa3d static var fallbackTextureMaterial:TextureMaterial = new TextureMaterial();
/**
* @private
*/
alternativa3d static var fallbackLightMapMaterial:LightMapMaterial = new LightMapMaterial();
/** /**
* Normal map. * Normal map.
*/ */
@@ -986,6 +995,30 @@ package alternativa.engine3d.materials {
// Check if textures uploaded in to the context. // Check if textures uploaded in to the context.
if (opacityMap != null && opacityMap._texture == null || glossinessMap != null && glossinessMap._texture == null || specularMap != null && specularMap._texture == null || lightMap != null && lightMap._texture == null) return; if (opacityMap != null && opacityMap._texture == null || glossinessMap != null && glossinessMap._texture == null || specularMap != null && specularMap._texture == null || lightMap != null && lightMap._texture == null) return;
if (camera.renderer.isConstrainedMode) {
// fallback to simpler material
if (lightMap == null) {
fallbackTextureMaterial.diffuseMap = diffuseMap;
fallbackTextureMaterial.opacityMap = opacityMap;
fallbackTextureMaterial.alphaThreshold = alphaThreshold;
fallbackTextureMaterial.alpha = alpha;
fallbackTextureMaterial.opaquePass = opaquePass;
fallbackTextureMaterial.transparentPass = transparentPass;
fallbackTextureMaterial.collectDraws(camera, surface, geometry, lights, lightsLength, useShadow, objectRenderPriority);
} else {
fallbackLightMapMaterial.diffuseMap = diffuseMap;
fallbackLightMapMaterial.lightMap = lightMap;
fallbackLightMapMaterial.lightMapChannel = lightMapChannel;
fallbackLightMapMaterial.opacityMap = opacityMap;
fallbackLightMapMaterial.alphaThreshold = alphaThreshold;
fallbackLightMapMaterial.alpha = alpha;
fallbackLightMapMaterial.opaquePass = opaquePass;
fallbackLightMapMaterial.transparentPass = transparentPass;
fallbackLightMapMaterial.collectDraws(camera, surface, geometry, lights, lightsLength, useShadow, objectRenderPriority);
}
return;
}
var object:Object3D = surface.object; var object:Object3D = surface.object;
// Buffers // Buffers

View File

@@ -98,6 +98,11 @@ package alternativa.engine3d.materials {
private static const _lightsProcedures:Dictionary = new Dictionary(true); private static const _lightsProcedures:Dictionary = new Dictionary(true);
/**
* @private
*/
alternativa3d static var fallbackMaterial:TextureMaterial = new TextureMaterial();
/** /**
* Creates a new VertexLightTextureMaterial instance. * Creates a new VertexLightTextureMaterial instance.
* *
@@ -282,6 +287,18 @@ package alternativa.engine3d.materials {
override alternativa3d function collectDraws(camera:Camera3D, surface:Surface, geometry:Geometry, lights:Vector.<Light3D>, lightsLength:int, useShadow:Boolean, objectRenderPriority:int = -1):void { override alternativa3d function collectDraws(camera:Camera3D, surface:Surface, geometry:Geometry, lights:Vector.<Light3D>, lightsLength:int, useShadow:Boolean, objectRenderPriority:int = -1):void {
if (diffuseMap == null || diffuseMap._texture == null || opacityMap != null && opacityMap._texture == null) return; if (diffuseMap == null || diffuseMap._texture == null || opacityMap != null && opacityMap._texture == null) return;
if (camera.renderer.isConstrainedMode) {
// fallback to texture material
fallbackMaterial.diffuseMap = diffuseMap;
fallbackMaterial.opacityMap = opacityMap;
fallbackMaterial.alphaThreshold = alphaThreshold;
fallbackMaterial.alpha = alpha;
fallbackMaterial.opaquePass = opaquePass;
fallbackMaterial.transparentPass = transparentPass;
fallbackMaterial.collectDraws(camera, surface, geometry, lights, lightsLength, useShadow, objectRenderPriority);
return;
}
var object:Object3D = surface.object; var object:Object3D = surface.object;
// Buffers // Buffers