void DispatchRays() { // update frame index and start path tracer _rayTracingShader.SetInt("_FrameIndex", _frameIndex); _rayTracingShader.SetShaderPass("DxrPass"); // // using e.g. ForwardDXR here will require binding all variables correctly, e.g. _EnvLightDatasRT // _rayTracingShader.SetShaderPass("ForwardDXR"); // var lightCluster = HDRenderPipeline.currentPipeline.RequestLightCluster(); // Shader.SetGlobalBuffer(HDShaderIDs._RaytracingLightCluster, lightCluster.GetCluster()); // Shader.SetGlobalBuffer(HDShaderIDs._LightDatasRT, lightCluster.GetLightDatas()); // Shader.SetGlobalBuffer(HDShaderIDs._EnvLightDatasRT, lightCluster.GetEnvLightDatas()); _rayTracingShader.SetFloat("_JitterAmount", resultTexture == ResultTexture.DxrTarget ? 0 : 1); _rayTracingShader.SetBool("_UseLensData", lensRenderer && lensRenderer.isActiveAndEnabled); if (lensRenderer) { _rayTracingShader.SetMatrix("_DataProviderTransform", lensRenderer.transform.localToWorldMatrix); _rayTracingShader.SetTexture("_PositionData", lensRenderer.lensPositionTex); _rayTracingShader.SetTexture("_DirectionData", lensRenderer.lensDirectionTex); } else { _rayTracingShader.SetTexture("_PositionData", Texture2D.whiteTexture); _rayTracingShader.SetTexture("_DirectionData", Texture2D.whiteTexture); } // start one thread for each pixel on screen _rayTracingShader.Dispatch("MyRaygenShader", _dxrTarget.width, _dxrTarget.height, 1, _camera); // update accumulation material _accumulationMaterial.SetTexture("_CurrentFrame", _dxrTarget); _accumulationMaterial.SetTexture("_Accumulation", _accumulationTarget1); _accumulationMaterial.SetInt("_FrameIndex", _frameIndex++); // accumulate current raytracing result Graphics.Blit(_dxrTarget, _accumulationTarget2, _accumulationMaterial); // switch accumulate textures var temp = _accumulationTarget1; _accumulationTarget1 = _accumulationTarget2; _accumulationTarget2 = temp; // // apply DLSS to the _dxrTarget // var cmd = new CommandBuffer(); // var initData = new DLSSCommandInitializationData() // { // featureFlags = DLSSFeatureFlags.DoSharpening, // inputRTHeight = (uint)_dxrTarget.height, // inputRTWidth = (uint)_dxrTarget.width, // outputRTWidth = (uint)(2 * _dxrTarget.width), // outputRTHeight = (uint)(2 * _dxrTarget.height), // quality = DLSSQuality.MaximumPerformance // }; // // var context = _nvidiaDevice.CreateFeature(cmd, initData); // var textureTable = new DLSSTextureTable() // { // colorInput = _dxrTarget, // colorOutput = null, // depth = null, // motionVectors = null, // }; // _nvidiaDevice.ExecuteDLSS(cmd, context, new DLSSTextureTable()); GetComponent <MeshRenderer>().sharedMaterial.mainTexture = resultTexture == ResultTexture.DxrTarget ? _dxrTarget : _accumulationTarget1; }