private void InitializeShadowmapAndCubemaps(DeviceContext context, double timeElapsed) { m_ShadowCamera.m_CameraForward = new Vector3(-0.15f, -1.0f, 0.15f); m_ShadowCamera.m_CameraForward.Normalize(); Vector3 min, max; m_SimpleSceneWrapper.GetSceneBounds(out min, out max); Vector3 sceneTop = (min + max) * 0.5f; sceneTop.Y = max.Y; m_ShadowCamera.m_OrthoZoomX = (max.X - min.X) * 0.7f; // some overlap m_ShadowCamera.m_OrthoZoomY = (max.Z - min.Z) * 0.7f; m_ShadowCamera.m_CameraPosition = sceneTop - m_ShadowCamera.m_CameraForward * 50.0f; m_ShadowCamera.m_CameraUp = new Vector3(0, 0, 1); CalculateAndUpdateConstantBuffer(context, timeElapsed); m_ResolvedShadow = m_ShadowEVSMGenerator.RenderShadows(context, m_SimpleSceneWrapper); context.PixelShader.SetShaderResource(m_GIRenderer.m_GIVolumeR.m_ShaderResourceView, 5); context.PixelShader.SetShaderResource(m_GIRenderer.m_GIVolumeG.m_ShaderResourceView, 6); context.PixelShader.SetShaderResource(m_GIRenderer.m_GIVolumeB.m_ShaderResourceView, 7); m_ResolvedShadow.BindSRV(context, 0); CubemapRenderHelper.RenderCubemap(context, m_CubeObject, m_CubeDepthObject, m_SimpleSceneWrapper, m_ViewportCamera.m_CameraPosition, 256.0f, false, new Color4(1.0f, 1.0f, 1.0f, 1.5f)); CubemapRenderHelper.GenerateCubemapMips(context, "PrefilterEnvLighting", m_CubeObjectFiltered, m_CubeObject); m_ShadowsInitialized = true; }
public void ExecutePass(DeviceContext context, SimpleSceneWrapper sceneWrapper, Vector3 position) { //using (new GpuProfilePoint(context, "CubemapRender")) { context.PixelShader.SetShaderResource(m_GIVolumeR.m_ShaderResourceView, 5); context.PixelShader.SetShaderResource(m_GIVolumeG.m_ShaderResourceView, 6); context.PixelShader.SetShaderResource(m_GIVolumeB.m_ShaderResourceView, 7); CubemapRenderHelper.RenderCubemap(context, m_CubeObject, m_CubeObjectDepth, sceneWrapper, position, 50.0f, false, new Color4(1.0f, 0.75f, 0.75f, 1.0f)); } //using (new GpuProfilePoint(context, "InitSH")) { context.PixelShader.SetShaderResource(m_CubeObject.m_ShaderResourceView, 0); m_InitialSHSet.BindAsRenderTarget(context); PostEffectHelper.RenderFullscreenTriangle(context, "GIInitSH"); RenderTargetSet.BindNull(context); DownsamplePass(context, m_InitialSHSet, m_Downsampled16x16SHSetR, m_Downsampled16x16SHSetG, m_Downsampled16x16SHSetB); m_Downsampled16x16SHSetR.BindSRV(context, 0); m_Downsampled4x4SHSetR.BindAsRenderTarget(context); PostEffectHelper.RenderFullscreenTriangle(context, "Downsample4x4"); RenderTargetSet.BindNull(context); m_Downsampled16x16SHSetG.BindSRV(context, 0); m_Downsampled4x4SHSetG.BindAsRenderTarget(context); PostEffectHelper.RenderFullscreenTriangle(context, "Downsample4x4"); RenderTargetSet.BindNull(context); m_Downsampled16x16SHSetB.BindSRV(context, 0); m_Downsampled4x4SHSetB.BindAsRenderTarget(context); PostEffectHelper.RenderFullscreenTriangle(context, "Downsample4x4"); RenderTargetSet.BindNull(context); Vector3 sceneMin, sceneMax; sceneWrapper.GetSceneBounds(out sceneMin, out sceneMax); Vector3 positionInVolume = position - sceneMin; positionInVolume.X = positionInVolume.X / (sceneMax.X - sceneMin.X); positionInVolume.Y = positionInVolume.Y / (sceneMax.Y - sceneMin.Y); positionInVolume.Z = positionInVolume.Z / (sceneMax.Z - sceneMin.Z); dynamic scb = m_GIConstantBuffer; scb.g_InjectPosition = new Vector4(new Vector3(positionInVolume.X * (float)(m_VolumeSizeX - 1), positionInVolume.Y * (float)(m_VolumeSizeY - 1), positionInVolume.Z * (float)(m_VolumeSizeZ - 1)), 0); m_GIConstantBuffer.CompileAndBind(context); m_Downsampled4x4SHSetR.BindSRV(context, 2); m_Downsampled4x4SHSetG.BindSRV(context, 3); m_Downsampled4x4SHSetB.BindSRV(context, 4); context.ComputeShader.SetUnorderedAccessView(m_GIVolumeR.m_UnorderedAccessView, 0); context.ComputeShader.SetUnorderedAccessView(m_GIVolumeG.m_UnorderedAccessView, 1); context.ComputeShader.SetUnorderedAccessView(m_GIVolumeB.m_UnorderedAccessView, 2); ShaderManager.ExecuteComputeForSize(context, 1, 1, 1, "InjectSHIntoVolume"); ContextHelper.ClearCSContext(context); } }