- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: fog fixed distance to island & override ThreeJS fog shader #151
Conversation
Instead of depending on the camera position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Visually the fog looks very nice, good job!
Am I missing something or are the ocean waves no longer animated?
You didn't see anything 🙈 ... jokes aside, you're absolutely right. Thanks for the catch - that slipped through my fingers while I was too focused on the fog 😅 I fixed it right away. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay 😅
Resolves #95
❤️ Pair-Programmed with @Myzios
Not used idea
One giant torus around the scene that has a ray marching depth gradient shader so that the inner has 100% transparency all the way to the outer with 0% transparency. That is very resource hungry and also not really possible in ThreeJS.
Used idea
The ThreeJS fog is a shader applied to every material. Unfortunately, the
material.fog
istrue
by default, making every material simulating a fog when one is present in the scene.Patching ThreeJS and setting the default to
false
would be an option, but we do not use the declarative approach from TresJS with automatic adding to scenes, but the imperative way with ouraddToGroup
oraddShadowAndAddToGroup
functions. So we could add functionality to disable the fog shader on a material and do this per default in our add to group functions:zlig/src/utils/threeHelper.ts
Lines 36 to 44 in 6a231b1
zlig/src/utils/threeHelper.ts
Lines 46 to 55 in 6a231b1
Now we could override the default fog shader in order to stick to a fixed position in the scene and not be dependent on the camera position by modifying each shader that should be effected by a fog:
zlig/src/utils/threeHelper.ts
Lines 67 to 101 in 6a231b1
This new fog shader mechanism was added to the Ocean and the SeaBed (see use of function
overrideFogShader
).Known Problems
addToGroup
oraddShadowAndAddToGroup
, or set the fog on the material manually tofalse
.addToGroup
oraddShadowAndAddToGroup
, but not when using a normal scene add imperative or TresJS declerative addition.This is also weird with the fog bc the two planes (ocean & ocean floor) are not the same length from the perspective of the camera:
So we apply a shorter fog shader to the ocean than to the ocean floor in order to make it more even. But the camera can be tilted and the current offset is a fixed value. So this effect is sometimes better & sometimes worse depending on the angle of the camera. We tried finding a nice sweet spot but ignore a very strong angle. The more from above the camera looks, the better.