Sichtweite und Nebel hinzugefügt
This commit is contained in:
22
blight-assets/src/main/resources/MatDefs/BlightFog.j3md
Normal file
22
blight-assets/src/main/resources/MatDefs/BlightFog.j3md
Normal file
@@ -0,0 +1,22 @@
|
||||
MaterialDef BlightFog {
|
||||
|
||||
MaterialParameters {
|
||||
Texture2D Texture
|
||||
Texture2D DepthTexture
|
||||
Int NumSamples
|
||||
Int NumSamplesDepth
|
||||
|
||||
Color FogColor : 0.75 0.80 0.88 1.0
|
||||
Float FogDensity : 0.40
|
||||
Float FogDistance : 600.0
|
||||
// Wird jeden Frame aus der echten Kamera gesetzt (near, far)
|
||||
Vector2 FrustumNearFar : 1.0 1000.0
|
||||
}
|
||||
|
||||
Technique {
|
||||
VertexShader GLSL150: Common/MatDefs/Post/Post15.vert
|
||||
FragmentShader GLSL150: Shaders/BlightFog.frag
|
||||
|
||||
WorldParameters {}
|
||||
}
|
||||
}
|
||||
37
blight-assets/src/main/resources/Shaders/BlightFog.frag
Normal file
37
blight-assets/src/main/resources/Shaders/BlightFog.frag
Normal file
@@ -0,0 +1,37 @@
|
||||
#import "Common/ShaderLib/GLSLCompat.glsllib"
|
||||
|
||||
uniform sampler2D m_Texture;
|
||||
uniform sampler2D m_DepthTexture;
|
||||
uniform vec4 m_FogColor;
|
||||
uniform float m_FogDensity;
|
||||
uniform float m_FogDistance;
|
||||
// Kamera-Frustum (near, far) — wird jeden Frame aus der echten Kamera gesetzt
|
||||
uniform vec2 m_FrustumNearFar;
|
||||
|
||||
in vec2 texCoord;
|
||||
|
||||
void main() {
|
||||
vec4 sceneColor = texture2D(m_Texture, texCoord);
|
||||
float rawDepth = texture2D(m_DepthTexture, texCoord).r;
|
||||
|
||||
// Sky-Pixel (Depth-Buffer = 1.0) nicht nebeln
|
||||
if (rawDepth >= 1.0) {
|
||||
gl_FragColor = sceneColor;
|
||||
return;
|
||||
}
|
||||
|
||||
float near = m_FrustumNearFar.x;
|
||||
float far = m_FrustumNearFar.y;
|
||||
|
||||
// Depth-Buffer [0,1] → echte Weltdistanz (Meter)
|
||||
// Herleitung: z_view = near*far / (far - rawDepth*(far-near))
|
||||
float linearDist = (near * far) / (far - rawDepth * (far - near));
|
||||
|
||||
// Normiert auf FogDistance; d=1 entspricht genau der eingestellten Nebel-Distanz
|
||||
float d = linearDist / m_FogDistance;
|
||||
|
||||
// Exponential-squared fog (gleiche Formel wie JME FogFilter, korrekte Tiefe)
|
||||
float fogFactor = clamp(exp2(-m_FogDensity * m_FogDensity * d * d * 1.4426950408), 0.0, 1.0);
|
||||
|
||||
gl_FragColor = mix(m_FogColor, sceneColor, fogFactor);
|
||||
}
|
||||
Reference in New Issue
Block a user