From 206b67ebbd576d360367a3dfb4472a9d95b198d6 Mon Sep 17 00:00:00 2001 From: Holly Date: Wed, 19 Mar 2025 23:51:30 +0000 Subject: [PATCH] fog and lights --- src/DynamicMap.gd | 157 ++++++++++++++++++++++++++++--- src/LoadWorld.gd | 1 + src/Player.gd | 4 +- src/file_parsers/RMesh.gd | 35 +++---- src/objects/LightTemplate.gd | 16 ++++ src/objects/LightTemplate.gd.uid | 1 + 6 files changed, 181 insertions(+), 33 deletions(-) create mode 100644 src/objects/LightTemplate.gd create mode 100644 src/objects/LightTemplate.gd.uid diff --git a/src/DynamicMap.gd b/src/DynamicMap.gd index cfd1f14..4c6799a 100644 --- a/src/DynamicMap.gd +++ b/src/DynamicMap.gd @@ -435,6 +435,7 @@ 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 = Utils.CurveValue(TempLightVolume, LightVolume, 50.0) if PlayerRoom: + env.fog_enabled = true env.fog_depth_begin = CameraFogNear * LightVolume env.fog_depth_end = CameraFogFar * LightVolume #CameraFogRange(Camera, CameraFogNear*LightVolume,CameraFogFar*LightVolume) @@ -442,7 +443,7 @@ func _process(delta: float) -> void: #CameraFogMode Camera,1 if PlayerRoom: Global.player.camera.near = 0.05 - Global.player.camera.far = max(min(CameraFogFar * LightVolume * 1.5, 28), 0.06) + Global.player.camera.far = max(min(CameraFogFar * LightVolume * 1.5, 28), 0.06) * 100 #CameraRange(Camera, 0.05, Min(CameraFogFar*LightVolume*1.5,28)) #If PlayerRoom\RoomTemplate\Name<>"pocketdimension" Then #CameraClsColor(Camera, 0,0,0) @@ -554,6 +555,7 @@ func UpdateRooms(): if z < 4.0: if abs(EntityY(Global.player) - EntityY(r.obj)) < 1.5: PlayerRoom = r + print(r) foundNewPlayerRoom = true hide = false if PlayerRoom == null else true @@ -834,6 +836,23 @@ var Step2SFX = Utils.Init1DArray(6) var eventSystem: EventSystem +var lightTemplates: Array[LightTemplate] + +func AddTempLight(rt: RoomTemplate, x: float, y: float, z: float, ltype: int, range: float, r: int, g: int, b: int) -> LightTemplate: + var lt: LightTemplate = LightTemplate.new() + lightTemplates.push_back(lt) + lt.roomtemplate = rt + lt.x = x + lt.y = y + lt.z = z + lt.ltype = ltype + lt.range = range + lt.r = r + lt.g = g + lt.b = b + + return lt + func _ready() -> void: # 0 = light containment, 1 = heavy containment, 2 = entrance AmbientSFXAmount[0] = 8 @@ -4635,19 +4654,15 @@ func FillRoom(r:Room): #PositionEntity r\Levers[0],r\x+205.0*RoomScale,r\y+200.0*RoomScale,r\z+2287.0*RoomScale #EntityParent r\Levers[0],r\obj #;[End Block] - # - #For lt.lighttemplates = Each LightTemplates - #If lt\roomtemplate = r\RoomTemplate Then - #newlt = AddLight(r, r\x+lt\x, r\y+lt\y, r\z+lt\z, lt\ltype, lt\range, lt\r, lt\g, lt\b) - #If newlt <> 0 Then - #If lt\ltype = 3 Then - #LightConeAngles(newlt, lt\innerconeangle, lt\outerconeangle) - #RotateEntity(newlt, lt\pitch, lt\yaw, 0) - #EndIf - #EndIf - #EndIf - #Next - # + + for lt: LightTemplate in lightTemplates: + if lt.roomtemplate == r.RoomTemplate: + var newlt = AddLight(r, r.x + lt.x, r.y + lt.y, r.z + lt.z, lt.ltype, lt.range, lt.r, lt.g, lt.b) + if newlt != null: + if lt.ltype == 3: + # TODO: LightConeAngles(newlt, lt.innerconeangle, lt.outerconeangle) + RotateEntity(newlt, lt.pitch, lt.yaw, 0) + #For ts.tempscreens = Each TempScreens #If ts\roomtemplate = r\RoomTemplate Then #CreateScreen(r\x+ts\x, r\y+ts\y, r\z+ts\z, ts\imgpath, r) @@ -4683,6 +4698,118 @@ func FillRoom(r:Room): # #CatchErrors("FillRoom ("+r\RoomTemplate\Name+")") +func CreateLight(ltype: int): + var light: Light3D + if ltype == 1: + light = DirectionalLight3D.new() + elif ltype == 1: + light = OmniLight3D.new() + elif ltype == 2: + light = SpotLight3D.new() + else: + light = DirectionalLight3D.new() + + return light + +var LightSpriteTex = Utils.Init1DArray(10) + +func AddLight(room: Room, x: float, y: float, z: float, ltype: int, range: float, r: int, g: int, b: int): + if room != null: + for i in range(0, Constants.MaxRoomLights): + if room.Lights[i] == null: + room.Lights[i] = CreateLight(ltype) + #room\LightDist[i] = range + LightRange(room.Lights[i], range) + LightColor(room.Lights[i], r, g, b) + EntityParent(room.Lights[i], room.obj) + PositionEntity(room.Lights[i], x, y, z, true) + + room.LightIntensity[i] = (r + g + b) / 255.0 / 3.0 + + room.LightSprites[i] = CreateSprite() + ScaleSprite(room.LightSprites[i], 0.13 , 0.13) + EntityTexture(room.LightSprites[i], LightSpriteTex[0]) + # TODO: EntityBlend (room\LightSprites[i], 3) + EntityParent(room.LightSprites[i], room.obj) + PositionEntity(room.LightSprites[i], x, y, z) + + room.LightSpritesPivot[i] = CreatePivot() + #EntityRadius room.LightSpritesPivot[i],0.05 + EntityParent(room.LightSpritesPivot[i], room.obj) + PositionEntity(room.LightSpritesPivot[i], x, y, z) + + room.LightSprites2[i] = CreateSprite() + EntityParent(room.LightSprites2[i], room.obj) + PositionEntity(room.LightSprites2[i], x, y, z) + ScaleSprite(room.LightSprites2[i], 0.6, 0.6) + EntityTexture(room.LightSprites2[i], LightSpriteTex[2]) + #EntityBlend(room.LightSprites2[i], 3) + #EntityOrder(room.LightSprites2[i], -1) + EntityColor(room.LightSprites2[i], r, g, b) + #EntityFX(room.LightSprites2[i],1) + RotateEntity(room.LightSprites2[i], 0, 0, randi_range(0, 360)) + SpriteViewMode(room.LightSprites2[i], 1) + room.LightSpriteHidden[i] = true + room.LightSprites2[i].visible = false + #HideEntity room\LightSprites2[i] + room.LightFlicker[i] = randi_range(1, 10) + + room.LightR[i] = r + room.LightG[i] = g + room.LightB[i] = b + + room.Lights[i].visible = false + #HideEntity room.Lights[i] + + room.MaxLights = room.MaxLights + 1 + + return room.Lights[i] + else: + var light = CreateLight(ltype) + EntityParent(light, room.obj) + LightRange(light, range) + LightColor(light, r, g, b) + PositionEntity(light, x, y, z, true) + var sprite = CreateSprite() + PositionEntity(sprite, x, y, z) + ScaleSprite(sprite, 0.13 , 0.13) + EntityTexture(sprite, LightSpriteTex[0]) + # TODO: EntityBlend (sprite, 3) + return light + +func SpriteViewMode(sprite: Sprite3D, mode: int): + if mode == 1: + sprite.billboard = BaseMaterial3D.BILLBOARD_ENABLED + elif mode == 2: + sprite.billboard = BaseMaterial3D.BILLBOARD_DISABLED + elif mode == 3: + sprite.billboard = BaseMaterial3D.BILLBOARD_ENABLED + elif mode == 4: + sprite.billboard = BaseMaterial3D.BILLBOARD_FIXED_Y + else: + sprite.billboard = BaseMaterial3D.BILLBOARD_ENABLED + +func CreateSprite(): + return Sprite3D.new() + +func CreatePivot(): + return Node3D.new() + +func EntityColor(sprite: Sprite3D, r: int, g: int, b: int): + sprite.modulate = Color8(r, g, b) + +func EntityTexture(sprite: Sprite3D, tex): + sprite.texture = tex + +func LightColor(light: Light3D, r: int, g: int, b: int): + light.light_color = Color8(r, g, b) + +func LightRange(light: Light3D, range: float): + if light is OmniLight3D: + light.omni_range = range + elif light is SpotLight3D: + light.spot_range = range + func LoadRoomTemplates(file: String): var TemporaryString: String var i: int @@ -4827,7 +4954,7 @@ var loadedRoomMeshes: int = 0 func LoadRoomMesh(rt: RoomTemplate): var path = Utils.GetCaseiFileName(str("res://", rt.objPath.replace("\\", "/"))).replace("res://", "") if rt.objPath.contains(".rmesh"): # file is roommesh - rt.obj = RMesh.LoadRMesh(path, rt) + rt.obj = RMesh.LoadRMesh(path, rt, self) # TODO: Implement b3d maps, not pressing as newer vers use exclusively rmesh #else: #file is b3d #If rt\objPath <> "" Then rt\obj = LoadWorld(rt\objPath, rt) Else rt\obj = CreatePivot() diff --git a/src/LoadWorld.gd b/src/LoadWorld.gd index 073b458..0afc765 100644 --- a/src/LoadWorld.gd +++ b/src/LoadWorld.gd @@ -21,6 +21,7 @@ var frameDelay = 1 func _process(delta: float) -> void: if loadStage == 0 and frameDelay == 0: LoadAllSounds.Go(map) + map.LoadRoomTemplates("Data/rooms.ini") diff --git a/src/Player.gd b/src/Player.gd index 935625a..c14a5cd 100644 --- a/src/Player.gd +++ b/src/Player.gd @@ -248,7 +248,7 @@ func _process(delta: float) -> void: if not UnableToMove: Shake = fmod((Shake + Global.FPSfactor * min(Sprint, 1.5) * 7), 720) if shake < 180 and fmod(Shake, 360) >= 180 and KillTimer >= 0: - print("step sound") + print("step sound " + str(shake)) if CurrStepSFX == 0: var temp = GetStepSound() if Sprint == 1.0: @@ -383,7 +383,7 @@ func _process(delta: float) -> void: Global.PlayTempSound(map.StepSFX[0][0][randi_range(0, 7)]) Global.PlayerSoundVolume = max(3.0, Global.PlayerSoundVolume) DropSpeed = 0 - else: + elif not is_on_floor(): DropSpeed = min(max(DropSpeed - 0.006 * Global.FPSfactor, -2.0), 0.0) if PlayerFallingPickDistance != 0: floorPick.target_position.y = -PlayerFallingPickDistance diff --git a/src/file_parsers/RMesh.gd b/src/file_parsers/RMesh.gd index e109c87..58a7dd3 100644 --- a/src/file_parsers/RMesh.gd +++ b/src/file_parsers/RMesh.gd @@ -10,7 +10,7 @@ static var RMESH_LOAD_COUNT = 0 const surfaceShader = preload("res://shaders/LightmapSurface.gdshader") -static func LoadRMesh(file: String, rt: RoomTemplate): +static func LoadRMesh(file: String, rt: RoomTemplate, map: DynamicMap): var correctedPath = file.replace("\\", "/") var fileName = correctedPath.split("/")[-1] @@ -90,6 +90,8 @@ static func LoadRMesh(file: String, rt: RoomTemplate): var activeBump: Texture2D = null var hasNoLightmap = false + var lightTemplates: Array[LightTemplate] + for i1 in range(count): # drawn mesh childMesh = Mesh.new() var vertices = PackedVector3Array() @@ -277,6 +279,7 @@ static func LoadRMesh(file: String, rt: RoomTemplate): #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 + mat.shading_mode = BaseMaterial3D.SHADING_MODE_PER_VERTEX meshInstance.set_surface_override_material(0, mat) else: var mat = ShaderMaterial.new() @@ -340,6 +343,8 @@ static func LoadRMesh(file: String, rt: RoomTemplate): var mat = StandardMaterial3D.new() #mat.albedo_color = Color(randi() % 255 / 255.0, randi() % 255 / 255.0, randi() % 255 / 255.0) mat.albedo_color = Color.GREEN + mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA + mat.albedo_color.a = 0.25 meshInstance.set_surface_override_material(0, mat) meshInstance.create_trimesh_collision() meshInstance.visible = true @@ -392,8 +397,8 @@ static func LoadRMesh(file: String, rt: RoomTemplate): #mat.albedo_color = Color(randi() % 255 / 255.0, randi() % 255 / 255.0, randi() % 255 / 255.0) mat.albedo_color = Color.RED meshInstance.set_surface_override_material(0, mat) - meshInstance.create_trimesh_collision() - #meshInstance.visible = false + #meshInstance.create_trimesh_collision() + meshInstance.visible = false scene.add_child(meshInstance) rt.TempTriggerboxName[tb] = ReadString(reader) meshInstance.name = rt.TempTriggerboxName[tb] @@ -447,11 +452,11 @@ static func LoadRMesh(file: String, rt: RoomTemplate): var g = int(lcolor[1]) / 255 * intensity var b = int(lcolor[2]) / 255 * intensity - var pointlight = OmniLight3D.new() - pointlight.light_color = Color(r, g, b) + #var pointlight = OmniLight3D.new() + #pointlight.light_color = Color(r, g, b) #scene.add_child(pointlight) - pointlight.position = Vector3(temp1, temp2, temp3) - #AddTempLight(rt, temp1,temp2,temp3, 2, range, r,g,b) + #pointlight.position = Vector3(temp1, temp2, temp3) + map.AddTempLight(rt, temp1, temp2, temp3, 2, range, r, g, b) else: reader.readFloat() ReadString(reader) @@ -468,18 +473,16 @@ static func LoadRMesh(file: String, rt: RoomTemplate): var g = int(lcolor[1]) / 255 * intensity var b = int(lcolor[2]) / 255 * intensity - #Local lt.LightTemplates = AddTempLight(rt, temp1,temp2,temp3, 2, range, r,g,b) - var angles = ReadString(reader) - #pitch#=Piece(angles,1," ") - #yaw#=Piece(angles,2," ") - #lt\pitch = pitch - #lt\yaw = yaw - # + var lt: LightTemplate = map.AddTempLight(rt, temp1, temp2, temp3, 2, range, r, g, b) + var angles = ReadString(reader).split(" ") + lt.pitch = angles[0].to_float() + lt.yaw = angles[1].to_float() + var innerconeangle = reader.readInt() var outerconeangle = reader.readInt() #print(str("spotlight. Range: ", range, ", lcolor: ", lcolor, ", intensity:", intensity, ", angles: ", angles, ", innerconeangle: ", innerconeangle, ", outerconeangle: ", outerconeangle)) - #lt\innerconeangle = ReadInt(f) - #lt\outerconeangle = ReadInt(f) + lt.innerconeangle = innerconeangle + lt.outerconeangle = outerconeangle else: reader.readFloat() ReadString(reader) diff --git a/src/objects/LightTemplate.gd b/src/objects/LightTemplate.gd new file mode 100644 index 0000000..ec13cc4 --- /dev/null +++ b/src/objects/LightTemplate.gd @@ -0,0 +1,16 @@ +class_name LightTemplate + +var roomtemplate: RoomTemplate +var ltype: int +var x: float +var y: float +var z: float +var range: float +var r: int +var g: int +var b: int + +var pitch: float +var yaw: float +var innerconeangle: float # maybe int?? +var outerconeangle: float diff --git a/src/objects/LightTemplate.gd.uid b/src/objects/LightTemplate.gd.uid new file mode 100644 index 0000000..273cf07 --- /dev/null +++ b/src/objects/LightTemplate.gd.uid @@ -0,0 +1 @@ +uid://cjh18a6cybo2v