mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-28 07:56:26 +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();
|
int sizeZ = box.sizeZ();
|
||||||
glTexImage3D(GL_TEXTURE_3D, 0, GL30.GL_RG8, sizeX, sizeY, sizeZ, 0, GL30.GL_RG, GL_UNSIGNED_BYTE, 0);
|
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();
|
glTexture.unbind();
|
||||||
oldState.makeActive();
|
oldState.makeActive();
|
||||||
}
|
}
|
||||||
|
@ -73,11 +79,6 @@ public class GPULightVolume extends LightVolume {
|
||||||
|
|
||||||
textureUnit.makeActive();
|
textureUnit.makeActive();
|
||||||
glTexture.bind();
|
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();
|
uploadTexture();
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ void FLWFinalizeNormal(inout vec3 normal) {
|
||||||
#if defined(VERTEX_SHADER)
|
#if defined(VERTEX_SHADER)
|
||||||
void FLWFinalizeWorldPos(inout vec4 worldPos) {
|
void FLWFinalizeWorldPos(inout vec4 worldPos) {
|
||||||
#if defined(USE_FOG)
|
#if defined(USE_FOG)
|
||||||
FragDistance = length(worldPos.xyz - uCameraPos);
|
FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
gl_Position = uViewProjection * worldPos;
|
gl_Position = uViewProjection * worldPos;
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#define USE_FOG
|
|
||||||
|
|
||||||
#if defined(VERTEX_SHADER)
|
#if defined(VERTEX_SHADER)
|
||||||
out float FragDistance;
|
out float FragDistance;
|
||||||
#elif defined(FRAGMENT_SHADER)
|
#elif defined(FRAGMENT_SHADER)
|
||||||
|
@ -8,6 +6,18 @@ in float FragDistance;
|
||||||
uniform vec4 uFogColor;
|
uniform vec4 uFogColor;
|
||||||
uniform vec2 uFogRange;
|
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() {
|
float FLWFogFactor() {
|
||||||
return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
return (uFogRange.y - FragDistance) / (uFogRange.y - uFogRange.x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,7 @@ void FLWFinalizeNormal(inout vec3 normal) {
|
||||||
|
|
||||||
#if defined(VERTEX_SHADER)
|
#if defined(VERTEX_SHADER)
|
||||||
void FLWFinalizeWorldPos(inout vec4 worldPos) {
|
void FLWFinalizeWorldPos(inout vec4 worldPos) {
|
||||||
#if defined(USE_FOG)
|
FragDistance = cylindrical_distance(worldPos.xyz, uCameraPos);
|
||||||
FragDistance = length(worldPos.xyz - uCameraPos);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
gl_Position = uViewProjection * worldPos;
|
gl_Position = uViewProjection * worldPos;
|
||||||
}
|
}
|
||||||
|
@ -41,13 +39,11 @@ vec4 FLWBlockTexture(vec2 texCoords) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FLWFinalizeColor(vec4 color) {
|
void FLWFinalizeColor(vec4 color) {
|
||||||
#if defined(USE_FOG)
|
|
||||||
float a = color.a;
|
float a = color.a;
|
||||||
float fog = clamp(FLWFogFactor(), 0., 1.);
|
float fog = clamp(FLWFogFactor(), 0., 1.);
|
||||||
|
|
||||||
color = mix(uFogColor, color, fog);
|
color = mix(uFogColor, color, fog);
|
||||||
color.a = a;
|
color.a = a;
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(ALPHA_DISCARD)
|
#if defined(ALPHA_DISCARD)
|
||||||
if (color.a < ALPHA_DISCARD) {
|
if (color.a < ALPHA_DISCARD) {
|
||||||
|
|
Loading…
Reference in a new issue