Exemple #1
0
		private void DoRayTracingOutline(CustomPassContext ctx)
		{
			ctx.cmd.SetRayTracingShaderPass(rayTracingOutlineShader, "JTRPRayTracingOutline");
			if (ShaderConfig.s_CameraRelativeRendering != 0)
				_outlineRAS.Build(ctx.hdCamera.camera.transform.position);
			else
				_outlineRAS.Build();
			if (outlineRenderers != null)
				foreach (var renderer in outlineRenderers)
					if (renderer != null)
						_outlineRAS.UpdateInstanceTransform(renderer);
			ctx.cmd.SetRayTracingAccelerationStructure(rayTracingOutlineShader, "_RaytracingAccelerationStructure",
													   _outlineRAS);
			ctx.cmd.SetRayTracingTextureParam(rayTracingOutlineShader, "RenderTarget", ctx.cameraColorBuffer);
			ctx.cmd.SetRayTracingTextureParam(rayTracingOutlineShader, "_DepthTexture", ctx.cameraDepthBuffer);
			ctx.cmd.SetRayTracingTextureParam(rayTracingOutlineShader, "_OutlineMask", _outlineMask);
			ctx.cmd.DispatchRays(rayTracingOutlineShader, "RayTracingOutlineRaygen",
								 (uint)ctx.cameraColorBuffer.rt.width,
								 (uint)ctx.cameraColorBuffer.rt.height, 1);
		}
Exemple #2
0
    public void Update()
    {
        // if loading world is not enabled, build AS and return
        if (!Settings.Instance.loadWorld)
        {
            if (_accelerationStructure != null)
            {
                _accelerationStructure.UpdateInstanceTransform(sun.GetComponent <Renderer>());
                _accelerationStructure.Build();
            }

            return;
        }

        _radius = Settings.Instance.WorldRadius;

        if (runningJobs > 0)
        {
            runningJobs = 0;
            JobHandle.CompleteAll(_jobHandles);
        }
        if (_jobHandlesAlocated)
        {
            _jobHandles.Dispose();
        }
        _jobHandles         = new NativeList <JobHandle>(Allocator.Persistent);
        _jobHandlesAlocated = true;

        // If camera moved to another chunk, generate new chunks in multiple phases
        Vector3Int chunkWherePlayerStands = ChunkWherePlayerStands();

        if ((!chunkWherePlayerStands.Equals(_chunkWherePlayerStood) || _prevRadius != _radius) && phase == Phase.Resting)
        {
            _chunkWherePlayerStood = chunkWherePlayerStands;

            int radiusInChunks = _chunkSize * _radius;
            FindMissingChunks(chunkWherePlayerStands, radiusInChunks);

            if (_toGenerate.Count > 0)
            {
                _iter = _toGenerate.Count - 1;
                phase = Phase.GeneratingBlocks;
            }
            else if (_prevRadius != _radius)
            {
                phase = Phase.RemovingChunks;
            }
            else
            {
                phase = Phase.Resting;
            }

            _prevRadius = _radius;
        }
        else if (phase == Phase.GeneratingBlocks)
        {
            for (; _iter >= 0 && runningJobs < _maxJobsAtOnce * 5; _iter--)
            {
                _jobHandles.Add(_toGenerate[_iter].GenerateBlocks(centroids));
                runningJobs++;
            }

            if (_iter < 0)
            {
                phase = Phase.GeneratingMeshData;
                _iter = _toGenerate.Count - 1;
            }
        }
        else if (phase == Phase.GeneratingMeshData)
        {
            for (; _iter >= 0 && runningJobs <= _maxJobsAtOnce * 4; _iter--)
            {
                if (!_toGenerate[_iter].IsEmpty())
                {
                    _jobHandles.Add(_toGenerate[_iter].GenerateMeshData());
                    _toGenerate[_iter].PrepareMesh();
                    runningJobs++;
                }
            }

            if (_iter < 0)
            {
                phase = Phase.GeneratingFlora;
                _iter = _toGenerate.Count - 1;
            }
        }
        else if (phase == Phase.GeneratingFlora)
        {
            for (; _iter >= 0 && runningJobs <= _maxJobsAtOnce * 4; _iter--)
            {
                if (_toGenerate[_iter].AreTrees())
                {
                    _jobHandles.Add(_toGenerate[_iter].GenerateTrees());
                    runningJobs++;
                }
            }

            if (_iter < 0)
            {
                phase = Phase.FillingMeshes;
                _iter = _toGenerate.Count - 1;
            }
        }
        else if (phase == Phase.FillingMeshes)
        {
            int runningFinishes = 0;

            for (; _iter >= 0 && runningFinishes < 2; _iter--)
            {
                if (!_toGenerate[_iter].IsEmpty())
                {
                    runningFinishes += _toGenerate[_iter].FinishCreatingChunk();
                    _accelerationStructure.AddInstance(_toGenerate[_iter].chunk.GetComponent <Renderer>(), null, null, true, false, 0x01);
                }
            }

            if (_iter < 0)
            {
                phase = Phase.RemovingChunks;
                _toGenerate.Clear();
            }
        }
        else if (phase == Phase.RemovingChunks)
        {
            int radiusInChunks = _chunkSize * _radius;
            RemoveChunks(chunkWherePlayerStands, radiusInChunks);
            phase = Phase.Resting;
        }
        else
        {
            phase = Phase.Resting;
        }

        // Update sun transform and build AS
        if (_accelerationStructure != null)
        {
            _accelerationStructure.UpdateInstanceTransform(sun.GetComponent <Renderer>());
            _accelerationStructure.Build();
        }

        if (phase == Phase.Resting)
        {
            Settings.Instance.reprojectWithIDs = true;
        }
        else
        {
            Settings.Instance.reprojectWithIDs = false;
        }
    }