Тут есть ребята, которые могут помочь мне с SSAO?
А то вот какой он у меня:
precision highp float;
#ifdef _vertex_
in vec3 _attr_position_;
in vec2 _attr_texcoord_1_;
out vec2 texcoord_1;
void main()
{
gl_Position = vec4(_attr_position_, 1.0);
texcoord_1 = _attr_texcoord_1_;
}
#endif
#ifdef _fragment_
in vec2 texcoord_1;
uniform sampler2D _position_buffer_;
uniform sampler2D _normal_buffer_;
layout(location = 0) out vec4 color;
float doAmbientOcclusion(vec2 uv, vec3 p, vec3 cnorm)
{
vec3 diff = texture(_position_buffer_, texcoord_1 + uv).xyz - p;
vec3 v = normalize(diff);
float d = length(diff) * 1.0;
return max(0.0,dot(cnorm,v) - 0.005)*(1.0/(1.0+d))*0.7;
}
float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}
vec2 rnd(float i, float j)
{
float f = rand(texcoord_1.xy);
float r = mod(f, 0.05);
return vec2(i + r, j + r);
}
void main()
{
vec4 pos = texture(_position_buffer_, texcoord_1);
vec3 norm = texture(_normal_buffer_, texcoord_1).xyz;
float ao = 1.0;
float z = pos.a;
for (float i = -0.04; i <= 0.04; i += 0.05)
{
ao -= doAmbientOcclusion(rnd(i, 0.0), pos.xyz, norm);
}
for (float j = -0.04; j <= 0.04; j += 0.05)
{
ao -= doAmbientOcclusion(rnd(0.0, j), pos.xyz, norm);
}
color = vec4 (ao);
}
#endif