set parameters as uniforms

This commit is contained in:
jrkb 2023-07-15 14:40:09 +02:00
parent f3d7365777
commit 2080b0470c

View file

@ -5,6 +5,11 @@ precision highp float;
uniform sampler2D msdf;
uniform float fade;
uniform float visibilityRadius;
uniform float far_z;
uniform float near_z;
uniform float width;
uniform float height;
uniform vec2 unitRange;
uniform vec4 bgColor;
@ -32,13 +37,14 @@ float screenPxDistance(vec3 msdf_rgb, vec2 uv) {
return screenPxRange(uv)*(sd - 0.5);
}
float near = 1.0;
float far = 4400.0 + 400.0;
float width = 1920.0;
float height = 1080.0;
//float near = 1.0;
//float far = 4400.0 + 400.0;
//float width = 1920.0 * 2.0;
//float height = 1080.0 * 2.0;
float linearizeDepth(float depth)
{
return (2.0 * near * far) / (far + near - (depth * 2.0 - 1.0) * (far - near));
return (2.0 * near_z * far_z) / (far_z + near_z - (depth * 2.0 - 1.0) * (far_z - near_z));
}
void main()
@ -71,13 +77,15 @@ void main()
discard;
//outputColor = vec4(vec3(fgColor),1.0); //mix(bgColor, fgColor, opacity);
float z = linearizeDepth(gl_FragCoord.z) / far;
float z = linearizeDepth(gl_FragCoord.z) / far_z;
vec2 screenPos = abs(vec2(
(gl_FragCoord.x / width) * 2.0 - 1.0,
(gl_FragCoord.y / height) * 2.0 - 1.0
));
// INFO: this needs to be adjusted if field of view is adjusted
float d = smoothstep(0.2, 0.8, z + 0.2 * (screenPos.x + screenPos.y));
//float d = smoothstep(0.2, 0.8, z + 0.2 * (screenPos.x + screenPos.y));
float l = 0.2;
float d = smoothstep(l, 1.0-l, z + l * (screenPos.x + screenPos.y));
d = min(d, fade);
outputColor = vec4(mix(fgColor.rgb, backgroundColor.rgb, d),1.0);
//outputColor = vec4(mix(1.0 - msdf_rgb_a.rgb, backgroundColor.rgb, d),1.0);