sky: improve sun scatter

This commit is contained in:
Bixilon 2022-11-06 00:34:19 +01:00
parent 1d9cd231ae
commit 8af2dd1435
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 6 additions and 7 deletions

View File

@ -34,7 +34,7 @@ Resources:
## Tasks
- [ ] Light scatter
- [x] Light scatter
- [ ] Atmosphere effect
- [ ] improve fog color
- [ ] Lens flare

View File

@ -56,10 +56,9 @@ class SunScatterRenderer(
}
private fun calculateIntensity(progress: Float): Float {
val delta = (abs(progress - 0.5f) * 2.0f)
val sine = minOf(sin(delta * PI.toFloat() / 2.0f), 0.6f)
val delta = (abs(progress) * 2.0f)
return 1.0f - sine
return maxOf(sin(delta * PI.toFloat() / 2.0f), 0.5f)
}
private fun calculateSunPosition(): Vec3 {
@ -79,9 +78,9 @@ class SunScatterRenderer(
if (!sky.profile.sunScatter || sky.time.phase == DayPhases.DAY || sky.time.phase == DayPhases.NIGHT || !sky.properties.sun) {
return
}
shader.use()
if (timeUpdate) {
calculateMatrix()
shader.use()
shader.setMat4("uScatterMatrix", matrix)
shader.setFloat("uIntensity", calculateIntensity(sky.time.progress))
shader.setVec3("uSunPosition", calculateSunPosition())

View File

@ -36,11 +36,11 @@ uniform vec3 uSunPosition;
#define END_DISTANCE MAX_DISTANCE - 0.2f
#define YELLOWISH vec3(0.9f, 0.8f, 0.25f)
#define YELLOWISH vec3(1.0f, 0.6f, 0.15f)
#define REDISH vec3(1.0f, 0.4f, 0.05f)
void main() {
foutColor = vec4(REDISH, uIntensity * 0.8f);
foutColor = vec4(REDISH, uIntensity);
float distance = length(uSunPosition - finFragmentPosition);
float distanceMultiplier = 0.0f;