public static float ShadowCascadeSplit(this MyShadowsQuality shadowQuality, int cascade) { if (cascade == 0) { return(1.0f); } var lastCascadeSplit = MyRender11.Settings.ShadowCascadeMaxDistance; switch (shadowQuality) { case MyShadowsQuality.MEDIUM: lastCascadeSplit *= MyRender11.Settings.ShadowCascadeMaxDistanceMultiplierMedium; break; case MyShadowsQuality.HIGH: lastCascadeSplit *= MyRender11.Settings.ShadowCascadeMaxDistanceMultiplierHigh; break; } //float lerpAmount = 0.00f; var spreadFactor = MyRender11.Settings.ShadowCascadeSpreadFactor; float logSplit = (float)Math.Pow(lastCascadeSplit, (cascade + spreadFactor) / (4.0 + spreadFactor)); //float uniformSplit = 1.0f + (cascade4 - 1.0f) * cascade / 4.0f; //float practicalSplit = MathHelper.Lerp(logSplit, uniformSplit, lerpAmount); //float usedSplit = practicalSplit; return(logSplit); }
public static float ShadowCascadeSplit(this MyShadowsQuality shadowQuality, int cascade) { if (cascade == 0) { return(1.0f); } var lastCascadeSplit = MyRenderProxy.Settings.ShadowCascadeMaxDistance; switch (shadowQuality) { case MyShadowsQuality.MEDIUM: lastCascadeSplit *= MyRenderProxy.Settings.ShadowCascadeMaxDistanceMultiplierMedium; break; case MyShadowsQuality.HIGH: lastCascadeSplit *= MyRenderProxy.Settings.ShadowCascadeMaxDistanceMultiplierHigh; break; } var spreadFactor = MyRenderProxy.Settings.ShadowCascadeSpreadFactor; float logSplit = (float)Math.Pow(lastCascadeSplit, (cascade + spreadFactor) / (MyRenderProxy.Settings.ShadowCascadeCount + spreadFactor)); return(logSplit); }
public static int Resolution(this MyShadowsQuality shadowQuality) { switch (shadowQuality) { case MyShadowsQuality.LOW: return(512); case MyShadowsQuality.HIGH: return(1024); } return(-1); }
public static int BackOffset(this MyShadowsQuality shadowQuality) { switch (shadowQuality) { // CHECK-ME: This is no sense. Previous revision is the same case MyShadowsQuality.DISABLED: case MyShadowsQuality.LOW: case MyShadowsQuality.MEDIUM: case MyShadowsQuality.HIGH: return((int)MyShadowCascades.Settings.Data.ShadowCascadeZOffset); } return(-1); }
private static void RenderDirectionalEnvironmentLight(ISrvTexture postProcessedShadows, IRtvTexture ambientOcclusion) { PixelShaderId directionalPixelShader; MyShadowsQuality shadowsQuality = MyRender11.Settings.User.ShadowQuality.GetShadowsQuality(); if (!MyRender11.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows || shadowsQuality == MyShadowsQuality.DISABLED) { if (m_directionalEnvironmentLightNoShadow == PixelShaderId.NULL) { m_directionalEnvironmentLightNoShadow = MyShaders.CreatePs("Lighting/LightDir.hlsl", new[] { new ShaderMacro("NO_SHADOWS", null) }); } directionalPixelShader = m_directionalEnvironmentLightNoShadow; } else { directionalPixelShader = m_directionalEnvironmentLightPixel; } //context.VertexShader.Set(MyCommon.FullscreenShader.VertexShader); RC.PixelShader.Set(directionalPixelShader); RC.AllShaderStages.SetConstantBuffer(4, MyRender11.DynamicShadows.ShadowCascades.CascadeConstantBuffer); RC.PixelShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MySamplerStateManager.Shadowmap); MyFileTextureManager texManager = MyManagers.FileTextures; RC.PixelShader.SetSrv(MyCommon.SKYBOX_SLOT, texManager.GetTexture(MyRender11.Environment.Data.Skybox, MyFileTextureEnum.CUBEMAP, true)); ISrvBindable skybox = MyRender11.IsIntelBrokenCubemapsWorkaround ? MyGeneratedTextureManager.IntelFallbackCubeTex : (ISrvBindable)MyManagers.EnvironmentProbe.Cubemap; RC.PixelShader.SetSrv(MyCommon.SKYBOX_IBL_SLOT, skybox); RC.PixelShader.SetSrv(MyCommon.CASCADES_SM_SLOT, MyRender11.DynamicShadows.ShadowCascades.CascadeShadowmapArray); RC.PixelShader.SetSrv(MyCommon.SHADOW_SLOT, postProcessedShadows); RC.PixelShader.SetSrv(MyCommon.AMBIENT_BRDF_LUT_SLOT, MyCommon.GetAmbientBrdfLut()); RC.PixelShader.SetSrv(MyCommon.AO_SLOT, ambientOcclusion); MyScreenPass.RunFullscreenPixelFreq(MyGBuffer.Main.LBuffer); if (MyRender11.MultisamplingEnabled) { RC.PixelShader.Set(m_directionalEnvironmentLightSample); MyScreenPass.RunFullscreenSampleFreq(MyGBuffer.Main.LBuffer); } RC.PixelShader.SetSrv(MyCommon.SHADOW_SLOT, null); }
public static int BackOffset(this MyShadowsQuality shadowQuality) { switch (shadowQuality) { case MyShadowsQuality.LOW: return((int)MyRender11.Settings.ShadowCascadeZOffset); case MyShadowsQuality.MEDIUM: return((int)MyRender11.Settings.ShadowCascadeZOffset); case MyShadowsQuality.HIGH: return((int)MyRender11.Settings.ShadowCascadeZOffset); } return(-1); }
public static int ShadowCascadeResolution(this MyShadowsQuality shadowQuality) { switch (shadowQuality) { case MyShadowsQuality.DISABLED: case MyShadowsQuality.LOW: return(512); case MyShadowsQuality.MEDIUM: return(1024); case MyShadowsQuality.HIGH: return(1024); } return(-1); }
public bool IsSetToLowQuality() { MyTextureAnisoFiltering?anisotropicFiltering = this.AnisotropicFiltering; MyTextureAnisoFiltering nONE = MyTextureAnisoFiltering.NONE; if ((((MyTextureAnisoFiltering)anisotropicFiltering.GetValueOrDefault()) == nONE) & (anisotropicFiltering != null)) { MyAntialiasingMode?antialiasingMode = this.AntialiasingMode; MyAntialiasingMode mode = MyAntialiasingMode.NONE; if ((((MyAntialiasingMode)antialiasingMode.GetValueOrDefault()) == mode) & (antialiasingMode != null)) { MyShadowsQuality?shadowQuality = this.ShadowQuality; MyShadowsQuality lOW = MyShadowsQuality.LOW; if ((((MyShadowsQuality)shadowQuality.GetValueOrDefault()) == lOW) & (shadowQuality != null)) { MyTextureQuality?textureQuality = this.TextureQuality; MyTextureQuality quality2 = MyTextureQuality.LOW; if ((((MyTextureQuality)textureQuality.GetValueOrDefault()) == quality2) & (textureQuality != null)) { MyRenderQualityEnum?modelQuality = this.ModelQuality; MyRenderQualityEnum enum2 = MyRenderQualityEnum.LOW; if ((((MyRenderQualityEnum)modelQuality.GetValueOrDefault()) == enum2) & (modelQuality != null)) { modelQuality = this.VoxelQuality; enum2 = MyRenderQualityEnum.LOW; if ((((MyRenderQualityEnum)modelQuality.GetValueOrDefault()) == enum2) & (modelQuality != null)) { float?grassDrawDistance = this.GrassDrawDistance; float num = 0f; return((grassDrawDistance.GetValueOrDefault() == num) & (grassDrawDistance != null)); } } } } } } return(false); }
internal void GatherArray(RwTexId postprocessTarget, RwTexId cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer) { if (!MyRenderProxy.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows) { return; } MarkCascadesInStencil(cascadeInfo); MyGpuProfiler.IC_BeginBlock("Cascades postprocess"); MyRenderContext renderContext = MyRenderContext.Immediate; DeviceContext deviceContext = renderContext.DeviceContext; MyShadowsQuality shadowsQuality = MyRender11.RenderSettings.ShadowQuality.GetShadowsQuality(); if (shadowsQuality == MyShadowsQuality.LOW) { renderContext.SetCS(m_gatherCS_LD); } else if (shadowsQuality == MyShadowsQuality.MEDIUM) { renderContext.SetCS(m_gatherCS_MD); } else if (shadowsQuality == MyShadowsQuality.HIGH) { renderContext.SetCS(m_gatherCS_HD); } ComputeShaderId.TmpUav[0] = postprocessTarget.Uav; deviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount); deviceContext.ComputeShader.SetShaderResource(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.m_SRV_depth : MyGBuffer.Main.DepthStencil.m_SRV_depth); deviceContext.ComputeShader.SetShaderResource(1, MyGBuffer.Main.DepthStencil.m_SRV_stencil); deviceContext.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, SamplerStates.m_shadowmap); if (!MyStereoRender.Enable) { deviceContext.ComputeShader.SetConstantBuffer(0, MyCommon.FrameConstants); } else { MyStereoRender.CSBindRawCB_FrameConstants(renderContext); } deviceContext.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer); deviceContext.ComputeShader.SetShaderResource(MyCommon.CASCADES_SM_SLOT, cascadeArray.SRV); Vector2I threadGroups = GetThreadGroupCount(); deviceContext.Dispatch(threadGroups.X, threadGroups.Y, 1); ComputeShaderId.TmpUav[0] = null; renderContext.DeviceContext.ComputeShader.SetUnorderedAccessViews(0, ComputeShaderId.TmpUav, ComputeShaderId.TmpCount); deviceContext.ComputeShader.SetShaderResource(0, null); deviceContext.ComputeShader.SetShaderResource(1, null); if (shadowsQuality == MyShadowsQuality.HIGH && MyRender11.Settings.EnableShadowBlur) { MyBlur.Run(postprocessTarget.Rtv, MyRender11.CascadesHelper.Rtv, MyRender11.CascadesHelper.SRV, postprocessTarget.SRV, depthDiscardThreshold: 0.2f); } MyGpuProfiler.IC_EndBlock(); }
public static MyShadowsQuality GetShadowsQuality(this MyShadowsQuality shadowQuality) { return(shadowQuality); }
internal void GatherArray(IUavTexture postprocessTarget, ISrvBindable cascadeArray, MyProjectionInfo[] cascadeInfo, ConstantsBufferId cascadeConstantBuffer) { MyShadowsQuality shadowsQuality = MyRender11.RenderSettings.ShadowQuality.GetShadowsQuality(); if (!MyRender11.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows || shadowsQuality == MyShadowsQuality.DISABLED) { RC.ClearUav(postprocessTarget, new RawInt4()); return; } MarkCascadesInStencil(cascadeInfo); MyGpuProfiler.IC_BeginBlock("Cascades postprocess"); if (shadowsQuality == MyShadowsQuality.LOW) { RC.ComputeShader.Set(m_gatherCS_LD); } else if (shadowsQuality == MyShadowsQuality.MEDIUM) { RC.ComputeShader.Set(m_gatherCS_MD); } else if (shadowsQuality == MyShadowsQuality.HIGH) { RC.ComputeShader.Set(m_gatherCS_HD); } RC.ComputeShader.SetUav(0, postprocessTarget); RC.ComputeShader.SetSrv(0, MyRender11.MultisamplingEnabled ? MyScreenDependants.m_resolvedDepth.SrvDepth : MyGBuffer.Main.DepthStencil.SrvDepth); RC.ComputeShader.SetSrv(1, MyGBuffer.Main.DepthStencil.SrvStencil); RC.ComputeShader.SetSampler(MyCommon.SHADOW_SAMPLER_SLOT, MySamplerStateManager.Shadowmap); if (!MyStereoRender.Enable) { RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.CSBindRawCB_FrameConstants(RC); } //RC.ComputeShader.SetConstantBuffer(4, MyManagers.Shadows.GetCsmConstantBufferOldOne()); RC.ComputeShader.SetConstantBuffer(4, cascadeConstantBuffer); RC.ComputeShader.SetSrv(MyCommon.CASCADES_SM_SLOT, cascadeArray); //RC.ComputeShader.SetSrv(MyCommon.CASCADES_SM_SLOT, MyManagers.Shadow.GetCsmForGbuffer()); Vector2I threadGroups = GetThreadGroupCount(); RC.Dispatch(threadGroups.X, threadGroups.Y, 1); RC.ComputeShader.SetUav(0, null); RC.ComputeShader.SetSrv(0, null); RC.ComputeShader.SetSrv(1, null); if (shadowsQuality == MyShadowsQuality.HIGH && MyShadowCascades.Settings.Data.EnableShadowBlur) { IBorrowedUavTexture helper = MyManagers.RwTexturesPool.BorrowUav("MyShadowCascadesPostProcess.Helper", Format.R8_UNorm); MyBlur.Run(postprocessTarget, helper, postprocessTarget, depthStencilState: MyDepthStencilStateManager.IgnoreDepthStencil, depthDiscardThreshold: 0.2f, clearColor: Color4.White); helper.Release(); } MyGpuProfiler.IC_EndBlock(); }