|
@@ -99,124 +99,7 @@ namespace SharpGLTF.Runtime
|
|
|
_View = Matrix.Invert(cameraMatrix);
|
|
_View = Matrix.Invert(cameraMatrix);
|
|
|
_Projection = SceneUtils.CreatePerspectiveFieldOfView(_FieldOfView, _Device.Viewport.AspectRatio, _NearPlane);
|
|
_Projection = SceneUtils.CreatePerspectiveFieldOfView(_FieldOfView, _Device.Viewport.AspectRatio, _NearPlane);
|
|
|
// _DistanceComparer = MODELINST.GetDistanceComparer(-_View.Translation);
|
|
// _DistanceComparer = MODELINST.GetDistanceComparer(-_View.Translation);
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
- public void DrawMesh(PBREnvironment environment, Mesh mesh, Matrix worldMatrix)
|
|
|
|
|
- {
|
|
|
|
|
- var proj = GetProjectionMatrix();
|
|
|
|
|
-
|
|
|
|
|
- PushState();
|
|
|
|
|
-
|
|
|
|
|
- foreach (var e in mesh.OpaqueEffects)
|
|
|
|
|
- {
|
|
|
|
|
- ModelInstance.UpdateProjViewTransforms(e, proj, _View);
|
|
|
|
|
- ModelInstance.UpdateWorldTransforms(e, worldMatrix);
|
|
|
|
|
- environment.ApplyTo(e);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- mesh.DrawOpaque();
|
|
|
|
|
-
|
|
|
|
|
- foreach (var e in mesh.TranslucidEffects)
|
|
|
|
|
- {
|
|
|
|
|
- ModelInstance.UpdateProjViewTransforms(e, proj, _View);
|
|
|
|
|
- ModelInstance.UpdateWorldTransforms(e, worldMatrix);
|
|
|
|
|
- environment.ApplyTo(e);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- mesh.DrawTranslucid();
|
|
|
|
|
-
|
|
|
|
|
- PopState();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /// <summary>
|
|
|
|
|
- /// Draw a single model instance
|
|
|
|
|
- /// </summary>
|
|
|
|
|
- /// <param name="environment">Defines the athmospheric and lighting environment to use for the render.</param>
|
|
|
|
|
- /// <param name="modelInstance">Defines the instance that is going to be rendered.</param>
|
|
|
|
|
- /// <remarks>
|
|
|
|
|
- /// Rendering models one by one is accepted, but some features like translucent parts sortings will not work
|
|
|
|
|
- /// unless you manually render the models in the correct order.
|
|
|
|
|
- /// </remarks>
|
|
|
|
|
- public void DrawModelInstance(PBREnvironment environment, MODELINST modelInstance)
|
|
|
|
|
- {
|
|
|
|
|
- PushState();
|
|
|
|
|
-
|
|
|
|
|
- var proj = GetProjectionMatrix();
|
|
|
|
|
-
|
|
|
|
|
- foreach (var e in modelInstance.SharedEffects)
|
|
|
|
|
- {
|
|
|
|
|
- environment.ApplyTo(e);
|
|
|
|
|
- ModelInstance.UpdateProjViewTransforms(e, proj, _View);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- modelInstance.DrawAllParts(proj, _View);
|
|
|
|
|
-
|
|
|
|
|
- PopState();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /// <summary>
|
|
|
|
|
- /// Draws a batch of model instances.
|
|
|
|
|
- /// </summary>
|
|
|
|
|
- /// <param name="environment">Defines the athmospheric and lighting environment to use for the render.</param>
|
|
|
|
|
- /// <param name="modelInstances">A batch of model instances.</param>
|
|
|
|
|
- /// <remarks>
|
|
|
|
|
- /// Rendering multiple models in a batch has a number of advantages over rendering models one by one:
|
|
|
|
|
- /// - It allows splitting the rendering between opaque and translucent parts, which are rendered in the correct
|
|
|
|
|
- /// order to preserve rendering correctness.
|
|
|
|
|
- /// - Less redundant calls.
|
|
|
|
|
- /// - Futher optimizations are possible, like batching instances that share the same template model in a single
|
|
|
|
|
- /// drawing call.
|
|
|
|
|
- /// - Possibility to add shadows, where some instances cast shadows over others.
|
|
|
|
|
- /// </remarks>
|
|
|
|
|
- public void DrawSceneInstances(PBREnvironment environment, params MODELINST[] modelInstances)
|
|
|
|
|
- {
|
|
|
|
|
- PushState();
|
|
|
|
|
-
|
|
|
|
|
- // todo: fustrum culling goes here
|
|
|
|
|
-
|
|
|
|
|
- var proj = GetProjectionMatrix();
|
|
|
|
|
-
|
|
|
|
|
- _SceneInstances.Clear();
|
|
|
|
|
- _SceneInstances.AddRange(modelInstances);
|
|
|
|
|
- _SceneInstances.Sort(_DistanceComparer);
|
|
|
|
|
-
|
|
|
|
|
- // gather all effects from all visible instances.
|
|
|
|
|
- _SceneEffects.Clear();
|
|
|
|
|
- _SceneEffects.UnionWith(_SceneInstances.SelectMany(item => item.SharedEffects));
|
|
|
|
|
-
|
|
|
|
|
- // set Projection & View on all visible effects.
|
|
|
|
|
-
|
|
|
|
|
- foreach (var e in _SceneEffects)
|
|
|
|
|
- {
|
|
|
|
|
- ModelInstance.UpdateProjViewTransforms(e, proj, _View);
|
|
|
|
|
- // todo: set env.Exposure
|
|
|
|
|
- // todo: set env.AmbientLight
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // todo: find the closest lights for each visible instance.
|
|
|
|
|
-
|
|
|
|
|
- // render opaque parts from closest to farthest
|
|
|
|
|
-
|
|
|
|
|
- foreach (var instance in _SceneInstances)
|
|
|
|
|
- {
|
|
|
|
|
- foreach (var e in instance.SharedEffects) environment.ApplyTo(e);
|
|
|
|
|
- instance.DrawOpaqueParts();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // render translucid parts from farthest to closest
|
|
|
|
|
-
|
|
|
|
|
- _SceneInstances.Reverse();
|
|
|
|
|
-
|
|
|
|
|
- foreach (var instance in _SceneInstances)
|
|
|
|
|
- {
|
|
|
|
|
- foreach (var e in instance.SharedEffects) environment.ApplyTo(e);
|
|
|
|
|
- instance.DrawTranslucidParts();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- PopState();
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
|
}
|
|
}
|