private void CreateAfterForwardOpaqueCommandBuffer(Camera camera) { #if ENABLE_FORWARD_OPAQUE_CAPTURE if (afterForwardOpaqueCommandBuffer != null) { camera.RemoveCommandBuffer(CameraEvent.AfterForwardOpaque, afterForwardOpaqueCommandBuffer); camera.RemoveCommandBuffer(CameraEvent.AfterSkybox, afterForwardOpaqueCommandBuffer); } if (afterForwardOpaqueCommandBuffer == null || (AfterOpaqueBuffer != null && (AfterOpaqueBuffer.width != camera.pixelWidth || AfterOpaqueBuffer.height != camera.pixelHeight))) { if (AfterOpaqueBuffer != null) { AfterOpaqueBuffer.Clear(); AfterOpaqueBuffer.Release(); Destroy(AfterOpaqueBuffer); AfterOpaqueBuffer = WeatherMakerFullScreenEffect.CreateRenderTexture(WeatherMakerFullScreenEffect.GetRenderTextureDescriptor(1, 1, 1, RenderTextureFormat.DefaultHDR, 0, camera)); } afterForwardOpaqueCommandBuffer = new CommandBuffer { name = afterForwardOpaqueCommandBufferName + Time.unscaledDeltaTime }; afterForwardOpaqueCommandBuffer.Blit(BuiltinRenderTextureType.CameraTarget, AfterOpaqueBuffer); afterForwardOpaqueCommandBuffer.SetGlobalTexture(WMS._CameraOpaqueTexture, AfterOpaqueBuffer); } if (camera.clearFlags == CameraClearFlags.Skybox) { camera.AddCommandBuffer(CameraEvent.AfterSkybox, afterForwardOpaqueCommandBuffer); } else { camera.AddCommandBuffer(CameraEvent.AfterForwardOpaque, afterForwardOpaqueCommandBuffer); } #endif }
public void PreCullFrame(Camera camera, WeatherMakerDownsampleScale scale, WeatherMakerTemporalReprojectionSize projSize) { if (TemporalReprojectionMaterial == null) { return; } WeatherMakerCameraType cameraType = WeatherMakerScript.GetCameraType(camera); if (cameraType == WeatherMakerCameraType.Other) { return; } int projSizeInt = (int)projSize; int downsampling = (int)scale; int frameWidth = camera.pixelWidth / downsampling; int frameHeight = camera.pixelHeight / downsampling; // ensure reprojection fits cleanly into frame while (frameWidth % projSizeInt != 0) { frameWidth++; } while (frameHeight % projSizeInt != 0) { frameHeight++; } if (frameWidth != FrameWidth || frameHeight != FrameHeight || ReprojectionSize != projSizeInt) { DisposeRenderTextures(); ReprojectionSize = projSizeInt; ReprojectionSizeSquared = ReprojectionSize * ReprojectionSize; CreateFrameNumbers(); FrameWidth = frameWidth; FrameHeight = frameHeight; SubFrameWidth = frameWidth / projSizeInt; SubFrameHeight = frameHeight / projSizeInt; RenderTextureFormat format = camera.allowHDR ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default; RenderTextureDescriptor descSubFrame = WeatherMakerFullScreenEffect.GetRenderTextureDescriptor(downsampling, projSizeInt, projSizeInt, format, 0, camera); subFrameCurrent = WeatherMakerFullScreenEffect.CreateRenderTexture(descSubFrame, FilterMode.Bilinear, TextureWrapMode.Clamp); subFrameCurrent.name = "WeatherMakerTemporalReprojectionSubFrame"; RenderTextureDescriptor descPrevFrame = WeatherMakerFullScreenEffect.GetRenderTextureDescriptor(downsampling, projSizeInt, 1, format, 0, camera); prevFrameCurrent = WeatherMakerFullScreenEffect.CreateRenderTexture(descPrevFrame, FilterMode.Bilinear, TextureWrapMode.Clamp); prevFrameCurrent.name = "WeatherMakerTemporalReprojectionPrevFrame"; OffsetXConstant = (1.0f / (float)frameWidth); OffsetYConstant = (1.0f / (float)frameHeight); OffsetXConstant2 = (-0.5f * (float)(ReprojectionSize - 1) * OffsetXConstant); OffsetYConstant2 = (-0.5f * (float)(ReprojectionSize - 1) * OffsetYConstant); NeedsFirstFrameHandling = true; } ComputeTemporalOffsets(); }
private RenderTargetIdentifier UpdateDepthDownsampler(ref RenderTexture tex, int scale) { RenderTextureDescriptor desc = WeatherMakerFullScreenEffect.GetRenderTextureDescriptor(scale, 0, 1, RenderTextureFormat.RFloat); if (tex == null || tex.width != desc.width || tex.height != desc.height) { WeatherMakerFullScreenEffect.DestroyRenderTexture(ref tex); tex = WeatherMakerFullScreenEffect.CreateRenderTexture(desc, FilterMode.Point, TextureWrapMode.Clamp); tex.name = "WeatherMakerDepthTexture_" + scale; } return(tex); }