This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/draw/engines/eevee/shaders/effect_mist_frag.glsl
Jason Fielder 7c9e128bbf Metal: GLSL Compatibility - explicit mat4_to_mat3 conversion
Explicit constructor for mat3 from a mat4 is not valid and cannot be overloaded.

Adding explicit texture resource type flags for depth textures. This is an explicit requirement for Metal Shading language. This is a temporary compatibility, as this path is already supported in GPU_SHADER_CREATE_INFO under ImageType::DEPTH_2D, though required in shader source for MSL shaders which do not have create info.

Authored by Apple: Michael Parkin-White

Ref T96261

Reviewed By: fclem

Maniphest Tasks: T96261

Differential Revision: https://developer.blender.org/D14418
2022-03-30 19:47:00 +02:00

37 lines
922 B
GLSL

#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
/* Convert depth to Mist factor */
uniform vec3 mistSettings;
uniform depth2D depthBuffer;
#define mistStart mistSettings.x
#define mistInvDistance mistSettings.y
#define mistFalloff mistSettings.z
out vec4 fragColor;
void main()
{
vec2 texel_size = 1.0 / vec2(textureSize(depthBuffer, 0)).xy;
vec2 uvs = gl_FragCoord.xy * texel_size;
float depth = textureLod(depthBuffer, uvs, 0.0).r;
vec3 co = get_view_space_from_depth(uvs, depth);
float zcor = (ProjectionMatrix[3][3] == 0.0) ? length(co) : -co.z;
/* bring depth into 0..1 range */
float mist = saturate((zcor - mistStart) * mistInvDistance);
/* falloff */
mist = pow(mist, mistFalloff);
fragColor = vec4(mist);
// if (mist > 0.999) fragColor = vec4(1.0);
// else if (mist > 0.0001) fragColor = vec4(0.5);
// else fragColor = vec4(0.0);
}