diff --git a/.gitignore b/.gitignore
index 9aa9d49..6f31bda 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
.idea/**/*
.settings/*
*.iml
+pom.xml
*.svn*
*.DS_store*
diff --git a/pom.xml b/pom.xml
index 618d7c3..a8c15ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
platform.clients.fp11.libraries
Alternativa3D
swc
- 8.31.0-SNAPSHOT
+ 8.32.0-SNAPSHOT
platform.clients.fp11.tools.maven
BasePom
diff --git a/src/alternativa/Alternativa3D.as b/src/alternativa/Alternativa3D.as
index d9ae176..06ca898 100644
--- a/src/alternativa/Alternativa3D.as
+++ b/src/alternativa/Alternativa3D.as
@@ -17,6 +17,6 @@ package alternativa {
/**
* Library version in the format: generation.feature-version.fix-version.
*/
- public static const version:String = "8.30.0";
+ public static const version:String = "8.31.0";
}
}
diff --git a/src/alternativa/engine3d/materials/StandardMaterial.as b/src/alternativa/engine3d/materials/StandardMaterial.as
index c1018cc..adc2f77 100644
--- a/src/alternativa/engine3d/materials/StandardMaterial.as
+++ b/src/alternativa/engine3d/materials/StandardMaterial.as
@@ -53,7 +53,7 @@ package alternativa.engine3d.materials {
private static var caches:Dictionary = new Dictionary(true);
private var cachedContext3D:Context3D;
- private var programsCache:Vector.;
+ private var programsCache:Dictionary;
private var groups:Vector.> = new Vector.>();
/**
@@ -104,8 +104,6 @@ package alternativa.engine3d.materials {
* @private
*/
alternativa3d static var fogTexture:TextureResource;
- //light procedure caching. The key is light3d instance.
- private static const _lightFragmentProcedures:Dictionary = new Dictionary();
// inputs : position
private static const _passVaryingsProcedure:Procedure = new Procedure([
@@ -405,10 +403,11 @@ package alternativa.engine3d.materials {
// inputs: tNormal", "tViewVector", "shadow", "cAmbientColor"
// outputs : light, hightlight
- private function formDirectionalProcedure(procedure:Procedure, light:Light3D, useShadow:Boolean):void {
+ private function formDirectionalProcedure(procedure:Procedure, index:int, useShadow:Boolean):void {
var source:Array = [
- "#c0=c" + light.lightID + "Direction",
- "#c1=c" + light.lightID + "Color",
+ // Position - dirction vector of light
+ "#c0=c" + index + "Position",
+ "#c1=c" + index + "Color",
// Calculate half-way vector
"add t0.xyz, i1.xyz, c0.xyz",
"mov t0.w, c0.w",
@@ -418,7 +417,7 @@ package alternativa.engine3d.materials {
"pow t0.w, t0.w, o1.w",
// Calculate light
"dp3 t0.x, i0.xyz, c0.xyz",
- "sat t0.x, t0.x",
+ "sat t0.x, t0.x"
];
if (useShadow) {
source.push("mul t0.xw, t0.xw, i2.x");
@@ -435,12 +434,12 @@ package alternativa.engine3d.materials {
procedure.compileFromArray(source);
}
- private function formOmniProcedure(procedure:Procedure, light:Light3D, useShadow:Boolean):void {
+ private function formOmniProcedure(procedure:Procedure, index:int, useShadow:Boolean):void {
// fragmentLinker.setInputParams(omniMulShadowProcedure, "tNormal", "tViewVector", "tTotalLight", "cAmbientColor");
var source:Array = [
- "#c0=c" + light.lightID + "Position",
- "#c1=c" + light.lightID + "Color",
- "#c2=c" + light.lightID + "Radius",
+ "#c0=c" + index + "Position",
+ "#c1=c" + index + "Color",
+ "#c2=c" + index + "Radius",
"#v0=vPosition"
];
if (useShadow) {
@@ -515,16 +514,9 @@ package alternativa.engine3d.materials {
* @param directionalLight
* @param lightsLength
*/
- private function getProgram(object:Object3D, programs:Vector., camera:Camera3D, materialKey:String, opacityMap:TextureResource, alphaTest:int, lightsGroup:Vector., lightsLength:int, isFirstGroup:Boolean, shadowedLight:Light3D):StandardMaterialProgram {
+ private function getProgram(object:Object3D, programs:Dictionary, camera:Camera3D, materialKey:String, opacityMap:TextureResource, alphaTest:int, lightsGroup:Vector., lightsLength:int, isFirstGroup:Boolean, shadowedLight:Light3D):StandardMaterialProgram {
var key:String = materialKey + (opacityMap != null ? "O" : "o") + alphaTest.toString();
- var program:StandardMaterialProgram = null;//programs[key];
-
- for (var i:int = 0; i();
+ programsCache = new Dictionary();
caches[cachedContext3D] = programsCache;
}
}
-// var optionsPrograms:Dictionary = programsCache[object.transformProcedure];
-// if (optionsPrograms == null) {
-// optionsPrograms = new Dictionary(false);
-// programsCache[object.transformProcedure] = optionsPrograms;
-// }
+ var optionsPrograms:Dictionary = programsCache[object.transformProcedure];
+ if (optionsPrograms == null) {
+ optionsPrograms = new Dictionary(false);
+ programsCache[object.transformProcedure] = optionsPrograms;
+ }
// Form groups of lights
var groupsCount:int = 0;
@@ -1048,11 +1030,11 @@ package alternativa.engine3d.materials {
if (alphaThreshold > 0) {
// Alpha test
// use opacityMap if it is presented
- program = getProgram(object, programsCache, camera, materialKey, opacityMap, 1, null, 0, true, null);
+ program = getProgram(object, optionsPrograms, camera, materialKey, opacityMap, 1, null, 0, true, null);
addDrawUnits(program, camera, surface, geometry, opacityMap, null, 0, true, null, true, false, objectRenderPriority);
} else {
// do not use opacityMap at all
- program = getProgram(object, programsCache, camera, materialKey, null, 0, null, 0, true, null);
+ program = getProgram(object, optionsPrograms, camera, materialKey, null, 0, null, 0, true, null);
addDrawUnits(program, camera, surface, geometry, null, null, 0, true, null, true, false, objectRenderPriority);
}
}
@@ -1061,11 +1043,11 @@ package alternativa.engine3d.materials {
// use opacityMap if it is presented
if (alphaThreshold <= alpha && !opaquePass) {
// Alpha threshold
- program = getProgram(object, programsCache, camera, materialKey, opacityMap, 2, null, 0, true, null);
+ program = getProgram(object, optionsPrograms, camera, materialKey, opacityMap, 2, null, 0, true, null);
addDrawUnits(program, camera, surface, geometry, opacityMap, null, 0, true, null, false, true, objectRenderPriority);
} else {
// There is no Alpha threshold or check z-buffer by previous pass
- program = getProgram(object, programsCache, camera, materialKey, opacityMap, 0, null, 0, true, null);
+ program = getProgram(object, optionsPrograms, camera, materialKey, opacityMap, 0, null, 0, true, null);
addDrawUnits(program, camera, surface, geometry, opacityMap, null, 0, true, null, false, true, objectRenderPriority);
}
}
@@ -1094,11 +1076,11 @@ package alternativa.engine3d.materials {
if (alphaThreshold > 0) {
// Alpha test
// use opacityMap if it is presented
- program = getProgram(object, programsCache, camera, materialKey, opacityMap, 1, lightGroup, lightGroupLength, isFirstGroup, null);
+ program = getProgram(object, optionsPrograms, camera, materialKey, opacityMap, 1, lightGroup, lightGroupLength, isFirstGroup, null);
addDrawUnits(program, camera, surface, geometry, opacityMap, lightGroup, lightGroupLength, isFirstGroup, null, true, false, objectRenderPriority);
} else {
// do not use opacityMap at all
- program = getProgram(object, programsCache, camera, materialKey, null, 0, lightGroup, lightGroupLength, isFirstGroup, null);
+ program = getProgram(object, optionsPrograms, camera, materialKey, null, 0, lightGroup, lightGroupLength, isFirstGroup, null);
addDrawUnits(program, camera, surface, geometry, null, lightGroup, lightGroupLength, isFirstGroup, null, true, false, objectRenderPriority);
}
}
@@ -1107,11 +1089,11 @@ package alternativa.engine3d.materials {
// use opacityMap if it is presented
if (alphaThreshold <= alpha && !opaquePass) {
// Alpha threshold
- program = getProgram(object, programsCache, camera, materialKey, opacityMap, 2, lightGroup, lightGroupLength, isFirstGroup, null);
+ program = getProgram(object, optionsPrograms, camera, materialKey, opacityMap, 2, lightGroup, lightGroupLength, isFirstGroup, null);
addDrawUnits(program, camera, surface, geometry, opacityMap, lightGroup, lightGroupLength, isFirstGroup, null, false, true, objectRenderPriority);
} else {
// There is no Alpha threshold or check z-buffer by previous pass
- program = getProgram(object, programsCache, camera, materialKey, opacityMap, 0, lightGroup, lightGroupLength, isFirstGroup, null);
+ program = getProgram(object, optionsPrograms, camera, materialKey, opacityMap, 0, lightGroup, lightGroupLength, isFirstGroup, null);
addDrawUnits(program, camera, surface, geometry, opacityMap, lightGroup, lightGroupLength, isFirstGroup, null, false, true, objectRenderPriority);
}
}
@@ -1119,7 +1101,7 @@ package alternativa.engine3d.materials {
lightGroup.length = 0;
}
- if (shadowGroupLength > 0){
+ if (shadowGroupLength > 0) {
// Group of ligths with shadow
// For each light we will create new drawUnit
for (j = 0; j < shadowGroupLength; j++) {
@@ -1140,11 +1122,11 @@ package alternativa.engine3d.materials {
if (alphaThreshold > 0) {
// Alpha test
// use opacityMap if it is presented
- program = getProgram(object, programsCache, camera, materialKey, opacityMap, 1, null, 0, isFirstGroup, light);
+ program = getProgram(object, optionsPrograms, camera, materialKey, opacityMap, 1, null, 0, isFirstGroup, light);
addDrawUnits(program, camera, surface, geometry, opacityMap, null, 0, isFirstGroup, light, true, false, objectRenderPriority);
} else {
// do not use opacityMap at all
- program = getProgram(object, programsCache, camera, materialKey, null, 0, null, 0, isFirstGroup, light);
+ program = getProgram(object, optionsPrograms, camera, materialKey, null, 0, null, 0, isFirstGroup, light);
addDrawUnits(program, camera, surface, geometry, null, null, 0, isFirstGroup, light, true, false, objectRenderPriority);
}
}
@@ -1153,11 +1135,11 @@ package alternativa.engine3d.materials {
// use opacityMap if it is presented
if (alphaThreshold <= alpha && !opaquePass) {
// Alpha threshold
- program = getProgram(object, programsCache, camera, materialKey, opacityMap, 2, null, 0, isFirstGroup, light);
+ program = getProgram(object, optionsPrograms, camera, materialKey, opacityMap, 2, null, 0, isFirstGroup, light);
addDrawUnits(program, camera, surface, geometry, opacityMap, null, 0, isFirstGroup, light, false, true, objectRenderPriority);
} else {
// There is no Alpha threshold or check z-buffer by previous pass
- program = getProgram(object, programsCache, camera, materialKey, opacityMap, 0, null, 0, isFirstGroup, light);
+ program = getProgram(object, optionsPrograms, camera, materialKey, opacityMap, 0, null, 0, isFirstGroup, light);
addDrawUnits(program, camera, surface, geometry, opacityMap, null, 0, isFirstGroup, light, false, true, objectRenderPriority);
}
}
@@ -1218,8 +1200,18 @@ class StandardMaterialProgram extends ShaderProgram {
public var sSpecular:int = -1;
public var sLightMap:int = -1;
- public function StandardMaterialProgram(vertex:Linker, fragment:Linker) {
+ public var cPosition:Vector.;
+ public var cRadius:Vector.;
+ public var cAxis:Vector.;
+ public var cColor:Vector.;
+
+ public function StandardMaterialProgram(vertex:Linker, fragment:Linker, numLigths:int) {
super(vertex, fragment);
+
+ cPosition = new Vector.(numLigths);
+ cRadius = new Vector.(numLigths);
+ cAxis = new Vector.(numLigths);
+ cColor = new Vector.(numLigths);
}
override public function upload(context3D:Context3D):void {
@@ -1242,6 +1234,14 @@ class StandardMaterialProgram extends ShaderProgram {
sGlossiness = fragmentShader.findVariable("sGlossiness");
sSpecular = fragmentShader.findVariable("sSpecular");
sLightMap = fragmentShader.findVariable("sLightMap");
- }
+ var count:int = cPosition.length;
+ for (var i:int = 0; i < count; i++) {
+ cPosition[i] = fragmentShader.findVariable("c" + i + "Position");
+ cRadius[i] = fragmentShader.findVariable("c" + i + "Radius");
+ cAxis[i] = fragmentShader.findVariable("c" + i + "Axis");
+ cColor[i] = fragmentShader.findVariable("c" + i + "Color");
+ }
+
+ }
}