mirror of
https://github.com/MapMakersAndProgrammers/Alternativa3D.git
synced 2025-10-27 10:29:07 -07:00
work version
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
.idea/**/*
|
.idea/**/*
|
||||||
.settings/*
|
.settings/*
|
||||||
*.iml
|
*.iml
|
||||||
|
pom.xml
|
||||||
*.svn*
|
*.svn*
|
||||||
*.DS_store*
|
*.DS_store*
|
||||||
|
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -3,7 +3,7 @@
|
|||||||
<groupId>platform.clients.fp11.libraries</groupId>
|
<groupId>platform.clients.fp11.libraries</groupId>
|
||||||
<artifactId>Alternativa3D</artifactId>
|
<artifactId>Alternativa3D</artifactId>
|
||||||
<packaging>swc</packaging>
|
<packaging>swc</packaging>
|
||||||
<version>8.31.0-SNAPSHOT</version>
|
<version>8.32.0-SNAPSHOT</version>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>platform.clients.fp11.tools.maven</groupId>
|
<groupId>platform.clients.fp11.tools.maven</groupId>
|
||||||
<artifactId>BasePom</artifactId>
|
<artifactId>BasePom</artifactId>
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ package alternativa {
|
|||||||
/**
|
/**
|
||||||
* Library version in the format: generation.feature-version.fix-version.
|
* 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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ package alternativa.engine3d.materials {
|
|||||||
|
|
||||||
private static var caches:Dictionary = new Dictionary(true);
|
private static var caches:Dictionary = new Dictionary(true);
|
||||||
private var cachedContext3D:Context3D;
|
private var cachedContext3D:Context3D;
|
||||||
private var programsCache:Array;
|
private var programsCache:Dictionary;
|
||||||
private var groups:Vector.<Vector.<Light3D>> = new Vector.<Vector.<Light3D>>();
|
private var groups:Vector.<Vector.<Light3D>> = new Vector.<Vector.<Light3D>>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -417,10 +417,11 @@ package alternativa.engine3d.materials {
|
|||||||
|
|
||||||
// inputs: tNormal", "tViewVector", "shadow", "cAmbientColor"
|
// inputs: tNormal", "tViewVector", "shadow", "cAmbientColor"
|
||||||
// outputs : light, hightlight
|
// 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 = [
|
var source:Array = [
|
||||||
"#c0=c" + light.lightID + "Direction",
|
// Position - dirction vector of light
|
||||||
"#c1=c" + light.lightID + "Color",
|
"#c0=c" + index + "Position",
|
||||||
|
"#c1=c" + index + "Color",
|
||||||
// Calculate half-way vector
|
// Calculate half-way vector
|
||||||
"add t0.xyz, i1.xyz, c0.xyz",
|
"add t0.xyz, i1.xyz, c0.xyz",
|
||||||
"mov t0.w, c0.w",
|
"mov t0.w, c0.w",
|
||||||
@@ -430,7 +431,7 @@ package alternativa.engine3d.materials {
|
|||||||
"pow t0.w, t0.w, o1.w",
|
"pow t0.w, t0.w, o1.w",
|
||||||
// Calculate light
|
// Calculate light
|
||||||
"dp3 t0.x, i0.xyz, c0.xyz",
|
"dp3 t0.x, i0.xyz, c0.xyz",
|
||||||
"sat t0.x, t0.x",
|
"sat t0.x, t0.x"
|
||||||
];
|
];
|
||||||
if (useShadow) {
|
if (useShadow) {
|
||||||
source.push("mul t0.xw, t0.xw, i2.x");
|
source.push("mul t0.xw, t0.xw, i2.x");
|
||||||
@@ -447,12 +448,12 @@ package alternativa.engine3d.materials {
|
|||||||
procedure.compileFromArray(source);
|
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");
|
// fragmentLinker.setInputParams(omniMulShadowProcedure, "tNormal", "tViewVector", "tTotalLight", "cAmbientColor");
|
||||||
var source:Array = [
|
var source:Array = [
|
||||||
"#c0=c" + light.lightID + "Position",
|
"#c0=c" + index + "Position",
|
||||||
"#c1=c" + light.lightID + "Color",
|
"#c1=c" + index + "Color",
|
||||||
"#c2=c" + light.lightID + "Radius",
|
"#c2=c" + index + "Radius",
|
||||||
"#v0=vPosition"
|
"#v0=vPosition"
|
||||||
];
|
];
|
||||||
if (useShadow) {
|
if (useShadow) {
|
||||||
@@ -633,11 +634,8 @@ package alternativa.engine3d.materials {
|
|||||||
fragmentLinker.addProcedure(shadowProc);
|
fragmentLinker.addProcedure(shadowProc);
|
||||||
fragmentLinker.setOutputParams(shadowProc, "tTotalLight");
|
fragmentLinker.setOutputParams(shadowProc, "tTotalLight");
|
||||||
|
|
||||||
var dirMulShadowProcedure:Procedure = _lightFragmentProcedures[shadowedLight.shadow];
|
var dirMulShadowProcedure:Procedure = new Procedure(null, "lightShadowDirectional");
|
||||||
if (dirMulShadowProcedure == null) {
|
formDirectionalProcedure(dirMulShadowProcedure, 0, true);
|
||||||
dirMulShadowProcedure = new Procedure();
|
|
||||||
formDirectionalProcedure(dirMulShadowProcedure, shadowedLight, true);
|
|
||||||
}
|
|
||||||
fragmentLinker.addProcedure(dirMulShadowProcedure);
|
fragmentLinker.addProcedure(dirMulShadowProcedure);
|
||||||
fragmentLinker.setInputParams(dirMulShadowProcedure, "tNormal", "tViewVector", "tTotalLight", "cAmbientColor");
|
fragmentLinker.setInputParams(dirMulShadowProcedure, "tNormal", "tViewVector", "tTotalLight", "cAmbientColor");
|
||||||
fragmentLinker.setOutputParams(dirMulShadowProcedure, "tTotalLight", "tTotalHighLight");
|
fragmentLinker.setOutputParams(dirMulShadowProcedure, "tTotalLight", "tTotalHighLight");
|
||||||
@@ -649,11 +647,8 @@ package alternativa.engine3d.materials {
|
|||||||
fragmentLinker.addProcedure(shadowProc);
|
fragmentLinker.addProcedure(shadowProc);
|
||||||
fragmentLinker.setOutputParams(shadowProc, "tTotalLight");
|
fragmentLinker.setOutputParams(shadowProc, "tTotalLight");
|
||||||
|
|
||||||
var omniMulShadowProcedure:Procedure = _lightFragmentProcedures[shadowedLight.shadow];
|
var omniMulShadowProcedure:Procedure = new Procedure(null, "lightShadowDirectional");
|
||||||
if (omniMulShadowProcedure == null) {
|
formOmniProcedure(omniMulShadowProcedure, 0, true);
|
||||||
omniMulShadowProcedure= new Procedure();
|
|
||||||
formOmniProcedure(omniMulShadowProcedure, shadowedLight, true);
|
|
||||||
}
|
|
||||||
fragmentLinker.addProcedure(omniMulShadowProcedure);
|
fragmentLinker.addProcedure(omniMulShadowProcedure);
|
||||||
fragmentLinker.setInputParams(omniMulShadowProcedure, "tNormal", "tViewVector", "tTotalLight", "cAmbientColor");
|
fragmentLinker.setInputParams(omniMulShadowProcedure, "tNormal", "tViewVector", "tTotalLight", "cAmbientColor");
|
||||||
fragmentLinker.setOutputParams(omniMulShadowProcedure, "tTotalLight", "tTotalHighLight");
|
fragmentLinker.setOutputParams(omniMulShadowProcedure, "tTotalLight", "tTotalHighLight");
|
||||||
@@ -663,52 +658,49 @@ package alternativa.engine3d.materials {
|
|||||||
for (i = 0; i < lightsLength; i++) {
|
for (i = 0; i < lightsLength; i++) {
|
||||||
var light:Light3D = lightsGroup[i];
|
var light:Light3D = lightsGroup[i];
|
||||||
if (light == shadowedLight && (shadowedLight is DirectionalLight || shadowedLight is OmniLight)) continue;
|
if (light == shadowedLight && (shadowedLight is DirectionalLight || shadowedLight is OmniLight)) continue;
|
||||||
var lightFragmentProcedure:Procedure = _lightFragmentProcedures[light];
|
var lightFragmentProcedure:Procedure = new Procedure();
|
||||||
if (lightFragmentProcedure == null) {
|
lightFragmentProcedure.name = "light" + i.toString();
|
||||||
lightFragmentProcedure = new Procedure();
|
if (light is DirectionalLight) {
|
||||||
lightFragmentProcedure.name = "light" + i.toString();
|
formDirectionalProcedure(lightFragmentProcedure, i, false);
|
||||||
if (light is DirectionalLight) {
|
lightFragmentProcedure.name += "Directional";
|
||||||
formDirectionalProcedure(lightFragmentProcedure, light, false);
|
} else if (light is OmniLight) {
|
||||||
lightFragmentProcedure.name += "Directional";
|
formOmniProcedure(lightFragmentProcedure, i, false);
|
||||||
} else if (light is OmniLight) {
|
lightFragmentProcedure.name += "Omni";
|
||||||
formOmniProcedure(lightFragmentProcedure, light, false);
|
} else if (light is SpotLight) {
|
||||||
lightFragmentProcedure.name += "Omni";
|
lightFragmentProcedure.compileFromArray([
|
||||||
} else if (light is SpotLight) {
|
"#c0=c" + i + "Position",
|
||||||
lightFragmentProcedure.compileFromArray([
|
"#c1=c" + i + "Color",
|
||||||
"#c0=c" + light.lightID + "Position",
|
"#c2=c" + i + "Radius",
|
||||||
"#c1=c" + light.lightID + "Color",
|
"#c3=c" + i + "Axis",
|
||||||
"#c2=c" + light.lightID + "Radius",
|
"#v0=vPosition",
|
||||||
"#c3=c" + light.lightID + "Axis",
|
// Calculate vector from the point to light
|
||||||
"#v0=vPosition",
|
"sub t0, c0, v0",// L = pos - lightPos
|
||||||
// Calculate vector from the point to light
|
"dp3 t0.w, t0, t0",// lenSqr
|
||||||
"sub t0, c0, v0",// L = pos - lightPos
|
"nrm t0.xyz,t0.xyz",// L = normalize(L)
|
||||||
"dp3 t0.w, t0, t0",// lenSqr
|
// Calculate half-way vector
|
||||||
"nrm t0.xyz,t0.xyz",// L = normalize(L)
|
"add t2.xyz, i1.xyz, t0.xyz",
|
||||||
// Calculate half-way vector
|
"nrm t2.xyz, t2.xyz",
|
||||||
"add t2.xyz, i1.xyz, t0.xyz",
|
//Calculate a flare
|
||||||
"nrm t2.xyz, t2.xyz",
|
"dp3 t2.x, t2.xyz, i0.xyz",
|
||||||
//Calculate a flare
|
"pow t2.x, t2.x, o1.w",
|
||||||
"dp3 t2.x, t2.xyz, i0.xyz",
|
"dp3 t1.x, t0.xyz, c3.xyz", //axisDirDot
|
||||||
"pow t2.x, t2.x, o1.w",
|
"dp3 t0.x, t0, i0.xyz",// dot = dot(normal, L)
|
||||||
"dp3 t1.x, t0.xyz, c3.xyz", //axisDirDot
|
"sqt t0.w, t0.w",// len = sqt(lensqr)
|
||||||
"dp3 t0.x, t0, i0.xyz",// dot = dot(normal, L)
|
"sub t0.w, t0.w, c2.y",// len = len - atenuationBegin
|
||||||
"sqt t0.w, t0.w",// len = sqt(lensqr)
|
"div t0.y, t0.w, c2.x",// att = len/radius
|
||||||
"sub t0.w, t0.w, c2.y",// len = len - atenuationBegin
|
"sub t0.w, c0.w, t0.y",// att = 1 - len/radius
|
||||||
"div t0.y, t0.w, c2.x",// att = len/radius
|
"sub t0.y, t1.x, c2.w",
|
||||||
"sub t0.w, c0.w, t0.y",// att = 1 - len/radius
|
"div t0.y, t0.y, c2.z",
|
||||||
"sub t0.y, t1.x, c2.w",
|
"sat t0.xyw,t0.xyw",// t = sat(t)
|
||||||
"div t0.y, t0.y, c2.z",
|
"mul t1.xyz,c1.xyz,t0.yyy",// t = color*t
|
||||||
"sat t0.xyw,t0.xyw",// t = sat(t)
|
"mul t1.xyz,t1.xyz,t0.www",//
|
||||||
"mul t1.xyz,c1.xyz,t0.yyy",// t = color*t
|
"mul t2.xyz, t2.x, t1.xyz",
|
||||||
"mul t1.xyz,t1.xyz,t0.www",//
|
"add o1.xyz, o1.xyz, t2.xyz",
|
||||||
"mul t2.xyz, t2.x, t1.xyz",
|
"mul t1.xyz, t1.xyz, t0.xxx",
|
||||||
"add o1.xyz, o1.xyz, t2.xyz",
|
|
||||||
"mul t1.xyz, t1.xyz, t0.xxx",
|
|
||||||
|
|
||||||
"add o0.xyz, o0.xyz, t1.xyz"
|
"add o0.xyz, o0.xyz, t1.xyz"
|
||||||
]);
|
]);
|
||||||
lightFragmentProcedure.name += "Spot";
|
lightFragmentProcedure.name += "Spot";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fragmentLinker.addProcedure(lightFragmentProcedure);
|
fragmentLinker.addProcedure(lightFragmentProcedure);
|
||||||
fragmentLinker.setInputParams(lightFragmentProcedure, "tNormal", "tViewVector");
|
fragmentLinker.setInputParams(lightFragmentProcedure, "tNormal", "tViewVector");
|
||||||
@@ -757,10 +749,9 @@ package alternativa.engine3d.materials {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
fragmentLinker.varyings = vertexLinker.varyings;
|
fragmentLinker.varyings = vertexLinker.varyings;
|
||||||
program = new StandardMaterialProgram(vertexLinker, fragmentLinker);
|
program = new StandardMaterialProgram(vertexLinker, fragmentLinker, (shadowedLight != null) ? 1 : lightsLength);
|
||||||
program.upload(camera.context3D);
|
|
||||||
|
|
||||||
// program.key = key;
|
program.upload(camera.context3D);
|
||||||
programs[key] = program;
|
programs[key] = program;
|
||||||
}
|
}
|
||||||
return program;
|
return program;
|
||||||
@@ -817,8 +808,8 @@ package alternativa.engine3d.materials {
|
|||||||
transform = light.lightToObjectTransform;
|
transform = light.lightToObjectTransform;
|
||||||
len = Math.sqrt(transform.c*transform.c + transform.g*transform.g + transform.k*transform.k);
|
len = Math.sqrt(transform.c*transform.c + transform.g*transform.g + transform.k*transform.k);
|
||||||
|
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Direction"), -transform.c/len, -transform.g/len, -transform.k/len, 1);
|
drawUnit.setFragmentConstantsFromNumbers(program.cPosition[i], -transform.c/len, -transform.g/len, -transform.k/len, 1);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Color"), light.red, light.green, light.blue);
|
drawUnit.setFragmentConstantsFromNumbers(program.cColor[i], light.red, light.green, light.blue);
|
||||||
} else if (light is OmniLight) {
|
} else if (light is OmniLight) {
|
||||||
omni = light as OmniLight;
|
omni = light as OmniLight;
|
||||||
transform = light.lightToObjectTransform;
|
transform = light.lightToObjectTransform;
|
||||||
@@ -827,9 +818,9 @@ package alternativa.engine3d.materials {
|
|||||||
rScale += Math.sqrt(transform.c*transform.c + transform.g*transform.g + transform.k*transform.k);
|
rScale += Math.sqrt(transform.c*transform.c + transform.g*transform.g + transform.k*transform.k);
|
||||||
rScale /= 3;
|
rScale /= 3;
|
||||||
|
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Position"), transform.d, transform.h, transform.l);
|
drawUnit.setFragmentConstantsFromNumbers(program.cPosition[i], transform.d, transform.h, transform.l);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Radius"), 1, omni.attenuationEnd*rScale - omni.attenuationBegin*rScale, omni.attenuationBegin*rScale);
|
drawUnit.setFragmentConstantsFromNumbers(program.cRadius[i], 1, omni.attenuationEnd*rScale - omni.attenuationBegin*rScale, omni.attenuationBegin*rScale);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Color"), light.red, light.green, light.blue);
|
drawUnit.setFragmentConstantsFromNumbers(program.cColor[i], light.red, light.green, light.blue);
|
||||||
} else if (light is SpotLight) {
|
} else if (light is SpotLight) {
|
||||||
spot = light as SpotLight;
|
spot = light as SpotLight;
|
||||||
transform = light.lightToObjectTransform;
|
transform = light.lightToObjectTransform;
|
||||||
@@ -840,10 +831,10 @@ package alternativa.engine3d.materials {
|
|||||||
falloff = Math.cos(spot.falloff*0.5);
|
falloff = Math.cos(spot.falloff*0.5);
|
||||||
hotspot = Math.cos(spot.hotspot*0.5);
|
hotspot = Math.cos(spot.hotspot*0.5);
|
||||||
|
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Position"), transform.d, transform.h, transform.l);
|
drawUnit.setFragmentConstantsFromNumbers(program.cPosition[i], transform.d, transform.h, transform.l);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Axis"), -transform.c/len, -transform.g/len, -transform.k/len);
|
drawUnit.setFragmentConstantsFromNumbers(program.cAxis[i], -transform.c/len, -transform.g/len, -transform.k/len);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Radius"), spot.attenuationEnd*rScale - spot.attenuationBegin*rScale, spot.attenuationBegin*rScale, hotspot == falloff ? 0.000001 : hotspot - falloff, falloff);
|
drawUnit.setFragmentConstantsFromNumbers(program.cRadius[i], spot.attenuationEnd*rScale - spot.attenuationBegin*rScale, spot.attenuationBegin*rScale, hotspot == falloff ? 0.000001 : hotspot - falloff, falloff);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Color"), light.red, light.green, light.blue);
|
drawUnit.setFragmentConstantsFromNumbers(program.cColor[i], light.red, light.green, light.blue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -853,8 +844,8 @@ package alternativa.engine3d.materials {
|
|||||||
if (light is DirectionalLight) {
|
if (light is DirectionalLight) {
|
||||||
transform = light.lightToObjectTransform;
|
transform = light.lightToObjectTransform;
|
||||||
len = Math.sqrt(transform.c*transform.c + transform.g*transform.g + transform.k*transform.k);
|
len = Math.sqrt(transform.c*transform.c + transform.g*transform.g + transform.k*transform.k);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Direction"), -transform.c/len, -transform.g/len, -transform.k/len, 1);
|
drawUnit.setFragmentConstantsFromNumbers(program.cPosition[0], -transform.c/len, -transform.g/len, -transform.k/len, 1);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Color"), light.red, light.green, light.blue);
|
drawUnit.setFragmentConstantsFromNumbers(program.cColor[0], light.red, light.green, light.blue);
|
||||||
} else if (light is OmniLight) {
|
} else if (light is OmniLight) {
|
||||||
omni = light as OmniLight;
|
omni = light as OmniLight;
|
||||||
transform = light.lightToObjectTransform;
|
transform = light.lightToObjectTransform;
|
||||||
@@ -862,9 +853,9 @@ package alternativa.engine3d.materials {
|
|||||||
rScale += Math.sqrt(transform.b*transform.b + transform.f*transform.f + transform.j*transform.j);
|
rScale += Math.sqrt(transform.b*transform.b + transform.f*transform.f + transform.j*transform.j);
|
||||||
rScale += Math.sqrt(transform.c*transform.c + transform.g*transform.g + transform.k*transform.k);
|
rScale += Math.sqrt(transform.c*transform.c + transform.g*transform.g + transform.k*transform.k);
|
||||||
rScale /= 3;
|
rScale /= 3;
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Position"), transform.d, transform.h, transform.l);
|
drawUnit.setFragmentConstantsFromNumbers(program.cPosition[0], transform.d, transform.h, transform.l);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Radius"), 1, omni.attenuationEnd*rScale - omni.attenuationBegin*rScale, omni.attenuationBegin*rScale);
|
drawUnit.setFragmentConstantsFromNumbers(program.cRadius[0], 1, omni.attenuationEnd*rScale - omni.attenuationBegin*rScale, omni.attenuationBegin*rScale);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Color"), light.red, light.green, light.blue);
|
drawUnit.setFragmentConstantsFromNumbers(program.cColor[0], light.red, light.green, light.blue);
|
||||||
} else if (light is SpotLight) {
|
} else if (light is SpotLight) {
|
||||||
spot = light as SpotLight;
|
spot = light as SpotLight;
|
||||||
transform = light.lightToObjectTransform;
|
transform = light.lightToObjectTransform;
|
||||||
@@ -875,10 +866,10 @@ package alternativa.engine3d.materials {
|
|||||||
falloff = Math.cos(spot.falloff*0.5);
|
falloff = Math.cos(spot.falloff*0.5);
|
||||||
hotspot = Math.cos(spot.hotspot*0.5);
|
hotspot = Math.cos(spot.hotspot*0.5);
|
||||||
|
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Position"), transform.d, transform.h, transform.l);
|
drawUnit.setFragmentConstantsFromNumbers(program.cPosition[0], transform.d, transform.h, transform.l);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Axis"), -transform.c/len, -transform.g/len, -transform.k/len);
|
drawUnit.setFragmentConstantsFromNumbers(program.cAxis[0], -transform.c/len, -transform.g/len, -transform.k/len);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Radius"), spot.attenuationEnd*rScale - spot.attenuationBegin*rScale, spot.attenuationBegin*rScale, hotspot == falloff ? 0.000001 : hotspot - falloff, falloff);
|
drawUnit.setFragmentConstantsFromNumbers(program.cRadius[0], spot.attenuationEnd*rScale - spot.attenuationBegin*rScale, spot.attenuationBegin*rScale, hotspot == falloff ? 0.000001 : hotspot - falloff, falloff);
|
||||||
drawUnit.setFragmentConstantsFromNumbers(program.fragmentShader.getVariableIndex("c" + light.lightID + "Color"), light.red, light.green, light.blue);
|
drawUnit.setFragmentConstantsFromNumbers(program.cColor[0], light.red, light.green, light.blue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1014,16 +1005,16 @@ package alternativa.engine3d.materials {
|
|||||||
cachedContext3D = camera.context3D;
|
cachedContext3D = camera.context3D;
|
||||||
programsCache = caches[cachedContext3D];
|
programsCache = caches[cachedContext3D];
|
||||||
if (programsCache == null) {
|
if (programsCache == null) {
|
||||||
programsCache = new Array();
|
programsCache = new Dictionary(true);
|
||||||
caches[cachedContext3D] = programsCache;
|
caches[cachedContext3D] = programsCache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// var optionsPrograms:Dictionary = programsCache[object.transformProcedure];
|
var optionsPrograms:Array = programsCache[object.transformProcedure];
|
||||||
// if (optionsPrograms == null) {
|
if (optionsPrograms == null) {
|
||||||
// optionsPrograms = new Dictionary(false);
|
optionsPrograms = new Array();
|
||||||
// programsCache[object.transformProcedure] = optionsPrograms;
|
programsCache[object.transformProcedure] = optionsPrograms;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Form groups of lights
|
// Form groups of lights
|
||||||
var groupsCount:int = 0;
|
var groupsCount:int = 0;
|
||||||
@@ -1064,11 +1055,11 @@ package alternativa.engine3d.materials {
|
|||||||
if (alphaThreshold > 0) {
|
if (alphaThreshold > 0) {
|
||||||
// Alpha test
|
// Alpha test
|
||||||
// use opacityMap if it is presented
|
// 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);
|
addDrawUnits(program, camera, surface, geometry, opacityMap, null, 0, true, null, true, false, objectRenderPriority);
|
||||||
} else {
|
} else {
|
||||||
// do not use opacityMap at all
|
// 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);
|
addDrawUnits(program, camera, surface, geometry, null, null, 0, true, null, true, false, objectRenderPriority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1077,11 +1068,11 @@ package alternativa.engine3d.materials {
|
|||||||
// use opacityMap if it is presented
|
// use opacityMap if it is presented
|
||||||
if (alphaThreshold <= alpha && !opaquePass) {
|
if (alphaThreshold <= alpha && !opaquePass) {
|
||||||
// Alpha threshold
|
// 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);
|
addDrawUnits(program, camera, surface, geometry, opacityMap, null, 0, true, null, false, true, objectRenderPriority);
|
||||||
} else {
|
} else {
|
||||||
// There is no Alpha threshold or check z-buffer by previous pass
|
// 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);
|
addDrawUnits(program, camera, surface, geometry, opacityMap, null, 0, true, null, false, true, objectRenderPriority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1116,11 +1107,11 @@ package alternativa.engine3d.materials {
|
|||||||
if (alphaThreshold > 0) {
|
if (alphaThreshold > 0) {
|
||||||
// Alpha test
|
// Alpha test
|
||||||
// use opacityMap if it is presented
|
// 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);
|
addDrawUnits(program, camera, surface, geometry, opacityMap, lightGroup, lightGroupLength, isFirstGroup, null, true, false, objectRenderPriority);
|
||||||
} else {
|
} else {
|
||||||
// do not use opacityMap at all
|
// 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);
|
addDrawUnits(program, camera, surface, geometry, null, lightGroup, lightGroupLength, isFirstGroup, null, true, false, objectRenderPriority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1129,11 +1120,11 @@ package alternativa.engine3d.materials {
|
|||||||
// use opacityMap if it is presented
|
// use opacityMap if it is presented
|
||||||
if (alphaThreshold <= alpha && !opaquePass) {
|
if (alphaThreshold <= alpha && !opaquePass) {
|
||||||
// Alpha threshold
|
// 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);
|
addDrawUnits(program, camera, surface, geometry, opacityMap, lightGroup, lightGroupLength, isFirstGroup, null, false, true, objectRenderPriority);
|
||||||
} else {
|
} else {
|
||||||
// There is no Alpha threshold or check z-buffer by previous pass
|
// 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);
|
addDrawUnits(program, camera, surface, geometry, opacityMap, lightGroup, lightGroupLength, isFirstGroup, null, false, true, objectRenderPriority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1141,7 +1132,7 @@ package alternativa.engine3d.materials {
|
|||||||
lightGroup.length = 0;
|
lightGroup.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shadowGroupLength > 0){
|
if (shadowGroupLength > 0) {
|
||||||
// Group of ligths with shadow
|
// Group of ligths with shadow
|
||||||
// For each light we will create new drawUnit
|
// For each light we will create new drawUnit
|
||||||
for (j = 0; j < shadowGroupLength; j++) {
|
for (j = 0; j < shadowGroupLength; j++) {
|
||||||
@@ -1184,11 +1175,11 @@ package alternativa.engine3d.materials {
|
|||||||
if (alphaThreshold > 0) {
|
if (alphaThreshold > 0) {
|
||||||
// Alpha test
|
// Alpha test
|
||||||
// use opacityMap if it is presented
|
// 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);
|
addDrawUnits(program, camera, surface, geometry, opacityMap, null, 0, isFirstGroup, light, true, false, objectRenderPriority);
|
||||||
} else {
|
} else {
|
||||||
// do not use opacityMap at all
|
// 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);
|
addDrawUnits(program, camera, surface, geometry, null, null, 0, isFirstGroup, light, true, false, objectRenderPriority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1197,11 +1188,11 @@ package alternativa.engine3d.materials {
|
|||||||
// use opacityMap if it is presented
|
// use opacityMap if it is presented
|
||||||
if (alphaThreshold <= alpha && !opaquePass) {
|
if (alphaThreshold <= alpha && !opaquePass) {
|
||||||
// Alpha threshold
|
// 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);
|
addDrawUnits(program, camera, surface, geometry, opacityMap, null, 0, isFirstGroup, light, false, true, objectRenderPriority);
|
||||||
} else {
|
} else {
|
||||||
// There is no Alpha threshold or check z-buffer by previous pass
|
// 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);
|
addDrawUnits(program, camera, surface, geometry, opacityMap, null, 0, isFirstGroup, light, false, true, objectRenderPriority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1262,8 +1253,18 @@ class StandardMaterialProgram extends ShaderProgram {
|
|||||||
public var sSpecular:int = -1;
|
public var sSpecular:int = -1;
|
||||||
public var sLightMap:int = -1;
|
public var sLightMap:int = -1;
|
||||||
|
|
||||||
public function StandardMaterialProgram(vertex:Linker, fragment:Linker) {
|
public var cPosition:Vector.<int>;
|
||||||
|
public var cRadius:Vector.<int>;
|
||||||
|
public var cAxis:Vector.<int>;
|
||||||
|
public var cColor:Vector.<int>;
|
||||||
|
|
||||||
|
public function StandardMaterialProgram(vertex:Linker, fragment:Linker, numLigths:int) {
|
||||||
super(vertex, fragment);
|
super(vertex, fragment);
|
||||||
|
|
||||||
|
cPosition = new Vector.<int>(numLigths);
|
||||||
|
cRadius = new Vector.<int>(numLigths);
|
||||||
|
cAxis = new Vector.<int>(numLigths);
|
||||||
|
cColor = new Vector.<int>(numLigths);
|
||||||
}
|
}
|
||||||
|
|
||||||
override public function upload(context3D:Context3D):void {
|
override public function upload(context3D:Context3D):void {
|
||||||
@@ -1286,6 +1287,14 @@ class StandardMaterialProgram extends ShaderProgram {
|
|||||||
sGlossiness = fragmentShader.findVariable("sGlossiness");
|
sGlossiness = fragmentShader.findVariable("sGlossiness");
|
||||||
sSpecular = fragmentShader.findVariable("sSpecular");
|
sSpecular = fragmentShader.findVariable("sSpecular");
|
||||||
sLightMap = fragmentShader.findVariable("sLightMap");
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user