ISrvBindable CreateNewTexture(Vector2I resolution) { string debugName = string.Format("Debug-mipmap-{0}x{1}", resolution.X, resolution.Y); int mipmapLevels = MyResourceUtils.GetMipmapsCount(Math.Max(resolution.X, resolution.Y)); resolution.X = MyResourceUtils.GetMipmapStride(resolution.X, 0); // this is required by texture compression resolution.Y = MyResourceUtils.GetMipmapStride(resolution.Y, 0); // this is required by texture compression ISrvTexture dstTex = MyManagers.RwTextures.CreateSrv(debugName, resolution.X, resolution.Y, Format.BC7_UNorm_SRgb, mipmapLevels: mipmapLevels); for (int i = 0; i < mipmapLevels; i++) { ISrvBindable srcTex = m_fileTextures[i % m_fileTextures.Length]; Vector2I mipmapResolution = new Vector2I(MyResourceUtils.GetMipmapSize(resolution.X, i), MyResourceUtils.GetMipmapSize(resolution.Y, i)); for (int x = 0; x < mipmapResolution.X; x += srcTex.Size.X) { for (int y = 0; y < mipmapResolution.Y; y += srcTex.Size.Y) { MyRender11.RC.CopySubresourceRegion(srcTex, 0, null, dstTex, i, x, y); } } } return(dstTex); }
public static void DisplayHistogram(IRtvBindable output, ISrvBindable avgLumSrv, ISrvTexture histogram) { RC.PixelShader.SetSrvs(0, histogram, avgLumSrv); RC.PixelShader.Set(m_drawHistogram); RC.SetRtv(output); MyScreenPass.DrawFullscreenQuad(new MyViewport(64, 64, 512, 64)); //m_histogram.Release(); //m_histogram = null; }
public void CopyRedToAll(IRtvBindable output, ISrvTexture source) { MyRenderContext RC = MyRender11.RC; RC.SetBlendState(null); RC.SetRtv(output); RC.PixelShader.Set(m_ps); RC.PixelShader.SetSrv(0, source); MyScreenPass.DrawFullscreenQuad(); RC.ResetTargets(); }
public void CopyRedToAll(IRtvBindable output, ISrvTexture source) { MyRenderContext RC = MyRender11.RC; RC.SetBlendState(null); RC.SetRtv(output); RC.PixelShader.Set(m_ps); RC.PixelShader.SetSrv(0, source); MyScreenPass.DrawFullscreenQuad(); RC.ResetTargets(); }
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 void DisposeTex(ref ISrvTexture texture) { if (texture == null) { return; } MySrvTexture textureInternal = (MySrvTexture)texture; if (m_isDeviceInit) { textureInternal.OnDeviceEnd(); } m_srvTextures.Deallocate(textureInternal); texture = null; }
public void CopyRedToAll(IRtvBindable output, ISrvTexture source) { m_postprocessRedToAll.CopyRedToAll(output, source); }
public void CopyRedToAll(IRtvBindable output, ISrvTexture source) { m_postprocessRedToAll.CopyRedToAll(output, source); }
internal static void Render(ISrvTexture postProcessedShadows, IRtvTexture ambientOcclusion) { ProfilerShort.Begin("PreparePointLights"); MyGpuProfiler.IC_BeginBlock("Map lights to tiles"); if (MyRender11.DebugOverrides.PointLights) { PreparePointLights(); } MyGpuProfiler.IC_BeginNextBlock("Apply point lights"); ProfilerShort.End(); ProfilerShort.Begin("RenderPointlightsTiled"); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); if (!MyStereoRender.Enable) { RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.CSBindRawCB_FrameConstants(RC); MyStereoRender.PSBindRawCB_FrameConstants(RC); } RC.PixelShader.SetSrvs(0, MyGBuffer.Main); RC.AllShaderStages.SetSrv(MyCommon.MATERIAL_BUFFER_SLOT, MySceneMaterials.m_buffer); RC.SetBlendState(MyBlendStateManager.BlendAdditive); RC.SetDepthStencilState(!MyStereoRender.Enable ? MyDepthStencilStateManager.IgnoreDepthStencil : MyDepthStencilStateManager.StereoIgnoreDepthStencil); RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers); if (MyRender11.DebugOverrides.PointLights) { RenderPointlightsTiled(ambientOcclusion); } ProfilerShort.End(); ProfilerShort.Begin("RenderSpotlights"); MyGpuProfiler.IC_BeginNextBlock("Apply spotlights"); if (MyRender11.DebugOverrides.SpotLights) { RenderSpotlights(); } ProfilerShort.End(); ProfilerShort.Begin("RenderDirectionalEnvironmentLight"); MyGpuProfiler.IC_BeginNextBlock("Apply directional light"); if (MyRender11.DebugOverrides.EnvLight) { RenderDirectionalEnvironmentLight(postProcessedShadows, ambientOcclusion); } MyGpuProfiler.IC_EndBlock(); ProfilerShort.End(); // Because of BindGBufferForRead: RC.AllShaderStages.SetSrv(0, null); RC.AllShaderStages.SetSrv(1, null); RC.AllShaderStages.SetSrv(2, null); RC.AllShaderStages.SetSrv(3, null); RC.AllShaderStages.SetSrv(4, null); RC.SetBlendState(null); RC.SetRtv(null); }
static void RenderDirectionalEnvironmentLight(ISrvTexture postProcessedShadows, IRtvTexture ambientOcclusion) { PixelShaderId directionalPixelShader; MyShadowsQuality shadowsQuality = MyRender11.RenderSettings.ShadowQuality.GetShadowsQuality(); if (!MyRender11.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows || shadowsQuality == MyShadowsQuality.DISABLED) { if (DirectionalEnvironmentLight_NoShadow == PixelShaderId.NULL) DirectionalEnvironmentLight_NoShadow = MyShaders.CreatePs("Lighting/LightDir.hlsl", new[] { new ShaderMacro("NO_SHADOWS", null) }); directionalPixelShader = DirectionalEnvironmentLight_NoShadow; } else directionalPixelShader = DirectionalEnvironmentLight_Pixel; //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(DirectionalEnvironmentLight_Sample); MyScreenPass.RunFullscreenSampleFreq(MyGBuffer.Main.LBuffer); } RC.PixelShader.SetSrv(MyCommon.SHADOW_SLOT, null); }
internal static void Render(ISrvTexture postProcessedShadows, IRtvTexture ambientOcclusion) { MyLights.Update(); MyGpuProfiler.IC_BeginBlock("Map lights to tiles"); if (MyRender11.DebugOverrides.PointLights) PreparePointLights(); MyGpuProfiler.IC_BeginNextBlock("Apply point lights"); RC.SetPrimitiveTopology(PrimitiveTopology.TriangleList); if (!MyStereoRender.Enable) { RC.ComputeShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); RC.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants); } else { MyStereoRender.CSBindRawCB_FrameConstants(RC); MyStereoRender.PSBindRawCB_FrameConstants(RC); } RC.PixelShader.SetSrvs(0, MyGBuffer.Main); RC.AllShaderStages.SetSrv(MyCommon.MATERIAL_BUFFER_SLOT, MySceneMaterials.m_buffer); RC.SetBlendState(MyBlendStateManager.BlendAdditive); if (!MyStereoRender.Enable) RC.SetDepthStencilState(MyDepthStencilStateManager.IgnoreDepthStencil); else RC.SetDepthStencilState(MyDepthStencilStateManager.StereoIgnoreDepthStencil); RC.PixelShader.SetSamplers(0, MySamplerStateManager.StandardSamplers); if (MyRender11.DebugOverrides.PointLights) RenderPointlightsTiled(ambientOcclusion); MyGpuProfiler.IC_BeginNextBlock("Apply spotlights"); if (MyRender11.DebugOverrides.SpotLights) RenderSpotlights(); MyGpuProfiler.IC_BeginNextBlock("Apply directional light"); if (MyRender11.DebugOverrides.EnvLight) RenderDirectionalEnvironmentLight(postProcessedShadows, ambientOcclusion); MyGpuProfiler.IC_EndBlock(); // Because of BindGBufferForRead: RC.AllShaderStages.SetSrv(0, null); RC.AllShaderStages.SetSrv(1, null); RC.AllShaderStages.SetSrv(2, null); RC.AllShaderStages.SetSrv(3, null); RC.AllShaderStages.SetSrv(4, null); RC.SetBlendState(null); RC.SetRtv(null); }
public void DisposeTex(ref ISrvTexture texture) { if (texture == null) return; MySrvTexture textureInternal = (MySrvTexture) texture; if (m_isDeviceInit) textureInternal.OnDeviceEnd(); m_srvTextures.Deallocate(textureInternal); texture = null; }
public static void DisplayHistogram(IRtvBindable output, ISrvBindable avgLumSrv, ISrvTexture histogram) { RC.PixelShader.SetSrvs(0, histogram, avgLumSrv); RC.PixelShader.Set(m_drawHistogram); RC.SetRtv(output); MyScreenPass.DrawFullscreenQuad(new MyViewport(64, 64, 512, 64)); //m_histogram.Release(); //m_histogram = null; }