test.gd 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. extends Node3D
  2. enum GIMode {
  3. NONE,
  4. LIGHTMAP_GI_ALL,
  5. LIGHTMAP_GI_INDIRECT,
  6. VOXEL_GI,
  7. SDFGI,
  8. MAX, # Maximum value of the enum, used internally.
  9. }
  10. # Keep this in sync with the GIMode enum (except for MAX).
  11. const GI_MODE_TEXTS = [
  12. "Environment Lighting (Fastest)",
  13. "Baked Lightmap All (Fast)",
  14. "Baked Lightmap Indirect (Average)",
  15. "VoxelGI (Slow)",
  16. "SDFGI (Slow)",
  17. ]
  18. enum ReflectionProbeMode {
  19. NONE,
  20. ONCE,
  21. ALWAYS,
  22. MAX,
  23. }
  24. # Keep this in sync with the ReflectionProbeMode enum (except for MAX).
  25. const REFLECTION_PROBE_MODE_TEXTS = [
  26. "Disabled - Using environment, VoxelGI or SDFGI reflections (Fast)",
  27. "Enabled - \"Once\" Update Mode (Average)",
  28. "Enabled - \"Always\" Update Mode (Slow)",
  29. ]
  30. enum SSILMode {
  31. NONE,
  32. SSAO,
  33. SSIL,
  34. SSAO_AND_SSIL,
  35. MAX, # Maximum value of the enum, used internally.
  36. }
  37. # Keep this in sync with the SSILMode enum (except for MAX).
  38. const SSIL_MODE_TEXTS = [
  39. "Disabled (Fastest)",
  40. "Screen-space ambient occlusion (Fast)",
  41. "Screen-space indirect lighting (Average)",
  42. "SSAO + SSIL (Slow)",
  43. ]
  44. var gi_mode = GIMode.NONE
  45. var reflection_probe_mode = ReflectionProbeMode.NONE
  46. var ssil_mode = SSILMode.NONE
  47. @onready var environment = $WorldEnvironment.environment
  48. @onready var gi_mode_label = $GIMode
  49. @onready var reflection_probe_mode_label = $ReflectionProbeMode
  50. @onready var reflection_probe = $Camera/ReflectiveSphere/ReflectionProbe
  51. @onready var ssil_mode_label = $SSILMode
  52. # Several copies of the level mesh are required to cycle between different GI modes.
  53. @onready var zdm2_no_lightmap = $Zdm2NoLightmap
  54. @onready var zdm2_lightmap_all = $Zdm2LightmapAll
  55. @onready var zdm2_lightmap_indirect = $Zdm2LightmapIndirect
  56. func _ready():
  57. set_gi_mode(gi_mode)
  58. set_reflection_probe_mode(reflection_probe_mode)
  59. set_ssil_mode(ssil_mode)
  60. func _input(event):
  61. if event.is_action_pressed("cycle_gi_mode"):
  62. set_gi_mode(wrapi(gi_mode + 1, 0, GIMode.MAX))
  63. if event.is_action_pressed("cycle_reflection_probe_mode"):
  64. set_reflection_probe_mode(wrapi(reflection_probe_mode + 1, 0, ReflectionProbeMode.MAX))
  65. if event.is_action_pressed("cycle_ssil_mode"):
  66. set_ssil_mode(wrapi(ssil_mode + 1, 0, SSILMode.MAX))
  67. func set_gi_mode(p_gi_mode):
  68. gi_mode = p_gi_mode
  69. gi_mode_label.text = "Global illumination: %s " % GI_MODE_TEXTS[gi_mode]
  70. match p_gi_mode:
  71. GIMode.NONE:
  72. $Zdm2NoLightmap.visible = true
  73. $Zdm2LightmapAll.visible = false
  74. $Zdm2LightmapIndirect.visible = false
  75. # Halve sky contribution to prevent shaded areas from looking too bright and blue.
  76. environment.ambient_light_sky_contribution = 0.5
  77. $LightmapGIIndirect.visible = false
  78. $LightmapGIAll.visible = false
  79. $VoxelGI.visible = false
  80. environment.sdfgi_enabled = false
  81. # There is no difference between Indirect and Disabled when no GI is used.
  82. # Pick the default value (which is Indirect).
  83. $Sun.light_bake_mode = Light3D.BAKE_DYNAMIC
  84. $GrateOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
  85. $GarageOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
  86. $CornerSpotLight.light_bake_mode = Light3D.BAKE_DYNAMIC
  87. GIMode.LIGHTMAP_GI_ALL:
  88. $Zdm2NoLightmap.visible = false
  89. $Zdm2LightmapAll.visible = true
  90. $Zdm2LightmapIndirect.visible = false
  91. # Halve sky contribution to prevent dynamic objects from looking too bright and blue.
  92. # (When using lightmaps, this property doesn't affect lightmapped surfaces.)
  93. environment.ambient_light_sky_contribution = 0.5
  94. $LightmapGIIndirect.visible = false
  95. $LightmapGIAll.visible = true
  96. $VoxelGI.visible = false
  97. environment.sdfgi_enabled = false
  98. # Make lights not affect baked surfaces by setting their bake mode to All.
  99. $Sun.light_bake_mode = Light3D.BAKE_STATIC
  100. $GrateOmniLight.light_bake_mode = Light3D.BAKE_STATIC
  101. $GarageOmniLight.light_bake_mode = Light3D.BAKE_STATIC
  102. $CornerSpotLight.light_bake_mode = Light3D.BAKE_STATIC
  103. GIMode.LIGHTMAP_GI_INDIRECT:
  104. $Zdm2NoLightmap.visible = false
  105. $Zdm2LightmapAll.visible = false
  106. $Zdm2LightmapIndirect.visible = true
  107. # Halve sky contribution to prevent dynamic objects from looking too bright and blue.
  108. # (When using lightmaps, this property doesn't affect lightmapped surfaces.)
  109. environment.ambient_light_sky_contribution = 0.5
  110. $LightmapGIIndirect.visible = true
  111. $LightmapGIAll.visible = false
  112. $VoxelGI.visible = false
  113. environment.sdfgi_enabled = false
  114. $Sun.light_bake_mode = Light3D.BAKE_DYNAMIC
  115. $GrateOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
  116. $GarageOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
  117. $CornerSpotLight.light_bake_mode = Light3D.BAKE_DYNAMIC
  118. GIMode.VOXEL_GI:
  119. $Zdm2NoLightmap.visible = true
  120. $Zdm2LightmapAll.visible = false
  121. $Zdm2LightmapIndirect.visible = false
  122. environment.ambient_light_sky_contribution = 1.0
  123. $LightmapGIIndirect.visible = false
  124. $LightmapGIAll.visible = false
  125. $VoxelGI.visible = true
  126. environment.sdfgi_enabled = false
  127. # Bake mode must be Indirect, not Disabled. Otherwise, GI will
  128. # not be visible for those lights.
  129. $Sun.light_bake_mode = Light3D.BAKE_DYNAMIC
  130. $GrateOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
  131. $GarageOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
  132. $CornerSpotLight.light_bake_mode = Light3D.BAKE_DYNAMIC
  133. GIMode.SDFGI:
  134. $Zdm2NoLightmap.visible = true
  135. $Zdm2LightmapAll.visible = false
  136. $Zdm2LightmapIndirect.visible = false
  137. environment.ambient_light_sky_contribution = 1.0
  138. $LightmapGIIndirect.visible = false
  139. $LightmapGIAll.visible = false
  140. $VoxelGI.visible = false
  141. environment.sdfgi_enabled = true
  142. # Bake mode must be Indirect, not Disabled. Otherwise, GI will
  143. # not be visible for those lights.
  144. $Sun.light_bake_mode = Light3D.BAKE_DYNAMIC
  145. $GrateOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
  146. $GarageOmniLight.light_bake_mode = Light3D.BAKE_DYNAMIC
  147. $CornerSpotLight.light_bake_mode = Light3D.BAKE_DYNAMIC
  148. func set_reflection_probe_mode(p_reflection_probe_mode):
  149. reflection_probe_mode = p_reflection_probe_mode
  150. reflection_probe_mode_label.text = "Reflection probe: %s " % REFLECTION_PROBE_MODE_TEXTS[reflection_probe_mode]
  151. match p_reflection_probe_mode:
  152. ReflectionProbeMode.NONE:
  153. reflection_probe.visible = false
  154. reflection_probe.update_mode = ReflectionProbe.UPDATE_ONCE
  155. ReflectionProbeMode.ONCE:
  156. reflection_probe.visible = true
  157. reflection_probe.update_mode = ReflectionProbe.UPDATE_ONCE
  158. ReflectionProbeMode.ALWAYS:
  159. reflection_probe.visible = true
  160. reflection_probe.update_mode = ReflectionProbe.UPDATE_ALWAYS
  161. func set_ssil_mode(p_ssil_mode):
  162. ssil_mode = p_ssil_mode
  163. ssil_mode_label.text = "Screen-space lighting effects: %s " % SSIL_MODE_TEXTS[ssil_mode]
  164. match p_ssil_mode:
  165. SSILMode.NONE:
  166. environment.ssao_enabled = false
  167. environment.ssil_enabled = false
  168. SSILMode.SSAO:
  169. environment.ssao_enabled = true
  170. environment.ssil_enabled = false
  171. SSILMode.SSIL:
  172. environment.ssao_enabled = false
  173. environment.ssil_enabled = true
  174. SSILMode.SSAO_AND_SSIL:
  175. environment.ssao_enabled = true
  176. environment.ssil_enabled = true