private void UpdateParameters() { // update raytracing scene, in case something moved _rtas.Update(); // frustum corners for current camera transform Vector3 bottomLeft = _camera.ViewportToWorldPoint(new Vector3(0, 0, _camera.farClipPlane)).normalized; Vector3 topLeft = _camera.ViewportToWorldPoint(new Vector3(0, 1, _camera.farClipPlane)).normalized; Vector3 bottomRight = _camera.ViewportToWorldPoint(new Vector3(1, 0, _camera.farClipPlane)).normalized; Vector3 topRight = _camera.ViewportToWorldPoint(new Vector3(1, 1, _camera.farClipPlane)).normalized; // update camera, environment parameters _rayTracingShader.SetVector("_SkyColor", SkyColor.gamma); _rayTracingShader.SetVector("_GroundColor", GroundColor.gamma); _rayTracingShader.SetVector("_TopLeftFrustumDir", topLeft); _rayTracingShader.SetVector("_TopRightFrustumDir", topRight); _rayTracingShader.SetVector("_BottomLeftFrustumDir", bottomLeft); _rayTracingShader.SetVector("_BottomRightFrustumDir", bottomRight); _rayTracingShader.SetVector("_CameraPos", _camera.transform.position); _cameraWorldMatrix = _camera.transform.localToWorldMatrix; // reset accumulation frame counter _frameIndex = 0; }
private void OnRenderImage(RenderTexture source, RenderTexture destination) { CheckNulls(); CheckRenderTexture(); SetShaderProperties(); _RTAS.Update(); shader.Dispatch("RayGen", cam.pixelWidth / (int)resolution, cam.pixelHeight / (int)resolution, 1, cam); Graphics.Blit(source, destination); }
void Reset() { _AccelerationStructure.Update(); PathTracingShader.SetVector("_AmbientColor", AmbientColor.gamma); Matrix4x4 frustum = Matrix4x4.identity; frustum.SetRow(0, _Camera.ViewportToWorldPoint(new Vector3(0, 1, _Camera.farClipPlane)).normalized); frustum.SetRow(1, _Camera.ViewportToWorldPoint(new Vector3(1, 1, _Camera.farClipPlane)).normalized); frustum.SetRow(2, _Camera.ViewportToWorldPoint(new Vector3(0, 0, _Camera.farClipPlane)).normalized); frustum.SetRow(3, _Camera.ViewportToWorldPoint(new Vector3(1, 0, _Camera.farClipPlane)).normalized); PathTracingShader.SetMatrix("_Frustum", frustum); PathTracingShader.SetVector("_WorldSpaceCameraPos", _Camera.transform.position); _ModelMatrix = _Camera.transform.localToWorldMatrix; _Frame = 0; }