mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-26 15:06:28 +01:00
Cylindrical fog
- having the world position is very nice - mojang manages to do multiple matrix multiplications
This commit is contained in:
parent
b183641000
commit
4a86c112dd
4 changed files with 20 additions and 13 deletions
|
@ -55,6 +55,12 @@ public class GPULightVolume extends LightVolume {
|
|||
int sizeZ = box.sizeZ();
|
||||
glTexImage3D(GL_TEXTURE_3D, 0, GL30.GL_RG8, sizeX, sizeY, sizeZ, 0, GL30.GL_RG, GL_UNSIGNED_BYTE, 0);
|
||||
|
||||
glTexture.setParameteri(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexture.setParameteri(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexture.setParameteri(GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
|
||||
glTexture.setParameteri(GL_TEXTURE_WRAP_R, GL_MIRRORED_REPEAT);
|
||||
glTexture.setParameteri(GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
||||
|
||||
glTexture.unbind();
|
||||
oldState.makeActive();
|
||||
}
|
||||
|
@ -73,11 +79,6 @@ public class GPULightVolume extends LightVolume {
|
|||
|
||||
textureUnit.makeActive();
|
||||
glTexture.bind();
|
||||
glTexture.setParameteri(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexture.setParameteri(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexture.setParameteri(GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
|
||||
glTexture.setParameteri(GL_TEXTURE_WRAP_R, GL_MIRRORED_REPEAT);
|
||||
glTexture.setParameteri(GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
||||
|
||||
uploadTexture();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ void FLWFinalizeNormal(inout vec3 normal) {
|
|||
#if defined(VERTEX_SHADER)
|
||||
void FLWFinalizeWorldPos(inout vec4 worldPos) {
|
||||
#if defined(USE_FOG)
|
||||
FragDistance = length(worldPos.xyz - uCameraPos);
|
||||
FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
|
||||
#endif
|
||||
|
||||
gl_Position = uViewProjection * worldPos;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#define USE_FOG
|
||||
|
||||
#if defined(VERTEX_SHADER)
|
||||
out float FragDistance;
|
||||
#elif defined(FRAGMENT_SHADER)
|
||||
|
@ -8,6 +6,18 @@ in float FragDistance;
|
|||
uniform vec4 uFogColor;
|
||||
uniform vec2 uFogRange;
|
||||
|
||||
float cylindrical_distance(vec3 worldPos, vec3 cameraPos) {
|
||||
float distXZ = length(worldPos.xz - cameraPos.xz);
|
||||
float distY = abs(worldPos.y - cameraPos.y);
|
||||
return max(distXZ, distY);
|
||||
}
|
||||
|
||||
float cylindrical_distance(vec3 worldPos) {
|
||||
float distXZ = length(worldPos.xz);
|
||||
float distY = abs(worldPos.y);
|
||||
return max(distXZ, distY);
|
||||
}
|
||||
|
||||
float FLWFogFactor() {
|
||||
return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
||||
}
|
||||
|
|
|
@ -16,9 +16,7 @@ void FLWFinalizeNormal(inout vec3 normal) {
|
|||
|
||||
#if defined(VERTEX_SHADER)
|
||||
void FLWFinalizeWorldPos(inout vec4 worldPos) {
|
||||
#if defined(USE_FOG)
|
||||
FragDistance = length(worldPos.xyz - uCameraPos);
|
||||
#endif
|
||||
FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
|
||||
|
||||
gl_Position = uViewProjection * worldPos;
|
||||
}
|
||||
|
@ -41,13 +39,11 @@ vec4 FLWBlockTexture(vec2 texCoords) {
|
|||
}
|
||||
|
||||
void FLWFinalizeColor(vec4 color) {
|
||||
#if defined(USE_FOG)
|
||||
float a = color.a;
|
||||
float fog = clamp(FLWFogFactor(), 0., 1.);
|
||||
|
||||
color = mix(uFogColor, color, fog);
|
||||
color.a = a;
|
||||
#endif
|
||||
|
||||
#if defined(ALPHA_DISCARD)
|
||||
if (color.a < ALPHA_DISCARD) {
|
||||
|
|
Loading…
Reference in a new issue