add ambient light shifting based on room lights

This commit is contained in:
Holly Stubbs 2025-03-19 01:19:53 +00:00
parent fb73f9e475
commit bfc3e55c27
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
6 changed files with 190 additions and 14 deletions

View file

@ -8,6 +8,10 @@ background_mode = 1
ambient_light_source = 2
ambient_light_color = Color(1, 1, 1, 1)
sdfgi_use_occlusion = true
fog_mode = 1
fog_light_color = Color(0, 0, 0, 1)
fog_density = 1.0
fog_depth_begin = 1.0
[node name="DynamicMap" type="Node3D"]
script = ExtResource("1_mytgt")

View file

@ -2,7 +2,7 @@
// using UV2 and a normal map and smash em together.
shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx;
render_mode unshaded;
uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_enable;
uniform sampler2D texture_normal : hint_roughness_normal, filter_linear_mipmap, repeat_enable;

View file

@ -422,18 +422,34 @@ var SelectedDoor: Door = null
var UpdateDoorsTimer: float = 0.0
var QuickLoadPercent: int = -1
var RemoteDoorOn: bool = false
var TempLightVolume: float
@onready var Brightness: int = INI.GetInt(Global.options["options"], "brightness")
@onready var CameraFogNear: float = INI.GetFloat(Global.options["options"], "camera fog near")
@onready var CameraFogFar: float = INI.GetFloat(Global.options["options"], "camera fog far")
@onready var worldEnvironment: WorldEnvironment = $WorldEnvironment
@onready var env: Environment = worldEnvironment.environment
func _process(delta: float) -> void:
if not MenuOpen and not InvOpen and OtherOpen == null and SelectedDoor == null and not ConsoleOpen and not Using294 and SelectedScreen == null and EndingTimer >= 0:
#LightVolume = CurveValue(TempLightVolume, LightVolume, 50.0)
LightVolume = Utils.CurveValue(TempLightVolume, LightVolume, 50.0)
if PlayerRoom:
env.fog_depth_begin = CameraFogNear * LightVolume
env.fog_depth_end = CameraFogFar * LightVolume
#CameraFogRange(Camera, CameraFogNear*LightVolume,CameraFogFar*LightVolume)
#CameraFogColor(Camera, 0,0,0)
#CameraFogMode Camera,1
if PlayerRoom:
Global.player.camera.near = 0.05
Global.player.camera.far = max(min(CameraFogFar * LightVolume * 1.5, 28), 0.06)
#CameraRange(Camera, 0.05, Min(CameraFogFar*LightVolume*1.5,28))
#If PlayerRoom\RoomTemplate\Name<>"pocketdimension" Then
#CameraClsColor(Camera, 0,0,0)
#EndIf
if PlayerRoom:
env.ambient_light_energy = Brightness / 255.0
#AmbientLight Brightness, Brightness, Brightness
#PlayerSoundVolume = CurveValue(0.0, PlayerSoundVolume, 5.0)
@ -475,6 +491,149 @@ func _process(delta: float) -> void:
#Use427()
#UpdateMonitorSaving()
var SelectedMap = ""
var PlayerZone = 0
var PlayerRoom: Room = null
func UpdateRooms():
var dist: float
var j: int
var x: float
var z: float
var hide = true
# The reason why it is like this:
# When the map gets spawned by a seed, it starts from LCZ to HCZ to EZ (bottom to top)
# A map loaded by the map creator starts from EZ to HCZ to LCZ (top to bottom) and that's why this little code thing with the (SelectedMap="") needs to be there
# - ENDSHN
if (EntityZ(Global.player) / 8.0) < I_Zone.Transition[1] - int(SelectedMap == ""):
PlayerZone = 2
elif (EntityZ(Global.player) / 8.0) >= I_Zone.Transition[1] - int(SelectedMap == "") and (EntityZ(Global.player) / 8.0) < I_Zone.Transition[0] - int(SelectedMap == ""):
PlayerZone = 1
else:
PlayerZone = 0
TempLightVolume=0
var foundNewPlayerRoom = false
if PlayerRoom != null:
if abs(EntityY(Global.player) - EntityY(PlayerRoom.obj)) < 1.5:
x = abs(PlayerRoom.x - EntityX(Global.player, true))
if x < 4.0:
z = abs(PlayerRoom.z - EntityZ(Global.player, true))
if z < 4.0:
foundNewPlayerRoom = true
if not foundNewPlayerRoom: # it's likely that an adjacent room is the new player room, check for that
for i in range(0, 4):
if PlayerRoom.Adjacent[i] != null:
x = abs(PlayerRoom.Adjacent[i].x - EntityX(Global.player, true))
if x < 4.0:
z = abs(PlayerRoom.Adjacent[i].z - EntityZ(Global.player, true))
if z < 4.0:
foundNewPlayerRoom = true
PlayerRoom = PlayerRoom.Adjacent[i]
break
else:
foundNewPlayerRoom = true # PlayerRoom stays the same when you're high up, or deep down
for r: Room in rooms:
x = abs(r.x - EntityX(Global.player, true))
z = abs(r.z - EntityZ(Global.player, true))
r.dist = max(x, z)
if x < 16 and z < 16:
for i in range(0, Constants.MaxRoomEmitters):
if r.SoundEmitter[i] != null:
dist = EntityDistance(r.SoundEmitterObj[i], Global.player)
# TODO: if dist < r.SoundEmitterRange[i]:
#r.SoundEmitterCHN[i] = LoopSound2(RoomAmbience[r.SoundEmitter[i]], r.SoundEmitterCHN[i], Global.player.camera, r.SoundEmitterObj[i], r.SoundEmitterRange[i])
if (not foundNewPlayerRoom) and (PlayerRoom != r):
if x < 4.0:
if z < 4.0:
if abs(EntityY(Global.player) - EntityY(r.obj)) < 1.5:
PlayerRoom = r
foundNewPlayerRoom = true
hide = false if PlayerRoom == null else true
if PlayerRoom:
if r == PlayerRoom:
hide = false
if hide:
if IsRoomAdjacent(PlayerRoom, r):
hide = false
if hide:
for i in range(0, 4):
if (IsRoomAdjacent(PlayerRoom.Adjacent[i], r)):
hide = false
break
if hide:
r.obj.visible = false
else:
r.obj.visible = true
for i in range(0, Constants.MaxRoomLights):
if r.Lights[i] != null:
dist = EntityDistance(Global.player, r.Lights[i])
if dist < HideDistance:
TempLightVolume = TempLightVolume + r.LightIntensity[i] * r.LightIntensity[i] * ((HideDistance - dist) / HideDistance)
#ShowEntity(r.Lights[i])
else:
break
#if DebugHUD:
#if r.TriggerboxAmount > 0:
#for i in range(0, r.TriggerboxAmount):
#EntityColor r\Triggerbox[i],255,255,0
#EntityAlpha r\Triggerbox[i],0.2
#else:
#if r.TriggerboxAmount > 0:
#for i in range(0, r.TriggerboxAmount):
#EntityColor r\Triggerbox[i],255,255,255
#EntityAlpha r\Triggerbox[i],0.0
#Next
#EndIf
#EndIf
if PlayerRoom:
MapFound[floor(EntityX(PlayerRoom.obj) / 8.0)][floor(EntityZ(PlayerRoom.obj) / 8.0)] = 1
PlayerRoom.found = true
else:
TempLightVolume = 50
TempLightVolume = max(TempLightVolume / 4.5, 1.0)
if PlayerRoom != null:
#EntityAlpha(GetChild(PlayerRoom\obj,2),1)
for i in range(0, 4):
if PlayerRoom.Adjacent[i] != null:
if PlayerRoom.AdjDoor[i] != null:
x = abs(EntityX(Global.player, true) - EntityX(PlayerRoom.AdjDoor[i].frameobj, true))
z = abs(EntityZ(Global.player, true) - EntityZ(PlayerRoom.AdjDoor[i].frameobj, true))
#if PlayerRoom.AdjDoor[i].openstate = 0:
#EntityAlpha(GetChild(PlayerRoom\Adjacent[i]\obj,2),0)
#ElseIf (Not EntityInView(PlayerRoom\AdjDoor[i]\frameobj,Camera))
#EntityAlpha(GetChild(PlayerRoom\Adjacent[i]\obj,2),0)
#Else
#EntityAlpha(GetChild(PlayerRoom\Adjacent[i]\obj,2),1)
#EndIf
#for j in range(0, 4):
#if (PlayerRoom.Adjacent[i].Adjacent[j] != null):
#if (PlayerRoom.Adjacent[i].Adjacent[j] != PlayerRoom):
#EntityAlpha(GetChild(PlayerRoom\Adjacent[i]\Adjacent[j]\obj,2),0)
func IsRoomAdjacent(this: Room, that: Room):
if this == null:
return false
if this == that:
return true
for i in range(0, 4):
if that == this.Adjacent[i]:
return true
return false
var emitters: Array = []
func UpdateEmitters():
# TODO: Particle emitters temp disabled!!

View file

@ -295,7 +295,7 @@ func UpdateEvents():
Global.player.CurrStepSFX = 0
#UpdateRooms()
map.UpdateRooms()
for e: Event in events:
if e.EventName == "exit1":

View file

@ -23,16 +23,21 @@ func GetTextureFromCache(rawFileName:String):
var TRANSPARENT_TEXTURE = load("res://a0.png")
var MISSING_TEXTURE = load("res://missing.png")
var TextureLoadFailed: bool = false
func LoadTexture(rawFileName: String):
var fixedName = rawFileName.replace("\\", "/")
var fileName = Utils.GetCaseiFileName(str("" if rawFileName.contains("res://") else "res://", fixedName))
if fileName == null:
TextureLoadFailed = true
return MISSING_TEXTURE
elif fileName.contains("<null>"):
TextureLoadFailed = true
return MISSING_TEXTURE
var loadedTexture = load(fileName)
textureCache.get_or_add(fixedName, loadedTexture)
TextureLoadFailed = false
return loadedTexture
func GetTextureSafe(rawFileName: String):

View file

@ -88,6 +88,7 @@ static func LoadRMesh(file: String, rt: RoomTemplate):
var activeAlbedo: Texture2D = null
var activeAlbedoHasAlpha = false
var activeBump: Texture2D = null
var hasNoLightmap = false
for i1 in range(count): # drawn mesh
childMesh = Mesh.new()
@ -116,8 +117,12 @@ static func LoadRMesh(file: String, rt: RoomTemplate):
if tex[j2] == null: # texture is not in cache
if blendType < 3:
tex[j2] = Global.LoadTexture(str(file, textureName))
if j2 == 0:
hasNoLightmap = Global.TextureLoadFailed
else:
tex[j2] = Global.LoadTexture(str(file, textureName)) # TODO: load with alpha
if j2 == 0:
hasNoLightmap = Global.TextureLoadFailed
#if tex[j2] != null:
##if blendType == 1:
@ -267,17 +272,20 @@ static func LoadRMesh(file: String, rt: RoomTemplate):
var meshInstance = MeshInstance3D.new()
arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arr)
meshInstance.mesh = arr_mesh
#var mat = StandardMaterial3D.new()
#mat.albedo_color = Color(randi() % 255 / 255.0, randi() % 255 / 255.0, randi() % 255 / 255.0)
#mat.albedo_texture = activeAlbedo
#mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA_DEPTH_PRE_PASS if activeAlbedoHasAlpha else BaseMaterial3D.TRANSPARENCY_DISABLED
var mat = ShaderMaterial.new()
mat.shader = surfaceShader
mat.set_shader_parameter("texture_albedo", activeAlbedo)
if texBump[1] != null:
mat.set_shader_parameter("texture_normal", texBump[1])
mat.set_shader_parameter("texture_lightmap", tex[0])
meshInstance.set_surface_override_material(0, mat)
if hasNoLightmap:
var mat = StandardMaterial3D.new()
#mat.albedo_color = Color(randi() % 255 / 255.0, randi() % 255 / 255.0, randi() % 255 / 255.0)
mat.albedo_texture = activeAlbedo
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA_DEPTH_PRE_PASS if activeAlbedoHasAlpha else BaseMaterial3D.TRANSPARENCY_DISABLED
meshInstance.set_surface_override_material(0, mat)
else:
var mat = ShaderMaterial.new()
mat.shader = surfaceShader
mat.set_shader_parameter("texture_albedo", activeAlbedo)
if texBump[1] != null:
mat.set_shader_parameter("texture_normal", texBump[1])
mat.set_shader_parameter("texture_lightmap", tex[0])
meshInstance.set_surface_override_material(0, mat)
meshInstance.create_trimesh_collision()
meshInstance.get_child(0).set_meta("texName", textureName)
scene.add_child(meshInstance)