Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / PostProcessingController.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Rendering.PostProcessing;
  5. public class PostProcessingController : MonoBehaviour
  6. {
  7. PostProcessVolume ppv;
  8. Bloom bloom;
  9. Grain grain;
  10. ColorGrading colorGrading;
  11. LensDistortion lensDistortion;
  12. Vignette vignette;
  13. DepthOfField depthOfField;
  14. PlayerController playerController;
  15. [SerializeField] private float maxDistance;
  16. private List<float> originalValues;
  17. void Start()
  18. {
  19. ppv = GetComponent<PostProcessVolume>();
  20. ppv.profile.TryGetSettings(out bloom);
  21. ppv.profile.TryGetSettings(out grain);
  22. ppv.profile.TryGetSettings(out colorGrading);
  23. ppv.profile.TryGetSettings(out vignette);
  24. ppv.profile.TryGetSettings(out depthOfField);
  25. ppv.profile.TryGetSettings(out lensDistortion);
  26. playerController = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
  27. }
  28. void Update()
  29. {
  30. UpdatePostProcessing(Vector3.Distance(playerController.transpassedCoordinate, playerController.transform.position));
  31. }
  32. public void UpdatePostProcessing(float distance)
  33. {
  34. if (playerController.transpassedCoordinate != Vector3.zero)
  35. {
  36. if (distance < maxDistance)
  37. {
  38. bloom.dirtIntensity.value = 30 * distance / maxDistance;
  39. grain.intensity.value = 1 * distance / maxDistance;
  40. lensDistortion.intensity.value = 40 * distance / maxDistance;
  41. vignette.intensity.value = 0.7f * distance / maxDistance;
  42. if (depthOfField.focusDistance.value <= 10 && distance != 0)
  43. depthOfField.focusDistance.value = maxDistance / distance;
  44. else depthOfField.focusDistance.value = 10;
  45. }
  46. }
  47. }
  48. }