Basically, I am trying to make it seem like the player is underwater using fog, but, even though the fog "works", it seems to change in opacity based on what direction you are facing and where you are on the map instead of remaining the same.
import panda3d.core
import ursina
from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
from ursina.shaders import basic_lighting_shader
app = Ursina()
random.seed(0)
ground = Entity(model='cube', collider='box', scale=(64, 1, 64), texture='Textures/floor1.png', texture_scale=(4,4))
tester = Entity(model='sphere', collider='box', scale=2, texture="grass")
editor_camera = EditorCamera(enabled=False, ignore_paused=True)
player = FirstPersonController(model='cube', z=10, color=color.orange, origin_y=-.5, speed=8)
player.collider = BoxCollider(player, Vec3(0,1,0), Vec3(1,2,1))
Sky(color=color.black)
def input(key):
if key == "g":
print(scene.fog.getLinearOnsetPoint())
print(scene.fog.get_linear_onset_point())
def pause_input(key):
if key == "escape":
quit()
if key == 'tab': # press tab to toggle edit/play mode
editor_camera.enabled = not editor_camera.enabled
player.visible_self = editor_camera.enabled
player.cursor.enabled = not editor_camera.enabled
mouse.locked = not editor_camera.enabled
editor_camera.position = player.position
application.paused = editor_camera.enabled
scene.fog_density = .05
scene.fog_color = color.blue
pause_handler = Entity(ignore_paused=True, input=pause_input)
app.run()
I think it has something to do with the fog points, but I don't know how to update them to take into account player position and what direction they are facing. I've tried some versions where I updated the fog points by using the player position, but it still doesn't work correctly when you look around. The problem is most noticeable on the floor.
The fog appeared to render incorrectly because the floor was one giant plane I think, and the fog overlay was trying to base off of distance from the center of the floor instead of whatever part of the floor is closest. I fixed it by making the floor a bunch of pieces. To make the fog appear wherever I was looking, I just put walls and ceiling around the map.