mirror of
https://github.com/MapMakersAndProgrammers/Alternativa3D.git
synced 2025-10-26 09:59:10 -07:00
Remove dup variable. Changed biasMultiplyer=0.97. Fixed few bug with culling.
This commit is contained in:
@@ -1084,6 +1084,7 @@ package alternativa.engine3d.materials {
|
|||||||
else{
|
else{
|
||||||
var lightLengthInGroup:int;
|
var lightLengthInGroup:int;
|
||||||
var isFirstGroup:Boolean = true;
|
var isFirstGroup:Boolean = true;
|
||||||
|
var j:int;
|
||||||
for (i = 0; i < groupsCount; i++) {
|
for (i = 0; i < groupsCount; i++) {
|
||||||
var lightGroup:Vector.<Light3D> = groups[i];
|
var lightGroup:Vector.<Light3D> = groups[i];
|
||||||
lightLengthInGroup = lightGroup.length;
|
lightLengthInGroup = lightGroup.length;
|
||||||
@@ -1095,7 +1096,7 @@ package alternativa.engine3d.materials {
|
|||||||
(_normalMapSpace.toString()) +
|
(_normalMapSpace.toString()) +
|
||||||
((glossinessMap != null) ? "G" : "g") +
|
((glossinessMap != null) ? "G" : "g") +
|
||||||
((specularMap != null) ? "S" : "s");
|
((specularMap != null) ? "S" : "s");
|
||||||
for (var j:int = 0; j < lightLengthInGroup; j++) {
|
for (j = 0; j < lightLengthInGroup; j++) {
|
||||||
light = lightGroup[j];
|
light = lightGroup[j];
|
||||||
materialKey += light.lightID;
|
materialKey += light.lightID;
|
||||||
}
|
}
|
||||||
@@ -1134,7 +1135,7 @@ package alternativa.engine3d.materials {
|
|||||||
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 (var j:int = 0; j < shadowGroupLength; j++) {
|
for (j = 0; j < shadowGroupLength; j++) {
|
||||||
|
|
||||||
light = shadowGroup[j];
|
light = shadowGroup[j];
|
||||||
// Form key
|
// Form key
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ package alternativa.engine3d.shadows {
|
|||||||
/**
|
/**
|
||||||
* Degree of correcting offset of shadow map space. It need for getting rid of self-shadowing artifacts.
|
* Degree of correcting offset of shadow map space. It need for getting rid of self-shadowing artifacts.
|
||||||
*/
|
*/
|
||||||
public var biasMultiplier:Number = 0.99;
|
public var biasMultiplier:Number = 0.97;
|
||||||
|
|
||||||
private static const DIFFERENCE_MULTIPLIER:Number = 32768;
|
private static const DIFFERENCE_MULTIPLIER:Number = 32768;
|
||||||
|
|
||||||
|
|||||||
@@ -42,12 +42,17 @@ package alternativa.engine3d.shadows {
|
|||||||
|
|
||||||
public class OmniLightShadow extends Shadow{
|
public class OmniLightShadow extends Shadow{
|
||||||
|
|
||||||
|
// TODO: calculate bias automaticaly
|
||||||
/**
|
/**
|
||||||
* Degree of correcting offset of shadow map space. It need for getting rid of self-shadowing artifacts.
|
* Degree of correcting offset of shadow map space. It need for getting rid of self-shadowing artifacts.
|
||||||
*/
|
*/
|
||||||
public var biasMultiplier:Number = 0.99;
|
public var biasMultiplier:Number = 0.97;
|
||||||
private static const DIFFERENCE_MULTIPLIER:Number = 32768;
|
private static const DIFFERENCE_MULTIPLIER:Number = 32768;
|
||||||
private static const DEBUG_TYPE:String = "Sphere"; // Box
|
private static const DEBUG_TYPE:String = "Sphere"; // Box
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
alternativa3d static var debugRadiusScale:Number = 0.5;
|
||||||
|
|
||||||
private var renderer:Renderer = new Renderer();
|
private var renderer:Renderer = new Renderer();
|
||||||
|
|
||||||
@@ -236,21 +241,19 @@ package alternativa.engine3d.shadows {
|
|||||||
_light.lightToObjectTransform.combine(caster.cameraToLocalTransform, _light.localToCameraTransform);
|
_light.lightToObjectTransform.combine(caster.cameraToLocalTransform, _light.localToCameraTransform);
|
||||||
caster.localToLightTransform.combine(_light.cameraToLocalTransform, caster.localToCameraTransform);
|
caster.localToLightTransform.combine(_light.cameraToLocalTransform, caster.localToCameraTransform);
|
||||||
|
|
||||||
// Pack camera culling
|
|
||||||
caster.culling <<= 16;
|
|
||||||
// collect actualCasters for light
|
// collect actualCasters for light
|
||||||
if (caster.boundBox == null || OmniLight(_light).checkBound(caster)){
|
if (caster.boundBox == null || OmniLight(_light).checkBound(caster)){
|
||||||
actualCasters[actualCastersCount] = caster;
|
actualCasters[actualCastersCount] = caster;
|
||||||
actualCastersCount++;
|
actualCastersCount++;
|
||||||
|
|
||||||
|
// Pack camera culling
|
||||||
|
caster.culling <<= 16;
|
||||||
if (caster.boundBox != null) {
|
if (caster.boundBox != null) {
|
||||||
// 1 - calculate planes in object space
|
// 1 - calculate planes in object space
|
||||||
calculatePlanes(caster.localToLightTransform);
|
calculatePlanes(caster.localToLightTransform);
|
||||||
// 2 - check object location cameras (sections)
|
// 2 - check object location cameras (sections)
|
||||||
caster.culling |= recognizeObjectCameras(caster.boundBox);
|
caster.culling |= recognizeObjectCameras(caster.boundBox);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
caster.culling |= 63;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update Skin Joints matrices
|
// update Skin Joints matrices
|
||||||
@@ -328,7 +331,7 @@ package alternativa.engine3d.shadows {
|
|||||||
if (debugObject == null) {
|
if (debugObject == null) {
|
||||||
debugObject = createDebugObject(debugMaterial, camera.context3D);
|
debugObject = createDebugObject(debugMaterial, camera.context3D);
|
||||||
}
|
}
|
||||||
debugObject.scaleX = debugObject.scaleY = debugObject.scaleZ = radius;
|
debugObject.scaleX = debugObject.scaleY = debugObject.scaleZ = debugRadiusScale;
|
||||||
debugObject.composeTransforms();
|
debugObject.composeTransforms();
|
||||||
|
|
||||||
// Формируем матрицу трансформации для debugObject
|
// Формируем матрицу трансформации для debugObject
|
||||||
@@ -341,6 +344,48 @@ package alternativa.engine3d.shadows {
|
|||||||
actualCasters.length = 0;
|
actualCasters.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function collectActualChildren(root:Object3D):void{
|
||||||
|
for (var child:Object3D = root.childrenList; child != null; child = child.next) {
|
||||||
|
if (child.visible){
|
||||||
|
// calculate transform matrices
|
||||||
|
_light.lightToObjectTransform.combine(child.cameraToLocalTransform, _light.localToCameraTransform);
|
||||||
|
child.localToLightTransform.combine(_light.cameraToLocalTransform, child.localToCameraTransform);
|
||||||
|
|
||||||
|
// collect actualCasters for light
|
||||||
|
if (child.boundBox == null || OmniLight(_light).checkBound(child)){
|
||||||
|
actualCasters[actualCastersCount] = child;
|
||||||
|
actualCastersCount++;
|
||||||
|
|
||||||
|
// Pack camera culling
|
||||||
|
child.culling <<= 16;
|
||||||
|
if (child.boundBox != null) {
|
||||||
|
// 1 - calculate planes in object space
|
||||||
|
calculatePlanes(child.localToLightTransform);
|
||||||
|
// 2 - check object location cameras (sections)
|
||||||
|
child.culling |= recognizeObjectCameras(child.boundBox);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update Skin Joints matrices
|
||||||
|
var skin:Skin = child as Skin;
|
||||||
|
if (skin != null) {
|
||||||
|
// Calculate joints matrices
|
||||||
|
for (var skinChild:Object3D = skin.childrenList; skinChild != null; skinChild = skinChild.next) {
|
||||||
|
if (skinChild.transformChanged) skinChild.composeTransforms();
|
||||||
|
// Write transformToSkin matrix to localToGlobalTransform property
|
||||||
|
skinChild.localToGlobalTransform.copy(skinChild.transform);
|
||||||
|
if (skinChild is Joint) {
|
||||||
|
Joint(skinChild).calculateTransform();
|
||||||
|
}
|
||||||
|
skin.calculateJointsTransforms(skinChild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (child.childrenList != null) collectActualChildren(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var sections:SectionPlane;
|
private var sections:SectionPlane;
|
||||||
|
|
||||||
private function calculatePlanes(transform:Transform3D):void {
|
private function calculatePlanes(transform:Transform3D):void {
|
||||||
@@ -497,50 +542,6 @@ package alternativa.engine3d.shadows {
|
|||||||
return culling;
|
return culling;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function collectActualChildren(root:Object3D):void{
|
|
||||||
for (var child:Object3D = root.childrenList; child != null; child = child.next) {
|
|
||||||
if (child.visible){
|
|
||||||
// calculate transform matrices
|
|
||||||
_light.lightToObjectTransform.combine(child.cameraToLocalTransform, _light.localToCameraTransform);
|
|
||||||
child.localToLightTransform.combine(_light.cameraToLocalTransform, child.localToCameraTransform);
|
|
||||||
|
|
||||||
// Pack camera culling
|
|
||||||
child.culling <<= 16;
|
|
||||||
// collect actualCasters for light
|
|
||||||
if (child.boundBox == null || OmniLight(_light).checkBound(child)){
|
|
||||||
actualCasters[actualCastersCount] = child;
|
|
||||||
actualCastersCount++;
|
|
||||||
|
|
||||||
if (child.boundBox != null) {
|
|
||||||
// 1 - calculate planes in object space
|
|
||||||
calculatePlanes(child.localToLightTransform);
|
|
||||||
// 2 - check object location cameras (sections)
|
|
||||||
child.culling |= recognizeObjectCameras(child.boundBox);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
child.culling |= 63;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update Skin Joints matrices
|
|
||||||
var skin:Skin = child as Skin;
|
|
||||||
if (skin != null) {
|
|
||||||
// Calculate joints matrices
|
|
||||||
for (var skinChild:Object3D = skin.childrenList; skinChild != null; skinChild = skinChild.next) {
|
|
||||||
if (skinChild.transformChanged) skinChild.composeTransforms();
|
|
||||||
// Write transformToSkin matrix to localToGlobalTransform property
|
|
||||||
skinChild.localToGlobalTransform.copy(skinChild.transform);
|
|
||||||
if (skinChild is Joint) {
|
|
||||||
Joint(skinChild).calculateTransform();
|
|
||||||
}
|
|
||||||
skin.calculateJointsTransforms(skinChild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (child.childrenList != null) collectActualChildren(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private function collectDraws(context:Context3D, caster:Object3D, edgeCamera:Camera3D):void{
|
private function collectDraws(context:Context3D, caster:Object3D, edgeCamera:Camera3D):void{
|
||||||
// если объект является мешем, собираем для него дроуколы
|
// если объект является мешем, собираем для него дроуколы
|
||||||
var mesh:Mesh = caster as Mesh;
|
var mesh:Mesh = caster as Mesh;
|
||||||
@@ -912,8 +913,8 @@ package alternativa.engine3d.shadows {
|
|||||||
this._mapSize = value;
|
this._mapSize = value;
|
||||||
if (value < 2) {
|
if (value < 2) {
|
||||||
throw new ArgumentError("Map size cannot be less than 2.");
|
throw new ArgumentError("Map size cannot be less than 2.");
|
||||||
} else if (value > 2048) {
|
} else if (value > 1024) {
|
||||||
throw new ArgumentError("Map size exceeds maximum value 2048.");
|
throw new ArgumentError("Map size exceeds maximum value 1024.");
|
||||||
}
|
}
|
||||||
if ((Math.log(value)/Math.LN2 % 1) != 0) {
|
if ((Math.log(value)/Math.LN2 % 1) != 0) {
|
||||||
throw new ArgumentError("Map size must be power of two.");
|
throw new ArgumentError("Map size must be power of two.");
|
||||||
|
|||||||
Reference in New Issue
Block a user