RenderWorld cleanup, Shadowmap cleanup + improvements

This commit is contained in:
dexyfex 2018-01-03 15:25:20 +11:00
parent 56f9378506
commit de582fee02
5 changed files with 157 additions and 314 deletions

View File

@ -1120,20 +1120,12 @@ namespace CodeWalker.GameFiles
public Quaternion MloRefOrientation { get; set; } public Quaternion MloRefOrientation { get; set; }
public MetaWrapper[] Extensions { get; set; } public MetaWrapper[] Extensions { get; set; }
public bool ChildrenRendered; //used when rendering ymap mode to reduce LOD flashing...
public int Index { get; set; } public int Index { get; set; }
public Vector3 CamRel; //used for rendering...
public float Distance; //used for rendering
public bool IsVisible; //used for rendering public bool IsVisible; //used for rendering
public bool Rendered; //used for rendering
public bool ChildRendered; //used for rendering
public bool ChildrenVisible; //used for rendering public bool ChildrenVisible; //used for rendering
public bool ChildrenLoading; //used for rendering public bool ChildrenRendered; //used when rendering ymap mode to reduce LOD flashing...
public float LargestChildLodDist; //used for rendering public YmapEntityDef Parent { get; set; } //for browsing convenience, also used/updated for rendering
public YmapEntityDef Parent { get; set; } //used for rendering public MetaHash ParentName { get; set; } //just for browsing convenience
public uint ParentGuid { get; set; } //used for rendering
public MetaHash ParentName { get; set; } //used for rendering
public YmapFile Ymap { get; set; } public YmapFile Ymap { get; set; }
@ -1398,7 +1390,6 @@ namespace CodeWalker.GameFiles
ChildList = new List<YmapEntityDef>(); ChildList = new List<YmapEntityDef>();
} }
c.Parent = this; c.Parent = this;
c.ParentGuid = CEntityDef.guid;
c.ParentName = CEntityDef.archetypeName; c.ParentName = CEntityDef.archetypeName;
ChildList.Add(c); ChildList.Add(c);

View File

@ -1376,34 +1376,31 @@ namespace CodeWalker.Rendering
foreach (var ae in spaceEnts) //used by active space entities (eg "bullets") foreach (var ae in spaceEnts) //used by active space entities (eg "bullets")
{ {
if (ae.EntityDef == null) continue; //nothing to render... if (ae.EntityDef == null) continue; //nothing to render...
RenderWorldCalcEntityVisibility(camera, ae.EntityDef); RenderWorldCalcEntityVisibility(ae.EntityDef);
renderworldentities.Add(ae.EntityDef); renderworldentities.Add(ae.EntityDef);
} }
} }
if (MapViewEnabled)
{
//find the max Z value for positioning camera in map view, to help shadows
//float minZ = float.MaxValue; //float minZ = float.MaxValue;
float maxZ = float.MinValue; float maxZ = float.MinValue;
float cvwidth = camera.OrthographicSize * camera.AspectRatio * 0.5f; float cvwidth = camera.OrthographicSize * camera.AspectRatio * 0.5f;
float cvheight = camera.OrthographicSize * 0.5f; float cvheight = camera.OrthographicSize * 0.5f;
float cvwmin = camera.Position.X - cvwidth; float cvwmin = camera.Position.X - cvwidth; //TODO:make all these vars global...
float cvwmax = camera.Position.X + cvwidth; float cvwmax = camera.Position.X + cvwidth;
float cvhmin = camera.Position.Y - cvheight; float cvhmin = camera.Position.Y - cvheight;
float cvhmax = camera.Position.Y + cvheight; float cvhmax = camera.Position.Y + cvheight;
foreach (var ymap in VisibleYmaps) for (int y = 0; y < VisibleYmaps.Count; y++)
{ {
var ymap = VisibleYmaps[y];
if (ymap.AllEntities != null) if (ymap.AllEntities != null)
{ {
for (int i = 0; i < ymap.AllEntities.Length; i++) for (int i = 0; i < ymap.AllEntities.Length; i++)
{ {
var ent = ymap.AllEntities[i]; var ent = ymap.AllEntities[i];
ent.LargestChildLodDist = 0;
ent.ChildrenLoading = false;
ent.Rendered = false;
ent.ChildRendered = false;
if (MapViewEnabled)
{
//find the max Z value for positioning camera in map view, to help shadows
if ((ent.Position.Z < 1000.0f) && (ent.BSRadius < 500.0f)) if ((ent.Position.Z < 1000.0f) && (ent.BSRadius < 500.0f))
{ {
float r = ent.BSRadius; float r = ent.BSRadius;
@ -1416,18 +1413,16 @@ namespace CodeWalker.Rendering
} }
} }
} }
}
if (MapViewEnabled)
{
//move the camera closer to the geometry, to help shadows in map view. //move the camera closer to the geometry, to help shadows in map view.
if (maxZ == float.MinValue) maxZ = 1000.0f; if (maxZ == float.MinValue) maxZ = 1000.0f;
camera.Position.Z = Math.Min(maxZ, 1000.0f); camera.Position.Z = Math.Min(maxZ, 1000.0f);
} }
foreach (var ymap in VisibleYmaps) for (int y = 0; y < VisibleYmaps.Count; y++)
{ {
var ymap = VisibleYmaps[y];
if (ymap.RootEntities != null) if (ymap.RootEntities != null)
{ {
YmapFile pymap; YmapFile pymap;
@ -1445,26 +1440,26 @@ namespace CodeWalker.Rendering
{ {
p = pymap.AllEntities[pind]; p = pymap.AllEntities[pind];
ent.Parent = p; ent.Parent = p;
ent.ParentGuid = p.CEntityDef.guid;
ent.ParentName = p.CEntityDef.archetypeName; ent.ParentName = p.CEntityDef.archetypeName;
} }
} }
else else
{ }//should only happen if parent ymap not loaded yet... { }//should only happen if parent ymap not loaded yet...
} }
RenderWorldRecurseCalcEntityVisibility(camera, ent); RenderWorldRecurseCalcEntityVisibility(ent);
} }
} }
} }
foreach (var ymap in VisibleYmaps) for (int y = 0; y < VisibleYmaps.Count; y++)
{ {
var ymap = VisibleYmaps[y];
if (ymap.RootEntities != null) if (ymap.RootEntities != null)
{ {
for (int i = 0; i < ymap.RootEntities.Length; i++) for (int i = 0; i < ymap.RootEntities.Length; i++)
{ {
var ent = ymap.RootEntities[i]; var ent = ymap.RootEntities[i];
RenderWorldRecurseAddEntities(ent, renderworldentities); RenderWorldRecurseAddEntities(ent);
} }
} }
} }
@ -1480,47 +1475,6 @@ namespace CodeWalker.Rendering
var ent = renderworldentities[i]; var ent = renderworldentities[i];
var arch = ent.Archetype; var arch = ent.Archetype;
var pent = ent.Parent; var pent = ent.Parent;
if (renderinteriors && ent.IsMlo) //render Mlo child entities...
{
if ((ent.MloInstance != null) && (ent.MloInstance.Entities != null))
{
for (int j = 0; j < ent.MloInstance.Entities.Length; j++)
{
var intent = ent.MloInstance.Entities[j];
var intarch = intent.Archetype;
if (intarch == null) continue; //missing archetype...
if (!RenderIsEntityFinalRender(intent)) continue; //proxy or something..
intent.CamRel = intent.Position - camera.Position;
intent.Distance = intent.CamRel.Length();
intent.IsVisible = true;
var bscent = intent.CamRel + intent.BSCenter;
float bsrad = intent.BSRadius;
if (!camera.ViewFrustum.ContainsSphereNoClipNoOpt(ref bscent, bsrad))
{
continue; //frustum cull interior ents
}
var intdrbl = gameFileCache.TryGetDrawable(intarch);
var intrndbl = TryGetRenderable(intarch, intdrbl);
if (intrndbl == null) continue; //no renderable
if (!(intrndbl.IsLoaded && (intrndbl.AllTexturesLoaded || !waitforchildrentoload))) continue; //not loaded yet
RenderableEntity intrent = new RenderableEntity();
intrent.Entity = intent;
intrent.Renderable = intrndbl;
renderworldrenderables.Add(intrent);
}
}
if (rendercollisionmeshes)
{
RenderInteriorCollisionMesh(ent);
}
}
ent.Rendered = true;
var drawable = gameFileCache.TryGetDrawable(arch); var drawable = gameFileCache.TryGetDrawable(arch);
Renderable rndbl = TryGetRenderable(arch, drawable); Renderable rndbl = TryGetRenderable(arch, drawable);
if ((rndbl != null) && rndbl.IsLoaded && (rndbl.AllTexturesLoaded || !waitforchildrentoload)) if ((rndbl != null) && rndbl.IsLoaded && (rndbl.AllTexturesLoaded || !waitforchildrentoload))
@ -1529,24 +1483,15 @@ namespace CodeWalker.Rendering
rent.Entity = ent; rent.Entity = ent;
rent.Renderable = rndbl; rent.Renderable = rndbl;
renderworldrenderables.Add(rent); renderworldrenderables.Add(rent);
if (pent != null)
{
pent.ChildRendered = true;
}
} }
else if (waitforchildrentoload) else if (waitforchildrentoload)
{ {
//todo: render parent if children loading....... //todo: render parent if children loading.......
} }
}
for (int i = 0; i < renderworldrenderables.Count; i++) if (ent.IsMlo && rendercollisionmeshes && renderinteriors)
{ {
var ent = renderworldrenderables[i].Entity; RenderInteriorCollisionMesh(ent);
if (ent.ChildRendered && !ent.ChildrenLoading)
{
ent.ChildrenRendered = true;
} }
} }
@ -1563,8 +1508,9 @@ namespace CodeWalker.Rendering
if (rendergrass) if (rendergrass)
{ {
foreach (var ymap in renderworldVisibleYmapDict.Values) for (int y = 0; y < VisibleYmaps.Count; y++)
{ {
var ymap = VisibleYmaps[y];
if (ymap.GrassInstanceBatches != null) if (ymap.GrassInstanceBatches != null)
{ {
RenderYmapGrass(ymap); RenderYmapGrass(ymap);
@ -1573,8 +1519,9 @@ namespace CodeWalker.Rendering
} }
if (renderdistlodlights && timecycle.IsNightTime) if (renderdistlodlights && timecycle.IsNightTime)
{ {
foreach (var ymap in renderworldVisibleYmapDict.Values) for (int y = 0; y < VisibleYmaps.Count; y++)
{ {
var ymap = VisibleYmaps[y];
if (ymap.DistantLODLights != null) if (ymap.DistantLODLights != null)
{ {
RenderYmapDistantLODLights(ymap); RenderYmapDistantLODLights(ymap);
@ -1592,39 +1539,33 @@ namespace CodeWalker.Rendering
return true; return true;
} }
private void RenderWorldCalcEntityVisibility(Camera cam, YmapEntityDef ent) private void RenderWorldCalcEntityVisibility(YmapEntityDef ent)
{ {
ent.CamRel = ent.Position - cam.Position; float dist = (ent.Position - camera.Position).Length();
ent.Distance = ent.CamRel.Length();
float distval = ent.Distance;
if (MapViewEnabled) if (MapViewEnabled)
{ {
distval = cam.OrthographicSize / MapViewDetail; dist = camera.OrthographicSize / MapViewDetail;
} }
var loddist = ent.CEntityDef.lodDist; var loddist = ent.CEntityDef.lodDist;
var cloddist = ent.CEntityDef.childLodDist; var cloddist = ent.CEntityDef.childLodDist;
var loddistmultdef = renderworldLodDistMult * 1.0f;
var loddistmultorph = renderworldDetailDistMult * 1.5f;
var loddistmultarch = renderworldLodDistMult * 1.0f;
if (loddist <= 0.0f)//usually -1 or -2 if (loddist <= 0.0f)//usually -1 or -2
{ {
if (ent.Archetype != null) if (ent.Archetype != null)
{ {
loddist = ent.Archetype.LodDist * loddistmultarch; loddist = ent.Archetype.LodDist * renderworldLodDistMult;
} }
} }
else if (ent.CEntityDef.lodLevel == Unk_1264241711.LODTYPES_DEPTH_ORPHANHD) else if (ent.CEntityDef.lodLevel == Unk_1264241711.LODTYPES_DEPTH_ORPHANHD)
{ {
loddist *= loddistmultorph; //orphan view dist adjustment... loddist *= renderworldDetailDistMult * 1.5f; //orphan view dist adjustment...
} }
else else
{ {
loddist *= loddistmultdef; loddist *= renderworldLodDistMult;
} }
@ -1632,31 +1573,19 @@ namespace CodeWalker.Rendering
{ {
if (ent.Archetype != null) if (ent.Archetype != null)
{ {
cloddist = ent.Archetype.LodDist * loddistmultarch; cloddist = ent.Archetype.LodDist * renderworldLodDistMult;
//cloddist = ent.Archetype.BSRadius * 50.0f;
} }
} }
else else
{ {
cloddist *= loddistmultdef; cloddist *= renderworldLodDistMult;
}
if (cloddist == 0)
{
//cloddist = loddist;//always try to show children, based on their loddist
} }
ent.IsVisible = (distval <= loddist); ent.IsVisible = (dist <= loddist);
ent.ChildrenVisible = (distval <= cloddist) && (ent.CEntityDef.numChildren > 0); ent.ChildrenVisible = (dist <= cloddist) && (ent.CEntityDef.numChildren > 0);
ent.ChildrenLoading = false;
if ((ent.Parent != null) && (ent.CEntityDef.lodLevel != Unk_1264241711.LODTYPES_DEPTH_ORPHANHD))
{
if (ent.Parent.CEntityDef.childLodDist == 0.0f)
{
ent.Parent.LargestChildLodDist = Math.Max(ent.Parent.LargestChildLodDist, loddist);
}
}
if (renderworldMaxLOD != Unk_1264241711.LODTYPES_DEPTH_ORPHANHD) if (renderworldMaxLOD != Unk_1264241711.LODTYPES_DEPTH_ORPHANHD)
{ {
@ -1671,15 +1600,10 @@ namespace CodeWalker.Rendering
ent.ChildrenVisible = false; ent.ChildrenVisible = false;
} }
} }
if (!ent.IsVisible)
{
ent.ChildrenRendered = false;
} }
} private void RenderWorldRecurseCalcEntityVisibility(YmapEntityDef ent)
private void RenderWorldRecurseCalcEntityVisibility(Camera cam, YmapEntityDef ent)
{ {
RenderWorldCalcEntityVisibility(cam, ent); RenderWorldCalcEntityVisibility(ent);
if (ent.ChildrenVisible) if (ent.ChildrenVisible)
{ {
if (ent.Children != null) if (ent.Children != null)
@ -1689,17 +1613,14 @@ namespace CodeWalker.Rendering
var child = ent.Children[i]; var child = ent.Children[i];
if (child.Ymap == ent.Ymap) if (child.Ymap == ent.Ymap)
{ {
RenderWorldRecurseCalcEntityVisibility(cam, child); RenderWorldRecurseCalcEntityVisibility(child);
} }
} }
} }
} }
} }
private void RenderWorldRecurseAddEntities(YmapEntityDef ent, List<YmapEntityDef> res) private void RenderWorldRecurseAddEntities(YmapEntityDef ent)
{ {
//bool useclod = false; //(ent.CEntityDef.childLodDist == 0.0f);
//bool hide = useclod ? (ent.AnyChildVisible /*&& !ent.AnyChildInvisible*/) : ent.ChildrenVisible;
//bool force = !useclod && (ent.Parent != null) && ent.Parent.ChildrenVisible && !hide;
bool hide = ent.ChildrenVisible; bool hide = ent.ChildrenVisible;
bool force = (ent.Parent != null) && ent.Parent.ChildrenVisible && !hide; bool force = (ent.Parent != null) && ent.Parent.ChildrenVisible && !hide;
if (force || (ent.IsVisible && !hide)) if (force || (ent.IsVisible && !hide))
@ -1708,7 +1629,7 @@ namespace CodeWalker.Rendering
{ {
if (!RenderIsEntityFinalRender(ent)) return; if (!RenderIsEntityFinalRender(ent)) return;
var bscent = ent.CamRel + ent.BSCenter; var bscent = ent.Position + ent.BSCenter - camera.Position;
float bsrad = ent.BSRadius; float bsrad = ent.BSRadius;
if (!camera.ViewFrustum.ContainsSphereNoClipNoOpt(ref bscent, bsrad)) if (!camera.ViewFrustum.ContainsSphereNoClipNoOpt(ref bscent, bsrad))
{ {
@ -1716,10 +1637,34 @@ namespace CodeWalker.Rendering
} }
res.Add(ent); renderworldentities.Add(ent);
if (renderinteriors && ent.IsMlo) //render Mlo child entities...
{
if ((ent.MloInstance != null) && (ent.MloInstance.Entities != null))
{
for (int j = 0; j < ent.MloInstance.Entities.Length; j++)
{
var intent = ent.MloInstance.Entities[j];
if (intent.Archetype == null) continue; //missing archetype...
if (!RenderIsEntityFinalRender(intent)) continue; //proxy or something..
intent.IsVisible = true;
var iebscent = intent.Position + intent.BSCenter - camera.Position;
float iebsrad = intent.BSRadius;
if (!camera.ViewFrustum.ContainsSphereNoClipNoOpt(ref iebscent, iebsrad))
{
continue; //frustum cull interior ents
}
renderworldentities.Add(intent);
}
}
}
} }
else
{ }
} }
if (ent.IsVisible && ent.ChildrenVisible && (ent.Children != null)) if (ent.IsVisible && ent.ChildrenVisible && (ent.Children != null))
{ {
@ -1728,13 +1673,17 @@ namespace CodeWalker.Rendering
var child = ent.Children[i]; var child = ent.Children[i];
if (child.Ymap == ent.Ymap) if (child.Ymap == ent.Ymap)
{ {
RenderWorldRecurseAddEntities(ent.Children[i], res); RenderWorldRecurseAddEntities(ent.Children[i]);
} }
} }
} }
} }
private bool RenderIsEntityFinalRender(YmapEntityDef ent) private bool RenderIsEntityFinalRender(YmapEntityDef ent)
{ {
var arch = ent.Archetype; var arch = ent.Archetype;
@ -1850,7 +1799,6 @@ namespace CodeWalker.Rendering
bool timed = (arch.Type == MetaName.CTimeArchetypeDef); bool timed = (arch.Type == MetaName.CTimeArchetypeDef);
if (!timed || (rendertimedents && (rendertimedentsalways || arch.IsActive(timeofday)))) if (!timed || (rendertimedents && (rendertimedentsalways || arch.IsActive(timeofday))))
{ {
ent.CamRel = ent.Position - camera.Position;
RenderArchetype(arch, ent); RenderArchetype(arch, ent);
} }
} }
@ -1885,8 +1833,8 @@ namespace CodeWalker.Rendering
if (!timed || (rendertimedents && (rendertimedentsalways || arch.IsActive(timeofday)))) if (!timed || (rendertimedents && (rendertimedentsalways || arch.IsActive(timeofday))))
{ {
bool usechild = false; bool usechild = false;
entity.CamRel = entity.Position - camera.Position; Vector3 camrel = entity.Position - camera.Position;
float dist = (entity.CamRel + entity.BSCenter).Length(); float dist = (camrel + entity.BSCenter).Length();
float rad = arch.BSRadius; float rad = arch.BSRadius;
float loddist = entity.CEntityDef.lodDist; float loddist = entity.CEntityDef.lodDist;
if (loddist < 1.0f) if (loddist < 1.0f)
@ -1925,8 +1873,6 @@ namespace CodeWalker.Rendering
if (!usechild && !entity.ChildrenRendered) if (!usechild && !entity.ChildrenRendered)
{ {
if (renderinteriors && entity.IsMlo) //render Mlo child entities... if (renderinteriors && entity.IsMlo) //render Mlo child entities...
{ {
if ((entity.MloInstance != null) && (entity.MloInstance.Entities != null)) if ((entity.MloInstance != null) && (entity.MloInstance.Entities != null))
@ -1936,13 +1882,7 @@ namespace CodeWalker.Rendering
var intent = entity.MloInstance.Entities[j]; var intent = entity.MloInstance.Entities[j];
var intarch = intent.Archetype; var intarch = intent.Archetype;
if (intarch == null) continue; //missing archetype... if (intarch == null) continue; //missing archetype...
if (!RenderIsEntityFinalRender(intent)) continue; //proxy or something.. if (!RenderIsEntityFinalRender(intent)) continue; //proxy or something..
intent.CamRel = intent.Position - camera.Position;
intent.Distance = intent.CamRel.Length();
intent.IsVisible = true;
RenderArchetype(intarch, intent); RenderArchetype(intarch, intent);
} }
} }
@ -1953,8 +1893,6 @@ namespace CodeWalker.Rendering
} }
return RenderArchetype(arch, entity); return RenderArchetype(arch, entity);
} }
return true; return true;
@ -2102,7 +2040,8 @@ namespace CodeWalker.Rendering
if (arche == null) return false; if (arche == null) return false;
Vector3 camrel = (entity != null) ? entity.CamRel : -camera.Position; Vector3 entpos = (entity != null) ? entity.Position : Vector3.Zero;
Vector3 camrel = entpos - camera.Position;
Quaternion orientation = Quaternion.Identity; Quaternion orientation = Quaternion.Identity;
Vector3 scale = Vector3.One; Vector3 scale = Vector3.One;

View File

@ -573,14 +573,23 @@ namespace CodeWalker.Rendering
context.OutputMerger.DepthStencilState = dsEnabled; context.OutputMerger.DepthStencilState = dsEnabled;
context.Rasterizer.State = rsSolid; context.Rasterizer.State = rsSolid;
//find the casters float maxdist = 3000.0f;// cascade.IntervalFar * 5.0f;
//find the casters within range
shadowcasters.Clear(); shadowcasters.Clear();
shadowcastercount = 0; shadowcastercount = 0;
foreach (var sbatch in shadowbatches) for (int b = 0; b < shadowbatches.Count; b++)
{ {
foreach (var srend in sbatch.Geometries) //shadowcasters.AddRange(shadowbatches[b].Geometries);
var sbgeoms = shadowbatches[b].Geometries;
for (int g = 0; g < sbgeoms.Count; g++)
{ {
shadowcasters.Add(srend); var sbgeom = sbgeoms[g];
float idist = sbgeom.Inst.Distance - sbgeom.Inst.Radius;
if (idist <= maxdist)
{
shadowcasters.Add(sbgeom);
}
} }
} }
@ -592,21 +601,17 @@ namespace CodeWalker.Rendering
Shadowmap.BeginDepthRender(context, i); Shadowmap.BeginDepthRender(context, i);
float cfar = 3000.0f;// cascade.IntervalFar * 5.0f;
float worldtocascade = cascade.WorldUnitsToCascadeUnits * 2.0f; float worldtocascade = cascade.WorldUnitsToCascadeUnits * 2.0f;
float minrad = cascade.WorldUnitsPerTexel * 3.0f;
shadowbatch.Clear(); shadowbatch.Clear();
for (int c=0; c<shadowcasters.Count; c++) for (int c = 0; c < shadowcasters.Count; c++)
{ {
//if the caster overlaps the cascade, draw it //if the caster overlaps the cascade, draw it
var caster = shadowcasters[c]; var caster = shadowcasters[c];
if (caster.Inst.Radius <= (cascade.WorldUnitsPerTexel * 2.0f)) continue; //don't render little things if (caster.Inst.Radius <= minrad) continue; //don't render little things
if ((caster.Inst.Distance-caster.Inst.Radius) > cfar) continue; //performance improvement?
Vector3 iscenepos = caster.Inst.Position - Shadowmap.SceneOrigin; Vector3 iscenepos = caster.Inst.Position - Shadowmap.SceneOrigin;
Vector3 ilightpos = cascade.Matrix.Multiply(iscenepos - caster.Inst.BSCenter); Vector3 ilightpos = cascade.Matrix.Multiply(iscenepos + caster.Inst.BSCenter);
//Vector3 ilightrad = cascade.Matrix.Multiply(new Vector3(caster.Inst.Radius));
//float ilightradf = caster.Inst.Radius;// ilightrad.Length();
float ilightradf = caster.Inst.Radius * worldtocascade; float ilightradf = caster.Inst.Radius * worldtocascade;
float ilightminx = ilightpos.X - ilightradf; float ilightminx = ilightpos.X - ilightradf;
float ilightmaxx = ilightpos.X + ilightradf; float ilightmaxx = ilightpos.X + ilightradf;

View File

@ -30,11 +30,9 @@ namespace CodeWalker.Rendering
public List<ShadowmapCascade> Cascades; public List<ShadowmapCascade> Cascades;
Matrix SceneCamView; Matrix SceneCamView;
Matrix LightView; Matrix LightView;
//Matrix LightViewInv;
Vector3 LightDirection; Vector3 LightDirection;
int TextureSize; int TextureSize;
public int CascadeCount; public int CascadeCount;
//public const int MaxCascades = 6;
int PCFSize; int PCFSize;
float PCFOffset; float PCFOffset;
float BlurBetweenCascades; float BlurBetweenCascades;
@ -67,12 +65,6 @@ namespace CodeWalker.Rendering
ShadowVars = new GpuVarsBuffer<ShadowmapVars>(device); ShadowVars = new GpuVarsBuffer<ShadowmapVars>(device);
//DepthTexture = DXUtility.CreateTexture2D(device, TextureSize, TextureSize, 1, 16, Format.R32_Typeless, 1, 0, ResourceUsage.Default, BindFlags.DepthStencil | BindFlags.ShaderResource, 0, 0);
//DepthTextureSS = DXUtility.CreateSamplerState(device, TextureAddressMode.Border, new Color4(1.0f), Comparison.Always, Filter.MinMagMipLinear, 0, 0.0f, 0.0f, 0.0f);
//DepthTextureSRV = DXUtility.CreateShaderResourceView(device, DepthTexture, Format.R32_Float, ShaderResourceViewDimension.Texture2DArray, 1, 0, 16, 0);
DepthTexture = DXUtility.CreateTexture2D(device, TextureSize* CascadeCount, TextureSize, 1, 1, Format.R32_Typeless, 1, 0, ResourceUsage.Default, BindFlags.DepthStencil | BindFlags.ShaderResource, 0, 0); DepthTexture = DXUtility.CreateTexture2D(device, TextureSize* CascadeCount, TextureSize, 1, 1, Format.R32_Typeless, 1, 0, ResourceUsage.Default, BindFlags.DepthStencil | BindFlags.ShaderResource, 0, 0);
DepthTextureSS = DXUtility.CreateSamplerState(device, TextureAddressMode.Border, new Color4(0.0f), Comparison.Less, Filter.ComparisonMinMagLinearMipPoint, 0, 0.0f, 0.0f, 0.0f); DepthTextureSS = DXUtility.CreateSamplerState(device, TextureAddressMode.Border, new Color4(0.0f), Comparison.Less, Filter.ComparisonMinMagLinearMipPoint, 0, 0.0f, 0.0f, 0.0f);
DepthTextureSRV = DXUtility.CreateShaderResourceView(device, DepthTexture, Format.R32_Float, ShaderResourceViewDimension.Texture2D, 1, 0, 0, 0); DepthTextureSRV = DXUtility.CreateShaderResourceView(device, DepthTexture, Format.R32_Float, ShaderResourceViewDimension.Texture2D, 1, 0, 0, 0);
@ -88,7 +80,6 @@ namespace CodeWalker.Rendering
c.ZFar = 1.0f; c.ZFar = 1.0f;
c.IntervalNear = 0.0f; c.IntervalNear = 0.0f;
c.IntervalFar = 1.0f; c.IntervalFar = 1.0f;
//c.DepthTextureDSV = DXUtility.CreateDepthStencilView(device, DepthTexture, Format.D32_Float, i);
c.DepthRenderVP = new ViewportF() c.DepthRenderVP = new ViewportF()
{ {
Height = (float)TextureSize, Height = (float)TextureSize,
@ -154,14 +145,6 @@ namespace CodeWalker.Rendering
} }
if (Cascades != null) if (Cascades != null)
{ {
//foreach (var cascade in Cascades)
//{
// if (cascade.DepthTextureDSV != null)
// {
// cascade.DepthTextureDSV.Dispose();
// cascade.DepthTextureDSV = null;
// }
//}
Cascades.Clear(); Cascades.Clear();
Cascades = null; Cascades = null;
} }
@ -174,57 +157,49 @@ namespace CodeWalker.Rendering
RTS.Set(context); RTS.Set(context);
var ppos = cam.Position;// p.GetCurrentPosition(); var ppos = cam.Position;
var view = cam.ViewMatrix;// p.GetCurrentView(); var view = cam.ViewMatrix;
var proj = cam.ProjMatrix;// p.GetCurrentProj(); var proj = cam.ProjMatrix;
var viewproj = cam.ViewProjMatrix;// p.GetCurrentViewProj(); var viewproj = cam.ViewProjMatrix;
//need to compute a local scene space for the shadows. use a snapped version of the camera coords... //need to compute a local scene space for the shadows. use a snapped version of the camera coords...
Vector3 pp = ppos; Vector3 pp = ppos;
float snapsize = 20.0f;// 1000000; //20m in planet space... //ideally should snap to texel size float snapsize = 20.0f; //20m snap... //ideally should snap to texel size
SceneOrigin.X = pp.X - (pp.X % snapsize); SceneOrigin.X = pp.X - (pp.X % snapsize);
SceneOrigin.Y = pp.Y - (pp.Y % snapsize); SceneOrigin.Y = pp.Y - (pp.Y % snapsize);
SceneOrigin.Z = pp.Z - (pp.Z % snapsize); SceneOrigin.Z = pp.Z - (pp.Z % snapsize);
SceneCamPos = (pp - SceneOrigin);//.ToV3F();// *0.0001f; SceneCamPos = (pp - SceneOrigin);
//the items passed in here are visible items. need to compute the scene bounds from these. //the items passed in here are visible items. need to compute the scene bounds from these.
Vector4 vFLTMAX = new Vector4(float.MaxValue);// FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX ); Vector4 vFLTMAX = new Vector4(float.MaxValue);
Vector4 vFLTMIN = new Vector4(float.MinValue);// -FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX ); Vector4 vFLTMIN = new Vector4(float.MinValue);
Vector3 vHMAX = new Vector3(float.MaxValue);// V3H(9223372036854775807); Vector3 vHMAX = new Vector3(float.MaxValue);
Vector3 vHMIN = new Vector3(float.MinValue);// V3H(-((huge)9223372036854775807)); Vector3 vHMIN = new Vector3(float.MinValue);
WorldMin = vHMAX; WorldMin = vHMAX;
WorldMax = vHMIN; WorldMax = vHMIN;
foreach (var item in items) for (int i = 0; i < items.Count; i++)
{ {
Vector3 icamrel = item.Inst.CamRel;// item->Seed.Position.RelativeTo(ppos).ToV3F(); var inst = items[i].Inst;
float idist = icamrel.Length();// V3FLength(icamrel);
float irad = item.Inst.Renderable.Key.BoundingSphereRadius;// ((huge)item->Radius + 1); //+1 to account for rounding down
if ((idist-irad) > 3000.0f) continue; //3km limit
Vector3 imin = item.Inst.BBMin - 100.0f; //extra bias to make sure scene isn't too small in model view... Vector3 imin = inst.BBMin - 100.0f; //extra bias to make sure scene isn't too small in model view...
Vector3 imax = item.Inst.BBMax + 100.0f; Vector3 imax = inst.BBMax + 100.0f;
//Vector3 ipos = item.Inst.Position;// item->Seed.Position;
//Vector3 imin = ipos - irad;
//Vector3 imax = ipos + irad;
WorldMin = Vector3.Min(WorldMin, imin); WorldMin = Vector3.Min(WorldMin, imin);
WorldMax = Vector3.Max(WorldMax, imax); WorldMax = Vector3.Max(WorldMax, imax);
} }
SceneMin = (WorldMin - SceneOrigin);// *0.0001f; SceneMin = (WorldMin - SceneOrigin);
SceneMax = (WorldMax - SceneOrigin);// *0.0001f; SceneMax = (WorldMax - SceneOrigin);
SceneCenter = (SceneMax + SceneMin) * 0.5f; SceneCenter = (SceneMax + SceneMin) * 0.5f;
SceneExtent = (SceneMax - SceneMin) * 0.5f; SceneExtent = (SceneMax - SceneMin) * 0.5f;
//M16F camViewInv = M16FInverse(camView);
Matrix sceneCamTrans = Matrix.Translation(-SceneCamPos); Matrix sceneCamTrans = Matrix.Translation(-SceneCamPos);
SceneCamView = Matrix.Multiply(sceneCamTrans, view); SceneCamView = Matrix.Multiply(sceneCamTrans, view);
Matrix camViewInv = Matrix.Invert(SceneCamView); Matrix camViewInv = Matrix.Invert(SceneCamView);
Vector3 lightUp = new Vector3(0.0f, 1.0f, 0.0f); //BUG: should select this depending on light dir!? Vector3 lightUp = new Vector3(0.0f, 1.0f, 0.0f); //BUG: should select this depending on light dir!?
LightView = Matrix.LookAtLH(lightDir, Vector3.Zero, lightUp); //BUG?: pos/lightdir wrong way around?? LightView = Matrix.LookAtLH(lightDir, Vector3.Zero, lightUp); //BUG?: pos/lightdir wrong way around??
//LightView = Matrix.LookAtLH(Vector3.Zero, -lightDir, lightUp); //BUG?: pos/lightdir wrong way around??
LightDirection = lightDir; LightDirection = lightDir;
Vector4[] vSceneAABBPointsLightSpace = new Vector4[8]; Vector4[] vSceneAABBPointsLightSpace = new Vector4[8];
@ -233,7 +208,6 @@ namespace CodeWalker.Rendering
// Transform the scene AABB to Light space. // Transform the scene AABB to Light space.
for (int index = 0; index < 8; ++index) for (int index = 0; index < 8; ++index)
{ {
//vSceneAABBPointsLightSpace[index] = XMVector4Transform(vSceneAABBPointsLightSpace[index], matLightCameraView);
vSceneAABBPointsLightSpace[index] = LightView.Multiply(vSceneAABBPointsLightSpace[index]); vSceneAABBPointsLightSpace[index] = LightView.Multiply(vSceneAABBPointsLightSpace[index]);
} }
@ -243,9 +217,6 @@ namespace CodeWalker.Rendering
Vector4 vLightCameraOrthographicMax; Vector4 vLightCameraOrthographicMax;
float fCameraNearFarRange = 1000.0f; //(far - near) //1000m in planet space float fCameraNearFarRange = 1000.0f; //(far - near) //1000m in planet space
float[] fCascadeIntervals = { 0.0075f, 0.02f, 0.06f, 0.15f, 0.5f, 1.0f, 1.5f, 2.5f }; float[] fCascadeIntervals = { 0.0075f, 0.02f, 0.06f, 0.15f, 0.5f, 1.0f, 1.5f, 2.5f };
//CascadeCount = 6;
//float fCascadeIntervals[] = { 0.005f, 0.015f, 0.03f, 0.06f, 0.12f, 0.25f, 0.6f, 1.0f };
//CascadeCount = 8;
Vector4 vWorldUnitsPerTexel = Vector4.Zero; Vector4 vWorldUnitsPerTexel = Vector4.Zero;
float fInvTexelCount = 1.0f / (float)TextureSize; float fInvTexelCount = 1.0f / (float)TextureSize;
@ -275,9 +246,9 @@ namespace CodeWalker.Rendering
for (int icpIndex = 0; icpIndex < 8; ++icpIndex) for (int icpIndex = 0; icpIndex < 8; ++icpIndex)
{ {
// Transform the frustum from camera view space to world space. // Transform the frustum from camera view space to world space.
vFrustumPoints[icpIndex] = camViewInv.Multiply(vFrustumPoints[icpIndex]);// +V4FF(SceneCamPos, 0.0f);// XMVector4Transform(vFrustumPoints[icpIndex], matInverseViewCamera); vFrustumPoints[icpIndex] = camViewInv.Multiply(vFrustumPoints[icpIndex]);
// Transform the point from world space to Light Camera Space. // Transform the point from world space to Light Camera Space.
vTempTranslatedCornerPoint = LightView.Multiply(vFrustumPoints[icpIndex]);// XMVector4Transform(vFrustumPoints[icpIndex], matLightCameraView); vTempTranslatedCornerPoint = LightView.Multiply(vFrustumPoints[icpIndex]);
// Find the closest point. // Find the closest point.
vLightCameraOrthographicMin = Vector4.Min(vTempTranslatedCornerPoint, vLightCameraOrthographicMin); vLightCameraOrthographicMin = Vector4.Min(vTempTranslatedCornerPoint, vLightCameraOrthographicMin);
vLightCameraOrthographicMax = Vector4.Max(vTempTranslatedCornerPoint, vLightCameraOrthographicMax); vLightCameraOrthographicMax = Vector4.Max(vTempTranslatedCornerPoint, vLightCameraOrthographicMax);
@ -293,7 +264,7 @@ namespace CodeWalker.Rendering
Vector4 vDiagonal = (vFrustumPoints[0] - vFrustumPoints[6]); Vector4 vDiagonal = (vFrustumPoints[0] - vFrustumPoints[6]);
// The bound is the length of the diagonal of the frustum interval. // The bound is the length of the diagonal of the frustum interval.
float fCascadeBound = vDiagonal.XYZ().Length();// V3FLength(V4FToV3F(vDiagonal)); float fCascadeBound = vDiagonal.XYZ().Length();
vDiagonal = new Vector4(fCascadeBound); vDiagonal = new Vector4(fCascadeBound);
// The offset calculated will pad the ortho projection so that it is always the same size // The offset calculated will pad the ortho projection so that it is always the same size
@ -326,63 +297,36 @@ namespace CodeWalker.Rendering
//These are the unconfigured near and far plane values. They are purposly awful to show //These are the unconfigured near and far plane values. They are purposly awful to show
// how important calculating accurate near and far planes is. // how important calculating accurate near and far planes is.
float fNearPlane;// = 100000.0f; float fNearPlane;
float fFarPlane;// = -100000.0f; float fFarPlane;
//V4F tmpmin = vLightCameraOrthographicMin;
//vLightCameraOrthographicMin = -vLightCameraOrthographicMax;
//vLightCameraOrthographicMax = -tmpmin;
// By intersecting the light frustum with the scene AABB we can get a tighter bound on the near and far plane. // By intersecting the light frustum with the scene AABB we can get a tighter bound on the near and far plane.
ComputeNearAndFar(out fNearPlane, out fFarPlane, vLightCameraOrthographicMin, vLightCameraOrthographicMax, vSceneAABBPointsLightSpace); ComputeNearAndFar(out fNearPlane, out fFarPlane, vLightCameraOrthographicMin, vLightCameraOrthographicMax, vSceneAABBPointsLightSpace);
//near/far swap necessary because the scene camera has negative aspect ratio... // Create the orthographic projection for this cascade.
//float tmpn = fNearPlane;
//fNearPlane = -fFarPlane;
//fFarPlane = -tmpn;
// Craete the orthographic projection for this cascade.
cascade.Ortho = Matrix.OrthoOffCenterLH(vLightCameraOrthographicMin.X, vLightCameraOrthographicMax.X, vLightCameraOrthographicMin.Y, vLightCameraOrthographicMax.Y, fNearPlane, fFarPlane); cascade.Ortho = Matrix.OrthoOffCenterLH(vLightCameraOrthographicMin.X, vLightCameraOrthographicMax.X, vLightCameraOrthographicMin.Y, vLightCameraOrthographicMax.Y, fNearPlane, fFarPlane);
//M16FOrthographicOffCenter(cascade.Ortho, vLightCameraOrthographicMin.x, vLightCameraOrthographicMax.x, vLightCameraOrthographicMax.y, vLightCameraOrthographicMin.y, fNearPlane, fFarPlane);
//D3DXMatrixOrthoOffCenterLH(&m_matShadowProj[iCascadeIndex],
// XMVectorGetX(vLightCameraOrthographicMin),
// XMVectorGetX(vLightCameraOrthographicMax),
// XMVectorGetY(vLightCameraOrthographicMin),
// XMVectorGetY(vLightCameraOrthographicMax),
// fNearPlane, fFarPlane);
cascade.ZNear = fNearPlane; cascade.ZNear = fNearPlane;
cascade.ZFar = fFarPlane; cascade.ZFar = fFarPlane;
cascade.IntervalNear = fFrustumIntervalBegin; cascade.IntervalNear = fFrustumIntervalBegin;
cascade.IntervalFar = fFrustumIntervalEnd; cascade.IntervalFar = fFrustumIntervalEnd;
//m_fCascadePartitionsFrustum[iCascadeIndex] = fFrustumIntervalEnd;
cascade.Matrix = Matrix.Multiply(LightView, cascade.Ortho); cascade.Matrix = Matrix.Multiply(LightView, cascade.Ortho);
//cascade.Matrix = cascade.Ortho;
cascade.MatrixInv = Matrix.Invert(cascade.Matrix); cascade.MatrixInv = Matrix.Invert(cascade.Matrix);
cascade.WorldUnitsPerTexel = fWorldUnitsPerTexel; cascade.WorldUnitsPerTexel = fWorldUnitsPerTexel;
cascade.WorldUnitsToCascadeUnits = 2.0f / fCascadeBound;// (cascade.WorldUnitsPerTexel * fInvTexelCount); cascade.WorldUnitsToCascadeUnits = 2.0f / fCascadeBound;
} }
context.ClearDepthStencilView(DepthTextureDSV, DepthStencilClearFlags.Depth, 1.0f, 0); context.ClearDepthStencilView(DepthTextureDSV, DepthStencilClearFlags.Depth, 1.0f, 0);
//context.ClearDepthStencilView(cascade.DepthTextureDSV, DepthStencilClearFlags.Depth, 1.0f, 0);
//ID3D11RenderTargetView* pnullView = NULL;
// Set a null render target so as not to render color. // Set a null render target so as not to render color.
context.OutputMerger.SetRenderTargets(DepthTextureDSV, (RenderTargetView)null); context.OutputMerger.SetRenderTargets(DepthTextureDSV, (RenderTargetView)null);
//context.OutputMerger.SetRenderTargets(cascade.DepthTextureDSV, (RenderTargetView)null);
//context->OMSetRenderTargets(1, &pnullView, cascade.DepthTextureDSV.Get());
context.OutputMerger.SetDepthStencilState(DepthRenderDS); context.OutputMerger.SetDepthStencilState(DepthRenderDS);
//context->OMSetDepthStencilState(DepthRenderDS.Get(), 1);
context.Rasterizer.State = DepthRenderRS; context.Rasterizer.State = DepthRenderRS;
//context->RSSetState(DepthRenderRS.Get());
} }
@ -390,24 +334,7 @@ namespace CodeWalker.Rendering
{ {
ShadowmapCascade cascade = Cascades[cascadeIndex]; ShadowmapCascade cascade = Cascades[cascadeIndex];
//context.ClearDepthStencilView(DepthTextureDSV, DepthStencilClearFlags.Depth, 1.0f, 0);
////context.ClearDepthStencilView(cascade.DepthTextureDSV, DepthStencilClearFlags.Depth, 1.0f, 0);
////ID3D11RenderTargetView* pnullView = NULL;
//// Set a null render target so as not to render color.
//context.OutputMerger.SetRenderTargets(DepthTextureDSV, (RenderTargetView)null);
////context.OutputMerger.SetRenderTargets(cascade.DepthTextureDSV, (RenderTargetView)null);
////context->OMSetRenderTargets(1, &pnullView, cascade.DepthTextureDSV.Get());
//context.OutputMerger.SetDepthStencilState(DepthRenderDS);
////context->OMSetDepthStencilState(DepthRenderDS.Get(), 1);
//context.Rasterizer.State = DepthRenderRS;
////context->RSSetState(DepthRenderRS.Get());
context.Rasterizer.SetViewport(cascade.DepthRenderVP); context.Rasterizer.SetViewport(cascade.DepthRenderVP);
//context.Rasterizer.SetViewport(DepthRenderVP);
//context->RSSetViewports(1, &DepthRenderVP);
} }
public void EndUpdate(DeviceContext context) public void EndUpdate(DeviceContext context)
@ -418,7 +345,6 @@ namespace CodeWalker.Rendering
public void SetFinalRenderResources(DeviceContext context) public void SetFinalRenderResources(DeviceContext context)
{ {
//ShadowmapVars & v = ShadowVars.Vars;
ShadowVars.Vars.CamScenePos = new Vector4(SceneCamPos, 0.0f); //in shadow scene coords ShadowVars.Vars.CamScenePos = new Vector4(SceneCamPos, 0.0f); //in shadow scene coords
ShadowVars.Vars.CamSceneView = Matrix.Transpose(SceneCamView); ShadowVars.Vars.CamSceneView = Matrix.Transpose(SceneCamView);
ShadowVars.Vars.LightView = Matrix.Transpose(LightView); ShadowVars.Vars.LightView = Matrix.Transpose(LightView);
@ -431,27 +357,9 @@ namespace CodeWalker.Rendering
for (int i = 0; i < CascadeCount; ++i) for (int i = 0; i < CascadeCount; ++i)
{ {
ShadowmapCascade cascade = Cascades[i]; ShadowmapCascade cascade = Cascades[i];
//M16F mShadowTexture = m_matShadowProj[index] * dxmatTextureScale * dxmatTextureTranslation;
Matrix mShadowTexture = Matrix.Multiply(cascade.Ortho, dxmatTextureST); Matrix mShadowTexture = Matrix.Multiply(cascade.Ortho, dxmatTextureST);
//ShadowVars.Vars.CascadeScales[i].x = mShadowTexture.M11;
//ShadowVars.Vars.CascadeScales[i].y = mShadowTexture.M22;
//ShadowVars.Vars.CascadeScales[i].z = mShadowTexture.M33;
//ShadowVars.Vars.CascadeScales[i].w = 1.0f;
ShadowVars.Vars.CascadeScales.Set(i, new Vector4(mShadowTexture.M11, mShadowTexture.M22, mShadowTexture.M33, 1.0f)); ShadowVars.Vars.CascadeScales.Set(i, new Vector4(mShadowTexture.M11, mShadowTexture.M22, mShadowTexture.M33, 1.0f));
//v.CascadeOffsets[i].x = mShadowTexture.M41;
//v.CascadeOffsets[i].y = mShadowTexture.M42;
//v.CascadeOffsets[i].z = mShadowTexture.M43;
//v.CascadeOffsets[i].w = 0.0f;
ShadowVars.Vars.CascadeOffsets.Set(i, new Vector4(mShadowTexture.M41, mShadowTexture.M42, mShadowTexture.M43, 0.0f)); ShadowVars.Vars.CascadeOffsets.Set(i, new Vector4(mShadowTexture.M41, mShadowTexture.M42, mShadowTexture.M43, 0.0f));
//v.CascadeDepths[i].x = cascade.IntervalFar;
//v.CascadeDepths[i].y = 0.0f;
//v.CascadeDepths[i].z = 0.0f;
//v.CascadeDepths[i].w = 0.0f;
ShadowVars.Vars.CascadeDepths.Set(i, new Vector4(cascade.IntervalFar, 0.0f, 0.0f, 0.0f)); ShadowVars.Vars.CascadeDepths.Set(i, new Vector4(cascade.IntervalFar, 0.0f, 0.0f, 0.0f));
} }
@ -543,7 +451,6 @@ namespace CodeWalker.Rendering
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
// Transform point. // Transform point.
//Points[i] = XMVector4Transform(HomogenousPoints[i], matInverse);
Points[i] = matInverse.Multiply(HomogeneousPoints[i]); Points[i] = matInverse.Multiply(HomogeneousPoints[i]);
} }
@ -553,22 +460,22 @@ namespace CodeWalker.Rendering
sf.Orientation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f); sf.Orientation = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
// Compute the slopes. // Compute the slopes.
Points[0] = Points[0] * (1.0f / Points[0].Z);// XMVectorReciprocal(XMVectorSplatZ(Points[0])); Points[0] = Points[0] * (1.0f / Points[0].Z);
Points[1] = Points[1] * (1.0f / Points[1].Z);// XMVectorReciprocal(XMVectorSplatZ(Points[1])); Points[1] = Points[1] * (1.0f / Points[1].Z);
Points[2] = Points[2] * (1.0f / Points[2].Z);// XMVectorReciprocal(XMVectorSplatZ(Points[2])); Points[2] = Points[2] * (1.0f / Points[2].Z);
Points[3] = Points[3] * (1.0f / Points[3].Z);// XMVectorReciprocal(XMVectorSplatZ(Points[3])); Points[3] = Points[3] * (1.0f / Points[3].Z);
sf.RightSlope = Points[0].X;// XMVectorGetX(Points[0]); sf.RightSlope = Points[0].X;
sf.LeftSlope = Points[1].X;// XMVectorGetX(Points[1]); sf.LeftSlope = Points[1].X;
sf.TopSlope = Points[2].Y;// XMVectorGetY(Points[2]); sf.TopSlope = Points[2].Y;
sf.BottomSlope = Points[3].Y;// XMVectorGetY(Points[3]); sf.BottomSlope = Points[3].Y;
// Compute near and far. // Compute near and far.
Points[4] = Points[4] * (1.0f / Points[4].W);// XMVectorReciprocal(XMVectorSplatW(Points[4])); Points[4] = Points[4] * (1.0f / Points[4].W);
Points[5] = Points[5] * (1.0f / Points[5].W);// XMVectorReciprocal(XMVectorSplatW(Points[5])); Points[5] = Points[5] * (1.0f / Points[5].W);
sf.Near = Points[4].Z;// XMVectorGetZ(Points[4]); sf.Near = Points[4].Z;
sf.Far = Points[5].Z;// XMVectorGetZ(Points[5]); sf.Far = Points[5].Z;
} }
@ -586,17 +493,17 @@ namespace CodeWalker.Rendering
vViewFrust.Near = -fCascadeIntervalBegin; //negative due to negative aspect ratio projection matrix.. vViewFrust.Near = -fCascadeIntervalBegin; //negative due to negative aspect ratio projection matrix..
vViewFrust.Far = -fCascadeIntervalEnd; vViewFrust.Far = -fCascadeIntervalEnd;
Vector3 vGrabY = new Vector3(0.0f, 1.0f, 0.0f);// ,0x00000000 }; Vector3 vGrabY = new Vector3(0.0f, 1.0f, 0.0f);
Vector3 vGrabX = new Vector3(1.0f, 0.0f, 0.0f);// , 0x00000000 }; Vector3 vGrabX = new Vector3(1.0f, 0.0f, 0.0f);
Vector3 vRightTop = new Vector3(vViewFrust.RightSlope, vViewFrust.TopSlope, 1.0f);// , 1.0f }; Vector3 vRightTop = new Vector3(vViewFrust.RightSlope, vViewFrust.TopSlope, 1.0f);
Vector3 vLeftBottom = new Vector3(vViewFrust.LeftSlope, vViewFrust.BottomSlope, 1.0f);// , 1.0f }; Vector3 vLeftBottom = new Vector3(vViewFrust.LeftSlope, vViewFrust.BottomSlope, 1.0f);
Vector3 vNear = new Vector3(vViewFrust.Near, vViewFrust.Near, vViewFrust.Near);// ,1.0f }; Vector3 vNear = new Vector3(vViewFrust.Near, vViewFrust.Near, vViewFrust.Near);
Vector3 vFar = new Vector3(vViewFrust.Far, vViewFrust.Far, vViewFrust.Far);// ,1.0f }; Vector3 vFar = new Vector3(vViewFrust.Far, vViewFrust.Far, vViewFrust.Far);
Vector3 vRightTopNear = vRightTop * vNear;// XMVectorMultiply(vRightTop, vNear); Vector3 vRightTopNear = vRightTop * vNear;
Vector3 vRightTopFar = vRightTop * vFar;// XMVectorMultiply(vRightTop, vFar); Vector3 vRightTopFar = vRightTop * vFar;
Vector3 vLeftBottomNear = vLeftBottom * vNear;// XMVectorMultiply(vLeftBottom, vNear); Vector3 vLeftBottomNear = vLeftBottom * vNear;
Vector3 vLeftBottomFar = vLeftBottom * vFar;// XMVectorMultiply(vLeftBottom, vFar); Vector3 vLeftBottomFar = vLeftBottom * vFar;
pvCornerPointsWorld[0] = new Vector4(vRightTopNear, 1.0f); pvCornerPointsWorld[0] = new Vector4(vRightTopNear, 1.0f);
pvCornerPointsWorld[1] = new Vector4(V3FSelect(vRightTopNear, vLeftBottomNear, vGrabX), 1.0f); pvCornerPointsWorld[1] = new Vector4(V3FSelect(vRightTopNear, vLeftBottomNear, vGrabX), 1.0f);
@ -639,8 +546,8 @@ namespace CodeWalker.Rendering
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Initialize the near and far planes // Initialize the near and far planes
fNearPlane = float.MaxValue;// FLT_MAX; fNearPlane = float.MaxValue;
fFarPlane = float.MinValue;// -FLT_MAX; fFarPlane = float.MinValue;
ShadowmapTriangle[] triangleList = new ShadowmapTriangle[16]; ShadowmapTriangle[] triangleList = new ShadowmapTriangle[16];
int iTriangleCnt = 1; int iTriangleCnt = 1;
@ -913,9 +820,6 @@ namespace CodeWalker.Rendering
public ShadowmapVarsCascadeData CascadeOffsets; public ShadowmapVarsCascadeData CascadeOffsets;
public ShadowmapVarsCascadeData CascadeScales; public ShadowmapVarsCascadeData CascadeScales;
public ShadowmapVarsCascadeData CascadeDepths; //in scene eye space public ShadowmapVarsCascadeData CascadeDepths; //in scene eye space
//public Vector4 CascadeOffsets[16];
//public Vector4 CascadeScales[16];
//public Vector4 CascadeDepths[16]; //in scene eye space
public int CascadeCount; public int CascadeCount;
public int CascadeVisual; public int CascadeVisual;
public int PCFLoopStart; public int PCFLoopStart;
@ -1008,7 +912,6 @@ namespace CodeWalker.Rendering
public Matrix Ortho { get; set; } public Matrix Ortho { get; set; }
public Matrix Matrix { get; set; } public Matrix Matrix { get; set; }
public Matrix MatrixInv { get; set; } public Matrix MatrixInv { get; set; }
//public DepthStencilView DepthTextureDSV { get; set; }
public ViewportF DepthRenderVP { get; set; } public ViewportF DepthRenderVP { get; set; }
public float WorldUnitsPerTexel { get; set; } //updated each frame for culling public float WorldUnitsPerTexel { get; set; } //updated each frame for culling
public float WorldUnitsToCascadeUnits { get; set; } public float WorldUnitsToCascadeUnits { get; set; }

View File

@ -28,7 +28,6 @@ world view grid option?
---[Editor stuff]--- ---[Editor stuff]---
delete key - delete item!
add entities with preview... asset browser add entities with preview... asset browser
undo add/delete entities, cargens, path nodes, scenario points... undo add/delete entities, cargens, path nodes, scenario points...
@ -61,7 +60,6 @@ model view - improve .ynv rendering (portals etc)
model view - YPT particles - animate particles? do more work on format? model view - YPT particles - animate particles? do more work on format?
mapDataGroups - how to isolate one of the grouped ymaps? eg destruction etc. mapDataGroups - how to isolate one of the grouped ymaps? eg destruction etc.
entitySets - like mapDataGroups but for interiors..... in Mlo data?
fix LOD switching fix LOD switching
fix decal ordering? fix decal ordering?
@ -102,6 +100,13 @@ Audio stuff - do more work on .rel format (see https://github.com/CamxxCore/Rag
done: done:
[v.29]
entitySets - like mapDataGroups but for interiors..... in Mlo data
delete key - delete item!
[v.28]
Audio zones display
[v.27] [v.27]