/// <summary> /// Only to be called with FastOcclusionBoundingBoxDraw /// </summary> public static void PrepareFastOcclusionBoundingBoxDraw() { MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw; effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabled); effectOQ.SetViewMatrix(MyCamera.ViewMatrixAtZero); effectOQ.SetProjectionMatrix(MyCamera.ProjectionMatrix); if (!MyRenderConstants.RenderQualityProfile.ForwardRender) { var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth); effectOQ.SetDepthRT(depthRenderTarget); effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget)); } }
/// <summary> /// Draw occlusion bounding box method with our premade effect and box. /// </summary> /// <param name="bbox"></param> /// <param name="scale"></param> /// <param name="enableDepthTesting"></param> /// <param name="billboardLike">Indicates whether the occlusion object (box) is rotated to face the camera or not.</param> public static void DrawOcclusionBoundingBox(BoundingBox bbox, float scale, bool enableDepthTesting, bool billboardLike = false, bool useDepthTarget = true) { useDepthTarget &= !MyRenderConstants.RenderQualityProfile.ForwardRender; var cameraToBBox = bbox.GetCenter() - MyCamera.Position; Matrix worldMatrix = billboardLike ? Matrix.CreateWorld(Vector3.Zero, MyMwcUtils.Normalize(cameraToBBox), MyMwcUtils.Normalize(MyCamera.UpVector + MyCamera.LeftVector)) : Matrix.Identity; Vector3 scaleV = (bbox.Max - bbox.Min) * scale; worldMatrix *= Matrix.CreateScale(scaleV); worldMatrix.Translation = cameraToBBox; MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw; if (enableDepthTesting && !MyRenderConstants.RenderQualityProfile.ForwardRender) { effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabled); } else { effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestDisabled); } effectOQ.SetWorldMatrix(worldMatrix); effectOQ.SetViewMatrix(MyCamera.ViewMatrixAtZero); effectOQ.SetProjectionMatrix(MyCamera.ProjectionMatrix); if (useDepthTarget) { var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth); effectOQ.SetDepthRT(depthRenderTarget); effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget)); } effectOQ.Begin(); //draw m_modelBoxLowRes.Render(); effectOQ.End(); }
private void IssueSpotQuery() { if (((LightType & LightTypeEnum.Spotlight) > 0) && SpotQuery != null && SpotQueryState == QueryState.IssueOcc) { BlendState previousBlendState = BlendState.Current;; MyStateObjects.DisabledColorChannels_BlendState.Apply(); // RasterizerState.CullNone.Apply(); // DepthStencilState.None.Apply(); MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw; effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabled); MatrixD spotWorld = SpotWorld; spotWorld.Translation = SpotWorld.Translation - MyRenderCamera.Position; effectOQ.SetWorldMatrix((Matrix)spotWorld); effectOQ.SetViewMatrix(MyRenderCamera.ViewMatrixAtZero); effectOQ.SetProjectionMatrix(MyRenderCamera.ProjectionMatrix); var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth); effectOQ.SetDepthRT(depthRenderTarget); effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget)); SpotQuery.Begin(); effectOQ.Begin(); MyDebugDraw.ModelCone.Render(); effectOQ.End(); SpotQuery.End(); SpotQueryState = QueryState.CheckOcc; previousBlendState.Apply(); } if (SpotQueryState == QueryState.WaitOcc) { SpotQueryState = QueryState.IssueOcc; } }
// Vertices must be in triangle strip order // 0--1 // | /| // |/ | // 2--3 public static void OcclusionPlaneDraw(Vector3[] quad) { Matrix worldMatrix = Matrix.Identity; worldMatrix.Translation = -MyCamera.Position; MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw; effectOQ.SetWorldMatrix(worldMatrix); effectOQ.SetViewMatrix(MyCamera.ViewMatrixAtZero); effectOQ.SetProjectionMatrix(MyCamera.ProjectionMatrix); if (!MyRenderConstants.RenderQualityProfile.ForwardRender) { var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth); effectOQ.SetDepthRT(depthRenderTarget); effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget)); effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabledNonMRT); } else { effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestDisabledNonMRT); } }