Shadow Methods for away3d 4x

To create authentic images, shapes, lights, and shadows from a computer, these three elements are essential. Here is an introduction to the shadow solutions provided in away3d and the usage of each as a memo.
To use shadows, you first need to know the following:
1:away3d shadows are added through Material's shadowMethod property;
2: To add shadows, you must provide a light source in the scene. There are two types of light in away3d - PointLight and DirectionalLight. Only DirectionalLight can produce shadows;
3: Although multiple light sources can work together in a scene, when PointLight and DirectionalLight are mixed, the resulting shadows may appear abnormal.
4: Light sources can illuminate scene objects even if they are not added to the scene, but they must be added to the scene to produce the correct shading effect.
5: Shadow-related properties, generation: castsShadows:Boolean determines whether an object shades or not; Accept: shadowMethod: shadowMapper that determines whether an object accepts a light source with a shadow attached to it: DirectionalShadowMapper by default;
6: Shadow map is not affected by transparency of material; Shadows still occur even when the object is completely transparent;
The various shadows are explained next:
HardShadowMapMethod: Used to create projected shadow maps with clear boundaries; This shadow does not contain a filtering algorithm, so the performance is the best; Usually used when making game items with high performance requirements;
Dithered ShadowMapMethod: Create soft shadows along the edges by random sampling; This shading can set the ambiguity of the edge through the range parameter. Shadow boundaries will be granulated when the range is large. The advantage of this shadow calculation method is that the edges are controllable.
FilteredShadowMapMethod: Calculates clear shadows using a two-line interpolation algorithm; The boundary of this shadow is softer than that of HardShadowMapMethod; The softness of shadows can also be improved by setting a higher anti-aliasing value.
NearShadowMapMethod: This shading method fades shadows by calculating the camera distance; This shadow is used to produce a uniform shadow fading effect. Relatively the most realistic shadow simulation method; Note that to use this method, it is not the DirectionalLight instance but the SimpleShadowMapMethodBase instance that needs to be passed to the construction method; The shadowMapper property that also requires DirectionalLight is an instance of NearDirectionalShadowMapper;
SoftShadowMapMethod: This shadow calculation method will result in a softer shadow boundary than the fully granular shadow boundary of the Dithered ShadowMapMethod. This method provides the effect of changing shadows with two parameters. Sampling (second parameter): The larger the range 1-32, the more accurate and slower it is; Range (third parameter): The larger the value, the larger the virtual range of shadow; Real shadowing can be achieved with NearShadowMapMethod and properly set parameters at the expense of, of course, the slowest speed.
TripleFilteredShadowMapMethod: This method uses a triple filtering algorithm to calculate shadow maps; The effect is better than FilteredShadowMapMethod; SoftShadowMapMethod and FilteredShadowMapMethod can completely replace it and are officially not recommended. The advantage of this method is that it is easy to use and, like the FilteredShadowMapMethod, does not require a direct effect of parameter settings.
Here's how many shadow s will consume performance, so you should have a good idea when using them and choose the best one:
HardShadowMapMethod<Dithered ShadowMapMethod<Filtered ShadowMapMethod<TripleFiltered ShadowMapMethod<SoftShadowMapMethod(rough test results, please correct if any errors)
NearShadowMapMethod is not there because NearShadowMapMethod needs to work with other methods;

The following record shadow test code scripts are easy to test:
The test environment provides an observational camera controller with a straight-line light, a floor and three boxes with colorMaterial and TextureMaterial, respectively.

import away3d.cameras.lenses.OrthographicOffCenterLens;
import away3d.cameras.Camera3D;
import away3d.materials.ColorMaterial;
import away3d.primitives.CubeGeometry;
import away3d.primitives.PlaneGeometry;
import away3d.entities.Mesh;
import away3d.containers.View3D;
import away3d.lights.PointLight;
import away3d.materials.lightpickers.StaticLightPicker;
import away3d.materials.methods.HardShadowMapMethod;
import away3d.materials.methods.DitheredShadowMapMethod;
import away3d.materials.methods.FilteredShadowMapMethod;
import away3d.materials.methods.NearShadowMapMethod;
import away3d.materials.methods.SoftShadowMapMethod;
import away3d.materials.methods.TripleFilteredShadowMapMethod;
import away3d.materials.TextureMaterial;
import away3d.textures.BitmapTexture;
import away3d.controllers.HoverController;
import away3d.lights.DirectionalLight;
import away3d.lights.shadowmaps.NearDirectionalShadowMapper;//Processing Shadow Mapper DirectionalLight contains DirectionalShadowMapper by default 

var v3d:View3D=new View3D();
var pln:Mesh=new Mesh(new PlaneGeometry(10000,10000),new ColorMaterial(0x333333));
var box:Mesh=new Mesh(new CubeGeometry(200,200,200),new ColorMaterial(0xFFcc00));
var box2:Mesh=new Mesh(new CubeGeometry(200,400,200),new ColorMaterial(0x99cc00));
var box3:Mesh=new Mesh(new CubeGeometry(300,300,300),new TextureMaterial(new BitmapTexture(new BTM())));
var dlight:DirectionalLight=new DirectionalLight(0.1,-1,0.2);//FilteredShadowMapMethod
v3d.scene.addChild(dlight);//Lights can illuminate objects without adding them to the scene, however, they cannot shade objects correctly without adding them
trace(v3d.antiAlias);//Default is 0
v3d.antiAlias=32;//Invalid in model anti-aliasing debugging environment
//dlight.shadowMapper=new NearDirectionalShadowMapper();// Parameter 0-1 Default 0.5 (NearShadowMapMethod requires the light to have a matching EarDirectionalShadowMaper)

var plight:PointLight=new PointLight();
var lp:Array=[dlight];//plight
var spk:StaticLightPicker=new StaticLightPicker(lp);
var HC:HoverController=new HoverController(,box);
//ColorMaterial(pln.material).shadowMethod=new FilteredShadowMapMethod(dlight);HardShadowMapMethod
//var shadowMethod:DitheredShadowMapMethod=new DitheredShadowMapMethod(dlight);
//Trace (shadowMethod.range);// The Dithered ShadowMapMethod creates shadows by sampling, and the shadowed boundaries are granular when the boundaries are large
//var shadowMethod:HardShadowMapMethod=new HardShadowMapMethod(dlight);// HardMapShadowMethod is used to create projected shadows with clear boundaries (which perform best)
//var shadowMethod:FilteredShadowMapMethod=new FilteredShadowMapMethod(dlight);//FilteredShadowMapMethod calculates soft shadows (softer than the HardMapShadowMethod boundary) using a two-line interpolation algorithm. Setting a higher anti-aliasing value also appears to improve the softness of shadows.
//Var shadowMethod: NearShadowMapMethod=new NearShadowMapMethod (new Filtered ShadowMapMethod (dlight);// Limiting the display of shadows based on the distance between the camera and the projection produces soft penumbral outlines, which require adding a corresponding NearDirectionalShadowMapper to the light (the default is DirectionalShadowMapper)
//var shadowMethod:SoftShadowMapMethod=new SoftShadowMapMethod(dlight,32,100);// Projection effect with smooth edges obtained from random sample distribution The second parameter is the number of samples The third parameter is the sampling range (min 1 Max 32) The larger the sample size, the more accurate it is and the slower it is. The larger the range, the more scattered the shadows are
//Var shadowMethod:TripleFilteredShadowMapMethod=new TripleFilteredShadowMapMethod(dlight);// TripleFiltered ShadowMapMethod (Triple Filtered ShadowMap Map) is used to produce soft edge shadows probably because the effect is similar to Filtered ShadowMapMethod so it is not recommended to use it, but in practice it is softer than the Filtered Method boundary
trace(shadowMethod.epsilon);//This value is used to adjust the display of shadows, increase if the shadows have overlapping patches, and decrease if the shadows have sections, defaulting to 0.02
/*ColorMaterial(box.material).shadowMethod=;FilteredShadowMapMethod//new NearShadowMapMethod(new DitheredShadowMapMethod(dlight)*/

var nx:Number;
var ny:Number;
function v3d_d(e:MouseEvent){
function v3d_m(e:MouseEvent){
var cx:Number=v3d.mouseX;
var cy:Number=v3d.mouseY;
function v3d_u(e:MouseEvent){
function run(e:Event){

Keywords: Game Development 3d

Added by ploiesti on Sat, 05 Mar 2022 19:13:58 +0200